Use shader optimization level 3 selectively.
Default to HLSL compiler optimization level 1 and work around a compiler bug with break in nested loops by using optimization level 3.
BUG=angle:603
Change-Id: I4f7985a5648f1b5f54d80554c21aced7fc1777c2
Reviewed-on: https://chromium-review.googlesource.com/194129
Tested-by: Nicolas Capens <nicolascapens@chromium.org>
Reviewed-by: Shannon Woods <shannonwoods@chromium.org>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index 1b0dce1..d3d064b 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -121,6 +121,7 @@
mUsesAtan2_3 = false;
mUsesAtan2_4 = false;
mUsesDiscardRewriting = false;
+ mUsesNestedBreak = false;
mNumRenderTargets = resources.EXT_draw_buffers ? resources.MaxDrawBuffers : 1;
@@ -131,6 +132,7 @@
mContainsLoopDiscontinuity = false;
mOutputLod0Function = false;
mInsideDiscontinuousLoop = false;
+ mNestedLoopDepth = 0;
mExcessiveLoopIndex = NULL;
@@ -675,6 +677,11 @@
out << "#define ANGLE_USES_DISCARD_REWRITING" << "\n";
}
+ if (mUsesNestedBreak)
+ {
+ out << "#define ANGLE_USES_NESTED_BREAK" << "\n";
+ }
+
if (mContext.shaderType == SH_FRAGMENT_SHADER)
{
TExtensionBehavior::const_iterator iter = mContext.extensionBehavior().find("GL_EXT_draw_buffers");
@@ -2797,6 +2804,8 @@
bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node)
{
+ mNestedLoopDepth++;
+
bool wasDiscontinuous = mInsideDiscontinuousLoop;
if (mContainsLoopDiscontinuity && !mInsideDiscontinuousLoop)
@@ -2808,6 +2817,9 @@
{
if (handleExcessiveLoop(node))
{
+ mInsideDiscontinuousLoop = wasDiscontinuous;
+ mNestedLoopDepth--;
+
return false;
}
}
@@ -2871,6 +2883,7 @@
out << "}\n";
mInsideDiscontinuousLoop = wasDiscontinuous;
+ mNestedLoopDepth--;
return false;
}
@@ -2887,6 +2900,11 @@
case EOpBreak:
if (visit == PreVisit)
{
+ if (mNestedLoopDepth > 1)
+ {
+ mUsesNestedBreak = true;
+ }
+
if (mExcessiveLoopIndex)
{
out << "{Break";