Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wgpu-core] Inline RayQuery Support #3631

Closed
wants to merge 187 commits into from
Closed
Show file tree
Hide file tree
Changes from 179 commits
Commits
Show all changes
187 commits
Select commit Hold shift + click to select a range
cd16e71
Initial commit
expenses Sep 3, 2022
ae4dcfe
Woo! building an AS works
expenses Sep 11, 2022
98cf75b
Fix alignment for amdpro driver
expenses Sep 11, 2022
6655d23
Ray tracing works in shaders!
expenses Sep 12, 2022
3be84cb
Merge remote-tracking branch 'origin/master' into hal-acceleration-st…
expenses Sep 12, 2022
2cc4385
Major clean up, allow for acceleration structure updates
expenses Sep 15, 2022
cd7c807
Fix trait implementaiton on gles
expenses Sep 15, 2022
4ef32a4
Put larger function call param lists into descriptors for easier dumm…
expenses Sep 15, 2022
8318b5f
Fix wasm build
expenses Sep 15, 2022
fecb538
Shuffle some code around, add a dummy implementation for DX12 with so…
expenses Sep 15, 2022
7905dc5
Add dummy implementation for metal
expenses Sep 16, 2022
e786743
Merge remote-tracking branch 'origin/master' into hal-acceleration-st…
expenses Sep 18, 2022
6f2b07a
Fix example, hopefully have fixed metal code
expenses Sep 18, 2022
9aca7f2
Merge branch 'hal-acceleration-structures' of github.com:expenses/wgp…
expenses Sep 18, 2022
3828af7
Changed surface_format in example.
daniel-keitel Feb 3, 2023
e2de5a3
Changed based on PR 3020#pullrequestreview-1139691697 feedback.
daniel-keitel Feb 3, 2023
112b549
Merge remote-tracking branch 'origin/master' into hal-acceleration-st…
daniel-keitel Feb 21, 2023
074ebe5
unsafe blocks in unsafe functions
daniel-keitel Feb 21, 2023
8ce204b
formatted code
daniel-keitel Feb 21, 2023
f52a70b
added utility functions to AccelerationStructureInstance (bit packing)
daniel-keitel Feb 22, 2023
f15e865
WIP api change build_acceleration_structures
daniel-keitel Feb 27, 2023
a3c0ffb
preperation for changes in get_acceleration_structure_build_sizes
daniel-keitel Feb 28, 2023
a59d888
WIP api change get_acceleration_structure_build_sizes
daniel-keitel Feb 28, 2023
93a347d
added aabbs and geometry flag support
daniel-keitel Mar 1, 2023
16cc4eb
fixed RAY_TRACING feature collision
daniel-keitel Mar 1, 2023
5b84238
renamed to build_acceleration_structure
daniel-keitel Mar 1, 2023
caa4ae7
fixed missing type parameter for metal
daniel-keitel Mar 1, 2023
ca3a54c
Merge remote-tracking branch 'origin/master' into hal-acceleration-st…
daniel-keitel Mar 1, 2023
ca03f34
Merge remote-tracking branch 'origin/master' into hal-acceleration-st…
daniel-keitel Mar 16, 2023
bee8a36
multiple AS builds at once
daniel-keitel Mar 19, 2023
a420b87
switched to using smallvec
daniel-keitel Mar 19, 2023
e48f7bd
small api change + documentation
daniel-keitel Mar 19, 2023
c1dc803
added to changelog
daniel-keitel Mar 19, 2023
9c67400
typo
daniel-keitel Mar 20, 2023
c91ce76
Merge remote-tracking branch 'origin/master' into hal-acceleration-st…
daniel-keitel Mar 27, 2023
c931edf
create_blas create_tlas
daniel-keitel Mar 27, 2023
e3a7fc9
example skeleton
daniel-keitel Mar 27, 2023
e932040
WIP
daniel-keitel Mar 27, 2023
f5e94e7
moved flags to wgt
daniel-keitel Mar 27, 2023
0b7e728
renamed feature RAY_TRACING to RAY_TRACING_ACCELERATION_STRUCTURE
daniel-keitel Mar 27, 2023
c078ab0
Merge branch 'hal-acceleration-structures' into ray-tracing + small fix
daniel-keitel Mar 27, 2023
079054e
WIP build blas/tlas
daniel-keitel Mar 28, 2023
cfc7e3d
WIP blas build
daniel-keitel Mar 29, 2023
ffe0b41
WIP blas build should work
daniel-keitel Mar 29, 2023
e8daf51
blas handle
daniel-keitel Mar 29, 2023
f06de72
WIP tlas build should work
daniel-keitel Mar 29, 2023
fd77e7d
"working" example
daniel-keitel Mar 30, 2023
fae31f0
WIP better iterators
daniel-keitel Mar 30, 2023
07dae89
iterators as inputs
daniel-keitel Mar 30, 2023
e8ae541
Merge branch 'hal-acceleration-structures' into ray-tracing
daniel-keitel Mar 30, 2023
d576029
compiles again
daniel-keitel Mar 30, 2023
b29d21b
improved iterators
daniel-keitel Mar 30, 2023
0b12bf3
some cleanup
daniel-keitel Mar 30, 2023
e13068d
build validation
daniel-keitel Mar 31, 2023
1f00adf
drop and destroy
daniel-keitel Mar 31, 2023
3114a55
cleanup
daniel-keitel Mar 31, 2023
28bf5c5
tracker cleanup
daniel-keitel Apr 1, 2023
8d03fcd
built when used validation
daniel-keitel Apr 1, 2023
f2ada4d
Merge remote-tracking branch 'origin/master' into hal-acceleration-st…
daniel-keitel Apr 1, 2023
1515bad
clippy
daniel-keitel Apr 1, 2023
7795bfc
Merge remote-tracking branch 'origin/hal-acceleration-structures' int…
daniel-keitel Apr 1, 2023
4bbfd49
better example with test
daniel-keitel Apr 1, 2023
26e5097
WIP broken tracing
daniel-keitel Apr 1, 2023
1bad671
fixed tracing
daniel-keitel Apr 4, 2023
abff39f
WIP working safe build (destruction missing)
daniel-keitel Apr 4, 2023
0f81195
fixed destructors, destructor tracing and working tracing for safe build
daniel-keitel Apr 5, 2023
9a33bf9
build age validation
daniel-keitel Apr 5, 2023
c08d454
clippy
daniel-keitel Apr 5, 2023
5a155b4
added acceleration structure barriers
daniel-keitel Apr 5, 2023
54b1a84
Merge branch 'hal-acceleration-structures' into ray-tracing
daniel-keitel Apr 5, 2023
db00f7e
instances in examples + barrier "fix"
daniel-keitel Apr 5, 2023
5971981
clippy
daniel-keitel Apr 6, 2023
386fdba
WIP validation (alignments)
daniel-keitel Apr 7, 2023
e4f4ec4
added blas input alignment requirement
daniel-keitel Apr 7, 2023
d66c383
Merge branch 'hal-acceleration-structures' into ray-tracing
daniel-keitel Apr 7, 2023
9d7d11d
more validation
daniel-keitel Apr 7, 2023
2dd47a6
Documentation
daniel-keitel Apr 9, 2023
0318170
validation fix
daniel-keitel Apr 9, 2023
b447ced
new example + example changes
daniel-keitel Apr 9, 2023
2dc8bf4
extracted into ray_tracing module in wgpu
daniel-keitel Apr 9, 2023
90a5240
simplified example
daniel-keitel Apr 9, 2023
2119391
removed incorrect validation
daniel-keitel Apr 10, 2023
d9a4ebd
WIP build api changes
daniel-keitel Apr 10, 2023
f981b45
WIP new example
daniel-keitel Apr 10, 2023
63fabe4
removed incorrect vertex validation
daniel-keitel Apr 10, 2023
0963c15
WIP example multiple blas in single build
daniel-keitel Apr 10, 2023
8e6e327
API change made TriangleGeometries owning
daniel-keitel Apr 10, 2023
4906c3e
WIP scene
daniel-keitel Apr 10, 2023
4119a4d
package tlas access + WIP scene materials
daniel-keitel Apr 11, 2023
0cf0d95
fixed panic when creating tlas with size 0
daniel-keitel Apr 11, 2023
a2cd571
fmt
daniel-keitel Apr 11, 2023
f37175f
added instance count validation
daniel-keitel Apr 11, 2023
fc54500
fixed shader binding layout validation
daniel-keitel Apr 12, 2023
4366ba7
temporary scratch buffer alignment
daniel-keitel Apr 17, 2023
a6f0ba3
Fixed tlas tracking in bind groups and device cleanup
daniel-keitel Apr 17, 2023
926e1ee
keep ref_count at drop
daniel-keitel Apr 17, 2023
037ed71
Merge commit '66c029f172af69d012d11f863d3c08eefa8f6395' into hal-acce…
daniel-keitel Apr 30, 2023
368e841
Merge commit '037ed71ff3e15ea38cd82579c9cca09cd72a0c70' into ray-trac…
daniel-keitel Apr 30, 2023
d02c99d
wip acceleration structure drop memory leak fix
daniel-keitel Jun 27, 2023
fec5e40
Merge remote-tracking branch 'origin/trunk' into HEAD
expenses Jul 24, 2023
cadea32
Small post-merge fixes
expenses Jul 24, 2023
52e1099
Merge commit '1ced67f05611c62f31aaf97cbbdc183ba6247bb9' into hal-acce…
JMS55 Aug 25, 2023
308cac8
Fix example
JMS55 Aug 25, 2023
24ec2fe
Update lockfile
JMS55 Aug 26, 2023
bcb646e
Misc fix
JMS55 Aug 26, 2023
1bcbfaa
Fix metal backend
JMS55 Aug 26, 2023
384767a
Misc docs
JMS55 Aug 26, 2023
b3d7794
Merge commit '384767af40e2e312babaa871f22f71dfb182cecc' into rt-wgpu-jms
JMS55 Aug 26, 2023
bc8f9ca
Remove misc
JMS55 Aug 26, 2023
dd30270
Misc
JMS55 Aug 26, 2023
936da8e
Fixes
JMS55 Aug 26, 2023
e145452
Undo d02c99d13af80f9a9404e9fe667a4d173b334540
JMS55 Aug 26, 2023
5192375
Merge commit '54a7f0eac9b1531d2ebeec4cff3af842772b098e' into rt-wgpu-jms
JMS55 Sep 4, 2023
811aa23
fixed ray-scene example
daniel-keitel Sep 4, 2023
c789f7f
first dedicated ray-tracing test
daniel-keitel Sep 6, 2023
a919529
Merge branch 'trunk' into hal-acceleration-structures
cwfitzgerald Sep 15, 2023
a09d116
fixed rt hal example after trunk merge
daniel-keitel Sep 16, 2023
34995ae
Merge remote-tracking branch 'origin/master' into hal-acceleration-st…
daniel-keitel Nov 11, 2023
77acca5
implemented requested changes
daniel-keitel Dec 1, 2023
efc6d90
Merge remote-tracking branch 'origin/master' into hal-acceleration-st…
daniel-keitel Dec 1, 2023
e7ec7c6
Merge branch 'ray-tracing' into trunk
Vecvec Dec 2, 2023
bb316b1
fix unexpected build errors (not the expected ones)
Vecvec Dec 4, 2023
d486837
few more patches
Vecvec Dec 4, 2023
f0c36db
Merge remote-tracking branch 'pull_Vecvec/hal-acceleration-structures…
Vecvec Dec 4, 2023
96bb3e7
fix more compile errors
Vecvec Dec 8, 2023
9b3266c
fix err
Vecvec Dec 8, 2023
06dc329
Merge branch 'trunk' into ray-tracing
Vecvec Dec 8, 2023
99f4236
fix all compile errors
Vecvec Dec 10, 2023
0fab2a4
Merge pull request #4 from gfx-rs/trunk
Vecvec Dec 10, 2023
5efddd7
fix clippy errors
Vecvec Dec 10, 2023
49d5e85
Merge remote-tracking branch 'origin/ray-tracing' into ray-tracing
Vecvec Dec 10, 2023
b7486bd
fix issues in ray-traced-triangle example
Vecvec Dec 10, 2023
2f49af2
fix clippy warnings
Vecvec Dec 10, 2023
014d283
fix wasm not compiling
Vecvec Dec 10, 2023
6a6345c
fix test
Vecvec Dec 10, 2023
a636d08
fix clippy (again)
Vecvec Dec 10, 2023
5ec1735
fix some rustfmt issues
Vecvec Dec 10, 2023
8604794
fix more rustfmt issues
Vecvec Dec 10, 2023
eb23a11
fix even more rustfmt issues
Vecvec Dec 10, 2023
b48b66d
fix yet more rustfmt issues
Vecvec Dec 11, 2023
14e65dd
add #[allow(dead_code)] to some structs to fix clippy on web assembly
Vecvec Dec 11, 2023
c9c027e
more format fixes
Vecvec Dec 11, 2023
9e9ae22
even more format fixes
Vecvec Dec 11, 2023
b00bc83
close to final format fixes
Vecvec Dec 11, 2023
2971bca
final format fixes (hopefully)
Vecvec Dec 11, 2023
4280f29
actual final format fixes (hopefully)
Vecvec Dec 11, 2023
4e06007
Merge pull request #5 from gfx-rs/trunk
Vecvec Dec 11, 2023
331625a
move ray_cube_cube example and fix bugs
Vecvec Dec 12, 2023
49b65e4
move other examples
Vecvec Dec 12, 2023
2f25773
fix crash when dropping
Vecvec Dec 12, 2023
74ce414
fix test
Vecvec Dec 12, 2023
3765def
apply clippy and rustfmt changes
Vecvec Dec 12, 2023
986d520
fix some memory leaks
Vecvec Dec 13, 2023
859f6c5
Merge from gfx-rs/trunk
Vecvec Dec 13, 2023
07f6e1a
Merge remote-tracking branch 'gfx-rs/trunk' into ray-tracing
Vecvec Dec 17, 2023
817e545
fix incompatibility with new wgpu trunk changes
Vecvec Dec 17, 2023
e0b6724
fix clippy & fmt
Vecvec Dec 17, 2023
d66fcaa
fix clippy errors on github
Vecvec Dec 17, 2023
9980d45
Merge remote-tracking branch 'gfx-rs/trunk' into ray-tracing
Vecvec Dec 18, 2023
c288e08
update to trunk
Vecvec Dec 18, 2023
8e606c2
remove a line that printed log "Created blas ..." in device create tlas
Vecvec Dec 18, 2023
a9d12af
Merge remote-tracking branch 'gfx-rs/trunk' into ray-tracing
Vecvec Dec 20, 2023
ea77c34
Merge remote-tracking branch 'gfx-rs/trunk' into ray-tracing
Vecvec Dec 21, 2023
0f3c84b
Merge remote-tracking branch 'gfx-rs/trunk' into ray-tracing
Vecvec Jan 2, 2024
909f366
Merge remote-tracking branch 'gfx-rs/trunk' into ray-tracing
Vecvec Jan 7, 2024
ccc6969
fix merge issues
Vecvec Jan 7, 2024
8c82cc5
Merge remote-tracking branch 'gfx-rs/trunk' into ray-tracing
Vecvec Jan 8, 2024
f2d5734
Merge remote-tracking branch 'gfx-rs/trunk' into ray-tracing
Vecvec Jan 14, 2024
8734e03
fix merge
Vecvec Jan 14, 2024
316f0e2
fix fmt
Vecvec Jan 14, 2024
f39a44c
Merge pull request #2 from Vecvec/ray-tracing
daniel-keitel Jan 17, 2024
1b4f220
restored example ray scene functionality
daniel-keitel Jan 17, 2024
78f399b
Merge commit 'c038b5c433aeb3bc55f2091da56216e3f1c07e74' into ray-tracing
JMS55 Feb 3, 2024
41133c4
WIP fix rebase
JMS55 Feb 3, 2024
41fe261
Fix compile issues
JMS55 Feb 4, 2024
d94cbeb
More fixes
JMS55 Feb 4, 2024
13c09f9
Merge commit '004e3efe84a320d9331371ed31fa50baa2414911' into ray-tracing
JMS55 Feb 18, 2024
b60f318
Fix rebase
JMS55 Feb 18, 2024
91b7546
Add wgls backend write_value_type AccelerationStructure
JMS55 Feb 18, 2024
972d9cb
Merge commit '5b9ade82233deac341c577ec02b70e7b3e518933' into ray-tracing
JMS55 Feb 25, 2024
2bc105d
Add back xtask Cargo.lock
JMS55 Feb 25, 2024
f3fa301
Revert serde path
JMS55 Feb 25, 2024
96877cc
Doc typos
JMS55 Feb 25, 2024
b459f37
Add -diff
JMS55 Feb 25, 2024
4a1080a
Revert more serde
JMS55 Feb 25, 2024
991c2c4
Revert serde again?
JMS55 Feb 25, 2024
e042a86
Fix doc typo
JMS55 Feb 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 154 additions & 0 deletions api_spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Ray tracing api proposal for wgpu (underlining Vulkan, Metal and DX12 implementations)

// The general design goal is to come up with an simpler Api, which allows for validation.
// Since this validation would have high overhead in some cases,
// I decided to provide more limited functions and unsafe functions for the same action, to evade this tradeoff.

// Error handling and traits like Debug are omitted.

// Core structures with no public members
pub struct Blas {}
pub struct Tlas {}
pub struct BlasRequirements {}
pub struct TlasInstances{}

// Size descriptors used to describe the size requirements of blas geometries.
// Also used internally for strict validation
pub struct BlasTriangleGeometrySizeDescriptor{
pub vertex_format: wgt::VertexFormat,
pub vertex_count: u32,
pub index_format: Option<wgt::IndexFormat>,
pub index_count: Option<u32>,
pub flags: AccelerationStructureGeometryFlags,
}

pub struct BlasProceduralGeometrySizeDescriptor{
pub count: u32,
pub flags: AccelerationStructureGeometryFlags,
}

// Procedural geometry contains AABBs
pub struct BlasProceduralGeometry{
pub size: BlasTriangleGeometrySize,
pub bounding_box_buffer: Buffer,
pub bounding_box_buffer_offset: wgt::BufferAddress,
pub bounding_box_stride: wgt::BufferAddress,
}

// Triangle Geometry contains vertices, optionally indices and transforms
pub struct BlasTriangleGeometry{
pub size: BlasTriangleGeometrySize,
pub vertex_buffer: Buffer
pub first_vertex: u32,
pub vertex_stride: wgt::BufferAddress,
pub index_buffer: Option<Buffer>,
pub index_buffer_offset: Option<wgt::BufferAddress>,
pub transform_buffer: Option<Buffer>,
pub transform_buffer_offset: Option<wgt::BufferAddress>,
}

// Build flags
pub struct AccelerationStructureFlags{
// build_speed, small_size, ...
}

// Geometry flags
pub struct AccelerationStructureGeometryFlags{
// opaque, no_duplicate_any_hit, ...
}

// Descriptors used to determine the memory requirements and validation of a acceleration structure
pub enum BlasGeometrySizeDescriptors{
Triangles{desc: Vec<BlasTriangleGeometrySizeDescriptor>},
Procedural(desc: Vec<BlasProceduralGeometrySize>)
}

// With prefer update, we decide if an update is possible, else we rebuild.
// Maybe a force update option could be useful
pub enum UpdateMode{
Build,
// Update,
PreferUpdate,
}

// General descriptor for the size requirements,
// since the required size depends on the contents and build flags
pub struct GetBlasRequirementsDescriptor{
pub flags: AccelerationStructureFlags,
}

// Creation descriptors, we provide flags, and update_mode.
// We store it in the structure, so we don't need to pass it every build.
pub struct CreateBlasDescriptor<'a>{
pub flags: AccelerationStructureFlags,
pub update_mode: UpdateMode,
}

pub struct CreateTlasDescriptor{
pub max_instances: u32,
pub flags: AccelerationStructureFlags,
pub update_mode: UpdateMode,
}

// Secure instance entry for tlas
struct TlasInstance{
transform: [f32; 12],
custom_index: u32,
mask: u8,
shader_binding_table_record_offset: u32,
flags: u8 //bitmap
blas: Blas
}

impl Device {
// Creates a new bottom level accelerations structures and sets internal states for validation and builds (e.g update mode)
pub fn create_blas(&self, desc: &CreateBlasDescriptor, entries: BlasGeometrySizeDescriptors) -> Blas;

// Creates a new top level accelerations structures and sets internal states for builds (e.g update mode)
pub fn create_tlas(&self, desc: &CreateTlasDescriptor) -> Tlas;
}

// Enum for the different types of geometries inside a single blas build
// [Should we used nested iterators with dynamic dispatch instead]
enum BlasGeometries<'a>{
TriangleGeometries(&'a [BlasTriangleGeometry])
ProceduralGeometries(&'a [BlasProceduralGeometry])
}

impl CommandEncoder {
// Build acceleration structures.
// Elements of blas may be used in a tlas (internal synchronization).
// This function will allocate a single big scratch buffer, that is shared between internal builds.
// If there are to many acceleration structures for a single build (size constraint),
// we will automatically distribute them between multiple internal builds. (reducing the required size of the scratch buffer).
// This version will be implemented in wgpu::util not wgpu-core.
pub fn build_acceleration_structures<'a>(&self,
blas: impl IntoIterator<Item=(&'a Blas,BlasGeometries<'a>)>,
tlas: impl IntoIterator<Item=(&'a Tlas,TlasInstances<'a>)>,
);

// unsafe version without validation for tlas, directly using an instance buffer.
// u32 for the number of instances to build
pub fn build_acceleration_structures_unsafe_tlas<'a>(&self,
blas: impl IntoIterator<Item=(&'a Blas,BlasGeometries<'a>)>,
tlas: impl IntoIterator<Item=(&'a Tlas,&'a Buffer, u32)>,
);

// Creates a new blas and copies (in a compacting way) the contents of the provided blas
// into the new one (compaction flag must be set).
pub fn compact_blas(&self, blas: &Blas) -> Blas;
}

// Safe Tlas Instance
impl TlasInstances{
pub fn new(max_instances: u32) -> Self;

// gets instances to read from
pub fn get(&self) -> &[TlasInstance];
// gets instances to modify, we keep track of the range to determine what we need to validate and copy
pub fn get_mut_range(&mut self, range: Range<u32>) -> &mut [TlasInstance];
// get the number of instances which will be build
pub fn active(&self) -> u32;
// set the number of instances which will be build
pub fn set_active(&mut self, active: u32);
}
3 changes: 3 additions & 0 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub mod hello_windows;
pub mod hello_workgroups;
pub mod mipmap;
pub mod msaa_line;
pub mod ray_cube_compute;
pub mod ray_cube_fragment;
pub mod ray_scene;
pub mod render_to_texture;
pub mod repeated_compute;
pub mod shadow;
Expand Down
18 changes: 18 additions & 0 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ const EXAMPLES: &[ExampleDesc] = &[
webgl: false, // No RODS
webgpu: true,
},
ExampleDesc {
name: "ray_cube_compute",
function: wgpu_examples::ray_cube_compute::main,
webgl: false, // No Ray-tracing extensions
webgpu: false, // No Ray-tracing extensions (yet)
},
ExampleDesc {
name: "ray_cube_fragment",
function: wgpu_examples::ray_cube_fragment::main,
webgl: false, // No Ray-tracing extensions
webgpu: false, // No Ray-tracing extensions (yet)
},
ExampleDesc {
name: "ray_scene",
function: wgpu_examples::ray_scene::main,
webgl: false, // No Ray-tracing extensions
webgpu: false, // No Ray-tracing extensions (yet)
},
];

fn get_example_name() -> Option<String> {
Expand Down
14 changes: 14 additions & 0 deletions examples/src/ray_cube_compute/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ray-cube

This example renders a ray traced cube with hardware acceleration.
A separate compute shader is used to perform the ray queries.

## To Run

```
cargo run --example ray-cube-compute
```

## Screenshots

![Cube example](screenshot.png)
52 changes: 52 additions & 0 deletions examples/src/ray_cube_compute/blit.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
};

// meant to be called with 3 vertex indices: 0, 1, 2
// draws one large triangle over the clip space like this:
// (the asterisks represent the clip space bounds)
//-1,1 1,1
// ---------------------------------
// | * .
// | * .
// | * .
// | * .
// | * .
// | * .
// |***************
// | . 1,-1
// | .
// | .
// | .
// | .
// |.
@vertex
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
var result: VertexOutput;
let x = i32(vertex_index) / 2;
let y = i32(vertex_index) & 1;
let tc = vec2<f32>(
f32(x) * 2.0,
f32(y) * 2.0
);
result.position = vec4<f32>(
tc.x * 2.0 - 1.0,
1.0 - tc.y * 2.0,
0.0, 1.0
);
result.tex_coords = tc;
return result;
}

@group(0)
@binding(0)
var r_color: texture_2d<f32>;
@group(0)
@binding(1)
var r_sampler: sampler;

@fragment
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, vertex.tex_coords);
}
Loading
Loading