The GPUSupportedFeatures
interface of the WebGPU API is a Set
-like object that describes additional functionality supported by a GPUAdapter
.
The GPUSupportedFeatures
object for the current adapter is accessed via the GPUAdapter.features
property.
You should note that not all features will be available to WebGPU in all browsers that support it, even if the features are supported by the underlying hardware. This could be due to constraints in the underlying system, browser, or adapter. For example:
- The underlying system might not be able to guarantee exposure of a feature in a way that is compatible with a certain browser.
- The browser vendor might not have found a secure way to implement support for that feature, or might just not have gotten round to it yet.
If you are hoping to take advantage of a specific additional feature in a WebGPU app, thorough testing is advised.
We have not listed the exact set of additional features available to be used in WebGPU, as it will vary between implementations and physical devices, and will change over time. For a list, refer to the Feature Index in the specification.
The following properties are available to all read-only Set
-like objects (the links below are to the Set
global object reference page).
-
size
Experimental
-
Returns the number of values in the set.
The following methods are available to all read-only Set
-like objects (the below links are to the Set
global object reference page).
-
has()
Experimental
-
Returns a boolean asserting whether an element is present with the given value in the set or not.
-
values()
Experimental
-
Returns a new iterator object that yields the values for each element in the set in insertion order.
-
keys()
Experimental
-
An alias for values()
.
-
entries()
Experimental
-
Returns a new iterator object that contains [value, value]
for each element in the set, in insertion order.
-
forEach()
Experimental
-
Calls a provided callback function once for each value present in the set, in insertion order.
async function init() {
if (!navigator.gpu) {
throw Error("WebGPU not supported.");
}
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
throw Error("Couldn't request WebGPU adapter.");
}
const adapterFeatures = adapter.features;
console.log(adapterFeatures.size);
console.log(adapterFeatures.has("texture-compression-astc"));
const valueIterator = adapterFeatures.values();
for (const value of valueIterator) {
console.log(value);
}
const keyIterator = adapterFeatures.keys();
for (const value of keyIterator) {
console.log(value);
}
const entryIterator = adapterFeatures.entries();
for (const entry of entryIterator) {
console.log(entry[0]);
}
adapterFeatures.forEach((value) => {
console.log(value);
});
}