Skip to content

Commit 795cf94

Browse files
author
Jack Elliott
committed
Add GroupSharedLimit as a shader attribute
1 parent fa3fe95 commit 795cf94

8 files changed

Lines changed: 51 additions & 0 deletions

File tree

include/dxc/DXIL/DxilFunctionProps.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct DxilFunctionProps {
117117
memset(&Node, 0, sizeof(Node));
118118
Node.LaunchType = DXIL::NodeLaunchType::Invalid;
119119
Node.LocalRootArgumentsTableIndex = -1;
120+
groupSharedLimitBytes = 0;
120121
}
121122
union {
122123
// Geometry shader.
@@ -174,6 +175,8 @@ struct DxilFunctionProps {
174175
// numThreads shared between multiple shader types and node shaders.
175176
unsigned numThreads[3];
176177

178+
unsigned groupSharedLimitBytes;
179+
177180
struct NodeProps {
178181
DXIL::NodeLaunchType LaunchType = DXIL::NodeLaunchType::Invalid;
179182
bool IsProgramEntry;

include/dxc/DXIL/DxilMetadataHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ class DxilMDHelper {
320320
static const unsigned kDxilNodeOutputsTag = 21;
321321
static const unsigned kDxilNodeMaxDispatchGridTag = 22;
322322
static const unsigned kDxilRangedWaveSizeTag = 23;
323+
static const unsigned kDxilMaxGroupSharedMemTag = 24;
323324

324325
// Node Input/Output State.
325326
static const unsigned kDxilNodeOutputIDTag = 0;

lib/DXIL/DxilMetadataHelper.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,10 @@ MDTuple *DxilMDHelper::EmitDxilEntryProperties(uint64_t rawShaderFlag,
16241624
}
16251625
MDVals.emplace_back(MDNode::get(m_Ctx, WaveSizeVal));
16261626
}
1627+
1628+
MDVals.emplace_back(Uint32ToConstMD(DxilMDHelper::kDxilMaxGroupSharedMemTag));
1629+
MDVals.emplace_back(
1630+
Uint32ToConstMD(props.groupSharedLimitBytes));
16271631
} break;
16281632
// Geometry shader.
16291633
case DXIL::ShaderKind::Geometry: {
@@ -1773,6 +1777,11 @@ void DxilMDHelper::LoadDxilEntryProperties(const MDOperand &MDO,
17731777
props.numThreads[2] = ConstMDToUint32(pNode->getOperand(2));
17741778
} break;
17751779

1780+
case DxilMDHelper::kDxilMaxGroupSharedMemTag: {
1781+
DXASSERT(props.IsCS(), "else invalid shader kind");
1782+
props.groupSharedLimitBytes = ConstMDToUint32(MDO);
1783+
} break;
1784+
17761785
case DxilMDHelper::kDxilGSStateTag: {
17771786
DXASSERT(props.IsGS(), "else invalid shader kind");
17781787
auto &GS = props.ShaderProps.GS;

lib/DxilValidation/DxilValidation.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3921,6 +3921,18 @@ static void ValidateGlobalVariables(ValidationContext &ValCtx) {
39213921
Rule = ValidationRule::SmMaxMSSMSize;
39223922
MaxSize = DXIL::kMaxMSSMSize;
39233923
}
3924+
3925+
// Check if the entry function has attribute to override TGSM size.
3926+
if (M.HasDxilEntryProps(M.GetEntryFunction())) {
3927+
DxilEntryProps &EntryProps = M.GetDxilEntryProps(M.GetEntryFunction());
3928+
if (EntryProps.props.IsCS()) {
3929+
unsigned SpecifiedTGSMSize = EntryProps.props.groupSharedLimitBytes;
3930+
if (SpecifiedTGSMSize > 0) {
3931+
MaxSize = SpecifiedTGSMSize;
3932+
}
3933+
}
3934+
}
3935+
39243936
if (TGSMSize > MaxSize) {
39253937
Module::global_iterator GI = M.GetModule()->global_end();
39263938
GlobalVariable *GV = &*GI;

tools/clang/include/clang/Basic/Attr.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,11 @@ def HLSLNumThreads: InheritableAttr {
671671
let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
672672
let Documentation = [Undocumented];
673673
}
674+
def HLSLGroupSharedLimit: InheritableAttr {
675+
let Spellings = [CXX11<"", "GroupSharedLimit", 2017>];
676+
let Args = [IntArgument<"Limit">];
677+
let Documentation = [Undocumented];
678+
}
674679
def HLSLRootSignature: InheritableAttr {
675680
let Spellings = [CXX11<"", "RootSignature", 2015>];
676681
let Args = [StringArgument<"SignatureName">];

tools/clang/lib/CodeGen/CGHLSLMS.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,21 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) {
16461646
}
16471647
}
16481648

1649+
if (const HLSLGroupSharedLimitAttr *Attr = FD->getAttr<HLSLGroupSharedLimitAttr>()) {
1650+
funcProps->groupSharedLimitBytes = Attr->getLimit();
1651+
1652+
if (isEntry && !SM->IsCS() && !SM->IsMS() && !SM->IsAS()) {
1653+
unsigned DiagID = Diags.getCustomDiagID(
1654+
DiagnosticsEngine::Error,
1655+
"attribute GroupSharedLimit only valid for CS/MS/AS.");
1656+
Diags.Report(Attr->getLocation(), DiagID);
1657+
return;
1658+
}
1659+
1660+
} else {
1661+
funcProps->groupSharedLimitBytes = DXIL::kMaxTGSMSize;
1662+
}
1663+
16491664
// Hull shader.
16501665
if (const HLSLPatchConstantFuncAttr *Attr =
16511666
FD->getAttr<HLSLPatchConstantFuncAttr>()) {

tools/clang/lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
833833
case AttributeList::AT_HLSLMaxVertexCount:
834834
case AttributeList::AT_HLSLUnroll:
835835
case AttributeList::AT_HLSLWaveSize:
836+
case AttributeList::AT_HLSLGroupSharedLimit:
836837
case AttributeList::AT_NoInline:
837838
// The following are not accepted in [attribute(param)] syntax:
838839
// case AttributeList::AT_HLSLCentroid:

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14656,6 +14656,11 @@ void hlsl::HandleDeclAttributeForHLSL(Sema &S, Decl *D, const AttributeList &A,
1465614656
S.Context.getAddrSpaceQualType(VD->getType(), DXIL::kTGSMAddrSpace));
1465714657
}
1465814658
break;
14659+
case AttributeList::AT_HLSLGroupSharedLimit:
14660+
declAttr = ::new (S.Context) HLSLGroupSharedLimitAttr(
14661+
A.getRange(), S.Context, ValidateAttributeIntArg(S, A),
14662+
A.getAttributeSpellingListIndex());
14663+
break;
1465914664
case AttributeList::AT_HLSLUniform:
1466014665
declAttr = ::new (S.Context) HLSLUniformAttr(
1466114666
A.getRange(), S.Context, A.getAttributeSpellingListIndex());

0 commit comments

Comments
 (0)