Skip to content

Commit 28313a2

Browse files
committed
tests: adjust for lack of PassMode::{Indirect, Cast}.
1 parent 2dc88f2 commit 28313a2

10 files changed

+158
-40
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This is a similar setup to the `issue-731` test, but instead of "just" the
2+
// missing copy out of the global (`Input`) `OpVariable`, small enough types
3+
// would fail much earlier (by generating unsupported pointer casts).
4+
// (Just like `issue-373`, the problem was the use of `PassMode::Cast`, through
5+
// the default Rust ABI adjustments, that we now override through query hooks)
6+
7+
// build-pass
8+
// compile-flags: -C llvm-args=--disassemble-entry=main
9+
10+
use spirv_std as _;
11+
12+
#[spirv(fragment)]
13+
pub fn main(mut in_array: [f32; 2], out_array: &mut [f32; 2]) {
14+
in_array[0] += 1.0;
15+
*out_array = in_array;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
%1 = OpFunction %2 None %3
2+
%4 = OpLabel
3+
%5 = OpVariable %6 Function
4+
%7 = OpVariable %6 Function
5+
OpLine %8 13 12
6+
%9 = OpLoad %10 %11
7+
OpLine %8 13 0
8+
OpStore %5 %9
9+
OpLine %8 14 4
10+
%12 = OpInBoundsAccessChain %13 %5 %14
11+
%15 = OpInBoundsAccessChain %13 %5 %14
12+
%16 = OpLoad %17 %15
13+
%18 = OpFAdd %17 %16 %19
14+
OpStore %12 %18
15+
OpLine %8 15 17
16+
OpCopyMemory %7 %5
17+
OpLine %8 15 4
18+
OpCopyMemory %20 %7
19+
OpLine %8 16 1
20+
OpReturn
21+
OpFunctionEnd

tests/ui/dis/issue-373.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Test that returning a single-scalar-field `#[repr(C)] struct` doesn't generate
2+
// unsupported pointer casts (the problem was the use of `PassMode::Cast`, through
3+
// the default Rust ABI adjustments, that we now override through query hooks).
4+
5+
// build-pass
6+
// compile-flags: -C llvm-args=--disassemble-entry=main
7+
8+
use spirv_std as _;
9+
10+
#[derive(Copy, Clone)]
11+
#[repr(C)]
12+
pub struct S {
13+
x: f32,
14+
}
15+
16+
fn f() -> S {
17+
S { x: 2.0 }
18+
}
19+
20+
#[spirv(fragment)]
21+
pub fn main(out: &mut f32) {
22+
*out = f().x;
23+
}

tests/ui/dis/issue-373.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%1 = OpFunction %2 None %3
2+
%4 = OpLabel
3+
OpLine %5 22 11
4+
%6 = OpFunctionCall %7 %8
5+
OpLine %5 22 11
6+
%9 = OpCompositeExtract %10 %6 0
7+
OpLine %5 22 4
8+
OpStore %11 %9
9+
OpLine %5 23 1
10+
OpReturn
11+
OpFunctionEnd

tests/ui/dis/issue-723-indirect-input.rs

-17
This file was deleted.

tests/ui/dis/issue-723-indirect-input.stderr

-23
This file was deleted.

tests/ui/dis/issue-731.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Test that non-immediate (i.e. not one of scalar/scalar-pair/vector) inputs
2+
// get properly copied out of the global (`Input`) `OpVariable` and mutation is
3+
// only ever done on `fn`-local `OpVariable`s, not on the original global.
4+
5+
// build-pass
6+
// compile-flags: -C llvm-args=--disassemble-entry=main
7+
8+
use spirv_std as _;
9+
10+
#[spirv(fragment)]
11+
pub fn main(mut in_array: [f32; 3], out_array: &mut [f32; 3]) {
12+
in_array[0] += 1.0;
13+
*out_array = in_array;
14+
}

tests/ui/dis/issue-731.stderr

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
%1 = OpFunction %2 None %3
2+
%4 = OpLabel
3+
%5 = OpVariable %6 Function
4+
%7 = OpVariable %6 Function
5+
OpLine %8 11 12
6+
%9 = OpLoad %10 %11
7+
OpLine %8 11 0
8+
OpStore %5 %9
9+
OpLine %8 12 4
10+
%12 = OpInBoundsAccessChain %13 %5 %14
11+
%15 = OpInBoundsAccessChain %13 %5 %14
12+
%16 = OpLoad %17 %15
13+
%18 = OpFAdd %17 %16 %19
14+
OpStore %12 %18
15+
OpLine %8 13 17
16+
OpCopyMemory %7 %5
17+
OpLine %8 13 4
18+
OpCopyMemory %20 %7
19+
OpLine %8 14 1
20+
OpReturn
21+
OpFunctionEnd

tests/ui/dis/pass-mode-cast-struct.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Test that a small enough `struct` doesn't generate unsupported pointer casts.
2+
// (Just like `issue-373`, the problem was the use of `PassMode::Cast`, through
3+
// the default Rust ABI adjustments, that we now override through query hooks)
4+
5+
// build-pass
6+
// compile-flags: -C llvm-args=--disassemble-entry=main
7+
8+
use spirv_std as _;
9+
10+
struct Foo {
11+
a: u32,
12+
b: u8,
13+
c: u8,
14+
}
15+
16+
impl Foo {
17+
fn unpack(data: u64) -> Self {
18+
Self {
19+
a: (data >> 16 & 0xffffff) as u32,
20+
b: (data & 0xff >> 8) as u8,
21+
c: (data & 0xff) as u8,
22+
}
23+
}
24+
}
25+
26+
#[spirv(fragment)]
27+
pub fn main(in_packed: u64, out_sum: &mut u32) {
28+
let foo = Foo::unpack(in_packed);
29+
*out_sum = foo.a + (foo.b + foo.c) as u32;
30+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
%1 = OpFunction %2 None %3
2+
%4 = OpLabel
3+
OpLine %5 27 12
4+
%6 = OpLoad %7 %8
5+
OpLine %5 28 14
6+
%9 = OpFunctionCall %10 %11 %6
7+
OpLine %5 29 15
8+
%12 = OpCompositeExtract %13 %9 0
9+
OpLine %5 29 24
10+
%14 = OpCompositeExtract %15 %9 1
11+
OpLine %5 29 32
12+
%16 = OpCompositeExtract %15 %9 2
13+
OpLine %5 29 23
14+
%17 = OpIAdd %15 %14 %16
15+
OpLine %5 29 23
16+
%18 = OpUConvert %13 %17
17+
OpLine %5 29 4
18+
%19 = OpIAdd %13 %12 %18
19+
OpStore %20 %19
20+
OpLine %5 30 1
21+
OpReturn
22+
OpFunctionEnd

0 commit comments

Comments
 (0)