1

I'm currently working on my Vulkan renderer and I'm trying to implement ImGUI. I use 2 separate render passes. One for the "main" rendering of my scene and one for DearImGUI. But here comes the problem. When I began the IMGUI renderpass I keep getting the following error:

validation layervkCmdBeginRenderPass(): pCreateInfo->pAttachments[0] VkImageView 0xead9370000000008 is invalid.
The Vulkan spec states: framebuffer must be a valid VkFramebuffer handle

My Renderpass code & framebuffer creation:

//Create Render Pass
VkAttachmentDescription attachment = {};
attachment.format = m_Context->m_SwapChainImageFormat;
attachment.samples = VK_SAMPLE_COUNT_1_BIT;
attachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachment.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;

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

VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &color_attachment;

VkSubpassDependency dependency = {};
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
dependency.dstSubpass = 0;
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependency.srcAccessMask = 0;  // or VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;

VkRenderPassCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
info.attachmentCount = 1;
info.pAttachments = &attachment;
info.subpassCount = 1;
info.pSubpasses = &subpass;
info.dependencyCount = 1;
info.pDependencies = &dependency;
if (vkCreateRenderPass(m_Context->m_LogicalDevice, &info, nullptr, &m_RenderPass) != VK_SUCCESS) {
    throw std::runtime_error("Could not create Dear ImGui's render pass");
}

{
    VkImageView attachmentImageView[1];
    VkFramebufferCreateInfo info = {};
    info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
    info.renderPass = m_RenderPass;
    info.attachmentCount = 1;
    info.pAttachments = attachmentImageView;
    info.width = m_Context->m_SwapChainExtent.width;
    info.height = m_Context->m_SwapChainExtent.height;
    info.layers = 1;
    m_FrameBuffers.resize(m_Context->m_SwapChainImageViews.size());
    for (uint32_t i = 0; i < m_Context->m_SwapChainImageViews.size(); i++)
    {
        std::cout << i << std::endl;
        std::cout << m_Context->m_SwapChainImageViews[i] << std::endl;

        attachmentImageView[0] = m_Context->m_SwapChainImageViews[i];
        vkCreateFramebuffer(m_Context->m_LogicalDevice, &info, nullptr, &m_FrameBuffers[i]);
    }
}

Here is the code for creating the image views:

VkImageView Image::createImageView(VulkanContext& context, VkImage &image, VkFormat format, VkImageAspectFlags aspectFlags, uint32_t mipLevels)
{
    VkImageViewCreateInfo viewInfo{};
    viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
    viewInfo.image = image;
    viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
    viewInfo.format = format;
    viewInfo.subresourceRange.aspectMask = aspectFlags;
    viewInfo.subresourceRange.baseMipLevel = 0;
    viewInfo.subresourceRange.levelCount = mipLevels;
    viewInfo.subresourceRange.baseArrayLayer = 0;
    viewInfo.subresourceRange.layerCount = 1;
    VkImageView imageView;
    if (vkCreateImageView(context.m_LogicalDevice, &viewInfo, nullptr, &imageView) != VK_SUCCESS) {
        throw std::runtime_error("failed to create image view!");
    }
    return imageView;
}

void Swapchain::createImageViews(VulkanContext &context)
{
    m_Context.m_SwapChainImageViews.resize(m_Context.m_SwapChainImages.size());

    for (size_t i = 0; i < m_Context.m_SwapChainImages.size(); i++) {
        m_Context.m_SwapChainImageViews[i] = Image::createImageView(context,context.m_SwapChainImages[i], m_Context.m_SwapChainImageFormat, VK_IMAGE_ASPECT_COLOR_BIT, 1);
    }
}

Also I want to mention that I've checked that nothing is VK_NULL_HANDLE.

1 Answer 1

0

You're creating an array of type VkImageView with a size of one right above your VkFramebufferCreateInfo struct with VkImageView attachmentImageView[1];

info.pAttachments expects you to provide an already created image view.

You have to create your VkImageViews first, then pass it to VkFramebufferCreateInfo. It's also a good idea to have as many VkImageViews as frames in flight.

For one image view:

VkImageView imageView;
...
vkCreateImageView(device, &ivInfo, nullptr, &imageView);
...
info.pAttachments = &imageView;

For an array or vector of VkFramebuffer and VkImageView:

std::vector<VkImageView> imageViews;
for (int i = 0; i < framesInFlight; ++i) {
    ...
    vkCreateImageView(device, &ivInfo, nullptr, &imageViews[i]);
}

std::vector<VkFramebuffer> framebuffers;
for (int i = 0; i < framesInFlight; ++i) {
    ...
    info.pAttachments = &imageViews[i];
    ...
    vkCreateFramebuffer(device, &info, nullptr, &framebuffers[i]);
}

If you have multiple image view attachments:

std::array<VkImageView, 2> attachmentImageViews;
std::vector<VkFramebuffer> framebuffers;
for (int i = 0; i < framesInFlight; ++i) {
    ...
    attachmentImageViews = { msaaImageView, imageView[i] }; // these need to have been already created
    info.attachmentCount = 2;
    info.pAttachments = attachmentImageViews.data();
    ...
    vkCreateFramebuffer(device, &info, nullptr, &framebuffers[i]);
}

The Vulkan spec states:

If flags does not include VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT and attachmentCount is not 0, pAttachments must be a valid pointer to an array of attachmentCount valid VkImageView handles

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.