From: Mikko Rasa Date: Fri, 11 Mar 2022 09:22:23 +0000 (+0200) Subject: Create specialized versions of SPIR-V modules with default spec values X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3efe3bab1c8290bd49a957ebec0ad97e58a35fcf;p=libs%2Fgl.git Create specialized versions of SPIR-V modules with default spec values It's important to remove unused resources in this case too. --- diff --git a/source/core/module.cpp b/source/core/module.cpp index 636fd13c..11d11af5 100644 --- a/source/core/module.cpp +++ b/source/core/module.cpp @@ -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) { diff --git a/source/core/module.h b/source/core/module.h index 2a4cac6b..51924d60 100644 --- a/source/core/module.h +++ b/source/core/module.h @@ -253,6 +253,7 @@ private: std::vector variables; std::vector spec_constants; std::vector blocks; + bool specializable = false; public: virtual Format get_format() const { return SPIR_V; } @@ -269,6 +270,7 @@ public: const std::vector &get_variables() const { return variables; } const std::vector &get_spec_constants() const { return spec_constants; } const std::vector &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 &) const; diff --git a/source/core/program.cpp b/source/core/program.cpp index 88187221..e4250b6c 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -39,7 +39,7 @@ void Program::add_stages(const Module &mod, const map &spec_values) add_glsl_stages(static_cast(mod), spec_values); break; case Module::SPIR_V: - if(!spec_values.empty()) + if(static_cast(mod).is_specializable()) { specialized_spirv = static_cast(mod).specialize(spec_values); final_module = specialized_spirv;