Skip to content

Commit 0d5b484

Browse files
authored
web: reimplement adapter|device_features (#3428)
1 parent 4bebad7 commit 0d5b484

File tree

5 files changed

+57
-76
lines changed

5 files changed

+57
-76
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Bottom level categories:
5656

5757
- Implement `CommandEncoder::clear_buffer`. By @raphlinus in [#3426](https://github.com/gfx-rs/wgpu/pull/3426)
5858
- Implement the new checks for readonly stencils. By @JCapucho in [#3443](https://github.com/gfx-rs/wgpu/pull/3443)
59+
- Reimplement `adapter|device_features`. By @jinleili in [#3428](https://github.com/gfx-rs/wgpu/pull/3428)
5960

6061
#### Vulkan
6162

Cargo.lock

Lines changed: 34 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async-executor = "1.0"
5151
bitflags = "1"
5252
bit-vec = "0.6"
5353
bytemuck = "1.4"
54-
cargo-run-wasm = "0.2.0"
54+
cargo-run-wasm = "0.3.0"
5555
cfg_aliases = "0.1"
5656
cfg-if = "1"
5757
codespan-reporting = "0.11"
@@ -114,11 +114,11 @@ glutin = "0.29.1"
114114
# wasm32 dependencies
115115
console_error_panic_hook = "0.1.7"
116116
console_log = "0.2"
117-
js-sys = "0.3.60"
118-
wasm-bindgen = "0.2.83"
119-
wasm-bindgen-futures = "0.4.33"
117+
js-sys = "0.3.61"
118+
wasm-bindgen = "0.2.84"
119+
wasm-bindgen-futures = "0.4.34"
120120
wasm-bindgen-test = "0.3"
121-
web-sys = "0.3.60"
121+
web-sys = "0.3.61"
122122

123123
# deno dependencies
124124
deno_console = "0.84.0"

wgpu-hal/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ objc = "0.2.5"
102102
core-graphics-types = "0.1"
103103

104104
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
105-
wasm-bindgen = "0.2.83"
106-
web-sys = { version = "0.3.60", features = ["Window", "HtmlCanvasElement", "WebGl2RenderingContext", "OffscreenCanvas"] }
107-
js-sys = "0.3.60"
105+
wasm-bindgen = "0.2.84"
106+
web-sys = { version = "0.3.61", features = ["Window", "HtmlCanvasElement", "WebGl2RenderingContext", "OffscreenCanvas"] }
107+
js-sys = "0.3.61"
108108

109109
[target.'cfg(unix)'.dependencies]
110110
libc = "0.2"
@@ -127,7 +127,7 @@ features = ["wgsl-in"]
127127

128128
[dev-dependencies]
129129
env_logger = "0.9"
130-
winit = "0.27.1" # for "halmark" example
130+
winit = "0.27.1" # for "halmark" example
131131

132132
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
133133
glutin = "0.29.1" # for "gles" example

wgpu/src/backend/web.rs

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,17 @@ const FEATURES_MAPPING: [(wgt::Features, web_sys::GpuFeatureName); 8] = [
585585
),
586586
];
587587

588+
fn map_wgt_features(supported_features: web_sys::GpuSupportedFeatures) -> wgt::Features {
589+
let mut features = wgt::Features::empty();
590+
for (wgpu_feat, web_feat) in FEATURES_MAPPING {
591+
match wasm_bindgen::JsValue::from(web_feat).as_string() {
592+
Some(value) if supported_features.has(&value) => features |= wgpu_feat,
593+
_ => {}
594+
}
595+
}
596+
features
597+
}
598+
588599
type JsFutureResult = Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>;
589600

590601
fn future_request_adapter(result: JsFutureResult) -> Option<(Identified<web_sys::GpuAdapter>, ())> {
@@ -931,23 +942,7 @@ impl crate::context::Context for Context {
931942
adapter: &Self::AdapterId,
932943
_adapter_data: &Self::AdapterData,
933944
) -> wgt::Features {
934-
let features = adapter.0.features();
935-
936-
let features_set: js_sys::Set = features
937-
.dyn_into()
938-
.expect("adapter.features() is not setlike");
939-
940-
let mut features = wgt::Features::empty();
941-
942-
for (wgpu_feat, web_feat) in FEATURES_MAPPING {
943-
let value = wasm_bindgen::JsValue::from(web_feat);
944-
945-
if features_set.has(&value) {
946-
features |= wgpu_feat;
947-
}
948-
}
949-
950-
features
945+
map_wgt_features(adapter.0.features())
951946
}
952947

953948
fn adapter_limits(
@@ -1112,23 +1107,7 @@ impl crate::context::Context for Context {
11121107
device: &Self::DeviceId,
11131108
_device_data: &Self::DeviceData,
11141109
) -> wgt::Features {
1115-
let features = device.0.features();
1116-
1117-
let features_set: js_sys::Set = features
1118-
.dyn_into()
1119-
.expect("device.features() is not setlike");
1120-
1121-
let mut features = wgt::Features::empty();
1122-
1123-
for (wgpu_feat, web_feat) in FEATURES_MAPPING {
1124-
let value = wasm_bindgen::JsValue::from(web_feat);
1125-
1126-
if features_set.has(&value) {
1127-
features |= wgpu_feat;
1128-
}
1129-
}
1130-
1131-
features
1110+
map_wgt_features(device.0.features())
11321111
}
11331112

11341113
fn device_limits(

0 commit comments

Comments
 (0)