🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Synchronization issue

Started by
0 comments, last by _void_ 3 years, 3 months ago

Hey guys,

I have raytracing shader where I write the raytraced result to a storage image. After, I run a render pass to read the raytraced result as an input attachment in the fragment shader and output the result to the swapchain.

As a result, I get a corrupted image on the screen. According to the validation layer, I have a synchronization issue

"[Validation | Error] SYNC-HAZARD-READ_AFTER_WRITE: (1287084845) Validation Error: [ SYNC-HAZARD-READ_AFTER_WRITE ] Object 0: handle = 0x5261630000000026, name = Sample::m_pPostRaytraceRenderPass, type = VK_OBJECT_TYPE_RENDER_PASS; | MessageID = 0x4cb75b2d | vkCmdBeginRenderPass: Hazard READ_AFTER_WRITE vs. layout transition in subpass 0 for attachment 0 aspect color during load with loadOp VK_ATTACHMENT_LOAD_OP_LOAD."

I am not able to grasp where the issue comes from. Do you spot anything wrong with my render pass setup?

VkAttachmentDescription attachmentDescs[2];
// Raytraced result as input attachment
attachmentDescs[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
attachmentDescs[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachmentDescs[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachmentDescs[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachmentDescs[0].initialLayout = VK_IMAGE_LAYOUT_GENERAL;
attachmentDescs[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
// Swapchain image as an output
attachmentDescs[1].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachmentDescs[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachmentDescs[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachmentDescs[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachmentDescs[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
attachmentDescs[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
	
// Raytraced result as input attachment
VkAttachmentReference inputAttachmentReference;
inputAttachmentReference.attachment = 0;
inputAttachmentReference.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;

// Swapchain image as color attachment
VkAttachmentReference colorAttachmentReference;
colorAttachmentReference.attachment = 1;
colorAttachmentReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

VkSubpassDependency subpassDependencies[2];
// Dependency on raytraced result to be ready from raytracing shader
subpassDependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
subpassDependencies[0].dstSubpass = 0; /*output raytraced result subpass*/
subpassDependencies[0].srcStageMask = VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR;
subpassDependencies[0].dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
subpassDependencies[0].srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
subpassDependencies[0].dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
// Dependency on swapchain image to be acquired and ready for output
subpassDependencies[1].srcSubpass = VK_SUBPASS_EXTERNAL;
subpassDependencies[1].dstSubpass = 0; /*output raytraced result subpass*/
subpassDependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpassDependencies[1].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpassDependencies[1].srcAccessMask = 0;
subpassDependencies[1].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;

VkSubpassDescription subpassDesc;
subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpassDesc.inputAttachmentCount = 1;
subpassDesc.pInputAttachments = &inputAttachmentReference;
subpassDesc.colorAttachmentCount = 1;
subpassDesc.pColorAttachments = &colorAttachmentReference;

// SubmitInfo configuration
const VkPipelineStageFlags submitWaitStageMasks = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkSubmitInfo submitInfo;
submitInfo.waitSemaphoreCount = 1;
submitInfo.pWaitSemaphores = &m_AcquiredSemaphores[m_FrameIndex];
submitInfo.pWaitDstStageMask = &submitWaitStageMasks;

Many thanks!

This topic is closed to new replies.

Advertisement