]> git.tdb.fi Git - libs/gl.git/commitdiff
Skip binding of low-numbered descriptor sets if they haven't changed
authorMikko Rasa <tdb@tdb.fi>
Wed, 16 Mar 2022 11:29:09 +0000 (13:29 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 16 Mar 2022 11:29:09 +0000 (13:29 +0200)
source/backends/vulkan/pipelinestate_backend.cpp

index a6a548aff42b0bee36eb0ba751f7ad3419aad5f1..02e7993c665fb52dd95e9ff3f92020cfb2584a68 100644 (file)
@@ -374,6 +374,7 @@ void VulkanPipelineState::apply(VkCommandBuffer command_buffer, const VulkanPipe
        const PipelineState &self = *static_cast<const PipelineState *>(this);
        const VulkanFunctions &vk = device.get_functions();
 
+       unsigned first_changed_desc_set = 0;
        if(!last)
                unapplied = ~0U;
        else if(last!=this)
@@ -387,6 +388,7 @@ void VulkanPipelineState::apply(VkCommandBuffer command_buffer, const VulkanPipe
                        if(descriptor_set_slots[i]!=last->descriptor_set_slots[i])
                        {
                                unapplied |= PipelineState::UNIFORMS;
+                               first_changed_desc_set = i;
                                break;
                        }
                if(self.viewport!=last_ps.viewport)
@@ -420,12 +422,13 @@ void VulkanPipelineState::apply(VkCommandBuffer command_buffer, const VulkanPipe
        if((unapplied&PipelineState::UNIFORMS) && !descriptor_set_slots.empty())
        {
                vector<VkDescriptorSet> descriptor_set_handles;
-               descriptor_set_handles.reserve(self.descriptor_set_slots.size());
-               for(unsigned i=0; i<self.descriptor_set_slots.size(); ++i)
-                       descriptor_set_handles.push_back(device.get_descriptor_pool().get_descriptor_set(self.descriptor_set_slots[i], self, i, frame));
+               descriptor_set_handles.reserve(descriptor_set_slots.size()-first_changed_desc_set);
+               for(unsigned i=first_changed_desc_set; i<descriptor_set_slots.size(); ++i)
+                       descriptor_set_handles.push_back(device.get_descriptor_pool().get_descriptor_set(
+                               self.descriptor_set_slots[i], self, i, frame));
 
                vk.CmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, self.shprog->layout_handle,
-                       0, descriptor_set_handles.size(), descriptor_set_handles.data(), 0, 0);
+                       first_changed_desc_set, descriptor_set_handles.size(), descriptor_set_handles.data(), 0, 0);
        }
 
        if(unapplied&(PipelineState::VIEWPORT|PipelineState::SCISSOR))