diff --git a/dep/glslang/OGLCompilersDLL/InitializeDll.cpp b/dep/glslang/OGLCompilersDLL/InitializeDll.cpp index abea9108b..756da78b4 100644 --- a/dep/glslang/OGLCompilersDLL/InitializeDll.cpp +++ b/dep/glslang/OGLCompilersDLL/InitializeDll.cpp @@ -158,6 +158,7 @@ bool DetachProcess() OS_FreeTLSIndex(ThreadInitializeIndex); ThreadInitializeIndex = OS_INVALID_TLS_INDEX; + DeinitializePoolIndex(); return success; } diff --git a/dep/glslang/glslang/Include/InitializeGlobals.h b/dep/glslang/glslang/Include/InitializeGlobals.h index 95d0a40e9..a9d27730b 100644 --- a/dep/glslang/glslang/Include/InitializeGlobals.h +++ b/dep/glslang/glslang/Include/InitializeGlobals.h @@ -38,6 +38,7 @@ namespace glslang { bool InitializePoolIndex(); +bool DeinitializePoolIndex(); } // end namespace glslang diff --git a/dep/glslang/glslang/MachineIndependent/PoolAlloc.cpp b/dep/glslang/glslang/MachineIndependent/PoolAlloc.cpp index 84c40f4e7..c27131d56 100644 --- a/dep/glslang/glslang/MachineIndependent/PoolAlloc.cpp +++ b/dep/glslang/glslang/MachineIndependent/PoolAlloc.cpp @@ -65,6 +65,15 @@ bool InitializePoolIndex() return true; } +bool DeinitializePoolIndex() +{ + if (PoolIndex == OS_INVALID_TLS_INDEX) + return false; + OS_FreeTLSIndex(PoolIndex); + PoolIndex = OS_INVALID_TLS_INDEX; + return true; +} + // // Implement the functionality of the TPoolAllocator class, which // is documented in PoolAlloc.h. diff --git a/dep/glslang/glslang/MachineIndependent/ShaderLang.cpp b/dep/glslang/glslang/MachineIndependent/ShaderLang.cpp index a1392dbde..23f2bf122 100644 --- a/dep/glslang/glslang/MachineIndependent/ShaderLang.cpp +++ b/dep/glslang/glslang/MachineIndependent/ShaderLang.cpp @@ -1429,6 +1429,7 @@ int ShFinalize() glslang::HlslScanContext::deleteKeywordMap(); #endif + DetachProcess(); return 1; } diff --git a/src/common/vulkan/shader_compiler.cpp b/src/common/vulkan/shader_compiler.cpp index bde1b32eb..9340522e6 100644 --- a/src/common/vulkan/shader_compiler.cpp +++ b/src/common/vulkan/shader_compiler.cpp @@ -24,6 +24,8 @@ bool InitializeGlslang(); static unsigned s_next_bad_shader_id = 1; +static bool glslang_initialized = false; + static std::optional CompileShaderToSPV(EShLanguage stage, const char* stage_filename, std::string_view source) { @@ -113,7 +115,6 @@ static std::optional CompileShaderToSPV(EShLanguage stage, cons bool InitializeGlslang() { - static bool glslang_initialized = false; if (glslang_initialized) return true; @@ -123,12 +124,23 @@ bool InitializeGlslang() return false; } +#ifndef LIBRETRO std::atexit([]() { glslang::FinalizeProcess(); }); +#endif glslang_initialized = true; return true; } +void DeinitializeGlslang() +{ + if (!glslang_initialized) + return; + + glslang::FinalizeProcess(); + glslang_initialized = false; +} + std::optional CompileVertexShader(std::string_view source_code) { return CompileShaderToSPV(EShLangVertex, "vs", source_code); diff --git a/src/common/vulkan/shader_compiler.h b/src/common/vulkan/shader_compiler.h index c39a06d1b..8d37bdba5 100644 --- a/src/common/vulkan/shader_compiler.h +++ b/src/common/vulkan/shader_compiler.h @@ -21,6 +21,8 @@ enum class Type Compute }; +void DeinitializeGlslang(); + // SPIR-V compiled code type using SPIRVCodeType = u32; using SPIRVCodeVector = std::vector; diff --git a/src/duckstation-libretro/libretro_vulkan_host_display.cpp b/src/duckstation-libretro/libretro_vulkan_host_display.cpp index 9eaee1f11..d4d3f29ee 100644 --- a/src/duckstation-libretro/libretro_vulkan_host_display.cpp +++ b/src/duckstation-libretro/libretro_vulkan_host_display.cpp @@ -136,6 +136,7 @@ void LibretroVulkanHostDisplay::DestroyResources() VulkanHostDisplay::DestroyResources(); Vulkan::Util::SafeDestroyFramebuffer(m_frame_framebuffer); m_frame_texture.Destroy(); + Vulkan::ShaderCompiler::DeinitializeGlslang(); } VkRenderPass LibretroVulkanHostDisplay::GetRenderPassForDisplay() const