summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-09-04 16:16:17 -0400
committerGitHub <noreply@github.com>2019-09-04 16:16:17 -0400
commitef36883ca1733a68162b199518275871c888391e (patch)
treea9af3b7859aede0720f3f5430d5e2abc8f0bd163 /source
parent30083e5958f62b995a56fc181f9944aadf9130d9 (diff)
Allow multiple threads to call glslang (#1046)
* Allow multiple threads to be able to call into glslang by * Having a single call to glslang::InitializeProcess() per process (in our case dll load) * Explicitly call glslang::InitThread * Fix problem with case in path for linux. * Rename s_processInitializer to g_processInitializer. Move into the function.
Diffstat (limited to 'source')
-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;
}