Commit 91b1004a by Geoff Lang

Only add the structure padding when compiling D3D11 shaders.

BUG=359225 Change-Id: Idc4e2c8631925324a5e7e2a591bd6aa75169817a Reviewed-on: https://chromium-review.googlesource.com/201890Tested-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 28bcf4ff
...@@ -193,7 +193,7 @@ void OutputHLSL::header() ...@@ -193,7 +193,7 @@ void OutputHLSL::header()
const TString &name = varying->second->getSymbol(); const TString &name = varying->second->getSymbol();
// Program linking depends on this exact format // Program linking depends on this exact format
varyings += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type) + ";\n"; varyings += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type, mOutputType) + ";\n";
} }
for (ReferencedSymbols::const_iterator attribute = mReferencedAttributes.begin(); attribute != mReferencedAttributes.end(); attribute++) for (ReferencedSymbols::const_iterator attribute = mReferencedAttributes.begin(); attribute != mReferencedAttributes.end(); attribute++)
...@@ -201,7 +201,7 @@ void OutputHLSL::header() ...@@ -201,7 +201,7 @@ void OutputHLSL::header()
const TType &type = attribute->second->getType(); const TType &type = attribute->second->getType();
const TString &name = attribute->second->getSymbol(); const TString &name = attribute->second->getSymbol();
attributes += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type) + ";\n"; attributes += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type, mOutputType) + ";\n";
} }
if (mUsesDiscardRewriting) if (mUsesDiscardRewriting)
...@@ -1772,7 +1772,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1772,7 +1772,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{ {
symbol->traverse(this); symbol->traverse(this);
out << arrayString(symbol->getType()); out << arrayString(symbol->getType());
out << " = " + initializer(symbol->getType()); out << " = " + initializer(symbol->getType(), mOutputType);
} }
else else
{ {
...@@ -2900,7 +2900,7 @@ TString OutputHLSL::arrayString(const TType &type) ...@@ -2900,7 +2900,7 @@ TString OutputHLSL::arrayString(const TType &type)
return "[" + str(type.getArraySize()) + "]"; return "[" + str(type.getArraySize()) + "]";
} }
static size_t getTypeComponentCount(const TType &type) static size_t getTypeComponentCount(const TType &type, ShShaderOutput outputType)
{ {
if (type.getStruct()) if (type.getStruct())
{ {
...@@ -2912,8 +2912,8 @@ static size_t getTypeComponentCount(const TType &type) ...@@ -2912,8 +2912,8 @@ static size_t getTypeComponentCount(const TType &type)
const TField *field = fields[i]; const TField *field = fields[i];
const TType *fieldType = field->type(); const TType *fieldType = field->type();
compCount += getTypeComponentCount(*fieldType); compCount += getTypeComponentCount(*fieldType, outputType);
if (!fieldType->getStruct()) if (!fieldType->getStruct() && outputType == SH_HLSL11_OUTPUT)
{ {
// Add padding size // Add padding size
compCount += 4 - fieldType->getNominalSize(); compCount += 4 - fieldType->getNominalSize();
...@@ -2933,11 +2933,11 @@ static size_t getTypeComponentCount(const TType &type) ...@@ -2933,11 +2933,11 @@ static size_t getTypeComponentCount(const TType &type)
} }
} }
TString OutputHLSL::initializer(const TType &type) TString OutputHLSL::initializer(const TType &type, ShShaderOutput outputType)
{ {
TString string; TString string;
size_t size = getTypeComponentCount(type); size_t size = getTypeComponentCount(type, outputType);
for (size_t component = 0; component < size; component++) for (size_t component = 0; component < size; component++)
{ {
string += "0"; string += "0";
...@@ -2991,7 +2991,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI ...@@ -2991,7 +2991,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
structure += " " + typeString(*field->type()) + " " + decorateField(field->name(), type) + arrayString(*field->type()) + ";\n"; structure += " " + typeString(*field->type()) + " " + decorateField(field->name(), type) + arrayString(*field->type()) + ";\n";
if (!field->type()->getStruct()) if (!field->type()->getStruct() && mOutputType == SH_HLSL11_OUTPUT)
{ {
// Add padding to prevent tight packing (crbug.com/359225) // Add padding to prevent tight packing (crbug.com/359225)
unsigned int padRequired = 4 - field->type()->getNominalSize(); unsigned int padRequired = 4 - field->type()->getNominalSize();
...@@ -3123,7 +3123,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI ...@@ -3123,7 +3123,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
constructor += "x" + str(parameterIndex); constructor += "x" + str(parameterIndex);
if (!field->type()->getStruct()) if (!field->type()->getStruct() && mOutputType == SH_HLSL11_OUTPUT)
{ {
unsigned int padRequired = 4 - field->type()->getNominalSize(); unsigned int padRequired = 4 - field->type()->getNominalSize();
switch (padRequired) switch (padRequired)
......
...@@ -37,7 +37,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -37,7 +37,7 @@ class OutputHLSL : public TIntermTraverser
TString textureString(const TType &type); TString textureString(const TType &type);
static TString qualifierString(TQualifier qualifier); static TString qualifierString(TQualifier qualifier);
static TString arrayString(const TType &type); static TString arrayString(const TType &type);
static TString initializer(const TType &type); static TString initializer(const TType &type, ShShaderOutput outputType);
static TString decorate(const TString &string); // Prepends 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, const TType &type); static TString decorateUniform(const TString &string, const TType &type);
static TString decorateField(const TString &string, const TType &structure); static TString decorateField(const TString &string, const TType &structure);
......
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