• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 #include <inttypes.h>
4 #include <stddef.h>
5 
6 #if defined(_WIN32)
7 #        define ANGLE_EXPORT __declspec(dllexport)
8 #elif defined(__GNUC__)
9 #        define ANGLE_EXPORT __attribute__((visibility("default")))
10 #else
11 #    define ANGLE_EXPORT
12 #endif
13 
14 extern "C" {
15 
16 typedef void* ST_Handle;
17 typedef uint64_t ST_CompileOptions;
18 
19 enum ST_ShaderSpec {
20     ST_GLES2_SPEC,
21     ST_WEBGL_SPEC,
22 
23     ST_GLES3_SPEC,
24     ST_WEBGL2_SPEC,
25 
26     ST_GLES3_1_SPEC,
27     ST_WEBGL3_SPEC,
28 
29     ST_GL_CORE_SPEC,
30     ST_GL_COMPATIBILITY_SPEC,
31 };
32 
33 enum ST_ShaderOutput {
34     // ESSL output only supported in some configurations.
35     ST_ESSL_OUTPUT = 0x8B45,
36 
37     // GLSL output only supported in some configurations.
38     ST_GLSL_COMPATIBILITY_OUTPUT = 0x8B46,
39     // Note: GL introduced core profiles in 1.5.
40     ST_GLSL_130_OUTPUT      = 0x8B47,
41     ST_GLSL_140_OUTPUT      = 0x8B80,
42     ST_GLSL_150_CORE_OUTPUT = 0x8B81,
43     ST_GLSL_330_CORE_OUTPUT = 0x8B82,
44     ST_GLSL_400_CORE_OUTPUT = 0x8B83,
45     ST_GLSL_410_CORE_OUTPUT = 0x8B84,
46     ST_GLSL_420_CORE_OUTPUT = 0x8B85,
47     ST_GLSL_430_CORE_OUTPUT = 0x8B86,
48     ST_GLSL_440_CORE_OUTPUT = 0x8B87,
49     ST_GLSL_450_CORE_OUTPUT = 0x8B88,
50 
51     // Prefer using these to specify HLSL output type:
52     ST_HLSL_3_0_OUTPUT       = 0x8B48,  // D3D 9
53     ST_HLSL_4_1_OUTPUT       = 0x8B49,  // D3D 11
54     ST_HLSL_4_0_FL9_3_OUTPUT = 0x8B4A,  // D3D 11 feature level 9_3
55 
56     // Output specialized GLSL to be fed to glslang for Vulkan SPIR.
57     ST_GLSL_VULKAN_OUTPUT = 0x8B4B,
58 
59     // Output specialized GLSL to be fed to glslang for Vulkan SPIR to be cross compiled to Metal
60     // later.
61     ST_GLSL_METAL_OUTPUT = 0x8B4C,
62 };
63 
64 // Compile options.
65 const ST_CompileOptions ST_VALIDATE               = 0;
66 const ST_CompileOptions ST_VALIDATE_LOOP_INDEXING = UINT64_C(1) << 0;
67 const ST_CompileOptions ST_INTERMEDIATE_TREE      = UINT64_C(1) << 1;
68 const ST_CompileOptions ST_OBJECT_CODE            = UINT64_C(1) << 2;
69 const ST_CompileOptions ST_VARIABLES              = UINT64_C(1) << 3;
70 const ST_CompileOptions ST_LINE_DIRECTIVES        = UINT64_C(1) << 4;
71 const ST_CompileOptions ST_SOURCE_PATH            = UINT64_C(1) << 5;
72 
73 // This flag will keep invariant declaration for input in fragment shader for GLSL >=4.20 on AMD.
74 // From GLSL >= 4.20, it's optional to add invariant for fragment input, but GPU vendors have
75 // different implementations about this. Some drivers forbid invariant in fragment for GLSL>= 4.20,
76 // e.g. Linux Mesa, some drivers treat that as optional, e.g. NVIDIA, some drivers require invariant
77 // must match between vertex and fragment shader, e.g. AMD. The behavior on AMD is obviously wrong.
78 // Remove invariant for input in fragment shader to workaround the restriction on Intel Mesa.
79 // But don't remove on AMD Linux to avoid triggering the bug on AMD.
80 const ST_CompileOptions ST_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT = UINT64_C(1) << 6;
81 
82 // Due to spec difference between GLSL 4.1 or lower and ESSL3, some platforms (for example, Mac OSX
83 // core profile) require a variable's "invariant"/"centroid" qualifiers to match between vertex and
84 // fragment shader. A simple solution to allow such shaders to link is to omit the two qualifiers.
85 // AMD driver in Linux requires invariant qualifier to match between vertex and fragment shaders,
86 // while ESSL3 disallows invariant qualifier in fragment shader and GLSL >= 4.2 doesn't require
87 // invariant qualifier to match between shaders. Remove invariant qualifier from vertex shader to
88 // workaround AMD driver bug.
89 // Note that the two flags take effect on ESSL3 input shaders translated to GLSL 4.1 or lower and to
90 // GLSL 4.2 or newer on Linux AMD.
91 // TODO(zmo): This is not a good long-term solution. Simply dropping these qualifiers may break some
92 // developers' content. A more complex workaround of dynamically generating, compiling, and
93 // re-linking shaders that use these qualifiers should be implemented.
94 const ST_CompileOptions ST_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3 = UINT64_C(1) << 7;
95 
96 // This flag works around bug in Intel Mac drivers related to abs(i) where
97 // i is an integer.
98 const ST_CompileOptions ST_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 8;
99 
100 // Enforce the GLSL 1.017 Appendix A section 7 packing restrictions.
101 // This flag only enforces (and can only enforce) the packing
102 // restrictions for uniform variables in both vertex and fragment
103 // shaders. ShCheckVariablesWithinPackingLimits() lets embedders
104 // enforce the packing restrictions for varying variables during
105 // program link time.
106 const ST_CompileOptions ST_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 9;
107 
108 // This flag ensures all indirect (expression-based) array indexing
109 // is clamped to the bounds of the array. This ensures, for example,
110 // that you cannot read off the end of a uniform, whether an array
111 // vec234, or mat234 type. The ST_ArrayIndexClampingStrategy enum,
112 // specified in the ST_BuiltInResources when constructing the
113 // compiler, selects the strategy for the clamping implementation.
114 // TODO(http://anglebug.com/4361): fix for compute shaders.
115 const ST_CompileOptions ST_CLAMP_INDIRECT_ARRAY_BOUNDS = UINT64_C(1) << 10;
116 
117 // This flag limits the complexity of an expression.
118 const ST_CompileOptions ST_LIMIT_EXPRESSION_COMPLEXITY = UINT64_C(1) << 11;
119 
120 // This flag limits the depth of the call stack.
121 const ST_CompileOptions ST_LIMIT_CALL_STACK_DEPTH = UINT64_C(1) << 12;
122 
123 // This flag initializes gl_Position to vec4(0,0,0,0) at the
124 // beginning of the vertex shader's main(), and has no effect in the
125 // fragment shader. It is intended as a workaround for drivers which
126 // incorrectly fail to link programs if gl_Position is not written.
127 const ST_CompileOptions ST_INIT_GL_POSITION = UINT64_C(1) << 13;
128 
129 // This flag replaces
130 //   "a && b" with "a ? b : false",
131 //   "a || b" with "a ? true : b".
132 // This is to work around a MacOSX driver bug that |b| is executed
133 // independent of |a|'s value.
134 const ST_CompileOptions ST_UNFOLD_SHORT_CIRCUIT = UINT64_C(1) << 14;
135 
136 // This flag initializes output variables to 0 at the beginning of main().
137 // It is to avoid undefined behaviors.
138 const ST_CompileOptions ST_INIT_OUTPUT_VARIABLES = UINT64_C(1) << 15;
139 
140 // This flag scalarizes vec/ivec/bvec/mat constructor args.
141 // It is intended as a workaround for Linux/Mac driver bugs.
142 const ST_CompileOptions ST_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS = UINT64_C(1) << 16;
143 
144 // This flag overwrites a struct name with a unique prefix.
145 // It is intended as a workaround for drivers that do not handle
146 // struct scopes correctly, including all Mac drivers and Linux AMD.
147 const ST_CompileOptions ST_REGENERATE_STRUCT_NAMES = UINT64_C(1) << 17;
148 
149 // This flag makes the compiler not prune unused function early in the
150 // compilation process. Pruning coupled with ST_LIMIT_CALL_STACK_DEPTH
151 // helps avoid bad shaders causing stack overflows.
152 const ST_CompileOptions ST_DONT_PRUNE_UNUSED_FUNCTIONS = UINT64_C(1) << 18;
153 
154 // This flag works around a bug in NVIDIA 331 series drivers related
155 // to pow(x, y) where y is a constant vector.
156 const ST_CompileOptions ST_REMOVE_POW_WITH_CONSTANT_EXPONENT = UINT64_C(1) << 19;
157 
158 // This flag works around bugs in Mac drivers related to do-while by
159 // transforming them into an other construct.
160 const ST_CompileOptions ST_REWRITE_DO_WHILE_LOOPS = UINT64_C(1) << 20;
161 
162 // This flag works around a bug in the HLSL compiler optimizer that folds certain
163 // constant pow expressions incorrectly. Only applies to the HLSL back-end. It works
164 // by expanding the integer pow expressions into a series of multiplies.
165 const ST_CompileOptions ST_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS = UINT64_C(1) << 21;
166 
167 // Flatten "#pragma STDGL invariant(all)" into the declarations of
168 // varying variables and built-in GLSL variables. This compiler
169 // option is enabled automatically when needed.
170 const ST_CompileOptions ST_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL = UINT64_C(1) << 22;
171 
172 // Some drivers do not take into account the base level of the texture in the results of the
173 // HLSL GetDimensions builtin.  This flag instructs the compiler to manually add the base level
174 // offsetting.
175 const ST_CompileOptions ST_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL = UINT64_C(1) << 23;
176 
177 // This flag works around an issue in translating GLSL function texelFetchOffset on
178 // INTEL drivers. It works by translating texelFetchOffset into texelFetch.
179 const ST_CompileOptions ST_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH = UINT64_C(1) << 24;
180 
181 // This flag works around condition bug of for and while loops in Intel Mac OSX drivers.
182 // Condition calculation is not correct. Rewrite it from "CONDITION" to "CONDITION && true".
183 const ST_CompileOptions ST_ADD_AND_TRUE_TO_LOOP_CONDITION = UINT64_C(1) << 25;
184 
185 // This flag works around a bug in evaluating unary minus operator on integer on some INTEL
186 // drivers. It works by translating -(int) into ~(int) + 1.
187 const ST_CompileOptions ST_REWRITE_INTEGER_UNARY_MINUS_OPERATOR = UINT64_C(1) << 26;
188 
189 // This flag works around a bug in evaluating isnan() on some INTEL D3D and Mac OSX drivers.
190 // It works by using an expression to emulate this function.
191 const ST_CompileOptions ST_EMULATE_ISNAN_FLOAT_FUNCTION = UINT64_C(1) << 27;
192 
193 // This flag will use all uniforms of unused std140 and shared uniform blocks at the
194 // beginning of the vertex/fragment shader's main(). It is intended as a workaround for Mac
195 // drivers with shader version 4.10. In those drivers, they will treat unused
196 // std140 and shared uniform blocks' members as inactive. However, WebGL2.0 based on
197 // OpenGL ES3.0.4 requires all members of a named uniform block declared with a shared or std140
198 // layout qualifier to be considered active. The uniform block itself is also considered active.
199 const ST_CompileOptions ST_USE_UNUSED_STANDARD_SHARED_BLOCKS = UINT64_C(1) << 28;
200 
201 // This flag works around a bug in unary minus operator on float numbers on Intel
202 // Mac OSX 10.11 drivers. It works by translating -float into 0.0 - float.
203 const ST_CompileOptions ST_REWRITE_FLOAT_UNARY_MINUS_OPERATOR = UINT64_C(1) << 29;
204 
205 // This flag works around a bug in evaluating atan(y, x) on some NVIDIA OpenGL drivers.
206 // It works by using an expression to emulate this function.
207 const ST_CompileOptions ST_EMULATE_ATAN2_FLOAT_FUNCTION = UINT64_C(1) << 30;
208 
209 // Set to initialize uninitialized local and global temporary variables. Should only be used with
210 // GLSL output. In HLSL output variables are initialized regardless of if this flag is set.
211 const ST_CompileOptions ST_INITIALIZE_UNINITIALIZED_LOCALS = UINT64_C(1) << 31;
212 
213 // The flag modifies the shader in the following way:
214 // Every occurrence of gl_InstanceID is replaced by the global temporary variable InstanceID.
215 // Every occurrence of gl_ViewID_OVR is replaced by the varying variable ViewID_OVR.
216 // At the beginning of the body of main() in a vertex shader the following initializers are added:
217 // ViewID_OVR = uint(gl_InstanceID) % num_views;
218 // InstanceID = gl_InstanceID / num_views;
219 // ViewID_OVR is added as a varying variable to both the vertex and fragment shaders.
220 const ST_CompileOptions ST_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW = UINT64_C(1) << 32;
221 
222 // With the flag enabled the GLSL/ESSL vertex shader is modified to include code for viewport
223 // selection in the following way:
224 // - Code to enable the extension ARB_shader_viewport_layer_array/NV_viewport_array2 is included.
225 // - Code to select the viewport index or layer is inserted at the beginning of main after
226 // ViewID_OVR's initialization.
227 // - A declaration of the uniform multiviewBaseViewLayerIndex.
228 // Note: The ST_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW flag also has to be enabled to have the
229 // temporary variable ViewID_OVR declared and initialized.
230 const ST_CompileOptions ST_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER = UINT64_C(1) << 33;
231 
232 // If the flag is enabled, gl_PointSize is clamped to the maximum point size specified in
233 // ST_BuiltInResources in vertex shaders.
234 const ST_CompileOptions ST_CLAMP_POINT_SIZE = UINT64_C(1) << 34;
235 
236 // Turn some arithmetic operations that operate on a float vector-scalar pair into vector-vector
237 // operations. This is done recursively. Some scalar binary operations inside vector constructors
238 // are also turned into vector operations.
239 //
240 // This is targeted to work around a bug in NVIDIA OpenGL drivers that was reproducible on NVIDIA
241 // driver version 387.92. It works around the most common occurrences of the bug.
242 const ST_CompileOptions ST_REWRITE_VECTOR_SCALAR_ARITHMETIC = UINT64_C(1) << 35;
243 
244 // Don't use loops to initialize uninitialized variables. Only has an effect if some kind of
245 // variable initialization is turned on.
246 const ST_CompileOptions ST_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES = UINT64_C(1) << 36;
247 
248 // Don't use D3D constant register zero when allocating space for uniforms. This is targeted to work
249 // around a bug in NVIDIA D3D driver version 388.59 where in very specific cases the driver would
250 // not handle constant register zero correctly. Only has an effect on HLSL translation.
251 const ST_CompileOptions ST_SKIP_D3D_CONSTANT_REGISTER_ZERO = UINT64_C(1) << 37;
252 
253 // Clamp gl_FragDepth to the range [0.0, 1.0] in case it is statically used.
254 const ST_CompileOptions ST_CLAMP_FRAG_DEPTH = UINT64_C(1) << 38;
255 
256 // Rewrite expressions like "v.x = z = expression;". Works around a bug in NVIDIA OpenGL drivers
257 // prior to version 397.31.
258 const ST_CompileOptions ST_REWRITE_REPEATED_ASSIGN_TO_SWIZZLED = UINT64_C(1) << 39;
259 
260 // Rewrite gl_DrawID as a uniform int
261 const ST_CompileOptions ST_EMULATE_GL_DRAW_ID = UINT64_C(1) << 40;
262 
263 // This flag initializes shared variables to 0.
264 // It is to avoid ompute shaders being able to read undefined values that could be coming from
265 // another webpage/application.
266 const ST_CompileOptions ST_INIT_SHARED_VARIABLES = UINT64_C(1) << 41;
267 
268 // Forces the value returned from an atomic operations to be always be resolved. This is targeted to
269 // workaround a bug in NVIDIA D3D driver where the return value from
270 // RWByteAddressBuffer.InterlockedAdd does not get resolved when used in the .yzw components of a
271 // RWByteAddressBuffer.Store operation. Only has an effect on HLSL translation.
272 // http://anglebug.com/3246
273 const ST_CompileOptions ST_FORCE_ATOMIC_VALUE_RESOLUTION = UINT64_C(1) << 42;
274 
275 // Rewrite gl_BaseVertex and gl_BaseInstance as uniform int
276 const ST_CompileOptions ST_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE = UINT64_C(1) << 43;
277 
278 // Emulate seamful cube map sampling for OpenGL ES2.0.  Currently only applies to the Vulkan
279 // backend, as is done after samplers are moved out of structs.  Can likely be made to work on
280 // the other backends as well.
281 const ST_CompileOptions ST_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING = UINT64_C(1) << 44;
282 
283 // This flag controls how to translate WEBGL_video_texture sampling function.
284 const ST_CompileOptions ST_TAKE_VIDEO_TEXTURE_AS_EXTERNAL_OES = UINT64_C(1) << 45;
285 
286 // If requested, validates the AST after every transformation.  Useful for debugging.
287 const ST_CompileOptions ST_VALIDATE_AST = UINT64_C(1) << 46;
288 
289 // Use old version of RewriteStructSamplers, which doesn't produce as many
290 // sampler arrays in parameters. This causes a few tests to pass on Android.
291 const ST_CompileOptions ST_USE_OLD_REWRITE_STRUCT_SAMPLERS = UINT64_C(1) << 47;
292 
293 // This flag works around a inconsistent behavior in Mac AMD driver where gl_VertexID doesn't
294 // include base vertex value. It replaces gl_VertexID with (gl_VertexID + angle_BaseVertex)
295 // when angle_BaseVertex is available.
296 const ST_CompileOptions ST_ADD_BASE_VERTEX_TO_VERTEX_ID = UINT64_C(1) << 48;
297 
298 // This works around the dynamic lvalue indexing of swizzled vectors on various platforms.
299 const ST_CompileOptions ST_REMOVE_DYNAMIC_INDEXING_OF_SWIZZLED_VECTOR = UINT64_C(1) << 49;
300 
301 // This flag works a driver bug that fails to allocate ShaderResourceView for StructuredBuffer
302 // on Windows 7 and earlier.
303 const ST_CompileOptions ST_DONT_TRANSLATE_UNIFORM_BLOCK_TO_STRUCTUREDBUFFER = UINT64_C(1) << 50;
304 
305 // This flag indicates whether Bresenham line raster emulation code should be generated.  This
306 // emulation is necessary if the backend uses a differnet algorithm to draw lines.  Currently only
307 // implemented for the Vulkan backend.
308 const ST_CompileOptions ST_ADD_BRESENHAM_LINE_RASTER_EMULATION = UINT64_C(1) << 51;
309 
310 // This flag allows disabling ARB_texture_rectangle on a per-compile basis. This is necessary
311 // for WebGL contexts becuase ARB_texture_rectangle may be necessary for the WebGL implementation
312 // internally but shouldn't be exposed to WebGL user code.
313 const ST_CompileOptions ST_DISABLE_ARB_TEXTURE_RECTANGLE = UINT64_C(1) << 52;
314 
315 // This flag works around a driver bug by rewriting uses of row-major matrices
316 // as column-major in ESSL 3.00 and greater shaders.
317 const ST_CompileOptions ST_REWRITE_ROW_MAJOR_MATRICES = UINT64_C(1) << 53;
318 
319 // Drop any explicit precision qualifiers from shader.
320 const ST_CompileOptions ST_IGNORE_PRECISION_QUALIFIERS = UINT64_C(1) << 54;
321 
322 // Allow compiler to do early fragment tests as an optimization.
323 const ST_CompileOptions ST_EARLY_FRAGMENT_TESTS_OPTIMIZATION = UINT64_C(1) << 55;
324 
325 // Defines alternate strategies for implementing array index clamping.
326 enum ST_ArrayIndexClampingStrategy
327 {
328     // Use the clamp intrinsic for array index clamping.
329     ST_CLAMP_WITH_CLAMP_INTRINSIC = 1,
330 
331     // Use a user-defined function for array index clamping.
332     ST_CLAMP_WITH_USER_DEFINED_INT_CLAMP_FUNCTION
333 };
334 
335 // The 64 bits hash function. The first parameter is the input string; the
336 // second parameter is the string length.
337 typedef uint64_t (*ST_HashFunction64)(const char*, size_t);
338 
339 // GLenum alias
340 typedef unsigned int GLenum;
341 
342 // Should be just like ShBuiltInResources; just keeping a private copy here
343 // to allow this to be more isolated.
344 struct ST_BuiltInResources
345 {
346     // Constants.
347     int MaxVertexAttribs;
348     int MaxVertexUniformVectors;
349     int MaxVaryingVectors;
350     int MaxVertexTextureImageUnits;
351     int MaxCombinedTextureImageUnits;
352     int MaxTextureImageUnits;
353     int MaxFragmentUniformVectors;
354     int MaxDrawBuffers;
355 
356     // Extensions.
357     // Set to 1 to enable the extension, else 0.
358     int OES_standard_derivatives;
359     int OES_EGL_image_external;
360     int OES_EGL_image_external_essl3;
361     int NV_EGL_stream_consumer_external;
362     int ARB_texture_rectangle;
363     int EXT_blend_func_extended;
364     int EXT_draw_buffers;
365     int EXT_frag_depth;
366     int EXT_shader_texture_lod;
367     int WEBGL_debug_shader_precision;
368     int EXT_shader_framebuffer_fetch;
369     int NV_shader_framebuffer_fetch;
370     int NV_shader_noperspective_interpolation;
371     int ARM_shader_framebuffer_fetch;
372     int OVR_multiview;
373     int OVR_multiview2;
374     int EXT_multisampled_render_to_texture;
375     int EXT_YUV_target;
376     int EXT_geometry_shader;
377     int EXT_gpu_shader5;
378     int EXT_shader_non_constant_global_initializers;
379     int OES_texture_storage_multisample_2d_array;
380     int OES_texture_3D;
381     int ANGLE_texture_multisample;
382     int ANGLE_multi_draw;
383     int ANGLE_base_vertex_base_instance;
384     int WEBGL_video_texture;
385     int APPLE_clip_distance;
386     int OES_texture_cube_map_array;
387     int EXT_texture_cube_map_array;
388 
389     // Set to 1 to enable replacing GL_EXT_draw_buffers #extension directives
390     // with GL_NV_draw_buffers in ESSL output. This flag can be used to emulate
391     // EXT_draw_buffers by using it in combination with GLES3.0 glDrawBuffers
392     // function. This applies to Tegra K1 devices.
393     int NV_draw_buffers;
394 
395     // Set to 1 if highp precision is supported in the ESSL 1.00 version of the
396     // fragment language. Does not affect versions of the language where highp
397     // support is mandatory.
398     // Default is 0.
399     int FragmentPrecisionHigh;
400 
401     // GLSL ES 3.0 constants.
402     int MaxVertexOutputVectors;
403     int MaxFragmentInputVectors;
404     int MinProgramTexelOffset;
405     int MaxProgramTexelOffset;
406 
407     // Extension constants.
408 
409     // Value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT for OpenGL ES output context.
410     // Value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS for OpenGL output context.
411     // GLES SL version 100 gl_MaxDualSourceDrawBuffersEXT value for EXT_blend_func_extended.
412     int MaxDualSourceDrawBuffers;
413 
414     // Value of GL_MAX_VIEWS_OVR.
415     int MaxViewsOVR;
416 
417     // Name Hashing.
418     // Set a 64 bit hash function to enable user-defined name hashing.
419     // Default is NULL.
420     ST_HashFunction64 HashFunction;
421 
422     // Selects a strategy to use when implementing array index clamping.
423     // Default is ST_CLAMP_WITH_CLAMP_INTRINSIC.
424     ST_ArrayIndexClampingStrategy ArrayIndexClampingStrategy;
425 
426     // The maximum complexity an expression can be when ST_LIMIT_EXPRESSION_COMPLEXITY is turned on.
427     int MaxExpressionComplexity;
428 
429     // The maximum depth a call stack can be.
430     int MaxCallStackDepth;
431 
432     // The maximum number of parameters a function can have when ST_LIMIT_EXPRESSION_COMPLEXITY is
433     // turned on.
434     int MaxFunctionParameters;
435 
436     // GLES 3.1 constants
437 
438     // texture gather offset constraints.
439     int MinProgramTextureGatherOffset;
440     int MaxProgramTextureGatherOffset;
441 
442     // maximum number of available image units
443     int MaxImageUnits;
444 
445     // maximum number of image uniforms in a vertex shader
446     int MaxVertexImageUniforms;
447 
448     // maximum number of image uniforms in a fragment shader
449     int MaxFragmentImageUniforms;
450 
451     // maximum number of image uniforms in a compute shader
452     int MaxComputeImageUniforms;
453 
454     // maximum total number of image uniforms in a program
455     int MaxCombinedImageUniforms;
456 
457     // maximum number of uniform locations
458     int MaxUniformLocations;
459 
460     // maximum number of ssbos and images in a shader
461     int MaxCombinedShaderOutputResources;
462 
463     // maximum number of groups in each dimension
464     int MaxComputeWorkGroupCount[3];
465     // maximum number of threads per work group in each dimension
466     int MaxComputeWorkGroupSize[3];
467 
468     // maximum number of total uniform components
469     int MaxComputeUniformComponents;
470 
471     // maximum number of texture image units in a compute shader
472     int MaxComputeTextureImageUnits;
473 
474     // maximum number of atomic counters in a compute shader
475     int MaxComputeAtomicCounters;
476 
477     // maximum number of atomic counter buffers in a compute shader
478     int MaxComputeAtomicCounterBuffers;
479 
480     // maximum number of atomic counters in a vertex shader
481     int MaxVertexAtomicCounters;
482 
483     // maximum number of atomic counters in a fragment shader
484     int MaxFragmentAtomicCounters;
485 
486     // maximum number of atomic counters in a program
487     int MaxCombinedAtomicCounters;
488 
489     // maximum binding for an atomic counter
490     int MaxAtomicCounterBindings;
491 
492     // maximum number of atomic counter buffers in a vertex shader
493     int MaxVertexAtomicCounterBuffers;
494 
495     // maximum number of atomic counter buffers in a fragment shader
496     int MaxFragmentAtomicCounterBuffers;
497 
498     // maximum number of atomic counter buffers in a program
499     int MaxCombinedAtomicCounterBuffers;
500 
501     // maximum number of buffer object storage in machine units
502     int MaxAtomicCounterBufferSize;
503 
504     // maximum number of uniform block bindings
505     int MaxUniformBufferBindings;
506 
507     // maximum number of shader storage buffer bindings
508     int MaxShaderStorageBufferBindings;
509 
510     // maximum point size (higher limit from ALIASED_POINT_SIZE_RANGE)
511     float MaxPointSize;
512 
513     // EXT_geometry_shader constants
514     int MaxGeometryUniformComponents;
515     int MaxGeometryUniformBlocks;
516     int MaxGeometryInputComponents;
517     int MaxGeometryOutputComponents;
518     int MaxGeometryOutputVertices;
519     int MaxGeometryTotalOutputComponents;
520     int MaxGeometryTextureImageUnits;
521     int MaxGeometryAtomicCounterBuffers;
522     int MaxGeometryAtomicCounters;
523     int MaxGeometryShaderStorageBlocks;
524     int MaxGeometryShaderInvocations;
525     int MaxGeometryImageUniforms;
526 
527     // Subpixel bits used in rasterization.
528     int SubPixelBits;
529 
530     // APPLE_clip_distance/EXT_clip_cull_distance constant
531     int MaxClipDistances;
532 };
533 
534 // Varying interpolation qualifier, see section 4.3.9 of the ESSL 3.00.4 spec
535 enum ST_InterpolationType {
536     ST_INTERPOLATION_SMOOTH,
537     ST_INTERPOLATION_CENTROID,
538     ST_INTERPOLATION_FLAT,
539     ST_INTERPOLATION_NOPERSPECTIVE
540 };
541 
542 // Uniform block layout qualifier, see section 4.3.8.3 of the ESSL 3.00.4 spec
543 enum ST_BlockLayoutType
544 {
545     ST_BLOCKLAYOUT_STANDARD,
546     ST_BLOCKLAYOUT_STD140 = ST_BLOCKLAYOUT_STANDARD,
547     ST_BLOCKLAYOUT_STD430,  // Shader storage block layout qualifier
548     ST_BLOCKLAYOUT_PACKED,
549     ST_BLOCKLAYOUT_SHARED
550 };
551 
552 // Interface Blocks, see section 4.3.9 of the ESSL 3.10 spec
553 enum class ST_BlockType
554 {
555     ST_BLOCK_UNIFORM,
556     ST_BLOCK_BUFFER,
557 
558     // Required in OpenGL ES 3.1 extension GL_OES_shader_io_blocks.
559     // TODO(jiawei.shao@intel.com): add BLOCK_OUT.
560     // Also used in GLSL
561     ST_BLOCK_IN
562 };
563 
564 // Base class for all variables defined in shaders, including Varyings, Uniforms, etc
565 // Note: we must override the copy constructor and assignment operator so we can
566 // work around excessive GCC binary bloating:
567 // See https://code.google.com/p/angleproject/issues/detail?id=697
568 struct ST_ShaderVariable {
569     GLenum type;
570     GLenum precision;
571     const char* name;
572     const char* mappedName;
573 
574     unsigned int arraySizeCount;
575     unsigned int* pArraySizes;
576 
577     unsigned int staticUse;
578     unsigned int active;
579 
580     unsigned int fieldsCount;
581     ST_ShaderVariable* pFields;
582 
583     const char* structName;
584 
585     // Only applies to interface block fields. Kept here for simplicity.
586     unsigned int isRowMajorLayout;
587 
588     // VariableWithLocation
589     int location;
590 
591     // Uniform
592     int binding;
593 
594     GLenum imageUnitFormat;
595     int offset;
596     unsigned int readonly;
597     unsigned int writeonly;
598 
599     // OutputVariable
600     // From EXT_blend_func_extended.
601     int index;
602 
603     // Varying
604     ST_InterpolationType interpolation;
605     unsigned int isInvariant;
606 
607     int flattenedOffsetInParentArrays;
608 };
609 
610 struct ST_InterfaceBlock {
611     const char* name;
612     const char* mappedName;
613     const char* instanceName;
614     unsigned int arraySize;
615     ST_BlockLayoutType layout;
616 
617     // Deprecated. Matrix packing should only be queried from individual fields of the block.
618     // TODO(oetuaho): Remove this once it is no longer used in Chromium.
619     unsigned int isRowMajorLayout;
620 
621     int binding;
622     unsigned int staticUse;
623     unsigned int active;
624     ST_BlockType blockType;
625 
626     unsigned int fieldsCount;
627     ST_ShaderVariable* pFields;
628 };
629 
630 struct ST_WorkGroupSize {
631     int localSizeQualifiers[3];
632 };
633 
634 struct ST_NameHashingMap {
635     unsigned int entryCount;
636     const char* const* ppUserNames;
637     const char* const* ppCompiledNames;
638 };
639 
640 struct ST_ShaderCompileInfo {
641     ST_Handle inputHandle;
642     GLenum type;
643     ST_ShaderSpec spec;
644     ST_ShaderOutput output;
645     ST_CompileOptions compileOptions;
646     const ST_BuiltInResources *pResources;
647     const char* pShaderString;
648 };
649 
650 // A one-stop shop for getting all shader info in one call
651 // Everything is written and allocated by the library, transferring ownership
652 // to the consumer. The consumer will need to call STFreeShaderResolveState()
653 // to free the memory.
654 struct ST_ShaderCompileResult {
655     ST_Handle outputHandle;
656     GLenum type;
657     int version;
658 
659     const char* originalSource;
660     const char* translatedSource;
661     const char* infoLog;
662 
663     ST_NameHashingMap* nameHashingMap;
664 
665     ST_WorkGroupSize workGroupSize;
666     unsigned int sharedMemSize;
667 
668     unsigned int inputVaryingsCount;
669     const ST_ShaderVariable* pInputVaryings;
670 
671     unsigned int outputVaryingsCount;
672     const ST_ShaderVariable* pOutputVaryings;
673 
674     unsigned int uniformsCount;
675     const ST_ShaderVariable* pUniforms;
676 
677     unsigned int uniformBlocksCount;
678     const ST_InterfaceBlock* pUniformBlocks;
679 
680     unsigned int shaderStorageBlocksCount;
681     const ST_InterfaceBlock* pShaderStorageBlocks;
682 
683     unsigned int allAttributesCount;
684     const ST_ShaderVariable* pAllAttributes;
685 
686     unsigned int activeAttributesCount;
687     const ST_ShaderVariable* pActiveAttributes;
688 
689     unsigned int activeOutputVariablesCount;
690     const ST_ShaderVariable* pActiveOutputVariables;
691 
692     bool earlyFragmentTestsOptimization;
693     int numViews;
694 
695     // Geometry shader
696     unsigned int geometryShaderInputPrimitiveType;
697     unsigned int geometryShaderOutputPrimitiveType;
698     unsigned int geometryShaderMaxVertices;
699     int geometryShaderMaxInvocations;
700     int geometryShaderInvocations;
701 
702     bool compileStatus;
703 };
704 
705 ANGLE_EXPORT void STInitialize(void);
706 ANGLE_EXPORT void STFinalize(void);
707 
708 ANGLE_EXPORT ST_BuiltInResources*
709 STGenerateResources(ST_BuiltInResources *pResources);
710 
711 ANGLE_EXPORT void STCompileAndResolve(
712     const ST_ShaderCompileInfo* pInfo,
713     ST_ShaderCompileResult** ppResult);
714 
715 ANGLE_EXPORT void STFreeShaderResolveState(
716     ST_ShaderCompileResult* state);
717 
718 ANGLE_EXPORT ST_ShaderVariable STCopyVariable(const ST_ShaderVariable* pInput);
719 ANGLE_EXPORT ST_InterfaceBlock STCopyInterfaceBlock(const ST_InterfaceBlock* pInput);
720 ANGLE_EXPORT void STDestroyVariable(ST_ShaderVariable* pInput);
721 ANGLE_EXPORT void STDestroyInterfaceBlock(ST_InterfaceBlock* pInput);
722 
723 typedef void (*STInitialize_t)(void);
724 typedef void (*STFinalize_t)(void);
725 
726 typedef ST_BuiltInResources*
727 (*STGenerateResources_t)(ST_BuiltInResources *pResources);
728 
729 typedef void (*STCompileAndResolve_t)(
730     const ST_ShaderCompileInfo* pInfo,
731     ST_ShaderCompileResult** ppResult);
732 
733 typedef void (*STFreeShaderResolveState_t)(
734     ST_ShaderCompileResult* state);
735 
736 typedef ST_ShaderVariable (*STCopyVariable_t)(const ST_ShaderVariable* pInput);
737 typedef ST_InterfaceBlock (*STCopyInterfaceBlock_t)(const ST_InterfaceBlock* pInput);
738 typedef void (*STDestroyVariable_t)(ST_ShaderVariable* pInput);
739 typedef void (*STDestroyInterfaceBlock_t)(ST_InterfaceBlock* pInput);
740 
741 struct STDispatch {
742     STInitialize_t initialize;
743     STFinalize_t finalize;
744     STGenerateResources_t generateResources;
745     STCompileAndResolve_t compileAndResolve;
746     STFreeShaderResolveState_t freeShaderResolveState;
747     STCopyVariable_t copyVariable;
748     STCopyInterfaceBlock_t copyInterfaceBlock;
749     STDestroyVariable_t destroyVariable;
750     STDestroyInterfaceBlock_t destroyInterfaceBlock;
751 };
752 
753 } // extern "C"
754