michael@0: // michael@0: // Copyright (c) 2002-2012 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 _SHHANDLE_INCLUDED_ michael@0: #define _SHHANDLE_INCLUDED_ michael@0: michael@0: // michael@0: // Machine independent part of the compiler private objects michael@0: // sent as ShHandle to the driver. michael@0: // michael@0: // This should not be included by driver code. michael@0: // michael@0: michael@0: #include "GLSLANG/ShaderLang.h" michael@0: michael@0: #include "compiler/BuiltInFunctionEmulator.h" michael@0: #include "compiler/ExtensionBehavior.h" michael@0: #include "compiler/HashNames.h" michael@0: #include "compiler/InfoSink.h" michael@0: #include "compiler/SymbolTable.h" michael@0: #include "compiler/VariableInfo.h" michael@0: #include "third_party/compiler/ArrayBoundsClamper.h" michael@0: michael@0: class LongNameMap; michael@0: class TCompiler; michael@0: class TDependencyGraph; michael@0: class TranslatorHLSL; michael@0: michael@0: // michael@0: // Helper function to identify specs that are based on the WebGL spec, michael@0: // like the CSS Shaders spec. michael@0: // michael@0: bool isWebGLBasedSpec(ShShaderSpec spec); michael@0: michael@0: // michael@0: // The base class used to back handles returned to the driver. michael@0: // michael@0: class TShHandleBase { michael@0: public: michael@0: TShHandleBase(); michael@0: virtual ~TShHandleBase(); michael@0: virtual TCompiler* getAsCompiler() { return 0; } michael@0: virtual TranslatorHLSL* getAsTranslatorHLSL() { return 0; } michael@0: michael@0: protected: michael@0: // Memory allocator. Allocates and tracks memory required by the compiler. michael@0: // Deallocates all memory when compiler is destructed. michael@0: TPoolAllocator allocator; michael@0: }; michael@0: michael@0: // michael@0: // The base class for the machine dependent compiler to derive from michael@0: // for managing object code from the compile. michael@0: // michael@0: class TCompiler : public TShHandleBase { michael@0: public: michael@0: TCompiler(ShShaderType type, ShShaderSpec spec); michael@0: virtual ~TCompiler(); michael@0: virtual TCompiler* getAsCompiler() { return this; } michael@0: michael@0: bool Init(const ShBuiltInResources& resources); michael@0: bool compile(const char* const shaderStrings[], michael@0: size_t numStrings, michael@0: int compileOptions); michael@0: michael@0: // Get results of the last compilation. michael@0: TInfoSink& getInfoSink() { return infoSink; } michael@0: const TVariableInfoList& getAttribs() const { return attribs; } michael@0: const TVariableInfoList& getUniforms() const { return uniforms; } michael@0: int getMappedNameMaxLength() const; michael@0: michael@0: ShHashFunction64 getHashFunction() const { return hashFunction; } michael@0: NameMap& getNameMap() { return nameMap; } michael@0: TSymbolTable& getSymbolTable() { return symbolTable; } michael@0: michael@0: protected: michael@0: ShShaderType getShaderType() const { return shaderType; } michael@0: ShShaderSpec getShaderSpec() const { return shaderSpec; } michael@0: // Initialize symbol-table with built-in symbols. michael@0: bool InitBuiltInSymbolTable(const ShBuiltInResources& resources); michael@0: // Clears the results from the previous compilation. michael@0: void clearResults(); michael@0: // Return true if function recursion is detected or call depth exceeded. michael@0: bool detectCallDepth(TIntermNode* root, TInfoSink& infoSink, bool limitCallStackDepth); michael@0: // Rewrites a shader's intermediate tree according to the CSS Shaders spec. michael@0: void rewriteCSSShader(TIntermNode* root); michael@0: // Returns true if the given shader does not exceed the minimum michael@0: // functionality mandated in GLSL 1.0 spec Appendix A. michael@0: bool validateLimitations(TIntermNode* root); michael@0: // Collect info for all attribs and uniforms. michael@0: void collectAttribsUniforms(TIntermNode* root); michael@0: // Map long variable names into shorter ones. michael@0: void mapLongVariableNames(TIntermNode* root); michael@0: // Translate to object code. michael@0: virtual void translate(TIntermNode* root) = 0; michael@0: // Returns true if, after applying the packing rules in the GLSL 1.017 spec michael@0: // Appendix A, section 7, the shader does not use too many uniforms. michael@0: bool enforcePackingRestrictions(); michael@0: // Returns true if the shader passes the restrictions that aim to prevent timing attacks. michael@0: bool enforceTimingRestrictions(TIntermNode* root, bool outputGraph); michael@0: // Returns true if the shader does not use samplers. michael@0: bool enforceVertexShaderTimingRestrictions(TIntermNode* root); michael@0: // Returns true if the shader does not use sampler dependent values to affect control michael@0: // flow or in operations whose time can depend on the input values. michael@0: bool enforceFragmentShaderTimingRestrictions(const TDependencyGraph& graph); michael@0: // Return true if the maximum expression complexity below the limit. michael@0: bool limitExpressionComplexity(TIntermNode* root); michael@0: // Get built-in extensions with default behavior. michael@0: const TExtensionBehavior& getExtensionBehavior() const; michael@0: // Get the resources set by InitBuiltInSymbolTable michael@0: const ShBuiltInResources& getResources() const; michael@0: michael@0: const ArrayBoundsClamper& getArrayBoundsClamper() const; michael@0: ShArrayIndexClampingStrategy getArrayIndexClampingStrategy() const; michael@0: const BuiltInFunctionEmulator& getBuiltInFunctionEmulator() const; michael@0: michael@0: private: michael@0: ShShaderType shaderType; michael@0: ShShaderSpec shaderSpec; michael@0: michael@0: int maxUniformVectors; michael@0: int maxExpressionComplexity; michael@0: int maxCallStackDepth; michael@0: michael@0: ShBuiltInResources compileResources; michael@0: michael@0: // Built-in symbol table for the given language, spec, and resources. michael@0: // It is preserved from compile-to-compile. michael@0: TSymbolTable symbolTable; michael@0: // Built-in extensions with default behavior. michael@0: TExtensionBehavior extensionBehavior; michael@0: bool fragmentPrecisionHigh; michael@0: michael@0: ArrayBoundsClamper arrayBoundsClamper; michael@0: ShArrayIndexClampingStrategy clampingStrategy; michael@0: BuiltInFunctionEmulator builtInFunctionEmulator; michael@0: michael@0: // Results of compilation. michael@0: TInfoSink infoSink; // Output sink. michael@0: TVariableInfoList attribs; // Active attributes in the compiled shader. michael@0: TVariableInfoList uniforms; // Active uniforms in the compiled shader. michael@0: michael@0: // Cached copy of the ref-counted singleton. michael@0: LongNameMap* longNameMap; michael@0: michael@0: // name hashing. michael@0: ShHashFunction64 hashFunction; michael@0: NameMap nameMap; michael@0: }; michael@0: michael@0: // michael@0: // This is the interface between the machine independent code michael@0: // and the machine dependent code. michael@0: // michael@0: // The machine dependent code should derive from the classes michael@0: // above. Then Construct*() and Delete*() will create and michael@0: // destroy the machine dependent objects, which contain the michael@0: // above machine independent information. michael@0: // michael@0: TCompiler* ConstructCompiler( michael@0: ShShaderType type, ShShaderSpec spec, ShShaderOutput output); michael@0: void DeleteCompiler(TCompiler*); michael@0: michael@0: #endif // _SHHANDLE_INCLUDED_