diff --git a/examples/runners/wgpu/src/graphics.rs b/examples/runners/wgpu/src/graphics.rs index 685c96cf58..60078534ea 100644 --- a/examples/runners/wgpu/src/graphics.rs +++ b/examples/runners/wgpu/src/graphics.rs @@ -170,6 +170,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::() as u32, @@ -305,11 +309,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); } diff --git a/examples/shaders/sky-shader/src/lib.rs b/examples/shaders/sky-shader/src/lib.rs index 4bebaf38f3..2dd8eb1463 100644 --- a/examples/shaders/sky-shader/src/lib.rs +++ b/examples/shaders/sky-shader/src/lib.rs @@ -130,10 +130,8 @@ fn get_ray_dir(uv: Vec2, pos: Vec3, look_at_pos: Vec3) -> Vec3 { (forward + uv.x * right + uv.y * up).normalize() } -pub fn fs(constants: &ShaderConstants, frag_coord: Vec2) -> Vec4 { - let mut uv = (frag_coord - 0.5 * vec2(constants.width as f32, constants.height as f32)) - / constants.height as f32; - uv.y = -uv.y; +pub fn fs(uv: Vec2) -> Vec4 { + let uv = uv - 0.5; // hard-code information because we can't bind buffers at the moment let eye_pos = vec3(0.0, 0.0997, 0.2); @@ -150,23 +148,23 @@ pub fn fs(constants: &ShaderConstants, frag_coord: Vec2) -> Vec4 { } #[spirv(fragment)] -pub fn main_fs( - #[spirv(frag_coord)] in_frag_coord: Vec4, - #[spirv(push_constant)] constants: &ShaderConstants, - output: &mut Vec4, -) { - let frag_coord = vec2(in_frag_coord.x, in_frag_coord.y); - *output = fs(constants, frag_coord); +pub fn main_fs(uv: Vec2, output: &mut Vec4) { + *output = fs(uv); } #[spirv(vertex)] -pub fn main_vs(#[spirv(vertex_index)] vert_idx: i32, #[spirv(position)] builtin_pos: &mut Vec4) { +pub fn main_vs( + #[spirv(vertex_index)] vert_idx: i32, + #[spirv(position)] builtin_pos: &mut Vec4, + out_uv: &mut Vec2, +) { // Create a "full screen triangle" by mapping the vertex index. // ported from https://www.saschawillems.de/blog/2016/08/13/vulkan-tutorial-on-rendering-a-fullscreen-quad-without-buffers/ let uv = vec2(((vert_idx << 1) & 2) as f32, (vert_idx & 2) as f32); let pos = 2.0 * uv - Vec2::ONE; *builtin_pos = pos.extend(0.0).extend(1.0); + *out_uv = uv; } #[cfg(test)]