From 67b6f8da24198ccccc5ab0856aa5528b78d8a051 Mon Sep 17 00:00:00 2001 From: Martin Valigursky Date: Wed, 27 May 2026 09:55:11 +0100 Subject: [PATCH] feat(graphics): expose WGSL pointer_composite_access as a device cap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds detection and automatic wiring for the WGSL `pointer_composite_access` language feature, which provides syntactic sugar for dereferencing pointers to composite types — `p.field` and `p[i]` instead of `(*p).field` and `(*p)[i]`. Follows the same pattern as `unrestricted_pointer_parameters` and `linear_indexing`: - `supportsPointerCompositeAccess` device flag, probed from navigator.gpu.wgslLanguageFeatures. - `CAPS_POINTER_COMPOSITE_ACCESS` shader define for conditional compilation. - `requires pointer_composite_access;` directive automatically injected into WGSL shaders on supporting devices. See https://developer.chrome.com/blog/new-in-webgpu-123#syntax_sugar_for_dereferencing_composites_in_wgsl --- src/platform/graphics/graphics-device.js | 14 ++++++++++++++ src/platform/graphics/shader-definition-utils.js | 3 +++ .../graphics/webgpu/webgpu-graphics-device.js | 1 + 3 files changed, 18 insertions(+) diff --git a/src/platform/graphics/graphics-device.js b/src/platform/graphics/graphics-device.js index 066a119938b..554fea11727 100644 --- a/src/platform/graphics/graphics-device.js +++ b/src/platform/graphics/graphics-device.js @@ -295,6 +295,19 @@ class GraphicsDevice extends EventHandler { */ supportsLinearIndexing = false; + /** + * True if the device supports the WGSL `pointer_composite_access` language feature, which + * provides syntactic sugar for dereferencing pointers to composite types: `p.field` and + * `p[i]` may be written instead of `(*p).field` and `(*p)[i]`. The + * `requires pointer_composite_access;` directive is automatically injected into WGSL + * shaders when this feature is available, and the shader define + * `CAPS_POINTER_COMPOSITE_ACCESS` is set for conditional compilation. + * + * @type {boolean} + * @readonly + */ + supportsPointerCompositeAccess = false; + /** * True if the device supports the WGSL `unrestricted_pointer_parameters` language feature, * which allows passing pointers in the `storage`, `uniform`, and `workgroup` address spaces @@ -697,6 +710,7 @@ class GraphicsDevice extends EventHandler { if (this.supportsSubgroupId) capsDefines.set('CAPS_SUBGROUP_ID', ''); if (this.supportsLinearIndexing) capsDefines.set('CAPS_LINEAR_INDEXING', ''); if (this.supportsUnrestrictedPointerParameters) capsDefines.set('CAPS_UNRESTRICTED_POINTER_PARAMETERS', ''); + if (this.supportsPointerCompositeAccess) capsDefines.set('CAPS_POINTER_COMPOSITE_ACCESS', ''); if (this.supportsStorageTextureRead) capsDefines.set('CAPS_STORAGE_TEXTURE_READ', ''); // Platform defines diff --git a/src/platform/graphics/shader-definition-utils.js b/src/platform/graphics/shader-definition-utils.js index 9eabe9ad422..06b923bc5d4 100644 --- a/src/platform/graphics/shader-definition-utils.js +++ b/src/platform/graphics/shader-definition-utils.js @@ -233,6 +233,9 @@ class ShaderDefinitionUtils { if (device.supportsUnrestrictedPointerParameters) { code += 'requires unrestricted_pointer_parameters;\n'; } + if (device.supportsPointerCompositeAccess) { + code += 'requires pointer_composite_access;\n'; + } return code; } diff --git a/src/platform/graphics/webgpu/webgpu-graphics-device.js b/src/platform/graphics/webgpu/webgpu-graphics-device.js index 43cd9389cd8..6cf67156387 100644 --- a/src/platform/graphics/webgpu/webgpu-graphics-device.js +++ b/src/platform/graphics/webgpu/webgpu-graphics-device.js @@ -325,6 +325,7 @@ class WebgpuGraphicsDevice extends GraphicsDevice { this.supportsSubgroupId = wgslFeatures?.has('subgroup_id'); this.supportsLinearIndexing = wgslFeatures?.has('linear_indexing'); this.supportsUnrestrictedPointerParameters = wgslFeatures?.has('unrestricted_pointer_parameters'); + this.supportsPointerCompositeAccess = wgslFeatures?.has('pointer_composite_access'); this.initCapsDefines(); }