Skip to content

Commit 582df86

Browse files
committed
abi layout: add some compiletests
1 parent c58aaec commit 582df86

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// build-fail
2+
3+
use core::num::NonZeroU32;
4+
use spirv_std::glam::Vec2;
5+
use spirv_std::spirv;
6+
7+
#[rust_gpu::vector::v1]
8+
pub struct FewerFields {
9+
_v: f32,
10+
}
11+
12+
#[rust_gpu::vector::v1]
13+
pub struct TooManyFields {
14+
_x: f32,
15+
_y: f32,
16+
_z: f32,
17+
_w: f32,
18+
_v: f32,
19+
}
20+
21+
#[rust_gpu::vector::v1]
22+
pub struct NotVectorField {
23+
_x: Vec2,
24+
_y: Vec2,
25+
}
26+
27+
#[rust_gpu::vector::v1]
28+
pub struct NotVectorField2 {
29+
_x: NonZeroU32,
30+
_y: NonZeroU32,
31+
}
32+
33+
#[rust_gpu::vector::v1]
34+
pub struct DifferentTypes {
35+
_x: f32,
36+
_y: u32,
37+
}
38+
39+
#[spirv(fragment)]
40+
pub fn entry(
41+
_: FewerFields,
42+
_: TooManyFields,
43+
_: NotVectorField,
44+
#[spirv(flat)] _: NotVectorField2,
45+
#[spirv(flat)] _: DifferentTypes,
46+
) {
47+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: `#[spirv(vector)]` must have 2, 3 or 4 members
2+
--> $DIR/invalid_vector_type.rs:8:1
3+
|
4+
8 | pub struct FewerFields {
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: `#[spirv(vector)]` must have 2, 3 or 4 members
8+
--> $DIR/invalid_vector_type.rs:13:1
9+
|
10+
13 | pub struct TooManyFields {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: `#[spirv(vector)]` type fields must all be floats, integers or bools
14+
--> $DIR/invalid_vector_type.rs:22:1
15+
|
16+
22 | pub struct NotVectorField {
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
18+
|
19+
= note: field type is f32x2
20+
21+
error: `#[spirv(vector)]` member types must all be the same
22+
--> $DIR/invalid_vector_type.rs:34:1
23+
|
24+
34 | pub struct DifferentTypes {
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
26+
27+
error: aborting due to 4 previous errors
28+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// build-pass
2+
// compile-flags: -C llvm-args=--disassemble
3+
// normalize-stderr-test "OpSource .*\n" -> ""
4+
// normalize-stderr-test "OpLine .*\n" -> ""
5+
// normalize-stderr-test "%\d+ = OpString .*\n" -> ""
6+
// normalize-stderr-test "; .*\n" -> ""
7+
// normalize-stderr-test "OpCapability VulkanMemoryModel\n" -> ""
8+
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"
9+
// ignore-vulkan1.0
10+
// ignore-vulkan1.1
11+
12+
use spirv_std::arch::subgroup_shuffle_up;
13+
use spirv_std::spirv;
14+
15+
#[repr(C)]
16+
#[derive(Copy, Clone, Default)]
17+
#[rust_gpu::vector::v1]
18+
pub struct Vec3 {
19+
x: f32,
20+
y: f32,
21+
z: f32,
22+
}
23+
24+
#[repr(C, align(16))]
25+
#[derive(Copy, Clone, Default)]
26+
#[rust_gpu::vector::v1]
27+
pub struct Vec3A {
28+
x: f32,
29+
y: f32,
30+
z: f32,
31+
}
32+
33+
#[repr(C)]
34+
#[derive(Copy, Clone, Default)]
35+
pub struct Data<T> {
36+
t: T,
37+
// this should generate two distinct structs where this member has different offsets
38+
value: f32,
39+
}
40+
41+
impl Vec3 {
42+
pub fn to_vec3a(&self) -> Vec3A {
43+
Vec3A {
44+
x: self.x,
45+
y: self.y,
46+
z: self.z,
47+
}
48+
}
49+
}
50+
51+
#[spirv(fragment)]
52+
pub fn main(input: Data<Vec3>, output: &mut Data<Vec3A>) {
53+
*output = Data {
54+
t: input.t.to_vec3a(),
55+
value: input.value,
56+
};
57+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
OpCapability Shader
2+
OpMemoryModel Logical Simple
3+
OpEntryPoint Fragment %1 "main" %2 %3
4+
OpExecutionMode %1 OriginUpperLeft
5+
OpName %5 "Data<Vec3>"
6+
OpMemberName %5 0 "t"
7+
OpMemberName %5 1 "value"
8+
OpName %6 "Data<Vec3A>"
9+
OpMemberName %6 0 "t"
10+
OpMemberName %6 1 "value"
11+
OpName %2 "input"
12+
OpName %7 "Data<Vec3>"
13+
OpMemberName %7 0 "t"
14+
OpMemberName %7 1 "value"
15+
OpName %8 "Data<Vec3A>"
16+
OpMemberName %8 0 "t"
17+
OpMemberName %8 1 "value"
18+
OpName %3 "output"
19+
OpDecorate %2 Location 0
20+
OpMemberDecorate %7 0 Offset 0
21+
OpMemberDecorate %7 1 Offset 12
22+
OpMemberDecorate %8 0 Offset 0
23+
OpMemberDecorate %8 1 Offset 16
24+
OpDecorate %3 Location 0
25+
%9 = OpTypeFloat 32
26+
%10 = OpTypeVector %9 3
27+
%5 = OpTypeStruct %10 %9
28+
%11 = OpTypePointer Input %5
29+
%6 = OpTypeStruct %10 %9
30+
%12 = OpTypePointer Output %6
31+
%13 = OpTypeVoid
32+
%14 = OpTypeFunction %13
33+
%2 = OpVariable %11 Input
34+
%7 = OpTypeStruct %10 %9
35+
%8 = OpTypeStruct %10 %9
36+
%3 = OpVariable %12 Output
37+
%1 = OpFunction %13 None %14
38+
%15 = OpLabel
39+
%16 = OpLoad %5 %2
40+
%17 = OpCompositeExtract %10 %16 0
41+
%18 = OpCompositeExtract %9 %16 1
42+
%19 = OpCompositeConstruct %7 %17 %18
43+
%20 = OpCompositeExtract %9 %19 0 0
44+
%21 = OpCompositeExtract %9 %19 0 1
45+
%22 = OpCompositeExtract %9 %19 0 2
46+
%23 = OpCompositeConstruct %10 %20 %21 %22
47+
%24 = OpCompositeExtract %9 %19 1
48+
%25 = OpCompositeConstruct %8 %23 %24
49+
%26 = OpCompositeExtract %10 %25 0
50+
%27 = OpCompositeExtract %9 %25 1
51+
%28 = OpCompositeConstruct %6 %26 %27
52+
OpStore %3 %28
53+
OpNoLine
54+
OpReturn
55+
OpFunctionEnd

0 commit comments

Comments
 (0)