Commit 05ae50dc by Olli Etuaho

Add basic support for HLSL output of switch and case

This patch outputs switch and case statements in HLSL, but ignores fall-through. Switch statements that include fall-through cause the platform HLSL compiler to generate errors. BUG=angle:921 Change-Id: I10efbfb45076cf4fd79840698abafd8111e597d4 Reviewed-on: https://chromium-review.googlesource.com/251527Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent 01cd8afa
...@@ -1778,7 +1778,11 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1778,7 +1778,11 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
traverseStatements(*sit); traverseStatements(*sit);
out << ";\n"; // Don't output ; after case labels, they're terminated by :
// This is needed especially since outputting a ; after a case statement would turn empty
// case statements into non-empty case statements, disallowing fall-through from them.
if ((*sit)->getAsCaseNode() == nullptr)
out << ";\n";
} }
if (mInsideFunction) if (mInsideFunction)
...@@ -2268,16 +2272,34 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node) ...@@ -2268,16 +2272,34 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
return false; return false;
} }
bool OutputHLSL::visitSwitch(Visit, TIntermSwitch *) bool OutputHLSL::visitSwitch(Visit visit, TIntermSwitch *node)
{ {
UNIMPLEMENTED(); if (node->getStatementList())
return false; {
outputTriplet(visit, "switch (", ") ", "");
// The curly braces get written when visiting the statementList aggregate
}
else
{
// No statementList, so it won't output curly braces
outputTriplet(visit, "switch (", ") {", "}\n");
}
return true;
} }
bool OutputHLSL::visitCase(Visit, TIntermCase *) bool OutputHLSL::visitCase(Visit visit, TIntermCase *node)
{ {
UNIMPLEMENTED(); if (node->hasCondition())
return false; {
outputTriplet(visit, "case (", "", "):\n");
return true;
}
else
{
TInfoSinkBase &out = getInfoSink();
out << "default:\n";
return false;
}
} }
void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node) void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
......
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