I’m having trouble working with buffer_reference with vulkan. I’m passing a buffer device address to my shader (a closest hit shader) through a uniform block but when I look at it with Nsight it doesn’t point to the right values.
One idea for you: GLSL_EXT_buffer_reference2 seems to imply that the reference type has a specific size. That wouldn’t be the case when the reference type contains an unsized array. In fact, the extension spec indicates one reason for its existance is to avoid doing what you’re doing:
If possible, you might want to pull the variable-length array one-level higher than the block you access via buffer_references. See materials and Material here:
If possible, you might want to pull the variable-length array one-level higher than the block you access via buffer_references. See materials and Material here
Do you mean something like this ?
layout(buffer_reference, scalar, std430) readonly buffer Indices
{
uvec3 Index;
};
layout(binding = 4, std140) uniform cb4
{
Indices indexBuffer;
};
// ...
Indices indices = Indices(obj.indexBuffer);
uvec3 triIndices = indices[gl_PrimitiveID].Index;
That still doesn’t work and it NSight reads [7, 3155034112, 7] from the first index instead of [0, 1, 2]
I got the code following this tutorial
https ://nvpro-samples.github.io/vk_raytracing_tutorial_KHR/#simplelighting/closesthit(raytrace.rchit))
I didn’t understand that I could specify the alignment using buffer_reference_align
Using this, I can access the correct indices without crashing and it turns out the Nsight view is buggy apparently since it doesn’t match the shader output if I output the indices I read.