Commit 0c6bb7a6 by zmo@google.com

Add an compile option to unroll for-loops with integer indices.

ANGLEBUG=193 TEST=with this option, for-loops with integer indices will be unrolled. Review URL: http://codereview.appspot.com/4899047 git-svn-id: https://angleproject.googlecode.com/svn/trunk@734 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent c23ff643
...@@ -81,7 +81,8 @@ typedef enum { ...@@ -81,7 +81,8 @@ typedef enum {
SH_ATTRIBUTES_UNIFORMS = 0x0008, SH_ATTRIBUTES_UNIFORMS = 0x0008,
SH_LINE_DIRECTIVES = 0x0010, SH_LINE_DIRECTIVES = 0x0010,
SH_SOURCE_PATH = 0x0020, SH_SOURCE_PATH = 0x0020,
SH_MAP_LONG_VARIABLE_NAMES = 0x0040 SH_MAP_LONG_VARIABLE_NAMES = 0x0040,
SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX = 0x0080
} ShCompileOptions; } ShCompileOptions;
// //
......
...@@ -83,6 +83,7 @@ int main(int argc, char* argv[]) ...@@ -83,6 +83,7 @@ int main(int argc, char* argv[])
case 'm': compileOptions |= SH_MAP_LONG_VARIABLE_NAMES; break; case 'm': compileOptions |= SH_MAP_LONG_VARIABLE_NAMES; break;
case 'o': compileOptions |= SH_OBJECT_CODE; break; case 'o': compileOptions |= SH_OBJECT_CODE; break;
case 'u': compileOptions |= SH_ATTRIBUTES_UNIFORMS; break; case 'u': compileOptions |= SH_ATTRIBUTES_UNIFORMS; break;
case 'l': compileOptions |= SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX; break;
case 'b': case 'b':
if (argv[0][2] == '=') { if (argv[0][2] == '=') {
switch (argv[0][3]) { switch (argv[0][3]) {
...@@ -176,12 +177,13 @@ int main(int argc, char* argv[]) ...@@ -176,12 +177,13 @@ int main(int argc, char* argv[])
// //
void usage() void usage()
{ {
printf("Usage: translate [-i -m -o -u -b=e -b=g -b=h -a] file1 file2 ...\n" printf("Usage: translate [-i -m -o -u -l -b=e -b=g -b=h -a] file1 file2 ...\n"
"Where: filename : filename ending in .frag or .vert\n" "Where: filename : filename ending in .frag or .vert\n"
" -i : print intermediate tree\n" " -i : print intermediate tree\n"
" -m : map long variable names\n" " -m : map long variable names\n"
" -o : print translated code\n" " -o : print translated code\n"
" -u : print active attribs and uniforms\n" " -u : print active attribs and uniforms\n"
" -l : unroll for-loops with integer indices\n"
" -b=e : output GLSL ES code (this is by default)\n" " -b=e : output GLSL ES code (this is by default)\n"
" -b=g : output GLSL code\n" " -b=g : output GLSL code\n"
" -b=h : output HLSL code\n" " -b=h : output HLSL code\n"
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
'compiler/debug.h', 'compiler/debug.h',
'compiler/DetectRecursion.cpp', 'compiler/DetectRecursion.cpp',
'compiler/DetectRecursion.h', 'compiler/DetectRecursion.h',
'compiler/ForLoopUnroll.cpp',
'compiler/ForLoopUnroll.h',
'compiler/glslang.h', 'compiler/glslang.h',
'compiler/glslang_lex.cpp', 'compiler/glslang_lex.cpp',
'compiler/glslang_tab.cpp', 'compiler/glslang_tab.cpp',
...@@ -103,8 +105,6 @@ ...@@ -103,8 +105,6 @@
], ],
'sources': [ 'sources': [
'compiler/CodeGenGLSL.cpp', 'compiler/CodeGenGLSL.cpp',
'compiler/ForLoopUnroll.cpp',
'compiler/ForLoopUnroll.h',
'compiler/OutputESSL.cpp', 'compiler/OutputESSL.cpp',
'compiler/OutputESSL.h', 'compiler/OutputESSL.h',
'compiler/OutputGLSLBase.cpp', 'compiler/OutputGLSLBase.cpp',
......
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 733 #define BUILD_REVISION 734
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// //
#include "compiler/DetectRecursion.h" #include "compiler/DetectRecursion.h"
#include "compiler/ForLoopUnroll.h"
#include "compiler/Initialize.h" #include "compiler/Initialize.h"
#include "compiler/ParseHelper.h" #include "compiler/ParseHelper.h"
#include "compiler/ShHandle.h" #include "compiler/ShHandle.h"
...@@ -155,6 +156,10 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -155,6 +156,10 @@ bool TCompiler::compile(const char* const shaderStrings[],
if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING)) if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING))
success = validateLimitations(root); success = validateLimitations(root);
// Unroll for-loop markup needs to happen after validateLimitations pass.
if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX))
ForLoopUnroll::MarkForLoopsWithIntegerIndicesForUnrolling(root);
// Call mapLongVariableNames() before collectAttribsUniforms() so in // Call mapLongVariableNames() before collectAttribsUniforms() so in
// collectAttribsUniforms() we already have the mapped symbol names and // collectAttribsUniforms() we already have the mapped symbol names and
// we could composite mapped and original variable names. // we could composite mapped and original variable names.
......
...@@ -6,6 +6,39 @@ ...@@ -6,6 +6,39 @@
#include "compiler/ForLoopUnroll.h" #include "compiler/ForLoopUnroll.h"
namespace {
class IntegerForLoopUnrollMarker : public TIntermTraverser {
public:
virtual bool visitLoop(Visit, TIntermLoop* node)
{
// This is called after ValidateLimitations pass, so all the ASSERT
// should never fail.
// See ValidateLimitations::validateForLoopInit().
ASSERT(node);
ASSERT(node->getType() == ELoopFor);
ASSERT(node->getInit());
TIntermAggregate* decl = node->getInit()->getAsAggregate();
ASSERT(decl && decl->getOp() == EOpDeclaration);
TIntermSequence& declSeq = decl->getSequence();
ASSERT(declSeq.size() == 1);
TIntermBinary* declInit = declSeq[0]->getAsBinaryNode();
ASSERT(declInit && declInit->getOp() == EOpInitialize);
ASSERT(declInit->getLeft());
TIntermSymbol* symbol = declInit->getLeft()->getAsSymbolNode();
ASSERT(symbol);
TBasicType type = symbol->getBasicType();
ASSERT(type == EbtInt || type == EbtFloat);
if (type == EbtInt)
node->setUnrollFlag(true);
return true;
}
};
} // anonymous namepsace
void ForLoopUnroll::FillLoopIndexInfo(TIntermLoop* node, TLoopIndexInfo& info) void ForLoopUnroll::FillLoopIndexInfo(TIntermLoop* node, TLoopIndexInfo& info)
{ {
ASSERT(node->getType() == ELoopFor); ASSERT(node->getType() == ELoopFor);
...@@ -109,6 +142,16 @@ void ForLoopUnroll::Pop() ...@@ -109,6 +142,16 @@ void ForLoopUnroll::Pop()
mLoopIndexStack.pop_back(); mLoopIndexStack.pop_back();
} }
// static
void ForLoopUnroll::MarkForLoopsWithIntegerIndicesForUnrolling(
TIntermNode* root)
{
ASSERT(root);
IntegerForLoopUnrollMarker marker;
root->traverse(&marker);
}
int ForLoopUnroll::getLoopIncrement(TIntermLoop* node) int ForLoopUnroll::getLoopIncrement(TIntermLoop* node)
{ {
TIntermNode* expr = node->getExpression(); TIntermNode* expr = node->getExpression();
......
...@@ -36,6 +36,8 @@ public: ...@@ -36,6 +36,8 @@ public:
void Push(TLoopIndexInfo& info); void Push(TLoopIndexInfo& info);
void Pop(); void Pop();
static void MarkForLoopsWithIntegerIndicesForUnrolling(TIntermNode* root);
private: private:
int getLoopIncrement(TIntermLoop* node); int getLoopIncrement(TIntermLoop* node);
......
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