Skip to content

Commit

Permalink
Fix OpRayQueryGenerateIntersectionKHR behavior (#2702)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LLJJDD authored Sep 19, 2023
1 parent 3d7228a commit 7aa4658
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions llpc/lower/llpcSpirvLowerRayQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ template <> void SpirvLowerRayQuery::createRayQueryFunc<OpRayQueryGenerateInters
// {
// rayQuery.commit = rayQuery.candidate
// rayQuery.committedStatus = gl_RayQueryCommittedIntersectionGeneratedEXT
// rayQuery.committed.rayTCurrent = tHit
// rayQuery.committed.rayTCurrent = tHit - rayQuery.rayTMin
// }
// }
func->addFnAttr(Attribute::AlwaysInline);
Expand Down Expand Up @@ -864,7 +864,11 @@ template <> void SpirvLowerRayQuery::createRayQueryFunc<OpRayQueryGenerateInters
storeAddr = m_builder->CreateGEP(
rayQueryTy, rayQuery,
{zero, m_builder->getInt32(RayQueryParams::Committed), m_builder->getInt32(RaySystemParams::RayTCurrent)});
m_builder->CreateStore(hitT, storeAddr);
Value *rayTMinAddr = m_builder->CreateGEP(rayQueryTy, rayQuery,
{m_builder->getInt32(0), m_builder->getInt32(RayQueryParams::RayTMin)});
auto minTVal = m_builder->CreateLoad(m_builder->getFloatTy(), rayTMinAddr);
// NOTE: rayTCurrent stored in rayQuery is relative to rayTMin, but tHit given by app is relative to ray origin.
m_builder->CreateStore(m_builder->CreateFSub(hitT, minTVal), storeAddr);
m_builder->CreateBr(endBlock);

m_builder->SetInsertPoint(endBlock);
Expand Down

0 comments on commit 7aa4658

Please sign in to comment.