Debian Codegraph @

clang/test/SemaHLSL/num_threads.hlsl

raw
1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-mesh -x hlsl -ast-dump -o - %s | FileCheck %s
3 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-amplification -x hlsl -ast-dump -o - %s | FileCheck %s
4 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -o - %s | FileCheck %s
5 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-pixel -x hlsl -ast-dump -o - %s -verify
6 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-vertex -x hlsl -ast-dump -o - %s -verify
7 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-hull -x hlsl -ast-dump -o - %s -verify
8 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-domain -x hlsl -ast-dump -o - %s -verify
9 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o - %s -DFAIL -verify
10 // RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-compute -x hlsl -ast-dump -o - %s -DFAIL -verify
11 // RUN: %clang_cc1 -triple dxil-pc-shadermodel4.0-compute -x hlsl -ast-dump -o - %s -DFAIL -verify
12
13 // RUN: %clang_cc1 -triple spirv-pc-vulkan1.3-compute -x hlsl -ast-dump -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
14
15 #if __SHADER_TARGET_STAGE == __SHADER_STAGE_COMPUTE || __SHADER_TARGET_STAGE == __SHADER_STAGE_MESH || __SHADER_TARGET_STAGE == __SHADER_STAGE_AMPLIFICATION || __SHADER_TARGET_STAGE == __SHADER_STAGE_LIBRARY
16 #ifdef FAIL
17
18 // expected-warning@+1 {{'numthreads' attribute only applies to global functions}}
19 [numthreads(1,1,1)]
20 struct Fido {
21 // expected-warning@+1 {{'numthreads' attribute only applies to global functions}}
22 [numthreads(1,1,1)]
23 void wag() {}
24
25 // expected-warning@+1 {{'numthreads' attribute only applies to global functions}}
26 [numthreads(1,1,1)]
27 static void oops() {}
28 };
29
30 // expected-warning@+1 {{'numthreads' attribute only applies to global functions}}
31 [numthreads(1,1,1)]
32 static void oops() {}
33
34 namespace spec {
35 // expected-warning@+1 {{'numthreads' attribute only applies to global functions}}
36 [numthreads(1,1,1)]
37 static void oops() {}
38 }
39
40 // expected-error@+1 {{'numthreads' attribute parameters do not match the previous declaration}}
41 [numthreads(1,1,1)]
42 // expected-note@+1 {{conflicting attribute is here}}
43 [numthreads(2,2,1)]
44 int doubledUp() {
45 return 1;
46 }
47
48 // expected-note@+1 {{conflicting attribute is here}}
49 [numthreads(1,1,1)]
50 int forwardDecl();
51
52 // expected-error@+1 {{'numthreads' attribute parameters do not match the previous declaration}}
53 [numthreads(2,2,1)]
54 int forwardDecl() {
55 return 1;
56 }
57
58 #if __SHADER_TARGET_MAJOR == 6
59 // expected-error@+1 {{'numthreads' attribute requires exactly 3 arguments}}
60 [numthreads]
61 // expected-error@+1 {{'numthreads' attribute requires exactly 3 arguments}}
62 [numthreads()]
63 // expected-error@+1 {{'numthreads' attribute requires exactly 3 arguments}}
64 [numthreads(1,2,3,4)]
65 // expected-error@+1 {{'numthreads' attribute requires an integer constant}}
66 [numthreads("1",2,3)]
67 // expected-error@+1 {{argument 'X' to numthreads attribute cannot exceed 1024}}
68 [numthreads(-1,2,3)]
69 // expected-error@+1 {{argument 'Y' to numthreads attribute cannot exceed 1024}}
70 [numthreads(1,-2,3)]
71 // expected-error@+1 {{argument 'Z' to numthreads attribute cannot exceed 1024}}
72 [numthreads(1,2,-3)]
73 // expected-error@+1 {{total number of threads cannot exceed 1024}}
74 [numthreads(1024,1024,1024)]
75 #elif __SHADER_TARGET_MAJOR == 5
76 // expected-error@+1 {{argument 'Z' to numthreads attribute cannot exceed 64}}
77 [numthreads(1,2,68)]
78 #else
79 // expected-error@+1 {{argument 'Z' to numthreads attribute cannot exceed 1}}
80 [numthreads(1,2,2)]
81 // expected-error@+1 {{total number of threads cannot exceed 768}}
82 [numthreads(1024,1,1)]
83 #endif // __SHADER_TARGET_MAJOR
84 #endif // FAIL
85 // CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:{{[0-9]+}}:2, col:18> 1 2 1
86 [numthreads(1,2,1)]
87 int entry() {
88 return 1;
89 }
90
91 // Because these two attributes match, they should both appear in the AST
92 [numthreads(2,2,1)]
93 // CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:{{[0-9]+}}:2, col:18> 2 2 1
94 int secondFn();
95
96 [numthreads(2,2,1)]
97 // CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:{{[0-9]+}}:2, col:18> 2 2 1
98 int secondFn() {
99 return 1;
100 }
101
102 [numthreads(4,2,1)]
103 // CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:{{[0-9]+}}:2, col:18> 4 2 1
104 int onlyOnForwardDecl();
105
106 // CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:{{[0-9]+}}:2, col:18> Inherited 4 2 1
107 int onlyOnForwardDecl() {
108 return 1;
109 }
110
111 #ifdef __spirv__
112 [numthreads(4,2,128)]
113 // CHECK-SPIRV: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:{{[0-9]+}}:2, col:20> 4 2 128
114 int largeZ();
115 #endif
116
117 #else // Vertex and Pixel only beyond here
118 // expected-error-re@+1 {{attribute 'numthreads' is unsupported in '{{[A-Za-z]+}}' shaders, requires one of the following: compute, amplification, mesh}}
119 [numthreads(1,1,1)]
120 int main() : A {
121 return 1;
122 }
123
124 #endif