From ef7a1aa28bcfc31de7abdc2c96d502683c8931dd Mon Sep 17 00:00:00 2001 From: "Jarosz, Piotr" Date: Thu, 24 Oct 2024 14:58:22 +0000 Subject: [PATCH] Add getPrimitiveIndexDelta Add getPrimitiveIndexDelta and minor refactor. --- .../AutoGenRTStackAccessPrivateOS.h | 10 ++++++ IGC/AdaptorCommon/RayTracing/RTBuilder.cpp | 33 ++++++++++--------- IGC/AdaptorCommon/RayTracing/RTBuilder.h | 5 +-- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/IGC/AdaptorCommon/RayTracing/AutoGenRTStackAccessPrivateOS.h b/IGC/AdaptorCommon/RayTracing/AutoGenRTStackAccessPrivateOS.h index dd61e0871ee0..9f352517a6a1 100644 --- a/IGC/AdaptorCommon/RayTracing/AutoGenRTStackAccessPrivateOS.h +++ b/IGC/AdaptorCommon/RayTracing/AutoGenRTStackAccessPrivateOS.h @@ -1479,6 +1479,16 @@ auto* _getGeometryIndex_Xe(Value* arg_0, Value* arg_1, Value* arg_2, const Twine return V_18; } +auto* _getPrimitiveIndexDelta_Xe(Value* arg_0, Value* arg_1, const Twine& _ReturnName = "") +{ + auto* V_2 = CreateInBoundsGEP(_struct_RTStackFormat__RTStack(*Ctx.getModule()), arg_0, { getInt64(0), getInt32(0), getInt32(3) }); + auto* V_3 = CreateInBoundsGEP(_struct_RTStackFormat__RTStack(*Ctx.getModule()), arg_0, { getInt64(0), getInt32(1), getInt32(3) }); + auto* V_4 = CreateSelect(arg_1, V_2, V_3); + auto* V_5 = CreateLoad(getInt32Ty(), V_4); + auto* V_6 = CreateAnd(V_5, getInt32(65535), _ReturnName); + return V_6; +} + void _createPotentialHit2CommittedHit_Xe(Value* arg_0) { auto* V_1 = CreateInBoundsGEP(_struct_RTStackFormat__RTStack(*Ctx.getModule()), arg_0, { getInt64(0), getInt32(1), getInt32(0) }); diff --git a/IGC/AdaptorCommon/RayTracing/RTBuilder.cpp b/IGC/AdaptorCommon/RayTracing/RTBuilder.cpp index 634d048d8eff..d8ac375de0cf 100644 --- a/IGC/AdaptorCommon/RayTracing/RTBuilder.cpp +++ b/IGC/AdaptorCommon/RayTracing/RTBuilder.cpp @@ -41,6 +41,7 @@ using namespace llvm; using namespace RTStackFormat; using namespace IGC; + namespace { class VAdapt { @@ -871,11 +872,11 @@ Value* RTBuilder::getPrimitiveIndex( } } -PHINode* RTBuilder::getPrimitiveIndex( +Value* RTBuilder::getPrimitiveIndex( RTBuilder::StackPointerVal* perLaneStackPtr, Value* leafType, bool Committed) { - switch (getMemoryStyle()) - { + switch (getMemoryStyle()) + { #define STYLE(X) \ case RTMemoryStyle::X: \ return _getPrimitiveIndex_##X( \ @@ -885,11 +886,12 @@ PHINode* RTBuilder::getPrimitiveIndex( VALUE_NAME("primitiveIndex")); #include "RayTracingMemoryStyle.h" #undef STYLE - } - IGC_ASSERT(0); - return {}; + } + IGC_ASSERT(0); + return nullptr; } + Value* RTBuilder::getGeometryIndex( RTBuilder::StackPointerVal* perLaneStackPtr, Instruction* I, @@ -904,37 +906,36 @@ Value* RTBuilder::getGeometryIndex( auto [ValidBB, PN] = validateInstanceLeafPtr(perLaneStackPtr, I, (ShaderTy == CallableShaderTypeMD::ClosestHit)); this->SetInsertPoint(ValidBB->getTerminator()); - Value* validGeomIndex = getGeometryIndex(perLaneStackPtr, &*BB->rbegin(), leafType, ShaderTy); + Value* validGeomIndex = getGeometryIndex(perLaneStackPtr, leafType, ShaderTy == CallableShaderTypeMD::ClosestHit); PN->addIncoming(validGeomIndex, getUnsetPhiBlock(PN)); this->SetInsertPoint(I); return PN; } else { - return getGeometryIndex(perLaneStackPtr, I, leafType, ShaderTy); + return getGeometryIndex(perLaneStackPtr, leafType, ShaderTy == CallableShaderTypeMD::ClosestHit); } } Value* RTBuilder::getGeometryIndex( RTBuilder::StackPointerVal* perLaneStackPtr, - Instruction* I, Value* leafType, - IGC::CallableShaderTypeMD ShaderTy) + bool committed) { - switch (getMemoryStyle()) - { + switch (getMemoryStyle()) + { #define STYLE(X) \ case RTMemoryStyle::X: \ return _getGeometryIndex_##X( \ perLaneStackPtr, \ leafType, \ - VAdapt{ *this, ShaderTy == ClosestHit }, \ + VAdapt{ *this, committed }, \ VALUE_NAME("geometryIndex")); #include "RayTracingMemoryStyle.h" #undef STYLE - } - IGC_ASSERT(0); - return {}; + } + IGC_ASSERT(0); + return nullptr; } Value* RTBuilder::getInstanceContributionToHitGroupIndex( diff --git a/IGC/AdaptorCommon/RayTracing/RTBuilder.h b/IGC/AdaptorCommon/RayTracing/RTBuilder.h index 7e1ce0d9f8c2..cf3bf6b94fd4 100644 --- a/IGC/AdaptorCommon/RayTracing/RTBuilder.h +++ b/IGC/AdaptorCommon/RayTracing/RTBuilder.h @@ -57,6 +57,7 @@ class RTBuilder : public IGCIRBuilder<> //TODO: this is hardcoded string, we might want to put all "printf" of different adaptors to one place eventually static constexpr char *PrintfFuncName = "printf"; + bool isChildOfXe2 = false; // Field for explicit GlobalBufferPtr - used on OpenCL path. @@ -400,8 +401,8 @@ class RTBuilder : public IGCIRBuilder<> Value* getRTStackSize(uint32_t Align); SyncStackPointerVal* getSyncStackPointer(Value* syncStackOffset, RTBuilder::RTMemoryAccessMode Mode); Value* getGeometryIndex( - StackPointerVal* perLaneStackPtr, Instruction* I, Value* leafType, IGC::CallableShaderTypeMD ShaderTy); - PHINode* getPrimitiveIndex( + StackPointerVal* perLaneStackPtr, Value* leafType, bool committed); + Value* getPrimitiveIndex( StackPointerVal* perLaneStackPtr, Value* leafType, bool Committed); Value* getInstanceIndex( StackPointerVal* perLaneStackPtr, IGC::CallableShaderTypeMD ShaderTy);