rtBuffer - indexing

That is normally not required. CUDA aligns structures to the biggest alignment required by any element inside the struct already.
See this documentation on the CUDA alignment requirements and esp. note the possibly different behavior for arrays of structs in host and device compilers in the second link:
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#vector-types
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#kernel-execution
When I use arrays of structures on host and device, I manually pad the structure size to the required alignment.

It’s needed if you would like to align things to bigger values. There are some examples in OptiX itself:
https://raytracing-docs.nvidia.com/optix7/api/html/group__optix__types.html#ga816ed5bbb93d53c783561497a474308e
where OPTIX_SBT_RECORD_ALIGNMENT is needed because the SBT record header starts with a char array which would normally be aligned to 1 byte and not 16.

Or this example where I defined my own half4 struct because CUDA provides only half and half2 types and it’s aligned to let the compiler generate vectorized (.v4) load and store PTX instructions:
https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/intro_denoiser/shaders/half_common.h#L42

1 Like