diff --git a/docs/api-reference/core/device-features.mdx b/docs/api-reference/core/device-features.mdx index af2ff6325a..529bc4eaf2 100644 --- a/docs/api-reference/core/device-features.mdx +++ b/docs/api-reference/core/device-features.mdx @@ -26,33 +26,37 @@ Each device has a `device.features` field that holds a `DeviceFeatures` object w -| Feature Name | This
Browser | Description | WebGL counterpart | -| ------------------------------------------ | ------------------------------------------------- | -------------------------------------------- | --------------------------------------- | +| Feature Name | This
Browser | Description | WebGL counterpart | +| ------------------------------------------ | ------------------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------ | | **WebGPU Extensions** | -| `depth-clip-control` | | Disable depth clipping via `unclippedDepth` | `WEBGL_depth_texture` | -| `indirect-first-instance` | | Specify instance index via GPU buffer | N/A | -| `timestamp-query` | | GPU timer query support | N/A | +| `depth-clip-control` | | Disable depth clipping via `unclippedDepth` | `WEBGL_depth_texture` | +| `indirect-first-instance` | | Specify instance index via GPU buffer | N/A | +| `timestamp-query` | | GPU timer query support | N/A | | **WebGL Extensions** | -| `timer-query-webgl` | | GPU timer support | `EXT_disjoint_timer_query` | -| `compilation-status-async-webgl` | | Non-blocking compile/link status | `KHR_parallel_shader_compile` | -| `polygon-mode-webgl` | | Wireframe rendering parameters (debug only) | `WEBGL_polygon_mode` | -| `provoking-vertex-webgl` | | Primitive vertex used for flat shading | `WEBGL_provoking_vertex` | +| `timer-query-webgl` | | GPU timer support | `EXT_disjoint_timer_query` | +| `compilation-status-async-webgl` | | Non-blocking compile/link status | `KHR_parallel_shader_compile` | +| `polygon-mode-webgl` | | Wireframe rendering parameters (debug only) | `WEBGL_polygon_mode` | +| `provoking-vertex-webgl` | | Primitive vertex used for flat shading | `WEBGL_provoking_vertex` | | **Shader Extensions** | -| `shader-f16` | | WGSL supports `f16` | N/A | -| `shader-noperspective-interpolation-webgl` | | GLSL `noperspective` interpolation qualifier | `NV_shader_noperspective_interpolation` | -| `shader-conservative-depth-webgl` | | GLSL enable early depth test optimizations | `EXT_conservative_depth` | -| `shader-clip-cull-distance-webgl` | | GLSL `gl_ClipDistance[]/gl_CullDistance[]` | `WEBGL_clip_cull_distance` | +| `shader-f16` | | WGSL supports `f16` | N/A | +| `shader-noperspective-interpolation-webgl` | | GLSL `noperspective` interpolation qualifier | `NV_shader_noperspective_interpolation` | +| `shader-conservative-depth-webgl` | | GLSL enable early depth test optimizations | `EXT_conservative_depth` | +| `shader-clip-cull-distance-webgl` | | GLSL `gl_ClipDistance[]/gl_CullDistance[]` | `WEBGL_clip_cull_distance` | | **Texture Extensions** | -| `depth24unorm-stencil8` | | | `GL.UNSIGNED_INT_24_8_WEBGL` | -| `depth32float-stencil8` | | | N/A | -| `rg11b10ufloat-renderable` | | rg11b10ufloat textures renderable | N/A | -| `float32-renderable-webgl` | | float32 textures renderable | `EXT_color_buffer_float` | -| `float16-renderable-webgl` | | float16 textures renderable | `EXT_color_buffer_half_float` | -| `float32-filterable` | | float32 textures are filterable | `OES_texture_float_linear` | -| `float16-filterable-webgl` | | float16 `linear` filtering | `OES_texture_half_float_linear` | -| `texture-filterable-anisotropic-webgl` | | anisotropic filtering, common | `EXT_texture_filter_anisotropic` | +| `depth24unorm-stencil8` | | | `GL.UNSIGNED_INT_24_8_WEBGL` | +| `depth32float-stencil8` | | | N/A | +| `rg11b10ufloat-renderable` | | rg11b10ufloat textures renderable | N/A | +| `float32-renderable-webgl` | | float32 textures renderable | `EXT_color_buffer_float` | +| `float16-renderable-webgl` | | float16 textures renderable | `EXT_color_buffer_half_float` | +| `rgb9e5ufloat-renderable-webgl` | | `rgb9e5ufloat` renderable | ['WEBGL_render_shared_exponent'][WEBGL_render_shared_exponent] | +| `snorm8-renderable-webgl` | | `r,rg,rgba8snorm` renderable | [EXT_render_snorm][EXT_render_snorm] | +| `norm16-renderable-webgl` | | `r,rg,rgba16norm` renderable | [EXT_texture_norm16][EXT_texture_norm16] | +| `snorm16-renderable-webgl` | | `r,rg,rgba16snorm` renderable | [EXT_texture_norm16][EXT_texture_norm16], [EXT_render_snorm][EXT_render_snorm] | +| `float32-filterable` | | float32 textures are filterable | `OES_texture_float_linear` | +| `float16-filterable-webgl` | | float16 textures are filterable | `OES_texture_half_float_linear` | +| `texture-filterable-anisotropic-webgl` | | anisotropic filtering, common | `EXT_texture_filter_anisotropic` | | `bgra8unorm-storage` | | can be used as storage binding. | -| `texture-blend-float-webgl` | | float texture blending | `EXT_float_blend` | +| `texture-blend-float-webgl` | | float texture blending | `EXT_float_blend` | | **Compressed Texture Support** | | `texture-compression-bc` | | DXT (BC1-BC7). Desktops. | | `texture-compression-bc5-webgl` | | DXT (BC1-BC5). Desktops. | @@ -92,6 +96,10 @@ if (webglDevice.gl.getExtension('EXT_disjoint_timer_query_webgl2')) { - [WebGL Report](https://webglreport.com/?v=2) - [WebGPU Report](https://webgpureport.org/) +[EXT_depth_clamp]: https://registry.khronos.org/webgl/extensions/EXT_depth_clamp/ +[EXT_render_snorm]: https://registry.khronos.org/webgl/extensions/EXT_depth_clamp/ +[EXT_depth_clamp]: https://registry.khronos.org/webgl/extensions/EXT_depth_clamp/ +[WEBGL_render_shared_exponent]: https://www.khronos.org/registry/webgl/extensions/WEBGL_render_shared_exponent/ [timer_query_webgl2]: https://www.khronos.org/registry/webgl/extensions/EXT_disjoint_timer_query_webgl2/ [texture_compression_bptc]: https://developer.mozilla.org/en-US/docs/Web/API/EXT_texture_compression_bptc [texture_compression_rgtc]: https://developer.mozilla.org/en-US/docs/Web/API/EXT_texture_compression_rgtc diff --git a/docs/api-reference/core/texture-formats.mdx b/docs/api-reference/core/texture-formats.mdx index d5782890ca..4697cd7d9c 100644 --- a/docs/api-reference/core/texture-formats.mdx +++ b/docs/api-reference/core/texture-formats.mdx @@ -56,7 +56,7 @@ Note that even though a GPU supports creating and sampling textures of a certain | `rgb9e5ufloat` | | | | `GL.RGB9_E5` | | `rg11b10ufloat` | | | | `GL.R11F_G11F_B10F` | | `rgb10a2unorm` | | | | `GL.RGB10_A2` | -| `rgb10a2unorm-webgl` | | | | `GL.RGB10_A2UI` | +| `rgb10a2uint-webgl` | | | | `GL.RGB10_A2UI` | | **6 bytes per pixel formats** | | | | | `rgb16unorm-webgl` | | | | | | `rgb16snorm-webgl` | | | | | diff --git a/docs/whats-new.md b/docs/whats-new.md index f630ce78dc..6cf75cb474 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -70,18 +70,30 @@ To accelerate WebGPU development, luma.gl v9 drops support for legacy functional **`@luma.gl/shadertools`** - All shader modules now use uniform buffers. -- NEW: `ShaderAssember` class that provides a clean entry point to the shader module system. +- NEW: `ShaderAssembler` class that provides a clean entry point to the shader module system. - New `CompilerMessage` type and `formatCompilerLog` function for portable shader log handling. **`@luma.gl/webgl`** -- Asynchronous shader compilation and linking is now supported on systems that support the [KHR_parallel_shader_compile](https://registry.khronos.org/webgl/extensions/KHR_parallel_shader_compile/) WebGL extension. This should speed up initialization for applications that create a lot of `RenderPipelines`. -- `parameters.unclippedDepth` - depth clipping can now be disabled if the `depth-clip-control` feature is available. See [`EXT_depth_clamp`][EXT_depth_clamp]. -- `parameters.provokingVertex: 'first'` controls which primitive vertex is used for flat shading. Check the `provoking-vertex-webgl` feature. -- `parameters.polygonMode: 'line'` enables wire frame rendering of polygons. Check the `polygon-mode-webgl` feature. -- `parameters.polygonOffsetLine: true` enables depth bias (polygon offset) for lines. Check the `polygon-mode-webgl` feature. -- `parameters.clipCullDistance0-7: true` enables `gl_ClipDistance[] / gl_CullDistance[]`. Check the `shader-clip-cull-distance-webgl` feature. +WebGL is not dead yet! Browsers (Chrome in particular) are still adding extensions to WebGL 2, and luma.gl +is adding support for many of the new features through the [`DeviceFeatures`](/docs/api-reference/core/device-features) API. + +New `Device.features` that improve WebGL application performance: +- `compilation-status-async-webgl`: Asynchronous shader compilation and linking is used automatically when available and speeds up applications that create many `RenderPipelines`. + +New `Device.features` that expose new WebGL GPU parameters: +- `depth-clip-control`: `parameters.unclippedDepth` - depth clipping can now be disabled if the feature is available. +- `provoking-vertex-webgl`: `parameters.provokingVertex` - controls which primitive vertex is used for flat shading. +- `polygon-mode-webgl`: `parameters.polygonMode` - enables wire frame rendering of polygons. Check the feature. +- `polygon-mode-webgl`: `parameters.polygonOffsetLine` - enables depth bias (polygon offset) for lines. +- `shader-clip-cull-distance-webgl`: `parameters.clipCullDistance0-7` - enables `gl_ClipDistance[] / gl_CullDistance[]`. + +New `Device.features` that enable new GLSL syntax - `shader-noperspective-interpolation-webgl`: GLSL vertex outputs and fragment inputs may be declared with a `noperspective` interpolation qualifier. -- `shader-conservative-depth-webgl`: New GLSL `gl_FragDepth` qualifiers `depth_any` `depth_greater` `depth_less` `depth_unchanged` can enable early depth test optimizations. +- `shader-conservative-depth-webgl`: GLSL `gl_FragDepth` qualifiers `depth_any` `depth_greater` `depth_less` `depth_unchanged` can enable early depth test optimizations. -[EXT_depth_clamp]: https://registry.khronos.org/webgl/extensions/EXT_depth_clamp/ +New `Device.features` that enable additional WebGL color format support: +- `rgb9e5ufloat-renderable-webgl`: `rgb9e5ufloat` are renderable. +- `snorm8-renderable-webgl`: `r,rg,rgba8snorm` are renderable. +- `norm16-renderable-webgl`: `r,rg,rgba16norm` are renderable. +- `snorm16-renderable-webgl`: `r,rg,rgba16snorm` are renderable. diff --git a/modules/constants/src/webgl-constants.ts b/modules/constants/src/webgl-constants.ts index 18dec9c79c..bffdb00387 100644 --- a/modules/constants/src/webgl-constants.ts +++ b/modules/constants/src/webgl-constants.ts @@ -1037,7 +1037,10 @@ enum GLEnum { SRC1_ALPHA_WEBGL = 0x8589, ONE_MINUS_SRC1_COLOR_WEBGL = 0x88fa, ONE_MINUS_SRC1_ALPHA_WEBGL = 0x88fb, - MAX_DUAL_SOURCE_DRAW_BUFFERS_WEBGL = 0x88fc + MAX_DUAL_SOURCE_DRAW_BUFFERS_WEBGL = 0x88fc, + + /** EXT_texture_mirror_clamp_to_edge https://registry.khronos.org/webgl/extensions/EXT_texture_mirror_clamp_to_edge/ */ + MIRROR_CLAMP_TO_EDGE_EXT = 0x8743 } export {GLEnum as GL}; diff --git a/modules/constants/src/webgl-types.ts b/modules/constants/src/webgl-types.ts index 71e4c02f1c..741628c8f6 100644 --- a/modules/constants/src/webgl-types.ts +++ b/modules/constants/src/webgl-types.ts @@ -471,6 +471,13 @@ export type GLExtensions = { // Predefined typescript types not available for the following extensions + /** https://registry.khronos.org/webgl/extensions/EXT_norm16/ */ + EXT_norm16?: EXT_norm16 | null; + /** https://registry.khronos.org/webgl/extensions/EXT_snorm/ */ + EXT_snorm?: EXT_snorm | null; + /** https://registry.khronos.org/webgl/extensions/WEBGL_render_shared_exponent/ */ + WEBGL_render_shared_exponent?: WEBGL_render_shared_exponent | null; + /** https://registry.khronos.org/webgl/extensions/EXT_depth_clamp/ */ EXT_depth_clamp?: EXT_depth_clamp | null; /** https://registry.khronos.org/webgl/extensions/WEBGL_provoking_vertex/ */ @@ -487,20 +494,36 @@ export type GLExtensions = { /** EXT_conservative_depth https://registry.khronos.org/webgl/extensions/EXT_conservative_depth/ */ EXT_conservative_depth?: EXT_conservative_depth | null; + /** OES_sample_variables https://registry.khronos.org/webgl/extensions/OES_sample_variables/ */ + OES_sample_variables?: OES_sample_variables | null; + /** EXT_polygon_offset_clamp https://registry.khronos.org/webgl/extensions/EXT_polygon_offset_clamp/ */ EXT_polygon_offset_clamp?: EXT_polygon_offset_clamp | null; /** EXT_clip_control https://registry.khronos.org/webgl/extensions/EXT_clip_control/ */ EXT_clip_control?: EXT_clip_control | null; + /** EXT_texture_mirror_clamp_to_edge https://registry.khronos.org/webgl/extensions/EXT_texture_mirror_clamp_to_edge/ */ + EXT_texture_mirror_clamp_to_edge?: EXT_texture_mirror_clamp_to_edge | null; + /** EXT_texture_mirror_clamp_to_edge https://registry.khronos.org/webgl/extensions/EXT_texture_mirror_clamp_to_edge/ */ + WEBGL_stencil_texturing?: WEBGL_stencil_texturing | null; + /** WEBGL_blend_func_extended https://registry.khronos.org/webgl/extensions/WEBGL_blend_func_extended/ */ WEBGL_blend_func_extended?: WEBGL_blend_func_extended | null; /** OES_draw_buffers_indexed https://registry.khronos.org/webgl/extensions/OES_draw_buffers_indexed/ */ OES_draw_buffers_indexed?: OES_draw_buffers_indexed | null; - // WEBGL1 extensions (available as built-in WebGL 2 APIs) + /** WEBGL_draw_instanced_base_vertex_base_instance https://registry.khronos.org/webgl/extensions/WEBGL_draw_instanced_base_vertex_base_instance/ */ + WEBGL_draw_instanced_base_vertex_base_instance?: WEBGL_draw_instanced_base_vertex_base_instance | null; + /** WEBGL_multi_draw https://registry.khronos.org/webgl/extensions/WEBGL_multi_draw/ */ + WEBGL_multi_draw?: WEBGL_multi_draw | null; + /** WEBGL_multi_draw_instanced_base_vertex_base_instance https://registry.khronos.org/webgl/extensions/WEBGL_multi_draw_instanced_base_vertex_base_instance/ */ + WEBGL_multi_draw_instanced_base_vertex_base_instance?: WEBGL_multi_draw_instanced_base_vertex_base_instance | null; + /** WEBGL_shader_pixel_local_storage https://registry.khronos.org/webgl/extensions/WEBGL_shader_pixel_local_storage/ */ + WEBGL_shader_pixel_local_storage?: WEBGL_shader_pixel_local_storage | null; + // WEBGL1 extensions (available as built-in WebGL 2 APIs) // ANGLE_instanced_arrays?: ANGLE_instanced_arrays | null; // EXT_blend_minmax?: EXT_blend_minmax | null; // EXT_frag_depth?: EXT_frag_depth | null; @@ -514,6 +537,21 @@ export type GLExtensions = { // WEBGL_multi_draw?: WEBGL_multi_draw | null; }; +/** https://registry.khronos.org/webgl/extensions/EXT_norm16/ */ +type EXT_norm16 = { + // Constants in GL enum +}; + +/** https://registry.khronos.org/webgl/extensions/EXT_snorm/ */ +type EXT_snorm = { + // Constants in GL enum +}; + +/** https://registry.khronos.org/webgl/extensions/WEBGL_render_shared_exponent/ */ +type WEBGL_render_shared_exponent = { + // Constants in GL enum +}; + /** https://registry.khronos.org/webgl/extensions/EXT_depth_clamp/ */ type EXT_depth_clamp = { // Constants in GL enum @@ -567,6 +605,9 @@ type NV_shader_noperspective_interpolation = {}; /** EXT_conservative_depth https://registry.khronos.org/webgl/extensions/EXT_conservative_depth/ */ type EXT_conservative_depth = {}; +/** OES_sample_variables https://registry.khronos.org/webgl/extensions/OES_sample_variables/ */ +type OES_sample_variables = {}; + /** EXT_polygon_offset_clamp https://registry.khronos.org/webgl/extensions/EXT_polygon_offset_clamp/ */ type EXT_polygon_offset_clamp = { POLYGON_OFFSET_CLAMP_EXT: 0x8e1b; @@ -614,3 +655,113 @@ type OES_draw_buffers_indexed = { /** Modifies color mask for an individual draw buffer */ colorMaskiOES(buf: number, r: boolean, g: boolean, b: boolean, a: boolean): void; }; + +/** EXT_texture_mirror_clamp_to_edge https://registry.khronos.org/webgl/extensions/EXT_texture_mirror_clamp_to_edge/ */ +type EXT_texture_mirror_clamp_to_edge = { + MIRROR_CLAMP_TO_EDGE_EXT: 0x8743; +}; + +/** WEBGL_stencil_texturing https://registry.khronos.org/webgl/extensions/WEBGL_stencil_texturing/ */ +type WEBGL_stencil_texturing = { + DEPTH_STENCIL_TEXTURE_MODE_WEBGL: 0x90ea; + STENCIL_INDEX_WEBGL: 0x1901; +}; + +/** WEBGL_draw_instanced_base_vertex_base_instance https://registry.khronos.org/webgl/extensions/WEBGL_draw_instanced_base_vertex_base_instance/ */ +type WEBGL_draw_instanced_base_vertex_base_instance = { + // drawArraysInstancedBaseInstanceWEBGL( + // GLenum mode, GLint first, GLsizei count, + // GLsizei instanceCount, GLuint baseInstance); + // drawElementsInstancedBaseVertexBaseInstanceWEBGL( + // GLenum mode, GLsizei count, GLenum type, GLintptr offset, + // GLsizei instanceCount, GLint baseVertex, GLuint baseInstance); +}; + +/** WEBGL_multi_draw https://registry.khronos.org/webgl/extensions/WEBGL_multi_draw/ */ +type WEBGL_multi_draw = { + // multiDrawArraysWEBGL( + // GLenum mode, + // ([AllowShared] Int32Array or sequence) firstsList, unsigned long long firstsOffset, + // ([AllowShared] Int32Array or sequence) countsList, unsigned long long countsOffset, + // GLsizei drawcount); + // multiDrawElementsWEBGL( + // GLenum mode, + // ([AllowShared] Int32Array or sequence) countsList, unsigned long long countsOffset, + // GLenum type, + // ([AllowShared] Int32Array or sequence) offsetsList, unsigned long long offsetsOffset, + // GLsizei drawcount); + // multiDrawArraysInstancedWEBGL( + // GLenum mode, + // ([AllowShared] Int32Array or sequence) firstsList, unsigned long long firstsOffset, + // ([AllowShared] Int32Array or sequence) countsList, unsigned long long countsOffset, + // ([AllowShared] Int32Array or sequence) instanceCountsList, unsigned long long instanceCountsOffset, + // GLsizei drawcount); + // multiDrawElementsInstancedWEBGL( + // GLenum mode, + // ([AllowShared] Int32Array or sequence) countsList, unsigned long long countsOffset, + // GLenum type, + // ([AllowShared] Int32Array or sequence) offsetsList, unsigned long long offsetsOffset, + // ([AllowShared] Int32Array or sequence) instanceCountsList, unsigned long long instanceCountsOffset, + // GLsizei drawcount); +}; + +/** WEBGL_multi_draw_instanced_base_vertex_base_instance https://registry.khronos.org/webgl/extensions/WEBGL_multi_draw_instanced_base_vertex_base_instance/ */ +type WEBGL_multi_draw_instanced_base_vertex_base_instance = { + // multiDrawArraysInstancedBaseInstanceWEBGL( + // GLenum mode, + // ([AllowShared] Int32Array or sequence) firstsList, unsigned long long firstsOffset, + // ([AllowShared] Int32Array or sequence) countsList, unsigned long long countsOffset, + // ([AllowShared] Int32Array or sequence) instanceCountsList, unsigned long long instanceCountsOffset, + // ([AllowShared] Uint32Array or sequence) baseInstancesList, unsigned long long baseInstancesOffset, + // GLsizei drawcount + // ); + // multiDrawElementsInstancedBaseVertexBaseInstanceWEBGL( + // GLenum mode, + // ([AllowShared] Int32Array or sequence) countsList, unsigned long long countsOffset, + // GLenum type, + // ([AllowShared] Int32Array or sequence) offsetsList, unsigned long long offsetsOffset, + // ([AllowShared] Int32Array or sequence) instanceCountsList, unsigned long long instanceCountsOffset, + // ([AllowShared] Int32Array or sequence) baseVerticesList, unsigned long long baseVerticesOffset, + // ([AllowShared] Uint32Array or sequence) baseInstancesList, unsigned long long baseInstancesOffset, + // GLsizei drawcount + // ); +}; + +/** WEBGL_shader_pixel_local_storage https://registry.khronos.org/webgl/extensions/WEBGL_shader_pixel_local_storage/ */ +type WEBGL_shader_pixel_local_storage = { + MAX_PIXEL_LOCAL_STORAGE_PLANES_WEBGL: 0x96e0; + MAX_COLOR_ATTACHMENTS_WITH_ACTIVE_PIXEL_LOCAL_STORAGE_WEBGL: 0x96e1; + MAX_COMBINED_DRAW_BUFFERS_AND_PIXEL_LOCAL_STORAGE_PLANES_WEBGL: 0x96e2; + PIXEL_LOCAL_STORAGE_ACTIVE_PLANES_WEBGL: 0x96e3; + LOAD_OP_ZERO_WEBGL: 0x96e4; + LOAD_OP_CLEAR_WEBGL: 0x96e5; + LOAD_OP_LOAD_WEBGL: 0x96e6; + STORE_OP_STORE_WEBGL: 0x96e7; + PIXEL_LOCAL_FORMAT_WEBGL: 0x96e8; + PIXEL_LOCAL_TEXTURE_NAME_WEBGL: 0x96e9; + PIXEL_LOCAL_TEXTURE_LEVEL_WEBGL: 0x96ea; + PIXEL_LOCAL_TEXTURE_LAYER_WEBGL: 0x96eb; + PIXEL_LOCAL_CLEAR_VALUE_FLOAT_WEBGL: 0x96ec; + PIXEL_LOCAL_CLEAR_VALUE_INT_WEBGL: 0x96ed; + PIXEL_LOCAL_CLEAR_VALUE_UNSIGNED_INT_WEBGL: 0x96ee; + isCoherent(): boolean; + framebufferTexturePixelLocalStorageWEBGL( + plane: number, + texture: WebGLTexture, + level: number, + layer: number + ): void; + // framebufferPixelLocalClearValuefvWEBGL(plane: number, + // Float32List value, + // optional unsigned long long srcOffset = 0): void; + // framebufferPixelLocalClearValueivWEBGL(plane: number, + // Int32List value, + // optional unsigned long long srcOffset = 0): void; + // framebufferPixelLocalClearValueuivWEBGL(plane: number, + // Uint32List value, + // optional unsigned long long srcOffset = 0): void; + beginPixelLocalStorageWEBGL(loadops: GL[]): void; + endPixelLocalStorageWEBGL(storeops: GL[]): void; + pixelLocalStorageBarrierWEBGL(): void; + getFramebufferPixelLocalStorageParameterWEBGL(plane: number, pname: GL): any; +}; diff --git a/modules/core/src/adapter/device.ts b/modules/core/src/adapter/device.ts index 0449235e30..6dc192caa2 100644 --- a/modules/core/src/adapter/device.ts +++ b/modules/core/src/adapter/device.ts @@ -163,7 +163,10 @@ export type WebGLDeviceFeature = // texture rendering | 'float32-renderable-webgl' | 'float16-renderable-webgl' + | 'rgb9e5ufloat_renderable-webgl' + | 'snorm8-renderable-webgl' | 'norm16-renderable-webgl' + | 'snorm16-renderable-webgl' // texture filtering | 'float16-filterable-webgl' diff --git a/modules/core/src/adapter/type-utils/decode-texture-format.ts b/modules/core/src/adapter/type-utils/decode-texture-format.ts index e6067ed991..f61fdeae2b 100644 --- a/modules/core/src/adapter/type-utils/decode-texture-format.ts +++ b/modules/core/src/adapter/type-utils/decode-texture-format.ts @@ -65,7 +65,7 @@ const EXCEPTIONS: Partial> = { rgb9e5ufloat: {format: 'rgb', bbp: 4}, rg11b10ufloat: {format: 'rgb', bbp: 4}, rgb10a2unorm: {format: 'rgba', bbp: 4}, - 'rgb10a2unorm-webgl': {format: 'rgba', bbp: 4}, + 'rgb10a2uint-webgl': {format: 'rgba', bbp: 4}, // Depth/stencil stencil8: {components: 1, bpp: 1, a: 'stencil'}, depth16unorm: {components: 1, bpp: 2, a: 'depth'}, diff --git a/modules/core/src/adapter/types/texture-formats.ts b/modules/core/src/adapter/types/texture-formats.ts index aa0b0418b0..37609ee369 100644 --- a/modules/core/src/adapter/types/texture-formats.ts +++ b/modules/core/src/adapter/types/texture-formats.ts @@ -150,7 +150,7 @@ export type WebGL2ColorTextureFormat = | 'rgb8snorm-webgl' | 'rg16unorm-webgl' | 'rg16snorm-webgl' - | 'rgb10a2unorm-webgl' + | 'rgb10a2uint-webgl' | 'rgb16unorm-webgl' | 'rgb16snorm-webgl' | 'rgba16unorm-webgl' diff --git a/modules/webgl/src/adapter/converters/texture-formats.ts b/modules/webgl/src/adapter/converters/texture-formats.ts index 017be6320c..dec7290e14 100644 --- a/modules/webgl/src/adapter/converters/texture-formats.ts +++ b/modules/webgl/src/adapter/converters/texture-formats.ts @@ -19,8 +19,15 @@ const texture_compression_etc1_webgl: DeviceFeature = 'texture-compression-etc1- const texture_compression_pvrtc_webgl: DeviceFeature = 'texture-compression-pvrtc-webgl'; const texture_compression_atc_webgl: DeviceFeature = 'texture-compression-atc-webgl'; -// const float32_renderable_webgl: DeviceFeature = 'float32-renderable-webgl'; -// const float16_renderable_webgl: DeviceFeature = 'float16-renderable-webgl'; +const float32_renderable: DeviceFeature = 'float32-renderable-webgl'; +const float16_renderable: DeviceFeature = 'float16-renderable-webgl'; +const rgb9e5ufloat_renderable: DeviceFeature = 'rgb9e5ufloat_renderable-webgl'; +const snorm8_renderable: DeviceFeature = 'snorm8-renderable-webgl'; +const norm16_renderable: DeviceFeature = 'norm16-renderable-webgl'; +const snorm16_renderable: DeviceFeature = 'snorm16-renderable-webgl'; + +const float32_filterable: DeviceFeature = 'float32-filterable'; +const float16_filterable: DeviceFeature = 'float16-filterable-webgl'; // Define local webgl extension strings to optimize minification const X_S3TC = 'WEBGL_compressed_texture_s3tc'; // BC1, BC2, BC3 @@ -35,14 +42,17 @@ const X_ATC = 'WEBGL_compressed_texture_atc'; // Define local webgl extension strings to optimize minification const EXT_texture_norm16 = 'EXT_texture_norm16'; +const EXT_render_snorm = 'EXT_render_snorm'; const EXT_color_buffer_float = 'EXT_color_buffer_float'; -// const EXT_HALF_FLOAT_WEBGL1 = 'EXT_color_buffer_half_float'; // prettier-ignore export const TEXTURE_FEATURES: Partial> = { - 'float32-renderable-webgl': ['EXT_color_buffer_float'], // [false, 'EXT_color_buffer_float'], + 'float32-renderable-webgl': ['EXT_color_buffer_float'], 'float16-renderable-webgl': ['EXT_color_buffer_half_float'], + 'rgb9e5ufloat_renderable-webgl': ['WEBGL_render_shared_exponent'], + 'snorm8-renderable-webgl': [EXT_render_snorm], 'norm16-renderable-webgl': [EXT_texture_norm16], + 'snorm16-renderable-webgl': [EXT_texture_norm16, EXT_render_snorm], 'float32-filterable': ['OES_texture_float_linear'], 'float16-filterable-webgl': ['OES_texture_half_float_linear'], @@ -143,21 +153,21 @@ export const TEXTURE_FORMATS: Record = { // 8-bit formats 'r8unorm': {gl: GL.R8, b: 1, c: 1, renderbuffer: true}, - 'r8snorm': {gl: GL.R8_SNORM, b: 1, c: 1}, + 'r8snorm': {gl: GL.R8_SNORM, b: 1, c: 1, render: snorm8_renderable}, 'r8uint': {gl: GL.R8UI, b: 1, c: 1, renderbuffer: true}, 'r8sint': {gl: GL.R8I, b: 1, c: 1, renderbuffer: true}, // 16-bit formats 'rg8unorm': {gl: GL.RG8, b: 2, c: 2, renderbuffer: true}, - 'rg8snorm': {gl: GL.RG8_SNORM, b: 2, c: 2}, + 'rg8snorm': {gl: GL.RG8_SNORM, b: 2, c: 2, render: snorm8_renderable}, 'rg8uint': {gl: GL.RG8UI, b: 2, c: 2, renderbuffer: true}, 'rg8sint': {gl: GL.RG8I, b: 2, c: 2, renderbuffer: true}, 'r16uint': {gl: GL.R16UI, b: 2, c: 1, renderbuffer: true}, 'r16sint': {gl: GL.R16I, b: 2, c: 1, renderbuffer: true}, - 'r16float': {gl: GL.R16F, b: 2, c: 1, render: 'float16-renderable-webgl', filter: 'float16-filterable-webgl', renderbuffer: true}, - 'r16unorm-webgl': {gl: GL.R16_EXT, b:2, c:1, f: 'norm16-renderable-webgl', renderbuffer: true, x: EXT_texture_norm16}, - 'r16snorm-webgl': {gl: GL.R16_SNORM_EXT, b:2, c:1, f: 'norm16-renderable-webgl', x: EXT_texture_norm16}, + 'r16float': {gl: GL.R16F, b: 2, c: 1, render: float16_renderable, filter: 'float16-filterable-webgl', renderbuffer: true}, + 'r16unorm-webgl': {gl: GL.R16_EXT, b:2, c:1, f: norm16_renderable, renderbuffer: true}, + 'r16snorm-webgl': {gl: GL.R16_SNORM_EXT, b:2, c:1, f: snorm16_renderable}, // Packed 16-bit formats 'rgba4unorm-webgl': {gl: GL.RGBA4, b: 2, c: 4, wgpu: false, renderbuffer: true}, @@ -171,7 +181,7 @@ export const TEXTURE_FORMATS: Record = { // 32-bit formats 'rgba8unorm': {gl: GL.RGBA8, b: 4, c: 2, bpp: 4}, 'rgba8unorm-srgb': {gl: GL.SRGB8_ALPHA8, b: 4, c: 4, bpp: 4}, - 'rgba8snorm': {gl: GL.RGBA8_SNORM, b: 4, c: 4}, + 'rgba8snorm': {gl: GL.RGBA8_SNORM, b: 4, c: 4, render: snorm8_renderable}, 'rgba8uint': {gl: GL.RGBA8UI, b: 4, c: 4, bpp: 4}, 'rgba8sint': {gl: GL.RGBA8I, b: 4, c: 4, bpp: 4}, // reverse colors, webgpu only @@ -181,42 +191,42 @@ export const TEXTURE_FORMATS: Record = { 'rg16uint': {gl: GL.RG16UI, b: 4, c: 1, bpp: 4}, 'rg16sint': {gl: GL.RG16I, b: 4, c: 2, bpp: 4}, // When using a WebGL 2 context and the EXT_color_buffer_float WebGL2 extension - 'rg16float': {gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: 'float16-renderable-webgl', filter: 'float16-filterable-webgl', renderbuffer: true}, - 'rg16unorm-webgl': {gl: GL.RG16_EXT, b:2, c:2, f: 'norm16-renderable-webgl', x: EXT_texture_norm16}, - 'rg16snorm-webgl': {gl: GL.RG16_SNORM_EXT, b:2, c:2, f: 'norm16-renderable-webgl', x: EXT_texture_norm16}, + 'rg16float': {gl: GL.RG16F, bpp: 4, b: 4, c: 2, render: float16_renderable, filter: float16_filterable, renderbuffer: true}, + 'rg16unorm-webgl': {gl: GL.RG16_EXT, b:2, c:2, render: norm16_renderable}, + 'rg16snorm-webgl': {gl: GL.RG16_SNORM_EXT, b:2, c:2, render: snorm16_renderable}, 'r32uint': {gl: GL.R32UI, b: 4, c: 1, bpp: 4, renderbuffer: true}, 'r32sint': {gl: GL.R32I, b: 4, c: 1, bpp: 4, renderbuffer: true}, - 'r32float': {gl: GL.R32F, bpp: 4, b: 4, c: 1, render: 'float32-renderable-webgl', filter: 'float32-filterable'}, + 'r32float': {gl: GL.R32F, bpp: 4, b: 4, c: 1, render: float32_renderable, filter: float32_filterable}, // Packed 32-bit formats - 'rgb9e5ufloat': {gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render: 'float16-renderable-webgl', filter: 'float16-filterable-webgl'}, - 'rg11b10ufloat': {gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1,render: 'float32-renderable-webgl', renderbuffer: true}, + 'rgb9e5ufloat': {gl: GL.RGB9_E5, b: 4, c: 3, p: 1, render: rgb9e5ufloat_renderable}, // , filter: true}, + 'rg11b10ufloat': {gl: GL.R11F_G11F_B10F, b: 4, c: 3, p: 1,render: float32_renderable, renderbuffer: true}, 'rgb10a2unorm': {gl: GL.RGB10_A2, b: 4, c: 4, p: 1, renderbuffer: true}, - 'rgb10a2unorm-webgl': {b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4, renderbuffer: true}, + 'rgb10a2uint-webgl': {b: 4, c: 4, gl: GL.RGB10_A2UI, p: 1, wgpu: false, bpp: 4, renderbuffer: true}, // 48-bit formats - 'rgb16unorm-webgl': {gl: GL.RGB16_EXT, b:2, c:3, f: 'norm16-renderable-webgl', x: EXT_texture_norm16}, - 'rgb16snorm-webgl': {gl: GL.RGB16_SNORM_EXT, b:2, c:3, f: 'norm16-renderable-webgl', x: EXT_texture_norm16}, + 'rgb16unorm-webgl': {gl: GL.RGB16_EXT, b:2, c:3, f: norm16_renderable}, // rgb not renderable + 'rgb16snorm-webgl': {gl: GL.RGB16_SNORM_EXT, b:2, c:3, f: norm16_renderable}, // rgb not renderable // 64-bit formats 'rg32uint': {gl: GL.RG32UI, b: 8, c: 2, renderbuffer: true}, 'rg32sint': {gl: GL.RG32I, b: 8, c: 2, renderbuffer: true}, - 'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: 'float32-renderable-webgl', filter: 'float32-filterable', renderbuffer: true}, + 'rg32float': {gl: GL.RG32F, b: 8, c: 2, render: float32_renderable, filter: float32_filterable, renderbuffer: true}, 'rgba16uint': {gl: GL.RGBA16UI, b: 8, c: 4, renderbuffer: true}, 'rgba16sint': {gl: GL.RGBA16I, b: 8, c: 4, renderbuffer: true}, - 'rgba16float': {gl: GL.RGBA16F, b: 8, c: 4, render: 'float16-renderable-webgl', filter: 'float16-filterable-webgl'}, - 'rgba16unorm-webgl': {gl: GL.RGBA16_EXT, b:2, c:4, f: 'norm16-renderable-webgl', renderbuffer: true, x: EXT_texture_norm16}, - 'rgba16snorm-webgl': {gl: GL.RGBA16_SNORM_EXT, b:2, c:4, f: 'norm16-renderable-webgl', x: EXT_texture_norm16}, + 'rgba16float': {gl: GL.RGBA16F, b: 8, c: 4, render: float16_renderable, filter: float16_filterable}, + 'rgba16unorm-webgl': {gl: GL.RGBA16_EXT, b:2, c:4, render: norm16_renderable, renderbuffer: true}, + 'rgba16snorm-webgl': {gl: GL.RGBA16_SNORM_EXT, b:2, c:4, render: snorm16_renderable}, // 96-bit formats (deprecated!) - 'rgb32float-webgl': {gl: GL.RGB32F, render: 'float32-renderable-webgl', filter: 'float32-filterable', + 'rgb32float-webgl': {gl: GL.RGB32F, render: float32_renderable, filter: float32_filterable, gl2ext: EXT_color_buffer_float, dataFormat: GL.RGB, types: [GL.FLOAT]}, // 128-bit formats 'rgba32uint': {gl: GL.RGBA32UI, b: 16, c: 4, renderbuffer: true}, 'rgba32sint': {gl: GL.RGBA32I, b: 16, c: 4, renderbuffer: true}, - 'rgba32float': {gl: GL.RGBA32F, b: 16, c: 4, render: 'float32-renderable-webgl', filter: 'float32-filterable', renderbuffer: true}, + 'rgba32float': {gl: GL.RGBA32F, b: 16, c: 4, render: float32_renderable, filter: float32_filterable, renderbuffer: true}, // Depth and stencil formats 'stencil8': {gl: GL.STENCIL_INDEX8, b: 1, c: 1, attachment: GL.STENCIL_ATTACHMENT, renderbuffer: true}, // 8 stencil bits