diff --git a/backends/webgpu/runtime/WebGPUDevice.cpp b/backends/webgpu/runtime/WebGPUDevice.cpp index 9f48347c16b..d4b148cda5f 100644 --- a/backends/webgpu/runtime/WebGPUDevice.cpp +++ b/backends/webgpu/runtime/WebGPUDevice.cpp @@ -13,9 +13,7 @@ #include #include #include -#ifdef WGPU_BACKEND_ENABLE_PROFILING #include -#endif // WGPU_BACKEND_ENABLE_PROFILING namespace executorch { namespace backends { @@ -143,16 +141,28 @@ WebGPUContext create_webgpu_context() { device_desc.requiredLimits = &supported_limits; } + // Request optional features when the adapter advertises them. A feature the + // adapter lacks is skipped (its fast path stays disabled). A feature the + // adapter advertises becomes required of the device, so if the device were + // to reject it, context creation fails below rather than falling back. The + // vector must outlive wgpuAdapterRequestDevice below (device_desc points + // into it). + std::vector required_features; + if (wgpuAdapterHasFeature(ctx.adapter, WGPUFeatureName_ShaderF16)) { + required_features.push_back(WGPUFeatureName_ShaderF16); + ctx.shader_f16_supported = true; + } #ifdef WGPU_BACKEND_ENABLE_PROFILING // Bench: enable TimestampQuery if available; fail-open (skip timing if not). - std::vector required_features; if (wgpuAdapterHasFeature(ctx.adapter, WGPUFeatureName_TimestampQuery)) { required_features.push_back(WGPUFeatureName_TimestampQuery); - device_desc.requiredFeatureCount = required_features.size(); - device_desc.requiredFeatures = required_features.data(); ctx.timestamp_supported = true; } #endif // WGPU_BACKEND_ENABLE_PROFILING + if (!required_features.empty()) { + device_desc.requiredFeatureCount = required_features.size(); + device_desc.requiredFeatures = required_features.data(); + } device_desc.uncapturedErrorCallbackInfo.callback = on_device_error; diff --git a/backends/webgpu/runtime/WebGPUDevice.h b/backends/webgpu/runtime/WebGPUDevice.h index a332edef443..12f73c969a7 100644 --- a/backends/webgpu/runtime/WebGPUDevice.h +++ b/backends/webgpu/runtime/WebGPUDevice.h @@ -25,6 +25,9 @@ struct WebGPUContext { WGPUAdapter adapter = nullptr; WGPUDevice device = nullptr; WGPUQueue queue = nullptr; + // True if the device was created with the ShaderF16 feature; reserved for a + // future fp16 storage/compute path (fp32 is used when false or unset). + bool shader_f16_supported = false; #ifdef WGPU_BACKEND_ENABLE_PROFILING // True if the device was created with the TimestampQuery feature (bench). bool timestamp_supported = false;