• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 372
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 MaxCombinedDrawBuffersAndPixelLocalStoragePlanes;
742 };
743 
744 //
745 // ShHandle held by but opaque to the driver.  It is allocated,
746 // managed, and de-allocated by the compiler. Its contents
747 // are defined by and used by the compiler.
748 //
749 // If handle creation fails, 0 will be returned.
750 //
751 using ShHandle = void *;
752 
753 namespace sh
754 {
755 using BinaryBlob       = std::vector<uint32_t>;
756 using ShaderBinaryBlob = std::vector<uint8_t>;
757 
758 //
759 // Driver must call this first, once, before doing any other compiler operations.
760 // If the function succeeds, the return value is true, else false.
761 //
762 bool Initialize();
763 //
764 // Driver should call this at shutdown.
765 // If the function succeeds, the return value is true, else false.
766 //
767 bool Finalize();
768 
769 //
770 // Initialize built-in resources with minimum expected values.
771 // Parameters:
772 // resources: The object to initialize. Will be comparable with memcmp.
773 //
774 void InitBuiltInResources(ShBuiltInResources *resources);
775 
776 //
777 // Returns a copy of the current ShBuiltInResources stored in the compiler.
778 // Parameters:
779 // handle: Specifies the handle of the compiler to be used.
780 ShBuiltInResources GetBuiltInResources(const ShHandle handle);
781 
782 //
783 // Returns the a concatenated list of the items in ShBuiltInResources as a null-terminated string.
784 // This function must be updated whenever ShBuiltInResources is changed.
785 // Parameters:
786 // handle: Specifies the handle of the compiler to be used.
787 const std::string &GetBuiltInResourcesString(const ShHandle handle);
788 
789 //
790 // Driver calls these to create and destroy compiler objects.
791 //
792 // Returns the handle of constructed compiler, null if the requested compiler is not supported.
793 // Parameters:
794 // type: Specifies the type of shader - GL_FRAGMENT_SHADER or GL_VERTEX_SHADER.
795 // spec: Specifies the language spec the compiler must conform to - SH_GLES2_SPEC or SH_WEBGL_SPEC.
796 // output: Specifies the output code type - for example SH_ESSL_OUTPUT, SH_GLSL_OUTPUT,
797 //         SH_HLSL_3_0_OUTPUT or SH_HLSL_4_1_OUTPUT. Note: Each output type may only
798 //         be supported in some configurations.
799 // resources: Specifies the built-in resources.
800 ShHandle ConstructCompiler(sh::GLenum type,
801                            ShShaderSpec spec,
802                            ShShaderOutput output,
803                            const ShBuiltInResources *resources);
804 void Destruct(ShHandle handle);
805 
806 //
807 // Compiles the given shader source.
808 // If the function succeeds, the return value is true, else false.
809 // Parameters:
810 // handle: Specifies the handle of compiler to be used.
811 // shaderStrings: Specifies an array of pointers to null-terminated strings containing the shader
812 // source code.
813 // numStrings: Specifies the number of elements in shaderStrings array.
814 // compileOptions: A mask of compile options defined above.
815 bool Compile(const ShHandle handle,
816              const char *const shaderStrings[],
817              size_t numStrings,
818              const ShCompileOptions &compileOptions);
819 
820 // Clears the results from the previous compilation.
821 void ClearResults(const ShHandle handle);
822 
823 // Return the version of the shader language.
824 int GetShaderVersion(const ShHandle handle);
825 
826 // Return the currently set language output type.
827 ShShaderOutput GetShaderOutputType(const ShHandle handle);
828 
829 // Returns null-terminated information log for a compiled shader.
830 // Parameters:
831 // handle: Specifies the compiler
832 const std::string &GetInfoLog(const ShHandle handle);
833 
834 // Returns null-terminated object code for a compiled shader.  Only valid for output types that
835 // generate human-readable code (GLSL, ESSL or HLSL).
836 // Parameters:
837 // handle: Specifies the compiler
838 const std::string &GetObjectCode(const ShHandle handle);
839 
840 // Returns object binary blob for a compiled shader.  Only valid for output types that
841 // generate binary blob (SPIR-V).
842 // Parameters:
843 // handle: Specifies the compiler
844 const BinaryBlob &GetObjectBinaryBlob(const ShHandle handle);
845 
846 // Returns a full binary for a compiled shader, to be loaded with glShaderBinary during runtime.
847 // Parameters:
848 // handle: Specifies the compiler
849 bool GetShaderBinary(const ShHandle handle,
850                      const char *const shaderStrings[],
851                      size_t numStrings,
852                      const ShCompileOptions &compileOptions,
853                      ShaderBinaryBlob *const binaryOut);
854 
855 // Returns a (original_name, hash) map containing all the user defined names in the shader,
856 // including variable names, function names, struct names, and struct field names.
857 // Parameters:
858 // handle: Specifies the compiler
859 const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle);
860 
861 // Shader variable inspection.
862 // Returns a pointer to a list of variables of the designated type.
863 // (See ShaderVars.h for type definitions, included above)
864 // Returns NULL on failure.
865 // Parameters:
866 // handle: Specifies the compiler
867 const std::vector<sh::ShaderVariable> *GetUniforms(const ShHandle handle);
868 const std::vector<sh::ShaderVariable> *GetVaryings(const ShHandle handle);
869 const std::vector<sh::ShaderVariable> *GetInputVaryings(const ShHandle handle);
870 const std::vector<sh::ShaderVariable> *GetOutputVaryings(const ShHandle handle);
871 const std::vector<sh::ShaderVariable> *GetAttributes(const ShHandle handle);
872 const std::vector<sh::ShaderVariable> *GetOutputVariables(const ShHandle handle);
873 const std::vector<sh::InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle);
874 const std::vector<sh::InterfaceBlock> *GetUniformBlocks(const ShHandle handle);
875 const std::vector<sh::InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle);
876 sh::WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle);
877 // Returns the number of views specified through the num_views layout qualifier. If num_views is
878 // not set, the function returns -1.
879 int GetVertexShaderNumViews(const ShHandle handle);
880 // Returns the pixel local storage uniform format at each binding index, or "NotPLS" if there is
881 // not one.
882 const std::vector<ShPixelLocalStorageFormat> *GetPixelLocalStorageFormats(const ShHandle handle);
883 
884 // Returns specialization constant usage bits
885 uint32_t GetShaderSpecConstUsageBits(const ShHandle handle);
886 
887 // Returns true if the passed in variables pack in maxVectors followingthe packing rules from the
888 // GLSL 1.017 spec, Appendix A, section 7.
889 // Returns false otherwise. Also look at the enforcePackingRestrictions flag above.
890 // Parameters:
891 // maxVectors: the available rows of registers.
892 // variables: an array of variables.
893 bool CheckVariablesWithinPackingLimits(int maxVectors,
894                                        const std::vector<sh::ShaderVariable> &variables);
895 
896 // Gives the compiler-assigned register for a shader storage block.
897 // The method writes the value to the output variable "indexOut".
898 // Returns true if it found a valid shader storage block, false otherwise.
899 // Parameters:
900 // handle: Specifies the compiler
901 // shaderStorageBlockName: Specifies the shader storage block
902 // indexOut: output variable that stores the assigned register
903 bool GetShaderStorageBlockRegister(const ShHandle handle,
904                                    const std::string &shaderStorageBlockName,
905                                    unsigned int *indexOut);
906 
907 // Gives the compiler-assigned register for a uniform block.
908 // The method writes the value to the output variable "indexOut".
909 // Returns true if it found a valid uniform block, false otherwise.
910 // Parameters:
911 // handle: Specifies the compiler
912 // uniformBlockName: Specifies the uniform block
913 // indexOut: output variable that stores the assigned register
914 bool GetUniformBlockRegister(const ShHandle handle,
915                              const std::string &uniformBlockName,
916                              unsigned int *indexOut);
917 
918 bool ShouldUniformBlockUseStructuredBuffer(const ShHandle handle,
919                                            const std::string &uniformBlockName);
920 const std::set<std::string> *GetSlowCompilingUniformBlockSet(const ShHandle handle);
921 
922 // Gives a map from uniform names to compiler-assigned registers in the default uniform block.
923 // Note that the map contains also registers of samplers that have been extracted from structs.
924 const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle);
925 
926 // Sampler, image and atomic counters share registers(t type and u type),
927 // GetReadonlyImage2DRegisterIndex and GetImage2DRegisterIndex return the first index into
928 // a range of reserved registers for image2D/iimage2D/uimage2D variables.
929 // Parameters: handle: Specifies the compiler
930 unsigned int GetReadonlyImage2DRegisterIndex(const ShHandle handle);
931 unsigned int GetImage2DRegisterIndex(const ShHandle handle);
932 
933 // The method records these used function names related with image2D/iimage2D/uimage2D, these
934 // functions will be dynamically generated.
935 // Parameters:
936 // handle: Specifies the compiler
937 const std::set<std::string> *GetUsedImage2DFunctionNames(const ShHandle handle);
938 
939 uint8_t GetClipDistanceArraySize(const ShHandle handle);
940 uint8_t GetCullDistanceArraySize(const ShHandle handle);
941 GLenum GetGeometryShaderInputPrimitiveType(const ShHandle handle);
942 GLenum GetGeometryShaderOutputPrimitiveType(const ShHandle handle);
943 int GetGeometryShaderInvocations(const ShHandle handle);
944 int GetGeometryShaderMaxVertices(const ShHandle handle);
945 unsigned int GetShaderSharedMemorySize(const ShHandle handle);
946 int GetTessControlShaderVertices(const ShHandle handle);
947 GLenum GetTessGenMode(const ShHandle handle);
948 GLenum GetTessGenSpacing(const ShHandle handle);
949 GLenum GetTessGenVertexOrder(const ShHandle handle);
950 GLenum GetTessGenPointMode(const ShHandle handle);
951 
952 // Returns a bitset of sh::MetadataFlags.  This bundles various bits purely for convenience.
953 uint32_t GetMetadataFlags(const ShHandle handle);
954 
955 // Returns the blend equation list supported in the fragment shader.  This is a bitset of
956 // gl::BlendEquationType, and can only include bits from KHR_blend_equation_advanced.
957 uint32_t GetAdvancedBlendEquations(const ShHandle handle);
958 
959 //
960 // Helper function to identify specs that are based on the WebGL spec.
961 //
IsWebGLBasedSpec(ShShaderSpec spec)962 inline bool IsWebGLBasedSpec(ShShaderSpec spec)
963 {
964     return (spec == SH_WEBGL_SPEC || spec == SH_WEBGL2_SPEC || spec == SH_WEBGL3_SPEC);
965 }
966 
967 // Can't prefix with just _ because then we might introduce a double underscore, which is not safe
968 // in GLSL (ESSL 3.00.6 section 3.8: All identifiers containing a double underscore are reserved for
969 // use by the underlying implementation). u is short for user-defined.
970 extern const char kUserDefinedNamePrefix[];
971 
972 enum class MetadataFlags
973 {
974     // Applicable to vertex shaders (technically all pre-rasterization shaders could use this flag,
975     // but the current and only user is GL, which does not support geometry/tessellation).
976     HasClipDistance,
977     // Applicable to fragment shaders
978     HasDiscard,
979     EnablesPerSampleShading,
980     HasInputAttachment0,
981     // Flag for attachment i is HasInputAttachment0 + i
982     HasInputAttachment7 = HasInputAttachment0 + 7,
983     HasDepthInputAttachment,
984     HasStencilInputAttachment,
985     // Applicable to geometry shaders
986     HasValidGeometryShaderInputPrimitiveType,
987     HasValidGeometryShaderOutputPrimitiveType,
988     HasValidGeometryShaderMaxVertices,
989     // Applicable to tessellation shaders
990     HasValidTessGenMode,
991     HasValidTessGenSpacing,
992     HasValidTessGenVertexOrder,
993     HasValidTessGenPointMode,
994 
995     InvalidEnum,
996     EnumCount = InvalidEnum,
997 };
998 
999 namespace vk
1000 {
1001 
1002 // Specialization constant ids
1003 enum class SpecializationConstantId : uint32_t
1004 {
1005     SurfaceRotation = 0,
1006     Dither          = 1,
1007 
1008     InvalidEnum = 2,
1009     EnumCount   = InvalidEnum,
1010 };
1011 
1012 enum class SpecConstUsage : uint32_t
1013 {
1014     Rotation = 0,
1015     Dither   = 1,
1016 
1017     InvalidEnum = 2,
1018     EnumCount   = InvalidEnum,
1019 };
1020 
1021 enum ColorAttachmentDitherControl
1022 {
1023     // See comments in ContextVk::updateDither and EmulateDithering.cpp
1024     kDitherControlNoDither   = 0,
1025     kDitherControlDither4444 = 1,
1026     kDitherControlDither5551 = 2,
1027     kDitherControlDither565  = 3,
1028 };
1029 
1030 namespace spirv
1031 {
1032 enum NonSemanticInstruction
1033 {
1034     // The overview instruction containing information such as what predefined ids are present in
1035     // the SPIR-V.  Simultaneously, this instruction identifies the location where the
1036     // types/constants/variables section ends and the functions section starts.
1037     kNonSemanticOverview,
1038     // The instruction identifying the entry to the shader, i.e. at the start of main()
1039     kNonSemanticEnter,
1040     // The instruction identifying where vertex or fragment data is output.
1041     // This is before return from main() in vertex, tessellation, and fragment shaders,
1042     // and before OpEmitVertex in geometry shaders.
1043     kNonSemanticOutput,
1044     // The instruction identifying the location where transform feedback emulation should be
1045     // written.
1046     kNonSemanticTransformFeedbackEmulation,
1047 };
1048 
1049 // The non-semantic instruction id has many bits available.  With kNonSemanticOverview, they are
1050 // used to provide additional overview details.  Providing this information in the instruction's
1051 // payload require OpConstants and recovering those, which is unnecessary complexity.
1052 constexpr uint32_t kNonSemanticInstructionBits       = 4;
1053 constexpr uint32_t kNonSemanticInstructionMask       = 0xF;
1054 constexpr uint32_t kOverviewHasSampleRateShadingMask = 0x10;
1055 constexpr uint32_t kOverviewHasSampleIDMask          = 0x20;
1056 constexpr uint32_t kOverviewHasOutputPerVertexMask   = 0x40;
1057 
1058 enum ReservedIds
1059 {
1060     kIdInvalid = 0,
1061 
1062     // =============================================================================================
1063     // Ids that are fixed and are always present in the SPIR-V where applicable.  The SPIR-V
1064     // transformer can thus reliably use these ids.
1065 
1066     // Global information
1067     kIdNonSemanticInstructionSet,
1068     kIdEntryPoint,
1069 
1070     // Basic types
1071     kIdVoid,
1072     kIdFloat,
1073     kIdVec2,
1074     kIdVec3,
1075     kIdVec4,
1076     kIdMat2,
1077     kIdMat3,
1078     kIdMat4,
1079     kIdInt,
1080     kIdIVec4,
1081     kIdUint,
1082 
1083     // Common constants
1084     kIdIntZero,
1085     kIdIntOne,
1086     kIdIntTwo,
1087     kIdIntThree,
1088 
1089     // Type pointers
1090     kIdIntInputTypePointer,
1091     kIdVec4OutputTypePointer,
1092     kIdIVec4FunctionTypePointer,
1093     kIdOutputPerVertexTypePointer,
1094 
1095     // Pre-rotation and Z-correction support
1096     kIdTransformPositionFunction,
1097     kIdInputPerVertexBlockArray,
1098     kIdOutputPerVertexBlockArray,
1099     kIdOutputPerVertexVar,
1100 
1101     // Transform feedback support
1102     kIdXfbEmulationGetOffsetsFunction,
1103     kIdXfbEmulationCaptureFunction,
1104     kIdXfbEmulationBufferVarZero,
1105     kIdXfbEmulationBufferVarOne,
1106     kIdXfbEmulationBufferVarTwo,
1107     kIdXfbEmulationBufferVarThree,
1108 
1109     // Multisampling support
1110     kIdSampleID,
1111 
1112     // =============================================================================================
1113     // ANGLE internal shader variables, which are not produced as ShaderVariables.
1114     // kIdShaderVariablesBegin marks the beginning of these ids.  variableId -> info maps in the
1115     // backend can use |variableId - kIdShaderVariablesBegin| as key into a flat array.
1116     //
1117     // Note that for blocks, only the block id is in this section as that is the id used in the
1118     // variableId -> info maps.
1119     kIdShaderVariablesBegin,
1120 
1121     // gl_PerVertex
1122     kIdInputPerVertexBlock = kIdShaderVariablesBegin,
1123     kIdOutputPerVertexBlock,
1124     // The driver and default uniform blocks
1125     kIdDriverUniformsBlock,
1126     kIdDefaultUniformsBlock,
1127     // The atomic counter block
1128     kIdAtomicCounterBlock,
1129     // Buffer block used for transform feedback emulation
1130     kIdXfbEmulationBufferBlockZero,
1131     kIdXfbEmulationBufferBlockOne,
1132     kIdXfbEmulationBufferBlockTwo,
1133     kIdXfbEmulationBufferBlockThree,
1134     // Additional varying added to hold untransformed gl_Position for transform feedback capture
1135     kIdXfbExtensionPosition,
1136     // Input attachments used for framebuffer fetch and advanced blend emulation
1137     kIdInputAttachment0,
1138     kIdInputAttachment7 = kIdInputAttachment0 + 7,
1139     kIdDepthInputAttachment,
1140     kIdStencilInputAttachment,
1141 
1142     kIdFirstUnreserved,
1143 };
1144 }  // namespace spirv
1145 
1146 // Packing information for driver uniform's misc field:
1147 // - 1 bit for whether surface rotation results in swapped axes
1148 // - 5 bits for advanced blend equation
1149 // - 6 bits for sample count
1150 // - 8 bits for enabled clip planes
1151 // - 1 bit for whether depth should be transformed to Vulkan clip space
1152 // - 1 bit for whether alpha to coverage is enabled
1153 // - 1 bit for whether the framebuffer is layered
1154 // - 9 bits unused
1155 constexpr uint32_t kDriverUniformsMiscSwapXYMask                  = 0x1;
1156 constexpr uint32_t kDriverUniformsMiscAdvancedBlendEquationOffset = 1;
1157 constexpr uint32_t kDriverUniformsMiscAdvancedBlendEquationMask   = 0x1F;
1158 constexpr uint32_t kDriverUniformsMiscSampleCountOffset           = 6;
1159 constexpr uint32_t kDriverUniformsMiscSampleCountMask             = 0x3F;
1160 constexpr uint32_t kDriverUniformsMiscEnabledClipPlanesOffset     = 12;
1161 constexpr uint32_t kDriverUniformsMiscEnabledClipPlanesMask       = 0xFF;
1162 constexpr uint32_t kDriverUniformsMiscTransformDepthOffset        = 20;
1163 constexpr uint32_t kDriverUniformsMiscTransformDepthMask          = 0x1;
1164 constexpr uint32_t kDriverUniformsMiscAlphaToCoverageOffset       = 21;
1165 constexpr uint32_t kDriverUniformsMiscAlphaToCoverageMask         = 0x1;
1166 constexpr uint32_t kDriverUniformsMiscLayeredFramebufferOffset    = 22;
1167 constexpr uint32_t kDriverUniformsMiscLayeredFramebufferMask      = 0x1;
1168 }  // namespace vk
1169 
1170 namespace mtl
1171 {
1172 // Specialization constant to enable multisampled rendering behavior.
1173 extern const char kMultisampledRenderingConstName[];
1174 
1175 // Specialization constant to emulate rasterizer discard.
1176 extern const char kRasterizerDiscardEnabledConstName[];
1177 
1178 // Specialization constant to enable depth write in fragment shaders.
1179 extern const char kDepthWriteEnabledConstName[];
1180 
1181 // Specialization constant to enable alpha to coverage.
1182 extern const char kEmulateAlphaToCoverageConstName[];
1183 
1184 // Specialization constant to write helper sample mask output.
1185 extern const char kWriteHelperSampleMaskConstName[];
1186 
1187 // Specialization constant to enable sample mask output.
1188 extern const char kSampleMaskWriteEnabledConstName[];
1189 }  // namespace mtl
1190 
1191 }  // namespace sh
1192 
1193 #endif  // GLSLANG_SHADERLANG_H_
1194