blob: 8294abf410f5f67a5178a386e40585949862b0c3 [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
7#ifndef _SHHANDLE_INCLUDED_
8#define _SHHANDLE_INCLUDED_
9
10//
11// Machine independent part of the compiler private objects
12// sent as ShHandle to the driver.
13//
14// This should not be included by driver code.
15//
16
17#include "GLSLANG/ShaderLang.h"
18
19#include "compiler/ExtensionBehavior.h"
20#include "compiler/InfoSink.h"
21#include "compiler/SymbolTable.h"
22#include "compiler/VariableInfo.h"
23
24class TCompiler;
25
26//
27// The base class used to back handles returned to the driver.
28//
29class TShHandleBase {
30public:
31 TShHandleBase();
32 virtual ~TShHandleBase();
33 virtual TCompiler* getAsCompiler() { return 0; }
34
35protected:
36 // Memory allocator. Allocates and tracks memory required by the compiler.
37 // Deallocates all memory when compiler is destructed.
38 TPoolAllocator allocator;
39};
40
41//
42// The base class for the machine dependent compiler to derive from
43// for managing object code from the compile.
44//
45class TCompiler : public TShHandleBase {
46public:
47 TCompiler(ShShaderType type, ShShaderSpec spec);
48 virtual ~TCompiler();
49 virtual TCompiler* getAsCompiler() { return this; }
50
51 bool Init(const ShBuiltInResources& resources);
52 bool compile(const char* const shaderStrings[],
53 const int numStrings,
54 int compileOptions);
55
56 // Get results of the last compilation.
57 TInfoSink& getInfoSink() { return infoSink; }
58 const TVariableInfoList& getAttribs() const { return attribs; }
59 const TVariableInfoList& getUniforms() const { return uniforms; }
60
61protected:
62 ShShaderType getShaderType() const { return shaderType; }
63 ShShaderSpec getShaderSpec() const { return shaderSpec; }
64 // Initialize symbol-table with built-in symbols.
65 bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
66 // Clears the results from the previous compilation.
67 void clearResults();
John Baumand4ae8632014-05-06 16:18:33 -040068 // Return true if function recursion is detected or call depth exceeded.
69 bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink);
John Bauman66b8ab22014-05-06 15:57:45 -040070 // Returns true if the given shader does not exceed the minimum
71 // functionality mandated in GLSL 1.0 spec Appendix A.
John Baumand4ae8632014-05-06 16:18:33 -040072 bool validateLimitations(TIntermNode *root);
John Bauman66b8ab22014-05-06 15:57:45 -040073 // Collect info for all attribs and uniforms.
John Baumand4ae8632014-05-06 16:18:33 -040074 void collectAttribsUniforms(TIntermNode *root);
John Bauman66b8ab22014-05-06 15:57:45 -040075 // Translate to object code.
John Baumand4ae8632014-05-06 16:18:33 -040076 virtual void translate(TIntermNode *root) = 0;
John Bauman66b8ab22014-05-06 15:57:45 -040077 // Get built-in extensions with default behavior.
78 const TExtensionBehavior& getExtensionBehavior() const;
79
80private:
81 ShShaderType shaderType;
82 ShShaderSpec shaderSpec;
83
John Baumand4ae8632014-05-06 16:18:33 -040084 unsigned int maxCallStackDepth;
85
John Bauman66b8ab22014-05-06 15:57:45 -040086 // Built-in symbol table for the given language, spec, and resources.
87 // It is preserved from compile-to-compile.
88 TSymbolTable symbolTable;
89 // Built-in extensions with default behavior.
90 TExtensionBehavior extensionBehavior;
91
92 // Results of compilation.
93 TInfoSink infoSink; // Output sink.
94 TVariableInfoList attribs; // Active attributes in the compiled shader.
95 TVariableInfoList uniforms; // Active uniforms in the compiled shader.
96};
97
98//
99// This is the interface between the machine independent code
100// and the machine dependent code.
101//
102// The machine dependent code should derive from the classes
103// above. Then Construct*() and Delete*() will create and
104// destroy the machine dependent objects, which contain the
105// above machine independent information.
106//
107TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec);
108void DeleteCompiler(TCompiler*);
109
110#endif // _SHHANDLE_INCLUDED_