Skip to content

Commit a9279de

Browse files
authored
Fix assorted issues with WebGL (gfx-rs#7448)
* Fix validation error when configuring the surface on WebGL * Remove unneeded `webgl` feature * Fix compilation of the `noop` backend on `wasm32` * Prevent `webgpu` examples from incorrectly falling back to WebGL * Reduce dependency set when building wasm examples * Fix various warnings
1 parent 02700ab commit a9279de

8 files changed

Lines changed: 17 additions & 21 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ wgpu = { version = "24.0.0", path = "./wgpu", default-features = false, features
6868
"dx12",
6969
"metal",
7070
"static-dxc",
71-
"webgl",
7271
"noop", # This should be removed if we ever have non-test crates that depend on wgpu
7372
] }
7473
wgpu-core = { version = "24.0.0", path = "./wgpu-core" }

examples/features/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ obj.workspace = true
4444
png.workspace = true
4545
pollster.workspace = true
4646
web-time.workspace = true
47-
wgpu.workspace = true
4847
wgpu-types = { workspace = true, features = [
4948
"trace", # TODO(#5974): this should be a dep on wgpu/trace and not wgpu-types at all
5049
] }
@@ -55,13 +54,15 @@ wgpu-test.workspace = true
5554

5655
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
5756
env_logger.workspace = true
57+
wgpu.workspace = true
5858

5959
[target.'cfg(target_arch = "wasm32")'.dependencies]
6060
console_error_panic_hook.workspace = true
6161
console_log.workspace = true
6262
fern.workspace = true
6363
wasm-bindgen.workspace = true
6464
wasm-bindgen-futures.workspace = true
65+
wgpu = { path = "../../wgpu", default-features = false, features = ["wgsl"] }
6566
# We need these features in the framework examples and tests
6667
web-sys = { workspace = true, features = [
6768
"Location",

wgpu-core/src/conv.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ pub fn is_valid_copy_dst_texture_format(
2727
}
2828
}
2929

30-
#[cfg_attr(
31-
any(not(target_arch = "wasm32"), target_os = "emscripten"),
32-
allow(unused)
33-
)]
30+
#[cfg_attr(any(not(webgl)), expect(unused))]
3431
pub fn is_valid_external_image_copy_dst_texture_format(format: wgt::TextureFormat) -> bool {
3532
use wgt::TextureFormat as Tf;
3633
match format {

wgpu-core/src/device/global.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,11 @@ impl Global {
18801880
Ok(wgt::PollStatus::Poll) => {
18811881
unreachable!("Cannot get a Poll result from a Wait action.")
18821882
}
1883+
Err(WaitIdleError::Timeout) if cfg!(target_arch = "wasm32") => {
1884+
// On wasm, you cannot actually successfully wait for the surface.
1885+
// However WebGL does not actually require you do this, so ignoring
1886+
// the failure is totally fine. See https://github.com/gfx-rs/wgpu/issues/7363
1887+
}
18831888
Err(e) => {
18841889
break 'error e.into();
18851890
}

wgpu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ webgl = ["wgpu-core/webgl", "dep:wgpu-hal", "dep:smallvec"]
7676
## but performs no computation.
7777
## Because it lacks basic functionality, it is only actually used if explicitly enabled
7878
## through `NoopBackendOptions`.
79-
noop = ["wgpu-core/noop"]
79+
noop = ["wgpu-core/noop", "dep:wgpu-hal", "dep:smallvec"]
8080

8181
#! **Note:** In the documentation, if you see that an item depends on a backend,
8282
#! it means that the item is only available when that backend is enabled _and_ the backend

wgpu/src/api/queue.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ crate::cmp::impl_eq_ord_hash_proxy!(Queue => .inner);
2727
/// There is no analogue in the WebGPU specification.
2828
#[derive(Debug, Clone)]
2929
pub struct SubmissionIndex {
30-
#[cfg_attr(
31-
all(
32-
target_arch = "wasm32",
33-
not(target_os = "emscripten"),
34-
not(feature = "webgl"),
35-
),
36-
expect(dead_code)
37-
)]
30+
#[cfg_attr(not(wgpu_core), expect(dead_code))]
3831
pub(crate) index: u64,
3932
}
4033
#[cfg(send_sync)]

wgpu/src/backend/wgpu_core.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,7 @@ fn map_texture_copy_view(
399399
}
400400
}
401401

402-
#[cfg_attr(
403-
any(not(target_arch = "wasm32"), target_os = "emscripten"),
404-
expect(unused)
405-
)]
402+
#[cfg_attr(not(webgl), expect(unused))]
406403
fn map_texture_tagged_copy_view(
407404
view: crate::CopyExternalImageDestInfo<&api::Texture>,
408405
) -> wgc::command::CopyExternalImageDestInfo {
@@ -1815,13 +1812,17 @@ impl dispatch::QueueInterface for CoreQueue {
18151812
}
18161813
}
18171814

1815+
// This method needs to exist if either webgpu or webgl is enabled,
1816+
// but we only actually have an implementation if webgl is enabled.
18181817
#[cfg(any(webgpu, webgl))]
1818+
#[cfg_attr(not(webgl), expect(unused_variables))]
18191819
fn copy_external_image_to_texture(
18201820
&self,
18211821
source: &crate::CopyExternalImageSourceInfo,
18221822
dest: crate::CopyExternalImageDestInfo<&crate::api::Texture>,
18231823
size: crate::Extent3d,
18241824
) {
1825+
#[cfg(webgl)]
18251826
match self.context.0.queue_copy_external_image_to_texture(
18261827
self.id,
18271828
source,

xtask/src/run_wasm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) fn run_wasm(shell: Shell, mut args: Arguments) -> anyhow::Result<()>
3232

3333
xshell::cmd!(
3434
shell,
35-
"cargo build --target wasm32-unknown-unknown --bin wgpu-examples --no-default-features --features webgpu {release_flag...}"
35+
"cargo build --target wasm32-unknown-unknown -p wgpu-examples --no-default-features --features webgpu {release_flag...}"
3636
)
3737
.args(&cargo_args)
3838
.quiet()
@@ -53,7 +53,7 @@ pub(crate) fn run_wasm(shell: Shell, mut args: Arguments) -> anyhow::Result<()>
5353

5454
xshell::cmd!(
5555
shell,
56-
"cargo build --target wasm32-unknown-unknown --bin wgpu-examples --no-default-features --features webgl {release_flag...}"
56+
"cargo build --target wasm32-unknown-unknown -p wgpu-examples --no-default-features --features webgl {release_flag...}"
5757
)
5858
.args(&cargo_args)
5959
.quiet()

0 commit comments

Comments
 (0)