1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/compiler/ShHandle.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,167 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2012 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 _SHHANDLE_INCLUDED_ 1.11 +#define _SHHANDLE_INCLUDED_ 1.12 + 1.13 +// 1.14 +// Machine independent part of the compiler private objects 1.15 +// sent as ShHandle to the driver. 1.16 +// 1.17 +// This should not be included by driver code. 1.18 +// 1.19 + 1.20 +#include "GLSLANG/ShaderLang.h" 1.21 + 1.22 +#include "compiler/BuiltInFunctionEmulator.h" 1.23 +#include "compiler/ExtensionBehavior.h" 1.24 +#include "compiler/HashNames.h" 1.25 +#include "compiler/InfoSink.h" 1.26 +#include "compiler/SymbolTable.h" 1.27 +#include "compiler/VariableInfo.h" 1.28 +#include "third_party/compiler/ArrayBoundsClamper.h" 1.29 + 1.30 +class LongNameMap; 1.31 +class TCompiler; 1.32 +class TDependencyGraph; 1.33 +class TranslatorHLSL; 1.34 + 1.35 +// 1.36 +// Helper function to identify specs that are based on the WebGL spec, 1.37 +// like the CSS Shaders spec. 1.38 +// 1.39 +bool isWebGLBasedSpec(ShShaderSpec spec); 1.40 + 1.41 +// 1.42 +// The base class used to back handles returned to the driver. 1.43 +// 1.44 +class TShHandleBase { 1.45 +public: 1.46 + TShHandleBase(); 1.47 + virtual ~TShHandleBase(); 1.48 + virtual TCompiler* getAsCompiler() { return 0; } 1.49 + virtual TranslatorHLSL* getAsTranslatorHLSL() { return 0; } 1.50 + 1.51 +protected: 1.52 + // Memory allocator. Allocates and tracks memory required by the compiler. 1.53 + // Deallocates all memory when compiler is destructed. 1.54 + TPoolAllocator allocator; 1.55 +}; 1.56 + 1.57 +// 1.58 +// The base class for the machine dependent compiler to derive from 1.59 +// for managing object code from the compile. 1.60 +// 1.61 +class TCompiler : public TShHandleBase { 1.62 +public: 1.63 + TCompiler(ShShaderType type, ShShaderSpec spec); 1.64 + virtual ~TCompiler(); 1.65 + virtual TCompiler* getAsCompiler() { return this; } 1.66 + 1.67 + bool Init(const ShBuiltInResources& resources); 1.68 + bool compile(const char* const shaderStrings[], 1.69 + size_t numStrings, 1.70 + int compileOptions); 1.71 + 1.72 + // Get results of the last compilation. 1.73 + TInfoSink& getInfoSink() { return infoSink; } 1.74 + const TVariableInfoList& getAttribs() const { return attribs; } 1.75 + const TVariableInfoList& getUniforms() const { return uniforms; } 1.76 + int getMappedNameMaxLength() const; 1.77 + 1.78 + ShHashFunction64 getHashFunction() const { return hashFunction; } 1.79 + NameMap& getNameMap() { return nameMap; } 1.80 + TSymbolTable& getSymbolTable() { return symbolTable; } 1.81 + 1.82 +protected: 1.83 + ShShaderType getShaderType() const { return shaderType; } 1.84 + ShShaderSpec getShaderSpec() const { return shaderSpec; } 1.85 + // Initialize symbol-table with built-in symbols. 1.86 + bool InitBuiltInSymbolTable(const ShBuiltInResources& resources); 1.87 + // Clears the results from the previous compilation. 1.88 + void clearResults(); 1.89 + // Return true if function recursion is detected or call depth exceeded. 1.90 + bool detectCallDepth(TIntermNode* root, TInfoSink& infoSink, bool limitCallStackDepth); 1.91 + // Rewrites a shader's intermediate tree according to the CSS Shaders spec. 1.92 + void rewriteCSSShader(TIntermNode* root); 1.93 + // Returns true if the given shader does not exceed the minimum 1.94 + // functionality mandated in GLSL 1.0 spec Appendix A. 1.95 + bool validateLimitations(TIntermNode* root); 1.96 + // Collect info for all attribs and uniforms. 1.97 + void collectAttribsUniforms(TIntermNode* root); 1.98 + // Map long variable names into shorter ones. 1.99 + void mapLongVariableNames(TIntermNode* root); 1.100 + // Translate to object code. 1.101 + virtual void translate(TIntermNode* root) = 0; 1.102 + // Returns true if, after applying the packing rules in the GLSL 1.017 spec 1.103 + // Appendix A, section 7, the shader does not use too many uniforms. 1.104 + bool enforcePackingRestrictions(); 1.105 + // Returns true if the shader passes the restrictions that aim to prevent timing attacks. 1.106 + bool enforceTimingRestrictions(TIntermNode* root, bool outputGraph); 1.107 + // Returns true if the shader does not use samplers. 1.108 + bool enforceVertexShaderTimingRestrictions(TIntermNode* root); 1.109 + // Returns true if the shader does not use sampler dependent values to affect control 1.110 + // flow or in operations whose time can depend on the input values. 1.111 + bool enforceFragmentShaderTimingRestrictions(const TDependencyGraph& graph); 1.112 + // Return true if the maximum expression complexity below the limit. 1.113 + bool limitExpressionComplexity(TIntermNode* root); 1.114 + // Get built-in extensions with default behavior. 1.115 + const TExtensionBehavior& getExtensionBehavior() const; 1.116 + // Get the resources set by InitBuiltInSymbolTable 1.117 + const ShBuiltInResources& getResources() const; 1.118 + 1.119 + const ArrayBoundsClamper& getArrayBoundsClamper() const; 1.120 + ShArrayIndexClampingStrategy getArrayIndexClampingStrategy() const; 1.121 + const BuiltInFunctionEmulator& getBuiltInFunctionEmulator() const; 1.122 + 1.123 +private: 1.124 + ShShaderType shaderType; 1.125 + ShShaderSpec shaderSpec; 1.126 + 1.127 + int maxUniformVectors; 1.128 + int maxExpressionComplexity; 1.129 + int maxCallStackDepth; 1.130 + 1.131 + ShBuiltInResources compileResources; 1.132 + 1.133 + // Built-in symbol table for the given language, spec, and resources. 1.134 + // It is preserved from compile-to-compile. 1.135 + TSymbolTable symbolTable; 1.136 + // Built-in extensions with default behavior. 1.137 + TExtensionBehavior extensionBehavior; 1.138 + bool fragmentPrecisionHigh; 1.139 + 1.140 + ArrayBoundsClamper arrayBoundsClamper; 1.141 + ShArrayIndexClampingStrategy clampingStrategy; 1.142 + BuiltInFunctionEmulator builtInFunctionEmulator; 1.143 + 1.144 + // Results of compilation. 1.145 + TInfoSink infoSink; // Output sink. 1.146 + TVariableInfoList attribs; // Active attributes in the compiled shader. 1.147 + TVariableInfoList uniforms; // Active uniforms in the compiled shader. 1.148 + 1.149 + // Cached copy of the ref-counted singleton. 1.150 + LongNameMap* longNameMap; 1.151 + 1.152 + // name hashing. 1.153 + ShHashFunction64 hashFunction; 1.154 + NameMap nameMap; 1.155 +}; 1.156 + 1.157 +// 1.158 +// This is the interface between the machine independent code 1.159 +// and the machine dependent code. 1.160 +// 1.161 +// The machine dependent code should derive from the classes 1.162 +// above. Then Construct*() and Delete*() will create and 1.163 +// destroy the machine dependent objects, which contain the 1.164 +// above machine independent information. 1.165 +// 1.166 +TCompiler* ConstructCompiler( 1.167 + ShShaderType type, ShShaderSpec spec, ShShaderOutput output); 1.168 +void DeleteCompiler(TCompiler*); 1.169 + 1.170 +#endif // _SHHANDLE_INCLUDED_