Interface and naming improvements:
 - the new C++ style interface now stands on its own, with the addition of glslang::InitializeProcess() and glslang::FinalizeProcess()
 - more "global" pool names from a decade ago are fixed to be thread names
 - StandAlone.cpp fully uses one of the old-style interface or new C++ style interface


git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23851 e7fa87d3-cd2b-0410-9028-fcbf551c1848
diff --git a/OGLCompilersDLL/InitializeDll.cpp b/OGLCompilersDLL/InitializeDll.cpp
index 5f5ec3a..970cd96 100644
--- a/OGLCompilersDLL/InitializeDll.cpp
+++ b/OGLCompilersDLL/InitializeDll.cpp
@@ -94,7 +94,7 @@
     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 eb0c6f4..b3a37dc 100644
--- a/StandAlone/StandAlone.cpp
+++ b/StandAlone/StandAlone.cpp
@@ -591,12 +591,6 @@
     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 @@
     // 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 @@
                 delete Work[w];
             }
         }
+
+        ShFinalize();
     }
 
     if (Delay)
diff --git a/glslang/Include/InitializeGlobals.h b/glslang/Include/InitializeGlobals.h
index b9a8304..6c9f54a 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 34d494f..59ddc41 100644
--- a/glslang/Include/PoolAlloc.h
+++ b/glslang/Include/PoolAlloc.h
@@ -252,9 +252,9 @@
 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 a1e012e..f1c5487 100644
--- a/glslang/Include/intermediate.h
+++ b/glslang/Include/intermediate.h
@@ -459,7 +459,7 @@
 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 9e50a19..e88573b 100644
--- a/glslang/MachineIndependent/PoolAlloc.cpp
+++ b/glslang/MachineIndependent/PoolAlloc.cpp
@@ -42,17 +42,17 @@
 
 OS_TLSIndex PoolIndex;
 
-void InitializeGlobalPools()
+void InitializeMemoryPools()
 {
-    TThreadGlobalPools* globalPools = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));    
-    if (globalPools)
+    TThreadMemoryPools* pools = static_cast<TThreadMemoryPools*>(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 FreeGlobalPools()
 {
     // Release the allocated memory for this thread.
-    TThreadGlobalPools* globalPools = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));    
+    TThreadMemoryPools* globalPools = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));    
     if (! globalPools)
         return;
 	
@@ -86,16 +86,16 @@
 
 TPoolAllocator& GetThreadPoolAllocator()
 {
-    TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
+    TThreadMemoryPools* threadData = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));
 
-    return *threadData->globalPoolAllocator;
+    return *threadData->threadPoolAllocator;
 }
 
 void SetThreadPoolAllocator(TPoolAllocator& poolAllocator)
 {
-    TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
+    TThreadMemoryPools* threadData = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));
 
-    threadData->globalPoolAllocator = &poolAllocator;
+    threadData->threadPoolAllocator = &poolAllocator;
 }
 
 //
diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp
index 01cf2f8..ea93c15 100644
--- a/glslang/MachineIndependent/ShaderLang.cpp
+++ b/glslang/MachineIndependent/ShaderLang.cpp
@@ -538,6 +538,8 @@
 //
 int ShInitialize()
 {
+    glslang::InitGlobalLock();
+
     if (! InitProcess())
         return 0;
 
@@ -546,7 +548,7 @@
     
     glslang::TScanContext::fillInKeywordMap();
 
-    return true;
+    return 1;
 }
 
 //
@@ -909,6 +911,16 @@
 
 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 8e43cbc..f9d3336 100644
--- a/glslang/Public/ShaderLang.h
+++ b/glslang/Public/ShaderLang.h
@@ -267,6 +267,20 @@
 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 @@
     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 @@
 
 } // end namespace glslang
 
-
 #endif // _COMPILER_INTERFACE_INCLUDED_