Decorate arrays uniforms with "ar_" to identify arrays of size 1.

TRAC #16567 Bug=136 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@760 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 024f1a91
#define MAJOR_VERSION 0
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 759
#define BUILD_REVISION 760
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -136,7 +136,7 @@ void OutputHLSL::header()
{
if (mReferencedUniforms.find(name.c_str()) != mReferencedUniforms.end())
{
uniforms += "uniform " + typeString(type) + " " + decorate(name) + arrayString(type) + ";\n";
uniforms += "uniform " + typeString(type) + " " + decorateUniform(name, type.isArray()) + arrayString(type) + ";\n";
}
}
else if (qualifier == EvqVaryingIn || qualifier == EvqInvariantVaryingIn)
......@@ -300,7 +300,7 @@ void OutputHLSL::header()
{
if (mReferencedUniforms.find(name.c_str()) != mReferencedUniforms.end())
{
uniforms += "uniform " + typeString(type) + " " + decorate(name) + arrayString(type) + ";\n";
uniforms += "uniform " + typeString(type) + " " + decorateUniform(name, type.isArray()) + arrayString(type) + ";\n";
}
}
else if (qualifier == EvqAttribute)
......@@ -729,17 +729,22 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
if (qualifier == EvqUniform)
{
mReferencedUniforms.insert(name.c_str());
out << decorateUniform(name, node->isArray());
}
else if (qualifier == EvqAttribute)
{
mReferencedAttributes.insert(name.c_str());
out << decorate(name);
}
else if (qualifier == EvqVaryingOut || qualifier == EvqInvariantVaryingOut || qualifier == EvqVaryingIn || qualifier == EvqInvariantVaryingIn)
{
mReferencedVaryings.insert(name.c_str());
out << decorate(name);
}
else
{
out << decorate(name);
}
out << decorate(name);
}
}
......@@ -2341,9 +2346,17 @@ TString OutputHLSL::decorate(const TString &string)
{
return "_" + string;
}
else
return string;
}
TString OutputHLSL::decorateUniform(const TString &string, bool array)
{
if (array)
{
return string;
return "ar_" + string; // Allows identifying arrays of size 1
}
return decorate(string);
}
}
......@@ -31,7 +31,8 @@ class OutputHLSL : public TIntermTraverser
static TString qualifierString(TQualifier qualifier);
static TString arrayString(const TType &type);
static TString initializer(const TType &type);
static TString decorate(const TString &string); // Prepend an underscore to avoid naming clashes
static TString decorate(const TString &string); // Prepends an underscore to avoid naming clashes
static TString decorateUniform(const TString &string, bool array);
protected:
void header();
......
......@@ -34,7 +34,7 @@ std::string str(int i)
}
Uniform::Uniform(GLenum type, const std::string &_name, unsigned int arraySize)
: type(type), _name(_name), name(Program::undecorate(_name)), arraySize(arraySize)
: type(type), _name(_name), name(Program::undecorateUniform(_name)), arraySize(arraySize)
{
int bytes = UniformTypeSize(type) * arraySize;
data = new unsigned char[bytes];
......@@ -50,11 +50,11 @@ Uniform::~Uniform()
bool Uniform::isArray()
{
return arraySize != 1; // FIXME: Arrays can be of size 1
return _name.substr(0, 3) == "ar_";
}
UniformLocation::UniformLocation(const std::string &_name, unsigned int element, unsigned int index)
: name(Program::undecorate(_name)), element(element), index(index)
: name(Program::undecorateUniform(_name)), element(element), index(index)
{
}
......@@ -1282,7 +1282,7 @@ bool Program::linkVaryings()
default: UNREACHABLE();
}
mVertexHLSL += decorate(attribute->name) + " : TEXCOORD" + str(semanticIndex) + ";\n";
mVertexHLSL += decorateAttribute(attribute->name) + " : TEXCOORD" + str(semanticIndex) + ";\n";
semanticIndex += VariableRowCount(attribute->type);
}
......@@ -1317,14 +1317,14 @@ bool Program::linkVaryings()
for (AttributeArray::iterator attribute = mVertexShader->mAttributes.begin(); attribute != mVertexShader->mAttributes.end(); attribute++)
{
mVertexHLSL += " " + decorate(attribute->name) + " = ";
mVertexHLSL += " " + decorateAttribute(attribute->name) + " = ";
if (VariableRowCount(attribute->type) > 1) // Matrix
{
mVertexHLSL += "transpose";
}
mVertexHLSL += "(input." + decorate(attribute->name) + ");\n";
mVertexHLSL += "(input." + decorateAttribute(attribute->name) + ");\n";
}
mVertexHLSL += "\n"
......@@ -1903,7 +1903,7 @@ Uniform *Program::createUniform(const D3DXCONSTANT_DESC &constantDescription, st
}
// This method needs to match OutputHLSL::decorate
std::string Program::decorate(const std::string &name)
std::string Program::decorateAttribute(const std::string &name)
{
if (name.substr(0, 3) != "gl_" && name.substr(0, 3) != "dx_")
{
......@@ -1913,12 +1913,16 @@ std::string Program::decorate(const std::string &name)
return name;
}
std::string Program::undecorate(const std::string &_name)
std::string Program::undecorateUniform(const std::string &_name)
{
if (_name.substr(0, 1) == "_")
{
return _name.substr(1);
}
else if (_name.substr(0, 3) == "ar_")
{
return _name.substr(3);
}
return _name;
}
......
......@@ -130,6 +130,9 @@ class Program
unsigned int getSerial() const;
static std::string decorateAttribute(const std::string &name); // Prepend an underscore
static std::string undecorateUniform(const std::string &_name); // Remove leading underscore
private:
DISALLOW_COPY_AND_ASSIGN(Program);
......@@ -168,9 +171,6 @@ class Program
void appendToInfoLog(const char *info, ...);
void resetInfoLog();
static std::string decorate(const std::string &name); // Prepend an underscore
static std::string undecorate(const std::string &_name); // Remove leading underscore
static unsigned int issueSerial();
FragmentShader *mFragmentShader;
......
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