blob: c90dbd26843a72268d47bf209c7b8750cad9b747 [file] [log] [blame]
John Bauman66b8ab22014-05-06 15:57:45 -04001//
John Baumand4ae8632014-05-06 16:18:33 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Nicolas Capens6407fe82015-02-10 16:27:49 -05007#ifndef _COMPILER_INCLUDED_
8#define _COMPILER_INCLUDED_
John Bauman66b8ab22014-05-06 15:57:45 -04009
Nicolas Capenscc863da2015-01-21 15:50:55 -050010#include "ExtensionBehavior.h"
11#include "InfoSink.h"
12#include "SymbolTable.h"
John Bauman66b8ab22014-05-06 15:57:45 -040013
Nicolas Capens6407fe82015-02-10 16:27:49 -050014enum 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//
29struct 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 Hetu6743bbf2015-04-21 17:06:14 -040042 int MaxVertexOutputVectors;
43 int MaxFragmentInputVectors;
44 int MinProgramTexelOffset;
45 int MaxProgramTexelOffset;
Nicolas Capens6407fe82015-02-10 16:27:49 -050046
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;
Nicolas Capensc66f0e32016-04-18 14:34:24 -040052 int EXT_draw_buffers;
Nicolas Capens6407fe82015-02-10 16:27:49 -050053
54 unsigned int MaxCallStackDepth;
55};
56
Nicolas Capens08ca3c62015-02-13 16:06:45 -050057typedef unsigned int GLenum;
58#define GL_FRAGMENT_SHADER 0x8B30
59#define GL_VERTEX_SHADER 0x8B31
60
Nicolas Capens6407fe82015-02-10 16:27:49 -050061//
John Bauman66b8ab22014-05-06 15:57:45 -040062// The base class for the machine dependent compiler to derive from
63// for managing object code from the compile.
64//
Nicolas Capens7a8ccc42015-02-10 15:42:31 -050065class TCompiler
66{
John Bauman66b8ab22014-05-06 15:57:45 -040067public:
Nicolas Capens08ca3c62015-02-13 16:06:45 -050068 TCompiler(GLenum shaderType);
John Bauman66b8ab22014-05-06 15:57:45 -040069 virtual ~TCompiler();
70 virtual TCompiler* getAsCompiler() { return this; }
71
72 bool Init(const ShBuiltInResources& resources);
73 bool compile(const char* const shaderStrings[],
74 const int numStrings,
75 int compileOptions);
76
77 // Get results of the last compilation.
Nicolas Capensb28964b2015-02-10 15:23:06 -050078 int getShaderVersion() const { return shaderVersion; }
John Bauman66b8ab22014-05-06 15:57:45 -040079 TInfoSink& getInfoSink() { return infoSink; }
John Bauman66b8ab22014-05-06 15:57:45 -040080
81protected:
Nicolas Capens08ca3c62015-02-13 16:06:45 -050082 GLenum getShaderType() const { return shaderType; }
John Bauman66b8ab22014-05-06 15:57:45 -040083 // Initialize symbol-table with built-in symbols.
84 bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
85 // Clears the results from the previous compilation.
86 void clearResults();
John Baumand4ae8632014-05-06 16:18:33 -040087 // Return true if function recursion is detected or call depth exceeded.
88 bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink);
John Bauman66b8ab22014-05-06 15:57:45 -040089 // Returns true if the given shader does not exceed the minimum
90 // functionality mandated in GLSL 1.0 spec Appendix A.
John Baumand4ae8632014-05-06 16:18:33 -040091 bool validateLimitations(TIntermNode *root);
John Bauman66b8ab22014-05-06 15:57:45 -040092 // Translate to object code.
Nicolas Capens014b9a62014-10-15 10:28:29 -040093 virtual bool translate(TIntermNode *root) = 0;
John Bauman66b8ab22014-05-06 15:57:45 -040094 // Get built-in extensions with default behavior.
95 const TExtensionBehavior& getExtensionBehavior() const;
96
97private:
Nicolas Capens08ca3c62015-02-13 16:06:45 -050098 GLenum shaderType;
John Bauman66b8ab22014-05-06 15:57:45 -040099
John Baumand4ae8632014-05-06 16:18:33 -0400100 unsigned int maxCallStackDepth;
101
John Bauman66b8ab22014-05-06 15:57:45 -0400102 // Built-in symbol table for the given language, spec, and resources.
103 // It is preserved from compile-to-compile.
104 TSymbolTable symbolTable;
105 // Built-in extensions with default behavior.
106 TExtensionBehavior extensionBehavior;
107
108 // Results of compilation.
Nicolas Capensb28964b2015-02-10 15:23:06 -0500109 int shaderVersion;
John Bauman66b8ab22014-05-06 15:57:45 -0400110 TInfoSink infoSink; // Output sink.
Nicolas Capens7a8ccc42015-02-10 15:42:31 -0500111
112 // Memory allocator. Allocates and tracks memory required by the compiler.
113 // Deallocates all memory when compiler is destructed.
114 TPoolAllocator allocator;
John Bauman66b8ab22014-05-06 15:57:45 -0400115};
116
Nicolas Capens6407fe82015-02-10 16:27:49 -0500117bool InitCompilerGlobals();
118void FreeCompilerGlobals();
John Bauman66b8ab22014-05-06 15:57:45 -0400119
Nicolas Capens6407fe82015-02-10 16:27:49 -0500120#endif // _COMPILER_INCLUDED_