mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-23 07:51:08 +01:00
refactor(webgpu): Use feature name/bit mapping from wgpu-types
add changelog entry
This commit is contained in:
1 parent
62547085d3
commit
5675caa183
2 files changed
+15
-86
No files matched your search
@@ -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
|
||||
|
||||
|
||||
+14
-86
@@ -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::<wgt::Features>().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::<js_sys::JsString>()
|
||||
.unwrap(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
.map(|feat| {
|
||||
wasm_bindgen::JsValue::from(feat.as_str())
|
||||
.dyn_into::<js_sys::JsString>()
|
||||
.unwrap()
|
||||
})
|
||||
.collect::<Vec<js_sys::JsString>>();
|
||||
mapped_desc.set_required_features(&required_features);
|
||||
|
||||
Reference in new issue
Block a user