gfx/angle/src/compiler/OutputHLSL.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/compiler/OutputHLSL.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,166 @@
     1.4 +//
     1.5 +// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
     1.6 +// Use of this source code is governed by a BSD-style license that can be
     1.7 +// found in the LICENSE file.
     1.8 +//
     1.9 +
    1.10 +#ifndef COMPILER_OUTPUTHLSL_H_
    1.11 +#define COMPILER_OUTPUTHLSL_H_
    1.12 +
    1.13 +#include <list>
    1.14 +#include <set>
    1.15 +#include <map>
    1.16 +
    1.17 +#define GL_APICALL
    1.18 +#include <GLES2/gl2.h>
    1.19 +
    1.20 +#include "compiler/intermediate.h"
    1.21 +#include "compiler/ParseHelper.h"
    1.22 +#include "compiler/CompilerUniform.h"
    1.23 +
    1.24 +namespace sh
    1.25 +{
    1.26 +class UnfoldShortCircuit;
    1.27 +
    1.28 +class OutputHLSL : public TIntermTraverser
    1.29 +{
    1.30 +  public:
    1.31 +    OutputHLSL(TParseContext &context, const ShBuiltInResources& resources, ShShaderOutput outputType);
    1.32 +    ~OutputHLSL();
    1.33 +
    1.34 +    void output();
    1.35 +
    1.36 +    TInfoSinkBase &getBodyStream();
    1.37 +    const ActiveUniforms &getUniforms();
    1.38 +
    1.39 +    TString typeString(const TType &type);
    1.40 +    TString textureString(const TType &type);
    1.41 +    static TString qualifierString(TQualifier qualifier);
    1.42 +    static TString arrayString(const TType &type);
    1.43 +    static TString initializer(const TType &type);
    1.44 +    static TString decorate(const TString &string);                      // Prepends an underscore to avoid naming clashes
    1.45 +    static TString decorateUniform(const TString &string, const TType &type);
    1.46 +    static TString decorateField(const TString &string, const TType &structure);
    1.47 +
    1.48 +  protected:
    1.49 +    void header();
    1.50 +
    1.51 +    // Visit AST nodes and output their code to the body stream
    1.52 +    void visitSymbol(TIntermSymbol*);
    1.53 +    void visitConstantUnion(TIntermConstantUnion*);
    1.54 +    bool visitBinary(Visit visit, TIntermBinary*);
    1.55 +    bool visitUnary(Visit visit, TIntermUnary*);
    1.56 +    bool visitSelection(Visit visit, TIntermSelection*);
    1.57 +    bool visitAggregate(Visit visit, TIntermAggregate*);
    1.58 +    bool visitLoop(Visit visit, TIntermLoop*);
    1.59 +    bool visitBranch(Visit visit, TIntermBranch*);
    1.60 +
    1.61 +    void traverseStatements(TIntermNode *node);
    1.62 +    bool isSingleStatement(TIntermNode *node);
    1.63 +    bool handleExcessiveLoop(TIntermLoop *node);
    1.64 +    void outputTriplet(Visit visit, const TString &preString, const TString &inString, const TString &postString);
    1.65 +    void outputLineDirective(int line);
    1.66 +    TString argumentString(const TIntermSymbol *symbol);
    1.67 +    int vectorSize(const TType &type) const;
    1.68 +
    1.69 +    void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters);
    1.70 +    const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion);
    1.71 +
    1.72 +    TString scopeString(unsigned int depthLimit);
    1.73 +    TString scopedStruct(const TString &typeName);
    1.74 +    TString structLookup(const TString &typeName);
    1.75 +
    1.76 +    TParseContext &mContext;
    1.77 +    const ShShaderOutput mOutputType;
    1.78 +    UnfoldShortCircuit *mUnfoldShortCircuit;
    1.79 +    bool mInsideFunction;
    1.80 +
    1.81 +    // Output streams
    1.82 +    TInfoSinkBase mHeader;
    1.83 +    TInfoSinkBase mBody;
    1.84 +    TInfoSinkBase mFooter;
    1.85 +
    1.86 +    typedef std::map<TString, TIntermSymbol*> ReferencedSymbols;
    1.87 +    ReferencedSymbols mReferencedUniforms;
    1.88 +    ReferencedSymbols mReferencedAttributes;
    1.89 +    ReferencedSymbols mReferencedVaryings;
    1.90 +
    1.91 +    // Parameters determining what goes in the header output
    1.92 +    bool mUsesTexture2D;
    1.93 +    bool mUsesTexture2D_bias;
    1.94 +    bool mUsesTexture2DLod;
    1.95 +    bool mUsesTexture2DProj;
    1.96 +    bool mUsesTexture2DProj_bias;
    1.97 +    bool mUsesTexture2DProjLod;
    1.98 +    bool mUsesTextureCube;
    1.99 +    bool mUsesTextureCube_bias;
   1.100 +    bool mUsesTextureCubeLod;
   1.101 +    bool mUsesTexture2DLod0;
   1.102 +    bool mUsesTexture2DLod0_bias;
   1.103 +    bool mUsesTexture2DProjLod0;
   1.104 +    bool mUsesTexture2DProjLod0_bias;
   1.105 +    bool mUsesTextureCubeLod0;
   1.106 +    bool mUsesTextureCubeLod0_bias;
   1.107 +    bool mUsesFragColor;
   1.108 +    bool mUsesFragData;
   1.109 +    bool mUsesDepthRange;
   1.110 +    bool mUsesFragCoord;
   1.111 +    bool mUsesPointCoord;
   1.112 +    bool mUsesFrontFacing;
   1.113 +    bool mUsesPointSize;
   1.114 +    bool mUsesFragDepth;
   1.115 +    bool mUsesXor;
   1.116 +    bool mUsesMod1;
   1.117 +    bool mUsesMod2v;
   1.118 +    bool mUsesMod2f;
   1.119 +    bool mUsesMod3v;
   1.120 +    bool mUsesMod3f;
   1.121 +    bool mUsesMod4v;
   1.122 +    bool mUsesMod4f;
   1.123 +    bool mUsesFaceforward1;
   1.124 +    bool mUsesFaceforward2;
   1.125 +    bool mUsesFaceforward3;
   1.126 +    bool mUsesFaceforward4;
   1.127 +    bool mUsesAtan2_1;
   1.128 +    bool mUsesAtan2_2;
   1.129 +    bool mUsesAtan2_3;
   1.130 +    bool mUsesAtan2_4;
   1.131 +
   1.132 +    int mNumRenderTargets;
   1.133 +
   1.134 +    typedef std::set<TString> Constructors;
   1.135 +    Constructors mConstructors;
   1.136 +
   1.137 +    typedef std::set<TString> StructNames;
   1.138 +    StructNames mStructNames;
   1.139 +
   1.140 +    typedef std::list<TString> StructDeclarations;
   1.141 +    StructDeclarations mStructDeclarations;
   1.142 +
   1.143 +    typedef std::vector<int> ScopeBracket;
   1.144 +    ScopeBracket mScopeBracket;
   1.145 +    unsigned int mScopeDepth;
   1.146 +
   1.147 +    int mUniqueIndex;   // For creating unique names
   1.148 +
   1.149 +    bool mContainsLoopDiscontinuity;
   1.150 +    bool mOutputLod0Function;
   1.151 +    bool mInsideDiscontinuousLoop;
   1.152 +
   1.153 +    TIntermSymbol *mExcessiveLoopIndex;
   1.154 +
   1.155 +    int mUniformRegister;
   1.156 +    int mSamplerRegister;
   1.157 +
   1.158 +    TString registerString(TIntermSymbol *operand);
   1.159 +    int samplerRegister(TIntermSymbol *sampler);
   1.160 +    int uniformRegister(TIntermSymbol *uniform);
   1.161 +    void declareUniform(const TType &type, const TString &name, int index);
   1.162 +    static GLenum glVariableType(const TType &type);
   1.163 +    static GLenum glVariablePrecision(const TType &type);
   1.164 +
   1.165 +    ActiveUniforms mActiveUniforms;
   1.166 +};
   1.167 +}
   1.168 +
   1.169 +#endif   // COMPILER_OUTPUTHLSL_H_

mercurial