Declare active uniforms.
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@1624 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/OutputHLSL.cpp b/src/compiler/OutputHLSL.cpp
index 9fafc6d..6bccc9a 100644
--- a/src/compiler/OutputHLSL.cpp
+++ b/src/compiler/OutputHLSL.cpp
@@ -2616,6 +2616,8 @@
int index = mSamplerRegister;
mSamplerRegister += sampler->totalRegisterCount();
+ declareUniform(type, sampler->getSymbol(), index);
+
return index;
}
@@ -2627,7 +2629,132 @@
int index = mUniformRegister;
mUniformRegister += uniform->totalRegisterCount();
+ declareUniform(type, uniform->getSymbol(), index);
+
return index;
}
+void OutputHLSL::declareUniform(const TType &type, const TString &name, int index)
+{
+ const TTypeList *structure = type.getStruct();
+
+ if (!structure)
+ {
+ mActiveUniforms.push_back(Uniform(glVariableType(type), name.c_str(), type.getArraySize(), index));
+ }
+ else
+ {
+ if (type.isArray())
+ {
+ int elementIndex = index;
+
+ for (int i = 0; i < type.getArraySize(); i++)
+ {
+ for (size_t j = 0; j < structure->size(); j++)
+ {
+ const TType &fieldType = *(*structure)[j].type;
+ const TString &fieldName = fieldType.getFieldName();
+
+ const TString uniformName = name + "[" + str(i) + "]." + fieldName;
+ declareUniform(fieldType, uniformName, elementIndex);
+ elementIndex += fieldType.elementRegisterCount();
+ }
+ }
+ }
+ else
+ {
+ int fieldIndex = index;
+
+ for (size_t i = 0; i < structure->size(); i++)
+ {
+ const TType &fieldType = *(*structure)[i].type;
+ const TString &fieldName = fieldType.getFieldName();
+
+ const TString uniformName = name + "." + fieldName;
+ declareUniform(fieldType, uniformName, fieldIndex);
+ fieldIndex += fieldType.totalRegisterCount();
+ }
+ }
+ }
+}
+
+GLenum OutputHLSL::glVariableType(const TType &type)
+{
+ if (type.getBasicType() == EbtFloat)
+ {
+ if (type.isScalar())
+ {
+ return GL_FLOAT;
+ }
+ else if (type.isVector())
+ {
+ switch(type.getNominalSize())
+ {
+ case 2: return GL_FLOAT_VEC2;
+ case 3: return GL_FLOAT_VEC3;
+ case 4: return GL_FLOAT_VEC4;
+ default: UNREACHABLE();
+ }
+ }
+ else if (type.isMatrix())
+ {
+ switch(type.getNominalSize())
+ {
+ case 2: return GL_FLOAT_MAT2;
+ case 3: return GL_FLOAT_MAT3;
+ case 4: return GL_FLOAT_MAT4;
+ default: UNREACHABLE();
+ }
+ }
+ else UNREACHABLE();
+ }
+ else if (type.getBasicType() == EbtInt)
+ {
+ if (type.isScalar())
+ {
+ return GL_INT;
+ }
+ else if (type.isVector())
+ {
+ switch(type.getNominalSize())
+ {
+ case 2: return GL_INT_VEC2;
+ case 3: return GL_INT_VEC3;
+ case 4: return GL_INT_VEC4;
+ default: UNREACHABLE();
+ }
+ }
+ else UNREACHABLE();
+ }
+ else if (type.getBasicType() == EbtBool)
+ {
+ if (type.isScalar())
+ {
+ return GL_BOOL;
+ }
+ else if (type.isVector())
+ {
+ switch(type.getNominalSize())
+ {
+ case 2: return GL_BOOL_VEC2;
+ case 3: return GL_BOOL_VEC3;
+ case 4: return GL_BOOL_VEC4;
+ default: UNREACHABLE();
+ }
+ }
+ else UNREACHABLE();
+ }
+ else if (type.getBasicType() == EbtSampler2D)
+ {
+ return GL_SAMPLER_2D;
+ }
+ else if (type.getBasicType() == EbtSamplerCube)
+ {
+ return GL_SAMPLER_CUBE;
+ }
+ else UNREACHABLE();
+
+ return GL_NONE;
+}
+
}
diff --git a/src/compiler/OutputHLSL.h b/src/compiler/OutputHLSL.h
index fafc04f..c7e0628 100644
--- a/src/compiler/OutputHLSL.h
+++ b/src/compiler/OutputHLSL.h
@@ -16,6 +16,7 @@
#include "compiler/intermediate.h"
#include "compiler/ParseHelper.h"
+#include "compiler/Uniform.h"
namespace sh
{
@@ -158,6 +159,10 @@
TString registerString(TIntermSymbol *operand);
int samplerRegister(TIntermSymbol *sampler);
int uniformRegister(TIntermSymbol *uniform);
+ void declareUniform(const TType &type, const TString &name, int index);
+ static GLenum glVariableType(const TType &type);
+
+ ActiveUniforms mActiveUniforms;
};
}
diff --git a/src/compiler/Uniform.cpp b/src/compiler/Uniform.cpp
new file mode 100644
index 0000000..55177fa
--- /dev/null
+++ b/src/compiler/Uniform.cpp
@@ -0,0 +1,20 @@
+//
+// Copyright (c) 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.
+//
+
+#include "compiler/Uniform.h"
+
+namespace sh
+{
+
+Uniform::Uniform(GLenum type, const char *name, int arraySize, int registerIndex)
+{
+ this->type = type;
+ this->name = name;
+ this->arraySize = arraySize;
+ this->registerIndex = registerIndex;
+}
+
+}
diff --git a/src/compiler/Uniform.h b/src/compiler/Uniform.h
new file mode 100644
index 0000000..5509a87
--- /dev/null
+++ b/src/compiler/Uniform.h
@@ -0,0 +1,34 @@
+//
+// Copyright (c) 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.
+//
+
+#ifndef COMPILER_UNIFORM_H_
+#define COMPILER_UNIFORM_H_
+
+#include <string>
+#include <vector>
+
+#define GL_APICALL
+#include <GLES2/gl2.h>
+
+namespace sh
+{
+
+struct Uniform
+{
+ Uniform(GLenum type, const char *name, int arraySize, int registerIndex);
+
+ GLenum type;
+ std::string name;
+ int arraySize;
+
+ int registerIndex;
+};
+
+typedef std::vector<Uniform> ActiveUniforms;
+
+}
+
+#endif // COMPILER_UNIFORM_H_
diff --git a/src/compiler/translator_hlsl.vcxproj b/src/compiler/translator_hlsl.vcxproj
index 4ebc11c..686ef46 100644
--- a/src/compiler/translator_hlsl.vcxproj
+++ b/src/compiler/translator_hlsl.vcxproj
@@ -148,6 +148,7 @@
<ClCompile Include="SearchSymbol.cpp" />
<ClCompile Include="TranslatorHLSL.cpp" />
<ClCompile Include="UnfoldShortCircuit.cpp" />
+ <ClCompile Include="Uniform.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DetectDiscontinuity.h" />
@@ -155,6 +156,7 @@
<ClInclude Include="SearchSymbol.h" />
<ClInclude Include="TranslatorHLSL.h" />
<ClInclude Include="UnfoldShortCircuit.h" />
+ <ClInclude Include="Uniform.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="translator_common.vcxproj">
diff --git a/src/compiler/translator_hlsl.vcxproj.filters b/src/compiler/translator_hlsl.vcxproj.filters
index beee069..f4824dc 100644
--- a/src/compiler/translator_hlsl.vcxproj.filters
+++ b/src/compiler/translator_hlsl.vcxproj.filters
@@ -29,6 +29,9 @@
<ClCompile Include="UnfoldShortCircuit.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Uniform.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="DetectDiscontinuity.h">
@@ -46,5 +49,8 @@
<ClInclude Include="UnfoldShortCircuit.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="Uniform.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file