gfx/angle/src/compiler/ShHandle.h

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 //
michael@0 2 // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
michael@0 3 // Use of this source code is governed by a BSD-style license that can be
michael@0 4 // found in the LICENSE file.
michael@0 5 //
michael@0 6
michael@0 7 #ifndef _SHHANDLE_INCLUDED_
michael@0 8 #define _SHHANDLE_INCLUDED_
michael@0 9
michael@0 10 //
michael@0 11 // Machine independent part of the compiler private objects
michael@0 12 // sent as ShHandle to the driver.
michael@0 13 //
michael@0 14 // This should not be included by driver code.
michael@0 15 //
michael@0 16
michael@0 17 #include "GLSLANG/ShaderLang.h"
michael@0 18
michael@0 19 #include "compiler/BuiltInFunctionEmulator.h"
michael@0 20 #include "compiler/ExtensionBehavior.h"
michael@0 21 #include "compiler/HashNames.h"
michael@0 22 #include "compiler/InfoSink.h"
michael@0 23 #include "compiler/SymbolTable.h"
michael@0 24 #include "compiler/VariableInfo.h"
michael@0 25 #include "third_party/compiler/ArrayBoundsClamper.h"
michael@0 26
michael@0 27 class LongNameMap;
michael@0 28 class TCompiler;
michael@0 29 class TDependencyGraph;
michael@0 30 class TranslatorHLSL;
michael@0 31
michael@0 32 //
michael@0 33 // Helper function to identify specs that are based on the WebGL spec,
michael@0 34 // like the CSS Shaders spec.
michael@0 35 //
michael@0 36 bool isWebGLBasedSpec(ShShaderSpec spec);
michael@0 37
michael@0 38 //
michael@0 39 // The base class used to back handles returned to the driver.
michael@0 40 //
michael@0 41 class TShHandleBase {
michael@0 42 public:
michael@0 43 TShHandleBase();
michael@0 44 virtual ~TShHandleBase();
michael@0 45 virtual TCompiler* getAsCompiler() { return 0; }
michael@0 46 virtual TranslatorHLSL* getAsTranslatorHLSL() { return 0; }
michael@0 47
michael@0 48 protected:
michael@0 49 // Memory allocator. Allocates and tracks memory required by the compiler.
michael@0 50 // Deallocates all memory when compiler is destructed.
michael@0 51 TPoolAllocator allocator;
michael@0 52 };
michael@0 53
michael@0 54 //
michael@0 55 // The base class for the machine dependent compiler to derive from
michael@0 56 // for managing object code from the compile.
michael@0 57 //
michael@0 58 class TCompiler : public TShHandleBase {
michael@0 59 public:
michael@0 60 TCompiler(ShShaderType type, ShShaderSpec spec);
michael@0 61 virtual ~TCompiler();
michael@0 62 virtual TCompiler* getAsCompiler() { return this; }
michael@0 63
michael@0 64 bool Init(const ShBuiltInResources& resources);
michael@0 65 bool compile(const char* const shaderStrings[],
michael@0 66 size_t numStrings,
michael@0 67 int compileOptions);
michael@0 68
michael@0 69 // Get results of the last compilation.
michael@0 70 TInfoSink& getInfoSink() { return infoSink; }
michael@0 71 const TVariableInfoList& getAttribs() const { return attribs; }
michael@0 72 const TVariableInfoList& getUniforms() const { return uniforms; }
michael@0 73 int getMappedNameMaxLength() const;
michael@0 74
michael@0 75 ShHashFunction64 getHashFunction() const { return hashFunction; }
michael@0 76 NameMap& getNameMap() { return nameMap; }
michael@0 77 TSymbolTable& getSymbolTable() { return symbolTable; }
michael@0 78
michael@0 79 protected:
michael@0 80 ShShaderType getShaderType() const { return shaderType; }
michael@0 81 ShShaderSpec getShaderSpec() const { return shaderSpec; }
michael@0 82 // Initialize symbol-table with built-in symbols.
michael@0 83 bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
michael@0 84 // Clears the results from the previous compilation.
michael@0 85 void clearResults();
michael@0 86 // Return true if function recursion is detected or call depth exceeded.
michael@0 87 bool detectCallDepth(TIntermNode* root, TInfoSink& infoSink, bool limitCallStackDepth);
michael@0 88 // Rewrites a shader's intermediate tree according to the CSS Shaders spec.
michael@0 89 void rewriteCSSShader(TIntermNode* root);
michael@0 90 // Returns true if the given shader does not exceed the minimum
michael@0 91 // functionality mandated in GLSL 1.0 spec Appendix A.
michael@0 92 bool validateLimitations(TIntermNode* root);
michael@0 93 // Collect info for all attribs and uniforms.
michael@0 94 void collectAttribsUniforms(TIntermNode* root);
michael@0 95 // Map long variable names into shorter ones.
michael@0 96 void mapLongVariableNames(TIntermNode* root);
michael@0 97 // Translate to object code.
michael@0 98 virtual void translate(TIntermNode* root) = 0;
michael@0 99 // Returns true if, after applying the packing rules in the GLSL 1.017 spec
michael@0 100 // Appendix A, section 7, the shader does not use too many uniforms.
michael@0 101 bool enforcePackingRestrictions();
michael@0 102 // Returns true if the shader passes the restrictions that aim to prevent timing attacks.
michael@0 103 bool enforceTimingRestrictions(TIntermNode* root, bool outputGraph);
michael@0 104 // Returns true if the shader does not use samplers.
michael@0 105 bool enforceVertexShaderTimingRestrictions(TIntermNode* root);
michael@0 106 // Returns true if the shader does not use sampler dependent values to affect control
michael@0 107 // flow or in operations whose time can depend on the input values.
michael@0 108 bool enforceFragmentShaderTimingRestrictions(const TDependencyGraph& graph);
michael@0 109 // Return true if the maximum expression complexity below the limit.
michael@0 110 bool limitExpressionComplexity(TIntermNode* root);
michael@0 111 // Get built-in extensions with default behavior.
michael@0 112 const TExtensionBehavior& getExtensionBehavior() const;
michael@0 113 // Get the resources set by InitBuiltInSymbolTable
michael@0 114 const ShBuiltInResources& getResources() const;
michael@0 115
michael@0 116 const ArrayBoundsClamper& getArrayBoundsClamper() const;
michael@0 117 ShArrayIndexClampingStrategy getArrayIndexClampingStrategy() const;
michael@0 118 const BuiltInFunctionEmulator& getBuiltInFunctionEmulator() const;
michael@0 119
michael@0 120 private:
michael@0 121 ShShaderType shaderType;
michael@0 122 ShShaderSpec shaderSpec;
michael@0 123
michael@0 124 int maxUniformVectors;
michael@0 125 int maxExpressionComplexity;
michael@0 126 int maxCallStackDepth;
michael@0 127
michael@0 128 ShBuiltInResources compileResources;
michael@0 129
michael@0 130 // Built-in symbol table for the given language, spec, and resources.
michael@0 131 // It is preserved from compile-to-compile.
michael@0 132 TSymbolTable symbolTable;
michael@0 133 // Built-in extensions with default behavior.
michael@0 134 TExtensionBehavior extensionBehavior;
michael@0 135 bool fragmentPrecisionHigh;
michael@0 136
michael@0 137 ArrayBoundsClamper arrayBoundsClamper;
michael@0 138 ShArrayIndexClampingStrategy clampingStrategy;
michael@0 139 BuiltInFunctionEmulator builtInFunctionEmulator;
michael@0 140
michael@0 141 // Results of compilation.
michael@0 142 TInfoSink infoSink; // Output sink.
michael@0 143 TVariableInfoList attribs; // Active attributes in the compiled shader.
michael@0 144 TVariableInfoList uniforms; // Active uniforms in the compiled shader.
michael@0 145
michael@0 146 // Cached copy of the ref-counted singleton.
michael@0 147 LongNameMap* longNameMap;
michael@0 148
michael@0 149 // name hashing.
michael@0 150 ShHashFunction64 hashFunction;
michael@0 151 NameMap nameMap;
michael@0 152 };
michael@0 153
michael@0 154 //
michael@0 155 // This is the interface between the machine independent code
michael@0 156 // and the machine dependent code.
michael@0 157 //
michael@0 158 // The machine dependent code should derive from the classes
michael@0 159 // above. Then Construct*() and Delete*() will create and
michael@0 160 // destroy the machine dependent objects, which contain the
michael@0 161 // above machine independent information.
michael@0 162 //
michael@0 163 TCompiler* ConstructCompiler(
michael@0 164 ShShaderType type, ShShaderSpec spec, ShShaderOutput output);
michael@0 165 void DeleteCompiler(TCompiler*);
michael@0 166
michael@0 167 #endif // _SHHANDLE_INCLUDED_

mercurial