Browse Source

Backends: Vulkan: Avoid calling vkCmdBindDescriptorSets() when texture has not changed. (#8666)

Michael Böhme 4 months ago
parent
commit
90025a62c7
2 changed files with 7 additions and 1 deletions
  1. 5 1
      backends/imgui_impl_vulkan.cpp
  2. 2 0
      docs/CHANGELOG.txt

+ 5 - 1
backends/imgui_impl_vulkan.cpp

@@ -588,6 +588,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
 
 
     // Render command lists
     // Render command lists
     // (Because we merged all buffers into a single one, we maintain our own offset into them)
     // (Because we merged all buffers into a single one, we maintain our own offset into them)
+    VkDescriptorSet last_desc_set = VK_NULL_HANDLE;
     int global_vtx_offset = 0;
     int global_vtx_offset = 0;
     int global_idx_offset = 0;
     int global_idx_offset = 0;
     for (const ImDrawList* draw_list : draw_data->CmdLists)
     for (const ImDrawList* draw_list : draw_data->CmdLists)
@@ -603,6 +604,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
                     ImGui_ImplVulkan_SetupRenderState(draw_data, pipeline, command_buffer, rb, fb_width, fb_height);
                     ImGui_ImplVulkan_SetupRenderState(draw_data, pipeline, command_buffer, rb, fb_width, fb_height);
                 else
                 else
                     pcmd->UserCallback(draw_list, pcmd);
                     pcmd->UserCallback(draw_list, pcmd);
+                last_desc_set = VK_NULL_HANDLE;
             }
             }
             else
             else
             {
             {
@@ -628,7 +630,9 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
 
 
                 // Bind DescriptorSet with font or user texture
                 // Bind DescriptorSet with font or user texture
                 VkDescriptorSet desc_set = (VkDescriptorSet)pcmd->GetTexID();
                 VkDescriptorSet desc_set = (VkDescriptorSet)pcmd->GetTexID();
-                vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, &desc_set, 0, nullptr);
+                if (desc_set != last_desc_set)
+                    vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, &desc_set, 0, nullptr);
+                last_desc_set = desc_set;
 
 
                 // Draw
                 // Draw
                 vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
                 vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);

+ 2 - 0
docs/CHANGELOG.txt

@@ -90,6 +90,8 @@ Other Changes:
   textures. (#8802) [@Daandelange]
   textures. (#8802) [@Daandelange]
 - Backends: Vulkan: Fixed texture update corruption introduced in 1.92.0,
 - Backends: Vulkan: Fixed texture update corruption introduced in 1.92.0,
   affecting some drivers/setups. (#8801, #8755, #8840) [@Retro52, @Miolith]
   affecting some drivers/setups. (#8801, #8755, #8840) [@Retro52, @Miolith]
+- Backends: Vulkan: Avoid calling vkCmdBindDescriptorSets() when texture
+  has not changed. (#8666) [@micb25]
 
 
 
 
 -----------------------------------------------------------------------
 -----------------------------------------------------------------------