Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: reimplement adapter|device_features #3428

Merged
merged 3 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Bottom level categories:

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

#### Vulkan

Expand Down
67 changes: 34 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async-executor = "1.0"
bitflags = "1"
bit-vec = "0.6"
bytemuck = "1.4"
cargo-run-wasm = "0.2.0"
cargo-run-wasm = "0.3.0"
cfg_aliases = "0.1"
cfg-if = "1"
codespan-reporting = "0.11"
Expand Down Expand Up @@ -114,11 +114,11 @@ glutin = "0.29.1"
# wasm32 dependencies
console_error_panic_hook = "0.1.7"
console_log = "0.2"
js-sys = "0.3.60"
wasm-bindgen = "0.2.83"
wasm-bindgen-futures = "0.4.33"
js-sys = "0.3.61"
wasm-bindgen = "0.2.84"
wasm-bindgen-futures = "0.4.34"
wasm-bindgen-test = "0.3"
web-sys = "0.3.60"
web-sys = "0.3.61"

# deno dependencies
deno_console = "0.84.0"
Expand Down
8 changes: 4 additions & 4 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ objc = "0.2.5"
core-graphics-types = "0.1"

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

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

[dev-dependencies]
env_logger = "0.9"
winit = "0.27.1" # for "halmark" example
winit = "0.27.1" # for "halmark" example

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
glutin = "0.29.1" # for "gles" example
47 changes: 13 additions & 34 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,17 @@ const FEATURES_MAPPING: [(wgt::Features, web_sys::GpuFeatureName); 8] = [
),
];

fn map_wgt_features(supported_features: web_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,
_ => {}
}
}
features
}

type JsFutureResult = Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>;

fn future_request_adapter(result: JsFutureResult) -> Option<(Identified<web_sys::GpuAdapter>, ())> {
Expand Down Expand Up @@ -931,23 +942,7 @@ impl crate::context::Context for Context {
adapter: &Self::AdapterId,
_adapter_data: &Self::AdapterData,
) -> wgt::Features {
let features = adapter.0.features();

let features_set: js_sys::Set = features
.dyn_into()
.expect("adapter.features() is not setlike");

let mut features = wgt::Features::empty();

for (wgpu_feat, web_feat) in FEATURES_MAPPING {
let value = wasm_bindgen::JsValue::from(web_feat);

if features_set.has(&value) {
features |= wgpu_feat;
}
}

features
map_wgt_features(adapter.0.features())
}

fn adapter_limits(
Expand Down Expand Up @@ -1112,23 +1107,7 @@ impl crate::context::Context for Context {
device: &Self::DeviceId,
_device_data: &Self::DeviceData,
) -> wgt::Features {
let features = device.0.features();

let features_set: js_sys::Set = features
.dyn_into()
.expect("device.features() is not setlike");

let mut features = wgt::Features::empty();

for (wgpu_feat, web_feat) in FEATURES_MAPPING {
let value = wasm_bindgen::JsValue::from(web_feat);

if features_set.has(&value) {
features |= wgpu_feat;
}
}

features
map_wgt_features(device.0.features())
}

fn device_limits(
Expand Down