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.
6
#ifndef _COMPILER_INTERFACE_INCLUDED_
7
#define _COMPILER_INTERFACE_INCLUDED_
9
#if defined(COMPONENT_BUILD)
10
#if defined(_WIN32) || defined(_WIN64)
12
#if defined(COMPILER_IMPLEMENTATION)
13
#define COMPILER_EXPORT __declspec(dllexport)
15
#define COMPILER_EXPORT __declspec(dllimport)
16
#endif // defined(COMPILER_IMPLEMENTATION)
18
#else // defined(WIN32)
19
#define COMPILER_EXPORT __attribute__((visibility("default")))
22
#else // defined(COMPONENT_BUILD)
23
#define COMPILER_EXPORT
27
// This is the platform independent interface between an OGL driver
28
// and the shading language compiler.
35
// Version number for shader translation API.
36
// It is incremented everytime the API changes.
37
#define SH_VERSION 107
40
// The names of the following enums have been derived by replacing GL prefix
41
// with SH. For example, SH_INFO_LOG_LENGTH is equivalent to GL_INFO_LOG_LENGTH.
42
// The enum values are also equal to the values of their GL counterpart. This
43
// is done to make it easier for applications to use the shader library.
46
SH_FRAGMENT_SHADER = 0x8B30,
47
SH_VERTEX_SHADER = 0x8B31
51
SH_GLES2_SPEC = 0x8B40,
52
SH_WEBGL_SPEC = 0x8B41,
54
// The CSS Shaders spec is a subset of the WebGL spec.
56
// In both CSS vertex and fragment shaders, ANGLE:
57
// (1) Reserves the "css_" prefix.
58
// (2) Renames the main function to css_main.
59
// (3) Disables the gl_MaxDrawBuffers built-in.
61
// In CSS fragment shaders, ANGLE:
62
// (1) Disables the gl_FragColor built-in.
63
// (2) Disables the gl_FragData built-in.
64
// (3) Enables the css_MixColor built-in.
65
// (4) Enables the css_ColorMatrix built-in.
67
// After passing a CSS shader through ANGLE, the browser is expected to append
68
// a new main function to it.
69
// This new main function will call the css_main function.
70
// It may also perform additional operations like varying assignment, texture
71
// access, and gl_FragColor assignment in order to implement the CSS Shaders
74
SH_CSS_SHADERS_SPEC = 0x8B42
78
SH_ESSL_OUTPUT = 0x8B45,
79
SH_GLSL_OUTPUT = 0x8B46,
80
SH_HLSL_OUTPUT = 0x8B47
87
SH_FLOAT_VEC2 = 0x8B50,
88
SH_FLOAT_VEC3 = 0x8B51,
89
SH_FLOAT_VEC4 = 0x8B52,
94
SH_BOOL_VEC2 = 0x8B57,
95
SH_BOOL_VEC3 = 0x8B58,
96
SH_BOOL_VEC4 = 0x8B59,
97
SH_FLOAT_MAT2 = 0x8B5A,
98
SH_FLOAT_MAT3 = 0x8B5B,
99
SH_FLOAT_MAT4 = 0x8B5C,
100
SH_SAMPLER_2D = 0x8B5E,
101
SH_SAMPLER_CUBE = 0x8B60,
102
SH_SAMPLER_2D_RECT_ARB = 0x8B63,
103
SH_SAMPLER_EXTERNAL_OES = 0x8D66
107
SH_INFO_LOG_LENGTH = 0x8B84,
108
SH_OBJECT_CODE_LENGTH = 0x8B88, // GL_SHADER_SOURCE_LENGTH
109
SH_ACTIVE_UNIFORMS = 0x8B86,
110
SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
111
SH_ACTIVE_ATTRIBUTES = 0x8B89,
112
SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
113
SH_MAPPED_NAME_MAX_LENGTH = 0x8B8B
119
SH_VALIDATE_LOOP_INDEXING = 0x0001,
120
SH_INTERMEDIATE_TREE = 0x0002,
121
SH_OBJECT_CODE = 0x0004,
122
SH_ATTRIBUTES_UNIFORMS = 0x0008,
123
SH_LINE_DIRECTIVES = 0x0010,
124
SH_SOURCE_PATH = 0x0020,
125
SH_MAP_LONG_VARIABLE_NAMES = 0x0040,
126
SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX = 0x0080,
128
// This is needed only as a workaround for certain OpenGL driver bugs.
129
SH_EMULATE_BUILT_IN_FUNCTIONS = 0x0100,
131
// This is an experimental flag to enforce restrictions that aim to prevent
133
// It generates compilation errors for shaders that could expose sensitive
134
// texture information via the timing channel.
135
// To use this flag, you must compile the shader under the WebGL spec
136
// (using the SH_WEBGL_SPEC flag).
137
SH_TIMING_RESTRICTIONS = 0x0200,
139
// This flag prints the dependency graph that is used to enforce timing
140
// restrictions on fragment shaders.
141
// This flag only has an effect if all of the following are true:
142
// - The shader spec is SH_WEBGL_SPEC.
143
// - The compile options contain the SH_TIMING_RESTRICTIONS flag.
144
// - The shader type is SH_FRAGMENT_SHADER.
145
SH_DEPENDENCY_GRAPH = 0x0400,
147
// Enforce the GLSL 1.017 Appendix A section 7 packing restrictions.
148
SH_ENFORCE_PACKING_RESTRICTIONS = 0x0800,
152
// Driver must call this first, once, before doing any other
153
// compiler operations.
154
// If the function succeeds, the return value is nonzero, else zero.
156
COMPILER_EXPORT int ShInitialize();
158
// Driver should call this at shutdown.
159
// If the function succeeds, the return value is nonzero, else zero.
161
COMPILER_EXPORT int ShFinalize();
164
// Implementation dependent built-in resources (constants and extensions).
165
// The names for these resources has been obtained by stripping gl_/GL_.
170
int MaxVertexAttribs;
171
int MaxVertexUniformVectors;
172
int MaxVaryingVectors;
173
int MaxVertexTextureImageUnits;
174
int MaxCombinedTextureImageUnits;
175
int MaxTextureImageUnits;
176
int MaxFragmentUniformVectors;
180
// Set to 1 to enable the extension, else 0.
181
int OES_standard_derivatives;
182
int OES_EGL_image_external;
183
int ARB_texture_rectangle;
184
} ShBuiltInResources;
187
// Initialize built-in resources with minimum expected values.
189
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources);
192
// ShHandle held by but opaque to the driver. It is allocated,
193
// managed, and de-allocated by the compiler. It's contents
194
// are defined by and used by the compiler.
196
// If handle creation fails, 0 will be returned.
198
typedef void* ShHandle;
201
// Driver calls these to create and destroy compiler objects.
203
// Returns the handle of constructed compiler, null if the requested compiler is
206
// type: Specifies the type of shader - SH_FRAGMENT_SHADER or SH_VERTEX_SHADER.
207
// spec: Specifies the language spec the compiler must conform to -
208
// SH_GLES2_SPEC or SH_WEBGL_SPEC.
209
// output: Specifies the output code type - SH_ESSL_OUTPUT, SH_GLSL_OUTPUT,
210
// or SH_HLSL_OUTPUT.
211
// resources: Specifies the built-in resources.
212
COMPILER_EXPORT ShHandle ShConstructCompiler(
215
ShShaderOutput output,
216
const ShBuiltInResources* resources);
217
COMPILER_EXPORT void ShDestruct(ShHandle handle);
220
// Compiles the given shader source.
221
// If the function succeeds, the return value is nonzero, else zero.
223
// handle: Specifies the handle of compiler to be used.
224
// shaderStrings: Specifies an array of pointers to null-terminated strings
225
// containing the shader source code.
226
// numStrings: Specifies the number of elements in shaderStrings array.
227
// compileOptions: A mask containing the following parameters:
228
// SH_VALIDATE: Validates shader to ensure that it conforms to the spec
229
// specified during compiler construction.
230
// SH_VALIDATE_LOOP_INDEXING: Validates loop and indexing in the shader to
231
// ensure that they do not exceed the minimum
232
// functionality mandated in GLSL 1.0 spec,
233
// Appendix A, Section 4 and 5.
234
// There is no need to specify this parameter when
235
// compiling for WebGL - it is implied.
236
// SH_INTERMEDIATE_TREE: Writes intermediate tree to info log.
237
// Can be queried by calling ShGetInfoLog().
238
// SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader.
239
// Can be queried by calling ShGetObjectCode().
240
// SH_ATTRIBUTES_UNIFORMS: Extracts attributes and uniforms.
241
// Can be queried by calling ShGetActiveAttrib() and
242
// ShGetActiveUniform().
244
COMPILER_EXPORT int ShCompile(
245
const ShHandle handle,
246
const char* const shaderStrings[],
247
const int numStrings,
251
// Returns a parameter from a compiled shader.
253
// handle: Specifies the compiler
254
// pname: Specifies the parameter to query.
255
// The following parameters are defined:
256
// SH_INFO_LOG_LENGTH: the number of characters in the information log
257
// including the null termination character.
258
// SH_OBJECT_CODE_LENGTH: the number of characters in the object code
259
// including the null termination character.
260
// SH_ACTIVE_ATTRIBUTES: the number of active attribute variables.
261
// SH_ACTIVE_ATTRIBUTE_MAX_LENGTH: the length of the longest active attribute
262
// variable name including the null
263
// termination character.
264
// SH_ACTIVE_UNIFORMS: the number of active uniform variables.
265
// SH_ACTIVE_UNIFORM_MAX_LENGTH: the length of the longest active uniform
266
// variable name including the null
267
// termination character.
268
// SH_MAPPED_NAME_MAX_LENGTH: the length of the mapped variable name including
269
// the null termination character.
271
// params: Requested parameter
272
COMPILER_EXPORT void ShGetInfo(const ShHandle handle,
276
// Returns nul-terminated information log for a compiled shader.
278
// handle: Specifies the compiler
279
// infoLog: Specifies an array of characters that is used to return
280
// the information log. It is assumed that infoLog has enough memory
281
// to accomodate the information log. The size of the buffer required
282
// to store the returned information log can be obtained by calling
283
// ShGetInfo with SH_INFO_LOG_LENGTH.
284
COMPILER_EXPORT void ShGetInfoLog(const ShHandle handle, char* infoLog);
286
// Returns null-terminated object code for a compiled shader.
288
// handle: Specifies the compiler
289
// infoLog: Specifies an array of characters that is used to return
290
// the object code. It is assumed that infoLog has enough memory to
291
// accomodate the object code. The size of the buffer required to
292
// store the returned object code can be obtained by calling
293
// ShGetInfo with SH_OBJECT_CODE_LENGTH.
294
COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode);
296
// Returns information about an active attribute variable.
298
// handle: Specifies the compiler
299
// index: Specifies the index of the attribute variable to be queried.
300
// length: Returns the number of characters actually written in the string
301
// indicated by name (excluding the null terminator) if a value other
302
// than NULL is passed.
303
// size: Returns the size of the attribute variable.
304
// type: Returns the data type of the attribute variable.
305
// name: Returns a null terminated string containing the name of the
306
// attribute variable. It is assumed that name has enough memory to
307
// accomodate the attribute variable name. The size of the buffer
308
// required to store the attribute variable name can be obtained by
309
// calling ShGetInfo with SH_ACTIVE_ATTRIBUTE_MAX_LENGTH.
310
// mappedName: Returns a null terminated string containing the mapped name of
311
// the attribute variable, It is assumed that mappedName has enough
312
// memory (SH_MAPPED_NAME_MAX_LENGTH), or NULL if don't care
313
// about the mapped name. If the name is not mapped, then name and
314
// mappedName are the same.
315
COMPILER_EXPORT void ShGetActiveAttrib(const ShHandle handle,
323
// Returns information about an active uniform variable.
325
// handle: Specifies the compiler
326
// index: Specifies the index of the uniform variable to be queried.
327
// length: Returns the number of characters actually written in the string
328
// indicated by name (excluding the null terminator) if a value
329
// other than NULL is passed.
330
// size: Returns the size of the uniform variable.
331
// type: Returns the data type of the uniform variable.
332
// name: Returns a null terminated string containing the name of the
333
// uniform variable. It is assumed that name has enough memory to
334
// accomodate the uniform variable name. The size of the buffer required
335
// to store the uniform variable name can be obtained by calling
336
// ShGetInfo with SH_ACTIVE_UNIFORMS_MAX_LENGTH.
337
// mappedName: Returns a null terminated string containing the mapped name of
338
// the uniform variable, It is assumed that mappedName has enough
339
// memory (SH_MAPPED_NAME_MAX_LENGTH), or NULL if don't care
340
// about the mapped name. If the name is not mapped, then name and
341
// mappedName are the same.
342
COMPILER_EXPORT void ShGetActiveUniform(const ShHandle handle,
354
#endif // _COMPILER_INTERFACE_INCLUDED_