Edit

kc3-lang/angle/src/compiler/ForLoopUnroll.h

Branch :

  • Show log

    Commit

  • Author : zmo@google.com
    Date : 2011-04-04 19:17:11
    Hash : 0b8d4eb2
    Message : Unroll for-loop if sampler array uses loop index as its index. If inside a for-loop, sampler array index is the loop index, Mac cg compiler will crash. This CL unroll the loop in such situation. The behavior is: 1) If the for-loop index is a float, we reject the shader. 2) If it is an integer, we unroll the for-loop. Things that should be done in the future are: 1) Add line number macros. 2) Add a limit to unroll iteration count. anglebug=94 Review URL: http://codereview.appspot.com/4331048 git-svn-id: https://angleproject.googlecode.com/svn/trunk@606 736b8ea6-26fd-11df-bfd4-992fa37f6226

  • src/compiler/ForLoopUnroll.h
  • //
    // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    #include "compiler/intermediate.h"
    
    struct TLoopIndexInfo {
        int id;
        int initValue;
        int stopValue;
        int incrementValue;
        TOperator op;
        int currentValue;
    };
    
    class ForLoopUnroll {
    public:
        ForLoopUnroll() { }
    
        void FillLoopIndexInfo(TIntermLoop* node, TLoopIndexInfo& info);
    
        // Update the info.currentValue for the next loop iteration.
        void Step();
    
        // Return false if loop condition is no longer satisfied.
        bool SatisfiesLoopCondition();
    
        // Check if the symbol is the index of a loop that's unrolled.
        bool NeedsToReplaceSymbolWithValue(TIntermSymbol* symbol);
    
        // Return the current value of a given loop index symbol.
        int GetLoopIndexValue(TIntermSymbol* symbol);
    
        void Push(TLoopIndexInfo& info);
        void Pop();
    
    private:
        int getLoopIncrement(TIntermLoop* node);
    
        int evaluateIntConstant(TIntermConstantUnion* node);
    
        TVector<TLoopIndexInfo> mLoopIndexStack;
    };