Skip to content

Commit 96a95d5

Browse files
committed
vec3: difftest for layout size and alignment
1 parent 0c2df59 commit 96a95d5

File tree

12 files changed

+133
-0
lines changed

12 files changed

+133
-0
lines changed

tests/difftests/tests/Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/difftests/tests/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ members = [
1717
"arch/push_constants/push_constants-wgsl",
1818
"storage_class/array_access/array_access-rust",
1919
"storage_class/array_access/array_access-wgsl",
20+
"lang/abi/vector_layout/cpu",
21+
"lang/abi/vector_layout/rust-gpu",
2022
"lang/control_flow/control_flow-rust",
2123
"lang/control_flow/control_flow-wgsl",
2224
"lang/control_flow_complex/control_flow_complex-rust",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "abi-vector-layout-cpu"
3+
edition.workspace = true
4+
5+
[lints]
6+
workspace = true
7+
8+
# GPU deps
9+
[dependencies]
10+
spirv-std.workspace = true
11+
bytemuck.workspace = true
12+
13+
# CPU deps (for the test harness)
14+
[target.'cfg(not(target_arch = "spirv"))'.dependencies]
15+
difftest.workspace = true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use crate::layout::eval_layouts;
2+
use difftest::config::Config;
3+
4+
pub fn run() {
5+
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
6+
config
7+
.write_result(bytemuck::bytes_of(&eval_layouts()))
8+
.unwrap()
9+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use bytemuck::{Pod, Zeroable};
2+
use spirv_std::glam::*;
3+
4+
#[repr(C)]
5+
#[derive(Copy, Clone, Zeroable, Pod)]
6+
pub struct SizeAndAlign {
7+
pub size: u32,
8+
pub align: u32,
9+
}
10+
11+
impl SizeAndAlign {
12+
pub fn from<T>() -> Self {
13+
Self {
14+
size: size_of::<T>() as u32,
15+
align: align_of::<T>() as u32,
16+
}
17+
}
18+
19+
pub fn flatten(&self) -> [u32; 2] {
20+
[self.size, self.align]
21+
}
22+
}
23+
24+
pub type EvalResult = [SizeAndAlign; 8];
25+
26+
pub fn eval_layouts() -> EvalResult {
27+
[
28+
SizeAndAlign::from::<u32>(),
29+
SizeAndAlign::from::<UVec2>(),
30+
SizeAndAlign::from::<UVec3>(),
31+
SizeAndAlign::from::<UVec4>(),
32+
SizeAndAlign::from::<f32>(),
33+
SizeAndAlign::from::<Vec2>(),
34+
SizeAndAlign::from::<Vec3>(),
35+
SizeAndAlign::from::<Vec4>(),
36+
]
37+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![cfg_attr(target_arch = "spirv", no_std)]
2+
3+
#[cfg(not(target_arch = "spirv"))]
4+
pub mod cpu_driver;
5+
pub mod layout;
6+
pub mod shader;
7+
#[cfg(not(target_arch = "spirv"))]
8+
pub mod shader_driver;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
abi_vector_layout_cpu::cpu_driver::run();
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use crate::layout::{EvalResult, eval_layouts};
2+
use spirv_std::spirv;
3+
4+
#[spirv(compute(threads(1)))]
5+
pub fn main_cs(#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] output: &mut EvalResult) {
6+
*output = eval_layouts();
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use crate::layout::EvalResult;
2+
use difftest::config::Config;
3+
use difftest::scaffold::compute::{BufferConfig, RustComputeShader, WgpuComputeTestMultiBuffer};
4+
5+
pub fn run() {
6+
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
7+
let test = WgpuComputeTestMultiBuffer::new(
8+
RustComputeShader::default(),
9+
[1, 1, 1],
10+
Vec::from(&[BufferConfig::writeback(size_of::<EvalResult>())]),
11+
);
12+
test.run_test(&config).unwrap();
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "abi-vector-layout-rust-gpu"
3+
edition.workspace = true
4+
5+
[lib]
6+
crate-type = ["lib", "dylib"]
7+
8+
[lints]
9+
workspace = true
10+
11+
[dependencies]
12+
abi-vector-layout-cpu = { path = "../cpu" }
13+
14+
# CPU deps (for the test harness)
15+
[target.'cfg(not(target_arch = "spirv"))'.dependencies]
16+
difftest.workspace = true

0 commit comments

Comments
 (0)