From c737d292d49d2d39b44e1cd903c1f8b79174f0d7 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 17 Mar 2022 21:47:01 +0200 Subject: [PATCH] Rebind all descriptor sets if push constant layout changes --- source/backends/vulkan/pipelinestate_backend.cpp | 8 +++++++- source/backends/vulkan/pipelinestate_backend.h | 1 + source/core/program.cpp | 5 ++++- source/core/program.h | 1 + source/core/reflectdata.h | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/source/backends/vulkan/pipelinestate_backend.cpp b/source/backends/vulkan/pipelinestate_backend.cpp index 4eba2895..d14bc00c 100644 --- a/source/backends/vulkan/pipelinestate_backend.cpp +++ b/source/backends/vulkan/pipelinestate_backend.cpp @@ -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; diff --git a/source/backends/vulkan/pipelinestate_backend.h b/source/backends/vulkan/pipelinestate_backend.h index 5570e5d9..d033fbb8 100644 --- a/source/backends/vulkan/pipelinestate_backend.h +++ b/source/backends/vulkan/pipelinestate_backend.h @@ -22,6 +22,7 @@ protected: mutable VkPipeline handle = 0; mutable std::vector descriptor_set_slots; mutable unsigned first_changed_desc_set = 0; + mutable std::uint32_t push_const_compat = 0; VulkanPipelineState(); VulkanPipelineState(VulkanPipelineState &&); diff --git a/source/core/program.cpp b/source/core/program.cpp index e4250b6c..f8c35ec5 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -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()) diff --git a/source/core/program.h b/source/core/program.h index e8487e09..ca5437f3 100644 --- a/source/core/program.h +++ b/source/core/program.h @@ -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 &get_uniform_blocks() const { return reflect_data.uniform_blocks; } const ReflectData::UniformBlockInfo &get_uniform_block_info(const std::string &) const; const std::vector &get_uniforms() const { return reflect_data.uniforms; } diff --git a/source/core/reflectdata.h b/source/core/reflectdata.h index ee98634b..1e82a61b 100644 --- a/source/core/reflectdata.h +++ b/source/core/reflectdata.h @@ -68,6 +68,7 @@ struct ReflectData std::vector attributes; unsigned n_clip_distances = 0; unsigned n_descriptor_sets = 0; + unsigned push_constants_size = 0; std::vector used_bindings; void update_layout_hash(); -- 2.43.0