本文介绍了Vulkan中多个子路径之间的布局转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图做两个简单的子通道,其中第二个依赖于第一个子通道。 // subpass 1 VkAttachmentReference colorReferences = {0,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}; VkSubpassDescription subpass1 = {}; subpass1.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpass1.pColorAttachments =& colorReferences; subpass1.colorAttachmentCount = 1; // subpass 2 VkAttachmentReference inputRefernce = {0,VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}; VkSubpassDescription subpass2 = {}; subpass2.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpass2.inputAttachmentCount = 1; subpass2.pInputAttachments =& inputRefernce; //渲染过程 VkAttachmentDescription attachmentDescs = {}; attachmentDescs.samples = VK_SAMPLE_COUNT_1_BIT; attachmentDescs.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; attachmentDescs.storeOp = VK_ATTACHMENT_STORE_OP_STORE; attachmentDescs.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachmentDescs.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; attachmentDescs.format = VK_FORMAT_R16G16B16A16_SFLOAT; attachmentDescs.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachmentDescs.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; VkSubpassDependency dependency = {}; dependency.srcSubpass = 0; dependency.dstSubpass = 1; dependency.srcStageMask = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT; dependency.dstStageMask = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT; dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; dependency.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; VkSubpassDescription子路径[2] = {subpass1,subpass2}; VkRenderPassCreateInfo renderPassInfo = {}; renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; renderPassInfo.pAttachments =& attachmentDescs; renderPassInfo.attachmentCount = 1; renderPassInfo.subpassCount = 2; renderPassInfo.pSubpass =子路径; renderPassInfo.dependencyCount = 1; renderPassInfo.pDependencies =& dependency; vkUtils :: checkResult(vkCreateRenderPass(_context-> device,& renderPassInfo,nullptr,& _renderPass)); 我有第一个和第二个子通道之间的依赖关系。规范说明: $ b 它只会在第一个子通道开始时使用附件清除。因为它们之间存在依赖关系,所以它不应该在第二个子通道中清除。我从验证层得到这个错误: 无法用无效的第一个布局VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL清除附件0。 但是 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL 布局在第二个subpass,而不是第一个?解决方案它似乎是图层中的一个错误,它根本不检查哪个用法第一个(它可能是在1.0.17 SDK中引入的 - 1.0.13不应该报告这个...): https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/sdk-1.0.17/layers/core_validation.cpp#L8557 spec引用: I am trying to do two simple subpasses, where the second one has a dependency on the first one. //subpass 1VkAttachmentReference colorReferences = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };VkSubpassDescription subpass1 = {};subpass1.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;subpass1.pColorAttachments = &colorReferences;subpass1.colorAttachmentCount = 1;//subpass 2VkAttachmentReference inputRefernce = { 0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL };VkSubpassDescription subpass2 = {};subpass2.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;subpass2.inputAttachmentCount = 1;subpass2.pInputAttachments = &inputRefernce;//Render passVkAttachmentDescription attachmentDescs = {};attachmentDescs.samples = VK_SAMPLE_COUNT_1_BIT;attachmentDescs.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;attachmentDescs.storeOp = VK_ATTACHMENT_STORE_OP_STORE;attachmentDescs.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;attachmentDescs.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;attachmentDescs.format = VK_FORMAT_R16G16B16A16_SFLOAT;attachmentDescs.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;attachmentDescs.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;VkSubpassDependency dependency = {};dependency.srcSubpass = 0;dependency.dstSubpass = 1; dependency.srcStageMask = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;dependency.dstStageMask = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;dependency.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;VkSubpassDescription subpasses[2] = { subpass1, subpass2 };VkRenderPassCreateInfo renderPassInfo = {};renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;renderPassInfo.pAttachments = &attachmentDescs;renderPassInfo.attachmentCount = 1;renderPassInfo.subpassCount = 2;renderPassInfo.pSubpasses = subpasses;renderPassInfo.dependencyCount = 1;renderPassInfo.pDependencies = &dependency;vkUtils::checkResult(vkCreateRenderPass(_context->device, &renderPassInfo, nullptr, &_renderPass));I have a dependency between the first and the second subpass. The specification says: It will only be cleared at the start of the first subpass the attachment is used. And because there is a dependency between them, it should not be cleared in the second subpass.I get this error from the validation layer:Cannot clear attachment 0 with invalid first layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL.But the VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL layout is in the second subpass, not the first one? 解决方案 It seems to be a bug in the layers, which simply do not check which usage is first (It was probably introduced in 1.0.17 SDK - 1.0.13 should not report this...):https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/sdk-1.0.17/layers/core_validation.cpp#L8557spec quote: 这篇关于Vulkan中多个子路径之间的布局转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-22 13:26