From 5675caa183579d6704523ddb4f6ccc963ecd0e84 Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Fri, 4 Sep 2026 10:39:11 -0700 Subject: [PATCH] refactor(webgpu): Use feature name/bit mapping from wgpu-types add changelog entry --- CHANGELOG.md | 1 + wgpu/src/backend/webgpu.rs | 100 ++++++------------------------------- 2 files changed, 15 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfeed3300..9d40ea6d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -170,6 +170,7 @@ By @sagudev in [#10307](https://github.com/gfx-rs/wgpu/pull/10307). #### WebGPU - Add `Device::import_external_texture` to bind a `GPUExternalTexture` sampled from an `HTMLVideoElement` or WebCodecs `VideoFrame`, without a copy. By @AdrianEddy in [#9936](https://github.com/gfx-rs/wgpu/pull/9936). +- The `subgroups` feature (and any other features added in the future) will now be reported by the WebGPU backend, if reported by the underlying WebGPU implementation. By @andyleiserson in [#10265](https://github.com/gfx-rs/wgpu/pull/10265). ### Changes diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 7bf97a70c..c70f67f37 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -776,82 +776,16 @@ fn map_map_mode(mode: crate::MapMode) -> u32 { } } -const FEATURES_MAPPING: [(wgt::Features, webgpu_sys::GpuFeatureName); 16] = [ - ( - wgt::Features::BGRA8UNORM_STORAGE, - webgpu_sys::GpuFeatureName::Bgra8unormStorage, - ), - ( - wgt::Features::CLIP_DISTANCES, - webgpu_sys::GpuFeatureName::ClipDistances, - ), - ( - wgt::Features::DEPTH32FLOAT_STENCIL8, - webgpu_sys::GpuFeatureName::Depth32floatStencil8, - ), - ( - wgt::Features::DEPTH_CLIP_CONTROL, - webgpu_sys::GpuFeatureName::DepthClipControl, - ), - ( - wgt::Features::DUAL_SOURCE_BLENDING, - webgpu_sys::GpuFeatureName::DualSourceBlending, - ), - ( - wgt::Features::FLOAT32_BLENDABLE, - webgpu_sys::GpuFeatureName::Float32Blendable, - ), - ( - wgt::Features::FLOAT32_FILTERABLE, - webgpu_sys::GpuFeatureName::Float32Filterable, - ), - ( - wgt::Features::INDIRECT_FIRST_INSTANCE, - webgpu_sys::GpuFeatureName::IndirectFirstInstance, - ), - ( - wgt::Features::RG11B10UFLOAT_RENDERABLE, - webgpu_sys::GpuFeatureName::Rg11b10ufloatRenderable, - ), - ( - wgt::Features::SHADER_F16, - webgpu_sys::GpuFeatureName::ShaderF16, - ), - ( - wgt::Features::TEXTURE_COMPRESSION_ASTC, - webgpu_sys::GpuFeatureName::TextureCompressionAstc, - ), - ( - wgt::Features::TEXTURE_COMPRESSION_ASTC_SLICED_3D, - webgpu_sys::GpuFeatureName::TextureCompressionAstcSliced3d, - ), - ( - wgt::Features::TEXTURE_COMPRESSION_BC, - webgpu_sys::GpuFeatureName::TextureCompressionBc, - ), - ( - wgt::Features::TEXTURE_COMPRESSION_BC_SLICED_3D, - webgpu_sys::GpuFeatureName::TextureCompressionBcSliced3d, - ), - ( - wgt::Features::TEXTURE_COMPRESSION_ETC2, - webgpu_sys::GpuFeatureName::TextureCompressionEtc2, - ), - ( - wgt::Features::TIMESTAMP_QUERY, - webgpu_sys::GpuFeatureName::TimestampQuery, - ), -]; - fn map_wgt_features(supported_features: webgpu_sys::GpuSupportedFeatures) -> wgt::Features { - let mut features = wgt::Features::empty(); - for (wgpu_feat, web_feat) in FEATURES_MAPPING { - match wasm_bindgen::JsValue::from(web_feat).as_string() { - Some(value) if supported_features.has(&value) => features |= wgpu_feat, - _ => {} - } + let mut wgpu_features = wgt::Features::default(); + for feature in supported_features.values().into_iter() { + let feature = feature.expect("`GpuSupportedFeatures` elements should be valid"); + let feature = feature + .as_string() + .expect("`GpuSupportedFeatures` should be string set"); + wgpu_features |= feature.parse::().unwrap_or_default(); } - features + wgpu_features } fn map_wgt_limits(limits: webgpu_sys::GpuSupportedLimits) -> wgt::Limits { @@ -1830,19 +1764,13 @@ impl dispatch::AdapterInterface for WebAdapter { let required_limits = map_js_sys_limits(&desc.required_limits); mapped_desc.set_required_limits(&required_limits); - let required_features = FEATURES_MAPPING + let required_features = desc + .required_features .iter() - .copied() - .flat_map(|(flag, value)| { - if desc.required_features.contains(flag) { - Some( - wasm_bindgen::JsValue::from(value) - .dyn_into::() - .unwrap(), - ) - } else { - None - } + .map(|feat| { + wasm_bindgen::JsValue::from(feat.as_str()) + .dyn_into::() + .unwrap() }) .collect::>(); mapped_desc.set_required_features(&required_features);