Commit 7258e30c by Corentin Wallez

TOutputGLSLBase::visitLoop clarify the function slightly

Since only for loops can be unrolled, handle each type of loop only once. This improvement was going to be part of a do-while workaround for Mac that will instead be done at the AST level. BUG=angleproject:891 Change-Id: Ic8ecf41aa6d9abd7a01c2230e908c85152f52b62 Reviewed-on: https://chromium-review.googlesource.com/302332 Tryjob-Request: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 947908f1
...@@ -1075,8 +1075,12 @@ bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node) ...@@ -1075,8 +1075,12 @@ bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node)
TInfoSinkBase &out = objSink(); TInfoSinkBase &out = objSink();
incrementDepth(node); incrementDepth(node);
// Loop header.
TLoopType loopType = node->getType(); TLoopType loopType = node->getType();
// Only for loops can be unrolled
ASSERT(!node->getUnrollFlag() || loopType == ELoopFor);
if (loopType == ELoopFor) // for loop if (loopType == ELoopFor) // for loop
{ {
if (!node->getUnrollFlag()) if (!node->getUnrollFlag())
...@@ -1093,6 +1097,8 @@ bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node) ...@@ -1093,6 +1097,8 @@ bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node)
if (node->getExpression()) if (node->getExpression())
node->getExpression()->traverse(this); node->getExpression()->traverse(this);
out << ")\n"; out << ")\n";
visitCodeBlock(node->getBody());
} }
else else
{ {
...@@ -1105,6 +1111,16 @@ bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node) ...@@ -1105,6 +1111,16 @@ bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node)
out << "for (int " << name << " = 0; " out << "for (int " << name << " = 0; "
<< name << " < 1; " << name << " < 1; "
<< "++" << name << ")\n"; << "++" << name << ")\n";
out << "{\n";
mLoopUnrollStack.push(node);
while (mLoopUnrollStack.satisfiesLoopCondition())
{
visitCodeBlock(node->getBody());
mLoopUnrollStack.step();
}
mLoopUnrollStack.pop();
out << "}\n";
} }
} }
else if (loopType == ELoopWhile) // while loop else if (loopType == ELoopWhile) // while loop
...@@ -1113,39 +1129,22 @@ bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node) ...@@ -1113,39 +1129,22 @@ bool TOutputGLSLBase::visitLoop(Visit visit, TIntermLoop *node)
ASSERT(node->getCondition() != NULL); ASSERT(node->getCondition() != NULL);
node->getCondition()->traverse(this); node->getCondition()->traverse(this);
out << ")\n"; out << ")\n";
visitCodeBlock(node->getBody());
} }
else // do-while loop else // do-while loop
{ {
ASSERT(loopType == ELoopDoWhile); ASSERT(loopType == ELoopDoWhile);
out << "do\n"; out << "do\n";
}
// Loop body.
if (node->getUnrollFlag())
{
out << "{\n";
mLoopUnrollStack.push(node);
while (mLoopUnrollStack.satisfiesLoopCondition())
{
visitCodeBlock(node->getBody());
mLoopUnrollStack.step();
}
mLoopUnrollStack.pop();
out << "}\n";
}
else
{
visitCodeBlock(node->getBody()); visitCodeBlock(node->getBody());
}
// Loop footer.
if (loopType == ELoopDoWhile) // do-while loop
{
out << "while ("; out << "while (";
ASSERT(node->getCondition() != NULL); ASSERT(node->getCondition() != NULL);
node->getCondition()->traverse(this); node->getCondition()->traverse(this);
out << ");\n"; out << ");\n";
} }
decrementDepth(); decrementDepth();
// No need to visit children. They have been already processed in // No need to visit children. They have been already processed in
......
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