John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1 | // |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Nicolas Capens | 6407fe8 | 2015-02-10 16:27:49 -0500 | [diff] [blame] | 7 | #ifndef _COMPILER_INCLUDED_ |
| 8 | #define _COMPILER_INCLUDED_ |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 9 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 10 | #include "ExtensionBehavior.h" |
| 11 | #include "InfoSink.h" |
| 12 | #include "SymbolTable.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 13 | |
Nicolas Capens | 6407fe8 | 2015-02-10 16:27:49 -0500 | [diff] [blame] | 14 | enum ShCompileOptions |
| 15 | { |
| 16 | SH_VALIDATE = 0, |
| 17 | SH_VALIDATE_LOOP_INDEXING = 0x0001, |
| 18 | SH_INTERMEDIATE_TREE = 0x0002, |
| 19 | SH_OBJECT_CODE = 0x0004, |
| 20 | SH_ATTRIBUTES_UNIFORMS = 0x0008, |
| 21 | SH_LINE_DIRECTIVES = 0x0010, |
| 22 | SH_SOURCE_PATH = 0x0020 |
| 23 | }; |
| 24 | |
| 25 | // |
| 26 | // Implementation dependent built-in resources (constants and extensions). |
| 27 | // The names for these resources has been obtained by stripping gl_/GL_. |
| 28 | // |
| 29 | struct ShBuiltInResources |
| 30 | { |
| 31 | ShBuiltInResources(); |
| 32 | |
| 33 | // Constants. |
| 34 | int MaxVertexAttribs; |
| 35 | int MaxVertexUniformVectors; |
| 36 | int MaxVaryingVectors; |
| 37 | int MaxVertexTextureImageUnits; |
| 38 | int MaxCombinedTextureImageUnits; |
| 39 | int MaxTextureImageUnits; |
| 40 | int MaxFragmentUniformVectors; |
| 41 | int MaxDrawBuffers; |
Alexis Hetu | 6743bbf | 2015-04-21 17:06:14 -0400 | [diff] [blame] | 42 | int MaxVertexOutputVectors; |
| 43 | int MaxFragmentInputVectors; |
| 44 | int MinProgramTexelOffset; |
| 45 | int MaxProgramTexelOffset; |
Nicolas Capens | 6407fe8 | 2015-02-10 16:27:49 -0500 | [diff] [blame] | 46 | |
| 47 | // Extensions. |
| 48 | // Set to 1 to enable the extension, else 0. |
| 49 | int OES_standard_derivatives; |
| 50 | int OES_fragment_precision_high; |
| 51 | int OES_EGL_image_external; |
| 52 | |
| 53 | unsigned int MaxCallStackDepth; |
| 54 | }; |
| 55 | |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 56 | typedef unsigned int GLenum; |
| 57 | #define GL_FRAGMENT_SHADER 0x8B30 |
| 58 | #define GL_VERTEX_SHADER 0x8B31 |
| 59 | |
Nicolas Capens | 6407fe8 | 2015-02-10 16:27:49 -0500 | [diff] [blame] | 60 | // |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 61 | // The base class for the machine dependent compiler to derive from |
| 62 | // for managing object code from the compile. |
| 63 | // |
Nicolas Capens | 7a8ccc4 | 2015-02-10 15:42:31 -0500 | [diff] [blame] | 64 | class TCompiler |
| 65 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 66 | public: |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 67 | TCompiler(GLenum shaderType); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 68 | virtual ~TCompiler(); |
| 69 | virtual TCompiler* getAsCompiler() { return this; } |
| 70 | |
| 71 | bool Init(const ShBuiltInResources& resources); |
| 72 | bool compile(const char* const shaderStrings[], |
| 73 | const int numStrings, |
| 74 | int compileOptions); |
| 75 | |
| 76 | // Get results of the last compilation. |
Nicolas Capens | b28964b | 2015-02-10 15:23:06 -0500 | [diff] [blame] | 77 | int getShaderVersion() const { return shaderVersion; } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 78 | TInfoSink& getInfoSink() { return infoSink; } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 79 | |
| 80 | protected: |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 81 | GLenum getShaderType() const { return shaderType; } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 82 | // Initialize symbol-table with built-in symbols. |
| 83 | bool InitBuiltInSymbolTable(const ShBuiltInResources& resources); |
| 84 | // Clears the results from the previous compilation. |
| 85 | void clearResults(); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 86 | // Return true if function recursion is detected or call depth exceeded. |
| 87 | bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 88 | // Returns true if the given shader does not exceed the minimum |
| 89 | // functionality mandated in GLSL 1.0 spec Appendix A. |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 90 | bool validateLimitations(TIntermNode *root); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 91 | // Translate to object code. |
Nicolas Capens | 014b9a6 | 2014-10-15 10:28:29 -0400 | [diff] [blame] | 92 | virtual bool translate(TIntermNode *root) = 0; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 93 | // Get built-in extensions with default behavior. |
| 94 | const TExtensionBehavior& getExtensionBehavior() const; |
| 95 | |
| 96 | private: |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 97 | GLenum shaderType; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 98 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 99 | unsigned int maxCallStackDepth; |
| 100 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 101 | // Built-in symbol table for the given language, spec, and resources. |
| 102 | // It is preserved from compile-to-compile. |
| 103 | TSymbolTable symbolTable; |
| 104 | // Built-in extensions with default behavior. |
| 105 | TExtensionBehavior extensionBehavior; |
| 106 | |
| 107 | // Results of compilation. |
Nicolas Capens | b28964b | 2015-02-10 15:23:06 -0500 | [diff] [blame] | 108 | int shaderVersion; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 109 | TInfoSink infoSink; // Output sink. |
Nicolas Capens | 7a8ccc4 | 2015-02-10 15:42:31 -0500 | [diff] [blame] | 110 | |
| 111 | // Memory allocator. Allocates and tracks memory required by the compiler. |
| 112 | // Deallocates all memory when compiler is destructed. |
| 113 | TPoolAllocator allocator; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 114 | }; |
| 115 | |
Nicolas Capens | 6407fe8 | 2015-02-10 16:27:49 -0500 | [diff] [blame] | 116 | bool InitCompilerGlobals(); |
| 117 | void FreeCompilerGlobals(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 118 | |
Nicolas Capens | 6407fe8 | 2015-02-10 16:27:49 -0500 | [diff] [blame] | 119 | #endif // _COMPILER_INCLUDED_ |