Fix assorted issues with WebGL (#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
This commit is contained in:
Connor Fitzgerald 2025-03-31 22:02:21 -04:00 committed by GitHub
parent 02700ab162
commit a9279de793
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 17 additions and 21 deletions

View File

@ -68,7 +68,6 @@ wgpu = { version = "24.0.0", path = "./wgpu", default-features = false, features
"dx12",
"metal",
"static-dxc",
"webgl",
"noop", # This should be removed if we ever have non-test crates that depend on wgpu
] }
wgpu-core = { version = "24.0.0", path = "./wgpu-core" }

View File

@ -44,7 +44,6 @@ obj.workspace = true
png.workspace = true
pollster.workspace = true
web-time.workspace = true
wgpu.workspace = true
wgpu-types = { workspace = true, features = [
"trace", # TODO(#5974): this should be a dep on wgpu/trace and not wgpu-types at all
] }
@ -55,6 +54,7 @@ wgpu-test.workspace = true
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger.workspace = true
wgpu.workspace = true
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook.workspace = true
@ -62,6 +62,7 @@ console_log.workspace = true
fern.workspace = true
wasm-bindgen.workspace = true
wasm-bindgen-futures.workspace = true
wgpu = { path = "../../wgpu", default-features = false, features = ["wgsl"] }
# We need these features in the framework examples and tests
web-sys = { workspace = true, features = [
"Location",

View File

@ -27,10 +27,7 @@ pub fn is_valid_copy_dst_texture_format(
}
}
#[cfg_attr(
any(not(target_arch = "wasm32"), target_os = "emscripten"),
allow(unused)
)]
#[cfg_attr(any(not(webgl)), expect(unused))]
pub fn is_valid_external_image_copy_dst_texture_format(format: wgt::TextureFormat) -> bool {
use wgt::TextureFormat as Tf;
match format {

View File

@ -1880,6 +1880,11 @@ impl Global {
Ok(wgt::PollStatus::Poll) => {
unreachable!("Cannot get a Poll result from a Wait action.")
}
Err(WaitIdleError::Timeout) if cfg!(target_arch = "wasm32") => {
// On wasm, you cannot actually successfully wait for the surface.
// However WebGL does not actually require you do this, so ignoring
// the failure is totally fine. See https://github.com/gfx-rs/wgpu/issues/7363
}
Err(e) => {
break 'error e.into();
}

View File

@ -76,7 +76,7 @@ webgl = ["wgpu-core/webgl", "dep:wgpu-hal", "dep:smallvec"]
## but performs no computation.
## Because it lacks basic functionality, it is only actually used if explicitly enabled
## through `NoopBackendOptions`.
noop = ["wgpu-core/noop"]
noop = ["wgpu-core/noop", "dep:wgpu-hal", "dep:smallvec"]
#! **Note:** In the documentation, if you see that an item depends on a backend,
#! it means that the item is only available when that backend is enabled _and_ the backend

View File

@ -27,14 +27,7 @@ crate::cmp::impl_eq_ord_hash_proxy!(Queue => .inner);
/// There is no analogue in the WebGPU specification.
#[derive(Debug, Clone)]
pub struct SubmissionIndex {
#[cfg_attr(
all(
target_arch = "wasm32",
not(target_os = "emscripten"),
not(feature = "webgl"),
),
expect(dead_code)
)]
#[cfg_attr(not(wgpu_core), expect(dead_code))]
pub(crate) index: u64,
}
#[cfg(send_sync)]

View File

@ -399,10 +399,7 @@ fn map_texture_copy_view(
}
}
#[cfg_attr(
any(not(target_arch = "wasm32"), target_os = "emscripten"),
expect(unused)
)]
#[cfg_attr(not(webgl), expect(unused))]
fn map_texture_tagged_copy_view(
view: crate::CopyExternalImageDestInfo<&api::Texture>,
) -> wgc::command::CopyExternalImageDestInfo {
@ -1815,13 +1812,17 @@ impl dispatch::QueueInterface for CoreQueue {
}
}
// This method needs to exist if either webgpu or webgl is enabled,
// but we only actually have an implementation if webgl is enabled.
#[cfg(any(webgpu, webgl))]
#[cfg_attr(not(webgl), expect(unused_variables))]
fn copy_external_image_to_texture(
&self,
source: &crate::CopyExternalImageSourceInfo,
dest: crate::CopyExternalImageDestInfo<&crate::api::Texture>,
size: crate::Extent3d,
) {
#[cfg(webgl)]
match self.context.0.queue_copy_external_image_to_texture(
self.id,
source,

View File

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