Problems with bottom level structure indices offsets in VK_KHR_RAY_TRACING

Greeting everyone

I’m creating a Hybrid Renderer using vulkan and I’m having some trouble in the raytracing component with VkAccelerationStructureBuildOffsetInfoKHR and offsets… From what I understand from the specification, the primitiveOffset should be an offset in bytes in either the index buffer or the vertex buffer (In my case since I have an index buffer associated it should be the index buffer).

The problem I’m facing is that I was expecting it to offset my index buffer but after I checked using nvidea nsight it appears it is offsetting my vertex buffer:


here you can see 2 instances where I would expect the index buffer to be offsetted but it appears to be the vertex buffer, see the @_24B).

The way I’m defining the offsets is the following:

VkAccelerationStructureBuildOffsetInfoKHR accelerationBuildOffsetInfo{};
accelerationBuildOffsetInfo.primitiveCount = numTriangles;
accelerationBuildOffsetInfo.primitiveOffset = firstIndex * sizeof(uint32_t);
accelerationBuildOffsetInfo.firstVertex = 0;
accelerationBuildOffsetInfo.transformOffset = 0;

My question is do I need to specify I want to use the index buffer, or what could I be doing wrong?

Thanks in advance!

The updated finalized ray tracing version is pretty clear on this, and it’s exactly as you said: If you’re using an index buffer, primitiveOffset refers to the index buffer:

If the geometry uses indices, primitiveCount × 3 indices are consumed from VkAccelerationStructureGeometryTrianglesDataKHR::indexData , starting at an offset of primitiveOffset . The value of firstVertex is added to the index values before fetching vertices.

This may have been a driver bug with the provisional extension, so you may want to updated to the finalized extension(s) and check if the offset is applied as the specification states.

I figured it out and it turns out to be a bug in nvidea nsight that offsets the vertex buffer no matter what, but the real program was working fine (had a bug but it was in a completely unrelated place, I didn’t know I needed to use an offset buffer in the closest hit shader to unpack the vertices).

Thank you for the help anyway!

Cross-ref:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.