upgrade examples to wgpu 30#579
Conversation
25b2f53 to
1aac44e
Compare
eddyb
left a comment
There was a problem hiding this comment.
It's been long enough that wgpu 30 is already out, oops!
| // Describe the pipeline layout and build the initial pipeline. | ||
| let push_constants_or_rossbo_emulation = { | ||
| const PUSH_CONSTANTS_SIZE: usize = std::mem::size_of::<ShaderConstants>(); | ||
| let stages = wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT; | ||
|
|
||
| if !options.emulate_push_constants_with_storage_buffer { | ||
| Ok(wgpu::PushConstantRange { | ||
| stages, | ||
| range: 0..PUSH_CONSTANTS_SIZE as u32, | ||
| }) | ||
| } else { | ||
| let buffer = device.create_buffer(&wgpu::BufferDescriptor { | ||
| label: None, | ||
| size: PUSH_CONSTANTS_SIZE as u64, | ||
| usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST, | ||
| mapped_at_creation: false, | ||
| }); | ||
| let binding0 = wgpu::BindGroupLayoutEntry { | ||
| binding: 0, | ||
| visibility: stages, | ||
| ty: wgpu::BindingType::Buffer { | ||
| ty: wgpu::BufferBindingType::Storage { read_only: true }, | ||
| has_dynamic_offset: false, | ||
| min_binding_size: Some((PUSH_CONSTANTS_SIZE as u64).try_into().unwrap()), | ||
| }, | ||
| count: None, | ||
| }; | ||
| let bind_group_layout = | ||
| device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { | ||
| label: None, | ||
| entries: &[binding0], | ||
| }); | ||
| let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { | ||
| label: None, | ||
| layout: &bind_group_layout, | ||
| entries: &[wgpu::BindGroupEntry { | ||
| binding: 0, | ||
| resource: buffer.as_entire_binding(), | ||
| }], | ||
| }); | ||
| Err((buffer, bind_group_layout, bind_group)) | ||
| } | ||
| }; | ||
| let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { | ||
| label: None, | ||
| bind_group_layouts: push_constants_or_rossbo_emulation | ||
| .as_ref() | ||
| .err() | ||
| .map(|(_, layout, _)| layout) | ||
| .as_slice(), | ||
| push_constant_ranges: push_constants_or_rossbo_emulation | ||
| .as_ref() | ||
| .map_or(&[], slice::from_ref), | ||
| bind_group_layouts: &[], | ||
| immediate_size: size_of::<ShaderConstants>() as u32, | ||
| }); |
There was a problem hiding this comment.
I think you could've kept the emulation (which is needed for e.g. running on actual WebGPU via wasm - unless wgpu does its own emulation internally? if that's true, you can remove the emulate_push_constants_with_storage_buffer option entirely!).
As per #387, you should be able to test the wasm build (and its use of WebGPU) via:
rustup target add wasm32-unknown-unknown
cargo run-wasm -p example-runner-wgpu
(you may need Chrome w/ e.g. --enable-features=Vulkan --enable-unsafe-webgpu - not sure if Firefox has gotten around to enabling WebGPU at all, outside nightly)
The main difference seems to be (assuming this emulation needs to be kept, as per above) that instead of wgpu::PushConstantRange, immediate_size is just an u32, so the non-emulation case would just become Ok(PUSH_CONSTANTS_SIZE).
There was a problem hiding this comment.
Rereading the documentation:
/// Supported platforms:
/// - DX12
/// - Vulkan
/// - Metal
/// - OpenGL (emulated with uniforms)
/// - WebGPU
So I thought it's supported for every platform, but:
WebGPU support is currently a proposal and will be available in browsers in the future.
So I guess we'll keep our emulation...
|
Updated it all the way to wgpu30 without removing our push constant emulation. Moved the removal to branch |
No description provided.