我有以下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 个未使用的参数。