-
Notifications
You must be signed in to change notification settings - Fork 61
[eddyb's version/leftovers] TypedBuffer
/ #[spirv(typed_buffer)]
.
#319
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/compiletests/ui/storage_class/typed-buffer-simple.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// build-pass | ||
// compile-flags: -C target-feature=+RuntimeDescriptorArray,+ext:SPV_EXT_descriptor_indexing | ||
|
||
// Tests the simplest `TypedBuffer` case: Multiple structs of of the same type and size. | ||
|
||
use spirv_std::{RuntimeArray, TypedBuffer, glam::UVec3, spirv}; | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct MyData { | ||
some_big_data: [u32; 1 << 24], | ||
} | ||
|
||
#[spirv(compute(threads(1)))] | ||
pub fn compute( | ||
#[spirv(global_invocation_id)] global_invocation_id: UVec3, | ||
#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] my_data: &mut RuntimeArray< | ||
TypedBuffer<MyData>, | ||
>, | ||
) { | ||
let mut load_dta = unsafe { my_data.index(global_invocation_id.x as usize) }.some_big_data[0]; | ||
load_dta = 32; | ||
|
||
let mut target = unsafe { &mut my_data.index_mut(global_invocation_id.y as usize) }; | ||
target.some_big_data[0] = load_dta; | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/compiletests/ui/storage_class/typed-buffer-unbound-struct.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// build-pass | ||
// compile-flags: -C target-feature=+RuntimeDescriptorArray,+ext:SPV_EXT_descriptor_indexing | ||
|
||
// Tests the more complex `TypedBuffer` case, where the size of each buffer in the binding is unbound, and also the data type is a struct. | ||
|
||
use spirv_std::{RuntimeArray, TypedBuffer, glam::UVec3, spirv}; | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct MyData { | ||
a: f32, | ||
b: [u32; 3], | ||
} | ||
|
||
#[spirv(compute(threads(1)))] | ||
pub fn compute( | ||
#[spirv(global_invocation_id)] global_invocation_id: UVec3, | ||
#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] my_data: &mut RuntimeArray< | ||
TypedBuffer<[MyData]>, | ||
>, | ||
) { | ||
let mut load_dta: MyData = unsafe { my_data.index(global_invocation_id.x as usize) }[0]; | ||
load_dta.b[0] = 32; | ||
|
||
let mut target = unsafe { &mut my_data.index_mut(global_invocation_id.y as usize)[0] }; | ||
*target = load_dta; | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/compiletests/ui/storage_class/typed-buffer-unbound.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// build-pass | ||
// compile-flags: -C target-feature=+RuntimeDescriptorArray,+ext:SPV_EXT_descriptor_indexing | ||
|
||
// Tests the more complex `TypedBuffer` case, where the size of each buffer in the binding is unbound. | ||
|
||
use spirv_std::{RuntimeArray, TypedBuffer, glam::UVec3, spirv}; | ||
|
||
#[spirv(compute(threads(1)))] | ||
pub fn compute( | ||
#[spirv(global_invocation_id)] global_invocation_id: UVec3, | ||
#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] my_data: &mut RuntimeArray< | ||
TypedBuffer<[u32]>, | ||
>, | ||
) { | ||
let mut load_dta: u32 = unsafe { my_data.index(global_invocation_id.x as usize) }[0]; | ||
load_dta = 32; | ||
|
||
let mut target = unsafe { &mut my_data.index_mut(global_invocation_id.y as usize)[0] }; | ||
*target = load_dta; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we loading data into
load_dta: u32
to then immediately replace the value with a const? Could DCE screw us over here?Also at https://github.com/Rust-GPU/rust-gpu/pull/319/files#diff-734d8d31bf0e2742d96036c34f019f361a6bb9674653012c7e3522c59919f506R16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, I wonder if this was meant to be
&mut
followed by*... = 32;
.Funnily enough, the bug this test catches (post-rust-lang/rust#134117) happens much earlier, so only MIR optimizations could invalidate that part, even in theory (though ideally we'd not rely on incidental stuff like this, and add separate tests).
Anyway, for reading values I tend to just add an output variable to write them to, guaranteeing the read will be kept around, I might make that change if it's not obvious what the original tests meant to do.