-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,37 @@ | ||
use core::marker::PhantomData; | ||
|
||
#[spirv(runtime_array)] | ||
pub struct RuntimeArray<T> { | ||
// spooky! this field does not exist, so if it's referenced in rust code, things will explode | ||
_do_not_touch: u32, | ||
_phantom: PhantomData<T>, | ||
} | ||
|
||
// It would be nice to use the Index/IndexMut traits here, but because we do not have the length of | ||
// the array, it's impossible to make them be safe operations (indexing out of bounds), and | ||
// Index/IndexMut are marked as safe functions. | ||
impl<T> RuntimeArray<T> { | ||
#[spirv_std_macros::gpu_only] | ||
pub unsafe fn index(&self, index: usize) -> &T { | ||
asm! { | ||
"%result = OpAccessChain _ {arr} {index}", | ||
"OpReturnValue %result", | ||
"%unused = OpLabel", | ||
arr = in(reg) self, | ||
index = in(reg) index, | ||
} | ||
loop {} | ||
} | ||
|
||
#[spirv_std_macros::gpu_only] | ||
pub unsafe fn index_mut(&mut self, index: usize) -> &mut T { | ||
asm! { | ||
"%result = OpAccessChain _ {arr} {index}", | ||
"OpReturnValue %result", | ||
"%unused = OpLabel", | ||
arr = in(reg) self, | ||
index = in(reg) index, | ||
} | ||
loop {} | ||
} | ||
} |
This file contains 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,17 @@ | ||
// build-pass | ||
use spirv_std::{Image2d, RuntimeArray, Sampler}; | ||
|
||
#[spirv(fragment)] | ||
pub fn main( | ||
#[spirv(descriptor_set = 0, binding = 0)] sampler: &Sampler, | ||
#[spirv(descriptor_set = 0, binding = 1)] slice: &RuntimeArray<Image2d>, | ||
#[spirv(descriptor_set = 0, binding = 2)] sized_slice: &[Image2d; 5], | ||
output: &mut glam::Vec4, | ||
) { | ||
let img = unsafe { slice.index(5) }; | ||
let v2 = glam::Vec2::new(0.0, 1.0); | ||
*output = img.sample(*sampler, v2); | ||
|
||
let img_2 = &sized_slice[2]; | ||
*output += img_2.sample(*sampler, v2); | ||
} |
This file contains 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,10 @@ | ||
// build-fail | ||
|
||
use spirv_std::{Image2d, RuntimeArray}; | ||
|
||
#[spirv(fragment)] | ||
pub fn main( | ||
#[spirv(descriptor_set = 0, binding = 0)] one: &[Image2d], | ||
#[spirv(uniform, descriptor_set = 0, binding = 0)] two: &RuntimeArray<u32>, | ||
) { | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/ui/storage_class/runtime_descriptor_array_error.stderr
This file contains 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,14 @@ | ||
error: uniform_constant buffers must use &RuntimeArray<T>, not &[T] | ||
--> $DIR/runtime_descriptor_array_error.rs:7:52 | ||
| | ||
7 | #[spirv(descriptor_set = 0, binding = 0)] one: &[Image2d], | ||
| ^^^^^^^^^^ | ||
|
||
warning: use &[T] instead of &RuntimeArray<T> | ||
--> $DIR/runtime_descriptor_array_error.rs:8:61 | ||
| | ||
8 | #[spirv(uniform, descriptor_set = 0, binding = 0)] two: &RuntimeArray<u32>, | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|