Skip to content

Commit 9827e1d

Browse files
SiebenCorgieeddyb
authored andcommitted
add test cases for TypedBuffer
1 parent fdbc059 commit 9827e1d

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// build-pass
2+
// compile-flags: -C target-feature=+RuntimeDescriptorArray,+ext:SPV_EXT_descriptor_indexing
3+
4+
// Tests the simplest `TypedBuffer` case: Multiple structs of of the same type and size.
5+
6+
use spirv_std::{RuntimeArray, TypedBuffer, glam::UVec3, spirv};
7+
8+
#[derive(Clone, Copy)]
9+
pub struct MyData {
10+
some_big_data: [u32; 1 << 24],
11+
}
12+
13+
#[spirv(compute(threads(1)))]
14+
pub fn compute(
15+
#[spirv(global_invocation_id)] global_invocation_id: UVec3,
16+
#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] my_data: &mut RuntimeArray<
17+
TypedBuffer<MyData>,
18+
>,
19+
) {
20+
let mut load_dta = unsafe { my_data.index(global_invocation_id.x as usize) }.some_big_data[0];
21+
load_dta = 32;
22+
23+
let mut target = unsafe { &mut my_data.index_mut(global_invocation_id.y as usize) };
24+
target.some_big_data[0] = load_dta;
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// build-pass
2+
// compile-flags: -C target-feature=+RuntimeDescriptorArray,+ext:SPV_EXT_descriptor_indexing
3+
4+
// 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.
5+
6+
use spirv_std::{RuntimeArray, TypedBuffer, glam::UVec3, spirv};
7+
8+
#[derive(Clone, Copy)]
9+
pub struct MyData {
10+
a: f32,
11+
b: [u32; 3],
12+
}
13+
14+
#[spirv(compute(threads(1)))]
15+
pub fn compute(
16+
#[spirv(global_invocation_id)] global_invocation_id: UVec3,
17+
#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] my_data: &mut RuntimeArray<
18+
TypedBuffer<[MyData]>,
19+
>,
20+
) {
21+
let mut load_dta: MyData = unsafe { my_data.index(global_invocation_id.x as usize) }[0];
22+
load_dta.b[0] = 32;
23+
24+
let mut target = unsafe { &mut my_data.index_mut(global_invocation_id.y as usize)[0] };
25+
*target = load_dta;
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// build-pass
2+
// compile-flags: -C target-feature=+RuntimeDescriptorArray,+ext:SPV_EXT_descriptor_indexing
3+
4+
// Tests the more complex `TypedBuffer` case, where the size of each buffer in the binding is unbound.
5+
6+
use spirv_std::{RuntimeArray, TypedBuffer, glam::UVec3, spirv};
7+
8+
#[spirv(compute(threads(1)))]
9+
pub fn compute(
10+
#[spirv(global_invocation_id)] global_invocation_id: UVec3,
11+
#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] my_data: &mut RuntimeArray<
12+
TypedBuffer<[u32]>,
13+
>,
14+
) {
15+
let mut load_dta: u32 = unsafe { my_data.index(global_invocation_id.x as usize) }[0];
16+
load_dta = 32;
17+
18+
let mut target = unsafe { &mut my_data.index_mut(global_invocation_id.y as usize)[0] };
19+
*target = load_dta;
20+
}

0 commit comments

Comments
 (0)