]> git.tdb.fi Git - libs/gl.git/commitdiff
Pack descriptor set and binding in a single variable
authorMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 12:53:30 +0000 (14:53 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 13:07:00 +0000 (15:07 +0200)
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
source/core/program.cpp
source/core/program.h
source/core/reflectdata.h

index 5067895de662e2a29676f07f988df3d9e7d1e371..ad11f00ba4e3470966b12f883490aa1baf1a9665 100644 (file)
@@ -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;
 
index 0b07da8e501e2a959d826dd4441347353223f27c..acdb20e88a5488063c3778a598af10f411b1b541 100644 (file)
@@ -55,6 +55,7 @@ void Program::collect_uniforms(const SpirVModule &mod)
        reflect_data.uniform_blocks.push_back(ReflectData::UniformBlockInfo());
        vector<vector<string> > 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();
 }
 
index dd7d4b5f029789a074815ff94d9112e27c6818a6..9a4eb27a2dcb94f7fbfadf0102a290e9460002a1 100644 (file)
@@ -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<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 2925da146b899b1e62ab642b09403400d8f2b761..a89e7fcf2972c973c89a803501ebbd6739f7f11c 100644 (file)
@@ -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<const UniformInfo *> uniforms;
                LayoutHash layout_hash = 0;
@@ -67,6 +65,7 @@ struct ReflectData
        LayoutHash layout_hash = 0;
        std::vector<AttributeInfo> attributes;
        unsigned n_clip_distances = 0;
+       unsigned n_descriptor_sets = 0;
 
        void update_layout_hash();
 };