summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang-glslang/slang-glslang.cpp52
1 files changed, 49 insertions, 3 deletions
diff --git a/source/slang-glslang/slang-glslang.cpp b/source/slang-glslang/slang-glslang.cpp
index 68bf7b6a3..25b46bafe 100644
--- a/source/slang-glslang/slang-glslang.cpp
+++ b/source/slang-glslang/slang-glslang.cpp
@@ -12,6 +12,8 @@
#include "SPIRV/doc.h"
#include "SPIRV/disassemble.h"
+#include "OGLCompilersDLL/InitializeDll.h"
+
#include "../../slang.h"
#if 0
@@ -190,6 +192,42 @@ static int glslang_dissassembleSPIRV(glslang_CompileRequest* request)
return 0;
}
+// We need a per process initialization
+class ProcessInitializer
+{
+public:
+ ProcessInitializer()
+ {
+ m_isInitialized = false;
+ }
+
+ bool init()
+ {
+ std::lock_guard<std::mutex> guard(m_mutex);
+ if (!m_isInitialized)
+ {
+ if (!glslang::InitializeProcess())
+ {
+ return false;
+ }
+ m_isInitialized = true;
+ }
+ return true;
+ }
+
+ ~ProcessInitializer()
+ {
+ // We *assume* will only be called once dll is detatched and that will be on a single thread
+ if (m_isInitialized)
+ {
+ glslang::FinalizeProcess();
+ }
+ }
+
+ std::mutex m_mutex;
+ bool m_isInitialized = false;
+};
+
extern "C"
#ifdef _MSC_VER
_declspec(dllexport)
@@ -198,7 +236,17 @@ __attribute__((__visibility__("default")))
#endif
int glslang_compile(glslang_CompileRequest* request)
{
- glslang::InitializeProcess();
+ static ProcessInitializer g_processInitializer;
+ if (!g_processInitializer.init())
+ {
+ // Failed
+ return 1;
+ }
+ if (!glslang::InitThread())
+ {
+ // Failed
+ return 1;
+ }
int result = 0;
switch(request->action)
@@ -216,7 +264,5 @@ int glslang_compile(glslang_CompileRequest* request)
break;
}
- glslang::FinalizeProcess();
-
return result;
}