diff --git a/OGLCompilersDLL/InitializeDll.cpp b/OGLCompilersDLL/InitializeDll.cpp index 5f5ec3ab..970cd960 100644 --- a/OGLCompilersDLL/InitializeDll.cpp +++ b/OGLCompilersDLL/InitializeDll.cpp @@ -94,7 +94,7 @@ bool InitThread() if (OS_GetTLSValue(ThreadInitializeIndex) != 0) return true; - InitializeGlobalPools(); + InitializeMemoryPools(); if (! OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) { assert(0 && "InitThread(): Unable to set init flag."); diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index eb0c6f43..b3a37dc4 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -591,12 +591,6 @@ int C_DECL main(int argc, char* argv[]) bool compileFailed = false; bool linkFailed = false; - // Init for front-end proper - ShInitialize(); - - // Init for standalone - glslang::InitGlobalLock(); - if (! ProcessArguments(argc, argv)) { usage(); return EFailUsage; @@ -620,9 +614,13 @@ int C_DECL main(int argc, char* argv[]) // 1) linking all arguments together, single-threaded, new C++ interface // 2) independent arguments, can be tackled by multiple asynchronous threads, for testing thread safety, using the old handle interface // - if (Options & EOptionsLinkProgram) + if (Options & EOptionsLinkProgram) { + glslang::InitializeProcess(); CompileAndLinkShaders(); - else { + glslang::FinalizeProcess(); + } else { + ShInitialize(); + bool printShaderNames = Worklist.size() > 1; if (Options & EOptionMultiThreaded) { @@ -650,6 +648,8 @@ int C_DECL main(int argc, char* argv[]) delete Work[w]; } } + + ShFinalize(); } if (Delay) diff --git a/glslang/Include/InitializeGlobals.h b/glslang/Include/InitializeGlobals.h index b9a8304c..6c9f54a0 100644 --- a/glslang/Include/InitializeGlobals.h +++ b/glslang/Include/InitializeGlobals.h @@ -37,7 +37,7 @@ namespace glslang { -void InitializeGlobalPools(); +void InitializeMemoryPools(); void FreeGlobalPools(); bool InitializePoolIndex(); void FreePoolIndex(); diff --git a/glslang/Include/PoolAlloc.h b/glslang/Include/PoolAlloc.h index 34d494f7..59ddc41b 100644 --- a/glslang/Include/PoolAlloc.h +++ b/glslang/Include/PoolAlloc.h @@ -252,9 +252,9 @@ private: typedef TPoolAllocator* PoolAllocatorPointer; extern TPoolAllocator& GetThreadPoolAllocator(); -struct TThreadGlobalPools +struct TThreadMemoryPools { - TPoolAllocator* globalPoolAllocator; + TPoolAllocator* threadPoolAllocator; }; void SetThreadPoolAllocator(TPoolAllocator& poolAllocator); diff --git a/glslang/Include/intermediate.h b/glslang/Include/intermediate.h index a1e012e3..f1c54873 100644 --- a/glslang/Include/intermediate.h +++ b/glslang/Include/intermediate.h @@ -459,7 +459,7 @@ protected: class TIntermSymbol : public TIntermTyped { public: // if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. If sym comes from - // per process globalpoolallocator, then it causes increased memory usage per compile + // per process threadPoolAllocator, then it causes increased memory usage per compile // it is essential to use "symbol = sym" to assign to symbol TIntermSymbol(int i, const TString& n, const TType& t) : TIntermTyped(t), id(i) { name = n;} diff --git a/glslang/MachineIndependent/PoolAlloc.cpp b/glslang/MachineIndependent/PoolAlloc.cpp index 9e50a196..e88573bc 100644 --- a/glslang/MachineIndependent/PoolAlloc.cpp +++ b/glslang/MachineIndependent/PoolAlloc.cpp @@ -42,17 +42,17 @@ namespace glslang { OS_TLSIndex PoolIndex; -void InitializeGlobalPools() +void InitializeMemoryPools() { - TThreadGlobalPools* globalPools = static_cast(OS_GetTLSValue(PoolIndex)); - if (globalPools) + TThreadMemoryPools* pools = static_cast(OS_GetTLSValue(PoolIndex)); + if (pools) return; - TPoolAllocator *globalPoolAllocator = new TPoolAllocator(); + TPoolAllocator *threadPoolAllocator = new TPoolAllocator(); - TThreadGlobalPools* threadData = new TThreadGlobalPools(); + TThreadMemoryPools* threadData = new TThreadMemoryPools(); - threadData->globalPoolAllocator = globalPoolAllocator; + threadData->threadPoolAllocator = threadPoolAllocator; OS_SetTLSValue(PoolIndex, threadData); } @@ -60,7 +60,7 @@ void InitializeGlobalPools() void FreeGlobalPools() { // Release the allocated memory for this thread. - TThreadGlobalPools* globalPools = static_cast(OS_GetTLSValue(PoolIndex)); + TThreadMemoryPools* globalPools = static_cast(OS_GetTLSValue(PoolIndex)); if (! globalPools) return; @@ -86,16 +86,16 @@ void FreePoolIndex() TPoolAllocator& GetThreadPoolAllocator() { - TThreadGlobalPools* threadData = static_cast(OS_GetTLSValue(PoolIndex)); + TThreadMemoryPools* threadData = static_cast(OS_GetTLSValue(PoolIndex)); - return *threadData->globalPoolAllocator; + return *threadData->threadPoolAllocator; } void SetThreadPoolAllocator(TPoolAllocator& poolAllocator) { - TThreadGlobalPools* threadData = static_cast(OS_GetTLSValue(PoolIndex)); + TThreadMemoryPools* threadData = static_cast(OS_GetTLSValue(PoolIndex)); - threadData->globalPoolAllocator = &poolAllocator; + threadData->threadPoolAllocator = &poolAllocator; } // diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index 01cf2f84..ea93c151 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -538,6 +538,8 @@ bool CompileDeferred( // int ShInitialize() { + glslang::InitGlobalLock(); + if (! InitProcess()) return 0; @@ -546,7 +548,7 @@ int ShInitialize() glslang::TScanContext::fillInKeywordMap(); - return true; + return 1; } // @@ -909,6 +911,16 @@ int ShGetUniformLocation(const ShHandle handle, const char* name) namespace glslang { +bool InitializeProcess() +{ + return ShInitialize() != 0; +} + +void FinalizeProcess() +{ + ShFinalize(); +} + class TDeferredCompiler : public TCompiler { public: TDeferredCompiler(EShLanguage s, TInfoSink& i) : TCompiler(s, i) { } diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index 8e43cbc8..f9d33364 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -267,6 +267,20 @@ class TIntermediate; class TProgram; class TPoolAllocator; +// Call this exactly once per process before using anything else +bool InitializeProcess(); + +// Call once per process to tear down everything +void FinalizeProcess(); + +// Make one TShader per shader that you will link into a program. Then +// provide the shader through setStrings(), then call parse(), then query +// the info logs. +// +// N.B.: Does not yet support having the same TShader instance being linked multiple programs. +// +// N.B.: Destruct a linked program *before* destructing the shaders linked into it. +// class TShader { public: explicit TShader(EShLanguage); @@ -291,6 +305,12 @@ private: TShader& operator=(TShader&); }; +// Make one TProgram per set of shaders that will get linked together. Add all +// the shaders that are to be linked together. After calling shader.parse() +// for all shaders, call link(). +// +// N.B.: Destruct a linked program *before* destructing the shaders linked into it. +// class TProgram { public: TProgram(); @@ -314,5 +334,4 @@ private: } // end namespace glslang - #endif // _COMPILER_INTERFACE_INCLUDED_