Skip to content

Commit 90bfb66

Browse files
authored
[SER] 'reordercoherent' HLSL attribute and DXIL encoding (microsoft#7250)
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 5d2fa92 commit 90bfb66

Some content is hidden

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

48 files changed

+585
-76
lines changed

include/dxc/DXIL/DxilMetadataHelper.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 3 additions & 0 deletions
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,8 @@ 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;
237240
}
238241

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

lib/DxilContainer/DxilContainerAssembler.cpp

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 1 deletion
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);

0 commit comments

Comments
 (0)