It seems that any 'sbtGASIndex' input can make 'optixGetTriangleVertexData' get correct result

static __forceinline__ __device__ void optixGetTriangleVertexData( OptixTraversableHandle gas,
                                                                   unsigned int           primIdx,
                                                                   unsigned int           sbtGASIndex,
                                                                   float                  time,
                                                                   float3                 data[3] )

I can pass anything to it such as:

float3 data[3];
optixGetTriangleVertexData(optixGetGASTraversableHandle(), optixGetPrimitiveIndex(), 114514,  optixGetRayTime(), data);

but still get the correct result without any exceptions (such as illegal memory access).
So does the sbtGASIndex have any effect?

Hi @JinkaiHu,

I think when you use optixGetPrimitiveIndex() in a hit shader, then this function may not need to use the traversable handle or sbtGasIndex in order to look up your triangle data. If you use a different primitive index than the current hit, then it likely will need those extra arguments. Even in cases when these arguments might not be needed, note that there can still be exceptions and validation errors if you pass bogus info, and behavior might change in the future to require the arguments to match a valid GAS & SBT. For that reason, we recommend using optixGetGASTraversableHandle(), optixGetPrimitiveIndex(), and optixGetSbtGASIndex() even for the current hit primitive.

There is a paragraph hinting at this, along with more info about vertex random access, in the OptiX Programming Guide: " Care has to be taken if optixGetTriangleVertexData is used with a primitive index other than the value returned by optixGetPrimitiveIndex. optixGetTriangleVertexData expects a local primitive index corresponding to the build input / sbtGASIndex plus the primitive index offset as specified in the build input at the acceleration structure build."

https://raytracing-docs.nvidia.com/optix8/guide/index.html#device_side_functions#vertex-random-access

And note that if you want random access (meaning accessing data for other triangles besides the current hit) you will need to build your AS using OPTIX_BUILD_FLAG_ALLOW_RANDOM_VERTEX_ACCESS


David.