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

Improved wgpu error handling, no more crashes through wgpu validation errors #4509

Merged
merged 14 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
113 changes: 96 additions & 17 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ blackbox = "0.2.0"
bytemuck = { version = "1.11", features = ["extern_crate_alloc"] }
camino = "1.1"
cargo-run-wasm = "0.3.2"
cfg_aliases = "0.1"
cfg-if = "1.0"
clap = "4.0"
clean-path = "0.2"
Expand Down
12 changes: 8 additions & 4 deletions crates/re_renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import-gltf = ["dep:gltf"]
serde = ["dep:serde"]

## Render using webgl instead of webgpu on wasm builds.
webgl = ["wgpu/webgl"]
webgl = ["wgpu/webgl", "dep:wgpu-core"]

[dependencies]
re_error.workspace = true
Expand All @@ -50,6 +50,7 @@ ahash.workspace = true
anyhow.workspace = true
bitflags.workspace = true
bytemuck.workspace = true
cfg-if.workspace = true
clean-path.workspace = true
document-features.workspace = true
ecolor = { workspace = true, features = ["bytemuck"] }
Expand All @@ -67,32 +68,35 @@ static_assertions.workspace = true
thiserror.workspace = true
type-map.workspace = true
wgpu.workspace = true
wgpu-core.workspace = true

# optional
arrow2 = { workspace = true, optional = true }
gltf = { workspace = true, optional = true }
serde = { version = "1", features = ["derive"], optional = true }
tobj = { version = "4.0", optional = true }
wgpu-core = { workspace = true, optional = true } # Needed for error handling when wgpu-core implemented backend is used.

# native
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
crossbeam.workspace = true
notify.workspace = true
wgpu-core.workspace = true

# For examples:
# webgpu
[target.'cfg(all(target_arch = "wasm32", not(features = "webgl")))'.dependencies]
wasm-bindgen-futures.workspace = true

[dev-dependencies]
unindent.workspace = true

# For build.rs:
[build-dependencies]

# Rerun
re_build_tools.workspace = true

# External
anyhow.workspace = true
cfg_aliases.workspace = true
clean-path.workspace = true
pathdiff.workspace = true
walkdir.workspace = true
17 changes: 17 additions & 0 deletions crates/re_renderer/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ fn should_run() -> bool {
}

fn main() {
// TODO(andreas): Create an upstream PR to fix this.
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
// Workaround for CARGO_CFG_DEBUG_ASSERTIONS not being set as expected.
// `cfg_aliases` relies on this.
if std::env::var("PROFILE") == Ok("debug".to_owned()) {
std::env::set_var("CARGO_CFG_DEBUG_ASSERTIONS", "1");
}

#[allow(clippy::str_to_string)] // TODO(andreas): Create an upstream PR to fix this.
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
{
cfg_aliases::cfg_aliases! {
native: { not(target_arch = "wasm32") },
webgl: { all(not(native), feature = "webgl") },
webgpu: { all(not(webgl), not(native)) },
load_shaders_from_disk: { all(native, debug_assertions) } // Shader reloading is only supported on native-debug currently.
}
}

if !should_run() {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions crates/re_renderer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ pub struct RenderContextConfig {
///
/// Other backend might work as well, but lack of support isn't regarded as a bug.
pub fn supported_backends() -> wgpu::Backends {
if cfg!(target_arch = "wasm32") {
// Web - WebGL is used automatically when wgpu is compiled with `webgl` feature.
wgpu::Backends::GL | wgpu::Backends::BROWSER_WEBGPU
} else {
if cfg!(native) {
// Native.
// Only use Vulkan & Metal unless explicitly told so since this reduces surfaces and thus surprises.
//
Expand All @@ -167,5 +164,8 @@ pub fn supported_backends() -> wgpu::Backends {
// For changing the backend we use standard wgpu env var, i.e. WGPU_BACKEND.
wgpu::util::backend_bits_from_env()
.unwrap_or(wgpu::Backends::VULKAN | wgpu::Backends::METAL)
} else {
// Web - WebGL is used automatically when wgpu is compiled with `webgl` feature.
wgpu::Backends::GL | wgpu::Backends::BROWSER_WEBGPU
}
}
Loading
Loading