Skip to content

upgrade examples to wgpu 29#579

Open
Firestar99 wants to merge 2 commits into
mainfrom
wgpu29
Open

upgrade examples to wgpu 29#579
Firestar99 wants to merge 2 commits into
mainfrom
wgpu29

Conversation

@Firestar99

@Firestar99 Firestar99 commented Apr 15, 2026

Copy link
Copy Markdown
Member

No description provided.

@Firestar99 Firestar99 marked this pull request as ready for review June 8, 2026 18:57
@Firestar99 Firestar99 requested review from LegNeato and eddyb as code owners June 8, 2026 18:57
@Firestar99 Firestar99 enabled auto-merge June 22, 2026 11:32

@eddyb eddyb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been long enough that wgpu 30 is already out, oops!

Comment on lines 133 to 138
// 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,
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants