WGSLLanguageFeatures
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
Note: This feature is available inWeb Workers.
TheWGSLLanguageFeatures interface of theWebGPU API is asetlike object that reports theWGSL language extensions supported by the WebGPU implementation.
TheWGSLLanguageFeatures object is accessed via theGPU.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.
In this article
Available features
The following WGSL language extensions are defined atWGSL 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_productAllowsDP4a (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
f32versions. They are commonly used in machine learning models in inferencing, within AI frameworks.Specifically, when
packed_4x8_integer_dot_productis available, WGSL code can use:- 32-bit integer scalars packing 4-component vectors of 8-bit integers to be used as inputs to dot product instructions (via the
dot4U8Packed()anddot4I8Packed()built-in functions). - Packing and unpacking instructions with packed 4-component vectors of 8-bit integers (via built-in functions such as
pack4xI8()andpack4xI8Clamp()).
- 32-bit integer scalars packing 4-component vectors of 8-bit integers to be used as inputs to dot product instructions (via the
pointer_composite_accessEnables 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_accessis available:- If
foois a pointer:foo.baris 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. - If
foois not a pointer: The dot (.) operator works exactly as you're used to for directly accessing members. - if
pais a pointer that stores the starting address of an array, thenpa[i]gives you direct access to the memory location where theith element of that array is stored.
SeeSyntax sugar for dereferencing composites in WGSL for further details and an example.
- If
readonly_and_readwrite_storage_texturesWhen available, allows the
"read-only"and"read-write"storageTexture.accessvalues 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.unrestricted_pointer_parametersLoosens restrictions on pointers being passed to WGSL functions. When available, the following are allowed:
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.
SeePointers As Function Parameters for more details.
Instance properties
The following property is available to all read-onlysetlike objects:
sizeReturns the number of values in the set.
Instance methods
The following methods are available to all read-onlysetlike objects:
has()Returns a boolean asserting whether or not an element with the given value is present in the set.
values()Returns a new iterator object that yieldsvalues for each element in the set in insertion order.
keys()An alias for
values().entries()Returns a new iterator object that containsan array of
[value, value]for each element in the set in insertion order.forEach()Calls the provided callback function once for each value present in the set in insertion order.
Examples
>Check whether an extension is available
if ( navigator.gpu.wgslLanguageFeatures.has( "readonly_and_readwrite_storage_textures", )) { console.log("Read-only and read-write storage textures are available");}Return set size and iterate through values
const wgslFeatures = navigator.gpu.wgslLanguageFeatures;// Return the size of the setconsole.log(wgslFeatures.size);// Iterate through all the set values using values()const valueIterator = wgslFeatures.values();for (const value of valueIterator) { console.log(value);}// …Specifications
| Specification |
|---|
| WebGPU> # gpuwgsllanguagefeatures> |