Commit 5878f832 by Olli Etuaho Committed by Commit Bot

Fix formatting of OutputHLSL::visitAggregate

Subsequent refactoring of this code will be easier to review if there won't be unrelated style changes that git cl format insists on doing. BUG=angleproject:1490 TEST=angle_unittests Change-Id: I102fd73bd92317ab438e1676422212f644d2859b Reviewed-on: https://chromium-review.googlesource.com/394649Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent b7fe49db
...@@ -1424,7 +1424,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1424,7 +1424,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
switch (node->getOp()) switch (node->getOp())
{ {
case EOpSequence: case EOpSequence:
{ {
if (mInsideFunction) if (mInsideFunction)
{ {
...@@ -1456,125 +1456,132 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1456,125 +1456,132 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
return false; return false;
} }
case EOpDeclaration: case EOpDeclaration:
if (visit == PreVisit) if (visit == PreVisit)
{
TIntermSequence *sequence = node->getSequence();
TIntermTyped *variable = (*sequence)[0]->getAsTyped();
ASSERT(sequence->size() == 1);
if (variable &&
(variable->getQualifier() == EvqTemporary ||
variable->getQualifier() == EvqGlobal || variable->getQualifier() == EvqConst))
{ {
ensureStructDefined(variable->getType()); TIntermSequence *sequence = node->getSequence();
TIntermTyped *variable = (*sequence)[0]->getAsTyped();
ASSERT(sequence->size() == 1);
if (!variable->getAsSymbolNode() || variable->getAsSymbolNode()->getSymbol() != "") // Variable declaration if (variable &&
(variable->getQualifier() == EvqTemporary ||
variable->getQualifier() == EvqGlobal || variable->getQualifier() == EvqConst))
{ {
if (!mInsideFunction) ensureStructDefined(variable->getType());
if (!variable->getAsSymbolNode() ||
variable->getAsSymbolNode()->getSymbol() != "") // Variable declaration
{ {
out << "static "; if (!mInsideFunction)
} {
out << "static ";
}
out << TypeString(variable->getType()) + " "; out << TypeString(variable->getType()) + " ";
TIntermSymbol *symbol = variable->getAsSymbolNode(); TIntermSymbol *symbol = variable->getAsSymbolNode();
if (symbol) if (symbol)
{ {
symbol->traverse(this); symbol->traverse(this);
out << ArrayString(symbol->getType()); out << ArrayString(symbol->getType());
out << " = " + initializer(symbol->getType()); out << " = " + initializer(symbol->getType());
}
else
{
variable->traverse(this);
}
} }
else else if (variable->getAsSymbolNode() &&
variable->getAsSymbolNode()->getSymbol() ==
"") // Type (struct) declaration
{ {
variable->traverse(this); // Already added to constructor map
} }
else
UNREACHABLE();
} }
else if (variable->getAsSymbolNode() && variable->getAsSymbolNode()->getSymbol() == "") // Type (struct) declaration else if (variable && IsVaryingOut(variable->getQualifier()))
{
// Already added to constructor map
}
else UNREACHABLE();
}
else if (variable && IsVaryingOut(variable->getQualifier()))
{
for (TIntermSequence::iterator sit = sequence->begin(); sit != sequence->end(); sit++)
{ {
TIntermSymbol *symbol = (*sit)->getAsSymbolNode(); for (TIntermSequence::iterator sit = sequence->begin(); sit != sequence->end();
sit++)
if (symbol)
{ {
// Vertex (output) varyings which are declared but not written to should still be declared to allow successful linking TIntermSymbol *symbol = (*sit)->getAsSymbolNode();
mReferencedVaryings[symbol->getSymbol()] = symbol;
} if (symbol)
else {
{ // Vertex (output) varyings which are declared but not written to should
(*sit)->traverse(this); // still be declared to allow successful linking
mReferencedVaryings[symbol->getSymbol()] = symbol;
}
else
{
(*sit)->traverse(this);
}
} }
} }
}
return false;
}
else if (visit == InVisit)
{
out << ", ";
}
break;
case EOpInvariantDeclaration:
// Do not do any translation
return false;
case EOpPrototype:
if (visit == PreVisit)
{
size_t index = mCallDag.findIndex(node);
// Skip the prototype if it is not implemented (and thus not used)
if (index == CallDAG::InvalidIndex)
{
return false; return false;
} }
else if (visit == InVisit)
{
out << ", ";
}
break;
case EOpInvariantDeclaration:
// Do not do any translation
return false;
case EOpPrototype:
if (visit == PreVisit)
{
size_t index = mCallDag.findIndex(node);
// Skip the prototype if it is not implemented (and thus not used)
if (index == CallDAG::InvalidIndex)
{
return false;
}
TIntermSequence *arguments = node->getSequence(); TIntermSequence *arguments = node->getSequence();
TString name = DecorateFunctionIfNeeded(node->getNameObj());
out << TypeString(node->getType()) << " " << name << DisambiguateFunctionName(arguments)
<< (mOutputLod0Function ? "Lod0(" : "(");
for (unsigned int i = 0; i < arguments->size(); i++) TString name = DecorateFunctionIfNeeded(node->getNameObj());
{ out << TypeString(node->getType()) << " " << name
TIntermSymbol *symbol = (*arguments)[i]->getAsSymbolNode(); << DisambiguateFunctionName(arguments) << (mOutputLod0Function ? "Lod0(" : "(");
if (symbol) for (unsigned int i = 0; i < arguments->size(); i++)
{ {
out << argumentString(symbol); TIntermSymbol *symbol = (*arguments)[i]->getAsSymbolNode();
if (i < arguments->size() - 1) if (symbol)
{ {
out << ", "; out << argumentString(symbol);
if (i < arguments->size() - 1)
{
out << ", ";
}
} }
else
UNREACHABLE();
} }
else UNREACHABLE();
}
out << ");\n"; out << ");\n";
// Also prototype the Lod0 variant if needed // Also prototype the Lod0 variant if needed
bool needsLod0 = mASTMetadataList[index].mNeedsLod0; bool needsLod0 = mASTMetadataList[index].mNeedsLod0;
if (needsLod0 && !mOutputLod0Function && mShaderType == GL_FRAGMENT_SHADER) if (needsLod0 && !mOutputLod0Function && mShaderType == GL_FRAGMENT_SHADER)
{ {
mOutputLod0Function = true; mOutputLod0Function = true;
node->traverse(this); node->traverse(this);
mOutputLod0Function = false; mOutputLod0Function = false;
} }
return false; return false;
} }
break; break;
case EOpComma: case EOpComma:
outputTriplet(out, visit, "(", ", ", ")"); outputTriplet(out, visit, "(", ", ", ")");
break; break;
case EOpFunction: case EOpFunction:
{ {
ASSERT(mCurrentFunctionMetadata == nullptr); ASSERT(mCurrentFunctionMetadata == nullptr);
TString name = TFunction::unmangleName(node->getNameObj().getString()); TString name = TFunction::unmangleName(node->getNameObj().getString());
...@@ -1639,8 +1646,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1639,8 +1646,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
return false; return false;
} }
break; case EOpFunctionCall:
case EOpFunctionCall:
{ {
TIntermSequence *arguments = node->getSequence(); TIntermSequence *arguments = node->getSequence();
...@@ -1721,7 +1727,6 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1721,7 +1727,6 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
return false; return false;
} }
break;
case EOpParameters: case EOpParameters:
outputTriplet(out, visit, "(", ", ", ")\n{\n"); outputTriplet(out, visit, "(", ", ", ")\n{\n");
break; break;
...@@ -1800,7 +1805,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1800,7 +1805,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpConstructMat4: case EOpConstructMat4:
outputConstructor(out, visit, node->getType(), "mat4", node->getSequence()); outputConstructor(out, visit, node->getType(), "mat4", node->getSequence());
break; break;
case EOpConstructStruct: case EOpConstructStruct:
{ {
if (node->getType().isArray()) if (node->getType().isArray())
{ {
...@@ -1829,31 +1834,31 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1829,31 +1834,31 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpVectorNotEqual: case EOpVectorNotEqual:
outputTriplet(out, visit, "(", " != ", ")"); outputTriplet(out, visit, "(", " != ", ")");
break; break;
case EOpMod: case EOpMod:
ASSERT(node->getUseEmulatedFunction()); ASSERT(node->getUseEmulatedFunction());
writeEmulatedFunctionTriplet(out, visit, "mod("); writeEmulatedFunctionTriplet(out, visit, "mod(");
break; break;
case EOpModf: case EOpModf:
outputTriplet(out, visit, "modf(", ", ", ")"); outputTriplet(out, visit, "modf(", ", ", ")");
break; break;
case EOpPow: case EOpPow:
outputTriplet(out, visit, "pow(", ", ", ")"); outputTriplet(out, visit, "pow(", ", ", ")");
break; break;
case EOpAtan: case EOpAtan:
ASSERT(node->getSequence()->size() == 2); // atan(x) is a unary operator ASSERT(node->getSequence()->size() == 2); // atan(x) is a unary operator
ASSERT(node->getUseEmulatedFunction()); ASSERT(node->getUseEmulatedFunction());
writeEmulatedFunctionTriplet(out, visit, "atan("); writeEmulatedFunctionTriplet(out, visit, "atan(");
break; break;
case EOpMin: case EOpMin:
outputTriplet(out, visit, "min(", ", ", ")"); outputTriplet(out, visit, "min(", ", ", ")");
break; break;
case EOpMax: case EOpMax:
outputTriplet(out, visit, "max(", ", ", ")"); outputTriplet(out, visit, "max(", ", ", ")");
break; break;
case EOpClamp: case EOpClamp:
outputTriplet(out, visit, "clamp(", ", ", ")"); outputTriplet(out, visit, "clamp(", ", ", ")");
break; break;
case EOpMix: case EOpMix:
{ {
TIntermTyped *lastParamNode = (*(node->getSequence()))[2]->getAsTyped(); TIntermTyped *lastParamNode = (*(node->getSequence()))[2]->getAsTyped();
if (lastParamNode->getType().getBasicType() == EbtBool) if (lastParamNode->getType().getBasicType() == EbtBool)
...@@ -1867,8 +1872,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1867,8 +1872,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{ {
outputTriplet(out, visit, "lerp(", ", ", ")"); outputTriplet(out, visit, "lerp(", ", ", ")");
} }
break;
} }
break;
case EOpStep: case EOpStep:
outputTriplet(out, visit, "step(", ", ", ")"); outputTriplet(out, visit, "step(", ", ", ")");
break; break;
...@@ -1884,24 +1889,25 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1884,24 +1889,25 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpCross: case EOpCross:
outputTriplet(out, visit, "cross(", ", ", ")"); outputTriplet(out, visit, "cross(", ", ", ")");
break; break;
case EOpFaceForward: case EOpFaceForward:
ASSERT(node->getUseEmulatedFunction()); ASSERT(node->getUseEmulatedFunction());
writeEmulatedFunctionTriplet(out, visit, "faceforward("); writeEmulatedFunctionTriplet(out, visit, "faceforward(");
break; break;
case EOpReflect: case EOpReflect:
outputTriplet(out, visit, "reflect(", ", ", ")"); outputTriplet(out, visit, "reflect(", ", ", ")");
break; break;
case EOpRefract: case EOpRefract:
outputTriplet(out, visit, "refract(", ", ", ")"); outputTriplet(out, visit, "refract(", ", ", ")");
break; break;
case EOpOuterProduct: case EOpOuterProduct:
ASSERT(node->getUseEmulatedFunction()); ASSERT(node->getUseEmulatedFunction());
writeEmulatedFunctionTriplet(out, visit, "outerProduct("); writeEmulatedFunctionTriplet(out, visit, "outerProduct(");
break; break;
case EOpMul: case EOpMul:
outputTriplet(out, visit, "(", " * ", ")"); outputTriplet(out, visit, "(", " * ", ")");
break; break;
default: UNREACHABLE(); default:
UNREACHABLE();
} }
return true; return true;
......
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