Skip to content

Commit 7cd7800

Browse files
fluffysquirrelsFirestar99
authored andcommitted
dedup builtins compiletest: add test for duplicate builtin declarations, failing
1 parent f52624e commit 7cd7800

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// build-pass
2+
// compile-flags: -C llvm-args=--disassemble
3+
// normalize-stderr-test "OpLine .*\n" -> ""
4+
// normalize-stderr-test "OpSource .*\n" -> ""
5+
// normalize-stderr-test "%\d+ = OpString .*\n" -> ""
6+
// normalize-stderr-test "OpCapability VulkanMemoryModel\n" -> ""
7+
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
8+
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"
9+
// normalize-stderr-test "; .*\n" -> ""
10+
11+
// ignore-spv1.0
12+
// ignore-spv1.1
13+
// ignore-spv1.2
14+
// ignore-vulkan1.0
15+
// ignore-vulkan1.1
16+
17+
use core::arch::asm;
18+
use spirv_std::{glam::*, spirv};
19+
20+
#[spirv(compute(threads(1)))]
21+
pub fn entry_1(#[spirv(local_invocation_index)] _local_idx: u32) {
22+
let _: u32 = local_invocation_index();
23+
let _: u32 = local_invocation_index();
24+
let _: u32 = sub_1();
25+
let _: u32 = sub_2();
26+
}
27+
28+
#[spirv(compute(threads(1)))]
29+
pub fn entry_2(#[spirv(local_invocation_index)] _local_idx: u32) {
30+
let _: u32 = local_invocation_index();
31+
let _: u32 = sub_1();
32+
let _: u32 = sub_2();
33+
}
34+
35+
#[inline(never)]
36+
fn sub_1() -> u32 {
37+
local_invocation_index()
38+
}
39+
40+
#[inline(never)]
41+
fn sub_2() -> u32 {
42+
local_invocation_index()
43+
}
44+
45+
#[inline]
46+
pub fn local_invocation_index() -> u32 {
47+
unsafe {
48+
let result = 0;
49+
asm! {
50+
"%builtin = OpVariable typeof{result} Input",
51+
"OpDecorate %builtin BuiltIn LocalInvocationIndex",
52+
"%result = OpLoad typeof*{result} %builtin",
53+
"OpStore {result} %result",
54+
result = in(reg) &result,
55+
}
56+
result
57+
}
58+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
OpCapability Shader
2+
OpMemoryModel Logical Simple
3+
OpEntryPoint GLCompute %1 "entry_1" %2 %3
4+
OpEntryPoint GLCompute %4 "entry_2" %2 %3
5+
OpExecutionMode %1 LocalSize 1 1 1
6+
OpExecutionMode %4 LocalSize 1 1 1
7+
OpName %6 "builtin_duplicates::entry_1"
8+
OpName %7 "builtin_duplicates::sub_1"
9+
OpName %8 "builtin_duplicates::sub_2"
10+
OpName %9 "builtin_duplicates::entry_2"
11+
OpDecorate %2 BuiltIn LocalInvocationIndex
12+
OpDecorate %3 BuiltIn LocalInvocationIndex
13+
%10 = OpTypeInt 32 0
14+
%11 = OpTypePointer Input %10
15+
%12 = OpTypeVoid
16+
%13 = OpTypeFunction %12
17+
%2 = OpVariable %11 Input
18+
%14 = OpTypeFunction %12 %10
19+
%3 = OpVariable %11 Input
20+
%15 = OpTypeFunction %10
21+
%1 = OpFunction %12 None %13
22+
%16 = OpLabel
23+
%17 = OpLoad %10 %2
24+
%18 = OpFunctionCall %12 %6 %17
25+
OpNoLine
26+
OpReturn
27+
OpFunctionEnd
28+
%6 = OpFunction %12 None %14
29+
%19 = OpFunctionParameter %10
30+
%20 = OpLabel
31+
%21 = OpLoad %10 %3
32+
%22 = OpLoad %10 %3
33+
%23 = OpFunctionCall %10 %7
34+
%24 = OpFunctionCall %10 %8
35+
OpNoLine
36+
OpReturn
37+
OpFunctionEnd
38+
%7 = OpFunction %10 DontInline %15
39+
%25 = OpLabel
40+
%26 = OpLoad %10 %3
41+
OpNoLine
42+
OpReturnValue %26
43+
OpFunctionEnd
44+
%8 = OpFunction %10 DontInline %15
45+
%27 = OpLabel
46+
%28 = OpLoad %10 %3
47+
OpNoLine
48+
OpReturnValue %28
49+
OpFunctionEnd
50+
%4 = OpFunction %12 None %13
51+
%29 = OpLabel
52+
%30 = OpLoad %10 %2
53+
%31 = OpFunctionCall %12 %9 %30
54+
OpNoLine
55+
OpReturn
56+
OpFunctionEnd
57+
%9 = OpFunction %12 None %14
58+
%32 = OpFunctionParameter %10
59+
%33 = OpLabel
60+
%34 = OpLoad %10 %3
61+
%35 = OpFunctionCall %10 %7
62+
%36 = OpFunctionCall %10 %8
63+
OpNoLine
64+
OpReturn
65+
OpFunctionEnd
66+
error: error:0:0 - [VUID-StandaloneSpirv-OpEntryPoint-09658] OpEntryPoint contains duplicate input variables with LocalInvocationIndex builtin
67+
%gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
68+
|
69+
= note: spirv-val failed
70+
= note: module `$TEST_BUILD_DIR/entry/builtin_duplicates.vulkan1.2`
71+
72+
error: aborting due to 1 previous error
73+

0 commit comments

Comments
 (0)