Skip to content

Commit b7d217e

Browse files
committed
abi layout difftest: cuda and scalar-math feature forwarding
1 parent aaf85e6 commit b7d217e

File tree

8 files changed

+54
-4
lines changed

8 files changed

+54
-4
lines changed

tests/difftests/tests/Cargo.lock

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

tests/difftests/tests/lang/abi/vector_layout/cpu/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ edition.workspace = true
55
[lints]
66
workspace = true
77

8+
[features]
9+
cuda = ["glam/cuda"]
10+
scalar-math = ["glam/scalar-math"]
11+
812
# GPU deps
913
[dependencies]
1014
spirv-std.workspace = true
15+
glam.workspace = true
1116
bytemuck.workspace = true
1217

1318
# CPU deps (for the test harness)

tests/difftests/tests/lang/abi/vector_layout/cpu/src/cpu_driver.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
use crate::glam_features::GlamFeatures;
12
use crate::layout::{LAYOUT_COUNT, LAYOUT_LEN, eval_layouts};
23
use difftest::config::Config;
34

4-
pub fn run() {
5+
pub fn run(glam_feature: GlamFeatures) {
6+
glam_feature.assert();
57
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
68
let mut out = vec![0; LAYOUT_LEN];
79
for gid in 0..LAYOUT_COUNT {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#[repr(u32)]
2+
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
3+
pub enum GlamFeatures {
4+
Default,
5+
Cuda,
6+
ScalarMath,
7+
}
8+
9+
impl GlamFeatures {
10+
pub fn is(&self) -> bool {
11+
match self {
12+
// cuda: 16 (!)
13+
// cuda + scalar-math: 8
14+
// scalar-math: (native) 4
15+
GlamFeatures::Default => align_of::<glam::Mat2>() == 16 && !GlamFeatures::Cuda.is(),
16+
// default, scalar-math: (native) 4
17+
GlamFeatures::Cuda => align_of::<glam::Vec2>() == 8,
18+
// default, cuda: 16
19+
GlamFeatures::ScalarMath => align_of::<glam::Vec4>() == 4,
20+
}
21+
}
22+
23+
pub fn assert(&self) {
24+
for feature in [Self::Default, Self::Cuda, Self::ScalarMath] {
25+
if *self == feature {
26+
assert!(feature.is(), "Expected feature {feature:?} to be enabled");
27+
} else {
28+
assert!(
29+
!feature.is(),
30+
"Feature {feature:?} mistakenly enabled! Too aggressive feature unification?"
31+
);
32+
}
33+
}
34+
}
35+
}

tests/difftests/tests/lang/abi/vector_layout/cpu/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#[cfg(not(target_arch = "spirv"))]
44
pub mod cpu_driver;
5+
pub mod glam_features;
56
pub mod layout;
67
pub mod shader;
78
#[cfg(not(target_arch = "spirv"))]
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use abi_vector_layout_cpu::glam_features::GlamFeatures;
2+
13
fn main() {
2-
abi_vector_layout_cpu::cpu_driver::run();
4+
abi_vector_layout_cpu::cpu_driver::run(GlamFeatures::Default);
35
}

tests/difftests/tests/lang/abi/vector_layout/cpu/src/shader_driver.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
use crate::glam_features::GlamFeatures;
12
use crate::layout::{LAYOUT_COUNT, LAYOUT_LEN};
23
use difftest::config::Config;
34
use difftest::scaffold::compute::{BufferConfig, RustComputeShader, WgpuComputeTestMultiBuffer};
45

5-
pub fn run() {
6+
pub fn run(glam_feature: GlamFeatures) {
7+
glam_feature.assert();
68
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
79
let test = WgpuComputeTestMultiBuffer::new(
810
RustComputeShader::default(),
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use abi_vector_layout_cpu::glam_features::GlamFeatures;
2+
13
fn main() {
2-
abi_vector_layout_cpu::shader_driver::run();
4+
abi_vector_layout_cpu::shader_driver::run(GlamFeatures::Default);
35
}

0 commit comments

Comments
 (0)