xref: /aosp_15_r20/external/angle/include/GLSLANG/ShaderLang.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2002 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 #include "KHR/khrplatform.h"
12 
13 #include <array>
14 #include <map>
15 #include <set>
16 #include <string>
17 #include <vector>
18 
19 //
20 // This is the platform independent interface between an OGL driver
21 // and the shading language compiler.
22 //
23 
24 // Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h
25 #include "ShaderVars.h"
26 
27 // Version number for shader translation API.
28 // It is incremented every time the API changes.
29 #define ANGLE_SH_VERSION 371
30 
31 enum ShShaderSpec
32 {
33     SH_GLES2_SPEC,
34     SH_WEBGL_SPEC,
35 
36     SH_GLES3_SPEC,
37     SH_WEBGL2_SPEC,
38 
39     SH_GLES3_1_SPEC,
40     SH_WEBGL3_SPEC,
41 
42     SH_GLES3_2_SPEC,
43 };
44 
45 enum ShShaderOutput
46 {
47     // NULL output for testing.
48     SH_NULL_OUTPUT,
49 
50     // ESSL output only supported in some configurations.
51     SH_ESSL_OUTPUT,
52 
53     // GLSL output only supported in some configurations.
54     SH_GLSL_COMPATIBILITY_OUTPUT,
55     // Note: GL introduced core profiles in 1.5.
56     SH_GLSL_130_OUTPUT,
57     SH_GLSL_140_OUTPUT,
58     SH_GLSL_150_CORE_OUTPUT,
59     SH_GLSL_330_CORE_OUTPUT,
60     SH_GLSL_400_CORE_OUTPUT,
61     SH_GLSL_410_CORE_OUTPUT,
62     SH_GLSL_420_CORE_OUTPUT,
63     SH_GLSL_430_CORE_OUTPUT,
64     SH_GLSL_440_CORE_OUTPUT,
65     SH_GLSL_450_CORE_OUTPUT,
66 
67     // Prefer using these to specify HLSL output type:
68     SH_HLSL_3_0_OUTPUT,  // D3D 9
69     SH_HLSL_4_1_OUTPUT,  // D3D 11
70 
71     // Output SPIR-V for the Vulkan backend.
72     SH_SPIRV_VULKAN_OUTPUT,
73 
74     // Output for MSL
75     SH_MSL_METAL_OUTPUT,
76 
77     // Output for WGSL
78     SH_WGSL_OUTPUT,
79 };
80 
81 struct ShCompileOptionsMetal
82 {
83     // Direct-to-metal backend constants:
84 
85     // Binding index for driver uniforms:
86     int driverUniformsBindingIndex = 0;
87     // Binding index for default uniforms:
88     int defaultUniformsBindingIndex = 0;
89     // Binding index for UBO's argument buffer
90     int UBOArgumentBufferBindingIndex = 0;
91 
92     bool generateShareableShaders = false;
93 
94     // Insert asm("") instructions into loop bodies, telling the compiler that all loops have side
95     // effects and cannot be optimized out.
96     bool injectAsmStatementIntoLoopBodies = false;
97 };
98 
99 // For ANGLE_shader_pixel_local_storage.
100 // Instructs the compiler which pixel local storage configuration to generate code for.
101 enum class ShPixelLocalStorageType : uint8_t
102 {
103     NotSupported,
104     ImageLoadStore,
105     FramebufferFetch,
106 };
107 
108 // For ANGLE_shader_pixel_local_storage.
109 // Used to track the PLS format at each binding index in a shader.
110 enum class ShPixelLocalStorageFormat : uint8_t
111 {
112     NotPLS,  // Indicates that no PLS uniform was declared at the binding index in question.
113     RGBA8,
114     RGBA8I,
115     RGBA8UI,
116     R32F,
117     R32UI,
118 };
119 
120 // For ANGLE_shader_pixel_local_storage_coherent.
121 // Instructs the compiler which fragment synchronization method to use, if any.
122 enum class ShFragmentSynchronizationType : uint8_t
123 {
124     NotSupported,  // Fragments cannot be ordered or synchronized.
125 
126     Automatic,  // Fragments are automatically raster-ordered and synchronized.
127 
128     FragmentShaderInterlock_NV_GL,
129     FragmentShaderOrdering_INTEL_GL,
130     FragmentShaderInterlock_ARB_GL,  // Also compiles to SPV_EXT_fragment_shader_interlock.
131 
132     RasterizerOrderViews_D3D,
133 
134     RasterOrderGroups_Metal,
135 
136     InvalidEnum,
137     EnumCount = InvalidEnum,
138 };
139 
140 struct ShPixelLocalStorageOptions
141 {
142     ShPixelLocalStorageType type = ShPixelLocalStorageType::NotSupported;
143 
144     // For ANGLE_shader_pixel_local_storage_coherent.
145     ShFragmentSynchronizationType fragmentSyncType = ShFragmentSynchronizationType::NotSupported;
146 
147     // ShPixelLocalStorageType::ImageLoadStore only: Can we use rgba8/rgba8i/rgba8ui image formats?
148     // Or do we need to manually pack and unpack from r32i/r32ui?
149     bool supportsNativeRGBA8ImageFormats = false;
150 
151     // anglebug.com/42266263 -- Metal [[raster_order_group()]] does not work for read_write textures
152     // on AMD when the render pass doesn't have a color attachment on slot 0. To work around this we
153     // attach one of the PLS textures to GL_COLOR_ATTACHMENT0, if there isn't one already.
154     bool renderPassNeedsAMDRasterOrderGroupsWorkaround = false;
155 };
156 
157 struct ShCompileOptions
158 {
159     ShCompileOptions();
160     ShCompileOptions(const ShCompileOptions &other);
161     ShCompileOptions &operator=(const ShCompileOptions &other);
162 
163     // Translates intermediate tree to glsl, hlsl, msl, or SPIR-V binary.  Can be queried by
164     // calling sh::GetObjectCode().
165     uint64_t objectCode : 1;
166 
167     // Whether debug info should be output in the shader.
168     uint64_t outputDebugInfo : 1;
169 
170     // Tracks the source path for shaders.  Can be queried with getSourcePath().
171     uint64_t sourcePath : 1;
172 
173     // Whether the internal representation of the AST should be output.
174     uint64_t intermediateTree : 1;
175 
176     // If requested, validates the AST after every transformation.  Useful for debugging.
177     uint64_t validateAST : 1;
178 
179     // Validates loop and indexing in the shader to ensure that they do not exceed the minimum
180     // functionality mandated in GLSL 1.0 spec, Appendix A, Section 4 and 5.  There is no need to
181     // specify this parameter when compiling for WebGL - it is implied.
182     uint64_t validateLoopIndexing : 1;
183 
184     // Emits #line directives in HLSL.
185     uint64_t lineDirectives : 1;
186 
187     // Due to spec difference between GLSL 4.1 or lower and ESSL3, some platforms (for example, Mac
188     // OSX core profile) require a variable's "invariant"/"centroid" qualifiers to match between
189     // vertex and fragment shader. A simple solution to allow such shaders to link is to omit the
190     // two qualifiers.  AMD driver in Linux requires invariant qualifier to match between vertex and
191     // fragment shaders, while ESSL3 disallows invariant qualifier in fragment shader and GLSL >=
192     // 4.2 doesn't require invariant qualifier to match between shaders. Remove invariant qualifier
193     // from vertex shader to workaround AMD driver bug.
194     // Note that the two flags take effect on ESSL3 input shaders translated to GLSL 4.1 or lower
195     // and to GLSL 4.2 or newer on Linux AMD.
196     // TODO(zmo): This is not a good long-term solution. Simply dropping these qualifiers may break
197     // some developers' content. A more complex workaround of dynamically generating, compiling, and
198     // re-linking shaders that use these qualifiers should be implemented.
199     uint64_t removeInvariantAndCentroidForESSL3 : 1;
200 
201     // This flag works around bug in Intel Mac drivers related to abs(i) where i is an integer.
202     uint64_t emulateAbsIntFunction : 1;
203 
204     // Enforce the GLSL 1.017 Appendix A section 7 packing restrictions.  This flag only enforces
205     // (and can only enforce) the packing restrictions for uniform variables in both vertex and
206     // fragment shaders. ShCheckVariablesWithinPackingLimits() lets embedders enforce the packing
207     // restrictions for varying variables during program link time.
208     uint64_t enforcePackingRestrictions : 1;
209 
210     // This flag ensures all indirect (expression-based) array indexing is clamped to the bounds of
211     // the array. This ensures, for example, that you cannot read off the end of a uniform, whether
212     // an array vec234, or mat234 type.
213     uint64_t clampIndirectArrayBounds : 1;
214 
215     // This flag limits the complexity of an expression.
216     uint64_t limitExpressionComplexity : 1;
217 
218     // This flag limits the depth of the call stack.
219     uint64_t limitCallStackDepth : 1;
220 
221     // This flag initializes gl_Position to vec4(0,0,0,0) at the beginning of the vertex shader's
222     // main(), and has no effect in the fragment shader. It is intended as a workaround for drivers
223     // which incorrectly fail to link programs if gl_Position is not written.
224     uint64_t initGLPosition : 1;
225 
226     // This flag replaces
227     //   "a && b" with "a ? b : false",
228     //   "a || b" with "a ? true : b".
229     // This is to work around a MacOSX driver bug that |b| is executed independent of |a|'s value.
230     uint64_t unfoldShortCircuit : 1;
231 
232     // This flag initializes output variables to 0 at the beginning of main().  It is to avoid
233     // undefined behaviors.
234     uint64_t initOutputVariables : 1;
235 
236     // This flag scalarizes vec/ivec/bvec/mat constructor args.  It is intended as a workaround for
237     // Linux/Mac driver bugs.
238     uint64_t scalarizeVecAndMatConstructorArgs : 1;
239 
240     // This flag overwrites a struct name with a unique prefix.  It is intended as a workaround for
241     // drivers that do not handle struct scopes correctly, including all Mac drivers and Linux AMD.
242     uint64_t regenerateStructNames : 1;
243 
244     // This flag works around bugs in Mac drivers related to do-while by transforming them into an
245     // other construct.
246     uint64_t rewriteDoWhileLoops : 1;
247 
248     // This flag works around a bug in the HLSL compiler optimizer that folds certain constant pow
249     // expressions incorrectly. Only applies to the HLSL back-end. It works by expanding the integer
250     // pow expressions into a series of multiplies.
251     uint64_t expandSelectHLSLIntegerPowExpressions : 1;
252 
253     // Flatten "#pragma STDGL invariant(all)" into the declarations of varying variables and
254     // built-in GLSL variables. This compiler option is enabled automatically when needed.
255     uint64_t flattenPragmaSTDGLInvariantAll : 1;
256 
257     // Some drivers do not take into account the base level of the texture in the results of the
258     // HLSL GetDimensions builtin.  This flag instructs the compiler to manually add the base level
259     // offsetting.
260     uint64_t HLSLGetDimensionsIgnoresBaseLevel : 1;
261 
262     // This flag works around an issue in translating GLSL function texelFetchOffset on INTEL
263     // drivers. It works by translating texelFetchOffset into texelFetch.
264     uint64_t rewriteTexelFetchOffsetToTexelFetch : 1;
265 
266     // This flag works around condition bug of for and while loops in Intel Mac OSX drivers.
267     // Condition calculation is not correct. Rewrite it from "CONDITION" to "CONDITION && true".
268     uint64_t addAndTrueToLoopCondition : 1;
269 
270     // This flag works around a bug in evaluating unary minus operator on integer on some INTEL
271     // drivers. It works by translating -(int) into ~(int) + 1.
272     uint64_t rewriteIntegerUnaryMinusOperator : 1;
273 
274     // This flag works around a bug in evaluating isnan() on some INTEL D3D and Mac OSX drivers.  It
275     // works by using an expression to emulate this function.
276     uint64_t emulateIsnanFloatFunction : 1;
277 
278     // This flag will use all uniforms of unused std140 and shared uniform blocks at the beginning
279     // of the vertex/fragment shader's main(). It is intended as a workaround for Mac drivers with
280     // shader version 4.10. In those drivers, they will treat unused std140 and shared uniform
281     // blocks' members as inactive. However, WebGL2.0 based on OpenGL ES3.0.4 requires all members
282     // of a named uniform block declared with a shared or std140 layout qualifier to be considered
283     // active. The uniform block itself is also considered active.
284     uint64_t useUnusedStandardSharedBlocks : 1;
285 
286     // This flag works around a bug in unary minus operator on float numbers on Intel Mac OSX 10.11
287     // drivers. It works by translating -float into 0.0 - float.
288     uint64_t rewriteFloatUnaryMinusOperator : 1;
289 
290     // This flag works around a bug in evaluating atan(y, x) on some NVIDIA OpenGL drivers.  It
291     // works by using an expression to emulate this function.
292     uint64_t emulateAtan2FloatFunction : 1;
293 
294     // Set to initialize uninitialized local and global temporary variables. Should only be used
295     // with GLSL output. In HLSL output variables are initialized regardless of if this flag is set.
296     uint64_t initializeUninitializedLocals : 1;
297 
298     // The flag modifies the shader in the following way:
299     //
300     // Every occurrence of gl_InstanceID is replaced by the global temporary variable InstanceID.
301     // Every occurrence of gl_ViewID_OVR is replaced by the varying variable ViewID_OVR.
302     // At the beginning of the body of main() in a vertex shader the following initializers are
303     // added:
304     //   ViewID_OVR = uint(gl_InstanceID) % num_views;
305     //   InstanceID = gl_InstanceID / num_views;
306     // ViewID_OVR is added as a varying variable to both the vertex and fragment shaders.
307     uint64_t initializeBuiltinsForInstancedMultiview : 1;
308 
309     // With the flag enabled the GLSL/ESSL vertex shader is modified to include code for viewport
310     // selection in the following way:
311     // - Code to enable the extension ARB_shader_viewport_layer_array/NV_viewport_array2 is
312     // included.
313     // - Code to select the viewport index or layer is inserted at the beginning of main after
314     //   ViewID_OVR's initialization.
315     // - A declaration of the uniform multiviewBaseViewLayerIndex.
316     // Note: The initializeBuiltinsForInstancedMultiview flag also has to be enabled to have the
317     // temporary variable ViewID_OVR declared and initialized.
318     uint64_t selectViewInNvGLSLVertexShader : 1;
319 
320     // If the flag is enabled, gl_PointSize is clamped to the maximum point size specified in
321     // ShBuiltInResources in vertex shaders.
322     uint64_t clampPointSize : 1;
323 
324     // This flag indicates whether advanced blend equation should be emulated.  Currently only
325     // implemented for the Vulkan backend.
326     uint64_t addAdvancedBlendEquationsEmulation : 1;
327 
328     // Don't use loops to initialize uninitialized variables. Only has an effect if some kind of
329     // variable initialization is turned on.
330     uint64_t dontUseLoopsToInitializeVariables : 1;
331 
332     // Don't use D3D constant register zero when allocating space for uniforms. This is targeted to
333     // work around a bug in NVIDIA D3D driver version 388.59 where in very specific cases the driver
334     // would not handle constant register zero correctly. Only has an effect on HLSL translation.
335     uint64_t skipD3DConstantRegisterZero : 1;
336 
337     // Clamp gl_FragDepth to the range [0.0, 1.0] in case it is statically used.
338     uint64_t clampFragDepth : 1;
339 
340     // Rewrite expressions like "v.x = z = expression;". Works around a bug in NVIDIA OpenGL drivers
341     // prior to version 397.31.
342     uint64_t rewriteRepeatedAssignToSwizzled : 1;
343 
344     // Rewrite gl_DrawID as a uniform int
345     uint64_t emulateGLDrawID : 1;
346 
347     // This flag initializes shared variables to 0.  It is to avoid ompute shaders being able to
348     // read undefined values that could be coming from another webpage/application.
349     uint64_t initSharedVariables : 1;
350 
351     // Forces the value returned from an atomic operations to be always be resolved. This is
352     // targeted to workaround a bug in NVIDIA D3D driver where the return value from
353     // RWByteAddressBuffer.InterlockedAdd does not get resolved when used in the .yzw components of
354     // a RWByteAddressBuffer.Store operation. Only has an effect on HLSL translation.
355     // http://anglebug.com/42261924
356     uint64_t forceAtomicValueResolution : 1;
357 
358     // Rewrite gl_BaseVertex and gl_BaseInstance as uniform int
359     uint64_t emulateGLBaseVertexBaseInstance : 1;
360 
361     // Workaround for a driver bug with nested switches.
362     uint64_t wrapSwitchInIfTrue : 1;
363 
364     // This flag controls how to translate WEBGL_video_texture sampling function.
365     uint64_t takeVideoTextureAsExternalOES : 1;
366 
367     // This flag works around a inconsistent behavior in Mac AMD driver where gl_VertexID doesn't
368     // include base vertex value. It replaces gl_VertexID with (gl_VertexID + angle_BaseVertex) when
369     // angle_BaseVertex is available.
370     uint64_t addBaseVertexToVertexID : 1;
371 
372     // This works around the dynamic lvalue indexing of swizzled vectors on various platforms.
373     uint64_t removeDynamicIndexingOfSwizzledVector : 1;
374 
375     // This flag works around a slow fxc compile performance issue with dynamic uniform indexing.
376     uint64_t allowTranslateUniformBlockToStructuredBuffer : 1;
377 
378     // This flag allows us to add a decoration for layout(yuv) in shaders.
379     uint64_t addVulkanYUVLayoutQualifier : 1;
380 
381     // This flag allows disabling ARB_texture_rectangle on a per-compile basis. This is necessary
382     // for WebGL contexts becuase ARB_texture_rectangle may be necessary for the WebGL
383     // implementation internally but shouldn't be exposed to WebGL user code.
384     uint64_t disableARBTextureRectangle : 1;
385 
386     // This flag works around a driver bug by rewriting uses of row-major matrices as column-major
387     // in ESSL 3.00 and greater shaders.
388     uint64_t rewriteRowMajorMatrices : 1;
389 
390     // Drop any explicit precision qualifiers from shader.
391     uint64_t ignorePrecisionQualifiers : 1;
392 
393     // Ask compiler to generate code for depth correction to conform to the Vulkan clip space.  If
394     // VK_EXT_depth_clip_control is supported, this code is not generated, saving a uniform look up.
395     uint64_t addVulkanDepthCorrection : 1;
396 
397     uint64_t forceShaderPrecisionHighpToMediump : 1;
398 
399     // Allow compiler to use specialization constant to do pre-rotation and y flip.
400     uint64_t useSpecializationConstant : 1;
401 
402     // Ask compiler to generate Vulkan transform feedback emulation support code.
403     uint64_t addVulkanXfbEmulationSupportCode : 1;
404 
405     // Ask compiler to generate Vulkan transform feedback support code when using the
406     // VK_EXT_transform_feedback extension.
407     uint64_t addVulkanXfbExtensionSupportCode : 1;
408 
409     // This flag initializes fragment shader's output variables to zero at the beginning of the
410     // fragment shader's main(). It is intended as a workaround for drivers which get context lost
411     // if gl_FragColor is not written.
412     uint64_t initFragmentOutputVariables : 1;
413 
414     // Always write explicit location layout qualifiers for fragment outputs.
415     uint64_t explicitFragmentLocations : 1;
416 
417     // Insert explicit casts for float/double/unsigned/signed int on macOS 10.15 with Intel driver
418     uint64_t addExplicitBoolCasts : 1;
419 
420     // Add round() after applying dither.  This works around a Qualcomm quirk where values can get
421     // ceil()ed instead.
422     uint64_t roundOutputAfterDithering : 1;
423 
424     // issuetracker.google.com/274859104 add OpQuantizeToF16 instruction to cast
425     // mediump floating-point values to 16 bit. ARM compiler utilized RelaxedPrecision
426     // to minimize type case and keep a mediump float as 32 bit when assigning it with
427     // a highp floating-point value. It is possible that GLSL shader code is comparing
428     // two meiump values, but ARM compiler is comparing a 32 bit value with a 16 bit value,
429     // causing the comparison to fail.
430     uint64_t castMediumpFloatTo16Bit : 1;
431 
432     // anglebug.com/42265995: packUnorm4x8 fails on Pixel 4 if it is not passed a highp vec4.
433     // TODO(anglebug.com/42265995): This workaround is currently only applied for pixel local
434     // storage. We may want to apply it generally.
435     uint64_t passHighpToPackUnormSnormBuiltins : 1;
436 
437     // Use an integer uniform to pass a bitset of enabled clip distances.
438     uint64_t emulateClipDistanceState : 1;
439 
440     // Use a uniform to emulate GL_CLIP_ORIGIN_EXT state.
441     uint64_t emulateClipOrigin : 1;
442 
443     // issuetracker.google.com/266235549 add aliased memory decoration to ssbo if the variable is
444     // not declared with "restrict" memory qualifier in GLSL
445     uint64_t aliasedUnlessRestrict : 1;
446 
447     // Use fragment shaders to compute and set coverage mask based on the alpha value
448     uint64_t emulateAlphaToCoverage : 1;
449 
450     // Rescope globals that are only used in one function to be function-local.
451     uint64_t rescopeGlobalVariables : 1;
452 
453     // Pre-transform explicit cubemap derivatives for Apple GPUs.
454     uint64_t preTransformTextureCubeGradDerivatives : 1;
455 
456     // Workaround for a driver bug with the use of the OpSelect SPIR-V instruction.
457     uint64_t avoidOpSelectWithMismatchingRelaxedPrecision : 1;
458 
459     // Whether SPIR-V 1.4 can be emitted.  If not set, SPIR-V 1.3 is emitted.
460     uint64_t emitSPIRV14 : 1;
461 
462     // Reject shaders with obvious undefined behavior:
463     //
464     // - Shader contains easy-to-detect infinite loops
465     //
466     uint64_t rejectWebglShadersWithUndefinedBehavior : 1;
467 
468     // Emulate r32f image with an r32ui image
469     uint64_t emulateR32fImageAtomicExchange : 1;
470 
471     // Rewrite for and while loops to loop normal form.
472     uint64_t simplifyLoopConditions : 1;
473 
474     // Specify struct in one statement, declare instance in other.
475     uint64_t separateCompoundStructDeclarations : 1;
476 
477     ShCompileOptionsMetal metal;
478     ShPixelLocalStorageOptions pls;
479 };
480 
481 // The 64 bits hash function. The first parameter is the input string; the
482 // second parameter is the string length.
483 using ShHashFunction64 = khronos_uint64_t (*)(const char *, size_t);
484 
485 //
486 // Implementation dependent built-in resources (constants and extensions).
487 // The names for these resources has been obtained by stripping gl_/GL_.
488 //
489 struct ShBuiltInResources
490 {
491     ShBuiltInResources();
492     ShBuiltInResources(const ShBuiltInResources &other);
493     ShBuiltInResources &operator=(const ShBuiltInResources &other);
494 
495     // Constants.
496     int MaxVertexAttribs;
497     int MaxVertexUniformVectors;
498     int MaxVaryingVectors;
499     int MaxVertexTextureImageUnits;
500     int MaxCombinedTextureImageUnits;
501     int MaxTextureImageUnits;
502     int MaxFragmentUniformVectors;
503     int MaxDrawBuffers;
504 
505     // Extensions.
506     // Set to 1 to enable the extension, else 0.
507     int OES_standard_derivatives;
508     int OES_EGL_image_external;
509     int OES_EGL_image_external_essl3;
510     int NV_EGL_stream_consumer_external;
511     int ARB_texture_rectangle;
512     int EXT_blend_func_extended;
513     int EXT_conservative_depth;
514     int EXT_draw_buffers;
515     int EXT_frag_depth;
516     int EXT_shader_texture_lod;
517     int EXT_shader_framebuffer_fetch;
518     int EXT_shader_framebuffer_fetch_non_coherent;
519     int NV_shader_framebuffer_fetch;
520     int NV_shader_noperspective_interpolation;
521     int ARM_shader_framebuffer_fetch;
522     int ARM_shader_framebuffer_fetch_depth_stencil;
523     int OVR_multiview;
524     int OVR_multiview2;
525     int EXT_multisampled_render_to_texture;
526     int EXT_multisampled_render_to_texture2;
527     int EXT_YUV_target;
528     int EXT_geometry_shader;
529     int OES_geometry_shader;
530     int OES_shader_io_blocks;
531     int EXT_shader_io_blocks;
532     int EXT_gpu_shader5;
533     int OES_gpu_shader5;
534     int EXT_shader_non_constant_global_initializers;
535     int OES_texture_storage_multisample_2d_array;
536     int OES_texture_3D;
537     int ANGLE_shader_pixel_local_storage;
538     int ANGLE_texture_multisample;
539     int ANGLE_multi_draw;
540     // TODO(angleproject:3402) remove after chromium side removal to pass compilation
541     int ANGLE_base_vertex_base_instance;
542     int WEBGL_video_texture;
543     int APPLE_clip_distance;
544     int OES_texture_cube_map_array;
545     int EXT_texture_cube_map_array;
546     int EXT_texture_query_lod;
547     int EXT_texture_shadow_lod;
548     int EXT_shadow_samplers;
549     int OES_shader_multisample_interpolation;
550     int OES_shader_image_atomic;
551     int EXT_tessellation_shader;
552     int OES_tessellation_shader;
553     int OES_texture_buffer;
554     int EXT_texture_buffer;
555     int OES_sample_variables;
556     int EXT_clip_cull_distance;
557     int ANGLE_clip_cull_distance;
558     int EXT_primitive_bounding_box;
559     int OES_primitive_bounding_box;
560     int EXT_separate_shader_objects;
561     int ANGLE_base_vertex_base_instance_shader_builtin;
562     int ANDROID_extension_pack_es31a;
563     int KHR_blend_equation_advanced;
564 
565     // Set to 1 to enable replacing GL_EXT_draw_buffers #extension directives
566     // with GL_NV_draw_buffers in ESSL output. This flag can be used to emulate
567     // EXT_draw_buffers by using it in combination with GLES3.0 glDrawBuffers
568     // function. This applies to Tegra K1 devices.
569     int NV_draw_buffers;
570 
571     // Set to 1 if highp precision is supported in the ESSL 1.00 version of the
572     // fragment language. Does not affect versions of the language where highp
573     // support is mandatory.
574     // Default is 0.
575     int FragmentPrecisionHigh;
576 
577     // GLSL ES 3.0 constants.
578     int MaxVertexOutputVectors;
579     int MaxFragmentInputVectors;
580     int MinProgramTexelOffset;
581     int MaxProgramTexelOffset;
582 
583     // Extension constants.
584 
585     // Value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT for OpenGL ES output context.
586     // Value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS for OpenGL output context.
587     // GLES SL version 100 gl_MaxDualSourceDrawBuffersEXT value for EXT_blend_func_extended.
588     int MaxDualSourceDrawBuffers;
589 
590     // Value of GL_MAX_VIEWS_OVR.
591     int MaxViewsOVR;
592 
593     // Name Hashing.
594     // Set a 64 bit hash function to enable user-defined name hashing.
595     // Default is NULL.
596     ShHashFunction64 HashFunction;
597 
598     // The maximum complexity an expression can be when limitExpressionComplexity is turned on.
599     int MaxExpressionComplexity;
600 
601     // The maximum depth of certain nestable statements (while, switch);
602     int MaxStatementDepth;
603 
604     // The maximum depth a call stack can be.
605     int MaxCallStackDepth;
606 
607     // The maximum number of parameters a function can have when limitExpressionComplexity is turned
608     // on.
609     int MaxFunctionParameters;
610 
611     // GLES 3.1 constants
612 
613     // texture gather offset constraints.
614     int MinProgramTextureGatherOffset;
615     int MaxProgramTextureGatherOffset;
616 
617     // maximum number of available image units
618     int MaxImageUnits;
619 
620     // OES_sample_variables constant
621     // maximum number of available samples
622     int MaxSamples;
623 
624     // maximum number of image uniforms in a vertex shader
625     int MaxVertexImageUniforms;
626 
627     // maximum number of image uniforms in a fragment shader
628     int MaxFragmentImageUniforms;
629 
630     // maximum number of image uniforms in a compute shader
631     int MaxComputeImageUniforms;
632 
633     // maximum total number of image uniforms in a program
634     int MaxCombinedImageUniforms;
635 
636     // maximum number of uniform locations
637     int MaxUniformLocations;
638 
639     // maximum number of ssbos and images in a shader
640     int MaxCombinedShaderOutputResources;
641 
642     // maximum number of groups in each dimension
643     std::array<int, 3> MaxComputeWorkGroupCount;
644     // maximum number of threads per work group in each dimension
645     std::array<int, 3> MaxComputeWorkGroupSize;
646 
647     // maximum number of total uniform components
648     int MaxComputeUniformComponents;
649 
650     // maximum number of texture image units in a compute shader
651     int MaxComputeTextureImageUnits;
652 
653     // maximum number of atomic counters in a compute shader
654     int MaxComputeAtomicCounters;
655 
656     // maximum number of atomic counter buffers in a compute shader
657     int MaxComputeAtomicCounterBuffers;
658 
659     // maximum number of atomic counters in a vertex shader
660     int MaxVertexAtomicCounters;
661 
662     // maximum number of atomic counters in a fragment shader
663     int MaxFragmentAtomicCounters;
664 
665     // maximum number of atomic counters in a program
666     int MaxCombinedAtomicCounters;
667 
668     // maximum binding for an atomic counter
669     int MaxAtomicCounterBindings;
670 
671     // maximum number of atomic counter buffers in a vertex shader
672     int MaxVertexAtomicCounterBuffers;
673 
674     // maximum number of atomic counter buffers in a fragment shader
675     int MaxFragmentAtomicCounterBuffers;
676 
677     // maximum number of atomic counter buffers in a program
678     int MaxCombinedAtomicCounterBuffers;
679 
680     // maximum number of buffer object storage in machine units
681     int MaxAtomicCounterBufferSize;
682 
683     // maximum number of uniform block bindings
684     int MaxUniformBufferBindings;
685 
686     // maximum number of shader storage buffer bindings
687     int MaxShaderStorageBufferBindings;
688 
689     // minimum point size (lower limit from ALIASED_POINT_SIZE_RANGE)
690     float MinPointSize;
691 
692     // maximum point size (higher limit from ALIASED_POINT_SIZE_RANGE)
693     float MaxPointSize;
694 
695     // EXT_geometry_shader constants
696     int MaxGeometryUniformComponents;
697     int MaxGeometryUniformBlocks;
698     int MaxGeometryInputComponents;
699     int MaxGeometryOutputComponents;
700     int MaxGeometryOutputVertices;
701     int MaxGeometryTotalOutputComponents;
702     int MaxGeometryTextureImageUnits;
703     int MaxGeometryAtomicCounterBuffers;
704     int MaxGeometryAtomicCounters;
705     int MaxGeometryShaderStorageBlocks;
706     int MaxGeometryShaderInvocations;
707     int MaxGeometryImageUniforms;
708 
709     // EXT_tessellation_shader constants
710     int MaxTessControlInputComponents;
711     int MaxTessControlOutputComponents;
712     int MaxTessControlTextureImageUnits;
713     int MaxTessControlUniformComponents;
714     int MaxTessControlTotalOutputComponents;
715     int MaxTessControlImageUniforms;
716     int MaxTessControlAtomicCounters;
717     int MaxTessControlAtomicCounterBuffers;
718 
719     int MaxTessPatchComponents;
720     int MaxPatchVertices;
721     int MaxTessGenLevel;
722 
723     int MaxTessEvaluationInputComponents;
724     int MaxTessEvaluationOutputComponents;
725     int MaxTessEvaluationTextureImageUnits;
726     int MaxTessEvaluationUniformComponents;
727     int MaxTessEvaluationImageUniforms;
728     int MaxTessEvaluationAtomicCounters;
729     int MaxTessEvaluationAtomicCounterBuffers;
730 
731     // Subpixel bits used in rasterization.
732     int SubPixelBits;
733 
734     // APPLE_clip_distance / EXT_clip_cull_distance / ANGLE_clip_cull_distance constants
735     int MaxClipDistances;
736     int MaxCullDistances;
737     int MaxCombinedClipAndCullDistances;
738 
739     // ANGLE_shader_pixel_local_storage.
740     int MaxPixelLocalStoragePlanes;
741     int MaxColorAttachmentsWithActivePixelLocalStorage;
742     int MaxCombinedDrawBuffersAndPixelLocalStoragePlanes;
743 };
744 
745 //
746 // ShHandle held by but opaque to the driver.  It is allocated,
747 // managed, and de-allocated by the compiler. Its contents
748 // are defined by and used by the compiler.
749 //
750 // If handle creation fails, 0 will be returned.
751 //
752 using ShHandle = void *;
753 
754 namespace sh
755 {
756 using BinaryBlob       = std::vector<uint32_t>;
757 using ShaderBinaryBlob = std::vector<uint8_t>;
758 
759 //
760 // Driver must call this first, once, before doing any other compiler operations.
761 // If the function succeeds, the return value is true, else false.
762 //
763 bool Initialize();
764 //
765 // Driver should call this at shutdown.
766 // If the function succeeds, the return value is true, else false.
767 //
768 bool Finalize();
769 
770 //
771 // Initialize built-in resources with minimum expected values.
772 // Parameters:
773 // resources: The object to initialize. Will be comparable with memcmp.
774 //
775 void InitBuiltInResources(ShBuiltInResources *resources);
776 
777 //
778 // Returns a copy of the current ShBuiltInResources stored in the compiler.
779 // Parameters:
780 // handle: Specifies the handle of the compiler to be used.
781 ShBuiltInResources GetBuiltInResources(const ShHandle handle);
782 
783 //
784 // Returns the a concatenated list of the items in ShBuiltInResources as a null-terminated string.
785 // This function must be updated whenever ShBuiltInResources is changed.
786 // Parameters:
787 // handle: Specifies the handle of the compiler to be used.
788 const std::string &GetBuiltInResourcesString(const ShHandle handle);
789 
790 //
791 // Driver calls these to create and destroy compiler objects.
792 //
793 // Returns the handle of constructed compiler, null if the requested compiler is not supported.
794 // Parameters:
795 // type: Specifies the type of shader - GL_FRAGMENT_SHADER or GL_VERTEX_SHADER.
796 // spec: Specifies the language spec the compiler must conform to - SH_GLES2_SPEC or SH_WEBGL_SPEC.
797 // output: Specifies the output code type - for example SH_ESSL_OUTPUT, SH_GLSL_OUTPUT,
798 //         SH_HLSL_3_0_OUTPUT or SH_HLSL_4_1_OUTPUT. Note: Each output type may only
799 //         be supported in some configurations.
800 // resources: Specifies the built-in resources.
801 ShHandle ConstructCompiler(sh::GLenum type,
802                            ShShaderSpec spec,
803                            ShShaderOutput output,
804                            const ShBuiltInResources *resources);
805 void Destruct(ShHandle handle);
806 
807 //
808 // Compiles the given shader source.
809 // If the function succeeds, the return value is true, else false.
810 // Parameters:
811 // handle: Specifies the handle of compiler to be used.
812 // shaderStrings: Specifies an array of pointers to null-terminated strings containing the shader
813 // source code.
814 // numStrings: Specifies the number of elements in shaderStrings array.
815 // compileOptions: A mask of compile options defined above.
816 bool Compile(const ShHandle handle,
817              const char *const shaderStrings[],
818              size_t numStrings,
819              const ShCompileOptions &compileOptions);
820 
821 // Clears the results from the previous compilation.
822 void ClearResults(const ShHandle handle);
823 
824 // Return the version of the shader language.
825 int GetShaderVersion(const ShHandle handle);
826 
827 // Return the currently set language output type.
828 ShShaderOutput GetShaderOutputType(const ShHandle handle);
829 
830 // Returns null-terminated information log for a compiled shader.
831 // Parameters:
832 // handle: Specifies the compiler
833 const std::string &GetInfoLog(const ShHandle handle);
834 
835 // Returns null-terminated object code for a compiled shader.  Only valid for output types that
836 // generate human-readable code (GLSL, ESSL or HLSL).
837 // Parameters:
838 // handle: Specifies the compiler
839 const std::string &GetObjectCode(const ShHandle handle);
840 
841 // Returns object binary blob for a compiled shader.  Only valid for output types that
842 // generate binary blob (SPIR-V).
843 // Parameters:
844 // handle: Specifies the compiler
845 const BinaryBlob &GetObjectBinaryBlob(const ShHandle handle);
846 
847 // Returns a full binary for a compiled shader, to be loaded with glShaderBinary during runtime.
848 // Parameters:
849 // handle: Specifies the compiler
850 bool GetShaderBinary(const ShHandle handle,
851                      const char *const shaderStrings[],
852                      size_t numStrings,
853                      const ShCompileOptions &compileOptions,
854                      ShaderBinaryBlob *const binaryOut);
855 
856 // Returns a (original_name, hash) map containing all the user defined names in the shader,
857 // including variable names, function names, struct names, and struct field names.
858 // Parameters:
859 // handle: Specifies the compiler
860 const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle);
861 
862 // Shader variable inspection.
863 // Returns a pointer to a list of variables of the designated type.
864 // (See ShaderVars.h for type definitions, included above)
865 // Returns NULL on failure.
866 // Parameters:
867 // handle: Specifies the compiler
868 const std::vector<sh::ShaderVariable> *GetUniforms(const ShHandle handle);
869 const std::vector<sh::ShaderVariable> *GetVaryings(const ShHandle handle);
870 const std::vector<sh::ShaderVariable> *GetInputVaryings(const ShHandle handle);
871 const std::vector<sh::ShaderVariable> *GetOutputVaryings(const ShHandle handle);
872 const std::vector<sh::ShaderVariable> *GetAttributes(const ShHandle handle);
873 const std::vector<sh::ShaderVariable> *GetOutputVariables(const ShHandle handle);
874 const std::vector<sh::InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle);
875 const std::vector<sh::InterfaceBlock> *GetUniformBlocks(const ShHandle handle);
876 const std::vector<sh::InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle);
877 sh::WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle);
878 // Returns the number of views specified through the num_views layout qualifier. If num_views is
879 // not set, the function returns -1.
880 int GetVertexShaderNumViews(const ShHandle handle);
881 // Returns the pixel local storage uniform format at each binding index, or "NotPLS" if there is
882 // not one.
883 const std::vector<ShPixelLocalStorageFormat> *GetPixelLocalStorageFormats(const ShHandle handle);
884 
885 // Returns specialization constant usage bits
886 uint32_t GetShaderSpecConstUsageBits(const ShHandle handle);
887 
888 // Returns true if the passed in variables pack in maxVectors followingthe packing rules from the
889 // GLSL 1.017 spec, Appendix A, section 7.
890 // Returns false otherwise. Also look at the enforcePackingRestrictions flag above.
891 // Parameters:
892 // maxVectors: the available rows of registers.
893 // variables: an array of variables.
894 bool CheckVariablesWithinPackingLimits(int maxVectors,
895                                        const std::vector<sh::ShaderVariable> &variables);
896 
897 // Gives the compiler-assigned register for a shader storage block.
898 // The method writes the value to the output variable "indexOut".
899 // Returns true if it found a valid shader storage block, false otherwise.
900 // Parameters:
901 // handle: Specifies the compiler
902 // shaderStorageBlockName: Specifies the shader storage block
903 // indexOut: output variable that stores the assigned register
904 bool GetShaderStorageBlockRegister(const ShHandle handle,
905                                    const std::string &shaderStorageBlockName,
906                                    unsigned int *indexOut);
907 
908 // Gives the compiler-assigned register for a uniform block.
909 // The method writes the value to the output variable "indexOut".
910 // Returns true if it found a valid uniform block, false otherwise.
911 // Parameters:
912 // handle: Specifies the compiler
913 // uniformBlockName: Specifies the uniform block
914 // indexOut: output variable that stores the assigned register
915 bool GetUniformBlockRegister(const ShHandle handle,
916                              const std::string &uniformBlockName,
917                              unsigned int *indexOut);
918 
919 bool ShouldUniformBlockUseStructuredBuffer(const ShHandle handle,
920                                            const std::string &uniformBlockName);
921 const std::set<std::string> *GetSlowCompilingUniformBlockSet(const ShHandle handle);
922 
923 // Gives a map from uniform names to compiler-assigned registers in the default uniform block.
924 // Note that the map contains also registers of samplers that have been extracted from structs.
925 const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle);
926 
927 // Sampler, image and atomic counters share registers(t type and u type),
928 // GetReadonlyImage2DRegisterIndex and GetImage2DRegisterIndex return the first index into
929 // a range of reserved registers for image2D/iimage2D/uimage2D variables.
930 // Parameters: handle: Specifies the compiler
931 unsigned int GetReadonlyImage2DRegisterIndex(const ShHandle handle);
932 unsigned int GetImage2DRegisterIndex(const ShHandle handle);
933 
934 // The method records these used function names related with image2D/iimage2D/uimage2D, these
935 // functions will be dynamically generated.
936 // Parameters:
937 // handle: Specifies the compiler
938 const std::set<std::string> *GetUsedImage2DFunctionNames(const ShHandle handle);
939 
940 uint8_t GetClipDistanceArraySize(const ShHandle handle);
941 uint8_t GetCullDistanceArraySize(const ShHandle handle);
942 GLenum GetGeometryShaderInputPrimitiveType(const ShHandle handle);
943 GLenum GetGeometryShaderOutputPrimitiveType(const ShHandle handle);
944 int GetGeometryShaderInvocations(const ShHandle handle);
945 int GetGeometryShaderMaxVertices(const ShHandle handle);
946 unsigned int GetShaderSharedMemorySize(const ShHandle handle);
947 int GetTessControlShaderVertices(const ShHandle handle);
948 GLenum GetTessGenMode(const ShHandle handle);
949 GLenum GetTessGenSpacing(const ShHandle handle);
950 GLenum GetTessGenVertexOrder(const ShHandle handle);
951 GLenum GetTessGenPointMode(const ShHandle handle);
952 
953 // Returns a bitset of sh::MetadataFlags.  This bundles various bits purely for convenience.
954 uint32_t GetMetadataFlags(const ShHandle handle);
955 
956 // Returns the blend equation list supported in the fragment shader.  This is a bitset of
957 // gl::BlendEquationType, and can only include bits from KHR_blend_equation_advanced.
958 uint32_t GetAdvancedBlendEquations(const ShHandle handle);
959 
960 //
961 // Helper function to identify specs that are based on the WebGL spec.
962 //
IsWebGLBasedSpec(ShShaderSpec spec)963 inline bool IsWebGLBasedSpec(ShShaderSpec spec)
964 {
965     return (spec == SH_WEBGL_SPEC || spec == SH_WEBGL2_SPEC || spec == SH_WEBGL3_SPEC);
966 }
967 
968 // Can't prefix with just _ because then we might introduce a double underscore, which is not safe
969 // in GLSL (ESSL 3.00.6 section 3.8: All identifiers containing a double underscore are reserved for
970 // use by the underlying implementation). u is short for user-defined.
971 extern const char kUserDefinedNamePrefix[];
972 
973 enum class MetadataFlags
974 {
975     // Applicable to vertex shaders (technically all pre-rasterization shaders could use this flag,
976     // but the current and only user is GL, which does not support geometry/tessellation).
977     HasClipDistance,
978     // Applicable to fragment shaders
979     HasDiscard,
980     EnablesPerSampleShading,
981     HasInputAttachment0,
982     // Flag for attachment i is HasInputAttachment0 + i
983     HasInputAttachment7 = HasInputAttachment0 + 7,
984     HasDepthInputAttachment,
985     HasStencilInputAttachment,
986     // Applicable to geometry shaders
987     HasValidGeometryShaderInputPrimitiveType,
988     HasValidGeometryShaderOutputPrimitiveType,
989     HasValidGeometryShaderMaxVertices,
990     // Applicable to tessellation shaders
991     HasValidTessGenMode,
992     HasValidTessGenSpacing,
993     HasValidTessGenVertexOrder,
994     HasValidTessGenPointMode,
995 
996     InvalidEnum,
997     EnumCount = InvalidEnum,
998 };
999 
1000 namespace vk
1001 {
1002 
1003 // Specialization constant ids
1004 enum class SpecializationConstantId : uint32_t
1005 {
1006     SurfaceRotation = 0,
1007     Dither          = 1,
1008 
1009     InvalidEnum = 2,
1010     EnumCount   = InvalidEnum,
1011 };
1012 
1013 enum class SpecConstUsage : uint32_t
1014 {
1015     Rotation = 0,
1016     Dither   = 1,
1017 
1018     InvalidEnum = 2,
1019     EnumCount   = InvalidEnum,
1020 };
1021 
1022 enum ColorAttachmentDitherControl
1023 {
1024     // See comments in ContextVk::updateDither and EmulateDithering.cpp
1025     kDitherControlNoDither   = 0,
1026     kDitherControlDither4444 = 1,
1027     kDitherControlDither5551 = 2,
1028     kDitherControlDither565  = 3,
1029 };
1030 
1031 namespace spirv
1032 {
1033 enum NonSemanticInstruction
1034 {
1035     // The overview instruction containing information such as what predefined ids are present in
1036     // the SPIR-V.  Simultaneously, this instruction identifies the location where the
1037     // types/constants/variables section ends and the functions section starts.
1038     kNonSemanticOverview,
1039     // The instruction identifying the entry to the shader, i.e. at the start of main()
1040     kNonSemanticEnter,
1041     // The instruction identifying where vertex or fragment data is output.
1042     // This is before return from main() in vertex, tessellation, and fragment shaders,
1043     // and before OpEmitVertex in geometry shaders.
1044     kNonSemanticOutput,
1045     // The instruction identifying the location where transform feedback emulation should be
1046     // written.
1047     kNonSemanticTransformFeedbackEmulation,
1048 };
1049 
1050 // The non-semantic instruction id has many bits available.  With kNonSemanticOverview, they are
1051 // used to provide additional overview details.  Providing this information in the instruction's
1052 // payload require OpConstants and recovering those, which is unnecessary complexity.
1053 constexpr uint32_t kNonSemanticInstructionBits       = 4;
1054 constexpr uint32_t kNonSemanticInstructionMask       = 0xF;
1055 constexpr uint32_t kOverviewHasSampleRateShadingMask = 0x10;
1056 constexpr uint32_t kOverviewHasSampleIDMask          = 0x20;
1057 constexpr uint32_t kOverviewHasOutputPerVertexMask   = 0x40;
1058 
1059 enum ReservedIds
1060 {
1061     kIdInvalid = 0,
1062 
1063     // =============================================================================================
1064     // Ids that are fixed and are always present in the SPIR-V where applicable.  The SPIR-V
1065     // transformer can thus reliably use these ids.
1066 
1067     // Global information
1068     kIdNonSemanticInstructionSet,
1069     kIdEntryPoint,
1070 
1071     // Basic types
1072     kIdVoid,
1073     kIdFloat,
1074     kIdVec2,
1075     kIdVec3,
1076     kIdVec4,
1077     kIdMat2,
1078     kIdMat3,
1079     kIdMat4,
1080     kIdInt,
1081     kIdIVec4,
1082     kIdUint,
1083 
1084     // Common constants
1085     kIdIntZero,
1086     kIdIntOne,
1087     kIdIntTwo,
1088     kIdIntThree,
1089 
1090     // Type pointers
1091     kIdIntInputTypePointer,
1092     kIdVec4OutputTypePointer,
1093     kIdIVec4FunctionTypePointer,
1094     kIdOutputPerVertexTypePointer,
1095 
1096     // Pre-rotation and Z-correction support
1097     kIdTransformPositionFunction,
1098     kIdInputPerVertexBlockArray,
1099     kIdOutputPerVertexBlockArray,
1100     kIdOutputPerVertexVar,
1101 
1102     // Transform feedback support
1103     kIdXfbEmulationGetOffsetsFunction,
1104     kIdXfbEmulationCaptureFunction,
1105     kIdXfbEmulationBufferVarZero,
1106     kIdXfbEmulationBufferVarOne,
1107     kIdXfbEmulationBufferVarTwo,
1108     kIdXfbEmulationBufferVarThree,
1109 
1110     // Multisampling support
1111     kIdSampleID,
1112 
1113     // =============================================================================================
1114     // ANGLE internal shader variables, which are not produced as ShaderVariables.
1115     // kIdShaderVariablesBegin marks the beginning of these ids.  variableId -> info maps in the
1116     // backend can use |variableId - kIdShaderVariablesBegin| as key into a flat array.
1117     //
1118     // Note that for blocks, only the block id is in this section as that is the id used in the
1119     // variableId -> info maps.
1120     kIdShaderVariablesBegin,
1121 
1122     // gl_PerVertex
1123     kIdInputPerVertexBlock = kIdShaderVariablesBegin,
1124     kIdOutputPerVertexBlock,
1125     // The driver and default uniform blocks
1126     kIdDriverUniformsBlock,
1127     kIdDefaultUniformsBlock,
1128     // The atomic counter block
1129     kIdAtomicCounterBlock,
1130     // Buffer block used for transform feedback emulation
1131     kIdXfbEmulationBufferBlockZero,
1132     kIdXfbEmulationBufferBlockOne,
1133     kIdXfbEmulationBufferBlockTwo,
1134     kIdXfbEmulationBufferBlockThree,
1135     // Additional varying added to hold untransformed gl_Position for transform feedback capture
1136     kIdXfbExtensionPosition,
1137     // Input attachments used for framebuffer fetch and advanced blend emulation
1138     kIdInputAttachment0,
1139     kIdInputAttachment7 = kIdInputAttachment0 + 7,
1140     kIdDepthInputAttachment,
1141     kIdStencilInputAttachment,
1142 
1143     kIdFirstUnreserved,
1144 };
1145 }  // namespace spirv
1146 
1147 // Packing information for driver uniform's misc field:
1148 // - 1 bit for whether surface rotation results in swapped axes
1149 // - 5 bits for advanced blend equation
1150 // - 6 bits for sample count
1151 // - 8 bits for enabled clip planes
1152 // - 1 bit for whether depth should be transformed to Vulkan clip space
1153 // - 1 bit for whether alpha to coverage is enabled
1154 // - 1 bit for whether the framebuffer is layered
1155 // - 9 bits unused
1156 constexpr uint32_t kDriverUniformsMiscSwapXYMask                  = 0x1;
1157 constexpr uint32_t kDriverUniformsMiscAdvancedBlendEquationOffset = 1;
1158 constexpr uint32_t kDriverUniformsMiscAdvancedBlendEquationMask   = 0x1F;
1159 constexpr uint32_t kDriverUniformsMiscSampleCountOffset           = 6;
1160 constexpr uint32_t kDriverUniformsMiscSampleCountMask             = 0x3F;
1161 constexpr uint32_t kDriverUniformsMiscEnabledClipPlanesOffset     = 12;
1162 constexpr uint32_t kDriverUniformsMiscEnabledClipPlanesMask       = 0xFF;
1163 constexpr uint32_t kDriverUniformsMiscTransformDepthOffset        = 20;
1164 constexpr uint32_t kDriverUniformsMiscTransformDepthMask          = 0x1;
1165 constexpr uint32_t kDriverUniformsMiscAlphaToCoverageOffset       = 21;
1166 constexpr uint32_t kDriverUniformsMiscAlphaToCoverageMask         = 0x1;
1167 constexpr uint32_t kDriverUniformsMiscLayeredFramebufferOffset    = 22;
1168 constexpr uint32_t kDriverUniformsMiscLayeredFramebufferMask      = 0x1;
1169 }  // namespace vk
1170 
1171 namespace mtl
1172 {
1173 // Specialization constant to enable multisampled rendering behavior.
1174 extern const char kMultisampledRenderingConstName[];
1175 
1176 // Specialization constant to emulate rasterizer discard.
1177 extern const char kRasterizerDiscardEnabledConstName[];
1178 
1179 // Specialization constant to enable depth write in fragment shaders.
1180 extern const char kDepthWriteEnabledConstName[];
1181 
1182 // Specialization constant to enable alpha to coverage.
1183 extern const char kEmulateAlphaToCoverageConstName[];
1184 
1185 // Specialization constant to write helper sample mask output.
1186 extern const char kWriteHelperSampleMaskConstName[];
1187 
1188 // Specialization constant to enable sample mask output.
1189 extern const char kSampleMaskWriteEnabledConstName[];
1190 }  // namespace mtl
1191 
1192 }  // namespace sh
1193 
1194 #endif  // GLSLANG_SHADERLANG_H_
1195