gpt4 book ai didi

c++ - Vulkan 验证层不断在 VkQueuePresentKHR() 上抛出图像布局错误

转载 作者:行者123 更新时间:2023-12-01 21:50:26 24 4
gpt4 key购买 nike

明显的菜鸟警告。从昨天开始学习Vulkan,正如标题所说,我在提交到present时不断收到上述错误。我已经检查了教程中的代码,但找不到任何明显的错误。这是我的 RenderPass 创建代码:

VkAttachmentDescription colorAttachmentDescription = {};
colorAttachmentDescription.format = this->surfaceFormat.format;
colorAttachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
colorAttachmentDescription.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colorAttachmentDescription.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
colorAttachmentDescription.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
colorAttachmentDescription.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
colorAttachmentDescription.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
colorAttachmentDescription.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;


VkAttachmentReference attachmentReference = {};
attachmentReference.attachment = 0;
attachmentReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;


VkSubpassDescription subpassDescription = {};
subpassDescription.colorAttachmentCount = 1;
subpassDescription.pColorAttachments = &attachmentReference;
subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;


VkSubpassDependency subpassDependency = {};
subpassDependency.srcSubpass = VK_SUBPASS_EXTERNAL;
subpassDependency.dstSubpass = 0;
subpassDependency.srcAccessMask = 0;
subpassDependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpassDependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpassDependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;


VkRenderPassCreateInfo renderPassCreateInfo = {};
renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassCreateInfo.attachmentCount = 1;
renderPassCreateInfo.pAttachments = &colorAttachmentDescription;
renderPassCreateInfo.subpassCount = 1;
renderPassCreateInfo.pSubpasses = &subpassDescription;
renderPassCreateInfo.dependencyCount = 1;
renderPassCreateInfo.pDependencies = &subpassDependency;


vkCreateRenderPass(logicalDevice, &renderPassCreateInfo, nullptr, &renderPass);

哦,我什至尝试将initialLayout更改为VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,但仍然收到错误。这是我收到的验证层错误。

VALIDATION LAYER : Images passed to present must be in layout VK_IMAGE_LAYOUT_PRESENT_SRC_KHR or VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR but is in VK_IMAGE_LAYOUT_UNDEFINED. The Vulkan spec states: Each element of pImageIndices must be the index of a presentable image acquired from the swapchain specified by the corresponding element of the pSwapchains array, and the presented image subresource must be in the VK_IMAGE_LAYOUT_PRESENT_SRC_KHR layout at the time the operation is executed on a VkDevice (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkPresentInfoKHR-pImageIndices-01296)

最佳答案

问题出在您发布的代码中忽略的渲染 channel 创建中。

仔细检查VkAttachmentDescription VkRenderPassCreateInfo 中的条目.

还要检查 attachmentCount 是否不为零。

关于c++ - Vulkan 验证层不断在 VkQueuePresentKHR() 上抛出图像布局错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60353747/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com