Skip to content

Commit 026d47c

Browse files
committed
Backends: Vulkan: store pColorAttachmentFormats deep-copy into an ImVector. (#8282, #8110)
1 parent c637148 commit 026d47c

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

backends/imgui_impl_vulkan.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ struct ImGui_ImplVulkan_Data
257257
VkShaderModule ShaderModuleVert;
258258
VkShaderModule ShaderModuleFrag;
259259
VkDescriptorPool DescriptorPool;
260+
ImVector<VkFormat> PipelineRenderingCreateInfoColorAttachmentFormats; // Deep copy of format array
260261

261262
// Texture management
262263
VkSampler TexSampler;
@@ -1160,6 +1161,13 @@ void ImGui_ImplVulkan_CreateMainPipeline(const ImGui_ImplVulkan_MainPipelineCrea
11601161
{
11611162
v->PipelineRenderingCreateInfo = info.PipelineRenderingCreateInfo;
11621163
pipeline_rendering_create_info = &v->PipelineRenderingCreateInfo;
1164+
if (v->PipelineRenderingCreateInfo.pColorAttachmentFormats != NULL)
1165+
{
1166+
// Deep copy buffer to reduce error-rate for end user (#8282)
1167+
bd->PipelineRenderingCreateInfoColorAttachmentFormats.resize((int)v->PipelineRenderingCreateInfo.colorAttachmentCount);
1168+
memcpy(bd->PipelineRenderingCreateInfoColorAttachmentFormats.Data, v->PipelineRenderingCreateInfo.pColorAttachmentFormats, (size_t)bd->PipelineRenderingCreateInfoColorAttachmentFormats.size_in_bytes());
1169+
v->PipelineRenderingCreateInfo.pColorAttachmentFormats = bd->PipelineRenderingCreateInfoColorAttachmentFormats.Data;
1170+
}
11631171
}
11641172
#endif
11651173
bd->Pipeline = ImGui_ImplVulkan_CreatePipeline(v->Device, v->Allocator, v->PipelineCache, v->RenderPass, v->MSAASamples, v->Subpass, pipeline_rendering_create_info);
@@ -1294,17 +1302,6 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info)
12941302
vkGetPhysicalDeviceProperties(info->PhysicalDevice, &properties);
12951303
bd->NonCoherentAtomSize = properties.limits.nonCoherentAtomSize;
12961304

1297-
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
1298-
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
1299-
if (v->PipelineRenderingCreateInfo.pColorAttachmentFormats != NULL)
1300-
{
1301-
// Deep copy buffer to reduce error-rate for end user (#8282)
1302-
VkFormat* formats_copy = (VkFormat*)IM_ALLOC(sizeof(VkFormat) * v->PipelineRenderingCreateInfo.colorAttachmentCount);
1303-
memcpy(formats_copy, v->PipelineRenderingCreateInfo.pColorAttachmentFormats, sizeof(VkFormat) * v->PipelineRenderingCreateInfo.colorAttachmentCount);
1304-
v->PipelineRenderingCreateInfo.pColorAttachmentFormats = formats_copy;
1305-
}
1306-
#endif
1307-
13081305
if (!ImGui_ImplVulkan_CreateDeviceObjects())
13091306
IM_ASSERT(0 && "ImGui_ImplVulkan_CreateDeviceObjects() failed!"); // <- Can't be hit yet.
13101307

@@ -1318,9 +1315,6 @@ void ImGui_ImplVulkan_Shutdown()
13181315
ImGuiIO& io = ImGui::GetIO();
13191316

13201317
ImGui_ImplVulkan_DestroyDeviceObjects();
1321-
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
1322-
IM_FREE((void*)const_cast<VkFormat*>(bd->VulkanInitInfo.PipelineRenderingCreateInfo.pColorAttachmentFormats));
1323-
#endif
13241318

13251319
io.BackendRendererName = nullptr;
13261320
io.BackendRendererUserData = nullptr;

0 commit comments

Comments
 (0)