Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPIR-V: Emit RayTmaxKHR builtin for RayTCurrent IOP #3320

Merged
merged 2 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/clang/lib/SPIRV/DeclResultIdMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2895,6 +2895,7 @@ SpirvVariable *DeclResultIdMapper::getBuiltinVar(spv::BuiltIn builtIn,
case spv::BuiltIn::SubgroupSize:
case spv::BuiltIn::SubgroupLocalInvocationId:
case spv::BuiltIn::HitTNV:
case spv::BuiltIn::RayTmaxNV:
case spv::BuiltIn::RayTminNV:
case spv::BuiltIn::HitKindNV:
case spv::BuiltIn::IncomingRayFlagsNV:
Expand Down
7 changes: 6 additions & 1 deletion tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9814,6 +9814,8 @@ SpirvEmitter::processIntrinsicLog10(const CallExpr *callExpr) {

SpirvInstruction *SpirvEmitter::processRayBuiltins(const CallExpr *callExpr,
hlsl::IntrinsicOp op) {
bool nvRayTracing =
featureManager.isExtensionEnabled(Extension::NV_ray_tracing);
spv::BuiltIn builtin = spv::BuiltIn::Max;
bool transposeMatrix = false;
const auto loc = callExpr->getExprLoc();
Expand All @@ -9825,7 +9827,10 @@ SpirvInstruction *SpirvEmitter::processRayBuiltins(const CallExpr *callExpr,
builtin = spv::BuiltIn::LaunchIdNV;
break;
case hlsl::IntrinsicOp::IOP_RayTCurrent:
builtin = spv::BuiltIn::HitTNV;
if (nvRayTracing)
builtin = spv::BuiltIn::HitTNV;
else
builtin = spv::BuiltIn::RayTmaxKHR;
break;
case hlsl::IntrinsicOp::IOP_RayTMin:
builtin = spv::BuiltIn::RayTminNV;
Expand Down
3 changes: 3 additions & 0 deletions tools/clang/test/CodeGenSPIRV/raytracing.khr.closesthit.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// CHECK: OpDecorate [[k:%\d+]] BuiltIn WorldToObjectNV
// CHECK: OpDecorate [[l:%\d+]] BuiltIn HitKindNV
// CHECK: OpDecorate [[m:%\d+]] BuiltIn RayGeometryIndexKHR
// CHECK: OpDecorate [[n:%\d+]] BuiltIn RayTmaxNV

// CHECK: OpTypePointer IncomingRayPayloadNV %Payload
struct Payload
Expand Down Expand Up @@ -75,6 +76,8 @@ void main(inout Payload MyPayload, in Attribute MyAttr) {
uint _16 = HitKind();
// CHECK: OpLoad %uint [[m]]
uint _17 = GeometryIndex();
// CHECK: OpLoad %float [[n]]
uint _18 = RayTCurrent();

Payload myPayload = { float4(0.0f,0.0f,0.0f,0.0f) };
CallData myCallData = { float4(0.0f,0.0f,0.0f,0.0f) };
Expand Down
3 changes: 3 additions & 0 deletions tools/clang/test/CodeGenSPIRV/raytracing.nv.anyhit.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// CHECK: OpDecorate [[j:%\d+]] BuiltIn ObjectToWorldNV
// CHECK: OpDecorate [[k:%\d+]] BuiltIn WorldToObjectNV
// CHECK: OpDecorate [[l:%\d+]] BuiltIn HitKindNV
// CHECK: OpDecorate [[m:%\d+]] BuiltIn HitTNV

// CHECK: OpTypePointer IncomingRayPayloadNV %Payload
struct Payload
Expand Down Expand Up @@ -67,6 +68,8 @@ void main(inout Payload MyPayload, in Attribute MyAttr) {
float4x3 _15 = WorldToObject4x3();
// CHECK: OpLoad %uint [[l]]
uint _16 = HitKind();
// CHECK: OpLoad %float [[m]]
uint _17 = RayTCurrent();

if (_16 == 1U) {
// CHECK: [[payloadread0:%\d+]] = OpLoad %Payload %MyPayload_0
Expand Down
3 changes: 3 additions & 0 deletions tools/clang/test/CodeGenSPIRV/raytracing.nv.closesthit.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// CHECK: OpDecorate [[j:%\d+]] BuiltIn ObjectToWorldNV
// CHECK: OpDecorate [[k:%\d+]] BuiltIn WorldToObjectNV
// CHECK: OpDecorate [[l:%\d+]] BuiltIn HitKindNV
// CHECK: OpDecorate [[m:%\d+]] BuiltIn HitTNV

// CHECK: OpTypePointer IncomingRayPayloadNV %Payload
struct Payload
Expand Down Expand Up @@ -67,6 +68,8 @@ void main(inout Payload MyPayload, in Attribute MyAttr) {
float4x3 _15 = WorldToObject4x3();
// CHECK: OpLoad %uint [[l]]
uint _16 = HitKind();
// CHECK: OpLoad %float [[m]]
uint _17 = RayTCurrent();

Payload myPayload = { float4(0.0f,0.0f,0.0f,0.0f) };
RayDesc rayDesc;
Expand Down