Skip to content

Commit 9b2e89d

Browse files
author
Jack Elliott
committed
Handle difference between MS and CS/AS and add a simple test
1 parent 214553d commit 9b2e89d

4 files changed

Lines changed: 110 additions & 11 deletions

File tree

include/dxc/DxilContainer/DxilPipelineStateValidation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ struct PSVRuntimeInfo3 : public PSVRuntimeInfo2 {
176176
};
177177

178178
struct PSVRuntimeInfo4 : public PSVRuntimeInfo3 {
179-
uint32_t GroupSharedMemoryLimit;
179+
uint32_t GroupSharedLimit;
180180
};
181181

182182
enum class PSVResourceType {

lib/DxilContainer/DxilPipelineStateValidation.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void hlsl::SetShaderProps(PSVRuntimeInfo4 *pInfo4, const DxilModule &DM) {
313313
case ShaderModel::Kind::Compute:
314314
case ShaderModel::Kind::Mesh:
315315
case ShaderModel::Kind::Amplification:
316-
pInfo4->GroupSharedMemoryLimit = DM.GetGroupSharedLimit();
316+
pInfo4->GroupSharedLimit = DM.GetGroupSharedLimit();
317317
break;
318318
default:
319319
break;
@@ -825,8 +825,8 @@ void hlsl::PrintPSVRuntimeInfo(llvm::raw_ostream &OS, PSVRuntimeInfo0 *pInfo0,
825825
<< pInfo2->NumThreadsY << "," << pInfo2->NumThreadsZ << ")\n";
826826
}
827827
if (pInfo4) {
828-
OS << Comment << " GroupSharedMemoryLimit="
829-
<< pInfo4->GroupSharedMemoryLimit << "\n";
828+
OS << Comment << " GroupSharedLimit="
829+
<< pInfo4->GroupSharedLimit << "\n";
830830
}
831831
break;
832832
case PSVShaderKind::Amplification:
@@ -836,8 +836,8 @@ void hlsl::PrintPSVRuntimeInfo(llvm::raw_ostream &OS, PSVRuntimeInfo0 *pInfo0,
836836
<< pInfo2->NumThreadsY << "," << pInfo2->NumThreadsZ << ")\n";
837837
}
838838
if (pInfo4) {
839-
OS << Comment << " GroupSharedMemoryLimit="
840-
<< pInfo4->GroupSharedMemoryLimit << "\n";
839+
OS << Comment << " GroupSharedLimit="
840+
<< pInfo4->GroupSharedLimit << "\n";
841841
}
842842
break;
843843
case PSVShaderKind::Mesh:
@@ -866,8 +866,8 @@ void hlsl::PrintPSVRuntimeInfo(llvm::raw_ostream &OS, PSVRuntimeInfo0 *pInfo0,
866866
<< pInfo2->NumThreadsY << "," << pInfo2->NumThreadsZ << ")\n";
867867
}
868868
if (pInfo4) {
869-
OS << Comment << " GroupSharedMemoryLimit="
870-
<< pInfo4->GroupSharedMemoryLimit << "\n";
869+
OS << Comment << " GroupSharedLimit="
870+
<< pInfo4->GroupSharedLimit << "\n";
871871
}
872872
break;
873873
case PSVShaderKind::Library:

tools/clang/lib/CodeGen/CGHLSLMS.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,8 +1647,6 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) {
16471647
}
16481648

16491649
if (const HLSLGroupSharedLimitAttr *Attr = FD->getAttr<HLSLGroupSharedLimitAttr>()) {
1650-
funcProps->groupSharedLimitBytes = Attr->getLimit();
1651-
16521650
if (isEntry && !SM->IsCS() && !SM->IsMS() && !SM->IsAS()) {
16531651
unsigned DiagID = Diags.getCustomDiagID(
16541652
DiagnosticsEngine::Error,
@@ -1657,8 +1655,24 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) {
16571655
return;
16581656
}
16591657

1658+
// Only valid for SM6.10+
1659+
if (!SM->IsSM610Plus()) {
1660+
unsigned DiagID = Diags.getCustomDiagID(
1661+
DiagnosticsEngine::Error,
1662+
"attribute GroupSharedLimit only valid for Shader Model 6.10 and above.");
1663+
Diags.Report(Attr->getLocation(), DiagID);
1664+
return;
1665+
}
1666+
1667+
funcProps->groupSharedLimitBytes = Attr->getLimit();
16601668
} else {
1661-
funcProps->groupSharedLimitBytes = DXIL::kMaxTGSMSize;
1669+
if (SM->IsMS()) { // Fallback to default limits
1670+
funcProps->groupSharedLimitBytes = DXIL::kMaxMSSMSize; // 28k For MS
1671+
} else if (SM->IsAS() || SM->IsCS()) {
1672+
funcProps->groupSharedLimitBytes = DXIL::kMaxTGSMSize; // 32k For AS/CS
1673+
} else {
1674+
funcProps->groupSharedLimitBytes = 0;
1675+
}
16621676
}
16631677

16641678
// Hull shader.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// RUN: %dxc -E MainPass -T cs_6_10 %s | FileCheck %s
2+
3+
#define NUM_BYTES_OF_SHARED_MEM (32*1024)
4+
#define NUM_DWORDS_SHARED_MEM (NUM_BYTES_OF_SHARED_MEM / 4)
5+
#define THREAD_GROUP_SIZE_X 1024
6+
7+
groupshared uint g_testBufferPASS[NUM_DWORDS_SHARED_MEM];
8+
9+
RWStructuredBuffer <uint> g_output : register(u0);
10+
11+
// CHECK: @MainPass
12+
13+
[GroupSharedLimit(NUM_BYTES_OF_SHARED_MEM)]
14+
[numthreads(THREAD_GROUP_SIZE_X, 1, 1)]
15+
void MainPass( uint3 DTid : SV_DispatchThreadID )
16+
{
17+
uint iterations = NUM_DWORDS_SHARED_MEM / THREAD_GROUP_SIZE_X;
18+
19+
for (uint i = 0; i < iterations; i++)
20+
{
21+
uint index = DTid.x + i * THREAD_GROUP_SIZE_X;
22+
g_testBufferPASS[index] = index;
23+
}
24+
25+
// synchronize all threads in the group
26+
GroupMemoryBarrierWithGroupSync();
27+
28+
// write the shared data to the output buffer
29+
for (uint i = 0; i < iterations; i++)
30+
{
31+
uint index = DTid.x + i * THREAD_GROUP_SIZE_X;
32+
g_output[index] = g_testBufferPASS[index];
33+
}
34+
}
35+
36+
// RUN: not %dxc -E MainFail -T cs_6_10 %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
37+
// CHECK-ERROR: Total Thread Group Shared Memory storage is 32772, exceeded 32768.
38+
39+
groupshared uint g_testBufferFAIL[NUM_DWORDS_SHARED_MEM + 1];
40+
41+
[GroupSharedLimit(NUM_BYTES_OF_SHARED_MEM)]
42+
[numthreads(THREAD_GROUP_SIZE_X, 1, 1)]
43+
void MainFail( uint3 DTid : SV_DispatchThreadID )
44+
{
45+
uint iterations = NUM_DWORDS_SHARED_MEM / THREAD_GROUP_SIZE_X;
46+
47+
for (uint i = 0; i < iterations; i++)
48+
{
49+
uint index = DTid.x + i * THREAD_GROUP_SIZE_X;
50+
g_testBufferFAIL[index] = index;
51+
}
52+
53+
// synchronize all threads in the group
54+
GroupMemoryBarrierWithGroupSync();
55+
56+
// write the shared data to the output buffer
57+
for (uint i = 0; i < iterations; i++)
58+
{
59+
uint index = DTid.x + i * THREAD_GROUP_SIZE_X;
60+
g_output[index] = g_testBufferFAIL[index];
61+
}
62+
}
63+
64+
// RUN: not %dxc -E MainFail2 -T cs_6_10 %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
65+
[numthreads(THREAD_GROUP_SIZE_X, 1, 1)]
66+
void MainFail2( uint3 DTid : SV_DispatchThreadID )
67+
{
68+
uint iterations = NUM_DWORDS_SHARED_MEM / THREAD_GROUP_SIZE_X;
69+
70+
for (uint i = 0; i < iterations; i++)
71+
{
72+
uint index = DTid.x + i * THREAD_GROUP_SIZE_X;
73+
g_testBufferFAIL[index] = index;
74+
}
75+
76+
// synchronize all threads in the group
77+
GroupMemoryBarrierWithGroupSync();
78+
79+
// write the shared data to the output buffer
80+
for (uint i = 0; i < iterations; i++)
81+
{
82+
uint index = DTid.x + i * THREAD_GROUP_SIZE_X;
83+
g_output[index] = g_testBufferFAIL[index];
84+
}
85+
}

0 commit comments

Comments
 (0)