Ray Tracing: any hit shader doesn't write to buffer (and ignoreIntersectionEXT blocks payload update)

TLDR: buffer writes from any hit shader are ignored.

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?

Also, I tried to avoid buffer writes by passing data from the any hit shader with the ray payload, but I noticed that ignoring hit with ignoreIntersectionEXT (this is what I actually need) blocks payload update. So, if we will succeed with buffers, will the update being blocked by ignoring the hit?

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