Payload for recursive ray tracing

For a recursive ray tracing program, where the new optixTrace() is called from the CH function and the original payload is packed into u0 and u1, can we pass u0 and u1 directly into the new call or do we have to pack the payload again?

Since the per ray payload pointer itself doesn’t change you can just pass through the same values.

Thanks

If a function is called from the closest hit function, can device functions like optixGetWorldRayDIrection() be used in it?

That question is a little too general for a yes or no answer.

Each of the OptiX built-in device functions might be allowed in only a subset of the program domains.
You need to look that up inside the OptiX Programming Guide, OptiX API Reference or headers for each function individually.
Here’s a nice table:
https://raytracing-docs.nvidia.com/optix7/guide/index.html#device_side_functions#device-side-functions
And each function lists that inside the headers and API reference, like here for optixGetWorldRayDirection:
https://raytracing-docs.nvidia.com/optix7/api/html/group__optix__device__api.html#ga1eb6345545b3cf9a67bb345a3b3052e6

Then if you mean some device function you call inside any of the allowed program domains, that function should normally be inlined by OptiX automatically and would have the same program scope, so yes, that’d work or the compiler or runtime would throw an error.
That’s why I rigorously use forceinline device on any function which is not a program or callable.

Thank you. That cleared it up.