Skip to content

Commit af7b1c8

Browse files
jaladreipsigcbot
authored andcommitted
Workaround the HW bug for rayquery check/release
Workaround the HW bug for rayquery check/release
1 parent c6e9bfa commit af7b1c8

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

IGC/AdaptorCommon/RayTracing/DynamicRayManagementPass.cpp

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,19 @@ bool DynamicRayManagementPass::TryProceedBasedApproach(Function& F)
358358
// following single entry multiple exits loop model, we insert one check and multiple releases
359359
checkBBs.insert(start);
360360

361-
for (auto* exitBB : exitBlocks)
362-
releaseBBs.insert(m_PDT->findNearestCommonDominator(end, exitBB));
361+
if (m_CGCtx->platform.allowDivergentControlFlowRayQueryCheckRelease())
362+
{
363+
for (auto* exitBB : exitBlocks)
364+
releaseBBs.insert(m_PDT->findNearestCommonDominator(end, exitBB));
365+
}
366+
else
367+
{
368+
for (auto* exitBB : exitBlocks)
369+
end = m_PDT->findNearestCommonDominator(end, exitBB);
370+
371+
releaseBBs.insert(end);
372+
}
373+
363374
}
364375

365376
llvm::erase_if(
@@ -385,7 +396,7 @@ bool DynamicRayManagementPass::TryProceedBasedApproach(Function& F)
385396
auto* init_guard = IRB.CreateStore(IRB.getFalse(), guard);
386397
guardStoresAndLoads.push_back(init_guard);
387398

388-
SmallVector<Instruction*> CheckReleaseIntrinsics;
399+
SmallVector<CallInst*> CheckReleaseIntrinsics;
389400

390401
for (auto* checkBB : checkBBs)
391402
{
@@ -439,6 +450,7 @@ bool DynamicRayManagementPass::TryProceedBasedApproach(Function& F)
439450

440451
SimplifyQuery SQ(F.getParent()->getDataLayout());
441452

453+
SmallVector<Instruction*> toErase;
442454
for (auto* I : CheckReleaseIntrinsics)
443455
{
444456
Value* flag = I->getOperand(0);
@@ -458,13 +470,42 @@ bool DynamicRayManagementPass::TryProceedBasedApproach(Function& F)
458470
if (auto* CI = dyn_cast_or_null<ConstantInt>(flag))
459471
{
460472
if (CI->isZero())
461-
I->eraseFromParent();
473+
toErase.push_back(I);
462474

463475
if (CI->isOne())
464476
I->setOperand(0, IRB.getTrue());
465477
}
478+
else
479+
{
480+
// if we encounter a nonconstant predicate and the platform can't handle divergent rayquery check/release
481+
// we undo as much as we can and bail from approach entirely
482+
if (!m_CGCtx->platform.allowDivergentControlFlowRayQueryCheckRelease())
483+
{
484+
llvm::for_each(
485+
CheckReleaseIntrinsics,
486+
[&](auto* I) {
487+
I->eraseFromParent();
488+
}
489+
);
490+
491+
return false;
492+
}
493+
}
494+
495+
// prevent LLVM from merging the calls
496+
if (!m_CGCtx->platform.allowDivergentControlFlowRayQueryCheckRelease())
497+
{
498+
I->addFnAttr(llvm::Attribute::NoMerge);
499+
}
466500
}
467501

502+
llvm::for_each(
503+
toErase,
504+
[&](auto* I) {
505+
I->eraseFromParent();
506+
}
507+
);
508+
468509
return true;
469510

470511
#endif // LLVM_VERSION_MAJOR >= 10

IGC/Compiler/CISACodeGen/Platform.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,5 +1743,10 @@ bool preferLSCCache() const
17431743
}
17441744

17451745

1746+
bool allowDivergentControlFlowRayQueryCheckRelease() const
1747+
{
1748+
return false;
1749+
}
1750+
17461751
};
17471752
}//namespace IGC

IGC/common/igc_flags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ DECLARE_IGC_GROUP("Raytracing Options")
914914
DECLARE_IGC_REGKEY(bool, DisableRayQueryDynamicRayManagementMechanismForExternalFunctionsCalls, false, "Disable dynamic ray management mechanism for shaders with external functions calls", true)
915915
DECLARE_IGC_REGKEY(bool, DisableRayQueryDynamicRayManagementMechanismForBarriers, false, "Disable dynamic ray management mechanism for shaders with barriers", true)
916916
DECLARE_IGC_REGKEY(bool, EnableOuterLoopHoistingForRayQueryDynamicRayManagementMechanism, false, "Disable dynamic ray management mechanism for shaders with barriers", true)
917-
DECLARE_IGC_REGKEY(bool, DisableProceedBasedApproachForRayQueryDynamicRayManagementMechanism, true, "Disables proceed based approach for dynamic ray management mechanism", true)
917+
DECLARE_IGC_REGKEY(bool, DisableProceedBasedApproachForRayQueryDynamicRayManagementMechanism, false, "Disables proceed based approach for dynamic ray management mechanism", true)
918918
DECLARE_IGC_REGKEY(bool, DisableWideTraceRay, false, "Disable SIMD16 style message payloads for send.rta", true)
919919
DECLARE_IGC_REGKEY(bool, ForceRTCheckInstanceLeafPtr, true, "Check MemHit::valid before loading GeometryIndex, PrimitiveIndex, etc.", true)
920920
DECLARE_IGC_REGKEY(DWORD, RTInValidDefaultIndex, 0xFFFFFFFF, "If MemHit::valid is false, the default value to return for some intrinsics like GeometryIndex or PrimitiveIndex etc.", true)

0 commit comments

Comments
 (0)