Skip to content

Commit b72a425

Browse files
author
nopandbrk
committed
Implement a map for function to resource handle
1 parent 196d8e8 commit b72a425

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

lib/DxilPIXPasses/DxilNonUniformResourceIndexInstrumentation.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool DxilNonUniformResourceIndexInstrumentation::runOnModule(Module &M) {
4040
LLVMContext &Ctx = M.getContext();
4141
OP *HlslOP = DM.GetOP();
4242

43-
hlsl::DxilResource *PixUavResource = nullptr;
43+
hlsl::DxilResource *PixUAVResource = nullptr;
4444

4545
UndefValue *UndefArg = UndefValue::get(Type::getInt32Ty(Ctx));
4646

@@ -57,6 +57,8 @@ bool DxilNonUniformResourceIndexInstrumentation::runOnModule(Module &M) {
5757
HlslOP->GetU32Const((uint32_t)OP::OpCode::AtomicBinOp);
5858
Constant *AtomicOr = HlslOP->GetU32Const((uint32_t)DXIL::AtomicBinOpCode::Or);
5959

60+
std::map<Function *, CallInst *> FunctionToUAVHandle;
61+
6062
// This is the main pass that will iterate through all of the resources that
6163
// are dynamically indexed. If not already marked NonUniformResourceIndex,
6264
// then insert WaveActiveAllEqual to determine if the index is uniform
@@ -70,15 +72,30 @@ bool DxilNonUniformResourceIndexInstrumentation::runOnModule(Module &M) {
7072
return true;
7173
}
7274

73-
if (!PixUavResource) {
74-
PixUavResource =
75-
PIXPassHelpers::CreateGlobalUAVResource(DM, 0, "PixUavResource");
75+
if (!PixUAVResource) {
76+
PixUAVResource =
77+
PIXPassHelpers::CreateGlobalUAVResource(DM, 0, "PixUAVResource");
7678
}
7779

78-
IRBuilder<> Builder(CreateHandle);
80+
CallInst *PixUAVHandle = nullptr;
81+
Function *F = CreateHandle->getParent()->getParent();
82+
83+
const auto FunctionToUAVHandleIter = FunctionToUAVHandle.lower_bound(F);
84+
85+
if ((FunctionToUAVHandleIter != FunctionToUAVHandle.end()) &&
86+
(FunctionToUAVHandleIter->first == F)) {
87+
PixUAVHandle = FunctionToUAVHandleIter->second;
88+
} else {
89+
IRBuilder<> Builder(F->getEntryBlock().getFirstInsertionPt());
7990

80-
CallInst *HandleForUAV = PIXPassHelpers::CreateHandleForResource(
81-
DM, Builder, PixUavResource, "PixUavHandle");
91+
PixUAVHandle = PIXPassHelpers::CreateHandleForResource(
92+
DM, Builder, PixUAVResource, "PixUAVHandle");
93+
94+
FunctionToUAVHandle.insert(FunctionToUAVHandleIter,
95+
{F, PixUAVHandle});
96+
}
97+
98+
IRBuilder<> Builder(CreateHandle);
8299

83100
uint32_t InstructionNumber = 0;
84101
if (!pix_dxil::PixDxilInstNum::FromInst(CreateHandle,
@@ -117,7 +134,7 @@ bool DxilNonUniformResourceIndexInstrumentation::runOnModule(Module &M) {
117134
AtomicOpFunc,
118135
{
119136
AtomicBinOpcode, // i32, ; opcode
120-
HandleForUAV, // %dx.types.Handle, ; resource handle
137+
PixUAVHandle, // %dx.types.Handle, ; resource handle
121138
AtomicOr, // i32, ; binary operation code :
122139
// EXCHANGE, IADD, AND, OR, XOR
123140
// IMIN, IMAX, UMIN, UMAX
@@ -130,7 +147,7 @@ bool DxilNonUniformResourceIndexInstrumentation::runOnModule(Module &M) {
130147
return true;
131148
});
132149

133-
const bool modified = (PixUavResource != nullptr);
150+
const bool modified = (PixUAVResource != nullptr);
134151

135152
if (modified) {
136153
DM.ReEmitDxilResources();

0 commit comments

Comments
 (0)