Skip to content

Commit 5280ca8

Browse files
authored
Fix operator precedence in OptiX ray payload pointer casting which broke due to (#6326) (#7194)
* Fix operator precedence in OptiX ray payload pointer casting Added extra parentheses around the cast to ensure proper operator precedence when dereferencing the OptiX ray payload pointer. This fixes the issue where the compiler was treating the expression as (RayPayload_0 *)getOptiXRayPayloadPtr()->color_0 instead of ((RayPayload_0 *)getOptiXRayPayloadPtr())->color_0. Error: nvrtc 12.9: tests/cuda/optix-cluster.slang(17): error : expression must have pointer-to-class type but it has type "void *" nvrtc 12.9: note : (RayPayload_0 *)getOptiXRayPayloadPtr()->color_0 = color_1; nvrtc 12.9: note : ^ Tested using: ./build/Debug/bin/slangc -target ptx -Xnvrtc -I"/home/haaggarwal/NVIDIA-OptiX-SDK-9.0.0-linux64-x86_64/include" -DSLANG_CUDA_ENABLE_OPTIX -entry closestHitShaderA ./tests/cuda/optix-cluster.slang * Fix Check
1 parent 83538e0 commit 5280ca8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

source/slang/slang-emit-cuda.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,9 @@ bool CUDASourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
882882
}
883883
case kIROp_GetOptiXRayPayloadPtr:
884884
{
885-
m_writer->emit("(");
885+
m_writer->emit("((");
886886
emitType(inst->getDataType());
887-
m_writer->emit(")getOptiXRayPayloadPtr()");
887+
m_writer->emit(")getOptiXRayPayloadPtr())");
888888
return true;
889889
}
890890
case kIROp_GetOptiXHitAttribute:

tests/cuda/optix-ignore-hit.slang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// optix-ignore-hit.slang
22
//TEST:SIMPLE(filecheck=CHECK): -target cuda -entry anyHitShader
3-
//CHECK: HitBuffer_insert_0((HitBuffer_0 *)getOptiXRayPayloadPtr(), hit_0.t_0);
3+
//CHECK: HitBuffer_insert_0(((HitBuffer_0 *)getOptiXRayPayloadPtr()), hit_0.t_0);
44
//CHECK: optixIgnoreIntersection
55

66

0 commit comments

Comments
 (0)