首页 > 解决方案 > 提交的命令缓冲区上的 CoreValidation-DrawState-InvalidImageLayout 错误

问题描述

我不知道为什么我会收到这个错误

消息:[UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout] 对象:0x55f38f345890(类型 = 6)| 提交的命令缓冲区期望图像 0x1e(子资源:aspectMask 0x1 数组第 0 层,mip 级别 0)在布局 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL 中——相反,图像 0x1e 的当前布局是 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR。

我正在使用命令缓冲区将图像从帧缓冲区传输到当前存在的图像,如下所示

    command_buffer.transitionImageLayout(
  framebuffer_image, ImageLayout::COLOR_ATTACHMENT_OPTIMAL, ImageLayout::TRANSFERT_SRC_OPTIMAL);

command_buffer.transitionImageLayout(
  current_image, ImageLayout::PRESENT_SRC, ImageLayout::TRANSFERT_DST_OPTIMAL);

command_buffer.blitImage(
  framebuffer_image, current_image, framebuffer_image.extent(), m_extent);

command_buffer.transitionImageLayout(
  framebuffer_image, ImageLayout::TRANSFERT_SRC_OPTIMAL, ImageLayout::COLOR_ATTACHMENT_OPTIMAL);

command_buffer.transitionImageLayout(
  current_image, ImageLayout::TRANSFERT_DST_OPTIMAL, ImageLayout::PRESENT_SRC);

错误在命令缓冲区提交时触发

我激活了 VK_LAYER_LUNARG_api_dump 层,我得到了这个:

https://pastebin.com/AFyePUpM

标签: c++vulkan

解决方案


错误消息非常简单。

您首先VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL在命令缓冲区中使用图像。我们可以看到并验证:

command_buffer.transitionImageLayout( framebuffer_image, ImageLayout::COLOR_ATTACHMENT_OPTIMAL // etc

该错误通知您该图像是在VK_IMAGE_LAYOUT_PRESENT_SRC_KHR而不是。这是如何发生的取决于您的代码的其余部分。您必须在之前(意外地)将图像转换为该布局。那将是通过一些 previousvkCmdPipelineBarrier或通过 renderpass finalLayout

(或者验证层中不太可能存在错误。在这种情况下,将其报告给KhronosGroup/Vulkan-ValidationLayers。)


推荐阅读