Include per-shader and per-program pools in the new C++ interface to glslang. (And...
authorJohn Kessenich <cepheus@frii.com>
Fri, 1 Nov 2013 03:08:40 +0000 (03:08 +0000)
committerJohn Kessenich <cepheus@frii.com>
Fri, 1 Nov 2013 03:08:40 +0000 (03:08 +0000)
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23844 e7fa87d3-cd2b-0410-9028-fcbf551c1848

StandAlone/StandAlone.cpp
Test/baseResults/120.vert.out
glslang/MachineIndependent/ShaderLang.cpp
glslang/Public/ShaderLang.h

index 441f88b..eb0c6f4 100644 (file)
@@ -537,7 +537,7 @@ void CompileAndLinkShaders()
     // Per-shader processing...
     //
 
-    glslang::TProgram program;
+    glslang::TProgram& program = *new glslang::TProgram;
     glslang::TWorkItem* workItem;
     while (Worklist.remove(workItem)) {
         EShLanguage stage = FindLanguage(workItem->name);
@@ -575,13 +575,15 @@ void CompileAndLinkShaders()
         puts(program.getInfoDebugLog());
     }
 
-    // free everything up
+    // Free everything up, program has to go before the shaders
+    // because it might have merged stuff from the shaders, and
+    // the stuff from the shaders has to have its destructors called
+    // before the pools holding the memory in the shaders is freed.
+    delete &program;
     while (shaders.size() > 0) {
         delete shaders.back();
         shaders.pop_back();
     }
-
-    // TODO: memory: for each compile, need a GetThreadPoolAllocator().pop();
 }
 
 int C_DECL main(int argc, char* argv[])
@@ -613,7 +615,6 @@ int C_DECL main(int argc, char* argv[])
 
     ProcessConfigFile();
 
-
     //
     // Two modes:
     // 1) linking all arguments together, single-threaded, new C++ interface
index 851bbf0..5175d5b 100644 (file)
@@ -34,13 +34,15 @@ ERROR: 0:52: 'arrays of arrays' : not supported with this profile: none
 ERROR: 0:53: 'arrays of arrays' : not supported with this profile: none\r
 ERROR: 0:56: 'out' : overloaded functions must have the same parameter qualifiers \r
 ERROR: 0:57: 'float' : overloaded functions must have the same return type \r
-ERROR: 0:86: 'overloadC' : no matching overloaded function found \r
-ERROR: 0:91: 'overloadD' : ambiguous function signature match: multiple signatures match under implicit type conversion \r
-ERROR: 0:102: 'overloadC' : no matching overloaded function found \r
-ERROR: 0:103: 'overloadE' : no matching overloaded function found \r
-ERROR: 0:104: 'overloadE' : no matching overloaded function found \r
+ERROR: 0:87: 'overloadC' : no matching overloaded function found \r
+ERROR: 0:90: 'overloadC' : no matching overloaded function found \r
+ERROR: 0:95: 'overloadD' : ambiguous function signature match: multiple signatures match under implicit type conversion \r
+ERROR: 0:106: 'overloadC' : no matching overloaded function found \r
 ERROR: 0:107: 'overloadE' : no matching overloaded function found \r
-ERROR: 42 compilation errors.  No code generated.\r
+ERROR: 0:108: 'overloadE' : no matching overloaded function found \r
+ERROR: 0:111: 'overloadE' : no matching overloaded function found \r
+ERROR: 0:117: 'overloadF' : no matching overloaded function found \r
+ERROR: 44 compilation errors.  No code generated.\r
 \r
 ERROR: node is still EOpNull!\r
 0:15  Function Definition: main( (void)\r
@@ -88,97 +90,104 @@ ERROR: node is still EOpNull!
 0:43        'gl_PointSize' (invariant gl_PointSize float)\r
 0:43        Constant:\r
 0:43          3.800000\r
-0:75  Function Definition: foo( (void)\r
-0:75    Function Parameters: \r
+0:78  Function Definition: foo( (void)\r
+0:78    Function Parameters: \r
 0:?     Sequence\r
-0:80      Function Call: overloadB(f1;f1; (2-component vector of float)\r
-0:80        'f' (float)\r
-0:80        'f' (float)\r
-0:81      Function Call: overloadB(f1;f1; (2-component vector of float)\r
-0:81        'f' (float)\r
-0:81        Constant:\r
-0:81          2 (const int)\r
-0:82      Function Call: overloadB(f1;f1; (2-component vector of float)\r
-0:82        Constant:\r
-0:82          1 (const int)\r
-0:82        'i' (int)\r
-0:84      Function Call: overloadC(i1;i1; (2-component vector of float)\r
+0:83      Function Call: overloadB(f1;f1; (2-component vector of float)\r
+0:83        'f' (float)\r
+0:83        'f' (float)\r
+0:84      Function Call: overloadB(f1;f1; (2-component vector of float)\r
+0:84        'f' (float)\r
 0:84        Constant:\r
-0:84          1 (const int)\r
-0:84        'i' (int)\r
-0:85      Function Call: overloadC(vf2;vf2; (2-component vector of float)\r
+0:84          2 (const int)\r
+0:85      Function Call: overloadB(f1;f1; (2-component vector of float)\r
 0:85        Constant:\r
-0:85          1.000000\r
-0:85          1.000000\r
-0:85        Constant:\r
-0:85          2.000000\r
-0:85          2.000000\r
-0:86      Constant:\r
-0:86        0.000000\r
-0:87      Function Call: overloadC(vf2;vf2; (2-component vector of float)\r
-0:87        Constant:\r
-0:87          1 (const int)\r
-0:87          1 (const int)\r
-0:87        Constant:\r
-0:87          2.000000\r
-0:87          2.000000\r
-0:89      Function Call: overloadD(i1;f1; (3-component vector of float)\r
-0:89        'i' (int)\r
-0:89        'f' (float)\r
-0:90      Function Call: overloadD(f1;i1; (3-component vector of float)\r
-0:90        'f' (float)\r
-0:90        'i' (int)\r
-0:91      Function Call: overloadD(f1;i1; (3-component vector of float)\r
-0:91        'i' (int)\r
-0:91        'i' (int)\r
-0:94      Function Call: overloadB(f1;f1; (2-component vector of float)\r
-0:94        Constant:\r
-0:94          1 (const int)\r
+0:85          1 (const int)\r
+0:85        'i' (int)\r
+0:87      Constant:\r
+0:87        0.000000\r
+0:88      Function Call: overloadC(i1;i1; (2-component vector of float)\r
+0:88        Constant:\r
+0:88          1 (const int)\r
+0:88        'i' (int)\r
+0:89      Function Call: overloadC(vf2;vf2; (2-component vector of float)\r
+0:89        Constant:\r
+0:89          1.000000\r
+0:89          1.000000\r
+0:89        Constant:\r
+0:89          2.000000\r
+0:89          2.000000\r
+0:90      Constant:\r
+0:90        0.000000\r
+0:91      Function Call: overloadC(vf2;vf2; (2-component vector of float)\r
+0:91        Constant:\r
+0:91          1 (const int)\r
+0:91          1 (const int)\r
+0:91        Constant:\r
+0:91          2.000000\r
+0:91          2.000000\r
+0:93      Function Call: overloadD(i1;f1; (3-component vector of float)\r
+0:93        'i' (int)\r
+0:93        'f' (float)\r
+0:94      Function Call: overloadD(f1;i1; (3-component vector of float)\r
+0:94        'f' (float)\r
 0:94        'i' (int)\r
-0:96      Constant:\r
-0:96        0.000000\r
-0:97      Function Call: texture2D(s21;vf2; (4-component vector of float)\r
-0:97        's2D' (uniform sampler2D)\r
-0:97        Constant:\r
-0:97          0 (const int)\r
-0:97          0 (const int)\r
-0:98      clamp (4-component vector of float)\r
-0:98        'attv4' (in 4-component vector of float)\r
-0:98        Constant:\r
-0:98          0 (const int)\r
+0:95      Function Call: overloadD(f1;i1; (3-component vector of float)\r
+0:95        'i' (int)\r
+0:95        'i' (int)\r
+0:98      Function Call: overloadB(f1;f1; (2-component vector of float)\r
 0:98        Constant:\r
 0:98          1 (const int)\r
-0:99      clamp (4-component vector of float)\r
-0:99        Convert float to int (4-component vector of int)\r
-0:99          'attv4' (in 4-component vector of float)\r
-0:99        Constant:\r
-0:99          0 (const int)\r
-0:99        Constant:\r
-0:99          1 (const int)\r
-0:102      Constant:\r
-0:102        0.000000\r
-0:103      Constant:\r
-0:103        0.000000\r
-0:104      Constant:\r
-0:104        0.000000\r
-0:105      Function Call: overloadE(vf2; (3-component vector of float)\r
-0:105        Constant:\r
-0:105          3.300000\r
-0:105          3.300000\r
-0:106      Function Call: overloadE(mf22; (3-component vector of float)\r
-0:106        Constant:\r
-0:106          0.500000\r
-0:106          0.000000\r
-0:106          0.000000\r
-0:106          0.500000\r
+0:98        'i' (int)\r
+0:100      Constant:\r
+0:100        0.000000\r
+0:101      Function Call: texture2D(s21;vf2; (4-component vector of float)\r
+0:101        's2D' (uniform sampler2D)\r
+0:101        Constant:\r
+0:101          0 (const int)\r
+0:101          0 (const int)\r
+0:102      clamp (4-component vector of float)\r
+0:102        'attv4' (in 4-component vector of float)\r
+0:102        Constant:\r
+0:102          0 (const int)\r
+0:102        Constant:\r
+0:102          1 (const int)\r
+0:103      clamp (4-component vector of float)\r
+0:103        Convert float to int (4-component vector of int)\r
+0:103          'attv4' (in 4-component vector of float)\r
+0:103        Constant:\r
+0:103          0 (const int)\r
+0:103        Constant:\r
+0:103          1 (const int)\r
+0:106      Constant:\r
+0:106        0.000000\r
 0:107      Constant:\r
 0:107        0.000000\r
-0:108      Function Call: overloadE(vf2; (3-component vector of float)\r
-0:108        Constant:\r
-0:108          1 (const int)\r
-0:108          1 (const int)\r
-0:111      Function Call: overloadE(f1[2]; (3-component vector of float)\r
-0:111        'b' (2-element array of float)\r
+0:108      Constant:\r
+0:108        0.000000\r
+0:109      Function Call: overloadE(vf2; (3-component vector of float)\r
+0:109        Constant:\r
+0:109          3.300000\r
+0:109          3.300000\r
+0:110      Function Call: overloadE(mf22; (3-component vector of float)\r
+0:110        Constant:\r
+0:110          0.500000\r
+0:110          0.000000\r
+0:110          0.000000\r
+0:110          0.500000\r
+0:111      Constant:\r
+0:111        0.000000\r
+0:112      Function Call: overloadE(vf2; (3-component vector of float)\r
+0:112        Constant:\r
+0:112          1 (const int)\r
+0:112          1 (const int)\r
+0:115      Function Call: overloadE(f1[2]; (3-component vector of float)\r
+0:115        'b' (2-element array of float)\r
+0:117      Constant:\r
+0:117        0.000000\r
+0:118      Function Call: overloadF(i1; (3-component vector of float)\r
+0:118        Constant:\r
+0:118          1 (const int)\r
 0:?   Linker Objects\r
 0:?     'i' (in 4-component vector of float)\r
 0:?     'o' (smooth out 4-component vector of float)\r
index 4072776..01cf2f8 100644 (file)
@@ -240,7 +240,7 @@ void SetupBuiltinSymbolTable(int version, EProfile profile)
     }
 
     // Switch to a new pool
-    TPoolAllocator& savedGPA = GetThreadPoolAllocator();
+    TPoolAllocator& previousAllocator = GetThreadPoolAllocator();
     TPoolAllocator* builtInPoolAllocator = new TPoolAllocator();
     SetThreadPoolAllocator(*builtInPoolAllocator);
 
@@ -282,7 +282,7 @@ void SetupBuiltinSymbolTable(int version, EProfile profile)
         delete stageTables[stage];
 
     delete builtInPoolAllocator;
-    SetThreadPoolAllocator(savedGPA);
+    SetThreadPoolAllocator(previousAllocator);
 
     glslang::ReleaseGlobalLock();
 }
@@ -915,9 +915,8 @@ public:
     virtual bool compile(TIntermNode* root, int version = 0, EProfile profile = ENoProfile) { return true; }
 };
 
-
 TShader::TShader(EShLanguage s) 
-    : stage(s)
+    : pool(0), stage(s)
 {
     infoSink = new TInfoSink;
     compiler = new TDeferredCompiler(stage, *infoSink);
@@ -929,6 +928,7 @@ TShader::~TShader()
     delete infoSink;
     delete compiler;
     delete intermediate;
+    delete pool;
 }
 
 //
@@ -936,9 +936,13 @@ TShader::~TShader()
 //
 bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages)
 {
-    return CompileDeferred(compiler, strings, numStrings, 0, EShOptNone, builtInResources, defaultVersion, forwardCompatible, messages, *intermediate);
+    if (! InitThread())
+        return false;
+    
+    pool = new TPoolAllocator();
+    SetThreadPoolAllocator(*pool);
 
-    // TODO: memory: pool needs to be popped
+    return CompileDeferred(compiler, strings, numStrings, 0, EShOptNone, builtInResources, defaultVersion, forwardCompatible, messages, *intermediate);
 }
 
 const char* TShader::getInfoLog()
@@ -951,7 +955,7 @@ const char* TShader::getInfoDebugLog()
     return infoSink->debug.c_str();
 }
 
-TProgram::TProgram()
+TProgram::TProgram() : pool(0)
 {
     infoSink = new TInfoSink;
     for (int s = 0; s < EShLangCount; ++s)
@@ -963,6 +967,8 @@ TProgram::~TProgram()
     delete infoSink;
     for (int s = 0; s < EShLangCount; ++s)
         delete intermediate[s];
+
+    delete pool;
 }
 
 //
@@ -973,6 +979,9 @@ bool TProgram::link(EShMessages messages)
 {
     bool error = false;
 
+    pool = new TPoolAllocator();
+    SetThreadPoolAllocator(*pool);
+
     for (int s = 0; s < EShLangCount; ++s) {
         if (! linkStage((EShLanguage)s, messages))
             error = true;
index 2463ea2..8e43cbc 100644 (file)
@@ -265,6 +265,7 @@ namespace glslang {
 
 class TIntermediate;
 class TProgram;
+class TPoolAllocator;
 
 class TShader {
 public:
@@ -276,6 +277,7 @@ public:
     const char* getInfoDebugLog();
 
 protected:
+    TPoolAllocator* pool;
     EShLanguage stage;
     TCompiler* compiler;
     TIntermediate* intermediate;
@@ -301,6 +303,7 @@ protected:
     bool linkStage(EShLanguage, EShMessages);
 
 protected:
+    TPoolAllocator* pool;
     std::list<TShader*> stages[EShLangCount];
     TIntermediate* intermediate[EShLangCount];
     TInfoSink* infoSink;