From b813fb24367716fc543e9c59f0fc2b1fc13073e6 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 5 Mar 2025 09:50:29 +0000 Subject: [PATCH] Allow glslang global lock to be used during process teardown * During capture we may have to shutdown glslang from inside a global destructor, we need to ensure the lock is still valid. --- .../glslang/MachineIndependent/ShaderLang.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/renderdoc/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp b/renderdoc/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp index 040b21daf..89eb99941 100644 --- a/renderdoc/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp +++ b/renderdoc/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp @@ -83,7 +83,11 @@ int NumberOfClients = 0; // global initialization lock #ifndef DISABLE_THREAD_SUPPORT -std::mutex init_lock; +std::mutex &init_lock() +{ + std::mutex *lock = new std::mutex; + return *lock; +} #endif @@ -430,7 +434,7 @@ bool SetupBuiltinSymbolTable(int version, EProfile profile, const SpvVersion& sp // Make sure only one thread tries to do this at a time #ifndef DISABLE_THREAD_SUPPORT - const std::lock_guard lock(init_lock); + const std::lock_guard lock(init_lock()); #endif // See if it's already been done for this version/profile combination @@ -1333,7 +1337,7 @@ bool CompileDeferred( int ShInitialize() { #ifndef DISABLE_THREAD_SUPPORT - const std::lock_guard lock(init_lock); + const std::lock_guard lock(init_lock()); #endif ++NumberOfClients; @@ -1390,7 +1394,7 @@ void ShDestruct(ShHandle handle) int ShFinalize() { #ifndef DISABLE_THREAD_SUPPORT - const std::lock_guard lock(init_lock); + const std::lock_guard lock(init_lock()); #endif --NumberOfClients; assert(NumberOfClients >= 0);