1 // 2 // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #ifndef COMPILER_FORLOOPUNROLL_H_ 8 #define COMPILER_FORLOOPUNROLL_H_ 9 10 #include "compiler/translator/LoopInfo.h" 11 12 // This class detects for-loops that needs to be unrolled. 13 // Currently we support two unroll conditions: 14 // 1) kForLoopWithIntegerIndex: unroll if the index type is integer. 15 // 2) kForLoopWithSamplerArrayIndex: unroll where a sampler array index 16 // is also the loop integer index, and reject and fail a compile 17 // where a sampler array index is also the loop float index. 18 class ForLoopUnrollMarker : public TIntermTraverser 19 { 20 public: 21 enum UnrollCondition 22 { 23 kIntegerIndex, 24 kSamplerArrayIndex 25 }; 26 27 ForLoopUnrollMarker(UnrollCondition condition) 28 : mUnrollCondition(condition), 29 mSamplerArrayIndexIsFloatLoopIndex(false), 30 mVisitSamplerArrayIndexNodeInsideLoop(false) 31 { 32 } 33 34 virtual bool visitBinary(Visit, TIntermBinary *node); 35 virtual bool visitLoop(Visit, TIntermLoop *node); 36 virtual void visitSymbol(TIntermSymbol *node); 37 38 bool samplerArrayIndexIsFloatLoopIndex() const 39 { 40 return mSamplerArrayIndexIsFloatLoopIndex; 41 } 42 43 private: 44 UnrollCondition mUnrollCondition; 45 TLoopStack mLoopStack; 46 bool mSamplerArrayIndexIsFloatLoopIndex; 47 bool mVisitSamplerArrayIndexNodeInsideLoop; 48 }; 49 50 #endif 51