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