]> git.tdb.fi Git - libs/gl.git/commitdiff
Create specialized versions of SPIR-V modules with default spec values
authorMikko Rasa <tdb@tdb.fi>
Fri, 11 Mar 2022 09:22:23 +0000 (11:22 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 11 Mar 2022 09:22:23 +0000 (11:22 +0200)
It's important to remove unused resources in this case too.

source/core/module.cpp
source/core/module.h
source/core/program.cpp

index 636fd13cf4a84cd623ce481b3231fb731e112b85..11d11af5d6485b1f7a80671f15dba95394554c21 100644 (file)
@@ -237,6 +237,8 @@ void SpirVModule::reflect()
        {
                auto i = spec_indices.find(b.condition);
                b.condition = (i!=spec_indices.end() ? &spec_constants[i->second] : 0);
+               if(b.condition)
+                       specializable = true;
 
                for(const Variable *&v: b.accessed_variables)
                {
index 2a4cac6b06758faa45910ffa48c463b271ee07eb..51924d606668db500e7b871f72f7677ae538190d 100644 (file)
@@ -253,6 +253,7 @@ private:
        std::vector<Variable> variables;
        std::vector<Constant> spec_constants;
        std::vector<InstructionBlock> blocks;
+       bool specializable = false;
 
 public:
        virtual Format get_format() const { return SPIR_V; }
@@ -269,6 +270,7 @@ public:
        const std::vector<Variable> &get_variables() const { return variables; }
        const std::vector<Constant> &get_spec_constants() const { return spec_constants; }
        const std::vector<InstructionBlock> &get_blocks() const { return blocks; }
+       bool is_specializable() const { return specializable; }
 
        /** Creates a new module which is a specialized version of this one. */
        SpirVModule *specialize(const std::map<std::string, int> &) const;
index 881872212bebc224209f020d24aae0b4cc64c485..e4250b6c05739b52d8f1e339db7c188ffac35aad 100644 (file)
@@ -39,7 +39,7 @@ void Program::add_stages(const Module &mod, const map<string, int> &spec_values)
                add_glsl_stages(static_cast<const GlslModule &>(mod), spec_values);
                break;
        case Module::SPIR_V:
-               if(!spec_values.empty())
+               if(static_cast<const SpirVModule &>(mod).is_specializable())
                {
                        specialized_spirv = static_cast<const SpirVModule &>(mod).specialize(spec_values);
                        final_module = specialized_spirv;