]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix handling of descriptor set bindings when shader stages change
authorMikko Rasa <tdb@tdb.fi>
Wed, 16 Mar 2022 15:56:30 +0000 (17:56 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 16 Mar 2022 15:56:30 +0000 (17:56 +0200)
Also set only the present stages for descriptor set layouts.

source/backends/vulkan/pipelinestate_backend.cpp
source/backends/vulkan/program_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)
index 2e9518108eca16e32ba9de5d9325343c1b469a05..728bacbce7c6f75217c258691287e9ee164a2597 100644 (file)
@@ -128,7 +128,7 @@ void VulkanProgram::finalize_uniforms()
                                binding.binding = b.bind_point&0xFFFFF;
                                binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
                                binding.descriptorCount = 1;
-                               binding.stageFlags = VK_SHADER_STAGE_ALL;
+                               binding.stageFlags = stage_flags;
                                binding.pImmutableSamplers = 0;
                        }
 
@@ -140,7 +140,7 @@ void VulkanProgram::finalize_uniforms()
                                binding.binding = u.binding&0xFFFFF;
                                binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                                binding.descriptorCount = 1;
-                               binding.stageFlags = VK_SHADER_STAGE_ALL;
+                               binding.stageFlags = stage_flags;
                                binding.pImmutableSamplers = 0;
                        }