files/en-us/web/api/wgsllanguagefeatures/index.md
{{APIRef("WebGPU API")}}{{SecureContext_Header}}{{AvailableInWorkers}}
The WGSLLanguageFeatures interface of the {{domxref("WebGPU API", "WebGPU API", "", "nocode")}} is a setlike object that reports the WGSL language extensions supported by the WebGPU implementation.
The WGSLLanguageFeatures object is accessed via the {{domxref("GPU.wgslLanguageFeatures")}} property.
[!NOTE] Not all WGSL language extensions are available to WebGPU in all browsers that support the API. We recommend you thoroughly test any extensions you choose to use.
{{InheritanceDiagram}}
The following WGSL language extensions are defined at WGSL language extensions in the WGSL specification. Bear in mind that the exact set of features available will vary across implementations and physical devices, and may change over time.
packed_4x8_integer_dot_product
: Allows DP4a (Dot Product of 4 Elements and Accumulate) GPU instructions to be used via your WGSL code. These efficiently perform 8-bit integer dot products to accelerate computation, saving memory and network bandwidth and improving performance compared with the equivalent f32 versions. They are commonly used in machine learning models in inferencing, within AI frameworks.
Specifically, when packed_4x8_integer_dot_product is available, WGSL code can use:
dot4U8Packed() and dot4I8Packed() built-in functions).pack4xI8() and pack4xI8Clamp()).pointer_composite_access
: Enables WGSL shader code to access components of complex data types using the same dot (.) syntax whether you're working directly with the data or with a pointer to it.
When pointer_composite_access is available:
foo is a pointer: foo.bar is available as a more convenient way to write (*foo).bar. The asterisk (*) would normally be needed to turn the pointer into a "reference" that can be dereferenced, but now both pointers and references are almost interchangeable.foo is not a pointer: The dot (.) operator works exactly as you're used to for directly accessing members.pa is a pointer that stores the starting address of an array, then pa[i] gives you direct access to the memory location where the ith element of that array is stored.See Syntax sugar for dereferencing composites in WGSL for further details and an example.
readonly_and_readwrite_storage_textures
"read-only" and "read-write" storageTexture.access values to be set when specifying storage texture bind group entry types in a bind group layout. These enable WGSL code to read storage textures, and read/write storage textures, respectively.subgroup_id
subgroup_id and num_subgroups WGSL built-in values are usable in compute shaders. These improve the process of scheduling work across subgroups, by indexing memory to avoid overlapping memory accesses. See WGSL subgroup_id extension for more details.
[!NOTE] For the
subgroup_idWGSL feature to be usable, thesubgroupsextension needs to be enabled in the {{domxref("GPUDevice")}} (see {{domxref("GPUSupportedFeatures")}}).
uniform_buffer_standard_layout
: When available, uniform buffers use the same memory layout constraints as storage buffers, which makes it easier to share data structures across both kinds of buffers. This means uniform buffers are no longer required to have 16-byte alignment on array elements, or to pad nested structure offsets to a multiple of 16 bytes.
See WGSL uniform_buffer_standard_layout extension for more details.
unrestricted_pointer_parameters
Parameter pointers to storage, uniform, and workgroup address spaces being passed to user-declared functions.
Pointers to structure members and array elements being passed to user-declared functions.
See Pointers As Function Parameters for more details.
The following property is available to all read-only setlike objects:
The following methods are available to all read-only setlike objects:
[value, value] for each element in the set in insertion order.if (
navigator.gpu.wgslLanguageFeatures.has(
"readonly_and_readwrite_storage_textures",
)
) {
console.log("Read-only and read-write storage textures are available");
}
const wgslFeatures = navigator.gpu.wgslLanguageFeatures;
// Return the size of the set
console.log(wgslFeatures.size);
// Iterate through all the set values using values()
const valueIterator = wgslFeatures.values();
for (const value of valueIterator) {
console.log(value);
}
// …
{{Specifications}}
{{Compat}}