Skip to content

Commit 54c5e4e

Browse files
authored
Merge branch 'trunk' into jj-push-qtxq
2 parents de48476 + 0ca8ba0 commit 54c5e4e

File tree

31 files changed

+605
-49
lines changed

31 files changed

+605
-49
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ Bottom level categories:
4848

4949
- Added opt-in "limit bucketing" functionality which can adjust adapter limits and features to match one of several pre-defined buckets. By @andyleiserson in [#9119](https://github.com/gfx-rs/wgpu/pull/9119).
5050

51+
### Changes
52+
53+
#### General
54+
55+
- `Features::CLIP_DISTANCE`, `naga::Capabilities::CLIP_DISTANCE`, and `naga::BuiltIn::ClipDistance` have been renamed to `CLIP_DISTANCES` and `ClipDistances` (viz., pluralized) as appropriate, to match the WebGPU spec. By @ErichDonGubler in [#9267](https://github.com/gfx-rs/wgpu/pull/9267).
56+
57+
#### Validation
58+
59+
- Add clip distances validation for `maxInterStageShaderVariables`. By @ErichDonGubler in [8762](https://github.com/gfx-rs/wgpu/pull/8762). This may break some existing programs, but it compiles with the WebGPU spec.
60+
5161
### Bug Fixes
5262

5363
#### General

cts_runner/test.lst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ webgpu:api,operation,vertex_state,correctness:setVertexBuffer_offset_and_attribu
5656

5757
webgpu:api,validation,buffer,create:*
5858
webgpu:api,validation,buffer,destroy:*
59+
webgpu:api,validation,capability_checks,features,clip_distances:*
5960
webgpu:api,validation,capability_checks,limits,maxBindGroups:setBindGroup,*
6061
webgpu:api,validation,capability_checks,limits,maxBindingsPerBindGroup:validate,*
6162
webgpu:api,validation,capability_checks,limits,maxBufferSize:*
@@ -343,8 +344,8 @@ fails-if(dx12,vulkan) webgpu:shader,execution,shader_io,fragment_builtins:inputs
343344
webgpu:shader,execution,shader_io,fragment_builtins:primitive_index,*
344345
webgpu:shader,execution,shader_io,fragment_builtins:subgroup_invocation_id:*
345346
webgpu:shader,execution,shader_io,fragment_builtins:subgroup_size:*
347+
webgpu:shader,execution,shader_io,vertex_builtins:outputs,clip_distances:*
346348
webgpu:shader,execution,statement,compound:*
347-
348349
webgpu:shader,validation,const_assert,const_assert:*
349350
webgpu:shader,validation,decl,assignment_statement:*
350351
webgpu:shader,validation,decl,compound_statement:*

docs/release-checklist.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ Day of Release:
3333
- Ensure `glow` and `rspirv` are updated to the latest version if needed.
3434
- Add a new header for the changelog with the release version and date.
3535
- Create a PR with all of the version changes and changelog updates.
36-
- Once the PR is CI clean, (force) merge it.
36+
- While waiting on the PR, do a dry run of publishing.
37+
```bash
38+
cargo publish --dry-run --workspace --all-features --exclude deno_webgpu
39+
```
40+
- Once the PR is CI clean and publish worked, (force) merge it.
3741
- Checkout `trunk` with the merged PR.
3842
- Publish! These commands can be pasted directly into your terminal in a single command, and they will publish everything.
3943
```bash
40-
cargo publish --workspace --exclude deno_webgpu
44+
cargo publish --workspace --all-features --exclude deno_webgpu
4145
```
4246
- If there were any newly published crates, ensure `github:gfx-rs/wgpu` is added as an owner of that crate.
4347
- Create a new tag called `vX.Y.Z` and push it to the repo.

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ These examples use a common framework to handle wgpu init, window creation, and
4040
- `shadow` - Likely by far the most complex example (certainly the largest in lines of code) of the official wgpu examples. `shadow` demonstrates basic scene rendering with the main attraction being lighting and shadows (as the name implies). It is recommended that any user looking into lighting be very familiar with the basic concepts of not only rendering with wgpu but also the primary mathematical ideas of computer graphics.
4141
- `multiple-render-targets` - Demonstrates how to render to two texture targets simultaneously from fragment shader.
4242
- `render_to_texture` - Renders to an image texture offscreen, demonstrating both off-screen rendering as well as how to add a sort of resolution-agnostic screenshot feature to an engine. This example either outputs an image file of your naming (pass command line arguments after specifying a `--` like `cargo run --bin wgpu-examples -- render_to_texture "test.png"`) or adds an `img` element containing the image to the page in WASM.
43+
- `render_with_compute` - Renders an image using compute shaders.
4344
- `ray_cube_fragment` - Demonstrates using ray queries with a fragment shader.
4445
- `ray_scene` - Demonstrates using ray queries and model loading
4546
- `ray_shadows` - Demonstrates a simple use of ray queries - high quality shadows - uses a light set with immediates to raytrace through an untransformed scene and detect whether there is something obstructing the light.

examples/features/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub mod ray_scene;
2626
pub mod ray_shadows;
2727
pub mod ray_traced_triangle;
2828
pub mod render_to_texture;
29+
pub mod render_with_compute;
2930
pub mod repeated_compute;
3031
pub mod shadow;
3132
pub mod skybox;

examples/features/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ const EXAMPLES: &[ExampleDesc] = &[
9292
webgl: false, // No canvas for WebGL
9393
webgpu: true,
9494
},
95+
ExampleDesc {
96+
name: "render_with_compute",
97+
function: wgpu_examples::render_with_compute::main,
98+
webgl: false,
99+
webgpu: true,
100+
},
95101
ExampleDesc {
96102
name: "repeated_compute",
97103
function: wgpu_examples::repeated_compute::main,
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
//! This renders to the screen with compute shaders. Note that due to limitations in Firefox,
2+
//! the wait will cause FPS to be capped at 10 when running on webgpu on Firefox. It is
3+
//! therefore not recommended to use this code, at least until
4+
//! <https://bugzilla.mozilla.org/show_bug.cgi?id=1870699> (and possibly further work) is resolved.
5+
6+
use std::time::Instant;
7+
8+
#[derive(bytemuck::Pod, bytemuck::Zeroable, Clone, Copy, Debug)]
9+
#[repr(C)]
10+
#[repr(align(16))]
11+
struct GlobalParams {
12+
time: f32,
13+
frame: f32,
14+
_padding: [u8; 8],
15+
}
16+
17+
pub struct Example {
18+
pipeline: wgpu::ComputePipeline,
19+
texture_view: wgpu::TextureView,
20+
global_params: wgpu::Buffer,
21+
bg: wgpu::BindGroup,
22+
bgl: wgpu::BindGroupLayout,
23+
blitter: wgpu::util::TextureBlitter,
24+
frame_count: u32,
25+
start_time: Option<Instant>,
26+
}
27+
impl crate::framework::Example for Example {
28+
fn init(
29+
config: &wgpu::SurfaceConfiguration,
30+
_adapter: &wgpu::Adapter,
31+
device: &wgpu::Device,
32+
_queue: &wgpu::Queue,
33+
) -> Self {
34+
let sm = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));
35+
let bgl = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
36+
label: None,
37+
entries: &[
38+
wgpu::BindGroupLayoutEntry {
39+
binding: 0,
40+
visibility: wgpu::ShaderStages::COMPUTE,
41+
ty: wgpu::BindingType::Buffer {
42+
ty: wgpu::BufferBindingType::Uniform,
43+
has_dynamic_offset: false,
44+
min_binding_size: None,
45+
},
46+
count: None,
47+
},
48+
wgpu::BindGroupLayoutEntry {
49+
binding: 1,
50+
visibility: wgpu::ShaderStages::COMPUTE,
51+
ty: wgpu::BindingType::StorageTexture {
52+
access: wgpu::StorageTextureAccess::WriteOnly,
53+
format: wgpu::TextureFormat::Rgba8Unorm,
54+
view_dimension: wgpu::TextureViewDimension::D2,
55+
},
56+
count: None,
57+
},
58+
],
59+
});
60+
let ppl = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
61+
label: None,
62+
bind_group_layouts: &[Some(&bgl)],
63+
immediate_size: 0,
64+
});
65+
let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
66+
label: None,
67+
layout: Some(&ppl),
68+
module: &sm,
69+
entry_point: None,
70+
compilation_options: Default::default(),
71+
cache: None,
72+
});
73+
let blitter = wgpu::util::TextureBlitter::new(device, config.format);
74+
let global_params = device.create_buffer(&wgpu::BufferDescriptor {
75+
label: None,
76+
size: size_of::<GlobalParams>() as u64,
77+
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
78+
mapped_at_creation: false,
79+
});
80+
81+
let (texture_view, bg) =
82+
create_tv_and_bg(device, &bgl, &global_params, config.width, config.height);
83+
Self {
84+
pipeline,
85+
texture_view,
86+
global_params,
87+
bg,
88+
bgl,
89+
blitter,
90+
frame_count: 0,
91+
start_time: None,
92+
}
93+
}
94+
95+
fn required_limits() -> wgpu::Limits {
96+
wgpu::Limits {
97+
max_storage_textures_per_shader_stage: 1,
98+
..Default::default()
99+
}
100+
}
101+
102+
fn resize(
103+
&mut self,
104+
config: &wgpu::SurfaceConfiguration,
105+
device: &wgpu::Device,
106+
_queue: &wgpu::Queue,
107+
) {
108+
let (texture_view, bg) = create_tv_and_bg(
109+
device,
110+
&self.bgl,
111+
&self.global_params,
112+
config.width,
113+
config.height,
114+
);
115+
self.bg = bg;
116+
self.texture_view = texture_view;
117+
}
118+
119+
fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) {
120+
let now = Instant::now();
121+
let start = *self.start_time.get_or_insert(now);
122+
let time_since_start = (now - start).as_secs_f32();
123+
queue.write_buffer(
124+
&self.global_params,
125+
0,
126+
bytemuck::bytes_of(&GlobalParams {
127+
time: time_since_start,
128+
frame: self.frame_count as f32,
129+
_padding: [0; 8],
130+
}),
131+
);
132+
let mut encoder = device.create_command_encoder(&Default::default());
133+
134+
{
135+
let mut pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
136+
label: None,
137+
timestamp_writes: None,
138+
});
139+
pass.set_pipeline(&self.pipeline);
140+
pass.set_bind_group(0, &self.bg, &[]);
141+
const SHADER_WORKGROUP_DIM: u32 = 16;
142+
pass.dispatch_workgroups(
143+
self.texture_view
144+
.texture()
145+
.width()
146+
.div_ceil(SHADER_WORKGROUP_DIM),
147+
self.texture_view
148+
.texture()
149+
.height()
150+
.div_ceil(SHADER_WORKGROUP_DIM),
151+
1,
152+
);
153+
}
154+
self.blitter
155+
.copy(device, &mut encoder, &self.texture_view, view);
156+
157+
queue.submit([encoder.finish()]);
158+
device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
159+
160+
self.frame_count += 1;
161+
}
162+
163+
fn update(&mut self, _event: winit::event::WindowEvent) {}
164+
}
165+
166+
fn create_tv_and_bg(
167+
device: &wgpu::Device,
168+
bgl: &wgpu::BindGroupLayout,
169+
global_params: &wgpu::Buffer,
170+
width: u32,
171+
height: u32,
172+
) -> (wgpu::TextureView, wgpu::BindGroup) {
173+
let texture = device.create_texture(&wgpu::TextureDescriptor {
174+
label: None,
175+
size: wgpu::Extent3d {
176+
width,
177+
height,
178+
depth_or_array_layers: 1,
179+
},
180+
mip_level_count: 1,
181+
sample_count: 1,
182+
dimension: wgpu::TextureDimension::D2,
183+
format: wgpu::TextureFormat::Rgba8Unorm,
184+
usage: wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::TEXTURE_BINDING,
185+
view_formats: &[],
186+
});
187+
let view = texture.create_view(&Default::default());
188+
let bg = device.create_bind_group(&wgpu::BindGroupDescriptor {
189+
label: None,
190+
layout: bgl,
191+
entries: &[
192+
wgpu::BindGroupEntry {
193+
binding: 0,
194+
resource: wgpu::BindingResource::Buffer(global_params.as_entire_buffer_binding()),
195+
},
196+
wgpu::BindGroupEntry {
197+
binding: 1,
198+
resource: wgpu::BindingResource::TextureView(&view),
199+
},
200+
],
201+
});
202+
(view, bg)
203+
}
204+
205+
pub fn main() {
206+
crate::framework::run::<Example>("render-with-compute");
207+
}

0 commit comments

Comments
 (0)