Edit

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

Branch :

  • Show log

    Commit

  • Author : apatrick@chromium.org
    Date : 2011-01-26 19:30:57
    Hash : 0f4cefe9
    Message : Map D3D calls and HLSL shaders back to GLES2 calls and GLSL ES shaders in PIX. This makes debugging and profiling using PIX a lot more convenient. The top level of events are the GLES calls with their arguments. Those can be expanded to see the D3D calls that were issued for a particular GLES call. When PIX is attached, the shaders are saved out to temporary files and referenced from the translated HLSL shaders via #line directives. This enabled source level debugging of the original GLSL from PIX for pixel and vertex shaders. The HLSL is also saved to a temporary file so that intrinsic functions like texture2D can be stepped into. It also avoids creating a text file in the current working directory, which has continued to be an issue. I made the dependency on d3d9.dll static again so it can be accessed by GetModuleHandle witihin DllMain. I added an EVENT macro that issues D3DPERF_BeginEvent and D3DPERF_EndEvent around a C++ block. I replaced TRACE with EVENT for all the entry points. I removed the tracing of shader source since the source is visible in PIX. The means by which the filename of the temporary shader file is passed into the shader compiler is a little clunky. I did it that way to avoid changing the function signatures and breaking folks using the translator. I plan to make the compiler respect #pragma optimize so that optimization can be disabled for debugging purposes. For now it just disables shader optimization in debug builds of ANGLE. Review URL: http://codereview.appspot.com/3945043 git-svn-id: https://angleproject.googlecode.com/svn/trunk@541 736b8ea6-26fd-11df-bfd4-992fa37f6226

  • src/compiler/OutputHLSL.h
  • //
    // Copyright (c) 2002-2010 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.
    //
    
    #ifndef COMPILER_OUTPUTHLSL_H_
    #define COMPILER_OUTPUTHLSL_H_
    
    #include <list>
    #include <set>
    
    #include "compiler/intermediate.h"
    #include "compiler/ParseHelper.h"
    
    namespace sh
    {
    class UnfoldSelect;
    
    class OutputHLSL : public TIntermTraverser
    {
      public:
        explicit OutputHLSL(TParseContext &context);
        ~OutputHLSL();
    
        void output();
    
        TInfoSinkBase &getBodyStream();
    
        TString typeString(const TType &type);
        static TString qualifierString(TQualifier qualifier);
        static TString arrayString(const TType &type);
        static TString initializer(const TType &type);
        static TString decorate(const TString &string);   // Prepend an underscore to avoid naming clashes
    
      protected:
        void header();
    
        // Visit AST nodes and output their code to the body stream
        void visitSymbol(TIntermSymbol*);
        void visitConstantUnion(TIntermConstantUnion*);
        bool visitBinary(Visit visit, TIntermBinary*);
        bool visitUnary(Visit visit, TIntermUnary*);
        bool visitSelection(Visit visit, TIntermSelection*);
        bool visitAggregate(Visit visit, TIntermAggregate*);
        bool visitLoop(Visit visit, TIntermLoop*);
        bool visitBranch(Visit visit, TIntermBranch*);
    
        bool isSingleStatement(TIntermNode *node);
        bool handleExcessiveLoop(TIntermLoop *node);
        void outputTriplet(Visit visit, const TString &preString, const TString &inString, const TString &postString);
        void outputLineDirective(int line);
        TString argumentString(const TIntermSymbol *symbol);
        int vectorSize(const TType &type) const;
    
        void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters);
        const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion);
    
        TString scopeString(unsigned int depthLimit);
        TString scopedStruct(const TString &typeName);
        TString structLookup(const TString &typeName);
    
        TParseContext &mContext;
        UnfoldSelect *mUnfoldSelect;
        bool mInsideFunction;
    
        // Output streams
        TInfoSinkBase mHeader;
        TInfoSinkBase mBody;
        TInfoSinkBase mFooter;
    
        std::set<std::string> mReferencedUniforms;
        std::set<std::string> mReferencedAttributes;
        std::set<std::string> mReferencedVaryings;
    
        // Parameters determining what goes in the header output
        bool mUsesTexture2D;
        bool mUsesTexture2D_bias;
        bool mUsesTexture2DProj;
        bool mUsesTexture2DProj_bias;
        bool mUsesTextureCube;
        bool mUsesTextureCube_bias;
        bool mUsesDepthRange;
        bool mUsesFragCoord;
        bool mUsesPointCoord;
        bool mUsesFrontFacing;
        bool mUsesPointSize;
        bool mUsesXor;
        bool mUsesMod1;
        bool mUsesMod2;
        bool mUsesMod3;
        bool mUsesMod4;
        bool mUsesFaceforward1;
        bool mUsesFaceforward2;
        bool mUsesFaceforward3;
        bool mUsesFaceforward4;
        bool mUsesEqualMat2;
        bool mUsesEqualMat3;
        bool mUsesEqualMat4;
        bool mUsesEqualVec2;
        bool mUsesEqualVec3;
        bool mUsesEqualVec4;
        bool mUsesEqualIVec2;
        bool mUsesEqualIVec3;
        bool mUsesEqualIVec4;
        bool mUsesEqualBVec2;
        bool mUsesEqualBVec3;
        bool mUsesEqualBVec4;
        bool mUsesAtan2;
    
        typedef std::set<TString> Constructors;
        Constructors mConstructors;
    
        typedef std::set<TString> StructNames;
        StructNames mStructNames;
    
        typedef std::list<TString> StructDeclarations;
        StructDeclarations mStructDeclarations;
    
        typedef std::vector<int> ScopeBracket;
        ScopeBracket mScopeBracket;
        unsigned int mScopeDepth;
    
        int mUniqueIndex;   // For creating unique names
    };
    }
    
    #endif   // COMPILER_OUTPUTHLSL_H_