Skip to content

Commit 33512df

Browse files
committed
[SER] 'reordercoherent' HLSL attribute and DXIL encoding
Specification: https://github.com/microsoft/hlsl-specs/blob/main/proposals/0027-shader-execution-reordering.md 'reordercoherent' encoding hlsl-specs PR: microsoft/hlsl-specs#453 DXC SER implementation tracker: microsoft#7214
1 parent 85f3432 commit 33512df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+505
-56
lines changed

include/dxc/DXIL/DxilMetadataHelper.h

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class DxilMDHelper {
233233
static const unsigned kDxilStructuredBufferElementStrideTag = 1;
234234
static const unsigned kDxilSamplerFeedbackKindTag = 2;
235235
static const unsigned kDxilAtomic64UseTag = 3;
236+
static const unsigned kDxilReorderCoherentTag = 4;
236237

237238
// Type system.
238239
static const char kDxilTypeSystemMDName[];

include/dxc/DXIL/DxilResource.h

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class DxilResource : public DxilResourceBase {
6363

6464
bool IsGloballyCoherent() const;
6565
void SetGloballyCoherent(bool b);
66+
bool IsReorderCoherent() const;
67+
void SetReorderCoherent(bool b);
6668
bool HasCounter() const;
6769
void SetHasCounter(bool b);
6870

@@ -97,6 +99,7 @@ class DxilResource : public DxilResourceBase {
9799
CompType m_CompType;
98100
DXIL::SamplerFeedbackType m_SamplerFeedbackType;
99101
bool m_bGloballyCoherent;
102+
bool m_bReorderCoherent;
100103
bool m_bHasCounter;
101104
bool m_bROV;
102105
bool m_bHasAtomic64Use;

include/dxc/DXIL/DxilResourceProperties.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ struct DxilResourceProperties {
4747
uint8_t SamplerCmpOrHasCounter : 1;
4848

4949
// BYTE 2
50-
uint8_t Reserved2;
50+
uint8_t IsReorderCoherent : 1;
51+
uint8_t Reserved2 : 7;
5152

5253
// BYTE 3
5354
uint8_t Reserved3;

include/dxc/DxilContainer/RDAT_LibraryTypes.inl

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ RDAT_ENUM_START(DxilResourceFlag, uint32_t)
2222
RDAT_ENUM_VALUE(UAVRasterizerOrderedView, 1 << 2)
2323
RDAT_ENUM_VALUE(DynamicIndexing, 1 << 3)
2424
RDAT_ENUM_VALUE(Atomics64Use, 1 << 4)
25+
RDAT_ENUM_VALUE(UAVReorderCoherent, 1 << 5)
2526
RDAT_ENUM_END()
2627

2728
RDAT_ENUM_START(DxilShaderStageFlags, uint32_t)

lib/DXIL/DxilMetadataHelper.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -3110,6 +3110,13 @@ void DxilExtraPropertyHelper::EmitUAVProperties(
31103110
DxilMDHelper::kDxilAtomic64UseTag, m_Ctx));
31113111
MDVals.emplace_back(DxilMDHelper::Uint32ToConstMD((unsigned)true, m_Ctx));
31123112
}
3113+
// Whether resource is reordercoherent.
3114+
if (DXIL::CompareVersions(m_ValMajor, m_ValMinor, 1, 9) >= 0 &&
3115+
UAV.IsReorderCoherent()) {
3116+
MDVals.emplace_back(DxilMDHelper::Uint32ToConstMD(
3117+
DxilMDHelper::kDxilReorderCoherentTag, m_Ctx));
3118+
MDVals.emplace_back(DxilMDHelper::BoolToConstMD(true, m_Ctx));
3119+
}
31133120
}
31143121

31153122
void DxilExtraPropertyHelper::LoadUAVProperties(const MDOperand &MDO,
@@ -3147,6 +3154,9 @@ void DxilExtraPropertyHelper::LoadUAVProperties(const MDOperand &MDO,
31473154
case DxilMDHelper::kDxilAtomic64UseTag:
31483155
UAV.SetHasAtomic64Use(DxilMDHelper::ConstMDToBool(MDO));
31493156
break;
3157+
case DxilMDHelper::kDxilReorderCoherentTag:
3158+
UAV.SetReorderCoherent(DxilMDHelper::ConstMDToBool(MDO));
3159+
break;
31503160
default:
31513161
DXASSERT(false, "Unknown resource record tag");
31523162
m_bExtraMetadata = true;

lib/DXIL/DxilResource.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ namespace hlsl {
2525
DxilResource::DxilResource()
2626
: DxilResourceBase(DxilResourceBase::Class::Invalid), m_SampleCount(0),
2727
m_ElementStride(0), m_SamplerFeedbackType((DXIL::SamplerFeedbackType)0),
28-
m_bGloballyCoherent(false), m_bHasCounter(false), m_bROV(false),
29-
m_bHasAtomic64Use(false) {}
28+
m_bGloballyCoherent(false), m_bReorderCoherent(false),
29+
m_bHasCounter(false), m_bROV(false), m_bHasAtomic64Use(false) {}
3030

3131
CompType DxilResource::GetCompType() const { return m_CompType; }
3232

@@ -74,6 +74,10 @@ bool DxilResource::IsGloballyCoherent() const { return m_bGloballyCoherent; }
7474

7575
void DxilResource::SetGloballyCoherent(bool b) { m_bGloballyCoherent = b; }
7676

77+
bool DxilResource::IsReorderCoherent() const { return m_bReorderCoherent; }
78+
79+
void DxilResource::SetReorderCoherent(bool b) { m_bReorderCoherent = b; }
80+
7781
bool DxilResource::HasCounter() const { return m_bHasCounter; }
7882

7983
void DxilResource::SetHasCounter(bool b) { m_bHasCounter = b; }

lib/DXIL/DxilResourceProperties.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ DxilResourceProperties loadPropsFromResourceBase(const DxilResourceBase *Res) {
190190
RP.Basic.IsUAV = true;
191191
RP.Basic.ResourceKind = (uint8_t)Res->GetKind();
192192
RP.Basic.IsGloballyCoherent = UAV->IsGloballyCoherent();
193+
RP.Basic.IsReorderCoherent = UAV->IsReorderCoherent();
193194
RP.Basic.SamplerCmpOrHasCounter = UAV->HasCounter();
194195
RP.Basic.IsROV = UAV->IsROV();
195196
SetResProperties(*UAV);
@@ -234,6 +235,9 @@ DxilResourceProperties tryMergeProps(DxilResourceProperties curProps,
234235
prevProps.Basic.IsGloballyCoherent) {
235236
curProps.Basic.IsGloballyCoherent = prevProps.Basic.IsGloballyCoherent;
236237
}
238+
if (curProps.Basic.IsReorderCoherent != prevProps.Basic.IsReorderCoherent) {
239+
curProps.Basic.IsReorderCoherent = prevProps.Basic.IsReorderCoherent;
240+
}
237241
}
238242

239243
if (curProps.Basic.ResourceKind == (uint8_t)DXIL::ResourceKind::CBuffer) {

lib/DxilContainer/DxilContainerAssembler.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,9 @@ class DxilRDATWriter : public DxilPartWriter {
10571057
if (pRes->IsGloballyCoherent())
10581058
info.Flags |=
10591059
static_cast<uint32_t>(RDAT::DxilResourceFlag::UAVGloballyCoherent);
1060+
if (pRes->IsReorderCoherent())
1061+
info.Flags |=
1062+
static_cast<uint32_t>(RDAT::DxilResourceFlag::UAVReorderCoherent);
10601063
if (pRes->IsROV())
10611064
info.Flags |= static_cast<uint32_t>(
10621065
RDAT::DxilResourceFlag::UAVRasterizerOrderedView);

lib/DxilPIXPasses/PixPassHelpers.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ hlsl::DxilResource *CreateGlobalUAVResource(hlsl::DxilModule &DM,
324324
(unsigned int)-2); // This is the reserved-for-tools register space
325325
pUAV->SetSampleCount(0); // This is what compiler generates for a raw UAV
326326
pUAV->SetGloballyCoherent(false);
327+
pUAV->SetReorderCoherent(false);
327328
pUAV->SetHasCounter(false);
328329
pUAV->SetCompType(
329330
CompType::getInvalid()); // This is what compiler generates for a raw UAV

lib/HLSL/DxilCondenseResources.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,8 @@ void DxilLowerCreateHandleForLib::ReplaceResourceUserWithHandle(
20612061
};
20622062

20632063
// Search all users for update counter
2064-
bool updateAnnotateHandle = res.IsGloballyCoherent();
2064+
bool updateAnnotateHandle =
2065+
res.IsGloballyCoherent() || res.IsReorderCoherent();
20652066
if (!res.HasCounter()) {
20662067
for (User *U : handle->users()) {
20672068
if (IsDxilOp(U, hlsl::OP::OpCode::BufferUpdateCounter)) {
@@ -2321,6 +2322,7 @@ void InitTBuffer(const DxilCBuffer *pSource, DxilResource *pDest) {
23212322
pDest->SetSampleCount(0);
23222323
pDest->SetElementStride(0);
23232324
pDest->SetGloballyCoherent(false);
2325+
pDest->SetReorderCoherent(false);
23242326
pDest->SetHasCounter(false);
23252327
pDest->SetRW(false);
23262328
pDest->SetROV(false);

lib/HLSL/DxilGenerationPass.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void InitResource(const DxilResource *pSource, DxilResource *pDest) {
8888
pDest->SetSampleCount(pSource->GetSampleCount());
8989
pDest->SetElementStride(pSource->GetElementStride());
9090
pDest->SetGloballyCoherent(pSource->IsGloballyCoherent());
91+
pDest->SetReorderCoherent(pSource->IsReorderCoherent());
9192
pDest->SetHasCounter(pSource->HasCounter());
9293
pDest->SetRW(pSource->IsRW());
9394
pDest->SetROV(pSource->IsROV());

lib/HLSL/DxilPatchShaderRecordBindings.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ unsigned int DxilPatchShaderRecordBindings::AddHandle(
341341

342342
if (pHandle) {
343343
pHandle->SetGloballyCoherent(false);
344+
pHandle->SetReorderCoherent(false);
344345
pHandle->SetHasCounter(false);
345346
pHandle->SetCompType(CompType::getF32()); // TODO: Need to handle all types
346347
}

lib/HLSL/HLModule.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ HLModule::AddResourceWithGlobalVariableAndProps(llvm::Constant *GV,
700700
Res->SetRW(true);
701701
Res->SetROV(RP.Basic.IsROV);
702702
Res->SetGloballyCoherent(RP.Basic.IsGloballyCoherent);
703+
Res->SetReorderCoherent(RP.Basic.IsReorderCoherent);
703704
Res->SetHasCounter(RP.Basic.SamplerCmpOrHasCounter);
704705
Res->SetKind(RK);
705706
Res->SetGlobalSymbol(GV);

tools/clang/include/clang/AST/HlslTypes.h

+1
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ bool IsHLSLUnsigned(clang::QualType type);
470470
bool IsHLSLMinPrecision(clang::QualType type);
471471
bool HasHLSLUNormSNorm(clang::QualType type, bool *pIsSNorm = nullptr);
472472
bool HasHLSLGloballyCoherent(clang::QualType type);
473+
bool HasHLSLReorderCoherent(clang::QualType type);
473474
bool IsHLSLInputPatchType(clang::QualType type);
474475
bool IsHLSLOutputPatchType(clang::QualType type);
475476
bool IsHLSLPointStreamType(clang::QualType type);

tools/clang/include/clang/AST/Type.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -3652,7 +3652,8 @@ class AttributedType : public Type, public llvm::FoldingSetNode {
36523652
attr_hlsl_row_major,
36533653
attr_hlsl_column_major,
36543654
attr_hlsl_globallycoherent,
3655-
// HLSL Change Ends
3655+
attr_hlsl_reordercoherent,
3656+
// HLSL Change Ends
36563657
};
36573658

36583659
private:

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

+6
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,12 @@ def HLSLGloballyCoherent : InheritableAttr {
854854
let Documentation = [Undocumented];
855855
}
856856

857+
def HLSLReorderCoherent : InheritableAttr {
858+
let Spellings = [CXX11<"", "reordercoherent", 2015>];
859+
let Subjects = SubjectList<[Var, Function]>;
860+
let Documentation = [Undocumented];
861+
}
862+
857863
def HLSLShader : InheritableAttr {
858864
let Spellings = [CXX11<"", "shader", 2017>];
859865
let Args = [StringArgument<"stage">]; // one of compute, pixel, vertex, hull, domain, geometry, node

tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

+10
Original file line numberDiff line numberDiff line change
@@ -7708,6 +7708,10 @@ def err_hlsl_varmodifierna_decltype : Error<
77087708
"%0 is not a valid modifier for a declaration of type %1">;
77097709
def note_hlsl_globallycoherent_applies_to : Note<
77107710
"'globallycoherent' can only be applied to UAV or RWDispatchNodeInputRecord objects">;
7711+
def note_hlsl_reordercoherent_applies_to : Note<
7712+
"'reordercoherent' can only be applied to UAV objects">;
7713+
def warn_hlsl_gc_implies_rc_attribute : Warning<
7714+
"Attribute 'reordercoherent' implied by 'globallycoherent' in %0. 'reordercoherent' ignored.">, DefaultWarn;
77117715
def err_hlsl_varmodifiersna : Error<
77127716
"%0 and %1 cannot be used together for a %2">;
77137717
def err_hlsl_vla : Error< // Patterened after err_opencl_vla
@@ -7759,6 +7763,12 @@ def warn_hlsl_unary_negate_unsigned : Warning<
77597763
def warn_hlsl_impcast_glc_mismatch : Warning<
77607764
"implicit conversion from %0 to %1 %select{loses|adds}2 globallycoherent annotation">,
77617765
InGroup<Conversion>, DefaultWarn;
7766+
def warn_hlsl_impcast_rdc_mismatch : Warning<
7767+
"implicit conversion from %0 to %1 %select{loses|adds}2 reordercoherent annotation">,
7768+
InGroup<Conversion>, DefaultWarn;
7769+
def warn_hlsl_impcast_rdc_glc_mismatch : Warning<
7770+
"implicit conversion from %0 to %1 %select{demotes globallycoherent to reordercoherent|promotes reordercoherent to globallycoherent}2 annotation">,
7771+
InGroup<Conversion>, DefaultWarn;
77627772
def warn_hlsl_narrowing : Warning<
77637773
"conversion from larger type %0 to smaller type %1, possible loss of data">,
77647774
InGroup<Conversion>, DefaultWarn;

tools/clang/include/clang/Basic/TokenKinds.def

+1
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ KEYWORD(lineadj , KEYHLSL)
508508
KEYWORD(triangle , KEYHLSL)
509509
KEYWORD(triangleadj , KEYHLSL)
510510
KEYWORD(globallycoherent , KEYHLSL)
511+
KEYWORD(reordercoherent , KEYHLSL)
511512
KEYWORD(interface , KEYHLSL)
512513
KEYWORD(sampler_state , KEYHLSL)
513514
KEYWORD(technique , KEYHLSL)

tools/clang/include/clang/Sema/Sema.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -3804,9 +3804,8 @@ class Sema {
38043804
bool CheckHLSLUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation Loc,
38053805
UnaryExprOrTypeTrait ExprKind);
38063806
void DiagnoseHLSLDeclAttr(const Decl *D, const Attr *A);
3807-
void DiagnoseGloballyCoherentMismatch(const Expr *SrcExpr,
3808-
QualType TargetType,
3809-
SourceLocation Loc);
3807+
void DiagnoseCoherenceMismatch(const Expr *SrcExpr, QualType TargetType,
3808+
SourceLocation Loc);
38103809
void CheckHLSLFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
38113810
const FunctionProtoType *Proto);
38123811
void DiagnoseReachableHLSLCall(CallExpr *CE, const hlsl::ShaderModel *SM,

tools/clang/lib/AST/HlslTypes.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ bool HasHLSLGloballyCoherent(clang::QualType type) {
278278
return false;
279279
}
280280

281+
bool HasHLSLReorderCoherent(clang::QualType type) {
282+
const AttributedType *AT = type->getAs<AttributedType>();
283+
while (AT) {
284+
AttributedType::Kind kind = AT->getAttrKind();
285+
if (kind == AttributedType::attr_hlsl_reordercoherent)
286+
return true;
287+
AT = AT->getLocallyUnqualifiedSingleStepDesugaredType()
288+
->getAs<AttributedType>();
289+
}
290+
return false;
291+
}
292+
281293
/// Checks whether the pAttributes indicate a parameter is inout or out; if
282294
/// inout, pIsIn will be set to true.
283295
bool IsParamAttributedAsOut(clang::AttributeList *pAttributes, bool *pIsIn);

tools/clang/lib/AST/Type.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2945,6 +2945,7 @@ bool AttributedType::isHLSLTypeSpec() const {
29452945
case attr_hlsl_snorm:
29462946
case attr_hlsl_unorm:
29472947
case attr_hlsl_globallycoherent:
2948+
case attr_hlsl_reordercoherent:
29482949
return true;
29492950
}
29502951
llvm_unreachable("invalid attr kind");
@@ -2975,7 +2976,8 @@ bool AttributedType::isCallingConv() const {
29752976
case attr_hlsl_snorm:
29762977
case attr_hlsl_unorm:
29772978
case attr_hlsl_globallycoherent:
2978-
// HLSL Change Ends
2979+
case attr_hlsl_reordercoherent:
2980+
// HLSL Change Ends
29792981
return false;
29802982

29812983
case attr_pcs:

tools/clang/lib/AST/TypePrinter.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,9 @@ void TypePrinter::printAttributedBefore(const AttributedType *T,
11741174
case AttributedType::attr_hlsl_globallycoherent:
11751175
OS << "globallycoherent ";
11761176
break;
1177+
case AttributedType::attr_hlsl_reordercoherent:
1178+
OS << "reordercoherent ";
1179+
break;
11771180
default:
11781181
// Only HLSL attribute types are covered.
11791182
break;

0 commit comments

Comments
 (0)