]> git.tdb.fi Git - libs/gl.git/commitdiff
Rebind all descriptor sets if push constant layout changes
authorMikko Rasa <tdb@tdb.fi>
Thu, 17 Mar 2022 19:47:01 +0000 (21:47 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 17 Mar 2022 19:55:07 +0000 (21:55 +0200)
source/backends/vulkan/pipelinestate_backend.cpp
source/backends/vulkan/pipelinestate_backend.h
source/core/program.cpp
source/core/program.h
source/core/reflectdata.h

index 4eba2895e4925cd9282672a22d207f248ca4d2a4..d14bc00c6539bb3c9509fab26abf4610cd151d1f 100644 (file)
@@ -41,6 +41,12 @@ void VulkanPipelineState::update() const
        if(changes&PipelineState::VERTEX_SETUP)
                self.vertex_setup->refresh();
 
+       if(changes&PipelineState::SHPROG)
+       {
+               push_const_compat = hash<32>(self.shprog->stage_flags);
+               push_const_compat = hash_update<32>(push_const_compat, self.shprog->get_push_constants_size());
+       }
+
        constexpr unsigned pipeline_mask = PipelineState::SHPROG|PipelineState::VERTEX_SETUP|PipelineState::FACE_CULL|
                PipelineState::DEPTH_TEST|PipelineState::STENCIL_TEST|PipelineState::BLEND|PipelineState::PRIMITIVE_TYPE;
        if(changes&pipeline_mask)
@@ -396,7 +402,7 @@ void VulkanPipelineState::apply(VkCommandBuffer command_buffer, const VulkanPipe
                if(handle!=last->handle)
                {
                        unapplied |= PipelineState::SHPROG;
-                       if(self.shprog->stage_flags!=last_ps.shprog->stage_flags)
+                       if(self.push_const_compat!=last_ps.push_const_compat)
                        {
                                unapplied |= PipelineState::UNIFORMS;
                                first_changed_desc_set = 0;
index 5570e5d965974fc8dfe26fa3aa8f0264fcc3e157..d033fbb8591897309cd4e7c106a204600cd19063 100644 (file)
@@ -22,6 +22,7 @@ protected:
        mutable VkPipeline handle = 0;
        mutable std::vector<unsigned> descriptor_set_slots;
        mutable unsigned first_changed_desc_set = 0;
+       mutable std::uint32_t push_const_compat = 0;
 
        VulkanPipelineState();
        VulkanPipelineState(VulkanPipelineState &&);
index e4250b6c05739b52d8f1e339db7c188ffac35aad..f8c35ec573ed9b1437ecb63879cca00b00b9d7ff 100644 (file)
@@ -82,8 +82,12 @@ void Program::collect_uniforms(const SpirVModule &mod)
                        reflect_data.uniform_blocks.emplace_back();
                        ReflectData::UniformBlockInfo &info = reflect_data.uniform_blocks.back();
                        info.name = v.struct_type->name;
+                       info.data_size = v.struct_type->size;
                        if(v.storage==SpirVModule::PUSH_CONSTANT)
+                       {
                                info.bind_point = ReflectData::PUSH_CONSTANT;
+                               reflect_data.push_constants_size = info.data_size;
+                       }
                        else
                        {
                                if(v.binding>=0)
@@ -92,7 +96,6 @@ void Program::collect_uniforms(const SpirVModule &mod)
                                        info.bind_point = ReflectData::DEFAULT_BLOCK;
                                n_descriptor_sets = max(n_descriptor_sets, v.descriptor_set+1);
                        }
-                       info.data_size = v.struct_type->size;
 
                        string prefix;
                        if(!v.name.empty())
index e8487e09d001bfc34acb4f0caab85f21784faf60..ca5437f3a6970e6d626bf36520ebc828d0697ab1 100644 (file)
@@ -74,6 +74,7 @@ private:
 public:
        ReflectData::LayoutHash get_uniform_layout_hash() const { return reflect_data.layout_hash; }
        unsigned get_n_descriptor_sets() const { return reflect_data.n_descriptor_sets; }
+       unsigned get_push_constants_size() const { return reflect_data.push_constants_size; }
        const std::vector<ReflectData::UniformBlockInfo> &get_uniform_blocks() const { return reflect_data.uniform_blocks; }
        const ReflectData::UniformBlockInfo &get_uniform_block_info(const std::string &) const;
        const std::vector<ReflectData::UniformInfo> &get_uniforms() const { return reflect_data.uniforms; }
index ee98634ba6fa187f6607f35caefd3bdf4e63af3a..1e82a61bfadef9ef4b75910f40c44d4ee24afbcc 100644 (file)
@@ -68,6 +68,7 @@ struct ReflectData
        std::vector<AttributeInfo> attributes;
        unsigned n_clip_distances = 0;
        unsigned n_descriptor_sets = 0;
+       unsigned push_constants_size = 0;
        std::vector<int> used_bindings;
 
        void update_layout_hash();