Skip to content

Commit 6228c2e

Browse files
committed
Backends: Vulkan: moved ImGui_ImplVulkanH_DestroyFrameRenderBuffers/ImGui_ImplVulkanH_DestroyWindowRenderBuffers as they are always used in a state where backend data is available.
1 parent 70bb6d1 commit 6228c2e

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

backends/imgui_impl_vulkan.cpp

+35-35
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@
9292
#endif
9393

9494
// Forward Declarations
95-
struct ImGui_ImplVulkanH_FrameRenderBuffers;
96-
struct ImGui_ImplVulkanH_WindowRenderBuffers;
95+
struct ImGui_ImplVulkan_FrameRenderBuffers;
96+
struct ImGui_ImplVulkan_WindowRenderBuffers;
9797
bool ImGui_ImplVulkan_CreateDeviceObjects();
9898
void ImGui_ImplVulkan_DestroyDeviceObjects();
99+
void ImGui_ImplVulkan_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkan_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator);
100+
void ImGui_ImplVulkan_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkan_WindowRenderBuffers* buffers, const VkAllocationCallbacks* allocator);
99101
void ImGui_ImplVulkanH_DestroyFrame(VkDevice device, ImGui_ImplVulkanH_Frame* fd, const VkAllocationCallbacks* allocator);
100102
void ImGui_ImplVulkanH_DestroyFrameSemaphores(VkDevice device, ImGui_ImplVulkanH_FrameSemaphores* fsd, const VkAllocationCallbacks* allocator);
101-
void ImGui_ImplVulkanH_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkanH_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator);
102-
void ImGui_ImplVulkanH_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkanH_WindowRenderBuffers* buffers, const VkAllocationCallbacks* allocator);
103103
void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
104104
void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator);
105105

@@ -191,7 +191,7 @@ static PFN_vkCmdEndRenderingKHR ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR;
191191

192192
// Reusable buffers used for rendering 1 current in-flight frame, for ImGui_ImplVulkan_RenderDrawData()
193193
// [Please zero-clear before use!]
194-
struct ImGui_ImplVulkanH_FrameRenderBuffers
194+
struct ImGui_ImplVulkan_FrameRenderBuffers
195195
{
196196
VkDeviceMemory VertexBufferMemory;
197197
VkDeviceMemory IndexBufferMemory;
@@ -203,11 +203,11 @@ struct ImGui_ImplVulkanH_FrameRenderBuffers
203203

204204
// Each viewport will hold 1 ImGui_ImplVulkanH_WindowRenderBuffers
205205
// [Please zero-clear before use!]
206-
struct ImGui_ImplVulkanH_WindowRenderBuffers
206+
struct ImGui_ImplVulkan_WindowRenderBuffers
207207
{
208208
uint32_t Index;
209209
uint32_t Count;
210-
ImGui_ImplVulkanH_FrameRenderBuffers* FrameRenderBuffers;
210+
ImGui_ImplVulkan_FrameRenderBuffers* FrameRenderBuffers;
211211
};
212212

213213
// Vulkan data
@@ -234,7 +234,7 @@ struct ImGui_ImplVulkan_Data
234234
VkCommandBuffer FontCommandBuffer;
235235

236236
// Render buffers for main window
237-
ImGui_ImplVulkanH_WindowRenderBuffers MainWindowRenderBuffers;
237+
ImGui_ImplVulkan_WindowRenderBuffers MainWindowRenderBuffers;
238238

239239
ImGui_ImplVulkan_Data()
240240
{
@@ -426,7 +426,7 @@ static void CreateOrResizeBuffer(VkBuffer& buffer, VkDeviceMemory& buffer_memory
426426
buffer_size = buffer_size_aligned;
427427
}
428428

429-
static void ImGui_ImplVulkan_SetupRenderState(ImDrawData* draw_data, VkPipeline pipeline, VkCommandBuffer command_buffer, ImGui_ImplVulkanH_FrameRenderBuffers* rb, int fb_width, int fb_height)
429+
static void ImGui_ImplVulkan_SetupRenderState(ImDrawData* draw_data, VkPipeline pipeline, VkCommandBuffer command_buffer, ImGui_ImplVulkan_FrameRenderBuffers* rb, int fb_width, int fb_height)
430430
{
431431
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
432432

@@ -485,17 +485,17 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
485485
pipeline = bd->Pipeline;
486486

487487
// Allocate array to store enough vertex/index buffers
488-
ImGui_ImplVulkanH_WindowRenderBuffers* wrb = &bd->MainWindowRenderBuffers;
488+
ImGui_ImplVulkan_WindowRenderBuffers* wrb = &bd->MainWindowRenderBuffers;
489489
if (wrb->FrameRenderBuffers == nullptr)
490490
{
491491
wrb->Index = 0;
492492
wrb->Count = v->ImageCount;
493-
wrb->FrameRenderBuffers = (ImGui_ImplVulkanH_FrameRenderBuffers*)IM_ALLOC(sizeof(ImGui_ImplVulkanH_FrameRenderBuffers) * wrb->Count);
494-
memset(wrb->FrameRenderBuffers, 0, sizeof(ImGui_ImplVulkanH_FrameRenderBuffers) * wrb->Count);
493+
wrb->FrameRenderBuffers = (ImGui_ImplVulkan_FrameRenderBuffers*)IM_ALLOC(sizeof(ImGui_ImplVulkan_FrameRenderBuffers) * wrb->Count);
494+
memset(wrb->FrameRenderBuffers, 0, sizeof(ImGui_ImplVulkan_FrameRenderBuffers) * wrb->Count);
495495
}
496496
IM_ASSERT(wrb->Count == v->ImageCount);
497497
wrb->Index = (wrb->Index + 1) % wrb->Count;
498-
ImGui_ImplVulkanH_FrameRenderBuffers* rb = &wrb->FrameRenderBuffers[wrb->Index];
498+
ImGui_ImplVulkan_FrameRenderBuffers* rb = &wrb->FrameRenderBuffers[wrb->Index];
499499

500500
if (draw_data->TotalVtxCount > 0)
501501
{
@@ -1032,7 +1032,7 @@ void ImGui_ImplVulkan_DestroyDeviceObjects()
10321032
{
10331033
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
10341034
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
1035-
ImGui_ImplVulkanH_DestroyWindowRenderBuffers(v->Device, &bd->MainWindowRenderBuffers, v->Allocator);
1035+
ImGui_ImplVulkan_DestroyWindowRenderBuffers(v->Device, &bd->MainWindowRenderBuffers, v->Allocator);
10361036
ImGui_ImplVulkan_DestroyFontsTexture();
10371037

10381038
if (bd->FontCommandBuffer) { vkFreeCommandBuffers(v->Device, bd->FontCommandPool, 1, &bd->FontCommandBuffer); bd->FontCommandBuffer = VK_NULL_HANDLE; }
@@ -1151,7 +1151,7 @@ void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count)
11511151
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
11521152
VkResult err = vkDeviceWaitIdle(v->Device);
11531153
check_vk_result(err);
1154-
ImGui_ImplVulkanH_DestroyWindowRenderBuffers(v->Device, &bd->MainWindowRenderBuffers, v->Allocator);
1154+
ImGui_ImplVulkan_DestroyWindowRenderBuffers(v->Device, &bd->MainWindowRenderBuffers, v->Allocator);
11551155
bd->VulkanInitInfo.MinImageCount = min_image_count;
11561156
}
11571157

@@ -1198,6 +1198,26 @@ void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set)
11981198
vkFreeDescriptorSets(v->Device, v->DescriptorPool, 1, &descriptor_set);
11991199
}
12001200

1201+
void ImGui_ImplVulkan_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkan_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator)
1202+
{
1203+
if (buffers->VertexBuffer) { vkDestroyBuffer(device, buffers->VertexBuffer, allocator); buffers->VertexBuffer = VK_NULL_HANDLE; }
1204+
if (buffers->VertexBufferMemory) { vkFreeMemory(device, buffers->VertexBufferMemory, allocator); buffers->VertexBufferMemory = VK_NULL_HANDLE; }
1205+
if (buffers->IndexBuffer) { vkDestroyBuffer(device, buffers->IndexBuffer, allocator); buffers->IndexBuffer = VK_NULL_HANDLE; }
1206+
if (buffers->IndexBufferMemory) { vkFreeMemory(device, buffers->IndexBufferMemory, allocator); buffers->IndexBufferMemory = VK_NULL_HANDLE; }
1207+
buffers->VertexBufferSize = 0;
1208+
buffers->IndexBufferSize = 0;
1209+
}
1210+
1211+
void ImGui_ImplVulkan_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkan_WindowRenderBuffers* buffers, const VkAllocationCallbacks* allocator)
1212+
{
1213+
for (uint32_t n = 0; n < buffers->Count; n++)
1214+
ImGui_ImplVulkan_DestroyFrameRenderBuffers(device, &buffers->FrameRenderBuffers[n], allocator);
1215+
IM_FREE(buffers->FrameRenderBuffers);
1216+
buffers->FrameRenderBuffers = nullptr;
1217+
buffers->Index = 0;
1218+
buffers->Count = 0;
1219+
}
1220+
12011221
//-------------------------------------------------------------------------
12021222
// Internal / Miscellaneous Vulkan Helpers
12031223
// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own app.)
@@ -1562,26 +1582,6 @@ void ImGui_ImplVulkanH_DestroyFrameSemaphores(VkDevice device, ImGui_ImplVulkanH
15621582
fsd->ImageAcquiredSemaphore = fsd->RenderCompleteSemaphore = VK_NULL_HANDLE;
15631583
}
15641584

1565-
void ImGui_ImplVulkanH_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkanH_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator)
1566-
{
1567-
if (buffers->VertexBuffer) { vkDestroyBuffer(device, buffers->VertexBuffer, allocator); buffers->VertexBuffer = VK_NULL_HANDLE; }
1568-
if (buffers->VertexBufferMemory) { vkFreeMemory(device, buffers->VertexBufferMemory, allocator); buffers->VertexBufferMemory = VK_NULL_HANDLE; }
1569-
if (buffers->IndexBuffer) { vkDestroyBuffer(device, buffers->IndexBuffer, allocator); buffers->IndexBuffer = VK_NULL_HANDLE; }
1570-
if (buffers->IndexBufferMemory) { vkFreeMemory(device, buffers->IndexBufferMemory, allocator); buffers->IndexBufferMemory = VK_NULL_HANDLE; }
1571-
buffers->VertexBufferSize = 0;
1572-
buffers->IndexBufferSize = 0;
1573-
}
1574-
1575-
void ImGui_ImplVulkanH_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkanH_WindowRenderBuffers* buffers, const VkAllocationCallbacks* allocator)
1576-
{
1577-
for (uint32_t n = 0; n < buffers->Count; n++)
1578-
ImGui_ImplVulkanH_DestroyFrameRenderBuffers(device, &buffers->FrameRenderBuffers[n], allocator);
1579-
IM_FREE(buffers->FrameRenderBuffers);
1580-
buffers->FrameRenderBuffers = nullptr;
1581-
buffers->Index = 0;
1582-
buffers->Count = 0;
1583-
}
1584-
15851585
//-----------------------------------------------------------------------------
15861586

15871587
#endif // #ifndef IMGUI_DISABLE

0 commit comments

Comments
 (0)