Skip to content

Commit

Permalink
HACK(eddyb): avoid push constants on wasm/WebGPU.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Mar 23, 2023
1 parent 817ea36 commit abc31ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 12 additions & 5 deletions examples/runners/wgpu/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ async fn run(
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
bind_group_layouts: &[],
// HACK(eddyb) disabling push constants to test WebGPU.
#[cfg(target_arch = "wasm32")]
push_constant_ranges: &[],
#[cfg(not(target_arch = "wasm32"))]
push_constant_ranges: &[wgpu::PushConstantRange {
stages: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT,
range: 0..std::mem::size_of::<ShaderConstants>() as u32,
Expand Down Expand Up @@ -298,11 +302,14 @@ async fn run(
};

rpass.set_pipeline(render_pipeline);
rpass.set_push_constants(
wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT,
0,
bytemuck::bytes_of(&push_constants),
);
// HACK(eddyb) disabling push constants to test WebGPU.
if cfg!(not(target_arch = "wasm32")) {
rpass.set_push_constants(
wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT,
0,
bytemuck::bytes_of(&push_constants),
);
}
rpass.draw(0..3, 0..1);
}

Expand Down
7 changes: 6 additions & 1 deletion examples/runners/wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,18 @@ pub struct Options {
pub fn main(
#[cfg(target_os = "android")] android_app: winit::platform::android::activity::AndroidApp,
) {
let options: Options = Options::from_args();
let mut options: Options = Options::from_args();

#[cfg(not(any(target_os = "android", target_arch = "wasm32")))]
if options.shader == RustGPUShader::Compute {
return compute::start(&options);
}

// HACK(eddyb) forcing a shader w/o push constants to test WebGPU.
if cfg!(target_arch = "wasm32") {
options.shader = RustGPUShader::Simplest;
}

graphics::start(
#[cfg(target_os = "android")]
android_app,
Expand Down

0 comments on commit abc31ac

Please sign in to comment.