Provide an API for accessing the uniform array.

TRAC #22239
Signed-off-by: Daniel Koch
Signed-off-by: Shannon Woods
Author: Nicolas Capens

git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1625 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/include/GLSLANG/ShaderLang.h b/include/GLSLANG/ShaderLang.h
index 545219a..1b8e32d 100644
--- a/include/GLSLANG/ShaderLang.h
+++ b/include/GLSLANG/ShaderLang.h
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 //
@@ -36,7 +36,7 @@
 
 // Version number for shader translation API.
 // It is incremented everytime the API changes.
-#define SH_VERSION 107
+#define SH_VERSION 108
 
 //
 // The names of the following enums have been derived by replacing GL prefix
@@ -115,7 +115,8 @@
   SH_MAPPED_NAME_MAX_LENGTH      =  0x6000,
   SH_NAME_MAX_LENGTH             =  0x6001,
   SH_HASHED_NAME_MAX_LENGTH      =  0x6002,
-  SH_HASHED_NAMES_COUNT          =  0x6003
+  SH_HASHED_NAMES_COUNT          =  0x6003,
+  SH_ACTIVE_UNIFORMS_ARRAY       =  0x6004
 } ShShaderInfo;
 
 // Compile options.
@@ -384,6 +385,18 @@
                                            char* name,
                                            char* hashedName);
 
+// Returns a parameter from a compiled shader.
+// Parameters:
+// handle: Specifies the compiler
+// pname: Specifies the parameter to query.
+// The following parameters are defined:
+// SH_ACTIVE_UNIFORMS_ARRAY: an STL vector of active uniforms. Valid only for
+//                           HLSL output.
+// params: Requested parameter
+COMPILER_EXPORT void ShGetInfoPointer(const ShHandle handle,
+                                      ShShaderInfo pname,
+                                      void** params);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/compiler/OutputHLSL.cpp b/src/compiler/OutputHLSL.cpp
index 6bccc9a..7139fa1 100644
--- a/src/compiler/OutputHLSL.cpp
+++ b/src/compiler/OutputHLSL.cpp
@@ -115,6 +115,11 @@
     return mBody;
 }
 
+const ActiveUniforms &OutputHLSL::getUniforms()
+{
+    return mActiveUniforms;
+}
+
 int OutputHLSL::vectorSize(const TType &type) const
 {
     int elementSize = type.isMatrix() ? type.getNominalSize() : 1;
diff --git a/src/compiler/OutputHLSL.h b/src/compiler/OutputHLSL.h
index c7e0628..68c9899 100644
--- a/src/compiler/OutputHLSL.h
+++ b/src/compiler/OutputHLSL.h
@@ -31,6 +31,7 @@
     void output();
 
     TInfoSinkBase &getBodyStream();
+    const ActiveUniforms &getUniforms();
 
     TString typeString(const TType &type);
     static TString qualifierString(TQualifier qualifier);
diff --git a/src/compiler/ShHandle.h b/src/compiler/ShHandle.h
index 23f0cf3..d6aa90b 100644
--- a/src/compiler/ShHandle.h
+++ b/src/compiler/ShHandle.h
@@ -26,6 +26,7 @@
 class LongNameMap;
 class TCompiler;
 class TDependencyGraph;
+class TranslatorHLSL;
 
 //
 // Helper function to identify specs that are based on the WebGL spec,
@@ -41,6 +42,7 @@
     TShHandleBase();
     virtual ~TShHandleBase();
     virtual TCompiler* getAsCompiler() { return 0; }
+    virtual TranslatorHLSL* getAsTranslatorHLSL() { return 0; }
 
 protected:
     // Memory allocator. Allocates and tracks memory required by the compiler.
diff --git a/src/compiler/ShaderLang.cpp b/src/compiler/ShaderLang.cpp
index ab56538..a4a8f6c 100644
--- a/src/compiler/ShaderLang.cpp
+++ b/src/compiler/ShaderLang.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 //
@@ -14,6 +14,7 @@
 #include "compiler/InitializeDll.h"
 #include "compiler/preprocessor/length_limits.h"
 #include "compiler/ShHandle.h"
+#include "compiler/TranslatorHLSL.h"
 
 //
 // This is the platform independent interface between an OGL driver
@@ -345,3 +346,21 @@
     // To be on the safe side in case the source is longer than expected.
     hashedName[len] = '\0';
 }
+
+void ShGetInfoPointer(const ShHandle handle, ShShaderInfo pname, void** params)
+{
+    if (!handle || !params)
+        return;
+
+    TShHandleBase* base = static_cast<TShHandleBase*>(handle);
+    TranslatorHLSL* translator = base->getAsTranslatorHLSL();
+    if (!translator) return;
+
+    switch(pname)
+    {
+    case SH_ACTIVE_UNIFORMS_ARRAY:
+        *params = (void*)&translator->getUniforms();
+        break;
+    default: UNREACHABLE();
+    }
+}
\ No newline at end of file
diff --git a/src/compiler/TranslatorHLSL.cpp b/src/compiler/TranslatorHLSL.cpp
index f41decd..807ceed 100644
--- a/src/compiler/TranslatorHLSL.cpp
+++ b/src/compiler/TranslatorHLSL.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 //
@@ -20,4 +20,5 @@
     sh::OutputHLSL outputHLSL(parseContext);
 
     outputHLSL.output();
+    mActiveUniforms = outputHLSL.getUniforms();
 }
diff --git a/src/compiler/TranslatorHLSL.h b/src/compiler/TranslatorHLSL.h
index c3f672b..51e2fbd 100644
--- a/src/compiler/TranslatorHLSL.h
+++ b/src/compiler/TranslatorHLSL.h
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 //
@@ -8,13 +8,19 @@
 #define COMPILER_TRANSLATORHLSL_H_
 
 #include "compiler/ShHandle.h"
+#include "compiler/Uniform.h"
 
 class TranslatorHLSL : public TCompiler {
 public:
     TranslatorHLSL(ShShaderType type, ShShaderSpec spec);
 
+    virtual TranslatorHLSL *getAsTranslatorHLSL() { return this; }
+    const sh::ActiveUniforms &getUniforms() { return mActiveUniforms; }
+
 protected:
     virtual void translate(TIntermNode* root);
+
+    sh::ActiveUniforms mActiveUniforms;
 };
 
 #endif  // COMPILER_TRANSLATORHLSL_H_