Skip to content

Commit 1ca7797

Browse files
author
Greg Roth
authored
Correct atomics on heap usage for libs (#3525)
The previous shader flag code failed to account for the library-specific handle creation function
1 parent bf11293 commit 1ca7797

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

include/dxc/DxilContainer/DxilRuntimeReflection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ enum class DxilResourceFlag : uint32_t {
148148
UAVCounter = 1 << 1,
149149
UAVRasterizerOrderedView = 1 << 2,
150150
DynamicIndexing = 1 << 3,
151+
Atomics64Use = 1 << 4,
151152
};
152153

153154
struct RuntimeDataResourceInfo {

lib/DXIL/DxilShaderFlags.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ struct ResKeyHash {
297297
}
298298
};
299299

300-
// Limited to retrieving handles created by CreateHandleFromBinding. returns null otherwise
301-
// map should contain resources indexed by class, lower, and upper bounds
302-
DxilResource *GetResourceFromAnnotateHandle(CallInst *handleCall,
300+
// Limited to retrieving handles created by CreateHandleFromBinding and CreateHandleForLib. returns null otherwise
301+
// map should contain resources indexed by space, class, lower, and upper bounds
302+
DxilResource *GetResourceFromAnnotateHandle(const hlsl::DxilModule *M, CallInst *handleCall,
303303
std::unordered_map<ResourceKey, DxilResource *, ResKeyHash, ResKeyEq> resMap) {
304304
DxilResource *resource = nullptr;
305305

@@ -317,6 +317,17 @@ DxilResource *GetResourceFromAnnotateHandle(CallInst *handleCall,
317317
DxilResourceBinding B = resource_helper::loadBindingFromConstant(*cast<Constant>(fromBind.get_bind()));
318318
ResourceKey key = {B.resourceClass, B.spaceID, B.rangeLowerBound, B.rangeUpperBound};
319319
resource = resMap[key];
320+
} else if (handleOp == DXIL::OpCode::CreateHandleForLib) {
321+
// If library handle, find DxilResource by checking the name
322+
if (LoadInst *LI = dyn_cast<LoadInst>(createCall->getArgOperand(
323+
DXIL::OperandIndex::kCreateHandleForLibResOpIdx))) {
324+
Value *resType = LI->getOperand(0);
325+
for (auto &&res : M->GetUAVs()) {
326+
if (res->GetGlobalSymbol() == resType) {
327+
return resource = res.get();
328+
}
329+
}
330+
}
320331
}
321332
}
322333

@@ -487,7 +498,7 @@ ShaderFlags ShaderFlags::CollectShaderFlags(const Function *F,
487498
if (DXIL::IsTyped(RP.getResourceKind()))
488499
hasAtomicInt64OnTypedResource = true;
489500
// set uses 64-bit flag if relevant
490-
if (DxilResource *res = GetResourceFromAnnotateHandle(handleCall, resMap)) {
501+
if (DxilResource *res = GetResourceFromAnnotateHandle(M, handleCall, resMap)) {
491502
res->SetHasAtomic64Use(true);
492503
} else {
493504
// Assuming CreateHandleFromHeap, which indicates a descriptor

lib/DxilContainer/DxilContainerAssembler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,8 @@ class DxilRDATWriter : public DxilPartWriter {
11791179
info.Flags |= static_cast<uint32_t>(DxilResourceFlag::UAVGloballyCoherent);
11801180
if (pRes->IsROV())
11811181
info.Flags |= static_cast<uint32_t>(DxilResourceFlag::UAVRasterizerOrderedView);
1182+
if (pRes->HasAtomic64Use())
1183+
info.Flags |= static_cast<uint32_t>(DxilResourceFlag::Atomics64Use);
11821184
// TODO: add dynamic index flag
11831185
}
11841186
m_pResourceTable->Insert(info);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %dxc -T lib_6_6 %s | FileCheck %s
2+
// Make sure library targets correctly identify non-dynamic resources
3+
4+
// CHECK: Note: shader requires additional functionality:
5+
// CHECK-NOT: 64-bit Atomics on Heap Resources
6+
7+
8+
RWStructuredBuffer<int64_t> myBuf : register(u0);
9+
10+
[shader("raygeneration")]
11+
[RootSignature("UAV(u0)")]
12+
void RGInt64OnDescriptorHeapIndex()
13+
{
14+
InterlockedAdd(myBuf[0], 1);
15+
}

0 commit comments

Comments
 (0)