Vulkan.hpp 低音炮附件违反了验证层

Vulkan.hpp Supbass attachment violates validation layer

我有以下 vulkan 初始化代码:

vk::AttachmentReference color_attachment_ref(0,
    vk::ImageLayout::eColorAttachmentOptimal);

auto colorAttachment = *(VkAttachmentDescription*)&color_attachment;
auto colorAttachmentRef = (VkAttachmentReference)color_attachment_ref;

/*vk::SubpassDescription spass({}, vk::PipelineBindPoint::eGraphics, 1,
    &color_attachment_ref);
auto subpass = (VkSubpassDescription) spass;*/
VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorAttachmentRef;

然而,当我尝试重构代码以使用 vulkan.hpp 中的对象时,这非常有效:

vk::AttachmentReference color_attachment_ref(0,
    vk::ImageLayout::eColorAttachmentOptimal);

auto colorAttachment = *(VkAttachmentDescription*)&color_attachment;
auto colorAttachmentRef = (VkAttachmentReference)color_attachment_ref;

vk::SubpassDescription spass({}, vk::PipelineBindPoint::eGraphics, 1,
    &color_attachment_ref);
auto subpass = (VkSubpassDescription) spass;
/*VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorAttachmentRef;*/

我得到:

validation layer: Layout for input attachment is VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.
UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout

据我所知,两种方法初始化是等价的,我搞砸了什么?

问题出在参数的顺序上。我传递的参数不对应函数签名,正确的版本是:

vk::SubpassDescription spass({}, vk::PipelineBindPoint::eGraphics, 0, nullptr, 1,
&color_attachment_ref);

考虑到 2 个未使用的参数。