blob: c38fdae96cd167fd71ec1103fe78dcf67f498a22 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
shannon.woods@transgaming.comb73964e2013-01-25 21:49:14 +00002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6#ifndef _COMPILER_INTERFACE_INCLUDED_
7#define _COMPILER_INTERFACE_INCLUDED_
8
Geoff Lang31f0dc02013-10-08 13:29:13 -04009#if defined(COMPONENT_BUILD) && !defined(ANGLE_TRANSLATOR_STATIC)
apatrick@chromium.org22eab922011-10-21 01:16:42 +000010#if defined(_WIN32) || defined(_WIN64)
11
Geoff Lang31f0dc02013-10-08 13:29:13 -040012#if defined(ANGLE_TRANSLATOR_IMPLEMENTATION)
apatrick@chromium.org22eab922011-10-21 01:16:42 +000013#define COMPILER_EXPORT __declspec(dllexport)
14#else
15#define COMPILER_EXPORT __declspec(dllimport)
Geoff Lang31f0dc02013-10-08 13:29:13 -040016#endif // defined(ANGLE_TRANSLATOR_IMPLEMENTATION)
apatrick@chromium.org22eab922011-10-21 01:16:42 +000017
Geoff Lang31f0dc02013-10-08 13:29:13 -040018#else // defined(_WIN32) || defined(_WIN64)
apatrick@chromium.org22eab922011-10-21 01:16:42 +000019#define COMPILER_EXPORT __attribute__((visibility("default")))
20#endif
21
Geoff Lang31f0dc02013-10-08 13:29:13 -040022#else // defined(COMPONENT_BUILD) && !defined(ANGLE_TRANSLATOR_STATIC)
apatrick@chromium.org22eab922011-10-21 01:16:42 +000023#define COMPILER_EXPORT
24#endif
25
daniel@transgaming.comc23f4612012-11-28 19:42:57 +000026#include "KHR/khrplatform.h"
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000027#include <stddef.h>
daniel@transgaming.comc23f4612012-11-28 19:42:57 +000028
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000029//
30// This is the platform independent interface between an OGL driver
alokp@chromium.org774d7062010-07-21 18:55:45 +000031// and the shading language compiler.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000032//
33
34#ifdef __cplusplus
alokp@chromium.org774d7062010-07-21 18:55:45 +000035extern "C" {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000036#endif
alokp@chromium.org2fa73692010-09-28 17:20:39 +000037
38// Version number for shader translation API.
Nicolas Capens344e7142013-06-24 15:39:21 -040039// It is incremented every time the API changes.
Jamie Madill68fe74a2014-05-27 12:56:01 -040040#define ANGLE_SH_VERSION 125
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000041
42//
43// The names of the following enums have been derived by replacing GL prefix
44// with SH. For example, SH_INFO_LOG_LENGTH is equivalent to GL_INFO_LOG_LENGTH.
45// The enum values are also equal to the values of their GL counterpart. This
46// is done to make it easier for applications to use the shader library.
47//
48typedef enum {
49 SH_FRAGMENT_SHADER = 0x8B30,
50 SH_VERTEX_SHADER = 0x8B31
51} ShShaderType;
52
53typedef enum {
54 SH_GLES2_SPEC = 0x8B40,
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000055 SH_WEBGL_SPEC = 0x8B41,
56
57 // The CSS Shaders spec is a subset of the WebGL spec.
58 //
59 // In both CSS vertex and fragment shaders, ANGLE:
60 // (1) Reserves the "css_" prefix.
61 // (2) Renames the main function to css_main.
62 // (3) Disables the gl_MaxDrawBuffers built-in.
63 //
64 // In CSS fragment shaders, ANGLE:
65 // (1) Disables the gl_FragColor built-in.
66 // (2) Disables the gl_FragData built-in.
67 // (3) Enables the css_MixColor built-in.
68 // (4) Enables the css_ColorMatrix built-in.
69 //
70 // After passing a CSS shader through ANGLE, the browser is expected to append
71 // a new main function to it.
72 // This new main function will call the css_main function.
73 // It may also perform additional operations like varying assignment, texture
74 // access, and gl_FragColor assignment in order to implement the CSS Shaders
75 // blend modes.
76 //
77 SH_CSS_SHADERS_SPEC = 0x8B42
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000078} ShShaderSpec;
79
80typedef enum {
shannon.woods@transgaming.comb73964e2013-01-25 21:49:14 +000081 SH_ESSL_OUTPUT = 0x8B45,
82 SH_GLSL_OUTPUT = 0x8B46,
shannon.woods@transgaming.com82043342013-01-25 21:49:34 +000083 SH_HLSL_OUTPUT = 0x8B47,
shannon.woods@transgaming.comb73964e2013-01-25 21:49:14 +000084 SH_HLSL9_OUTPUT = 0x8B47,
85 SH_HLSL11_OUTPUT = 0x8B48
zmo@google.com5601ea02011-06-10 18:23:25 +000086} ShShaderOutput;
87
88typedef enum {
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000089 SH_NONE = 0,
90 SH_INT = 0x1404,
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +000091 SH_UNSIGNED_INT = 0x1405,
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000092 SH_FLOAT = 0x1406,
93 SH_FLOAT_VEC2 = 0x8B50,
94 SH_FLOAT_VEC3 = 0x8B51,
95 SH_FLOAT_VEC4 = 0x8B52,
96 SH_INT_VEC2 = 0x8B53,
97 SH_INT_VEC3 = 0x8B54,
98 SH_INT_VEC4 = 0x8B55,
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +000099 SH_UNSIGNED_INT_VEC2 = 0x8DC6,
100 SH_UNSIGNED_INT_VEC3 = 0x8DC7,
101 SH_UNSIGNED_INT_VEC4 = 0x8DC8,
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000102 SH_BOOL = 0x8B56,
103 SH_BOOL_VEC2 = 0x8B57,
104 SH_BOOL_VEC3 = 0x8B58,
105 SH_BOOL_VEC4 = 0x8B59,
106 SH_FLOAT_MAT2 = 0x8B5A,
107 SH_FLOAT_MAT3 = 0x8B5B,
108 SH_FLOAT_MAT4 = 0x8B5C,
shannonwoods@chromium.org8da034c2013-05-30 00:19:15 +0000109 SH_FLOAT_MAT2x3 = 0x8B65,
110 SH_FLOAT_MAT2x4 = 0x8B66,
111 SH_FLOAT_MAT3x2 = 0x8B67,
112 SH_FLOAT_MAT3x4 = 0x8B68,
113 SH_FLOAT_MAT4x2 = 0x8B69,
114 SH_FLOAT_MAT4x3 = 0x8B6A,
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000115 SH_SAMPLER_2D = 0x8B5E,
Nicolas Capensda075352013-06-24 16:02:56 -0400116 SH_SAMPLER_3D = 0x8B5F,
kbr@chromium.org205fef32011-11-22 20:50:02 +0000117 SH_SAMPLER_CUBE = 0x8B60,
apatrick@chromium.org65756022012-01-17 21:45:38 +0000118 SH_SAMPLER_2D_RECT_ARB = 0x8B63,
Nicolas Capens344e7142013-06-24 15:39:21 -0400119 SH_SAMPLER_EXTERNAL_OES = 0x8D66,
Nicolas Capens8772b582013-06-24 16:14:19 -0400120 SH_SAMPLER_2D_ARRAY = 0x8DC1,
Nicolas Capens344e7142013-06-24 15:39:21 -0400121 SH_INT_SAMPLER_2D = 0x8DCA,
Nicolas Capensda075352013-06-24 16:02:56 -0400122 SH_INT_SAMPLER_3D = 0x8DCB,
Nicolas Capens344e7142013-06-24 15:39:21 -0400123 SH_INT_SAMPLER_CUBE = 0x8DCC,
Nicolas Capens8772b582013-06-24 16:14:19 -0400124 SH_INT_SAMPLER_2D_ARRAY = 0x8DCF,
Nicolas Capens2ffe0bb2013-06-24 15:56:19 -0400125 SH_UNSIGNED_INT_SAMPLER_2D = 0x8DD2,
Nicolas Capensda075352013-06-24 16:02:56 -0400126 SH_UNSIGNED_INT_SAMPLER_3D = 0x8DD3,
Nicolas Capens2ffe0bb2013-06-24 15:56:19 -0400127 SH_UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4,
Nicolas Capens2a1d8a32013-07-18 11:49:40 -0400128 SH_UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7,
129 SH_SAMPLER_2D_SHADOW = 0x8B62,
130 SH_SAMPLER_CUBE_SHADOW = 0x8DC5,
131 SH_SAMPLER_2D_ARRAY_SHADOW = 0x8DC4
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000132} ShDataType;
133
134typedef enum {
Zhenyao Mofa3c3462013-09-23 14:57:04 -0400135 SH_PRECISION_HIGHP = 0x5001,
136 SH_PRECISION_MEDIUMP = 0x5002,
137 SH_PRECISION_LOWP = 0x5003,
138 SH_PRECISION_UNDEFINED = 0
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400139} ShPrecisionType;
140
141typedef enum {
Jamie Madill47fdd132013-08-30 13:21:04 -0400142 SH_INFO_LOG_LENGTH = 0x8B84,
143 SH_OBJECT_CODE_LENGTH = 0x8B88, // GL_SHADER_SOURCE_LENGTH
144 SH_ACTIVE_UNIFORMS = 0x8B86,
145 SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
146 SH_ACTIVE_ATTRIBUTES = 0x8B89,
147 SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400148 SH_VARYINGS = 0x8BBB,
149 SH_VARYING_MAX_LENGTH = 0x8BBC,
Jamie Madill47fdd132013-08-30 13:21:04 -0400150 SH_MAPPED_NAME_MAX_LENGTH = 0x6000,
151 SH_NAME_MAX_LENGTH = 0x6001,
152 SH_HASHED_NAME_MAX_LENGTH = 0x6002,
153 SH_HASHED_NAMES_COUNT = 0x6003,
154 SH_ACTIVE_UNIFORMS_ARRAY = 0x6004,
155 SH_SHADER_VERSION = 0x6005,
156 SH_ACTIVE_INTERFACE_BLOCKS_ARRAY = 0x6006,
157 SH_ACTIVE_OUTPUT_VARIABLES_ARRAY = 0x6007,
158 SH_ACTIVE_ATTRIBUTES_ARRAY = 0x6008,
159 SH_ACTIVE_VARYINGS_ARRAY = 0x6009,
Jamie Madill68fe74a2014-05-27 12:56:01 -0400160 SH_RESOURCES_STRING_LENGTH = 0x600A,
161 SH_OUTPUT_TYPE = 0x600B
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000162} ShShaderInfo;
163
164// Compile options.
165typedef enum {
zmo@google.comfd747b82011-04-23 01:30:07 +0000166 SH_VALIDATE = 0,
167 SH_VALIDATE_LOOP_INDEXING = 0x0001,
168 SH_INTERMEDIATE_TREE = 0x0002,
169 SH_OBJECT_CODE = 0x0004,
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400170 SH_VARIABLES = 0x0008,
zmo@google.comfd747b82011-04-23 01:30:07 +0000171 SH_LINE_DIRECTIVES = 0x0010,
172 SH_SOURCE_PATH = 0x0020,
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800173 SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX = 0x0040,
Zhenyao Mo550c6002014-02-26 15:40:48 -0800174 // If a sampler array index happens to be a loop index,
175 // 1) if its type is integer, unroll the loop.
176 // 2) if its type is float, fail the shader compile.
177 // This is to work around a mac driver bug.
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800178 SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX = 0x0080,
zmo@google.com32e97312011-08-24 01:03:11 +0000179
180 // This is needed only as a workaround for certain OpenGL driver bugs.
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800181 SH_EMULATE_BUILT_IN_FUNCTIONS = 0x0100,
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000182
183 // This is an experimental flag to enforce restrictions that aim to prevent
184 // timing attacks.
185 // It generates compilation errors for shaders that could expose sensitive
186 // texture information via the timing channel.
187 // To use this flag, you must compile the shader under the WebGL spec
188 // (using the SH_WEBGL_SPEC flag).
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800189 SH_TIMING_RESTRICTIONS = 0x0200,
Zhenyao Mo550c6002014-02-26 15:40:48 -0800190
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +0000191 // This flag prints the dependency graph that is used to enforce timing
192 // restrictions on fragment shaders.
193 // This flag only has an effect if all of the following are true:
194 // - The shader spec is SH_WEBGL_SPEC.
195 // - The compile options contain the SH_TIMING_RESTRICTIONS flag.
196 // - The shader type is SH_FRAGMENT_SHADER.
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800197 SH_DEPENDENCY_GRAPH = 0x0400,
gman@chromium.org8d804792012-10-17 21:33:48 +0000198
199 // Enforce the GLSL 1.017 Appendix A section 7 packing restrictions.
Zhenyao Moa15f3e82013-09-23 14:57:08 -0400200 // This flag only enforces (and can only enforce) the packing
201 // restrictions for uniform variables in both vertex and fragment
202 // shaders. ShCheckVariablesWithinPackingLimits() lets embedders
203 // enforce the packing restrictions for varying variables during
204 // program link time.
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800205 SH_ENFORCE_PACKING_RESTRICTIONS = 0x0800,
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000206
207 // This flag ensures all indirect (expression-based) array indexing
208 // is clamped to the bounds of the array. This ensures, for example,
209 // that you cannot read off the end of a uniform, whether an array
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000210 // vec234, or mat234 type. The ShArrayIndexClampingStrategy enum,
211 // specified in the ShBuiltInResources when constructing the
212 // compiler, selects the strategy for the clamping implementation.
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800213 SH_CLAMP_INDIRECT_ARRAY_BOUNDS = 0x1000,
Jamie Madilleb1a0102013-07-08 13:31:38 -0400214
215 // This flag limits the complexity of an expression.
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800216 SH_LIMIT_EXPRESSION_COMPLEXITY = 0x2000,
Jamie Madilleb1a0102013-07-08 13:31:38 -0400217
218 // This flag limits the depth of the call stack.
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800219 SH_LIMIT_CALL_STACK_DEPTH = 0x4000,
Zhenyao Moac44cd22013-09-23 14:57:09 -0400220
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800221 // This flag initializes gl_Position to vec4(0,0,0,0) at the
222 // beginning of the vertex shader's main(), and has no effect in the
Zhenyao Moac44cd22013-09-23 14:57:09 -0400223 // fragment shader. It is intended as a workaround for drivers which
224 // incorrectly fail to link programs if gl_Position is not written.
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800225 SH_INIT_GL_POSITION = 0x8000,
Zhenyao Mo7cab38b2013-10-15 12:59:30 -0700226
227 // This flag replaces
228 // "a && b" with "a ? b : false",
229 // "a || b" with "a ? true : b".
230 // This is to work around a MacOSX driver bug that |b| is executed
231 // independent of |a|'s value.
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800232 SH_UNFOLD_SHORT_CIRCUIT = 0x10000,
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800233
234 // This flag initializes varyings without static use in vertex shader
235 // at the beginning of main(), and has no effects in the fragment shader.
236 // It is intended as a workaround for drivers which incorrectly optimize
237 // out such varyings and cause a link failure.
Zhenyao Mo3cdfcce2014-03-07 13:00:08 -0800238 SH_INIT_VARYINGS_WITHOUT_STATIC_USE = 0x20000,
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000239} ShCompileOptions;
alokp@chromium.org2fa73692010-09-28 17:20:39 +0000240
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000241// Defines alternate strategies for implementing array index clamping.
242typedef enum {
243 // Use the clamp intrinsic for array index clamping.
244 SH_CLAMP_WITH_CLAMP_INTRINSIC = 1,
245
246 // Use a user-defined function for array index clamping.
247 SH_CLAMP_WITH_USER_DEFINED_INT_CLAMP_FUNCTION
248} ShArrayIndexClampingStrategy;
249
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000250//
251// Driver must call this first, once, before doing any other
alokp@chromium.org774d7062010-07-21 18:55:45 +0000252// compiler operations.
alokp@chromium.orgb3999342010-08-12 19:46:23 +0000253// If the function succeeds, the return value is nonzero, else zero.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000254//
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000255COMPILER_EXPORT int ShInitialize();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000256//
257// Driver should call this at shutdown.
alokp@chromium.orgb3999342010-08-12 19:46:23 +0000258// If the function succeeds, the return value is nonzero, else zero.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000259//
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000260COMPILER_EXPORT int ShFinalize();
alokp@chromium.org29cd91a2010-07-16 19:30:45 +0000261
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000262// The 64 bits hash function. The first parameter is the input string; the
263// second parameter is the string length.
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000264typedef khronos_uint64_t (*ShHashFunction64)(const char*, size_t);
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000265
alokp@chromium.org29cd91a2010-07-16 19:30:45 +0000266//
alokp@chromium.org94a86ad2010-08-25 20:02:11 +0000267// Implementation dependent built-in resources (constants and extensions).
268// The names for these resources has been obtained by stripping gl_/GL_.
269//
270typedef struct
271{
272 // Constants.
273 int MaxVertexAttribs;
274 int MaxVertexUniformVectors;
275 int MaxVaryingVectors;
276 int MaxVertexTextureImageUnits;
277 int MaxCombinedTextureImageUnits;
278 int MaxTextureImageUnits;
279 int MaxFragmentUniformVectors;
280 int MaxDrawBuffers;
281
282 // Extensions.
283 // Set to 1 to enable the extension, else 0.
284 int OES_standard_derivatives;
zmo@google.com09c323a2011-08-12 18:22:25 +0000285 int OES_EGL_image_external;
kbr@chromium.org205fef32011-11-22 20:50:02 +0000286 int ARB_texture_rectangle;
shannon.woods@transgaming.com550cd092013-02-28 23:19:54 +0000287 int EXT_draw_buffers;
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400288 int EXT_frag_depth;
Nicolas Capens46485082014-04-15 13:12:50 -0400289 int EXT_shader_texture_lod;
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000290
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000291 // Set to 1 if highp precision is supported in the fragment language.
292 // Default is 0.
293 int FragmentPrecisionHigh;
294
shannonwoods@chromium.org74b86cf2013-05-30 00:02:58 +0000295 // GLSL ES 3.0 constants.
296 int MaxVertexOutputVectors;
297 int MaxFragmentInputVectors;
298 int MinProgramTexelOffset;
299 int MaxProgramTexelOffset;
300
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000301 // Name Hashing.
302 // Set a 64 bit hash function to enable user-defined name hashing.
303 // Default is NULL.
304 ShHashFunction64 HashFunction;
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000305
306 // Selects a strategy to use when implementing array index clamping.
307 // Default is SH_CLAMP_WITH_CLAMP_INTRINSIC.
308 ShArrayIndexClampingStrategy ArrayIndexClampingStrategy;
Jamie Madilleb1a0102013-07-08 13:31:38 -0400309
310 // The maximum complexity an expression can be.
311 int MaxExpressionComplexity;
312
313 // The maximum depth a call stack can be.
314 int MaxCallStackDepth;
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000315} ShBuiltInResources;
alokp@chromium.org94a86ad2010-08-25 20:02:11 +0000316
317//
318// Initialize built-in resources with minimum expected values.
319//
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000320COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources);
alokp@chromium.org94a86ad2010-08-25 20:02:11 +0000321
322//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000323// ShHandle held by but opaque to the driver. It is allocated,
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400324// managed, and de-allocated by the compiler. Its contents
alokp@chromium.org774d7062010-07-21 18:55:45 +0000325// are defined by and used by the compiler.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000326//
327// If handle creation fails, 0 will be returned.
328//
329typedef void* ShHandle;
330
331//
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400332// Returns the a concatenated list of the items in ShBuiltInResources as a string.
333// This function must be updated whenever ShBuiltInResources is changed.
334// Parameters:
335// handle: Specifies the handle of the compiler to be used.
336// outStringLen: Specifies the size of the buffer, in number of characters. The size
337// of the buffer required to store the resources string can be obtained
338// by calling ShGetInfo with SH_RESOURCES_STRING_LENGTH.
339// outStr: Returns a null-terminated string representing all the built-in resources.
340COMPILER_EXPORT void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, char *outStr);
341
342//
alokp@chromium.org774d7062010-07-21 18:55:45 +0000343// Driver calls these to create and destroy compiler objects.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000344//
zmo@google.com5601ea02011-06-10 18:23:25 +0000345// Returns the handle of constructed compiler, null if the requested compiler is
346// not supported.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000347// Parameters:
348// type: Specifies the type of shader - SH_FRAGMENT_SHADER or SH_VERTEX_SHADER.
349// spec: Specifies the language spec the compiler must conform to -
350// SH_GLES2_SPEC or SH_WEBGL_SPEC.
zmo@google.com5601ea02011-06-10 18:23:25 +0000351// output: Specifies the output code type - SH_ESSL_OUTPUT, SH_GLSL_OUTPUT,
shannon.woods@transgaming.com82043342013-01-25 21:49:34 +0000352// SH_HLSL9_OUTPUT or SH_HLSL11_OUTPUT.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000353// resources: Specifies the built-in resources.
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000354COMPILER_EXPORT ShHandle ShConstructCompiler(
355 ShShaderType type,
356 ShShaderSpec spec,
357 ShShaderOutput output,
358 const ShBuiltInResources* resources);
359COMPILER_EXPORT void ShDestruct(ShHandle handle);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000360
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000361//
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000362// Compiles the given shader source.
363// If the function succeeds, the return value is nonzero, else zero.
364// Parameters:
365// handle: Specifies the handle of compiler to be used.
366// shaderStrings: Specifies an array of pointers to null-terminated strings
367// containing the shader source code.
368// numStrings: Specifies the number of elements in shaderStrings array.
369// compileOptions: A mask containing the following parameters:
alokp@chromium.org1f299542010-11-12 15:50:23 +0000370// SH_VALIDATE: Validates shader to ensure that it conforms to the spec
371// specified during compiler construction.
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000372// SH_VALIDATE_LOOP_INDEXING: Validates loop and indexing in the shader to
373// ensure that they do not exceed the minimum
374// functionality mandated in GLSL 1.0 spec,
375// Appendix A, Section 4 and 5.
376// There is no need to specify this parameter when
377// compiling for WebGL - it is implied.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000378// SH_INTERMEDIATE_TREE: Writes intermediate tree to info log.
379// Can be queried by calling ShGetInfoLog().
380// SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader.
381// Can be queried by calling ShGetObjectCode().
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400382// SH_VARIABLES: Extracts attributes, uniforms, and varyings.
383// Can be queried by calling ShGetVariableInfo().
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000384//
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000385COMPILER_EXPORT int ShCompile(
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000386 const ShHandle handle,
alokp@chromium.org774d7062010-07-21 18:55:45 +0000387 const char* const shaderStrings[],
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000388 size_t numStrings,
alokp@chromium.org7beea402010-09-15 21:18:34 +0000389 int compileOptions
alokp@chromium.org774d7062010-07-21 18:55:45 +0000390 );
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000391
alokp@chromium.org7beea402010-09-15 21:18:34 +0000392// Returns a parameter from a compiled shader.
393// Parameters:
394// handle: Specifies the compiler
395// pname: Specifies the parameter to query.
396// The following parameters are defined:
397// SH_INFO_LOG_LENGTH: the number of characters in the information log
398// including the null termination character.
399// SH_OBJECT_CODE_LENGTH: the number of characters in the object code
400// including the null termination character.
401// SH_ACTIVE_ATTRIBUTES: the number of active attribute variables.
402// SH_ACTIVE_ATTRIBUTE_MAX_LENGTH: the length of the longest active attribute
403// variable name including the null
404// termination character.
405// SH_ACTIVE_UNIFORMS: the number of active uniform variables.
406// SH_ACTIVE_UNIFORM_MAX_LENGTH: the length of the longest active uniform
407// variable name including the null
408// termination character.
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400409// SH_VARYINGS: the number of varying variables.
410// SH_VARYING_MAX_LENGTH: the length of the longest varying variable name
411// including the null termination character.
zmo@google.comfd747b82011-04-23 01:30:07 +0000412// SH_MAPPED_NAME_MAX_LENGTH: the length of the mapped variable name including
413// the null termination character.
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000414// SH_NAME_MAX_LENGTH: the max length of a user-defined name including the
415// null termination character.
416// SH_HASHED_NAME_MAX_LENGTH: the max length of a hashed name including the
417// null termination character.
418// SH_HASHED_NAMES_COUNT: the number of hashed names from the latest compile.
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000419// SH_SHADER_VERSION: the version of the shader language
Jamie Madill68fe74a2014-05-27 12:56:01 -0400420// SH_OUTPUT_TYPE: the currently set language output type
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000421//
alokp@chromium.org7beea402010-09-15 21:18:34 +0000422// params: Requested parameter
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000423COMPILER_EXPORT void ShGetInfo(const ShHandle handle,
424 ShShaderInfo pname,
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000425 size_t* params);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000426
427// Returns nul-terminated information log for a compiled shader.
428// Parameters:
429// handle: Specifies the compiler
430// infoLog: Specifies an array of characters that is used to return
431// the information log. It is assumed that infoLog has enough memory
432// to accomodate the information log. The size of the buffer required
433// to store the returned information log can be obtained by calling
434// ShGetInfo with SH_INFO_LOG_LENGTH.
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000435COMPILER_EXPORT void ShGetInfoLog(const ShHandle handle, char* infoLog);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000436
437// Returns null-terminated object code for a compiled shader.
438// Parameters:
439// handle: Specifies the compiler
440// infoLog: Specifies an array of characters that is used to return
441// the object code. It is assumed that infoLog has enough memory to
442// accomodate the object code. The size of the buffer required to
443// store the returned object code can be obtained by calling
444// ShGetInfo with SH_OBJECT_CODE_LENGTH.
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000445COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000446
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400447// Returns information about a shader variable.
alokp@chromium.org7beea402010-09-15 21:18:34 +0000448// Parameters:
449// handle: Specifies the compiler
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400450// variableType: Specifies the variable type; options include
451// SH_ACTIVE_ATTRIBUTES, SH_ACTIVE_UNIFORMS, SH_VARYINGS.
452// index: Specifies the index of the variable to be queried.
alokp@chromium.org7beea402010-09-15 21:18:34 +0000453// length: Returns the number of characters actually written in the string
454// indicated by name (excluding the null terminator) if a value other
455// than NULL is passed.
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400456// size: Returns the size of the variable.
457// type: Returns the data type of the variable.
458// precision: Returns the precision of the variable.
Zhenyao Mod2d340b2013-09-23 14:57:05 -0400459// staticUse: Returns 1 if the variable is accessed in a statement after
460// pre-processing, whether or not run-time flow of control will
461// cause that statement to be executed.
462// Returns 0 otherwise.
alokp@chromium.org7beea402010-09-15 21:18:34 +0000463// name: Returns a null terminated string containing the name of the
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400464// variable. It is assumed that name has enough memory to accormodate
465// the variable name. The size of the buffer required to store the
466// variable name can be obtained by calling ShGetInfo with
467// SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, SH_ACTIVE_UNIFORM_MAX_LENGTH,
468// SH_VARYING_MAX_LENGTH.
zmo@google.comfd747b82011-04-23 01:30:07 +0000469// mappedName: Returns a null terminated string containing the mapped name of
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400470// the variable, It is assumed that mappedName has enough memory
471// (SH_MAPPED_NAME_MAX_LENGTH), or NULL if don't care about the
472// mapped name. If the name is not mapped, then name and mappedName
473// are the same.
474COMPILER_EXPORT void ShGetVariableInfo(const ShHandle handle,
475 ShShaderInfo variableType,
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000476 int index,
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000477 size_t* length,
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000478 int* size,
479 ShDataType* type,
Zhenyao Mo74da9f22013-09-23 14:57:01 -0400480 ShPrecisionType* precision,
Zhenyao Mod2d340b2013-09-23 14:57:05 -0400481 int* staticUse,
apatrick@chromium.org22eab922011-10-21 01:16:42 +0000482 char* name,
483 char* mappedName);
alokp@chromium.org7beea402010-09-15 21:18:34 +0000484
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000485// Returns information about a name hashing entry from the latest compile.
486// Parameters:
487// handle: Specifies the compiler
488// index: Specifies the index of the name hashing entry to be queried.
489// name: Returns a null terminated string containing the user defined name.
490// It is assumed that name has enough memory to accomodate the name.
491// The size of the buffer required to store the user defined name can
492// be obtained by calling ShGetInfo with SH_NAME_MAX_LENGTH.
493// hashedName: Returns a null terminated string containing the hashed name of
494// the uniform variable, It is assumed that hashedName has enough
495// memory to accomodate the name. The size of the buffer required
496// to store the name can be obtained by calling ShGetInfo with
497// SH_HASHED_NAME_MAX_LENGTH.
498COMPILER_EXPORT void ShGetNameHashingEntry(const ShHandle handle,
499 int index,
500 char* name,
501 char* hashedName);
502
daniel@transgaming.com043da132012-12-20 21:12:22 +0000503// Returns a parameter from a compiled shader.
504// Parameters:
505// handle: Specifies the compiler
506// pname: Specifies the parameter to query.
507// The following parameters are defined:
508// SH_ACTIVE_UNIFORMS_ARRAY: an STL vector of active uniforms. Valid only for
509// HLSL output.
510// params: Requested parameter
511COMPILER_EXPORT void ShGetInfoPointer(const ShHandle handle,
512 ShShaderInfo pname,
513 void** params);
514
Zhenyao Moa15f3e82013-09-23 14:57:08 -0400515typedef struct
516{
517 ShDataType type;
518 int size;
519} ShVariableInfo;
520
521// Returns 1 if the passed in variables pack in maxVectors following
522// the packing rules from the GLSL 1.017 spec, Appendix A, section 7.
523// Returns 0 otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
524// flag above.
525// Parameters:
526// maxVectors: the available rows of registers.
527// varInfoArray: an array of variable info (types and sizes).
528// varInfoArraySize: the size of the variable array.
529COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits(
530 int maxVectors,
531 ShVariableInfo* varInfoArray,
532 size_t varInfoArraySize);
533
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000534#ifdef __cplusplus
alokp@chromium.org774d7062010-07-21 18:55:45 +0000535}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000536#endif
537
538#endif // _COMPILER_INTERFACE_INCLUDED_