]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/vulkan/pipelinestate_backend.cpp
Fix handling of descriptor set bindings when shader stages change
[libs/gl.git] / source / backends / vulkan / pipelinestate_backend.cpp
index 351affab103a44d38706b5763ffdb578777bcac8..4eba2895e4925cd9282672a22d207f248ca4d2a4 100644 (file)
@@ -266,6 +266,7 @@ uint64_t VulkanPipelineState::compute_descriptor_set_hash(unsigned index) const
        const PipelineState &self = *static_cast<const PipelineState *>(this);
 
        uint64_t result = hash<64>(0, 0);
+       bool empty = true;
 
        auto i = lower_bound_member(self.uniform_blocks, static_cast<int>(index)<<20, &PipelineState::BoundUniformBlock::binding);
        for(; (i!=self.uniform_blocks.end() && static_cast<unsigned>(i->binding)>>20==index); ++i)
@@ -274,6 +275,7 @@ uint64_t VulkanPipelineState::compute_descriptor_set_hash(unsigned index) const
                        result = hash_update<64>(result, i->binding);
                        result = hash_update<64>(result, reinterpret_cast<uintptr_t>(i->block));
                        result = hash_update<64>(result, reinterpret_cast<uintptr_t>(i->buffer->handle));
+                       empty = false;
                }
 
        auto j = lower_bound_member(self.textures, index<<20, &PipelineState::BoundTexture::binding);
@@ -284,8 +286,12 @@ uint64_t VulkanPipelineState::compute_descriptor_set_hash(unsigned index) const
                        result = hash_update<64>(result, reinterpret_cast<uintptr_t>(j->texture->handle));
                        result = hash_update<64>(result, reinterpret_cast<uintptr_t>(j->sampler->handle));
                        result = hash_update<64>(result, j->level);
+                       empty = false;
                }
 
+       if(!empty)
+               result = hash_update<64>(result, self.shprog->stage_flags);
+
        return result;
 }
 
@@ -388,7 +394,14 @@ void VulkanPipelineState::apply(VkCommandBuffer command_buffer, const VulkanPipe
        {
                const PipelineState &last_ps = *static_cast<const PipelineState *>(last);
                if(handle!=last->handle)
+               {
                        unapplied |= PipelineState::SHPROG;
+                       if(self.shprog->stage_flags!=last_ps.shprog->stage_flags)
+                       {
+                               unapplied |= PipelineState::UNIFORMS;
+                               first_changed_desc_set = 0;
+                       }
+               }
                if(self.vertex_setup!=last_ps.vertex_setup)
                        unapplied |= PipelineState::VERTEX_SETUP;
                for(unsigned i=0; i<descriptor_set_slots.size(); ++i)