Skip to content

Commit 6f59c0f

Browse files
committed
asm fn_ptr: entry point tests, buffer access failing
1 parent aa22a94 commit 6f59c0f

12 files changed

+474
-0
lines changed
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-spv1.0
10+
// ignore-spv1.1
11+
// ignore-spv1.2
12+
// ignore-spv1.3
13+
// ignore-vulkan1.0
14+
// ignore-vulkan1.1
15+
16+
use core::arch::asm;
17+
use spirv_std::glam::*;
18+
use spirv_std::spirv;
19+
20+
#[inline]
21+
pub fn main(input: Vec4, out: &mut Vec4) {
22+
*out = input + 1.;
23+
}
24+
25+
pub fn entry() {
26+
unsafe {
27+
let mut input = Vec4::default();
28+
asm! {
29+
"%input = OpVariable typeof{input} Input",
30+
"OpName %input \"input\"",
31+
"OpDecorate %input Location 0",
32+
"%tmp = OpLoad typeof*{input} %input",
33+
"OpStore {input} %tmp",
34+
input = in(reg) &mut input,
35+
};
36+
let mut output = Vec4::default();
37+
main(input, &mut output);
38+
asm! {
39+
"%output = OpVariable typeof{output} Output",
40+
"OpName %output \"output\"",
41+
"OpDecorate %output Location 0",
42+
"%tmp = OpLoad _ {output}",
43+
"OpStore %output %tmp",
44+
output = in(reg) &output,
45+
};
46+
}
47+
}
48+
49+
/// we don't support `global_asm!` yet
50+
pub fn non_global_asm() {
51+
unsafe {
52+
asm! {
53+
"OpEntryPoint Vertex {entry} \"main\"",
54+
entry = in(reg) entry,
55+
}
56+
}
57+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
OpCapability Shader
2+
OpMemoryModel Logical Simple
3+
OpEntryPoint Vertex %1 "main" %2 %3
4+
OpName %2 "input"
5+
OpName %3 "output"
6+
OpName %1 "entry1_global_asm::entry"
7+
OpDecorate %2 Location 0
8+
OpDecorate %3 Location 0
9+
%7 = OpTypeVoid
10+
%8 = OpTypeFunction %7
11+
%9 = OpTypeFloat 32
12+
%10 = OpTypeVector %9 4
13+
%11 = OpTypePointer Input %10
14+
%2 = OpVariable %11 Input
15+
%12 = OpConstant %9 1
16+
%13 = OpTypePointer Output %10
17+
%3 = OpVariable %13 Output
18+
%1 = OpFunction %7 None %8
19+
%14 = OpLabel
20+
%15 = OpLoad %10 %2
21+
%16 = OpCompositeConstruct %10 %12 %12 %12 %12
22+
%17 = OpFAdd %10 %15 %16
23+
OpStore %3 %17
24+
OpNoLine
25+
OpReturn
26+
OpFunctionEnd
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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-spv1.0
10+
// ignore-spv1.1
11+
// ignore-spv1.2
12+
// ignore-spv1.3
13+
// ignore-vulkan1.0
14+
// ignore-vulkan1.1
15+
16+
use spirv_std::glam::*;
17+
use spirv_std::spirv;
18+
19+
#[spirv(vertex)]
20+
pub fn main(input: Vec4, output: &mut Vec4) {
21+
*output = input + 1.;
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
OpCapability Shader
2+
OpMemoryModel Logical Simple
3+
OpEntryPoint Vertex %1 "main" %2 %3
4+
OpName %2 "input"
5+
OpName %3 "output"
6+
OpDecorate %2 Location 0
7+
OpDecorate %3 Location 0
8+
%7 = OpTypeFloat 32
9+
%8 = OpTypeVector %7 4
10+
%9 = OpTypePointer Input %8
11+
%10 = OpTypePointer Output %8
12+
%11 = OpTypeVoid
13+
%12 = OpTypeFunction %11
14+
%2 = OpVariable %9 Input
15+
%13 = OpConstant %7 1
16+
%3 = OpVariable %10 Output
17+
%1 = OpFunction %11 None %12
18+
%14 = OpLabel
19+
%15 = OpLoad %8 %2
20+
%16 = OpCompositeConstruct %8 %13 %13 %13 %13
21+
%17 = OpFAdd %8 %15 %16
22+
OpStore %3 %17
23+
OpNoLine
24+
OpReturn
25+
OpFunctionEnd
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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-spv1.0
10+
// ignore-spv1.1
11+
// ignore-spv1.2
12+
// ignore-spv1.3
13+
// ignore-vulkan1.0
14+
// ignore-vulkan1.1
15+
16+
use core::arch::asm;
17+
use spirv_std::glam::*;
18+
use spirv_std::spirv;
19+
20+
#[inline]
21+
pub fn main(frag_coord: Vec4, viewport_size: &Vec2, output: &mut Vec4) {
22+
*output = Vec4::from((frag_coord.xy() / *viewport_size, 0., 1.));
23+
}
24+
25+
pub fn entry() {
26+
unsafe {
27+
let mut frag_coord = Vec4::default();
28+
asm! {
29+
"%frag_coord = OpVariable typeof{frag_coord} Input",
30+
"OpDecorate %frag_coord BuiltIn FragCoord",
31+
"OpName %frag_coord \"frag_coord\"",
32+
"%tmp = OpLoad typeof*{frag_coord} %frag_coord",
33+
"OpStore {frag_coord} %tmp",
34+
frag_coord = in(reg) &mut frag_coord,
35+
};
36+
37+
#[derive(Copy, Clone, Default)]
38+
struct ViewportBuffer(Vec2);
39+
let mut viewport_size = &ViewportBuffer::default();
40+
asm! {
41+
"OpDecorate typeof*{viewport_size} Block",
42+
"%viewport_size = OpVariable typeof{viewport_size} Input",
43+
"OpDecorate %viewport_size DescriptorSet 0",
44+
"OpDecorate %viewport_size Binding 0",
45+
"OpDecorate %viewport_size NonWritable",
46+
"OpName %viewport_size \"viewport_size\"",
47+
"%tmp = OpLoad typeof*{viewport_size} %viewport_size",
48+
"OpStore {viewport_size} %tmp",
49+
viewport_size = in(reg) &mut viewport_size,
50+
};
51+
52+
let mut output = Vec4::default();
53+
main(frag_coord, &viewport_size.0, &mut output);
54+
asm! {
55+
"%output = OpVariable typeof{output} Output",
56+
"OpName %output \"output\"",
57+
"OpDecorate %output Location 0",
58+
"%tmp = OpLoad _ {output}",
59+
"OpStore %output %tmp",
60+
output = in(reg) &output,
61+
};
62+
}
63+
}
64+
65+
/// we don't support `global_asm!` yet
66+
pub fn non_global_asm() {
67+
unsafe {
68+
asm! {
69+
"OpEntryPoint Fragment {entry} \"main\"",
70+
"OpExecutionMode {entry} OriginUpperLeft",
71+
entry = in(reg) entry,
72+
}
73+
}
74+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
OpCapability Shader
2+
OpMemoryModel Logical Simple
3+
OpEntryPoint Fragment %1 "main" %2 %3 %4
4+
OpExecutionMode %1 OriginUpperLeft
5+
OpName %2 "frag_coord"
6+
OpName %3 "viewport_size"
7+
OpName %9 "(spirv_std::glam::Vec2, f32, f32)"
8+
OpMemberName %9 0 "0"
9+
OpMemberName %9 1 "1"
10+
OpMemberName %9 2 "2"
11+
OpName %4 "output"
12+
OpName %1 "entry2_global_asm::entry"
13+
OpDecorate %2 BuiltIn FragCoord
14+
OpDecorate %10 Block
15+
OpDecorate %3 NonWritable
16+
OpDecorate %3 Binding 0
17+
OpDecorate %3 DescriptorSet 0
18+
OpMemberDecorate %9 0 Offset 0
19+
OpMemberDecorate %9 1 Offset 8
20+
OpMemberDecorate %9 2 Offset 12
21+
OpDecorate %4 Location 0
22+
%11 = OpTypeVoid
23+
%12 = OpTypeFunction %11
24+
%13 = OpTypeFloat 32
25+
%14 = OpTypeVector %13 4
26+
%15 = OpTypePointer Input %14
27+
%2 = OpVariable %15 Input
28+
%16 = OpTypeVector %13 2
29+
%10 = OpTypePointer Function %16
30+
%17 = OpTypePointer Input %10
31+
%3 = OpVariable %17 Input
32+
%18 = OpTypePointer Function %13
33+
%19 = OpTypeInt 32 0
34+
%20 = OpConstant %19 0
35+
%21 = OpConstant %19 1
36+
%9 = OpTypeStruct %16 %13 %13
37+
%22 = OpUndef %9
38+
%23 = OpConstant %13 0
39+
%24 = OpConstant %13 1
40+
%25 = OpTypePointer Output %14
41+
%4 = OpVariable %25 Output
42+
%1 = OpFunction %11 None %12
43+
%26 = OpLabel
44+
%27 = OpLoad %14 %2
45+
%28 = OpLoad %10 %3
46+
%29 = OpCompositeExtract %13 %27 0
47+
%30 = OpCompositeExtract %13 %27 1
48+
%31 = OpInBoundsAccessChain %18 %28 %20
49+
%32 = OpLoad %13 %31
50+
%33 = OpInBoundsAccessChain %18 %28 %21
51+
%34 = OpLoad %13 %33
52+
%35 = OpFDiv %13 %29 %32
53+
%36 = OpFDiv %13 %30 %34
54+
%37 = OpCompositeInsert %9 %35 %22 0 0
55+
%38 = OpCompositeInsert %9 %36 %37 0 1
56+
%39 = OpCompositeInsert %9 %23 %38 1
57+
%40 = OpCompositeInsert %9 %24 %39 2
58+
%41 = OpCompositeExtract %13 %40 0 0
59+
%42 = OpCompositeExtract %13 %40 0 1
60+
%43 = OpCompositeConstruct %14 %41 %42 %23 %24
61+
OpStore %4 %43
62+
OpNoLine
63+
OpReturn
64+
OpFunctionEnd
65+
error: error:0:0 - Block decoration on target <id> '10[%_ptr_Function_v2float]' must be a structure type
66+
OpDecorate %_ptr_Function_v2float Block
67+
|
68+
= note: spirv-val failed
69+
= note: module `$TEST_BUILD_DIR/spirv-attr/entry/entry2_global_asm.vulkan1.2`
70+
71+
error: aborting due to 1 previous error
72+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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-spv1.0
10+
// ignore-spv1.1
11+
// ignore-spv1.2
12+
// ignore-spv1.3
13+
// ignore-vulkan1.0
14+
// ignore-vulkan1.1
15+
16+
use spirv_std::glam::*;
17+
use spirv_std::spirv;
18+
19+
#[spirv(fragment)]
20+
pub fn main(
21+
#[spirv(frag_coord)] frag_coord: Vec4,
22+
#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] viewport_size: &Vec2,
23+
output: &mut Vec4,
24+
) {
25+
*output = Vec4::from((frag_coord.xy() / *viewport_size, 0., 1.));
26+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
OpCapability Shader
2+
OpMemoryModel Logical Simple
3+
OpEntryPoint Fragment %1 "main" %2 %3 %4
4+
OpExecutionMode %1 OriginUpperLeft
5+
OpName %2 "frag_coord"
6+
OpName %3 "viewport_size"
7+
OpName %9 "(spirv_std::glam::Vec2, f32, f32)"
8+
OpMemberName %9 0 "0"
9+
OpMemberName %9 1 "1"
10+
OpMemberName %9 2 "2"
11+
OpName %4 "output"
12+
OpDecorate %10 Block
13+
OpMemberDecorate %10 0 Offset 0
14+
OpDecorate %2 BuiltIn FragCoord
15+
OpDecorate %3 NonWritable
16+
OpDecorate %3 Binding 0
17+
OpDecorate %3 DescriptorSet 0
18+
OpMemberDecorate %9 0 Offset 0
19+
OpMemberDecorate %9 1 Offset 8
20+
OpMemberDecorate %9 2 Offset 12
21+
OpDecorate %4 Location 0
22+
%11 = OpTypeFloat 32
23+
%12 = OpTypeVector %11 4
24+
%13 = OpTypePointer Input %12
25+
%14 = OpTypeVector %11 2
26+
%10 = OpTypeStruct %14
27+
%15 = OpTypePointer StorageBuffer %10
28+
%16 = OpTypePointer Output %12
29+
%17 = OpTypeVoid
30+
%18 = OpTypeFunction %17
31+
%2 = OpVariable %13 Input
32+
%19 = OpTypePointer StorageBuffer %14
33+
%3 = OpVariable %15 StorageBuffer
34+
%20 = OpTypeInt 32 0
35+
%21 = OpConstant %20 0
36+
%22 = OpTypePointer StorageBuffer %11
37+
%23 = OpConstant %20 1
38+
%9 = OpTypeStruct %14 %11 %11
39+
%24 = OpUndef %9
40+
%25 = OpConstant %11 0
41+
%26 = OpConstant %11 1
42+
%4 = OpVariable %16 Output
43+
%1 = OpFunction %17 None %18
44+
%27 = OpLabel
45+
%28 = OpLoad %12 %2
46+
%29 = OpInBoundsAccessChain %19 %3 %21
47+
%30 = OpCompositeExtract %11 %28 0
48+
%31 = OpCompositeExtract %11 %28 1
49+
%32 = OpInBoundsAccessChain %22 %29 %21
50+
%33 = OpLoad %11 %32
51+
%34 = OpInBoundsAccessChain %22 %29 %23
52+
%35 = OpLoad %11 %34
53+
%36 = OpFDiv %11 %30 %33
54+
%37 = OpFDiv %11 %31 %35
55+
%38 = OpCompositeInsert %9 %36 %24 0 0
56+
%39 = OpCompositeInsert %9 %37 %38 0 1
57+
%40 = OpCompositeInsert %9 %25 %39 1
58+
%41 = OpCompositeInsert %9 %26 %40 2
59+
%42 = OpCompositeExtract %11 %41 0 0
60+
%43 = OpCompositeExtract %11 %41 0 1
61+
%44 = OpCompositeConstruct %12 %42 %43 %25 %26
62+
OpStore %4 %44
63+
OpNoLine
64+
OpReturn
65+
OpFunctionEnd

0 commit comments

Comments
 (0)