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