blob: 76c53bcadf1233639574ab019ff98ad43c9f7d89 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3// 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
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000017#include "GLSLANG/ShaderLang.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000018
alokp@chromium.orgad771eb2010-09-07 17:36:23 +000019#include "compiler/ExtensionBehavior.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000020#include "compiler/InfoSink.h"
alokp@chromium.orge4249f02010-07-26 18:13:52 +000021#include "compiler/SymbolTable.h"
alokp@chromium.org07620a52010-09-23 17:53:56 +000022#include "compiler/VariableInfo.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000023
24class TCompiler;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025
26//
27// The base class used to back handles returned to the driver.
28//
29class TShHandleBase {
30public:
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000031 TShHandleBase();
32 virtual ~TShHandleBase();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033 virtual TCompiler* getAsCompiler() { return 0; }
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +000034
35protected:
36 // Memory allocator. Allocates and tracks memory required by the compiler.
37 // Deallocates all memory when compiler is destructed.
38 TPoolAllocator allocator;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039};
40
41//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000042// 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:
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000047 TCompiler(ShShaderType type, ShShaderSpec spec);
48 virtual ~TCompiler();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000049 virtual TCompiler* getAsCompiler() { return this; }
alokp@chromium.org76b82082010-03-24 17:59:39 +000050
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000051 bool Init(const ShBuiltInResources& resources);
alokp@chromium.org07620a52010-09-23 17:53:56 +000052 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; }
zmo@google.comfd747b82011-04-23 01:30:07 +000060 int getMappedNameMaxLength() const;
alokp@chromium.org07620a52010-09-23 17:53:56 +000061
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000062protected:
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000063 ShShaderType getShaderType() const { return shaderType; }
64 ShShaderSpec getShaderSpec() const { return shaderSpec; }
alokp@chromium.org07620a52010-09-23 17:53:56 +000065 // Initialize symbol-table with built-in symbols.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000066 bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
alokp@chromium.org07620a52010-09-23 17:53:56 +000067 // Clears the results from the previous compilation.
68 void clearResults();
zmo@google.comb1762df2011-07-30 02:04:23 +000069 // Return true if function recursion is detected.
70 bool detectRecursion(TIntermNode* root);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000071 // Returns true if the given shader does not exceed the minimum
72 // functionality mandated in GLSL 1.0 spec Appendix A.
73 bool validateLimitations(TIntermNode* root);
alokp@chromium.org07620a52010-09-23 17:53:56 +000074 // Collect info for all attribs and uniforms.
75 void collectAttribsUniforms(TIntermNode* root);
zmo@google.comfd747b82011-04-23 01:30:07 +000076 // Map long variable names into shorter ones.
77 void mapLongVariableNames(TIntermNode* root);
alokp@chromium.org07620a52010-09-23 17:53:56 +000078 // Translate to object code.
79 virtual void translate(TIntermNode* root) = 0;
zmo@google.com5601ea02011-06-10 18:23:25 +000080 // Get built-in extensions with default behavior.
81 const TExtensionBehavior& getExtensionBehavior() const;
alokp@chromium.org07620a52010-09-23 17:53:56 +000082
83private:
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000084 ShShaderType shaderType;
85 ShShaderSpec shaderSpec;
alokp@chromium.orge4249f02010-07-26 18:13:52 +000086
87 // Built-in symbol table for the given language, spec, and resources.
88 // It is preserved from compile-to-compile.
89 TSymbolTable symbolTable;
alokp@chromium.orgad771eb2010-09-07 17:36:23 +000090 // Built-in extensions with default behavior.
91 TExtensionBehavior extensionBehavior;
alokp@chromium.org07620a52010-09-23 17:53:56 +000092
93 // Results of compilation.
94 TInfoSink infoSink; // Output sink.
95 TVariableInfoList attribs; // Active attributes in the compiled shader.
96 TVariableInfoList uniforms; // Active uniforms in the compiled shader.
zmo@google.com24c08c42011-05-27 17:40:48 +000097
98 // Pair of long varying varibale name <originalName, mappedName>.
99 TMap<TString, TString> varyingLongNameMap;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000100};
101
102//
103// This is the interface between the machine independent code
104// and the machine dependent code.
105//
106// The machine dependent code should derive from the classes
107// above. Then Construct*() and Delete*() will create and
108// destroy the machine dependent objects, which contain the
109// above machine independent information.
110//
zmo@google.com5601ea02011-06-10 18:23:25 +0000111TCompiler* ConstructCompiler(
112 ShShaderType type, ShShaderSpec spec, ShShaderOutput output);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000113void DeleteCompiler(TCompiler*);
114
daniel@transgaming.com5cb728c2011-05-17 18:34:24 +0000115#endif // _SHHANDLE_INCLUDED_