Skip to content

Commit cccb82e

Browse files
authored
[HLSL][SPIRV] Allow large z value in numthreads (#144934)
The current validation checks for numthreads assume that the target is DXIL so the version checks inadvertently issue error when targeting SPIR-V.
1 parent 879a557 commit cccb82e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,12 +1230,15 @@ void SemaHLSL::handleRootSignatureAttr(Decl *D, const ParsedAttr &AL) {
12301230
void SemaHLSL::handleNumThreadsAttr(Decl *D, const ParsedAttr &AL) {
12311231
llvm::VersionTuple SMVersion =
12321232
getASTContext().getTargetInfo().getTriple().getOSVersion();
1233+
bool IsDXIL = getASTContext().getTargetInfo().getTriple().getArch() ==
1234+
llvm::Triple::dxil;
1235+
12331236
uint32_t ZMax = 1024;
12341237
uint32_t ThreadMax = 1024;
1235-
if (SMVersion.getMajor() <= 4) {
1238+
if (IsDXIL && SMVersion.getMajor() <= 4) {
12361239
ZMax = 1;
12371240
ThreadMax = 768;
1238-
} else if (SMVersion.getMajor() == 5) {
1241+
} else if (IsDXIL && SMVersion.getMajor() == 5) {
12391242
ZMax = 64;
12401243
ThreadMax = 1024;
12411244
}

clang/test/SemaHLSL/num_threads.hlsl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-compute -x hlsl -ast-dump -o - %s -DFAIL -verify
1111
// RUN: %clang_cc1 -triple dxil-pc-shadermodel4.0-compute -x hlsl -ast-dump -o - %s -DFAIL -verify
1212

13+
// RUN: %clang_cc1 -triple spirv-pc-vulkan1.3-compute -x hlsl -ast-dump -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
14+
1315
#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
1416
#ifdef FAIL
1517

@@ -88,24 +90,30 @@ int entry() {
8890

8991
// Because these two attributes match, they should both appear in the AST
9092
[numthreads(2,2,1)]
91-
// CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:90:2, col:18> 2 2 1
93+
// CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:{{[0-9]+}}:2, col:18> 2 2 1
9294
int secondFn();
9395

9496
[numthreads(2,2,1)]
95-
// CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:94:2, col:18> 2 2 1
97+
// CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:{{[0-9]+}}:2, col:18> 2 2 1
9698
int secondFn() {
9799
return 1;
98100
}
99101

100102
[numthreads(4,2,1)]
101-
// CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:100:2, col:18> 4 2 1
103+
// CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:{{[0-9]+}}:2, col:18> 4 2 1
102104
int onlyOnForwardDecl();
103105

104-
// CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:100:2, col:18> Inherited 4 2 1
106+
// CHECK: HLSLNumThreadsAttr 0x{{[0-9a-fA-F]+}} <line:{{[0-9]+}}:2, col:18> Inherited 4 2 1
105107
int onlyOnForwardDecl() {
106108
return 1;
107109
}
108110

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+
109117
#else // Vertex and Pixel only beyond here
110118
// expected-error-re@+1 {{attribute 'numthreads' is unsupported in '{{[A-Za-z]+}}' shaders, requires one of the following: compute, amplification, mesh}}
111119
[numthreads(1,1,1)]

0 commit comments

Comments
 (0)