I set up a minimal ray tracing pipeline in vulkan, with any and closest hit shaders that write into buffers and ray payloads.
The problem is that buffer writes from the any hit shader seem not to take effect.
Here is the source code for the closest hit shader:
layout(set = 0, binding = 0, std430) writeonly buffer RayStatusBuffer {
uint items[];
} gRayStatus;
layout(location = 0) rayPayloadInEXT uint gRayPayload;
void main(void)
{
gRayStatus.items[0] = 1;
gRayPayload = 2;
}
The any hit shader code is identical, except for writing 3
and 4
for ray status buffer item and ray payload, respectively.
The buffer associated with gRayStatus
is initialized to 0
and fed to the pipeline with:
VkDescriptorSetLayoutBinding statusLB{};
statusLB.binding = 0;
statusLB.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
statusLB.descriptorCount = 1;
statusLB.stageFlags = VK_SHADER_STAGE_ANY_HIT_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
By calling traceRayEXT(..., flags = 0, ...)
from the raygen shader, I can read back the values 1
and 2
for ray status buffer item and ray payload, respectively and as expected.
But when calling traceRayEXT(..., flags = gl_RayFlagsSkipClosestHitShaderEXT, ...)
I would expect the output of the any hit shader (3
and 4
) to be present, but I get 0
and 4
, as if the buffer write would have been ignored.
Any idea on this?
sorry for the late response. From what I know, there could be two causes:
1° Any hit shaders are not called because of the flag VkGeometryFlagBitsKHR in the struct VkAccelerationStructureGeometryKHR used during the creation of a BLAS.
2° The conditions in which the any hit shaders are called. Look at this image helped me a lot: https://www.google.com/search?q=DxT+rtx+pipeline&tbm=isch&ved=2ahUKEwiTko-Gv-f8AhXCsEwKHUILD4IQ2-cCegQIABAA&oq=DxT+rtx+pipeline&gs_lcp=CgNpbWcQAzoECCMQJzoFCAAQgAQ6BggAEAUQHjoGCAAQCBAeOgQIABAeOgcIABCABBAYUKEPWIg5YPc5aAlwAHgAgAFmiAGyD5IBBDE4LjSYAQCgAQGqAQtnd3Mtd2l6LWltZ8ABAQ&sclient=img&ei=06DTY9PcIMLhsgLClryQCA&bih=1067&biw=1920&client=firefox-b-d#imgrc=38W16ovqUoCyRM As you can see from the picture an any shader shader is called only if the hit geometry is the closest and is not opaque