michael@0: // michael@0: // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #ifndef COMPILER_OUTPUTHLSL_H_ michael@0: #define COMPILER_OUTPUTHLSL_H_ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #define GL_APICALL michael@0: #include michael@0: michael@0: #include "compiler/intermediate.h" michael@0: #include "compiler/ParseHelper.h" michael@0: #include "compiler/CompilerUniform.h" michael@0: michael@0: namespace sh michael@0: { michael@0: class UnfoldShortCircuit; michael@0: michael@0: class OutputHLSL : public TIntermTraverser michael@0: { michael@0: public: michael@0: OutputHLSL(TParseContext &context, const ShBuiltInResources& resources, ShShaderOutput outputType); michael@0: ~OutputHLSL(); michael@0: michael@0: void output(); michael@0: michael@0: TInfoSinkBase &getBodyStream(); michael@0: const ActiveUniforms &getUniforms(); michael@0: michael@0: TString typeString(const TType &type); michael@0: TString textureString(const TType &type); michael@0: static TString qualifierString(TQualifier qualifier); michael@0: static TString arrayString(const TType &type); michael@0: static TString initializer(const TType &type); michael@0: static TString decorate(const TString &string); // Prepends an underscore to avoid naming clashes michael@0: static TString decorateUniform(const TString &string, const TType &type); michael@0: static TString decorateField(const TString &string, const TType &structure); michael@0: michael@0: protected: michael@0: void header(); michael@0: michael@0: // Visit AST nodes and output their code to the body stream michael@0: void visitSymbol(TIntermSymbol*); michael@0: void visitConstantUnion(TIntermConstantUnion*); michael@0: bool visitBinary(Visit visit, TIntermBinary*); michael@0: bool visitUnary(Visit visit, TIntermUnary*); michael@0: bool visitSelection(Visit visit, TIntermSelection*); michael@0: bool visitAggregate(Visit visit, TIntermAggregate*); michael@0: bool visitLoop(Visit visit, TIntermLoop*); michael@0: bool visitBranch(Visit visit, TIntermBranch*); michael@0: michael@0: void traverseStatements(TIntermNode *node); michael@0: bool isSingleStatement(TIntermNode *node); michael@0: bool handleExcessiveLoop(TIntermLoop *node); michael@0: void outputTriplet(Visit visit, const TString &preString, const TString &inString, const TString &postString); michael@0: void outputLineDirective(int line); michael@0: TString argumentString(const TIntermSymbol *symbol); michael@0: int vectorSize(const TType &type) const; michael@0: michael@0: void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters); michael@0: const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion); michael@0: michael@0: TString scopeString(unsigned int depthLimit); michael@0: TString scopedStruct(const TString &typeName); michael@0: TString structLookup(const TString &typeName); michael@0: michael@0: TParseContext &mContext; michael@0: const ShShaderOutput mOutputType; michael@0: UnfoldShortCircuit *mUnfoldShortCircuit; michael@0: bool mInsideFunction; michael@0: michael@0: // Output streams michael@0: TInfoSinkBase mHeader; michael@0: TInfoSinkBase mBody; michael@0: TInfoSinkBase mFooter; michael@0: michael@0: typedef std::map ReferencedSymbols; michael@0: ReferencedSymbols mReferencedUniforms; michael@0: ReferencedSymbols mReferencedAttributes; michael@0: ReferencedSymbols mReferencedVaryings; michael@0: michael@0: // Parameters determining what goes in the header output michael@0: bool mUsesTexture2D; michael@0: bool mUsesTexture2D_bias; michael@0: bool mUsesTexture2DLod; michael@0: bool mUsesTexture2DProj; michael@0: bool mUsesTexture2DProj_bias; michael@0: bool mUsesTexture2DProjLod; michael@0: bool mUsesTextureCube; michael@0: bool mUsesTextureCube_bias; michael@0: bool mUsesTextureCubeLod; michael@0: bool mUsesTexture2DLod0; michael@0: bool mUsesTexture2DLod0_bias; michael@0: bool mUsesTexture2DProjLod0; michael@0: bool mUsesTexture2DProjLod0_bias; michael@0: bool mUsesTextureCubeLod0; michael@0: bool mUsesTextureCubeLod0_bias; michael@0: bool mUsesFragColor; michael@0: bool mUsesFragData; michael@0: bool mUsesDepthRange; michael@0: bool mUsesFragCoord; michael@0: bool mUsesPointCoord; michael@0: bool mUsesFrontFacing; michael@0: bool mUsesPointSize; michael@0: bool mUsesFragDepth; michael@0: bool mUsesXor; michael@0: bool mUsesMod1; michael@0: bool mUsesMod2v; michael@0: bool mUsesMod2f; michael@0: bool mUsesMod3v; michael@0: bool mUsesMod3f; michael@0: bool mUsesMod4v; michael@0: bool mUsesMod4f; michael@0: bool mUsesFaceforward1; michael@0: bool mUsesFaceforward2; michael@0: bool mUsesFaceforward3; michael@0: bool mUsesFaceforward4; michael@0: bool mUsesAtan2_1; michael@0: bool mUsesAtan2_2; michael@0: bool mUsesAtan2_3; michael@0: bool mUsesAtan2_4; michael@0: michael@0: int mNumRenderTargets; michael@0: michael@0: typedef std::set Constructors; michael@0: Constructors mConstructors; michael@0: michael@0: typedef std::set StructNames; michael@0: StructNames mStructNames; michael@0: michael@0: typedef std::list StructDeclarations; michael@0: StructDeclarations mStructDeclarations; michael@0: michael@0: typedef std::vector ScopeBracket; michael@0: ScopeBracket mScopeBracket; michael@0: unsigned int mScopeDepth; michael@0: michael@0: int mUniqueIndex; // For creating unique names michael@0: michael@0: bool mContainsLoopDiscontinuity; michael@0: bool mOutputLod0Function; michael@0: bool mInsideDiscontinuousLoop; michael@0: michael@0: TIntermSymbol *mExcessiveLoopIndex; michael@0: michael@0: int mUniformRegister; michael@0: int mSamplerRegister; michael@0: michael@0: TString registerString(TIntermSymbol *operand); michael@0: int samplerRegister(TIntermSymbol *sampler); michael@0: int uniformRegister(TIntermSymbol *uniform); michael@0: void declareUniform(const TType &type, const TString &name, int index); michael@0: static GLenum glVariableType(const TType &type); michael@0: static GLenum glVariablePrecision(const TType &type); michael@0: michael@0: ActiveUniforms mActiveUniforms; michael@0: }; michael@0: } michael@0: michael@0: #endif // COMPILER_OUTPUTHLSL_H_