From 0e61ac01ae99391c6b1301a9bf8de62fe651dac3 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 17 Nov 2021 14:53:30 +0200 Subject: [PATCH] Pack descriptor set and binding in a single variable This makes them easier to pass around and there's plenty of bits available. Also add a variable for descriptor set count. --- source/core/module.h | 2 +- source/core/program.cpp | 14 ++++++++++---- source/core/program.h | 1 + source/core/reflectdata.h | 3 +-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/source/core/module.h b/source/core/module.h index 5067895d..ad11f00b 100644 --- a/source/core/module.h +++ b/source/core/module.h @@ -157,7 +157,7 @@ public: const Structure *struct_type = 0; unsigned array_size = 0; int location = -1; - int descriptor_set = 0; + unsigned descriptor_set = 0; int binding = -1; BuiltinSemantic builtin = NOT_BUILTIN; diff --git a/source/core/program.cpp b/source/core/program.cpp index 0b07da8e..acdb20e8 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -55,6 +55,7 @@ void Program::collect_uniforms(const SpirVModule &mod) reflect_data.uniform_blocks.push_back(ReflectData::UniformBlockInfo()); vector > block_uniform_names(1); + unsigned n_descriptor_sets = 0; for(const SpirVModule::Variable &v: mod.get_variables()) { if((v.storage==SpirVModule::UNIFORM || v.storage==SpirVModule::PUSH_CONSTANT) && v.struct_type) @@ -66,8 +67,11 @@ void Program::collect_uniforms(const SpirVModule &mod) info.bind_point = ReflectData::PUSH_CONSTANT; else { - info.bind_point = v.binding; - info.descriptor_set = v.descriptor_set; + if(v.binding>=0) + info.bind_point = v.binding | (v.descriptor_set<<20); + else + info.bind_point = ReflectData::DEFAULT_BLOCK; + n_descriptor_sets = max(n_descriptor_sets, v.descriptor_set+1); } info.data_size = v.struct_type->size; @@ -85,8 +89,9 @@ void Program::collect_uniforms(const SpirVModule &mod) info.name = v.name; info.tag = v.name; info.location = v.location; - info.binding = v.binding; - info.descriptor_set = v.descriptor_set; + if(v.binding>=0) + info.binding = v.binding | (v.descriptor_set<<20); + n_descriptor_sets = max(n_descriptor_sets, v.descriptor_set+1); info.array_size = max(v.array_size, 1U); info.type = v.type; } @@ -114,6 +119,7 @@ void Program::collect_uniforms(const SpirVModule &mod) block.update_layout_hash(); } + reflect_data.n_descriptor_sets = n_descriptor_sets; reflect_data.update_layout_hash(); } diff --git a/source/core/program.h b/source/core/program.h index dd7d4b5f..9a4eb27a 100644 --- a/source/core/program.h +++ b/source/core/program.h @@ -69,6 +69,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; } 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 2925da14..a89e7fcf 100644 --- a/source/core/reflectdata.h +++ b/source/core/reflectdata.h @@ -37,7 +37,6 @@ struct ReflectData unsigned matrix_stride = 0; DataType type = VOID; Tag tag; - int descriptor_set = 0; int binding = -1; }; @@ -45,7 +44,6 @@ struct ReflectData { std::string name; unsigned data_size = 0; - int descriptor_set = 0; int bind_point = DEFAULT_BLOCK; std::vector uniforms; LayoutHash layout_hash = 0; @@ -67,6 +65,7 @@ struct ReflectData LayoutHash layout_hash = 0; std::vector attributes; unsigned n_clip_distances = 0; + unsigned n_descriptor_sets = 0; void update_layout_hash(); }; -- 2.43.0