From 0ec14464ae7d2f989a135fdde51ed5c7aced7fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Delgado=20Kr=C3=A4mer?= Date: Wed, 31 Jul 2024 18:24:49 +0200 Subject: [PATCH] gi: remove unnecessary glslang initialization tracking --- src/gi/impl/GlslShaderCompiler.cpp | 34 ++++++------------------------ src/gi/impl/GlslShaderCompiler.h | 6 ++---- src/gi/impl/GlslShaderGen.cpp | 9 -------- src/gi/impl/GlslShaderGen.h | 2 -- 4 files changed, 9 insertions(+), 42 deletions(-) diff --git a/src/gi/impl/GlslShaderCompiler.cpp b/src/gi/impl/GlslShaderCompiler.cpp index 19f9b6ea..9ab655ba 100644 --- a/src/gi/impl/GlslShaderCompiler.cpp +++ b/src/gi/impl/GlslShaderCompiler.cpp @@ -97,37 +97,17 @@ namespace gtl } }; - static bool s_glslangInitialized = false; - - bool GiGlslShaderCompiler::init() - { - if (s_glslangInitialized) - { - assert(false); - return true; - } - - s_glslangInitialized = glslang::InitializeProcess(); - - return s_glslangInitialized; - } - - void GiGlslShaderCompiler::deinit() + GiGlslShaderCompiler::GiGlslShaderCompiler(const fs::path& shaderPath) + : m_fileIncluder(std::make_shared<_FileIncluder>(shaderPath)) { - if (!s_glslangInitialized) - { - assert(false); - return; - } - - glslang::FinalizeProcess(); - - s_glslangInitialized = false; + // glslang requires this static initialization, however it internally + // ref-counts and is thread-safe. The return value seems to be unused. + [[maybe_unused]] int r = glslang::InitializeProcess(); } - GiGlslShaderCompiler::GiGlslShaderCompiler(const fs::path& shaderPath) - : m_fileIncluder(std::make_shared<_FileIncluder>(shaderPath)) + GiGlslShaderCompiler::~GiGlslShaderCompiler() { + glslang::FinalizeProcess(); // see above } bool GiGlslShaderCompiler::compileGlslToSpv(ShaderStage stage, diff --git a/src/gi/impl/GlslShaderCompiler.h b/src/gi/impl/GlslShaderCompiler.h index 2b51e2eb..05ceae0b 100644 --- a/src/gi/impl/GlslShaderCompiler.h +++ b/src/gi/impl/GlslShaderCompiler.h @@ -40,15 +40,13 @@ namespace gtl public: GiGlslShaderCompiler(const fs::path& shaderPath); + ~GiGlslShaderCompiler(); + public: bool compileGlslToSpv(ShaderStage stage, std::string_view source, std::vector& spv); - static bool init(); - - static void deinit(); - private: std::shared_ptr m_fileIncluder; }; diff --git a/src/gi/impl/GlslShaderGen.cpp b/src/gi/impl/GlslShaderGen.cpp index 0b5511a2..392d475b 100644 --- a/src/gi/impl/GlslShaderGen.cpp +++ b/src/gi/impl/GlslShaderGen.cpp @@ -44,20 +44,11 @@ namespace gtl return false; } - if (!GiGlslShaderCompiler::init()) - { - return false; - } m_shaderCompiler = std::make_shared(m_shaderPath); return true; } - GiGlslShaderGen::~GiGlslShaderGen() - { - GiGlslShaderCompiler::deinit(); - } - void _sgGenerateCommonDefines(GiGlslStitcher& stitcher, const GiGlslShaderGen::CommonShaderParams& params) { #if defined(NDEBUG) || defined(__APPLE__) diff --git a/src/gi/impl/GlslShaderGen.h b/src/gi/impl/GlslShaderGen.h index 5786c126..049a03d1 100644 --- a/src/gi/impl/GlslShaderGen.h +++ b/src/gi/impl/GlslShaderGen.h @@ -40,8 +40,6 @@ namespace gtl public: bool init(std::string_view shaderPath, McRuntime& runtime); - ~GiGlslShaderGen(); - public: struct MaterialGenInfo {