Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for integer/data textures in WebGL2 and WebGPU #5921

Merged
merged 46 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2d92cdd
Support for integer/data textures in WebGL2 and WebGPU
liamdon Dec 28, 2023
441ddef
Add newline to fix lint
liamdon Dec 28, 2023
fb82f38
Fix RG16I string label
liamdon Dec 29, 2023
a5aff3e
Add optional check
liamdon Dec 29, 2023
cf7e085
Change comment to Not supported on WebGL1
liamdon Jan 11, 2024
167dbf3
Merge branch 'playcanvas:main' into integerTextures
liamdon Jan 11, 2024
e0e9d48
Clean up uniform buffer storage selection and padding
liamdon Jan 11, 2024
eadc793
Clean up spaces
liamdon Jan 11, 2024
faed1b2
Update WebGL1 not supported comment
liamdon Jan 11, 2024
0aad9e7
Use boolean flag to indicate integer pixel format
liamdon Jan 11, 2024
d120a5e
Reorder constants and fix webgpu typo
liamdon Jan 12, 2024
a9b19fc
Keep original textureDimensions order in shader-processor
liamdon Jan 12, 2024
226f820
Revert uniform-buffer with minimal additions
liamdon Jan 12, 2024
5d4a7c5
Do not allow changing integer texture mipmap/filter properties, log w…
liamdon Jan 12, 2024
8a507bf
Revert formatting changes to compressed formats
liamdon Jan 12, 2024
b06dd17
Revert previous comment change
liamdon Jan 12, 2024
de39dbf
Keep original order of pcUniformType in webgl-graphics-device
liamdon Jan 12, 2024
3f75752
Keep original order in webgl-graphics-device
liamdon Jan 12, 2024
8db0a1e
Minimize import diff
liamdon Jan 12, 2024
d696041
Minimize import diff
liamdon Jan 12, 2024
ad242c9
Sand simulation example
liamdon Jan 14, 2024
1b98c07
Clean up example a bit
liamdon Jan 15, 2024
58b8af5
Clean up some lines
liamdon Jan 15, 2024
450c4fc
Use single int texture instead of uvec2
liamdon Jan 15, 2024
ed815d9
Add additional keyboard shortcuts
liamdon Jan 15, 2024
2072c1d
Reuse vertex shader, add comment
liamdon Jan 15, 2024
a418af4
Add comments to resetData
liamdon Jan 15, 2024
893b5ca
Remove undefined throws
liamdon Jan 15, 2024
0a5e4f2
Use example description, remove screen and assets, add comments
liamdon Jan 15, 2024
1757afc
Revert description width change
liamdon Jan 15, 2024
3c87f7f
Add a WebGL1 warning in controls panel
liamdon Jan 15, 2024
c4d3a8f
Accept options object when creating shaders, allow changing outputTyp…
liamdon Jan 15, 2024
63febb9
Remove console log
liamdon Jan 15, 2024
4b9bfbd
Merge branch 'playcanvas:main' into integerTextures
liamdon Jan 15, 2024
d4bd689
Update src/platform/graphics/shader-utils.js
mvaligursky Jan 16, 2024
37e062f
Additional PR comments
liamdon Jan 16, 2024
8df55e1
Update src/scene/graphics/render-pass-shader-quad.js
mvaligursky Jan 17, 2024
4dd0110
Update src/scene/graphics/render-pass-shader-quad.js
mvaligursky Jan 17, 2024
1f111c2
Add note explaining use of 'comparison' for integer textures
liamdon Jan 17, 2024
a429aae
Update src/platform/graphics/webgpu/webgpu-bind-group-format.js
liamdon Jan 17, 2024
4f2e1b3
Update src/platform/graphics/shader-utils.js
liamdon Jan 17, 2024
a90f77d
Apply suggestions from code review
liamdon Jan 17, 2024
b401817
Update src/scene/graphics/render-pass-shader-quad.js
liamdon Jan 17, 2024
b93cd2c
Merge branch 'playcanvas:main' into integerTextures
liamdon Jan 18, 2024
a436a9f
For unsigned pixel formats, use U instead of UI
liamdon Jan 18, 2024
9c6a482
Change string names of pixelFormatInfo
liamdon Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
340 changes: 301 additions & 39 deletions src/platform/graphics/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,133 @@ export const PIXELFORMAT_ATC_RGBA = 30;
*/
export const PIXELFORMAT_BGRA8 = 31;

/**
* 8-bit signed integer single-channel (R) format (WebGL2 only).
mvaligursky marked this conversation as resolved.
Show resolved Hide resolved
*
* @type {number}
*/
export const PIXELFORMAT_R8I = 32;

/**
* 8-bit unsigned integer single-channel (R) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_R8UI = 33;
mvaligursky marked this conversation as resolved.
Show resolved Hide resolved

/**
* 16-bit signed integer single-channel (R) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_R16I = 34;

/**
* 16-bit unsigned integer single-channel (R) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_R16UI = 35;

/**
* 32-bit signed integer single-channel (R) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_R32I = 36;

/**
* 32-bit unsigned integer single-channel (R) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_R32UI = 37;

/**
* 8-bit per-channel signed integer (RG) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RG8I = 38;

/**
* 8-bit per-channel unsigned integer (RG) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RG8UI = 39;

/**
* 16-bit per-channel signed integer (RG) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RG16I = 40;

/**
* 16-bit per-channel unsigned integer (RG) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RG16UI = 41;

/**
* 32-bit per-channel signed integer (RG) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RG32I = 42;

/**
* 32-bit per-channel unsigned integer (RG) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RG32UI = 43;

/**
* 8-bit per-channel signed integer (RGBA) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RGBA8I = 44;

/**
* 8-bit per-channel unsigned integer (RGBA) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RGBA8UI = 45;

/**
* 16-bit per-channel signed integer (RGBA) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RGBA16I = 46;

/**
* 16-bit per-channel unsigned integer (RGBA) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RGBA16UI = 47;

/**
* 32-bit per-channel signed integer (RGBA) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RGBA32I = 48;

/**
* 32-bit per-channel unsigned integer (RGBA) format (WebGL2 only).
*
* @type {number}
*/
export const PIXELFORMAT_RGBA32UI = 49;


// map of engine PIXELFORMAT_*** enums to information about the format
export const pixelFormatInfo = new Map([

Expand Down Expand Up @@ -655,12 +782,36 @@ export const pixelFormatInfo = new Map([
[PIXELFORMAT_PVRTC_4BPP_RGBA_1, { name: 'PVRTC_4BPP_RGBA_1', blockSize: 8 }],
[PIXELFORMAT_ASTC_4x4, { name: 'ASTC_4x4', blockSize: 16 }],
[PIXELFORMAT_ATC_RGB, { name: 'ATC_RGB', blockSize: 8 }],
[PIXELFORMAT_ATC_RGBA, { name: 'ATC_RGBA', blockSize: 16 }]
[PIXELFORMAT_ATC_RGBA, { name: 'ATC_RGBA', blockSize: 16 }],

// uncompressed integer formats (WebGL2 Only)
liamdon marked this conversation as resolved.
Show resolved Hide resolved
[PIXELFORMAT_R8I, { name: 'R8I', size: 1, channelSize: 1 }],
liamdon marked this conversation as resolved.
Show resolved Hide resolved
[PIXELFORMAT_R8UI, { name: 'R8UI', size: 1, channelSize: 1 }],
[PIXELFORMAT_R16I, { name: 'R16I', size: 2, channelSize: 2 }],
[PIXELFORMAT_R16UI, { name: 'R16UI', size: 2, channelSize: 2 }],
[PIXELFORMAT_R32I, { name: 'R32I', size: 4, channelSize: 4 }],
[PIXELFORMAT_R32UI, { name: 'R32UI', size: 4, channelSize: 4 }],
[PIXELFORMAT_RG8I, { name: 'RG8I', size: 2, channelSize: 1 }],
[PIXELFORMAT_RG8UI, { name: 'RG8UI', size: 2, channelSize: 1 }],
[PIXELFORMAT_RG16I, { name: 'RG16I', size: 4, channelSize: 2 }],
[PIXELFORMAT_RG16UI, { name: 'RG16UI', size: 4, channelSize: 2 }],
[PIXELFORMAT_RG32I, { name: 'RG32I', size: 8, channelSize: 4 }],
[PIXELFORMAT_RG32UI, { name: 'RG32UI', size: 8, channelSize: 4 }],
[PIXELFORMAT_RGBA8I, { name: 'RGBA8I', size: 4, channelSize: 1 }],
[PIXELFORMAT_RGBA8UI, { name: 'RGBA8UI', size: 4, channelSize: 1 }],
[PIXELFORMAT_RGBA16I, { name: 'RGBA16I', size: 8, channelSize: 2 }],
[PIXELFORMAT_RGBA16UI, { name: 'RGBA16UI', size: 8, channelSize: 2 }],
[PIXELFORMAT_RGBA32I, { name: 'RGBA32I', size: 16, channelSize: 4 }],
[PIXELFORMAT_RGBA32UI, { name: 'RGBA32UI', size: 16, channelSize: 4 }]
willeastcott marked this conversation as resolved.
Show resolved Hide resolved
]);

// update this function when exposing additional compressed pixel formats
export const isCompressedPixelFormat = (format) => {
return pixelFormatInfo.get(format).blockSize !== undefined;
return pixelFormatInfo.get(format)?.blockSize !== undefined;
};

export const isIntegerPixelFormat = (format) => {
return pixelFormatInfo.get(format)?.channelSize !== undefined;
};

// get the pixel format array type
Expand All @@ -669,12 +820,31 @@ export const getPixelFormatArrayType = (format) => {
case PIXELFORMAT_RGB32F:
case PIXELFORMAT_RGBA32F:
return Float32Array;
case PIXELFORMAT_R32I:
case PIXELFORMAT_RG32I:
case PIXELFORMAT_RGBA32I:
return Int32Array;
case PIXELFORMAT_R32UI:
case PIXELFORMAT_RG32UI:
case PIXELFORMAT_RGBA32UI:
return Uint32Array;
case PIXELFORMAT_R16I:
case PIXELFORMAT_RG16I:
case PIXELFORMAT_RGBA16I:
return Int16Array;
case PIXELFORMAT_R16UI:
case PIXELFORMAT_RG16UI:
case PIXELFORMAT_RGBA16UI:
case PIXELFORMAT_RGB565:
case PIXELFORMAT_RGBA5551:
case PIXELFORMAT_RGBA4:
case PIXELFORMAT_RGB16F:
case PIXELFORMAT_RGBA16F:
return Uint16Array;
case PIXELFORMAT_R8I:
case PIXELFORMAT_RG8I:
case PIXELFORMAT_RGBA8I:
return Int8Array;
default:
return Uint8Array;
}
Expand Down Expand Up @@ -1169,58 +1339,150 @@ export const TYPE_FLOAT32 = 6;
*/
export const TYPE_FLOAT16 = 7;

export const UNIFORMTYPE_BOOL = 0;
/**
* Uniform and sampler types
*/
liamdon marked this conversation as resolved.
Show resolved Hide resolved
// Uniforms
export const UNIFORMTYPE_FLOAT = 0;
liamdon marked this conversation as resolved.
Show resolved Hide resolved
export const UNIFORMTYPE_INT = 1;
export const UNIFORMTYPE_FLOAT = 2;
export const UNIFORMTYPE_VEC2 = 3;
export const UNIFORMTYPE_VEC3 = 4;
export const UNIFORMTYPE_VEC4 = 5;
export const UNIFORMTYPE_IVEC2 = 6;
export const UNIFORMTYPE_IVEC3 = 7;
export const UNIFORMTYPE_IVEC4 = 8;
export const UNIFORMTYPE_BVEC2 = 9;
export const UNIFORMTYPE_BVEC3 = 10;
export const UNIFORMTYPE_BVEC4 = 11;
export const UNIFORMTYPE_MAT2 = 12;
export const UNIFORMTYPE_MAT3 = 13;
export const UNIFORMTYPE_MAT4 = 14;
export const UNIFORMTYPE_TEXTURE2D = 15;
export const UNIFORMTYPE_TEXTURECUBE = 16;
export const UNIFORMTYPE_FLOATARRAY = 17;
export const UNIFORMTYPE_TEXTURE2D_SHADOW = 18;
export const UNIFORMTYPE_TEXTURECUBE_SHADOW = 19;
export const UNIFORMTYPE_TEXTURE3D = 20;
export const UNIFORMTYPE_VEC2ARRAY = 21;
export const UNIFORMTYPE_VEC3ARRAY = 22;
export const UNIFORMTYPE_VEC4ARRAY = 23;
export const UNIFORMTYPE_MAT4ARRAY = 24;
export const UNIFORMTYPE_TEXTURE2D_ARRAY = 25;
export const UNIFORMTYPE_UINT = 2;
export const UNIFORMTYPE_BOOL = 3;

export const UNIFORMTYPE_VEC2 = 4;
export const UNIFORMTYPE_IVEC2 = 5;
export const UNIFORMTYPE_UVEC2 = 6;
export const UNIFORMTYPE_BVEC2 = 7;

export const UNIFORMTYPE_VEC3 = 8;
export const UNIFORMTYPE_IVEC3 = 9;
export const UNIFORMTYPE_UVEC3 = 10;
export const UNIFORMTYPE_BVEC3 = 11;

export const UNIFORMTYPE_VEC4 = 12;
export const UNIFORMTYPE_IVEC4 = 13;
export const UNIFORMTYPE_UVEC4 = 14;
export const UNIFORMTYPE_BVEC4 = 15;

export const UNIFORMTYPE_MAT2 = 16;
export const UNIFORMTYPE_MAT3 = 17;
export const UNIFORMTYPE_MAT4 = 18;

// Uniform buffers
export const UNIFORMTYPE_FLOATARRAY = 19;
export const UNIFORMTYPE_INTARRAY = 20;
export const UNIFORMTYPE_UINTARRAY = 21;
export const UNIFORMTYPE_BOOLARRAY = 22;

export const UNIFORMTYPE_VEC2ARRAY = 23;
export const UNIFORMTYPE_IVEC2ARRAY = 24;
export const UNIFORMTYPE_UVEC2ARRAY = 25;
export const UNIFORMTYPE_BVEC2ARRAY = 26;

export const UNIFORMTYPE_VEC3ARRAY = 27;
export const UNIFORMTYPE_IVEC3ARRAY = 28;
export const UNIFORMTYPE_UVEC3ARRAY = 29;
export const UNIFORMTYPE_BVEC3ARRAY = 30;

export const UNIFORMTYPE_VEC4ARRAY = 31;
export const UNIFORMTYPE_IVEC4ARRAY = 32;
export const UNIFORMTYPE_UVEC4ARRAY = 33;
export const UNIFORMTYPE_BVEC4ARRAY = 34;

export const UNIFORMTYPE_MAT4ARRAY = 35;

// Samplers: 2D
export const UNIFORMTYPE_TEXTURE2D = 36;
export const UNIFORMTYPE_ITEXTURE2D = 37;
export const UNIFORMTYPE_UTEXTURE2D = 38;
export const UNIFORMTYPE_TEXTURE2D_SHADOW = 39;

// Samplers: Cube
export const UNIFORMTYPE_TEXTURECUBE = 40;
export const UNIFORMTYPE_ITEXTURECUBE = 41;
export const UNIFORMTYPE_UTEXTURECUBE = 42;
export const UNIFORMTYPE_TEXTURECUBE_SHADOW = 43;

// Samplers: 3D
export const UNIFORMTYPE_TEXTURE3D = 44;
export const UNIFORMTYPE_ITEXTURE3D = 45;
export const UNIFORMTYPE_UTEXTURE3D = 46;

// Samplers Texture Array
export const UNIFORMTYPE_TEXTURE2D_ARRAY = 47;
export const UNIFORMTYPE_ITEXTURE2D_ARRAY = 48;
export const UNIFORMTYPE_UTEXTURE2D_ARRAY = 49;


export const uniformTypeToName = [
'bool',
'int',
// Uniforms
'float',
'int',
'uint',
'bool',

'vec2',
'vec3',
'vec4',
'ivec2',
'uvec2',
'bvec2',

'vec3',
'ivec3',
'uvec3',
'bvec3',

'vec4',
'ivec4',
'bec2',
'bec3',
'bec4',
'uvec4',
'bvec4',

'mat2',
'mat3',
'mat4',
'sampler2D',
'samplerCube',

// Uniform buffers
'', // not directly handled: UNIFORMTYPE_FLOATARRAY
'', // not directly handled: UNIFORMTYPE_INTARRAY
'', // not directly handled: UNIFORMTYPE_UINTARRAY
'', // not directly handled: UNIFORMTYPE_BOOLARRAY

'', // not directly handled: UNIFORMTYPE_VEC2ARRAY
'', // not directly handled: UNIFORMTYPE_IVEC2ARRAY
'', // not directly handled: UNIFORMTYPE_UVEC2ARRAY
'', // not directly handled: UNIFORMTYPE_BVEC2ARRAY

'', // not directly handled: UNIFORMTYPE_VEC3ARRAY
'', // not directly handled: UNIFORMTYPE_IVEC3ARRAY
'', // not directly handled: UNIFORMTYPE_UVEC3ARRAY
'', // not directly handled: UNIFORMTYPE_BVEC3ARRAY

'', // not directly handled: UNIFORMTYPE_VEC4ARRAY
'', // not directly handled: UNIFORMTYPE_IVEC4ARRAY
'', // not directly handled: UNIFORMTYPE_UVEC4ARRAY
'', // not directly handled: UNIFORMTYPE_BVEC4ARRAY

'', // not directly handled: UNIFORMTYPE_MAT4ARRAY

// Samplers: 2D
'sampler2D',
'isampler2D',
'usampler2D',
'sampler2DShadow',

// Samplers: Cube
'samplerCube',
'isamplerCube',
'usamplerCube',
'samplerCubeShadow',

// Samplers: 3D
'sampler3D',
'', // not directly handled: UNIFORMTYPE_VEC2ARRAY
'', // not directly handled: UNIFORMTYPE_VEC3ARRAY
'' // not directly handled: UNIFORMTYPE_VEC4ARRAY
'isampler3D',
'usampler3D',

// Samplers Texture Array
'sampler2DArray',
'isampler2DArray',
'usampler2DArray'
];

/**
Expand Down
Loading