Hey everyone!
I’ve been following vulkan-tutorials.com very closely but have been recently running into a strange problem.
Basically, vulkan crashes randomly on the first occurance of vkCmdBeginRenderPass. And I really mean randomly - 20% crash rate on start as far as I can tell.
Now, all the code that happens before that crash is pretty much the same as in https://vulkan-tutorial.com/code/depth_buffering.cpp with the only difference being, that I have 2 more subpasses, which I add as follows:
std::vector<VkSubpassDescription> subPasses;
std::vector<VkSubpassDependency> dependencies;
{
VkSubpassDescription subPass = {};
subPass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subPass.colorAttachmentCount = 1;
subPass.pColorAttachments = &colorAttachmentRef;
subPass.pDepthStencilAttachment = &depthAttachmentRef;
VkSubpassDependency dependency = {};
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
dependency.dstSubpass = 0;
dependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
dependency.srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependency.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
subPasses.push_back(subPass);
dependencies.push_back(dependency);
dependency.srcSubpass = 0;
dependency.dstSubpass = 1;
dependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependency.dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
dependency.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
dependencies.push_back(dependency);
}
{
VkSubpassDescription subPass = {};
subPass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subPass.colorAttachmentCount = 1;
subPass.pColorAttachments = &colorAttachmentRef;
subPass.pDepthStencilAttachment = &depthAttachmentRef;
VkSubpassDependency dependency = {};
dependency.srcSubpass = 1;
dependency.dstSubpass = 2;
dependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependency.dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
dependency.dstAccessMask = VK_ACCESS_SHADER_READ_BIT |
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
subPasses.push_back(subPass);
dependencies.push_back(dependency);
}
{
VkSubpassDescription subPass = {};
subPass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subPass.colorAttachmentCount = 1;
subPass.pColorAttachments = &colorAttachmentRef;
subPass.pDepthStencilAttachment = &depthAttachmentRef;
subPasses.push_back(subPass);
}
std::array<VkAttachmentDescription, 2> attachments = { colorAttachment, depthAttachment };
VkRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassInfo.attachmentCount = attachments.size();
renderPassInfo.pAttachments = attachments.data();
renderPassInfo.subpassCount = subPasses.size();
renderPassInfo.pSubpasses = subPasses.data();
renderPassInfo.dependencyCount = dependencies.size();
renderPassInfo.pDependencies = dependencies.data();
if (vkCreateRenderPass(device, &renderPassInfo, nullptr, renderPass.replace()) != VK_SUCCESS)
{
//failed to create render pass, etc..
}
The 2nd and 3rd Subpass Pipelines are the same as the first, just copy pasted with the correct VkGraphicsPipelineCreateInfo::subpass Number.
The reason why I’m using VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT (and the others) as the mask is, that I later want to add code for a second Attachment to draw on.
But it just sometimes crashes vkCmdBeginRenderPass and it’s driving me insane. Did I mess up the dependencies too bad? All the other code is the same as on vulkan-tutorial.com.
The error I’m getting:
Unhandled exception at 0x00007FFEB56AB9C6 (VkLayer_core_validation.dll) in Test.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
Does anyone have an idea what might be going wrong?