Use attributes to avoid unrolling and flatten conditionals.
[loop] and [flatten] help avoid unrolling make more shaders compile
successfully. When unrolling has to happen, an error X3531 is generated
so we have to try compiling again without these attributes.
BUG=395048,395286
Change-Id: I91ea8ac3a822ab1f1ac24907d42326e3c6c9d9af
Reviewed-on: https://chromium-review.googlesource.com/222810
Tested-by: Nicolas Capens <capn@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index bded1fa..277bea4 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -320,14 +320,22 @@
if (mUsesDiscardRewriting)
{
- out << "#define ANGLE_USES_DISCARD_REWRITING" << "\n";
+ out << "#define ANGLE_USES_DISCARD_REWRITING\n";
}
if (mUsesNestedBreak)
{
- out << "#define ANGLE_USES_NESTED_BREAK" << "\n";
+ out << "#define ANGLE_USES_NESTED_BREAK\n";
}
+ out << "#ifdef ANGLE_ENABLE_LOOP_FLATTEN\n"
+ "#define LOOP [loop]\n"
+ "#define FLATTEN [flatten]\n"
+ "#else\n"
+ "#define LOOP\n"
+ "#define FLATTEN\n"
+ "#endif\n";
+
if (mContext.shaderType == GL_FRAGMENT_SHADER)
{
TExtensionBehavior::const_iterator iter = mContext.extensionBehavior().find("GL_EXT_draw_buffers");
@@ -2293,7 +2301,7 @@
{
mUnfoldShortCircuit->traverse(node->getCondition());
- out << "if (";
+ out << "FLATTEN if (";
node->getCondition()->traverse(this);
@@ -2373,14 +2381,14 @@
if (node->getType() == ELoopDoWhile)
{
- out << "{do\n";
+ out << "{LOOP do\n";
outputLineDirective(node->getLine().first_line);
out << "{\n";
}
else
{
- out << "{for(";
+ out << "{LOOP for(";
if (node->getInit())
{
@@ -2687,7 +2695,7 @@
// for(int index = initial; index < clampedLimit; index += increment)
- out << "for(";
+ out << "LOOP for(";
index->traverse(this);
out << " = ";
out << initial;