我正在尝试使用在子通道0中创建的颜色附件作为子通道1中的输入附件。但是有一个问题我无法通过。
我目前的问题如下,我尝试使用VK_ATTACHMENT_LOAD_OP_CLEAR
在传递开始时清除附件0但是会出错。
Cannot clear attachment 0 with invalid first layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL.
对我来说这看起来很奇怪,附件0没有得到布局VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
,直到它是输入附件的subpass 1,而当布局仍然是VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
时,清除应该已经发生了(AFAIK)
我现在尝试在验证错误后继续运行,附件0 清除,这让我更加不确定。我显然可以忽略验证错误,但可能会发生一些奇怪的事情,这可能会导致以后出现问题,所以我不会轻易忽略它。
以下是给出错误的最小代码:
VkAttachmentDescription attachments[1] {};
attachments[0].format = VK_FORMAT_R16G16B16A16_SFLOAT;
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT;
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachments[0].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkAttachmentReference pass_0_ColorAttachments[1];
pass_0_ColorAttachments[0].attachment = 0;
pass_0_ColorAttachments[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkAttachmentReference pass_1_InputAttachments[1];
pass_1_InputAttachments[0].attachment = 0;
pass_1_InputAttachments[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
VkSubpassDescription subpasses[2] {};
subpasses[0].colorAttachmentCount = 1;
subpasses[0].pColorAttachments = pass_0_ColorAttachments;
subpasses[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpasses[1].inputAttachmentCount = 1;
subpasses[1].pInputAttachments = pass_1_InputAttachments;
subpasses[1].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
VkSubpassDependency subpassDependancies[1] {};
subpassDependancies[0].srcSubpass = 0;
subpassDependancies[0].dstSubpass = 1;
subpassDependancies[0].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpassDependancies[0].dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
subpassDependancies[0].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
subpassDependancies[0].dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
subpassDependancies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
VkRenderPassCreateInfo renderpassCreateInfo {};
renderpassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderpassCreateInfo.attachmentCount = 1;
renderpassCreateInfo.pAttachments = attachments;
renderpassCreateInfo.subpassCount = 2;
renderpassCreateInfo.pSubpasses = subpasses;
renderpassCreateInfo.dependencyCount = 1;
renderpassCreateInfo.pDependencies = subpassDependancies;
VkRenderPass renderPass;
vkCreateRenderPass(device, &renderpassCreateInfo, nullptr, &renderPass);
如果无法为首先用作颜色附件的附件指定VK_ATTACHMENT_LOAD_OP_CLEAR
,而在后面的子通道中作为输入附件,则下一部分仅相关(我认为没有理由为什么这是不可能的,除非vulkan确实如此)每个子通道的加载操作)。所以这是一个单独的问题。
我可以,而不是使用VK_ATTACHMENT_LOAD_OP_CLEAR
,使用vkCmdClearAttachments
手动清除附件,并使用VK_ATTACHMENT_LOAD_OP_DONT_CARE
进行附件的加载操作。
我在调用vkCmdClearAttachments
时出现崩溃错误
我启动了命令缓冲区记录和renderpass,并在第一个子通道中调用:
VkClearAttachment clearAtts[] = {{VK_IMAGE_ASPECT_COLOR_BIT, 1, {0,0,0,0}}};
VkClearRect rect = {{{0,0}, {1,1}}, 0, 1};
vkCmdClearAttachments(vkCommandBuffer, 1, clearAtts, 1, &rect);
{1,1}表示这不是问题的程度
答案 0 :(得分:4)
你遇到了同样的问题as was discovered here。这是1.0.17中验证层的错误。似乎current Github head有一个修复,但该修复不在1.0.21版本中。
但是仍然需要修复下面的内容;)
subpassDependancies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
您不会将图像作为颜色附件阅读。您将把它作为输入附件阅读。从片段着色器。这意味着VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
。
如果这样可以解决错误,那么我猜你的奇怪的依赖访问掩码会让验证层感到困惑。因此,它无法在子通道0和1之间建立有效的依赖关系链,因此认为子通道1是第一个。
此外,您的srcStageMask
和dstStageMask
位 way 过度指定。每个图形阶段都不会写入图像,并且每个图形阶段之后都不会访问它。您只是将图像写为颜色附件,而您只是在片段着色器中读取它。
因此,srcStageMask
应该只是VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
,而dstStageMask
应该是VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
。