Adjust the maximum loop iterations to keep the HLSL compiler happy

Trac #20913 Signed-off-by: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@1117 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 92d620c3
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 1116 #define BUILD_REVISION 1117
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -1769,9 +1769,11 @@ bool OutputHLSL::isSingleStatement(TIntermNode *node) ...@@ -1769,9 +1769,11 @@ bool OutputHLSL::isSingleStatement(TIntermNode *node)
return true; return true;
} }
// Handle loops with more than 255 iterations (unsupported by D3D9) by splitting them // Handle loops with more than 254 iterations (unsupported by D3D9) by splitting them
// (The D3D documentation says 255 iterations, but the compiler complains at anything more than 254).
bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node)
{ {
const int MAX_LOOP_ITERATIONS = 254;
TInfoSinkBase &out = mBody; TInfoSinkBase &out = mBody;
// Parse loops of the form: // Parse loops of the form:
...@@ -1887,14 +1889,14 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) ...@@ -1887,14 +1889,14 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node)
{ {
int iterations = (limit - initial) / increment; int iterations = (limit - initial) / increment;
if (iterations <= 255) if (iterations <= MAX_LOOP_ITERATIONS)
{ {
return false; // Not an excessive loop return false; // Not an excessive loop
} }
while (iterations > 0) while (iterations > 0)
{ {
int clampedLimit = initial + increment * std::min(255, iterations); int clampedLimit = initial + increment * std::min(MAX_LOOP_ITERATIONS, iterations);
// for(int index = initial; index < clampedLimit; index += increment) // for(int index = initial; index < clampedLimit; index += increment)
...@@ -1925,8 +1927,8 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) ...@@ -1925,8 +1927,8 @@ bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node)
outputLineDirective(node->getLine()); outputLineDirective(node->getLine());
out << ";}\n"; out << ";}\n";
initial += 255 * increment; initial += MAX_LOOP_ITERATIONS * increment;
iterations -= 255; iterations -= MAX_LOOP_ITERATIONS;
} }
return true; return true;
......
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