Skip to content

Commit 8cafb7f

Browse files
committed
support ray tracing pipeline stages
1 parent a402542 commit 8cafb7f

4 files changed

Lines changed: 111 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## unreleased
1010
### Added
11+
* Added support for ray tracing pipelines.
1112
* Added derive for Clone for generated bind group structs.
1213
* Added `inner` method for generated bind group structs for accessing the inner `wgpu::BindGroup`.
1314

‎wgsl_to_wgpu/src/data/entries_all_stages.wgsl‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
enable wgpu_mesh_shader;
2+
enable wgpu_ray_tracing_pipeline;
23

34
@group(0) @binding(0) var<uniform> a: f32;
45
@group(0) @binding(1) var<uniform> b: f32;
@@ -12,6 +13,10 @@ enable wgpu_mesh_shader;
1213
@group(0) @binding(9) var<uniform> j: u32;
1314
@group(0) @binding(10) var<uniform> k: u32;
1415
@group(0) @binding(11) var<uniform> l: f64;
16+
@group(0) @binding(12) var<uniform> m: u32;
17+
@group(0) @binding(13) var<uniform> n: u32;
18+
@group(0) @binding(14) var<uniform> o: u32;
19+
@group(0) @binding(15) var<uniform> p: u32;
1520

1621
fn inner() -> f32 {
1722
return d;
@@ -83,3 +88,33 @@ var<workgroup> mesh_output: MeshOutput;
8388
fn ms_main(@builtin(local_invocation_index) index: u32, @builtin(global_invocation_id) id: vec3<u32>) {
8489
mesh_output.vertex_count = index + i + k;
8590
}
91+
92+
struct HitCounters {
93+
hit_num: u32,
94+
selected_hit: u32,
95+
}
96+
97+
var<incoming_ray_payload> incoming_hit_num: HitCounters;
98+
99+
@ray_generation
100+
fn rg_main() {
101+
let x = i * m;
102+
}
103+
104+
@any_hit
105+
@incoming_payload(incoming_hit_num)
106+
fn ah_main() {
107+
let x = i * n;
108+
}
109+
110+
@closest_hit
111+
@incoming_payload(incoming_hit_num)
112+
fn ch_main() {
113+
let x = i * o;
114+
}
115+
116+
@miss
117+
@incoming_payload(incoming_hit_num)
118+
fn miss_main() {
119+
let x = i * p;
120+
}

‎wgsl_to_wgpu/src/snapshots/create_shader_multiple_entries.snap.rs‎

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pub mod bind_groups {
1515
pub j: wgpu::BufferBinding<'a>,
1616
pub k: wgpu::BufferBinding<'a>,
1717
pub l: wgpu::BufferBinding<'a>,
18+
pub m: wgpu::BufferBinding<'a>,
19+
pub n: wgpu::BufferBinding<'a>,
20+
pub o: wgpu::BufferBinding<'a>,
21+
pub p: wgpu::BufferBinding<'a>,
1822
}
1923
const LAYOUT_DESCRIPTOR0: wgpu::BindGroupLayoutDescriptor = wgpu::BindGroupLayoutDescriptor {
2024
label: Some("LayoutDescriptor0"),
@@ -106,11 +110,7 @@ pub mod bind_groups {
106110
},
107111
wgpu::BindGroupLayoutEntry {
108112
binding: 8,
109-
visibility: wgpu::ShaderStages::VERTEX
110-
.union(wgpu::ShaderStages::FRAGMENT)
111-
.union(wgpu::ShaderStages::COMPUTE)
112-
.union(wgpu::ShaderStages::TASK)
113-
.union(wgpu::ShaderStages::MESH),
113+
visibility: wgpu::ShaderStages::all(),
114114
ty: wgpu::BindingType::Buffer {
115115
ty: wgpu::BufferBindingType::Uniform,
116116
has_dynamic_offset: false,
@@ -148,6 +148,46 @@ pub mod bind_groups {
148148
},
149149
count: None,
150150
},
151+
wgpu::BindGroupLayoutEntry {
152+
binding: 12,
153+
visibility: wgpu::ShaderStages::NONE,
154+
ty: wgpu::BindingType::Buffer {
155+
ty: wgpu::BufferBindingType::Uniform,
156+
has_dynamic_offset: false,
157+
min_binding_size: None,
158+
},
159+
count: None,
160+
},
161+
wgpu::BindGroupLayoutEntry {
162+
binding: 13,
163+
visibility: wgpu::ShaderStages::NONE,
164+
ty: wgpu::BindingType::Buffer {
165+
ty: wgpu::BufferBindingType::Uniform,
166+
has_dynamic_offset: false,
167+
min_binding_size: None,
168+
},
169+
count: None,
170+
},
171+
wgpu::BindGroupLayoutEntry {
172+
binding: 14,
173+
visibility: wgpu::ShaderStages::NONE,
174+
ty: wgpu::BindingType::Buffer {
175+
ty: wgpu::BufferBindingType::Uniform,
176+
has_dynamic_offset: false,
177+
min_binding_size: None,
178+
},
179+
count: None,
180+
},
181+
wgpu::BindGroupLayoutEntry {
182+
binding: 15,
183+
visibility: wgpu::ShaderStages::NONE,
184+
ty: wgpu::BindingType::Buffer {
185+
ty: wgpu::BufferBindingType::Uniform,
186+
has_dynamic_offset: false,
187+
min_binding_size: None,
188+
},
189+
count: None,
190+
},
151191
],
152192
};
153193
impl BindGroup0 {
@@ -209,6 +249,22 @@ pub mod bind_groups {
209249
binding: 11,
210250
resource: wgpu::BindingResource::Buffer(bindings.l),
211251
},
252+
wgpu::BindGroupEntry {
253+
binding: 12,
254+
resource: wgpu::BindingResource::Buffer(bindings.m),
255+
},
256+
wgpu::BindGroupEntry {
257+
binding: 13,
258+
resource: wgpu::BindingResource::Buffer(bindings.n),
259+
},
260+
wgpu::BindGroupEntry {
261+
binding: 14,
262+
resource: wgpu::BindingResource::Buffer(bindings.o),
263+
},
264+
wgpu::BindGroupEntry {
265+
binding: 15,
266+
resource: wgpu::BindingResource::Buffer(bindings.p),
267+
},
212268
],
213269
label: Some("BindGroup0"),
214270
},
@@ -300,14 +356,24 @@ pub fn create_pipeline_layout(device: &wgpu::Device) -> wgpu::PipelineLayout {
300356
},
301357
)
302358
}
359+
pub const ENTRY_AH_MAIN: &str = "ah_main";
360+
pub const ENTRY_CH_MAIN: &str = "ch_main";
303361
pub const ENTRY_FS_MAIN: &str = "fs_main";
304362
pub const ENTRY_MAIN: &str = "main";
305363
pub const ENTRY_MAIN2: &str = "main2";
364+
pub const ENTRY_MISS_MAIN: &str = "miss_main";
306365
pub const ENTRY_MS_MAIN: &str = "ms_main";
366+
pub const ENTRY_RG_MAIN: &str = "rg_main";
307367
pub const ENTRY_TS_MAIN: &str = "ts_main";
308368
pub const ENTRY_VS_MAIN: &str = "vs_main";
309369
#[repr(C)]
310370
#[derive(Debug, Copy, Clone, PartialEq)]
371+
pub struct HitCounters {
372+
pub hit_num: u32,
373+
pub selected_hit: u32,
374+
}
375+
#[repr(C)]
376+
#[derive(Debug, Copy, Clone, PartialEq)]
311377
pub struct MeshOutput {}
312378
#[derive(Debug)]
313379
pub struct VertexEntry<const N: usize> {

‎wgsl_to_wgpu/src/wgsl.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ const fn naga_stages(stage: naga::ShaderStage) -> wgpu::ShaderStages {
2525
naga::ShaderStage::Compute => wgpu::ShaderStages::COMPUTE,
2626
naga::ShaderStage::Task => wgpu::ShaderStages::TASK,
2727
naga::ShaderStage::Mesh => wgpu::ShaderStages::MESH,
28-
naga::ShaderStage::RayGeneration => todo!(),
29-
naga::ShaderStage::Miss => todo!(),
30-
naga::ShaderStage::AnyHit => todo!(),
31-
naga::ShaderStage::ClosestHit => todo!(),
28+
naga::ShaderStage::RayGeneration => wgpu::ShaderStages::RAY_GENERATION,
29+
naga::ShaderStage::Miss => wgpu::ShaderStages::MISS,
30+
naga::ShaderStage::AnyHit => wgpu::ShaderStages::ANY_HIT,
31+
naga::ShaderStage::ClosestHit => wgpu::ShaderStages::CLOSEST_HIT,
3232
}
3333
}
3434

0 commit comments

Comments
 (0)