diff options
| author | Harsh Aggarwal (NVIDIA) <haaggarwal@nvidia.com> | 2025-05-26 23:52:45 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-26 18:22:45 +0000 |
| commit | 5280ca81025d42239fec492eb72d38606308751a (patch) | |
| tree | 170da146e2ad7ac421798da12472c053f2333ea3 | |
| parent | 83538e0b4b97425ecdae6f72f9c8fd44cb255aac (diff) | |
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
| -rw-r--r-- | source/slang/slang-emit-cuda.cpp | 4 | ||||
| -rw-r--r-- | tests/cuda/optix-ignore-hit.slang | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/source/slang/slang-emit-cuda.cpp b/source/slang/slang-emit-cuda.cpp index e5169ba38..e27fd25aa 100644 --- a/source/slang/slang-emit-cuda.cpp +++ b/source/slang/slang-emit-cuda.cpp @@ -882,9 +882,9 @@ bool CUDASourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu } case kIROp_GetOptiXRayPayloadPtr: { - m_writer->emit("("); + m_writer->emit("(("); emitType(inst->getDataType()); - m_writer->emit(")getOptiXRayPayloadPtr()"); + m_writer->emit(")getOptiXRayPayloadPtr())"); return true; } case kIROp_GetOptiXHitAttribute: diff --git a/tests/cuda/optix-ignore-hit.slang b/tests/cuda/optix-ignore-hit.slang index 8bb128ae0..54cc301bb 100644 --- a/tests/cuda/optix-ignore-hit.slang +++ b/tests/cuda/optix-ignore-hit.slang @@ -1,6 +1,6 @@ // optix-ignore-hit.slang //TEST:SIMPLE(filecheck=CHECK): -target cuda -entry anyHitShader -//CHECK: HitBuffer_insert_0((HitBuffer_0 *)getOptiXRayPayloadPtr(), hit_0.t_0); +//CHECK: HitBuffer_insert_0(((HitBuffer_0 *)getOptiXRayPayloadPtr()), hit_0.t_0); //CHECK: optixIgnoreIntersection |
