1 | // |
2 | // Copyright (c) 2002-2013 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 | #ifndef GLSLANG_SHADERLANG_H_ |
7 | #define GLSLANG_SHADERLANG_H_ |
8 | |
9 | #include <stddef.h> |
10 | |
11 | #if defined(__APPLE__) |
12 | #include "khrplatform.h" |
13 | #else |
14 | #include "../KHR/khrplatform.h" |
15 | #endif |
16 | |
17 | #include <array> |
18 | #include <map> |
19 | #include <set> |
20 | #include <string> |
21 | #include <vector> |
22 | |
23 | // |
24 | // This is the platform independent interface between an OGL driver |
25 | // and the shading language compiler. |
26 | // |
27 | |
28 | // Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h |
29 | #include "ShaderVars.h" |
30 | |
31 | // Version number for shader translation API. |
32 | // It is incremented every time the API changes. |
33 | #define ANGLE_SH_VERSION 206 |
34 | |
35 | enum ShShaderSpec |
36 | { |
37 | SH_GLES2_SPEC, |
38 | SH_WEBGL_SPEC, |
39 | |
40 | SH_GLES3_SPEC, |
41 | SH_WEBGL2_SPEC, |
42 | |
43 | SH_GLES3_1_SPEC, |
44 | SH_WEBGL3_SPEC, |
45 | }; |
46 | |
47 | enum ShShaderOutput |
48 | { |
49 | // ESSL output only supported in some configurations. |
50 | SH_ESSL_OUTPUT = 0x8B45, |
51 | |
52 | // GLSL output only supported in some configurations. |
53 | SH_GLSL_COMPATIBILITY_OUTPUT = 0x8B46, |
54 | // Note: GL introduced core profiles in 1.5. |
55 | SH_GLSL_130_OUTPUT = 0x8B47, |
56 | SH_GLSL_140_OUTPUT = 0x8B80, |
57 | SH_GLSL_150_CORE_OUTPUT = 0x8B81, |
58 | SH_GLSL_330_CORE_OUTPUT = 0x8B82, |
59 | SH_GLSL_400_CORE_OUTPUT = 0x8B83, |
60 | SH_GLSL_410_CORE_OUTPUT = 0x8B84, |
61 | SH_GLSL_420_CORE_OUTPUT = 0x8B85, |
62 | SH_GLSL_430_CORE_OUTPUT = 0x8B86, |
63 | SH_GLSL_440_CORE_OUTPUT = 0x8B87, |
64 | SH_GLSL_450_CORE_OUTPUT = 0x8B88, |
65 | |
66 | // Prefer using these to specify HLSL output type: |
67 | SH_HLSL_3_0_OUTPUT = 0x8B48, // D3D 9 |
68 | SH_HLSL_4_1_OUTPUT = 0x8B49, // D3D 11 |
69 | SH_HLSL_4_0_FL9_3_OUTPUT = 0x8B4A, // D3D 11 feature level 9_3 |
70 | |
71 | // Output specialized GLSL to be fed to glslang for Vulkan SPIR. |
72 | SH_GLSL_VULKAN_OUTPUT = 0x8B4B, |
73 | }; |
74 | |
75 | // Compile options. |
76 | // The Compile options type is defined in ShaderVars.h, to allow ANGLE to import the ShaderVars |
77 | // header without needing the ShaderLang header. This avoids some conflicts with glslang. |
78 | |
79 | const ShCompileOptions SH_VALIDATE = 0; |
80 | const ShCompileOptions SH_VALIDATE_LOOP_INDEXING = UINT64_C(1) << 0; |
81 | const ShCompileOptions SH_INTERMEDIATE_TREE = UINT64_C(1) << 1; |
82 | const ShCompileOptions SH_OBJECT_CODE = UINT64_C(1) << 2; |
83 | const ShCompileOptions SH_VARIABLES = UINT64_C(1) << 3; |
84 | const ShCompileOptions SH_LINE_DIRECTIVES = UINT64_C(1) << 4; |
85 | const ShCompileOptions SH_SOURCE_PATH = UINT64_C(1) << 5; |
86 | |
87 | // This flag will keep invariant declaration for input in fragment shader for GLSL >=4.20 on AMD. |
88 | // From GLSL >= 4.20, it's optional to add invariant for fragment input, but GPU vendors have |
89 | // different implementations about this. Some drivers forbid invariant in fragment for GLSL>= 4.20, |
90 | // e.g. Linux Mesa, some drivers treat that as optional, e.g. NVIDIA, some drivers require invariant |
91 | // must match between vertex and fragment shader, e.g. AMD. The behavior on AMD is obviously wrong. |
92 | // Remove invariant for input in fragment shader to workaround the restriction on Intel Mesa. |
93 | // But don't remove on AMD Linux to avoid triggering the bug on AMD. |
94 | const ShCompileOptions SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT = UINT64_C(1) << 6; |
95 | |
96 | // Due to spec difference between GLSL 4.1 or lower and ESSL3, some platforms (for example, Mac OSX |
97 | // core profile) require a variable's "invariant"/"centroid" qualifiers to match between vertex and |
98 | // fragment shader. A simple solution to allow such shaders to link is to omit the two qualifiers. |
99 | // AMD driver in Linux requires invariant qualifier to match between vertex and fragment shaders, |
100 | // while ESSL3 disallows invariant qualifier in fragment shader and GLSL >= 4.2 doesn't require |
101 | // invariant qualifier to match between shaders. Remove invariant qualifier from vertex shader to |
102 | // workaround AMD driver bug. |
103 | // Note that the two flags take effect on ESSL3 input shaders translated to GLSL 4.1 or lower and to |
104 | // GLSL 4.2 or newer on Linux AMD. |
105 | // TODO(zmo): This is not a good long-term solution. Simply dropping these qualifiers may break some |
106 | // developers' content. A more complex workaround of dynamically generating, compiling, and |
107 | // re-linking shaders that use these qualifiers should be implemented. |
108 | const ShCompileOptions SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3 = UINT64_C(1) << 7; |
109 | |
110 | // This flag works around bug in Intel Mac drivers related to abs(i) where |
111 | // i is an integer. |
112 | const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 8; |
113 | |
114 | // Enforce the GLSL 1.017 Appendix A section 7 packing restrictions. |
115 | // This flag only enforces (and can only enforce) the packing |
116 | // restrictions for uniform variables in both vertex and fragment |
117 | // shaders. ShCheckVariablesWithinPackingLimits() lets embedders |
118 | // enforce the packing restrictions for varying variables during |
119 | // program link time. |
120 | const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 9; |
121 | |
122 | // This flag ensures all indirect (expression-based) array indexing |
123 | // is clamped to the bounds of the array. This ensures, for example, |
124 | // that you cannot read off the end of a uniform, whether an array |
125 | // vec234, or mat234 type. The ShArrayIndexClampingStrategy enum, |
126 | // specified in the ShBuiltInResources when constructing the |
127 | // compiler, selects the strategy for the clamping implementation. |
128 | const ShCompileOptions SH_CLAMP_INDIRECT_ARRAY_BOUNDS = UINT64_C(1) << 10; |
129 | |
130 | // This flag limits the complexity of an expression. |
131 | const ShCompileOptions SH_LIMIT_EXPRESSION_COMPLEXITY = UINT64_C(1) << 11; |
132 | |
133 | // This flag limits the depth of the call stack. |
134 | const ShCompileOptions SH_LIMIT_CALL_STACK_DEPTH = UINT64_C(1) << 12; |
135 | |
136 | // This flag initializes gl_Position to vec4(0,0,0,0) at the |
137 | // beginning of the vertex shader's main(), and has no effect in the |
138 | // fragment shader. It is intended as a workaround for drivers which |
139 | // incorrectly fail to link programs if gl_Position is not written. |
140 | const ShCompileOptions SH_INIT_GL_POSITION = UINT64_C(1) << 13; |
141 | |
142 | // This flag replaces |
143 | // "a && b" with "a ? b : false", |
144 | // "a || b" with "a ? true : b". |
145 | // This is to work around a MacOSX driver bug that |b| is executed |
146 | // independent of |a|'s value. |
147 | const ShCompileOptions SH_UNFOLD_SHORT_CIRCUIT = UINT64_C(1) << 14; |
148 | |
149 | // This flag initializes output variables to 0 at the beginning of main(). |
150 | // It is to avoid undefined behaviors. |
151 | const ShCompileOptions SH_INIT_OUTPUT_VARIABLES = UINT64_C(1) << 15; |
152 | |
153 | // This flag scalarizes vec/ivec/bvec/mat constructor args. |
154 | // It is intended as a workaround for Linux/Mac driver bugs. |
155 | const ShCompileOptions SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS = UINT64_C(1) << 16; |
156 | |
157 | // This flag overwrites a struct name with a unique prefix. |
158 | // It is intended as a workaround for drivers that do not handle |
159 | // struct scopes correctly, including all Mac drivers and Linux AMD. |
160 | const ShCompileOptions SH_REGENERATE_STRUCT_NAMES = UINT64_C(1) << 17; |
161 | |
162 | // This flag makes the compiler not prune unused function early in the |
163 | // compilation process. Pruning coupled with SH_LIMIT_CALL_STACK_DEPTH |
164 | // helps avoid bad shaders causing stack overflows. |
165 | const ShCompileOptions SH_DONT_PRUNE_UNUSED_FUNCTIONS = UINT64_C(1) << 18; |
166 | |
167 | // This flag works around a bug in NVIDIA 331 series drivers related |
168 | // to pow(x, y) where y is a constant vector. |
169 | const ShCompileOptions SH_REMOVE_POW_WITH_CONSTANT_EXPONENT = UINT64_C(1) << 19; |
170 | |
171 | // This flag works around bugs in Mac drivers related to do-while by |
172 | // transforming them into an other construct. |
173 | const ShCompileOptions SH_REWRITE_DO_WHILE_LOOPS = UINT64_C(1) << 20; |
174 | |
175 | // This flag works around a bug in the HLSL compiler optimizer that folds certain |
176 | // constant pow expressions incorrectly. Only applies to the HLSL back-end. It works |
177 | // by expanding the integer pow expressions into a series of multiplies. |
178 | const ShCompileOptions SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS = UINT64_C(1) << 21; |
179 | |
180 | // Flatten "#pragma STDGL invariant(all)" into the declarations of |
181 | // varying variables and built-in GLSL variables. This compiler |
182 | // option is enabled automatically when needed. |
183 | const ShCompileOptions SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL = UINT64_C(1) << 22; |
184 | |
185 | // Some drivers do not take into account the base level of the texture in the results of the |
186 | // HLSL GetDimensions builtin. This flag instructs the compiler to manually add the base level |
187 | // offsetting. |
188 | const ShCompileOptions SH_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL = UINT64_C(1) << 23; |
189 | |
190 | // This flag works around an issue in translating GLSL function texelFetchOffset on |
191 | // INTEL drivers. It works by translating texelFetchOffset into texelFetch. |
192 | const ShCompileOptions SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH = UINT64_C(1) << 24; |
193 | |
194 | // This flag works around condition bug of for and while loops in Intel Mac OSX drivers. |
195 | // Condition calculation is not correct. Rewrite it from "CONDITION" to "CONDITION && true". |
196 | const ShCompileOptions SH_ADD_AND_TRUE_TO_LOOP_CONDITION = UINT64_C(1) << 25; |
197 | |
198 | // This flag works around a bug in evaluating unary minus operator on integer on some INTEL |
199 | // drivers. It works by translating -(int) into ~(int) + 1. |
200 | const ShCompileOptions SH_REWRITE_INTEGER_UNARY_MINUS_OPERATOR = UINT64_C(1) << 26; |
201 | |
202 | // This flag works around a bug in evaluating isnan() on some INTEL D3D and Mac OSX drivers. |
203 | // It works by using an expression to emulate this function. |
204 | const ShCompileOptions SH_EMULATE_ISNAN_FLOAT_FUNCTION = UINT64_C(1) << 27; |
205 | |
206 | // This flag will use all uniforms of unused std140 and shared uniform blocks at the |
207 | // beginning of the vertex/fragment shader's main(). It is intended as a workaround for Mac |
208 | // drivers with shader version 4.10. In those drivers, they will treat unused |
209 | // std140 and shared uniform blocks' members as inactive. However, WebGL2.0 based on |
210 | // OpenGL ES3.0.4 requires all members of a named uniform block declared with a shared or std140 |
211 | // layout qualifier to be considered active. The uniform block itself is also considered active. |
212 | const ShCompileOptions SH_USE_UNUSED_STANDARD_SHARED_BLOCKS = UINT64_C(1) << 28; |
213 | |
214 | // This flag works around a bug in unary minus operator on float numbers on Intel |
215 | // Mac OSX 10.11 drivers. It works by translating -float into 0.0 - float. |
216 | const ShCompileOptions SH_REWRITE_FLOAT_UNARY_MINUS_OPERATOR = UINT64_C(1) << 29; |
217 | |
218 | // This flag works around a bug in evaluating atan(y, x) on some NVIDIA OpenGL drivers. |
219 | // It works by using an expression to emulate this function. |
220 | const ShCompileOptions SH_EMULATE_ATAN2_FLOAT_FUNCTION = UINT64_C(1) << 30; |
221 | |
222 | // Set to initialize uninitialized local and global temporary variables. Should only be used with |
223 | // GLSL output. In HLSL output variables are initialized regardless of if this flag is set. |
224 | const ShCompileOptions SH_INITIALIZE_UNINITIALIZED_LOCALS = UINT64_C(1) << 31; |
225 | |
226 | // The flag modifies the shader in the following way: |
227 | // Every occurrence of gl_InstanceID is replaced by the global temporary variable InstanceID. |
228 | // Every occurrence of gl_ViewID_OVR is replaced by the varying variable ViewID_OVR. |
229 | // At the beginning of the body of main() in a vertex shader the following initializers are added: |
230 | // ViewID_OVR = uint(gl_InstanceID) % num_views; |
231 | // InstanceID = gl_InstanceID / num_views; |
232 | // ViewID_OVR is added as a varying variable to both the vertex and fragment shaders. |
233 | const ShCompileOptions SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW = UINT64_C(1) << 32; |
234 | |
235 | // With the flag enabled the GLSL/ESSL vertex shader is modified to include code for viewport |
236 | // selection in the following way: |
237 | // - Code to enable the extension NV_viewport_array2 is included. |
238 | // - Code to select the viewport index or layer is inserted at the beginning of main after |
239 | // ViewID_OVR's initialization. |
240 | // - A declaration of the uniform multiviewBaseViewLayerIndex. |
241 | // Note: The SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW flag also has to be enabled to have the |
242 | // temporary variable ViewID_OVR declared and initialized. |
243 | const ShCompileOptions SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER = UINT64_C(1) << 33; |
244 | |
245 | // If the flag is enabled, gl_PointSize is clamped to the maximum point size specified in |
246 | // ShBuiltInResources in vertex shaders. |
247 | const ShCompileOptions SH_CLAMP_POINT_SIZE = UINT64_C(1) << 34; |
248 | |
249 | // Turn some arithmetic operations that operate on a float vector-scalar pair into vector-vector |
250 | // operations. This is done recursively. Some scalar binary operations inside vector constructors |
251 | // are also turned into vector operations. |
252 | // |
253 | // This is targeted to work around a bug in NVIDIA OpenGL drivers that was reproducible on NVIDIA |
254 | // driver version 387.92. It works around the most common occurrences of the bug. |
255 | const ShCompileOptions SH_REWRITE_VECTOR_SCALAR_ARITHMETIC = UINT64_C(1) << 35; |
256 | |
257 | // Don't use loops to initialize uninitialized variables. Only has an effect if some kind of |
258 | // variable initialization is turned on. |
259 | const ShCompileOptions SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES = UINT64_C(1) << 36; |
260 | |
261 | // Don't use D3D constant register zero when allocating space for uniforms. This is targeted to work |
262 | // around a bug in NVIDIA D3D driver version 388.59 where in very specific cases the driver would |
263 | // not handle constant register zero correctly. Only has an effect on HLSL translation. |
264 | const ShCompileOptions SH_SKIP_D3D_CONSTANT_REGISTER_ZERO = UINT64_C(1) << 37; |
265 | |
266 | // Clamp gl_FragDepth to the range [0.0, 1.0] in case it is statically used. |
267 | const ShCompileOptions SH_CLAMP_FRAG_DEPTH = UINT64_C(1) << 38; |
268 | |
269 | // Rewrite expressions like "v.x = z = expression;". Works around a bug in NVIDIA OpenGL drivers |
270 | // prior to version 397.31. |
271 | const ShCompileOptions SH_REWRITE_REPEATED_ASSIGN_TO_SWIZZLED = UINT64_C(1) << 39; |
272 | |
273 | // Rewrite gl_DrawID as a uniform int |
274 | const ShCompileOptions SH_EMULATE_GL_DRAW_ID = UINT64_C(1) << 40; |
275 | |
276 | // This flag initializes shared variables to 0. |
277 | // It is to avoid ompute shaders being able to read undefined values that could be coming from |
278 | // another webpage/application. |
279 | const ShCompileOptions SH_INIT_SHARED_VARIABLES = UINT64_C(1) << 41; |
280 | |
281 | // Forces the value returned from an atomic operations to be always be resolved. This is targeted to |
282 | // workaround a bug in NVIDIA D3D driver where the return value from |
283 | // RWByteAddressBuffer.InterlockedAdd does not get resolved when used in the .yzw components of a |
284 | // RWByteAddressBuffer.Store operation. Only has an effect on HLSL translation. |
285 | // http://anglebug.com/3246 |
286 | const ShCompileOptions SH_FORCE_ATOMIC_VALUE_RESOLUTION = UINT64_C(1) << 42; |
287 | |
288 | // Defines alternate strategies for implementing array index clamping. |
289 | enum ShArrayIndexClampingStrategy |
290 | { |
291 | // Use the clamp intrinsic for array index clamping. |
292 | SH_CLAMP_WITH_CLAMP_INTRINSIC = 1, |
293 | |
294 | // Use a user-defined function for array index clamping. |
295 | SH_CLAMP_WITH_USER_DEFINED_INT_CLAMP_FUNCTION |
296 | }; |
297 | |
298 | // The 64 bits hash function. The first parameter is the input string; the |
299 | // second parameter is the string length. |
300 | using ShHashFunction64 = khronos_uint64_t (*)(const char *, size_t); |
301 | |
302 | // |
303 | // Implementation dependent built-in resources (constants and extensions). |
304 | // The names for these resources has been obtained by stripping gl_/GL_. |
305 | // |
306 | struct ShBuiltInResources |
307 | { |
308 | // Constants. |
309 | int MaxVertexAttribs; |
310 | int MaxVertexUniformVectors; |
311 | int MaxVaryingVectors; |
312 | int MaxVertexTextureImageUnits; |
313 | int MaxCombinedTextureImageUnits; |
314 | int MaxTextureImageUnits; |
315 | int MaxFragmentUniformVectors; |
316 | int MaxDrawBuffers; |
317 | |
318 | // Extensions. |
319 | // Set to 1 to enable the extension, else 0. |
320 | int OES_standard_derivatives; |
321 | int OES_EGL_image_external; |
322 | int OES_EGL_image_external_essl3; |
323 | int NV_EGL_stream_consumer_external; |
324 | int ARB_texture_rectangle; |
325 | int EXT_blend_func_extended; |
326 | int EXT_draw_buffers; |
327 | int EXT_frag_depth; |
328 | int EXT_shader_texture_lod; |
329 | int WEBGL_debug_shader_precision; |
330 | int EXT_shader_framebuffer_fetch; |
331 | int NV_shader_framebuffer_fetch; |
332 | int ARM_shader_framebuffer_fetch; |
333 | int OVR_multiview2; |
334 | int EXT_YUV_target; |
335 | int EXT_geometry_shader; |
336 | int OES_texture_storage_multisample_2d_array; |
337 | int ANGLE_texture_multisample; |
338 | int ANGLE_multi_draw; |
339 | |
340 | // Set to 1 to enable replacing GL_EXT_draw_buffers #extension directives |
341 | // with GL_NV_draw_buffers in ESSL output. This flag can be used to emulate |
342 | // EXT_draw_buffers by using it in combination with GLES3.0 glDrawBuffers |
343 | // function. This applies to Tegra K1 devices. |
344 | int NV_draw_buffers; |
345 | |
346 | // Set to 1 if highp precision is supported in the ESSL 1.00 version of the |
347 | // fragment language. Does not affect versions of the language where highp |
348 | // support is mandatory. |
349 | // Default is 0. |
350 | int FragmentPrecisionHigh; |
351 | |
352 | // GLSL ES 3.0 constants. |
353 | int MaxVertexOutputVectors; |
354 | int MaxFragmentInputVectors; |
355 | int MinProgramTexelOffset; |
356 | int MaxProgramTexelOffset; |
357 | |
358 | // Extension constants. |
359 | |
360 | // Value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT for OpenGL ES output context. |
361 | // Value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS for OpenGL output context. |
362 | // GLES SL version 100 gl_MaxDualSourceDrawBuffersEXT value for EXT_blend_func_extended. |
363 | int MaxDualSourceDrawBuffers; |
364 | |
365 | // Value of GL_MAX_VIEWS_OVR. |
366 | int MaxViewsOVR; |
367 | |
368 | // Name Hashing. |
369 | // Set a 64 bit hash function to enable user-defined name hashing. |
370 | // Default is NULL. |
371 | ShHashFunction64 HashFunction; |
372 | |
373 | // Selects a strategy to use when implementing array index clamping. |
374 | // Default is SH_CLAMP_WITH_CLAMP_INTRINSIC. |
375 | ShArrayIndexClampingStrategy ArrayIndexClampingStrategy; |
376 | |
377 | // The maximum complexity an expression can be when SH_LIMIT_EXPRESSION_COMPLEXITY is turned on. |
378 | int MaxExpressionComplexity; |
379 | |
380 | // The maximum depth a call stack can be. |
381 | int MaxCallStackDepth; |
382 | |
383 | // The maximum number of parameters a function can have when SH_LIMIT_EXPRESSION_COMPLEXITY is |
384 | // turned on. |
385 | int MaxFunctionParameters; |
386 | |
387 | // GLES 3.1 constants |
388 | |
389 | // texture gather offset constraints. |
390 | int MinProgramTextureGatherOffset; |
391 | int MaxProgramTextureGatherOffset; |
392 | |
393 | // maximum number of available image units |
394 | int MaxImageUnits; |
395 | |
396 | // maximum number of image uniforms in a vertex shader |
397 | int MaxVertexImageUniforms; |
398 | |
399 | // maximum number of image uniforms in a fragment shader |
400 | int MaxFragmentImageUniforms; |
401 | |
402 | // maximum number of image uniforms in a compute shader |
403 | int MaxComputeImageUniforms; |
404 | |
405 | // maximum total number of image uniforms in a program |
406 | int MaxCombinedImageUniforms; |
407 | |
408 | // maximum number of uniform locations |
409 | int MaxUniformLocations; |
410 | |
411 | // maximum number of ssbos and images in a shader |
412 | int MaxCombinedShaderOutputResources; |
413 | |
414 | // maximum number of groups in each dimension |
415 | std::array<int, 3> MaxComputeWorkGroupCount; |
416 | // maximum number of threads per work group in each dimension |
417 | std::array<int, 3> MaxComputeWorkGroupSize; |
418 | |
419 | // maximum number of total uniform components |
420 | int MaxComputeUniformComponents; |
421 | |
422 | // maximum number of texture image units in a compute shader |
423 | int MaxComputeTextureImageUnits; |
424 | |
425 | // maximum number of atomic counters in a compute shader |
426 | int MaxComputeAtomicCounters; |
427 | |
428 | // maximum number of atomic counter buffers in a compute shader |
429 | int MaxComputeAtomicCounterBuffers; |
430 | |
431 | // maximum number of atomic counters in a vertex shader |
432 | int MaxVertexAtomicCounters; |
433 | |
434 | // maximum number of atomic counters in a fragment shader |
435 | int MaxFragmentAtomicCounters; |
436 | |
437 | // maximum number of atomic counters in a program |
438 | int MaxCombinedAtomicCounters; |
439 | |
440 | // maximum binding for an atomic counter |
441 | int MaxAtomicCounterBindings; |
442 | |
443 | // maximum number of atomic counter buffers in a vertex shader |
444 | int MaxVertexAtomicCounterBuffers; |
445 | |
446 | // maximum number of atomic counter buffers in a fragment shader |
447 | int MaxFragmentAtomicCounterBuffers; |
448 | |
449 | // maximum number of atomic counter buffers in a program |
450 | int MaxCombinedAtomicCounterBuffers; |
451 | |
452 | // maximum number of buffer object storage in machine units |
453 | int MaxAtomicCounterBufferSize; |
454 | |
455 | // maximum number of uniform block bindings |
456 | int MaxUniformBufferBindings; |
457 | |
458 | // maximum number of shader storage buffer bindings |
459 | int MaxShaderStorageBufferBindings; |
460 | |
461 | // maximum point size (higher limit from ALIASED_POINT_SIZE_RANGE) |
462 | float MaxPointSize; |
463 | |
464 | // EXT_geometry_shader constants |
465 | int MaxGeometryUniformComponents; |
466 | int MaxGeometryUniformBlocks; |
467 | int MaxGeometryInputComponents; |
468 | int MaxGeometryOutputComponents; |
469 | int MaxGeometryOutputVertices; |
470 | int MaxGeometryTotalOutputComponents; |
471 | int MaxGeometryTextureImageUnits; |
472 | int MaxGeometryAtomicCounterBuffers; |
473 | int MaxGeometryAtomicCounters; |
474 | int MaxGeometryShaderStorageBlocks; |
475 | int MaxGeometryShaderInvocations; |
476 | int MaxGeometryImageUniforms; |
477 | }; |
478 | |
479 | // |
480 | // ShHandle held by but opaque to the driver. It is allocated, |
481 | // managed, and de-allocated by the compiler. Its contents |
482 | // are defined by and used by the compiler. |
483 | // |
484 | // If handle creation fails, 0 will be returned. |
485 | // |
486 | using ShHandle = void *; |
487 | |
488 | namespace sh |
489 | { |
490 | |
491 | // |
492 | // Driver must call this first, once, before doing any other compiler operations. |
493 | // If the function succeeds, the return value is true, else false. |
494 | // |
495 | bool Initialize(); |
496 | // |
497 | // Driver should call this at shutdown. |
498 | // If the function succeeds, the return value is true, else false. |
499 | // |
500 | bool Finalize(); |
501 | |
502 | // |
503 | // Initialize built-in resources with minimum expected values. |
504 | // Parameters: |
505 | // resources: The object to initialize. Will be comparable with memcmp. |
506 | // |
507 | void InitBuiltInResources(ShBuiltInResources *resources); |
508 | |
509 | // |
510 | // Returns the a concatenated list of the items in ShBuiltInResources as a null-terminated string. |
511 | // This function must be updated whenever ShBuiltInResources is changed. |
512 | // Parameters: |
513 | // handle: Specifies the handle of the compiler to be used. |
514 | const std::string &GetBuiltInResourcesString(const ShHandle handle); |
515 | |
516 | // |
517 | // Driver calls these to create and destroy compiler objects. |
518 | // |
519 | // Returns the handle of constructed compiler, null if the requested compiler is not supported. |
520 | // Parameters: |
521 | // type: Specifies the type of shader - GL_FRAGMENT_SHADER or GL_VERTEX_SHADER. |
522 | // spec: Specifies the language spec the compiler must conform to - SH_GLES2_SPEC or SH_WEBGL_SPEC. |
523 | // output: Specifies the output code type - for example SH_ESSL_OUTPUT, SH_GLSL_OUTPUT, |
524 | // SH_HLSL_3_0_OUTPUT or SH_HLSL_4_1_OUTPUT. Note: Each output type may only |
525 | // be supported in some configurations. |
526 | // resources: Specifies the built-in resources. |
527 | ShHandle ConstructCompiler(sh::GLenum type, |
528 | ShShaderSpec spec, |
529 | ShShaderOutput output, |
530 | const ShBuiltInResources *resources); |
531 | void Destruct(ShHandle handle); |
532 | |
533 | // |
534 | // Compiles the given shader source. |
535 | // If the function succeeds, the return value is true, else false. |
536 | // Parameters: |
537 | // handle: Specifies the handle of compiler to be used. |
538 | // shaderStrings: Specifies an array of pointers to null-terminated strings containing the shader |
539 | // source code. |
540 | // numStrings: Specifies the number of elements in shaderStrings array. |
541 | // compileOptions: A mask containing the following parameters: |
542 | // SH_VALIDATE: Validates shader to ensure that it conforms to the spec |
543 | // specified during compiler construction. |
544 | // SH_VALIDATE_LOOP_INDEXING: Validates loop and indexing in the shader to |
545 | // ensure that they do not exceed the minimum |
546 | // functionality mandated in GLSL 1.0 spec, |
547 | // Appendix A, Section 4 and 5. |
548 | // There is no need to specify this parameter when |
549 | // compiling for WebGL - it is implied. |
550 | // SH_INTERMEDIATE_TREE: Writes intermediate tree to info log. |
551 | // Can be queried by calling sh::GetInfoLog(). |
552 | // SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader. |
553 | // Can be queried by calling sh::GetObjectCode(). |
554 | // SH_VARIABLES: Extracts attributes, uniforms, and varyings. |
555 | // Can be queried by calling ShGetVariableInfo(). |
556 | // |
557 | bool Compile(const ShHandle handle, |
558 | const char *const shaderStrings[], |
559 | size_t numStrings, |
560 | ShCompileOptions compileOptions); |
561 | |
562 | // Clears the results from the previous compilation. |
563 | void ClearResults(const ShHandle handle); |
564 | |
565 | // Return the version of the shader language. |
566 | int GetShaderVersion(const ShHandle handle); |
567 | |
568 | // Return the currently set language output type. |
569 | ShShaderOutput GetShaderOutputType(const ShHandle handle); |
570 | |
571 | // Returns null-terminated information log for a compiled shader. |
572 | // Parameters: |
573 | // handle: Specifies the compiler |
574 | const std::string &GetInfoLog(const ShHandle handle); |
575 | |
576 | // Returns null-terminated object code for a compiled shader. |
577 | // Parameters: |
578 | // handle: Specifies the compiler |
579 | const std::string &GetObjectCode(const ShHandle handle); |
580 | |
581 | // Returns a (original_name, hash) map containing all the user defined names in the shader, |
582 | // including variable names, function names, struct names, and struct field names. |
583 | // Parameters: |
584 | // handle: Specifies the compiler |
585 | const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle); |
586 | |
587 | // Shader variable inspection. |
588 | // Returns a pointer to a list of variables of the designated type. |
589 | // (See ShaderVars.h for type definitions, included above) |
590 | // Returns NULL on failure. |
591 | // Parameters: |
592 | // handle: Specifies the compiler |
593 | const std::vector<sh::Uniform> *GetUniforms(const ShHandle handle); |
594 | const std::vector<sh::Varying> *GetVaryings(const ShHandle handle); |
595 | const std::vector<sh::Varying> *GetInputVaryings(const ShHandle handle); |
596 | const std::vector<sh::Varying> *GetOutputVaryings(const ShHandle handle); |
597 | const std::vector<sh::Attribute> *GetAttributes(const ShHandle handle); |
598 | const std::vector<sh::OutputVariable> *GetOutputVariables(const ShHandle handle); |
599 | const std::vector<sh::InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle); |
600 | const std::vector<sh::InterfaceBlock> *GetUniformBlocks(const ShHandle handle); |
601 | const std::vector<sh::InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle); |
602 | sh::WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle); |
603 | // Returns the number of views specified through the num_views layout qualifier. If num_views is |
604 | // not set, the function returns -1. |
605 | int GetVertexShaderNumViews(const ShHandle handle); |
606 | |
607 | // Returns true if the passed in variables pack in maxVectors followingthe packing rules from the |
608 | // GLSL 1.017 spec, Appendix A, section 7. |
609 | // Returns false otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS |
610 | // flag above. |
611 | // Parameters: |
612 | // maxVectors: the available rows of registers. |
613 | // variables: an array of variables. |
614 | bool CheckVariablesWithinPackingLimits(int maxVectors, |
615 | const std::vector<sh::ShaderVariable> &variables); |
616 | |
617 | // Gives the compiler-assigned register for a shader storage block. |
618 | // The method writes the value to the output variable "indexOut". |
619 | // Returns true if it found a valid shader storage block, false otherwise. |
620 | // Parameters: |
621 | // handle: Specifies the compiler |
622 | // shaderStorageBlockName: Specifies the shader storage block |
623 | // indexOut: output variable that stores the assigned register |
624 | bool GetShaderStorageBlockRegister(const ShHandle handle, |
625 | const std::string &shaderStorageBlockName, |
626 | unsigned int *indexOut); |
627 | |
628 | // Gives the compiler-assigned register for a uniform block. |
629 | // The method writes the value to the output variable "indexOut". |
630 | // Returns true if it found a valid uniform block, false otherwise. |
631 | // Parameters: |
632 | // handle: Specifies the compiler |
633 | // uniformBlockName: Specifies the uniform block |
634 | // indexOut: output variable that stores the assigned register |
635 | bool GetUniformBlockRegister(const ShHandle handle, |
636 | const std::string &uniformBlockName, |
637 | unsigned int *indexOut); |
638 | |
639 | // Gives a map from uniform names to compiler-assigned registers in the default uniform block. |
640 | // Note that the map contains also registers of samplers that have been extracted from structs. |
641 | const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle); |
642 | |
643 | // Sampler, image and atomic counters share registers(t type and u type), |
644 | // GetReadonlyImage2DRegisterIndex and GetImage2DRegisterIndex return the first index into |
645 | // a range of reserved registers for image2D/iimage2D/uimage2D variables. |
646 | // Parameters: handle: Specifies the compiler |
647 | unsigned int GetReadonlyImage2DRegisterIndex(const ShHandle handle); |
648 | unsigned int GetImage2DRegisterIndex(const ShHandle handle); |
649 | |
650 | // The method records these used function names related with image2D/iimage2D/uimage2D, these |
651 | // functions will be dynamically generated. |
652 | // Parameters: |
653 | // handle: Specifies the compiler |
654 | const std::set<std::string> *GetUsedImage2DFunctionNames(const ShHandle handle); |
655 | |
656 | bool HasValidGeometryShaderInputPrimitiveType(const ShHandle handle); |
657 | bool HasValidGeometryShaderOutputPrimitiveType(const ShHandle handle); |
658 | bool HasValidGeometryShaderMaxVertices(const ShHandle handle); |
659 | GLenum GetGeometryShaderInputPrimitiveType(const ShHandle handle); |
660 | GLenum GetGeometryShaderOutputPrimitiveType(const ShHandle handle); |
661 | int GetGeometryShaderInvocations(const ShHandle handle); |
662 | int GetGeometryShaderMaxVertices(const ShHandle handle); |
663 | |
664 | // |
665 | // Helper function to identify specs that are based on the WebGL spec. |
666 | // |
667 | inline bool IsWebGLBasedSpec(ShShaderSpec spec) |
668 | { |
669 | return (spec == SH_WEBGL_SPEC || spec == SH_WEBGL2_SPEC || spec == SH_WEBGL3_SPEC); |
670 | } |
671 | } // namespace sh |
672 | |
673 | #endif // GLSLANG_SHADERLANG_H_ |
674 | |