Skip to content

Commit 79a6f2c

Browse files
Vecvecdaniel-keitelJMS55atlv24cwfitzgerald
authored
Ray Queries (#6291)
* fix more compile errors * fix err * fix all compile errors * fix clippy errors * fix issues in ray-traced-triangle example * fix clippy warnings * fix wasm not compiling * fix test * fix clippy (again) * fix some rustfmt issues * fix more rustfmt issues * fix even more rustfmt issues * fix yet more rustfmt issues * add #[allow(dead_code)] to some structs to fix clippy on web assembly * more format fixes * even more format fixes * close to final format fixes * final format fixes (hopefully) * actual final format fixes (hopefully) * move ray_cube_cube example and fix bugs * move other examples * fix crash when dropping * fix test * apply clippy and rustfmt changes * fix some memory leaks * fix incompatibility with new wgpu trunk changes * fix clippy & fmt * fix clippy errors on github * update to trunk * remove a line that printed log "Created blas ..." in device create tlas * fix merge issues * fix merge * fix fmt * restored example ray scene functionality * WIP fix rebase * Fix compile issues * More fixes * Fix rebase * Add wgls backend write_value_type AccelerationStructure * Add back xtask Cargo.lock * Revert serde path * Doc typos * Add -diff * Revert more serde * Revert serde again? * Fix doc typo * add test * clippy & fmt * fix error "blas does not exist" * fix various things * fix unused acceleration structures causing invalid SPIR-V * fix merge * fix use after free in a different way (now moved tlas instances to wgpu_core) * refactor & fmt * remove accidentally created file * remove accidentally created file (actually) * merge & fix * Fix problems * fix validation error * fix validation * fix merge * fmt * fix merge * use staging buffer trackers in creating the ray-tracing staging buffers (not the tlas_s) * change one missed staging buffer's tracker * wip: example * finished shadow! * fix merge * clippy * remove some uses of blas ids * fmt * fix merge * deduplicate code shared between command_encoder_build_acceleration_structures and command_encoder_build_acceleration_structures_unsafe_tlas * clippy * fix merge * fix warnings * clippy & fmt * re-add matching to get_raw_tlas_instance_size and tlas_instance_into_bytes * fmt * fix command * wip: fix merge * fix merge * fmt & docs * fix wasm clippy * fix issues with tests * fix issues with tests * fmt & clippy (wasm) * wip ray-traced-triangle (non hal) * unify camera location in ray_shadows * fix tests * add readme to ray_traced_triangle * note that vertex format must be f32x3 (not yet validated) * changelog * require VertexFormat::Float32x3 * fix compile error * when creating and building acceleration structures require Features::RAY_TRACING_ACCELERATION_STRUCTURE is enabled * remove duplicate workaround * fix most feedback * remove all changes from .gitattributes * fix compile error in test * more changes along same lines * format * apply feedback to more places * fix `cargo clippy` not just `cargo clippy --all-features` * cache max instances from tlas creation * fix clippy * fix examples * fix tests * remove now useless docs * add more docs * yet more docs * still more docs * Documentation. * Running out of unique commit messages to say writing docs. * Add more references to docs. * Get BindGroup in scope * Remove unintentional changes * Remove #[allow(dead_code)] * Remove old comments * Add device.poll * make ray_scene start right way up * fmt * move scratch buffer to its own module * actually remove intentional changes (turns out wgt is inconsistent) * use better names in ray_scene/shader.wgsl * fmt * remove more unintentional changes. * work on ray_tracing use after free * spelling Co-authored-by: Connor Fitzgerald <[email protected]> * grammar Co-authored-by: Connor Fitzgerald <[email protected]> * move things into struct (should be all vectors with 3 item types or more) * remove long-standing locks. * fmt * move not using index buffer to test * impl index & index mut for tlas package * impl index & index mut for tlas package * fix errors * fix test errors * move everything out of ray_tracing.rs * more index_mut * fmt * fix docs links * move to separate impl block * fix older request review * fmt * remove missed deref * fix wasm clippy * change to suggestions * fmt * add a note as to why `command_encoder_build_acceleration_structures_unsafe_tlas` and `command_encoder_build_acceleration_structures` are currently separate * add a todo to reconsider soon `command_encoder_build_acceleration_structures_unsafe_tlas` * switch to mat4 in ray-tracing examples * Combine RT Tests Under Single Submodule * Add More Raytracing Tests and Re-Organize * Documentation and Formatting Fixes * Remove Forced Alignment in wgpu-hal * work on out_of_order_as_build and add out_of_order_as_build_use * fmt * update test label naming * fix one validation error * fix clippy & fmt * add acceleration structure creation tests * make mis-matched index test use the correct function * move validation into validate_command_buffer * fix tests * add blas and tlas to pending writes to remove (now unneeded) `device.poll()`s * remove commented out code from examples and properly use the constants in ray_shadow * add examples to examples\README.md * rename ray tracing to ray queries in readme * remove unneeded usage from scratch buffer creation * use snatchables for raw acceleration structures * format * add EXPERIMENTAL_ to features * fix missed comment --------- Co-authored-by: Daniel Keitel <[email protected]> Co-authored-by: JMS55 <[email protected]> Co-authored-by: atlas dostal <[email protected]> Co-authored-by: vero <[email protected]> Co-authored-by: Connor Fitzgerald <[email protected]>
1 parent 01973a9 commit 79a6f2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+10364
-81
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ By @MarijnS95 in [#6006](https://github.com/gfx-rs/wgpu/pull/6006).
200200

201201
### New Features
202202

203+
#### Wgpu
204+
205+
- Added initial acceleration structure and ray query support into wgpu. By @expenses @daniel-keitel @Vecvec @JMS55 @atlv24 in [#6291](https://github.com/gfx-rs/wgpu/pull/6291)
206+
203207
#### Naga
204208

205209
- Support constant evaluation for `firstLeadingBit` and `firstTrailingBit` numeric built-ins in WGSL. Front-ends that translate to these built-ins also benefit from constant evaluation. By @ErichDonGubler in [#5101](https://github.com/gfx-rs/wgpu/pull/5101).

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ cfg-if.workspace = true
3434
encase = { workspace = true, features = ["glam"] }
3535
flume.workspace = true
3636
getrandom.workspace = true
37-
glam.workspace = true
37+
glam = { workspace = true, features = ["bytemuck"] }
3838
ktx2.workspace = true
3939
log.workspace = true
4040
nanorand.workspace = true

examples/README.md

Lines changed: 45 additions & 39 deletions
Large diffs are not rendered by default.

examples/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ pub mod hello_windows;
1515
pub mod hello_workgroups;
1616
pub mod mipmap;
1717
pub mod msaa_line;
18+
pub mod ray_cube_compute;
19+
pub mod ray_cube_fragment;
20+
pub mod ray_scene;
21+
pub mod ray_shadows;
22+
pub mod ray_traced_triangle;
1823
pub mod render_to_texture;
1924
pub mod repeated_compute;
2025
pub mod shadow;

examples/src/main.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,36 @@ const EXAMPLES: &[ExampleDesc] = &[
146146
webgl: false, // No RODS
147147
webgpu: true,
148148
},
149+
ExampleDesc {
150+
name: "ray_cube_compute",
151+
function: wgpu_examples::ray_cube_compute::main,
152+
webgl: false, // No Ray-tracing extensions
153+
webgpu: false, // No Ray-tracing extensions (yet)
154+
},
155+
ExampleDesc {
156+
name: "ray_cube_fragment",
157+
function: wgpu_examples::ray_cube_fragment::main,
158+
webgl: false, // No Ray-tracing extensions
159+
webgpu: false, // No Ray-tracing extensions (yet)
160+
},
161+
ExampleDesc {
162+
name: "ray_scene",
163+
function: wgpu_examples::ray_scene::main,
164+
webgl: false, // No Ray-tracing extensions
165+
webgpu: false, // No Ray-tracing extensions (yet)
166+
},
167+
ExampleDesc {
168+
name: "ray_shadows",
169+
function: wgpu_examples::ray_shadows::main,
170+
webgl: false, // No Ray-tracing extensions
171+
webgpu: false, // No Ray-tracing extensions (yet)
172+
},
173+
ExampleDesc {
174+
name: "ray_traced_triangle",
175+
function: wgpu_examples::ray_traced_triangle::main,
176+
webgl: false,
177+
webgpu: false,
178+
},
149179
];
150180

151181
fn get_example_name() -> Option<String> {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ray-cube
2+
3+
This example renders a ray traced cube with hardware acceleration.
4+
A separate compute shader is used to perform the ray queries.
5+
6+
## To Run
7+
8+
```
9+
cargo run --bin wgpu-examples ray_cube_compute
10+
```
11+
12+
## Screenshots
13+
14+
![Cube example](screenshot.png)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
struct VertexOutput {
2+
@builtin(position) position: vec4<f32>,
3+
@location(0) tex_coords: vec2<f32>,
4+
};
5+
6+
// meant to be called with 3 vertex indices: 0, 1, 2
7+
// draws one large triangle over the clip space like this:
8+
// (the asterisks represent the clip space bounds)
9+
//-1,1 1,1
10+
// ---------------------------------
11+
// | * .
12+
// | * .
13+
// | * .
14+
// | * .
15+
// | * .
16+
// | * .
17+
// |***************
18+
// | . 1,-1
19+
// | .
20+
// | .
21+
// | .
22+
// | .
23+
// |.
24+
@vertex
25+
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
26+
var result: VertexOutput;
27+
let x = i32(vertex_index) / 2;
28+
let y = i32(vertex_index) & 1;
29+
let tc = vec2<f32>(
30+
f32(x) * 2.0,
31+
f32(y) * 2.0
32+
);
33+
result.position = vec4<f32>(
34+
tc.x * 2.0 - 1.0,
35+
1.0 - tc.y * 2.0,
36+
0.0, 1.0
37+
);
38+
result.tex_coords = tc;
39+
return result;
40+
}
41+
42+
@group(0)
43+
@binding(0)
44+
var r_color: texture_2d<f32>;
45+
@group(0)
46+
@binding(1)
47+
var r_sampler: sampler;
48+
49+
@fragment
50+
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
51+
return textureSample(r_color, r_sampler, vertex.tex_coords);
52+
}

0 commit comments

Comments
 (0)