Skip to content

Commit deacf03

Browse files
author
Greg Roth
authored
Add used by atomics resource flag (#3513)
To identify resources that are used in 64-bit atomics operations in order to catch invalid use of heap resources
1 parent 58163b0 commit deacf03

5 files changed

Lines changed: 21 additions & 1 deletion

File tree

docs/DXIL.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ The following signature shows the operation syntax::
18611861

18621862
; overloads: SM5.1: i32, SM6.0: i32
18631863
; returns: original value in memory before the operation
1864-
declare i32 @dx.op.atomicBinOp.i32(
1864+
declare i32 @dx.op.atomicCompareExchange.i32(
18651865
i32, ; opcode
18661866
%dx.types.Handle, ; resource handle
18671867
i32, ; coordinate c0

include/dxc/DXIL/DxilResource.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class DxilResource : public DxilResourceBase {
6666
bool IsTBuffer() const;
6767
bool IsFeedbackTexture() const;
6868

69+
bool HasAtomic64Use() const;
70+
void SetHasAtomic64Use(bool b);
71+
6972
static bool classof(const DxilResourceBase *R) {
7073
return R->GetClass() == DXIL::ResourceClass::SRV || R->GetClass() == DXIL::ResourceClass::UAV;
7174
}
@@ -78,6 +81,7 @@ class DxilResource : public DxilResourceBase {
7881
bool m_bGloballyCoherent;
7982
bool m_bHasCounter;
8083
bool m_bROV;
84+
bool m_bHasAtomic64Use;
8185
};
8286

8387
} // namespace hlsl

include/dxc/DxilContainer/DxilPipelineStateValidation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ enum class PSVResourceKind
179179
NumEntries
180180
};
181181

182+
enum class PSVResourceFlag
183+
{
184+
None = 0x00000000,
185+
UsedByAtomic64 = 0x00000001,
186+
};
187+
182188
// Table of null-terminated strings, overall size aligned to dword boundary, last byte must be null
183189
struct PSVStringTable {
184190
const char *Table;
@@ -203,6 +209,7 @@ struct PSVResourceBindInfo0
203209
struct PSVResourceBindInfo1 : public PSVResourceBindInfo0
204210
{
205211
uint32_t ResKind; // PSVResourceKind
212+
uint32_t ResFlags; // special characteristics of the resource
206213
};
207214

208215
// Helpers for output dependencies (ViewID and Input-Output tables)

lib/DXIL/DxilResource.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ bool DxilResource::IsFeedbackTexture() const {
149149
return GetKind() == Kind::FeedbackTexture2D || GetKind() == Kind::FeedbackTexture2DArray;
150150
}
151151

152+
bool DxilResource::HasAtomic64Use() const {
153+
return m_bHasAtomic64Use;
154+
}
155+
156+
void DxilResource::SetHasAtomic64Use(bool b) {
157+
m_bHasAtomic64Use = b;
158+
}
159+
152160
unsigned DxilResource::GetNumCoords(Kind ResourceKind) {
153161
const unsigned CoordSizeTab[] = {
154162
0, // Invalid = 0,

lib/DxilContainer/DxilContainerAssembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ class DxilPSVWriter : public DxilPartWriter {
764764
pBindInfo->UpperBound = R->GetUpperBound();
765765
if (pBindInfo1) {
766766
pBindInfo1->ResKind = (UINT)R->GetKind();
767+
pBindInfo1->ResFlags |= R->HasAtomic64Use()? (UINT)PSVResourceFlag::UsedByAtomic64 : 0;
767768
}
768769
uResIndex++;
769770
}

0 commit comments

Comments
 (0)