blob: 5383f7bd45db409578f1cf42b276fc743839e810 [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//
alokp@chromium.org774d7062010-07-21 18:55:45 +00008// Implement the top-level of interface to the compiler,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009// as defined in ShaderLang.h
10//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000012#include "GLSLANG/ShaderLang.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000013
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000014#include "compiler/Initialize.h"
15#include "compiler/InitializeDll.h"
16#include "compiler/ParseHelper.h"
17#include "compiler/ShHandle.h"
18#include "compiler/SymbolTable.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000019
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000020//
21// This is the platform independent interface between an OGL driver
alokp@chromium.org774d7062010-07-21 18:55:45 +000022// and the shading language compiler.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000023//
24
25//
26// Driver must call this first, once, before doing any other
alokp@chromium.org774d7062010-07-21 18:55:45 +000027// compiler operations.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000028//
29int ShInitialize()
30{
alokp@chromium.org34b99cd2010-07-27 18:37:55 +000031 if (!InitProcess())
32 return 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033
alokp@chromium.org34b99cd2010-07-27 18:37:55 +000034 return 1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000035}
36
37//
alokp@chromium.org94a86ad2010-08-25 20:02:11 +000038// Cleanup symbol tables
39//
40int ShFinalize()
41{
42 if (!DetachProcess())
43 return 0;
44
45 return 1;
46}
47
48//
49// Initialize built-in resources with minimum expected values.
50//
51void ShInitBuiltInResource(TBuiltInResource* resources)
52{
53 // Constants.
54 resources->MaxVertexAttribs = 8;
55 resources->MaxVertexUniformVectors = 128;
56 resources->MaxVaryingVectors = 8;
57 resources->MaxVertexTextureImageUnits = 0;
58 resources->MaxCombinedTextureImageUnits = 8;
59 resources->MaxTextureImageUnits = 8;
60 resources->MaxFragmentUniformVectors = 16;
61 resources->MaxDrawBuffers = 1;
62
63 // Extensions.
64 resources->OES_standard_derivatives = 0;
65}
66
67//
alokp@chromium.org774d7062010-07-21 18:55:45 +000068// Driver calls these to create and destroy compiler objects.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000069//
alokp@chromium.orge4249f02010-07-26 18:13:52 +000070ShHandle ShConstructCompiler(EShLanguage language, EShSpec spec, const TBuiltInResource* resources)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000071{
72 if (!InitThread())
73 return 0;
74
alokp@chromium.org29cd91a2010-07-16 19:30:45 +000075 TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(language, spec));
alokp@chromium.orge4249f02010-07-26 18:13:52 +000076 TCompiler* compiler = base->getAsCompiler();
77 if (compiler == 0)
78 return 0;
79
80 // Generate built-in symbol table.
alokp@chromium.org07620a52010-09-23 17:53:56 +000081 if (!compiler->Init(*resources)) {
alokp@chromium.orge4249f02010-07-26 18:13:52 +000082 ShDestruct(base);
83 return 0;
84 }
85
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000086 return reinterpret_cast<void*>(base);
87}
88
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000089void ShDestruct(ShHandle handle)
90{
91 if (handle == 0)
92 return;
93
94 TShHandleBase* base = static_cast<TShHandleBase*>(handle);
95
96 if (base->getAsCompiler())
97 DeleteCompiler(base->getAsCompiler());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000098}
99
100//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000101// Do an actual compile on the given strings. The result is left
102// in the given compile object.
103//
104// Return: The return value of ShCompile is really boolean, indicating
105// success or failure.
106//
107int ShCompile(
108 const ShHandle handle,
109 const char* const shaderStrings[],
110 const int numStrings,
alokp@chromium.org7beea402010-09-15 21:18:34 +0000111 int compileOptions)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000112{
113 if (!InitThread())
114 return 0;
115
116 if (handle == 0)
117 return 0;
118
119 TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
120 TCompiler* compiler = base->getAsCompiler();
121 if (compiler == 0)
122 return 0;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000123
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000124 GlobalPoolAllocator.push();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000125
alokp@chromium.org07620a52010-09-23 17:53:56 +0000126 bool success = compiler->compile(shaderStrings, numStrings, compileOptions);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000127
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000128 //
129 // Throw away all the temporary memory used by the compilation process.
130 //
131 GlobalPoolAllocator.pop();
132
133 return success ? 1 : 0;
134}
135
alokp@chromium.org7beea402010-09-15 21:18:34 +0000136void ShGetInfo(const ShHandle handle, EShInfo pname, int* params)
137{
138 if (!handle || !params)
139 return;
140
141 TShHandleBase* base = static_cast<TShHandleBase*>(handle);
142 TCompiler* compiler = base->getAsCompiler();
143 if (!compiler) return;
144
145 switch(pname)
146 {
147 case SH_INFO_LOG_LENGTH:
148 *params = compiler->getInfoSink().info.size() + 1;
149 break;
150 case SH_OBJECT_CODE_LENGTH:
151 *params = compiler->getInfoSink().obj.size() + 1;
152 break;
153 case SH_ACTIVE_UNIFORMS:
154 UNIMPLEMENTED();
155 break;
156 case SH_ACTIVE_UNIFORM_MAX_LENGTH:
157 UNIMPLEMENTED();
158 break;
159 case SH_ACTIVE_ATTRIBUTES:
160 UNIMPLEMENTED();
161 break;
162 case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH:
163 UNIMPLEMENTED();
164 break;
165
166 default: UNREACHABLE();
167 }
168}
169
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000170//
alokp@chromium.org774d7062010-07-21 18:55:45 +0000171// Return any compiler log of messages for the application.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000172//
alokp@chromium.org7beea402010-09-15 21:18:34 +0000173void ShGetInfoLog(const ShHandle handle, char* infoLog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000174{
alokp@chromium.org7beea402010-09-15 21:18:34 +0000175 if (!handle || !infoLog)
176 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000177
178 TShHandleBase* base = static_cast<TShHandleBase*>(handle);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000179 TCompiler* compiler = base->getAsCompiler();
180 if (!compiler) return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000181
alokp@chromium.org7beea402010-09-15 21:18:34 +0000182 TInfoSink& infoSink = compiler->getInfoSink();
183 strcpy(infoLog, infoSink.info.c_str());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000184}
185
186//
alokp@chromium.org774d7062010-07-21 18:55:45 +0000187// Return any object code.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000188//
alokp@chromium.org7beea402010-09-15 21:18:34 +0000189void ShGetObjectCode(const ShHandle handle, char* objCode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000190{
alokp@chromium.org7beea402010-09-15 21:18:34 +0000191 if (!handle || !objCode)
192 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000193
194 TShHandleBase* base = static_cast<TShHandleBase*>(handle);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000195 TCompiler* compiler = base->getAsCompiler();
196 if (!compiler) return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000197
alokp@chromium.org7beea402010-09-15 21:18:34 +0000198 TInfoSink& infoSink = compiler->getInfoSink();
199 strcpy(objCode, infoSink.obj.c_str());
200}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000201
alokp@chromium.org7beea402010-09-15 21:18:34 +0000202void ShGetActiveAttrib(const ShHandle handle,
203 int index,
204 int* length,
205 int* size,
206 EShDataType* type,
207 char* name)
208{
209 UNIMPLEMENTED();
210}
211
212void ShGetActiveUniform(const ShHandle handle,
213 int index,
214 int* length,
215 int* size,
216 EShDataType* type,
217 char* name)
218{
219 UNIMPLEMENTED();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000220}