Skip to content

Commit 8695a3a

Browse files
SiebenCorgieeddyb
authored andcommitted
add test cases for TypedBuffer
1 parent 9e640b7 commit 8695a3a

File tree

3 files changed

+62
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)