Skip to content

Commit f3e8665

Browse files
jaladreipsigcbot
authored andcommitted
Raytracing changes
* Expose internal flags in traceray interface * Enable calling getObjRayOrig and getObjRayDir with Miss shader type
1 parent a877a9d commit f3e8665

File tree

6 files changed

+73
-34
lines changed

6 files changed

+73
-34
lines changed

IGC/AdaptorCommon/RayTracing/AutoGenRTStackAccessPrivateOS.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ auto* _getObjWorldAndWorldObj_Xe(Value* arg_0, Value* arg_1, Value* arg_2, Value
19761976
SetInsertPoint(BB_5);
19771977
auto* V_31 = CreateAnd(arg_1, getInt32(3));
19781978
auto* V_32 = CreateICmpEQ(V_31, getInt32(0));
1979-
auto* V_33 = CreateSelect(V_32, ConstantFP::get(*Ctx.getLLVMContext(), APFloat(APFloat::IEEEsingle(), APInt(32, 0x0))), ConstantFP::get(*Ctx.getLLVMContext(), APFloat(APFloat::IEEEsingle(), APInt(32, 0x3f800000))));
1979+
auto* V_33 = CreateSelect(V_32, ConstantFP::get(*Ctx.getLLVMContext(), APFloat(APFloat::IEEEsingle(), APInt(32, 0x3f800000))), ConstantFP::get(*Ctx.getLLVMContext(), APFloat(APFloat::IEEEsingle(), APInt(32, 0x0))));
19801980
CreateBr(BB_7);
19811981
V_30->addIncoming(V_29, BB_6);
19821982
V_30->addIncoming(V_33, BB_5);
@@ -2023,7 +2023,7 @@ auto* _getObjWorldAndWorldObj_Xe3(Value* arg_0, Value* arg_1, Value* arg_2, Valu
20232023
SetInsertPoint(BB_5);
20242024
auto* V_29 = CreateAnd(arg_1, getInt32(3));
20252025
auto* V_30 = CreateICmpEQ(V_29, getInt32(0));
2026-
auto* V_31 = CreateSelect(V_30, ConstantFP::get(*Ctx.getLLVMContext(), APFloat(APFloat::IEEEsingle(), APInt(32, 0x0))), ConstantFP::get(*Ctx.getLLVMContext(), APFloat(APFloat::IEEEsingle(), APInt(32, 0x3f800000))));
2026+
auto* V_31 = CreateSelect(V_30, ConstantFP::get(*Ctx.getLLVMContext(), APFloat(APFloat::IEEEsingle(), APInt(32, 0x3f800000))), ConstantFP::get(*Ctx.getLLVMContext(), APFloat(APFloat::IEEEsingle(), APInt(32, 0x0))));
20272027
CreateBr(BB_7);
20282028
V_28->addIncoming(V_27, BB_6);
20292029
V_28->addIncoming(V_31, BB_5);

IGC/AdaptorCommon/RayTracing/RTBuilder.cpp

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -729,29 +729,45 @@ Value* RTBuilder::getObjRayOrig(
729729
RTBuilder::StackPointerVal* perLaneStackPtr, uint32_t dim, Value* ShaderTy,
730730
Instruction* I, bool checkInstanceLeafPtr)
731731
{
732-
auto* transformWorldToObject = CreateOr(
733-
{
734-
CreateICmpEQ(ShaderTy, getInt32(CallableShaderTypeMD::ClosestHit)),
735-
}
736-
);
737-
Instruction* trueTerm = nullptr;
738-
Instruction* falseTerm = nullptr;
732+
739733
auto* IP = &*GetInsertPoint();
740-
SplitBlockAndInsertIfThenElse(transformWorldToObject, IP, &trueTerm, &falseTerm);
741734

742-
SetInsertPoint(trueTerm);
735+
auto* oldBB = IP->getParent();
736+
auto* bb = SplitBlock(oldBB, IP);
737+
738+
auto* isClosestHitBB = BasicBlock::Create(*Ctx.getLLVMContext(), VALUE_NAME("isClosestHitBB"), IP->getFunction(), bb);
739+
SetInsertPoint(isClosestHitBB);
740+
auto* isClosestHitBBTerm = CreateBr(bb); // we have to do this because the functions we call are going to split the block again...
741+
SetInsertPoint(isClosestHitBBTerm);
743742
auto* newI = I->clone();
744-
newI->insertBefore(trueTerm);
745-
auto* trueV = this->TransformWorldToObject(perLaneStackPtr, dim, true, ShaderTy, newI, checkInstanceLeafPtr);
743+
Insert(newI);
744+
auto* isClosestHitV = this->TransformWorldToObject(perLaneStackPtr, dim, true, ShaderTy, newI, checkInstanceLeafPtr);
746745
newI->eraseFromParent();
747746

748-
SetInsertPoint(falseTerm);
749-
auto* falseV = getMemRayOrig(perLaneStackPtr, dim, BOTTOM_LEVEL_BVH, VALUE_NAME("ObjRayOrig[" + Twine(dim) + "]"));
747+
auto* isMissBB = BasicBlock::Create(Context, VALUE_NAME("isMissBB"), IP->getFunction(), bb);
748+
SetInsertPoint(isMissBB);
749+
auto* isMissBBTerm = CreateBr(bb);
750+
SetInsertPoint(isMissBBTerm);
751+
auto* isMissV = getWorldRayOrig(perLaneStackPtr, dim);
752+
753+
auto* defaultBB = BasicBlock::Create(Context, VALUE_NAME("default"), IP->getFunction(), bb);
754+
SetInsertPoint(defaultBB);
755+
auto* defaultBBTerm = CreateBr(bb);
756+
SetInsertPoint(defaultBBTerm);
757+
auto* defaultV = getMemRayOrig(perLaneStackPtr, dim, BOTTOM_LEVEL_BVH, VALUE_NAME("ObjRayOrig[" + Twine(dim) + "]"));
758+
759+
// create switch statement
760+
oldBB->getTerminator()->eraseFromParent();
761+
SetInsertPoint(oldBB);
762+
auto* switchI = CreateSwitch(ShaderTy, defaultBB);
763+
switchI->addCase(getInt32(Miss), isMissBB);
764+
switchI->addCase(getInt32(ClosestHit), isClosestHitBB);
750765

751766
SetInsertPoint(IP);
752-
auto* info = CreatePHI(trueV->getType(), 2);
753-
info->addIncoming(trueV, trueTerm->getParent());
754-
info->addIncoming(falseV, falseTerm->getParent());
767+
auto* info = CreatePHI(isClosestHitV->getType(), 3);
768+
info->addIncoming(isClosestHitV, isClosestHitBBTerm->getParent());
769+
info->addIncoming(isMissV, isMissBBTerm->getParent());
770+
info->addIncoming(defaultV, defaultBBTerm->getParent());
755771

756772
return info;
757773
}
@@ -760,29 +776,45 @@ Value* RTBuilder::getObjRayDir(
760776
RTBuilder::StackPointerVal* perLaneStackPtr, uint32_t dim, Value* ShaderTy,
761777
Instruction* I, bool checkInstanceLeafPtr)
762778
{
763-
auto* transformWorldToObject = CreateOr(
764-
{
765-
CreateICmpEQ(ShaderTy, getInt32(CallableShaderTypeMD::ClosestHit)),
766-
}
767-
);
768-
Instruction* trueTerm = nullptr;
769-
Instruction* falseTerm = nullptr;
779+
770780
auto* IP = &*GetInsertPoint();
771-
SplitBlockAndInsertIfThenElse(transformWorldToObject, IP, &trueTerm, &falseTerm);
772781

773-
SetInsertPoint(trueTerm);
782+
auto* oldBB = IP->getParent();
783+
auto* bb = SplitBlock(oldBB, IP);
784+
785+
auto* isClosestHitBB = BasicBlock::Create(*Ctx.getLLVMContext(), VALUE_NAME("isClosestHitBB"), IP->getFunction(), bb);
786+
SetInsertPoint(isClosestHitBB);
787+
auto* isClosestHitBBTerm = CreateBr(bb); // we have to do this because the functions we call are going to split the block again...
788+
SetInsertPoint(isClosestHitBBTerm);
774789
auto* newI = I->clone();
775-
newI->insertBefore(trueTerm);
776-
auto* trueV = this->TransformWorldToObject(perLaneStackPtr, dim, false, ShaderTy, newI, checkInstanceLeafPtr);
790+
Insert(newI);
791+
auto* isClosestHitV = this->TransformWorldToObject(perLaneStackPtr, dim, false, ShaderTy, newI, checkInstanceLeafPtr);
777792
newI->eraseFromParent();
778793

779-
SetInsertPoint(falseTerm);
780-
auto* falseV = getMemRayDir(perLaneStackPtr, dim, BOTTOM_LEVEL_BVH, VALUE_NAME("ObjRayDir[" + Twine(dim) + "]"));
794+
auto* isMissBB = BasicBlock::Create(Context, VALUE_NAME("isMissBB"), IP->getFunction(), bb);
795+
SetInsertPoint(isMissBB);
796+
auto* isMissBBTerm = CreateBr(bb);
797+
SetInsertPoint(isMissBBTerm);
798+
auto* isMissV = getWorldRayDir(perLaneStackPtr, dim);
799+
800+
auto* defaultBB = BasicBlock::Create(Context, VALUE_NAME("default"), IP->getFunction(), bb);
801+
SetInsertPoint(defaultBB);
802+
auto* defaultBBTerm = CreateBr(bb);
803+
SetInsertPoint(defaultBBTerm);
804+
auto* defaultV = getMemRayDir(perLaneStackPtr, dim, BOTTOM_LEVEL_BVH, VALUE_NAME("ObjRayDir[" + Twine(dim) + "]"));
805+
806+
// create switch statement
807+
oldBB->getTerminator()->eraseFromParent();
808+
SetInsertPoint(oldBB);
809+
auto* switchI = CreateSwitch(ShaderTy, defaultBB);
810+
switchI->addCase(getInt32(Miss), isMissBB);
811+
switchI->addCase(getInt32(ClosestHit), isClosestHitBB);
781812

782813
SetInsertPoint(IP);
783-
auto* info = CreatePHI(trueV->getType(), 2);
784-
info->addIncoming(trueV, trueTerm->getParent());
785-
info->addIncoming(falseV, falseTerm->getParent());
814+
auto* info = CreatePHI(isClosestHitV->getType(), 3);
815+
info->addIncoming(isClosestHitV, isClosestHitBBTerm->getParent());
816+
info->addIncoming(isMissV, isMissBBTerm->getParent());
817+
info->addIncoming(defaultV, defaultBBTerm->getParent());
786818

787819
return info;
788820
}

IGC/AdaptorCommon/RayTracing/RayTracingInterface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SPDX-License-Identifier: MIT
2121
#include "AdaptorCommon/RayTracing/RayTracingAddressSpaceAliasAnalysis.h"
2222
#include "AdaptorCommon/AddImplicitArgs.hpp"
2323
#include "AdaptorCommon/ProcessFuncAttributes.h"
24+
#include "AdaptorOCL/MoveStaticAllocas.h"
2425
#include "Compiler/CISACodeGen/CodeSinking.hpp"
2526
#include "Compiler/CISACodeGen/helper.h"
2627
#include "Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryUsageAnalysis.hpp"

IGC/AdaptorCommon/RayTracing/TraceRayInlineLoweringPass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ void TraceRayInlineLoweringPass::LowerAllocateRayQuery(
206206

207207
for (auto* I : convertRayQueryToRTStackPointers)
208208
{
209+
builder.SetInsertPoint(I);
209210
auto* rtstack = getShMemRayQueryRTStack(builder, I->getRayQueryAllocationHandle());
210211
I->replaceAllUsesWith(rtstack);
211212
}

IGC/GenISAIntrinsics/GenIntrinsicInst.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ class TraceRayAsyncHLIntrinsic : public ContinuationHLIntrinsic {
14631463
void setTMax(Value* V) { setOperand(15, V); }
14641464
Value* getPayload() const { return getOperand(16); }
14651465
Value* getComparisonValue() const { return getOperand(17); }
1466+
Value* getInternalRayFlags() const { return getOperand(18); }
14661467
};
14671468

14681469
class CallShaderHLIntrinsic : public ContinuationHLIntrinsic {

IGC/GenISAIntrinsics/generator/input/Intrinsic_definitions.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11464,6 +11464,10 @@ intrinsics:
1146411464
comment: "reserved"
1146511465
- !<ArgumentDefinition>
1146611466
name: Arg18
11467+
type_definition: *i32
11468+
comment: "reserved"
11469+
- !<ArgumentDefinition>
11470+
name: Arg19
1146711471
type_definition: *f32
1146811472
comment: "reserved"
1146911473
attributes:

0 commit comments

Comments
 (0)