@ -39,6 +39,9 @@ static VkDebugReportCallbackEXT g_DebugReport = VK_NULL_HANDLE;
static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE ;
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE ;
static VkCommandPool g_FontCommandPool = VK_NULL_HANDLE ;
static VkCommandBuffer g_FontCommandBuffer = VK_NULL_HANDLE ;
static ImGui_ImplVulkanH_Window g_MainWindowData ;
static uint32_t g_MinImageCount = 2 ;
static bool g_SwapChainRebuild = false ;
@ -261,6 +264,7 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
static void CleanupVulkan ( )
{
vkDestroyCommandPool ( g_Device , g_FontCommandPool , g_Allocator ) ;
vkDestroyDescriptorPool ( g_Device , g_DescriptorPool , g_Allocator ) ;
# ifdef IMGUI_VULKAN_DEBUG_REPORT
@ -367,6 +371,51 @@ static void FramePresent(ImGui_ImplVulkanH_Window* wd)
wd - > SemaphoreIndex = ( wd - > SemaphoreIndex + 1 ) % wd - > ImageCount ; // Now we can use the next set of semaphores
}
static void UploadFonts ( )
{
if ( g_FontCommandPool = = VK_NULL_HANDLE )
{
VkCommandPoolCreateInfo info = { } ;
info . sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO ;
info . flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT ;
info . queueFamilyIndex = g_QueueFamily ;
vkCreateCommandPool ( g_Device , & info , nullptr , & g_FontCommandPool ) ;
}
if ( g_FontCommandBuffer = = VK_NULL_HANDLE )
{
VkCommandBufferAllocateInfo info = { } ;
info . sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO ;
info . commandPool = g_FontCommandPool ;
info . commandBufferCount = 1 ;
VkResult err = vkAllocateCommandBuffers ( g_Device , & info , & g_FontCommandBuffer ) ;
check_vk_result ( err ) ;
}
VkResult err = vkResetCommandPool ( g_Device , g_FontCommandPool , 0 ) ;
check_vk_result ( err ) ;
VkCommandBufferBeginInfo begin_info = { } ;
begin_info . sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO ;
begin_info . flags | = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT ;
err = vkBeginCommandBuffer ( g_FontCommandBuffer , & begin_info ) ;
check_vk_result ( err ) ;
ImGui_ImplVulkan_CreateFontsTexture ( g_FontCommandBuffer ) ;
VkSubmitInfo end_info = { } ;
end_info . sType = VK_STRUCTURE_TYPE_SUBMIT_INFO ;
end_info . commandBufferCount = 1 ;
end_info . pCommandBuffers = & g_FontCommandBuffer ;
err = vkEndCommandBuffer ( g_FontCommandBuffer ) ;
check_vk_result ( err ) ;
err = vkQueueSubmit ( g_Queue , 1 , & end_info , VK_NULL_HANDLE ) ;
check_vk_result ( err ) ;
err = vkDeviceWaitIdle ( g_Device ) ;
check_vk_result ( err ) ;
ImGui_ImplVulkan_DestroyFontUploadObjects ( ) ;
}
// Main code
int main ( int , char * * )
{
@ -454,34 +503,7 @@ int main(int, char**)
//IM_ASSERT(font != nullptr);
// Upload Fonts
{
// Use any command queue
VkCommandPool command_pool = wd - > Frames [ wd - > FrameIndex ] . CommandPool ;
VkCommandBuffer command_buffer = wd - > Frames [ wd - > FrameIndex ] . CommandBuffer ;
err = vkResetCommandPool ( g_Device , command_pool , 0 ) ;
check_vk_result ( err ) ;
VkCommandBufferBeginInfo begin_info = { } ;
begin_info . sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO ;
begin_info . flags | = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT ;
err = vkBeginCommandBuffer ( command_buffer , & begin_info ) ;
check_vk_result ( err ) ;
ImGui_ImplVulkan_CreateFontsTexture ( command_buffer ) ;
VkSubmitInfo end_info = { } ;
end_info . sType = VK_STRUCTURE_TYPE_SUBMIT_INFO ;
end_info . commandBufferCount = 1 ;
end_info . pCommandBuffers = & command_buffer ;
err = vkEndCommandBuffer ( command_buffer ) ;
check_vk_result ( err ) ;
err = vkQueueSubmit ( g_Queue , 1 , & end_info , VK_NULL_HANDLE ) ;
check_vk_result ( err ) ;
err = vkDeviceWaitIdle ( g_Device ) ;
check_vk_result ( err ) ;
ImGui_ImplVulkan_DestroyFontUploadObjects ( ) ;
}
UploadFonts ( ) ;
// Our state
bool show_demo_window = true ;