Skip to content

Commit d1c9de9

Browse files
committed
[SER] 'reordercoherent' HLSL attribute
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 b646ad3 commit d1c9de9

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

+510
-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
@@ -3099,6 +3099,13 @@ void DxilExtraPropertyHelper::EmitUAVProperties(
30993099
DxilMDHelper::kDxilAtomic64UseTag, m_Ctx));
31003100
MDVals.emplace_back(DxilMDHelper::Uint32ToConstMD((unsigned)true, m_Ctx));
31013101
}
3102+
// Whether resource is reordercoherent.
3103+
if (DXIL::CompareVersions(m_ValMajor, m_ValMinor, 1, 9) >= 0 &&
3104+
UAV.IsReorderCoherent()) {
3105+
MDVals.emplace_back(DxilMDHelper::Uint32ToConstMD(
3106+
DxilMDHelper::kDxilReorderCoherentTag, m_Ctx));
3107+
MDVals.emplace_back(DxilMDHelper::BoolToConstMD(true, m_Ctx));
3108+
}
31023109
}
31033110

31043111
void DxilExtraPropertyHelper::LoadUAVProperties(const MDOperand &MDO,
@@ -3136,6 +3143,9 @@ void DxilExtraPropertyHelper::LoadUAVProperties(const MDOperand &MDO,
31363143
case DxilMDHelper::kDxilAtomic64UseTag:
31373144
UAV.SetHasAtomic64Use(DxilMDHelper::ConstMDToBool(MDO));
31383145
break;
3146+
case DxilMDHelper::kDxilReorderCoherentTag:
3147+
UAV.SetReorderCoherent(DxilMDHelper::ConstMDToBool(MDO));
3148+
break;
31393149
default:
31403150
DXASSERT(false, "Unknown resource record tag");
31413151
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
@@ -312,6 +312,7 @@ hlsl::DxilResource *CreateGlobalUAVResource(hlsl::DxilModule &DM,
312312
(unsigned int)-2); // This is the reserved-for-tools register space
313313
pUAV->SetSampleCount(0); // This is what compiler generates for a raw UAV
314314
pUAV->SetGloballyCoherent(false);
315+
pUAV->SetReorderCoherent(false);
315316
pUAV->SetHasCounter(false);
316317
pUAV->SetCompType(
317318
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
@@ -697,6 +697,7 @@ HLModule::AddResourceWithGlobalVariableAndProps(llvm::Constant *GV,
697697
Res->SetRW(true);
698698
Res->SetROV(RP.Basic.IsROV);
699699
Res->SetGloballyCoherent(RP.Basic.IsGloballyCoherent);
700+
Res->SetReorderCoherent(RP.Basic.IsReorderCoherent);
700701
Res->SetHasCounter(RP.Basic.SamplerCmpOrHasCounter);
701702
Res->SetKind(RK);
702703
Res->SetGlobalSymbol(GV);

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

+1
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ bool IsHLSLUnsigned(clang::QualType type);
461461
bool IsHLSLMinPrecision(clang::QualType type);
462462
bool HasHLSLUNormSNorm(clang::QualType type, bool *pIsSNorm = nullptr);
463463
bool HasHLSLGloballyCoherent(clang::QualType type);
464+
bool HasHLSLReorderCoherent(clang::QualType type);
464465
bool IsHLSLInputPatchType(clang::QualType type);
465466
bool IsHLSLOutputPatchType(clang::QualType type);
466467
bool IsHLSLPointStreamType(clang::QualType type);

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -3652,7 +3652,9 @@ 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+
// Shader Execution Reordering
3656+
attr_hlsl_reordercoherent,
3657+
// HLSL Change Ends
36563658
};
36573659

36583660
private:

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

+6
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,12 @@ def HLSLGloballyCoherent : InheritableAttr {
851851
let Documentation = [Undocumented];
852852
}
853853

854+
def HLSLReorderCoherent : InheritableAttr {
855+
let Spellings = [CXX11<"", "reordercoherent", 2015>];
856+
let Subjects = SubjectList<[Var, Function]>;
857+
let Documentation = [Undocumented];
858+
}
859+
854860
def HLSLShader : InheritableAttr {
855861
let Spellings = [CXX11<"", "shader", 2017>];
856862
let Args = [StringArgument<"stage">]; // one of compute, pixel, vertex, hull, domain, geometry, node

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

+14
Original file line numberDiff line numberDiff line change
@@ -7702,6 +7702,10 @@ def err_hlsl_varmodifierna_decltype : Error<
77027702
"%0 is not a valid modifier for a declaration of type %1">;
77037703
def note_hlsl_globallycoherent_applies_to : Note<
77047704
"'globallycoherent' can only be applied to UAV or RWDispatchNodeInputRecord objects">;
7705+
def note_hlsl_reordercoherent_applies_to : Note<
7706+
"'reordercoherent' can only be applied to UAV objects">;
7707+
def warn_hlsl_gc_implies_rc_attribute : Warning<
7708+
"Attribute 'reordercoherent' implied by 'globallycoherent' in %0. 'reordercoherent' ignored.">, DefaultWarn;
77057709
def err_hlsl_varmodifiersna : Error<
77067710
"%0 and %1 cannot be used together for a %2">;
77077711
def err_hlsl_vla : Error< // Patterened after err_opencl_vla
@@ -7753,6 +7757,12 @@ def warn_hlsl_unary_negate_unsigned : Warning<
77537757
def warn_hlsl_impcast_glc_mismatch : Warning<
77547758
"implicit conversion from %0 to %1 %select{loses|adds}2 globallycoherent annotation">,
77557759
InGroup<Conversion>, DefaultWarn;
7760+
def warn_hlsl_impcast_rdc_mismatch : Warning<
7761+
"implicit conversion from %0 to %1 %select{loses|adds}2 reordercoherent annotation">,
7762+
InGroup<Conversion>, DefaultWarn;
7763+
def warn_hlsl_impcast_rdc_glc_mismatch : Warning<
7764+
"implicit conversion from %0 to %1 %select{demotes globallycoherent to reordercoherent|promotes reordercoherent to globallycoherent}2 annotation">,
7765+
InGroup<Conversion>, DefaultWarn;
77567766
def warn_hlsl_narrowing : Warning<
77577767
"conversion from larger type %0 to smaller type %1, possible loss of data">,
77587768
InGroup<Conversion>, DefaultWarn;
@@ -7991,6 +8001,10 @@ def warn_hlsl_legacy_integer_literal_signedness: Warning<
79918001
InGroup<HLSLLegacyLiterals>, DefaultIgnore;
79928002
def err_hlsl_unsupported_semantic_index: Error<
79938003
"'%0' is defined with semantic index %1, but only values 0 through %2 are supported">;
8004+
8005+
// Shader Execution Reordering
8006+
def err_hlsl_reorder_coherent_invalid_shader_kind : Error<
8007+
"Attribute reordercoherent not valid in shader kind %0 (has to be callable, raygeneration, closesthit or miss)">;
79948008
// HLSL Change Ends
79958009

79968010
// SPIRV Change Starts

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
@@ -275,6 +275,18 @@ bool HasHLSLGloballyCoherent(clang::QualType type) {
275275
return false;
276276
}
277277

278+
bool HasHLSLReorderCoherent(clang::QualType type) {
279+
const AttributedType *AT = type->getAs<AttributedType>();
280+
while (AT) {
281+
AttributedType::Kind kind = AT->getAttrKind();
282+
if (kind == AttributedType::attr_hlsl_reordercoherent)
283+
return true;
284+
AT = AT->getLocallyUnqualifiedSingleStepDesugaredType()
285+
->getAs<AttributedType>();
286+
}
287+
return false;
288+
}
289+
278290
/// Checks whether the pAttributes indicate a parameter is inout or out; if
279291
/// inout, pIsIn will be set to true.
280292
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)