Improvement on loop unrolling with loops indexing sampler arrays
1) Before this workaround is hardwired on mac, now we move it behind a compil
2) Fix the issue where "break" inside the loop isn't handled while unrolled.
BUG=338474
TEST=webgl conformance test sampler-array-using-loop-index.html
Change-Id: I4996a42c2dea39a8a5af772c256f8e3cb383f59a
Reviewed-on: https://chromium-review.googlesource.com/188079
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Zhenyao Mo <zmo@chromium.org>
Conflicts:
include/GLSLANG/ShaderLang.h
src/compiler/translator/ValidateLimitations.cpp
Change-Id: I546197bd7df1634ebccdd380be14c3250cd56151
Reviewed-on: https://chromium-review.googlesource.com/189061
Reviewed-by: Shannon Woods <shannonwoods@chromium.org>
Tested-by: Zhenyao Mo <zmo@chromium.org>
diff --git a/src/compiler/translator/OutputGLSLBase.cpp b/src/compiler/translator/OutputGLSLBase.cpp
index e51bd12..816850e 100644
--- a/src/compiler/translator/OutputGLSLBase.cpp
+++ b/src/compiler/translator/OutputGLSLBase.cpp
@@ -161,8 +161,8 @@
void TOutputGLSLBase::visitSymbol(TIntermSymbol* node)
{
TInfoSinkBase& out = objSink();
- if (mLoopUnroll.NeedsToReplaceSymbolWithValue(node))
- out << mLoopUnroll.GetLoopIndexValue(node);
+ if (mLoopUnrollStack.needsToReplaceSymbolWithValue(node))
+ out << mLoopUnrollStack.getLoopIndexValue(node);
else
out << hashVariableName(node->getSymbol());
@@ -645,7 +645,8 @@
TLoopType loopType = node->getType();
if (loopType == ELoopFor) // for loop
{
- if (!node->getUnrollFlag()) {
+ if (!node->getUnrollFlag())
+ {
out << "for (";
if (node->getInit())
node->getInit()->traverse(this);
@@ -659,6 +660,18 @@
node->getExpression()->traverse(this);
out << ")\n";
}
+ else
+ {
+ // Need to put a one-iteration loop here to handle break.
+ TIntermSequence &declSeq =
+ node->getInit()->getAsAggregate()->getSequence();
+ TIntermSymbol *indexSymbol =
+ declSeq[0]->getAsBinaryNode()->getLeft()->getAsSymbolNode();
+ TString name = hashVariableName(indexSymbol->getSymbol());
+ out << "for (int " << name << " = 0; "
+ << name << " < 1; "
+ << "++" << name << ")\n";
+ }
}
else if (loopType == ELoopWhile) // while loop
{
@@ -676,15 +689,15 @@
// Loop body.
if (node->getUnrollFlag())
{
- TLoopIndexInfo indexInfo;
- mLoopUnroll.FillLoopIndexInfo(node, indexInfo);
- mLoopUnroll.Push(indexInfo);
- while (mLoopUnroll.SatisfiesLoopCondition())
+ out << "{\n";
+ mLoopUnrollStack.push(node);
+ while (mLoopUnrollStack.satisfiesLoopCondition())
{
visitCodeBlock(node->getBody());
- mLoopUnroll.Step();
+ mLoopUnrollStack.step();
}
- mLoopUnroll.Pop();
+ mLoopUnrollStack.pop();
+ out << "}\n";
}
else
{