Skip to content

Commit d9bb8aa

Browse files
committed
example-runner-wgpu: fix remaining issues, and default to mouse shader, for wasm/WebGPU.
1 parent 62307dc commit d9bb8aa

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

examples/runners/wgpu/src/graphics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ async fn run(
8888
window: Window,
8989
compiled_shader_modules: CompiledShaderModules,
9090
) {
91-
let backends =
92-
wgpu::Backends::from_env().unwrap_or(wgpu::Backends::VULKAN | wgpu::Backends::METAL);
91+
// FIXME(eddyb) should this just use `wgpu::Backends::PRIMARY`?
92+
// (that also enables the DirectX 12 backend, not sure we want that one?)
93+
let backends = wgpu::Backends::from_env()
94+
.unwrap_or(wgpu::Backends::VULKAN | wgpu::Backends::METAL | wgpu::Backends::BROWSER_WEBGPU);
9395
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
9496
backends,
9597
..Default::default()

examples/runners/wgpu/src/lib.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ fn maybe_watch(
216216
#[command()]
217217
pub struct Options {
218218
/// which shader to run
219-
#[arg(short, long, default_value = "sky")]
219+
#[cfg_attr(not(target_arch = "wasm32"), arg(short, long, default_value = "sky"))]
220+
#[cfg_attr(target_arch = "wasm32", arg(short, long, default_value = "mouse"))]
220221
shader: RustGPUShader,
221222

222223
#[arg(long)]
@@ -230,22 +231,24 @@ pub struct Options {
230231
pub fn main(
231232
#[cfg(target_os = "android")] android_app: winit::platform::android::activity::AndroidApp,
232233
) {
233-
// Hack: spirv_builder builds into a custom directory if running under cargo, to not
234-
// deadlock, and the default target directory if not. However, packages like `proc-macro2`
235-
// have different configurations when being built here vs. when building
236-
// rustc_codegen_spirv normally, so we *want* to build into a separate target directory, to
237-
// not have to rebuild half the crate graph every time we run. So, pretend we're running
238-
// under cargo by setting these environment variables.
239-
unsafe {
240-
std::env::set_var("OUT_DIR", env!("OUT_DIR"));
241-
std::env::set_var("PROFILE", env!("PROFILE"));
242-
}
243-
244234
let mut options = Options::parse();
245235

246236
#[cfg(not(any(target_os = "android", target_arch = "wasm32")))]
247-
if options.shader == RustGPUShader::Compute {
248-
return compute::start(&options);
237+
{
238+
// Hack: spirv_builder builds into a custom directory if running under cargo, to not
239+
// deadlock, and the default target directory if not. However, packages like `proc-macro2`
240+
// have different configurations when being built here vs. when building
241+
// rustc_codegen_spirv normally, so we *want* to build into a separate target directory, to
242+
// not have to rebuild half the crate graph every time we run. So, pretend we're running
243+
// under cargo by setting these environment variables.
244+
unsafe {
245+
std::env::set_var("OUT_DIR", env!("OUT_DIR"));
246+
std::env::set_var("PROFILE", env!("PROFILE"));
247+
}
248+
249+
if options.shader == RustGPUShader::Compute {
250+
return compute::start(&options);
251+
}
249252
}
250253

251254
// HACK(eddyb) force push constant emulation using (read-only) SSBOs, on

0 commit comments

Comments
 (0)