Vulkan: Only create imgui renderpass once (#972)

This commit is contained in:
goeiecool9999 2023-09-20 19:01:56 +02:00 committed by GitHub
parent 1d398551e2
commit b4aa10bee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 27 deletions

View File

@ -1508,34 +1508,37 @@ void VulkanRenderer::DeleteNullObjects()
void VulkanRenderer::ImguiInit() void VulkanRenderer::ImguiInit()
{ {
// TODO: renderpass swapchain format may change between srgb and rgb -> need reinit if (m_imguiRenderPass == VK_NULL_HANDLE)
VkAttachmentDescription colorAttachment = {}; {
colorAttachment.format = m_mainSwapchainInfo->m_surfaceFormat.format; // TODO: renderpass swapchain format may change between srgb and rgb -> need reinit
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT; VkAttachmentDescription colorAttachment = {};
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; colorAttachment.format = m_mainSwapchainInfo->m_surfaceFormat.format;
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
VkAttachmentReference colorAttachmentRef = {}; VkAttachmentReference colorAttachmentRef = {};
colorAttachmentRef.attachment = 0; colorAttachmentRef.attachment = 0;
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkSubpassDescription subpass = {}; VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = 1; subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorAttachmentRef; subpass.pColorAttachments = &colorAttachmentRef;
VkRenderPassCreateInfo renderPassInfo = {}; VkRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassInfo.attachmentCount = 1; renderPassInfo.attachmentCount = 1;
renderPassInfo.pAttachments = &colorAttachment; renderPassInfo.pAttachments = &colorAttachment;
renderPassInfo.subpassCount = 1; renderPassInfo.subpassCount = 1;
renderPassInfo.pSubpasses = &subpass; renderPassInfo.pSubpasses = &subpass;
const auto result = vkCreateRenderPass(m_logicalDevice, &renderPassInfo, nullptr, &m_imguiRenderPass); const auto result = vkCreateRenderPass(m_logicalDevice, &renderPassInfo, nullptr, &m_imguiRenderPass);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
throw VkException(result, "can't create imgui renderpass"); throw VkException(result, "can't create imgui renderpass");
}
ImGui_ImplVulkan_InitInfo info{}; ImGui_ImplVulkan_InitInfo info{};
info.Instance = m_instance; info.Instance = m_instance;
@ -1564,6 +1567,12 @@ void VulkanRenderer::Shutdown()
Renderer::Shutdown(); Renderer::Shutdown();
SubmitCommandBuffer(); SubmitCommandBuffer();
WaitDeviceIdle(); WaitDeviceIdle();
if (m_imguiRenderPass != VK_NULL_HANDLE)
{
vkDestroyRenderPass(m_logicalDevice, m_imguiRenderPass, nullptr);
m_imguiRenderPass = VK_NULL_HANDLE;
}
} }
void VulkanRenderer::UnrecoverableError(const char* errMsg) const void VulkanRenderer::UnrecoverableError(const char* errMsg) const

View File

@ -441,7 +441,7 @@ private:
bool m_destroyPadSwapchainNextAcquire = false; bool m_destroyPadSwapchainNextAcquire = false;
bool IsSwapchainInfoValid(bool mainWindow) const; bool IsSwapchainInfoValid(bool mainWindow) const;
VkRenderPass m_imguiRenderPass = nullptr; VkRenderPass m_imguiRenderPass = VK_NULL_HANDLE;
VkDescriptorPool m_descriptorPool; VkDescriptorPool m_descriptorPool;