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
parent f956186f
......@@ -113,6 +113,8 @@
'compiler/SymbolTable.cpp',
'compiler/SymbolTable.h',
'compiler/Types.h',
'compiler/Uniform.cpp',
'compiler/Uniform.h',
'compiler/util.cpp',
'compiler/util.h',
'compiler/ValidateLimitations.cpp',
......
......@@ -2616,6 +2616,8 @@ int OutputHLSL::samplerRegister(TIntermSymbol *sampler)
int index = mSamplerRegister;
mSamplerRegister += sampler->totalRegisterCount();
declareUniform(type, sampler->getSymbol(), index);
return index;
}
......@@ -2627,7 +2629,132 @@ int OutputHLSL::uniformRegister(TIntermSymbol *uniform)
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;
}
}
......@@ -16,6 +16,7 @@
#include "compiler/intermediate.h"
#include "compiler/ParseHelper.h"
#include "compiler/Uniform.h"
namespace sh
{
......@@ -158,6 +159,10 @@ class OutputHLSL : public TIntermTraverser
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;
};
}
......
//
// 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;
}
}
//
// 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_
......@@ -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">
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment