FrontendCommon: Fix descriptor/image validation errors in imgui render

This commit is contained in:
Connor McLaughlin 2020-09-08 11:41:19 +10:00
parent 2cecb8bbdb
commit 455f359125
3 changed files with 10 additions and 19 deletions

View file

@ -46,6 +46,7 @@
#include "imgui.h"
#include "imgui_impl_vulkan.h"
#include "common/vulkan/context.h"
#include "common/vulkan/texture.h"
#include <stdio.h>
@ -309,14 +310,7 @@ static void ImGui_ImplVulkan_UpdateAndBindDescriptors(const ImDrawCmd* pcmd, VkC
{
const Vulkan::Texture* tex = static_cast<const Vulkan::Texture*>(pcmd->TextureId);
VkDescriptorSet desc_set;
VkDescriptorSetAllocateInfo alloc_info = {};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
alloc_info.descriptorPool = g_VulkanInitInfo.DescriptorPool;
alloc_info.descriptorSetCount = 1;
alloc_info.pSetLayouts = &g_DescriptorSetLayout;
VkResult err = vkAllocateDescriptorSets(g_VulkanInitInfo.Device, &alloc_info, &desc_set);
check_vk_result(err);
VkDescriptorSet desc_set = g_vulkan_context->AllocateDescriptorSet(g_DescriptorSetLayout);
VkDescriptorImageInfo desc_image[1] = {};
desc_image[0].sampler = g_FontSampler;
@ -503,6 +497,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
// Create the Image View:
{
g_FontTexture.Adopt(g_FontImage, VK_IMAGE_VIEW_TYPE_2D, width, height, 1, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT);
g_FontTexture.TransitionToLayout(command_buffer, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}
// Create the Upload Buffer:
@ -807,7 +802,6 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend
IM_ASSERT(info->PhysicalDevice != VK_NULL_HANDLE);
IM_ASSERT(info->Device != VK_NULL_HANDLE);
IM_ASSERT(info->Queue != VK_NULL_HANDLE);
IM_ASSERT(info->DescriptorPool != VK_NULL_HANDLE);
IM_ASSERT(info->MinImageCount >= 2);
IM_ASSERT(info->ImageCount >= info->MinImageCount);
IM_ASSERT(render_pass != VK_NULL_HANDLE);
@ -824,9 +818,8 @@ void ImGui_ImplVulkan_Shutdown()
ImGui_ImplVulkan_DestroyDeviceObjects();
}
void ImGui_ImplVulkan_NewFrame(VkDescriptorPool DescriptorPool)
void ImGui_ImplVulkan_NewFrame()
{
g_VulkanInitInfo.DescriptorPool = DescriptorPool;
}
void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count)

View file

@ -34,7 +34,6 @@ struct ImGui_ImplVulkan_InitInfo
uint32_t QueueFamily;
VkQueue Queue;
VkPipelineCache PipelineCache;
VkDescriptorPool DescriptorPool;
uint32_t MinImageCount; // >= 2
uint32_t ImageCount; // >= MinImageCount
VkSampleCountFlagBits MSAASamples; // >= VK_SAMPLE_COUNT_1_BIT
@ -45,7 +44,7 @@ struct ImGui_ImplVulkan_InitInfo
// Called by user code
IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass);
IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown();
IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame(VkDescriptorPool DescriptorPool);
IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame();
IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer);
IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer);
IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontUploadObjects();

View file

@ -1,4 +1,4 @@
#include "vulkan_host_display.h"
#include "vulkan_host_display.h"
#include "common/assert.h"
#include "common/log.h"
#include "common/scope_guard.h"
@ -233,7 +233,7 @@ void VulkanHostDisplay::SetVSync(bool enabled)
bool VulkanHostDisplay::CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device)
{
if (!Vulkan::Context::Create(adapter_name, &wi, &m_swap_chain, debug_device, false))
if (!Vulkan::Context::Create(adapter_name, &wi, &m_swap_chain, true, true))
{
Log_ErrorPrintf("Failed to create Vulkan context");
return false;
@ -455,7 +455,6 @@ bool VulkanHostDisplay::CreateImGuiContext()
vii.QueueFamily = g_vulkan_context->GetGraphicsQueueFamilyIndex();
vii.Queue = g_vulkan_context->GetGraphicsQueue();
vii.PipelineCache = g_vulkan_shader_cache->GetPipelineCache();
vii.DescriptorPool = g_vulkan_context->GetGlobalDescriptorPool();
vii.MinImageCount = m_swap_chain->GetImageCount();
vii.ImageCount = m_swap_chain->GetImageCount();
vii.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
@ -466,7 +465,7 @@ bool VulkanHostDisplay::CreateImGuiContext()
return false;
}
ImGui_ImplVulkan_NewFrame(g_vulkan_context->GetCurrentDescriptorPool());
ImGui_ImplVulkan_NewFrame();
#endif
return true;
@ -532,7 +531,7 @@ bool VulkanHostDisplay::Render()
#ifdef WITH_IMGUI
if (ImGui::GetCurrentContext())
ImGui_ImplVulkan_NewFrame(g_vulkan_context->GetCurrentDescriptorPool());
ImGui_ImplVulkan_NewFrame();
#endif
return true;
@ -647,4 +646,4 @@ std::vector<std::string> VulkanHostDisplay::EnumerateAdapterNames()
return {};
}
} // namespace FrontendCommon
} // namespace FrontendCommon