Some other general OptiX device code tips and tricks.
- Always align your fields inside structures to offsets which match their native CUDA alignment restrictions.
I normally place them from bigger to smaller alignments. That avoids padding by the compiler (potentially smaller struct!) and inadvertent misaligned address errors.
https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/nvlink_shared/shaders/per_ray_data.h#L86 - Avoid the C++
booltype in structures or payloads.
Use native CUDA data types instead or combine multiple booleans into an unsigned int as bitfield. - Make sure to always initialize all per ray payload values correctly.
Always think about what values you expect when programs aren’t actually called. (You might be able to avoid miss programs when initializing the payloads for the miss case, e.g. shadow/visibility rays don’t need a miss program.)