Skip to content

Commit 7aa4658

Browse files
author
Junda Liu
authored
Fix OpRayQueryGenerateIntersectionKHR behavior (#2702)
Problem: In our GPURT implementation, rayQuery.RayTCurrent is relative to rayQuery.RayTMin, so for OpRayQueryGetIntersectionTKHR, we return (RayTCurrent + RayTMin) = Hit T relative to ray origin. However, for OpRayQueryGenerateIntersectionKHR, we simply store the HitT value given by shader into rayQuery.RayTCurrent, and return it with RayTMin offset when OpRayQueryGetIntersectionTKHR is called again. Fix: For OpRayQueryGenerateIntersectionKHR, we store (HitT - rayQuery.RayTMin), so that rayQuery.RayTCurrent always represents offset to RayTMin.
1 parent 3d7228a commit 7aa4658

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llpc/lower/llpcSpirvLowerRayQuery.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ template <> void SpirvLowerRayQuery::createRayQueryFunc<OpRayQueryGenerateInters
836836
// {
837837
// rayQuery.commit = rayQuery.candidate
838838
// rayQuery.committedStatus = gl_RayQueryCommittedIntersectionGeneratedEXT
839-
// rayQuery.committed.rayTCurrent = tHit
839+
// rayQuery.committed.rayTCurrent = tHit - rayQuery.rayTMin
840840
// }
841841
// }
842842
func->addFnAttr(Attribute::AlwaysInline);
@@ -864,7 +864,11 @@ template <> void SpirvLowerRayQuery::createRayQueryFunc<OpRayQueryGenerateInters
864864
storeAddr = m_builder->CreateGEP(
865865
rayQueryTy, rayQuery,
866866
{zero, m_builder->getInt32(RayQueryParams::Committed), m_builder->getInt32(RaySystemParams::RayTCurrent)});
867-
m_builder->CreateStore(hitT, storeAddr);
867+
Value *rayTMinAddr = m_builder->CreateGEP(rayQueryTy, rayQuery,
868+
{m_builder->getInt32(0), m_builder->getInt32(RayQueryParams::RayTMin)});
869+
auto minTVal = m_builder->CreateLoad(m_builder->getFloatTy(), rayTMinAddr);
870+
// NOTE: rayTCurrent stored in rayQuery is relative to rayTMin, but tHit given by app is relative to ray origin.
871+
m_builder->CreateStore(m_builder->CreateFSub(hitT, minTVal), storeAddr);
868872
m_builder->CreateBr(endBlock);
869873

870874
m_builder->SetInsertPoint(endBlock);

0 commit comments

Comments
 (0)