GPUDevice: features property
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("WebGPU API")}}{{SecureContext_Header}}{{AvailableInWorkers}}
The **features** read-only property of the {{domxref("GPUDevice")}} interface returns a {{domxref("GPUSupportedFeatures")}} object that describes additional functionality supported by the device. Only features requested during the creation of the device (i.e., when {{domxref("GPUAdapter.requestDevice()")}} is called) are included.
توجه: Not all features will be available to WebGPU in all browsers that support it, even if the features are supported by the underlying hardware. See {{domxref("GPUAdapter.features")}} for more details.
Value
A {{domxref("GPUSupportedFeatures")}} object instance. This is a setlike object.
Examples
In the following code we check whether a {{domxref("GPUAdapter")}} has the texture-compression-astc feature available. If so, we push it into the array of requiredFeatures, and request a device with that feature requirement using {{domxref("GPUAdapter.requestDevice()")}}.
We then log all items in the GPUDevice.features set to the console. This set should only contain a single item — texture-compression-astc — as that was the only feature requested when the device was created.
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 requiredFeatures = [];
if (adapter.features.has("texture-compression-astc")) {
requiredFeatures.push("texture-compression-astc");
}
const device = await adapter.requestDevice({
requiredFeatures,
});
device.features.forEach((value) => {
console.log(value);
});
// …
}Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- The WebGPU API