Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/include/GLSLANG/ShaderLang.h
1693 views
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 266
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 SPIR-V to be cross compiled to Metal.
76
SH_SPIRV_METAL_OUTPUT = 0x8B4C,
77
78
// Output for MSL
79
SH_MSL_METAL_OUTPUT = 0x8B4D,
80
};
81
82
// Compile options.
83
// The Compile options type is defined in ShaderVars.h, to allow ANGLE to import the ShaderVars
84
// header without needing the ShaderLang header. This avoids some conflicts with glslang.
85
86
const ShCompileOptions SH_VALIDATE = 0;
87
const ShCompileOptions SH_VALIDATE_LOOP_INDEXING = UINT64_C(1) << 0;
88
const ShCompileOptions SH_INTERMEDIATE_TREE = UINT64_C(1) << 1;
89
const ShCompileOptions SH_OBJECT_CODE = UINT64_C(1) << 2;
90
const ShCompileOptions SH_VARIABLES = UINT64_C(1) << 3;
91
const ShCompileOptions SH_LINE_DIRECTIVES = UINT64_C(1) << 4;
92
const ShCompileOptions SH_SOURCE_PATH = UINT64_C(1) << 5;
93
94
// If requested, validates the AST after every transformation. Useful for debugging.
95
const ShCompileOptions SH_VALIDATE_AST = UINT64_C(1) << 6;
96
97
// Due to spec difference between GLSL 4.1 or lower and ESSL3, some platforms (for example, Mac OSX
98
// core profile) require a variable's "invariant"/"centroid" qualifiers to match between vertex and
99
// fragment shader. A simple solution to allow such shaders to link is to omit the two qualifiers.
100
// AMD driver in Linux requires invariant qualifier to match between vertex and fragment shaders,
101
// while ESSL3 disallows invariant qualifier in fragment shader and GLSL >= 4.2 doesn't require
102
// invariant qualifier to match between shaders. Remove invariant qualifier from vertex shader to
103
// workaround AMD driver bug.
104
// Note that the two flags take effect on ESSL3 input shaders translated to GLSL 4.1 or lower and to
105
// GLSL 4.2 or newer on Linux AMD.
106
// TODO(zmo): This is not a good long-term solution. Simply dropping these qualifiers may break some
107
// developers' content. A more complex workaround of dynamically generating, compiling, and
108
// re-linking shaders that use these qualifiers should be implemented.
109
const ShCompileOptions SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3 = UINT64_C(1) << 7;
110
111
// This flag works around bug in Intel Mac drivers related to abs(i) where
112
// i is an integer.
113
const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 8;
114
115
// Enforce the GLSL 1.017 Appendix A section 7 packing restrictions.
116
// This flag only enforces (and can only enforce) the packing
117
// restrictions for uniform variables in both vertex and fragment
118
// shaders. ShCheckVariablesWithinPackingLimits() lets embedders
119
// enforce the packing restrictions for varying variables during
120
// program link time.
121
const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 9;
122
123
// This flag ensures all indirect (expression-based) array indexing
124
// is clamped to the bounds of the array. This ensures, for example,
125
// that you cannot read off the end of a uniform, whether an array
126
// vec234, or mat234 type.
127
const ShCompileOptions SH_CLAMP_INDIRECT_ARRAY_BOUNDS = UINT64_C(1) << 10;
128
129
// This flag limits the complexity of an expression.
130
const ShCompileOptions SH_LIMIT_EXPRESSION_COMPLEXITY = UINT64_C(1) << 11;
131
132
// This flag limits the depth of the call stack.
133
const ShCompileOptions SH_LIMIT_CALL_STACK_DEPTH = UINT64_C(1) << 12;
134
135
// This flag initializes gl_Position to vec4(0,0,0,0) at the
136
// beginning of the vertex shader's main(), and has no effect in the
137
// fragment shader. It is intended as a workaround for drivers which
138
// incorrectly fail to link programs if gl_Position is not written.
139
const ShCompileOptions SH_INIT_GL_POSITION = UINT64_C(1) << 13;
140
141
// This flag replaces
142
// "a && b" with "a ? b : false",
143
// "a || b" with "a ? true : b".
144
// This is to work around a MacOSX driver bug that |b| is executed
145
// independent of |a|'s value.
146
const ShCompileOptions SH_UNFOLD_SHORT_CIRCUIT = UINT64_C(1) << 14;
147
148
// This flag initializes output variables to 0 at the beginning of main().
149
// It is to avoid undefined behaviors.
150
const ShCompileOptions SH_INIT_OUTPUT_VARIABLES = UINT64_C(1) << 15;
151
152
// This flag scalarizes vec/ivec/bvec/mat constructor args.
153
// It is intended as a workaround for Linux/Mac driver bugs.
154
const ShCompileOptions SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS = UINT64_C(1) << 16;
155
156
// This flag overwrites a struct name with a unique prefix.
157
// It is intended as a workaround for drivers that do not handle
158
// struct scopes correctly, including all Mac drivers and Linux AMD.
159
const ShCompileOptions SH_REGENERATE_STRUCT_NAMES = UINT64_C(1) << 17;
160
161
// This flag works around bugs in Mac drivers related to do-while by
162
// transforming them into an other construct.
163
const ShCompileOptions SH_REWRITE_DO_WHILE_LOOPS = UINT64_C(1) << 18;
164
165
// This flag works around a bug in the HLSL compiler optimizer that folds certain
166
// constant pow expressions incorrectly. Only applies to the HLSL back-end. It works
167
// by expanding the integer pow expressions into a series of multiplies.
168
const ShCompileOptions SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS = UINT64_C(1) << 19;
169
170
// Flatten "#pragma STDGL invariant(all)" into the declarations of
171
// varying variables and built-in GLSL variables. This compiler
172
// option is enabled automatically when needed.
173
const ShCompileOptions SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL = UINT64_C(1) << 20;
174
175
// Some drivers do not take into account the base level of the texture in the results of the
176
// HLSL GetDimensions builtin. This flag instructs the compiler to manually add the base level
177
// offsetting.
178
const ShCompileOptions SH_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL = UINT64_C(1) << 21;
179
180
// This flag works around an issue in translating GLSL function texelFetchOffset on
181
// INTEL drivers. It works by translating texelFetchOffset into texelFetch.
182
const ShCompileOptions SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH = UINT64_C(1) << 22;
183
184
// This flag works around condition bug of for and while loops in Intel Mac OSX drivers.
185
// Condition calculation is not correct. Rewrite it from "CONDITION" to "CONDITION && true".
186
const ShCompileOptions SH_ADD_AND_TRUE_TO_LOOP_CONDITION = UINT64_C(1) << 23;
187
188
// This flag works around a bug in evaluating unary minus operator on integer on some INTEL
189
// drivers. It works by translating -(int) into ~(int) + 1.
190
const ShCompileOptions SH_REWRITE_INTEGER_UNARY_MINUS_OPERATOR = UINT64_C(1) << 24;
191
192
// This flag works around a bug in evaluating isnan() on some INTEL D3D and Mac OSX drivers.
193
// It works by using an expression to emulate this function.
194
const ShCompileOptions SH_EMULATE_ISNAN_FLOAT_FUNCTION = UINT64_C(1) << 25;
195
196
// This flag will use all uniforms of unused std140 and shared uniform blocks at the
197
// beginning of the vertex/fragment shader's main(). It is intended as a workaround for Mac
198
// drivers with shader version 4.10. In those drivers, they will treat unused
199
// std140 and shared uniform blocks' members as inactive. However, WebGL2.0 based on
200
// OpenGL ES3.0.4 requires all members of a named uniform block declared with a shared or std140
201
// layout qualifier to be considered active. The uniform block itself is also considered active.
202
const ShCompileOptions SH_USE_UNUSED_STANDARD_SHARED_BLOCKS = UINT64_C(1) << 26;
203
204
// This flag works around a bug in unary minus operator on float numbers on Intel
205
// Mac OSX 10.11 drivers. It works by translating -float into 0.0 - float.
206
const ShCompileOptions SH_REWRITE_FLOAT_UNARY_MINUS_OPERATOR = UINT64_C(1) << 27;
207
208
// This flag works around a bug in evaluating atan(y, x) on some NVIDIA OpenGL drivers.
209
// It works by using an expression to emulate this function.
210
const ShCompileOptions SH_EMULATE_ATAN2_FLOAT_FUNCTION = UINT64_C(1) << 28;
211
212
// Set to initialize uninitialized local and global temporary variables. Should only be used with
213
// GLSL output. In HLSL output variables are initialized regardless of if this flag is set.
214
const ShCompileOptions SH_INITIALIZE_UNINITIALIZED_LOCALS = UINT64_C(1) << 29;
215
216
// The flag modifies the shader in the following way:
217
// Every occurrence of gl_InstanceID is replaced by the global temporary variable InstanceID.
218
// Every occurrence of gl_ViewID_OVR is replaced by the varying variable ViewID_OVR.
219
// At the beginning of the body of main() in a vertex shader the following initializers are added:
220
// ViewID_OVR = uint(gl_InstanceID) % num_views;
221
// InstanceID = gl_InstanceID / num_views;
222
// ViewID_OVR is added as a varying variable to both the vertex and fragment shaders.
223
const ShCompileOptions SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW = UINT64_C(1) << 30;
224
225
// With the flag enabled the GLSL/ESSL vertex shader is modified to include code for viewport
226
// selection in the following way:
227
// - Code to enable the extension ARB_shader_viewport_layer_array/NV_viewport_array2 is included.
228
// - Code to select the viewport index or layer is inserted at the beginning of main after
229
// ViewID_OVR's initialization.
230
// - A declaration of the uniform multiviewBaseViewLayerIndex.
231
// Note: The SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW flag also has to be enabled to have the
232
// temporary variable ViewID_OVR declared and initialized.
233
const ShCompileOptions SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER = UINT64_C(1) << 31;
234
235
// If the flag is enabled, gl_PointSize is clamped to the maximum point size specified in
236
// ShBuiltInResources in vertex shaders.
237
const ShCompileOptions SH_CLAMP_POINT_SIZE = UINT64_C(1) << 32;
238
239
// Bit 33 is available.
240
241
// Don't use loops to initialize uninitialized variables. Only has an effect if some kind of
242
// variable initialization is turned on.
243
const ShCompileOptions SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES = UINT64_C(1) << 34;
244
245
// Don't use D3D constant register zero when allocating space for uniforms. This is targeted to work
246
// around a bug in NVIDIA D3D driver version 388.59 where in very specific cases the driver would
247
// not handle constant register zero correctly. Only has an effect on HLSL translation.
248
const ShCompileOptions SH_SKIP_D3D_CONSTANT_REGISTER_ZERO = UINT64_C(1) << 35;
249
250
// Clamp gl_FragDepth to the range [0.0, 1.0] in case it is statically used.
251
const ShCompileOptions SH_CLAMP_FRAG_DEPTH = UINT64_C(1) << 36;
252
253
// Rewrite expressions like "v.x = z = expression;". Works around a bug in NVIDIA OpenGL drivers
254
// prior to version 397.31.
255
const ShCompileOptions SH_REWRITE_REPEATED_ASSIGN_TO_SWIZZLED = UINT64_C(1) << 37;
256
257
// Rewrite gl_DrawID as a uniform int
258
const ShCompileOptions SH_EMULATE_GL_DRAW_ID = UINT64_C(1) << 38;
259
260
// This flag initializes shared variables to 0.
261
// It is to avoid ompute shaders being able to read undefined values that could be coming from
262
// another webpage/application.
263
const ShCompileOptions SH_INIT_SHARED_VARIABLES = UINT64_C(1) << 39;
264
265
// Forces the value returned from an atomic operations to be always be resolved. This is targeted to
266
// workaround a bug in NVIDIA D3D driver where the return value from
267
// RWByteAddressBuffer.InterlockedAdd does not get resolved when used in the .yzw components of a
268
// RWByteAddressBuffer.Store operation. Only has an effect on HLSL translation.
269
// http://anglebug.com/3246
270
const ShCompileOptions SH_FORCE_ATOMIC_VALUE_RESOLUTION = UINT64_C(1) << 40;
271
272
// Rewrite gl_BaseVertex and gl_BaseInstance as uniform int
273
const ShCompileOptions SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE = UINT64_C(1) << 41;
274
275
// Emulate seamful cube map sampling for OpenGL ES2.0. Currently only applies to the Vulkan
276
// backend, as is done after samplers are moved out of structs. Can likely be made to work on
277
// the other backends as well.
278
const ShCompileOptions SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING = UINT64_C(1) << 42;
279
280
// This flag controls how to translate WEBGL_video_texture sampling function.
281
const ShCompileOptions SH_TAKE_VIDEO_TEXTURE_AS_EXTERNAL_OES = UINT64_C(1) << 43;
282
283
// This flag works around a inconsistent behavior in Mac AMD driver where gl_VertexID doesn't
284
// include base vertex value. It replaces gl_VertexID with (gl_VertexID + angle_BaseVertex)
285
// when angle_BaseVertex is available.
286
const ShCompileOptions SH_ADD_BASE_VERTEX_TO_VERTEX_ID = UINT64_C(1) << 44;
287
288
// This works around the dynamic lvalue indexing of swizzled vectors on various platforms.
289
const ShCompileOptions SH_REMOVE_DYNAMIC_INDEXING_OF_SWIZZLED_VECTOR = UINT64_C(1) << 45;
290
291
// This flag works around a slow fxc compile performance issue with dynamic uniform indexing.
292
const ShCompileOptions SH_ALLOW_TRANSLATE_UNIFORM_BLOCK_TO_STRUCTUREDBUFFER = UINT64_C(1) << 46;
293
294
// This flag indicates whether Bresenham line raster emulation code should be generated. This
295
// emulation is necessary if the backend uses a differnet algorithm to draw lines. Currently only
296
// implemented for the Vulkan backend.
297
const ShCompileOptions SH_ADD_BRESENHAM_LINE_RASTER_EMULATION = UINT64_C(1) << 47;
298
299
// This flag allows disabling ARB_texture_rectangle on a per-compile basis. This is necessary
300
// for WebGL contexts becuase ARB_texture_rectangle may be necessary for the WebGL implementation
301
// internally but shouldn't be exposed to WebGL user code.
302
const ShCompileOptions SH_DISABLE_ARB_TEXTURE_RECTANGLE = UINT64_C(1) << 48;
303
304
// This flag works around a driver bug by rewriting uses of row-major matrices
305
// as column-major in ESSL 3.00 and greater shaders.
306
const ShCompileOptions SH_REWRITE_ROW_MAJOR_MATRICES = UINT64_C(1) << 49;
307
308
// Drop any explicit precision qualifiers from shader.
309
const ShCompileOptions SH_IGNORE_PRECISION_QUALIFIERS = UINT64_C(1) << 50;
310
311
// Allow compiler to do early fragment tests as an optimization.
312
const ShCompileOptions SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION = UINT64_C(1) << 51;
313
314
// Allow compiler to insert Android pre-rotation code.
315
const ShCompileOptions SH_ADD_PRE_ROTATION = UINT64_C(1) << 52;
316
317
const ShCompileOptions SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP = UINT64_C(1) << 53;
318
319
// Allow compiler to use specialization constant to do pre-rotation and y flip.
320
const ShCompileOptions SH_USE_SPECIALIZATION_CONSTANT = UINT64_C(1) << 54;
321
322
// Ask compiler to generate Vulkan transform feedback emulation support code.
323
const ShCompileOptions SH_ADD_VULKAN_XFB_EMULATION_SUPPORT_CODE = UINT64_C(1) << 55;
324
325
// Ask compiler to generate Vulkan transform feedback support code when using the
326
// VK_EXT_transform_feedback extension.
327
const ShCompileOptions SH_ADD_VULKAN_XFB_EXTENSION_SUPPORT_CODE = UINT64_C(1) << 56;
328
329
// This flag initializes fragment shader's output variables to zero at the beginning of the fragment
330
// shader's main(). It is intended as a workaround for drivers which get context lost if
331
// gl_FragColor is not written.
332
const ShCompileOptions SH_INIT_FRAGMENT_OUTPUT_VARIABLES = UINT64_C(1) << 57;
333
334
// Transitory flag to select between producing SPIR-V directly vs using glslang. Ignored in
335
// non-assert-enabled builds to avoid increasing ANGLE's binary size while both generators coexist.
336
const ShCompileOptions SH_GENERATE_SPIRV_DIRECTLY = UINT64_C(1) << 58;
337
338
// The 64 bits hash function. The first parameter is the input string; the
339
// second parameter is the string length.
340
using ShHashFunction64 = khronos_uint64_t (*)(const char *, size_t);
341
342
//
343
// Implementation dependent built-in resources (constants and extensions).
344
// The names for these resources has been obtained by stripping gl_/GL_.
345
//
346
struct ShBuiltInResources
347
{
348
// Constants.
349
int MaxVertexAttribs;
350
int MaxVertexUniformVectors;
351
int MaxVaryingVectors;
352
int MaxVertexTextureImageUnits;
353
int MaxCombinedTextureImageUnits;
354
int MaxTextureImageUnits;
355
int MaxFragmentUniformVectors;
356
int MaxDrawBuffers;
357
358
// Extensions.
359
// Set to 1 to enable the extension, else 0.
360
int OES_standard_derivatives;
361
int OES_EGL_image_external;
362
int OES_EGL_image_external_essl3;
363
int NV_EGL_stream_consumer_external;
364
int ARB_texture_rectangle;
365
int EXT_blend_func_extended;
366
int EXT_draw_buffers;
367
int EXT_frag_depth;
368
int EXT_shader_texture_lod;
369
int EXT_shader_framebuffer_fetch;
370
int EXT_shader_framebuffer_fetch_non_coherent;
371
int NV_shader_framebuffer_fetch;
372
int NV_shader_noperspective_interpolation;
373
int ARM_shader_framebuffer_fetch;
374
int OVR_multiview;
375
int OVR_multiview2;
376
int EXT_multisampled_render_to_texture;
377
int EXT_multisampled_render_to_texture2;
378
int EXT_YUV_target;
379
int EXT_geometry_shader;
380
int OES_geometry_shader;
381
int OES_shader_io_blocks;
382
int EXT_shader_io_blocks;
383
int EXT_gpu_shader5;
384
int EXT_shader_non_constant_global_initializers;
385
int OES_texture_storage_multisample_2d_array;
386
int OES_texture_3D;
387
int ANGLE_texture_multisample;
388
int ANGLE_multi_draw;
389
int ANGLE_base_vertex_base_instance;
390
int WEBGL_video_texture;
391
int APPLE_clip_distance;
392
int OES_texture_cube_map_array;
393
int EXT_texture_cube_map_array;
394
int EXT_shadow_samplers;
395
int OES_shader_multisample_interpolation;
396
int OES_shader_image_atomic;
397
int EXT_tessellation_shader;
398
int OES_texture_buffer;
399
int EXT_texture_buffer;
400
int OES_sample_variables;
401
int EXT_clip_cull_distance;
402
int EXT_primitive_bounding_box;
403
404
// Set to 1 to enable replacing GL_EXT_draw_buffers #extension directives
405
// with GL_NV_draw_buffers in ESSL output. This flag can be used to emulate
406
// EXT_draw_buffers by using it in combination with GLES3.0 glDrawBuffers
407
// function. This applies to Tegra K1 devices.
408
int NV_draw_buffers;
409
410
// Set to 1 if highp precision is supported in the ESSL 1.00 version of the
411
// fragment language. Does not affect versions of the language where highp
412
// support is mandatory.
413
// Default is 0.
414
int FragmentPrecisionHigh;
415
416
// GLSL ES 3.0 constants.
417
int MaxVertexOutputVectors;
418
int MaxFragmentInputVectors;
419
int MinProgramTexelOffset;
420
int MaxProgramTexelOffset;
421
422
// Extension constants.
423
424
// Value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT for OpenGL ES output context.
425
// Value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS for OpenGL output context.
426
// GLES SL version 100 gl_MaxDualSourceDrawBuffersEXT value for EXT_blend_func_extended.
427
int MaxDualSourceDrawBuffers;
428
429
// Value of GL_MAX_VIEWS_OVR.
430
int MaxViewsOVR;
431
432
// Name Hashing.
433
// Set a 64 bit hash function to enable user-defined name hashing.
434
// Default is NULL.
435
ShHashFunction64 HashFunction;
436
437
// The maximum complexity an expression can be when SH_LIMIT_EXPRESSION_COMPLEXITY is turned on.
438
int MaxExpressionComplexity;
439
440
// The maximum depth a call stack can be.
441
int MaxCallStackDepth;
442
443
// The maximum number of parameters a function can have when SH_LIMIT_EXPRESSION_COMPLEXITY is
444
// turned on.
445
int MaxFunctionParameters;
446
447
// GLES 3.1 constants
448
449
// texture gather offset constraints.
450
int MinProgramTextureGatherOffset;
451
int MaxProgramTextureGatherOffset;
452
453
// maximum number of available image units
454
int MaxImageUnits;
455
456
// OES_sample_variables constant
457
// maximum number of available samples
458
int MaxSamples;
459
460
// maximum number of image uniforms in a vertex shader
461
int MaxVertexImageUniforms;
462
463
// maximum number of image uniforms in a fragment shader
464
int MaxFragmentImageUniforms;
465
466
// maximum number of image uniforms in a compute shader
467
int MaxComputeImageUniforms;
468
469
// maximum total number of image uniforms in a program
470
int MaxCombinedImageUniforms;
471
472
// maximum number of uniform locations
473
int MaxUniformLocations;
474
475
// maximum number of ssbos and images in a shader
476
int MaxCombinedShaderOutputResources;
477
478
// maximum number of groups in each dimension
479
std::array<int, 3> MaxComputeWorkGroupCount;
480
// maximum number of threads per work group in each dimension
481
std::array<int, 3> MaxComputeWorkGroupSize;
482
483
// maximum number of total uniform components
484
int MaxComputeUniformComponents;
485
486
// maximum number of texture image units in a compute shader
487
int MaxComputeTextureImageUnits;
488
489
// maximum number of atomic counters in a compute shader
490
int MaxComputeAtomicCounters;
491
492
// maximum number of atomic counter buffers in a compute shader
493
int MaxComputeAtomicCounterBuffers;
494
495
// maximum number of atomic counters in a vertex shader
496
int MaxVertexAtomicCounters;
497
498
// maximum number of atomic counters in a fragment shader
499
int MaxFragmentAtomicCounters;
500
501
// maximum number of atomic counters in a program
502
int MaxCombinedAtomicCounters;
503
504
// maximum binding for an atomic counter
505
int MaxAtomicCounterBindings;
506
507
// maximum number of atomic counter buffers in a vertex shader
508
int MaxVertexAtomicCounterBuffers;
509
510
// maximum number of atomic counter buffers in a fragment shader
511
int MaxFragmentAtomicCounterBuffers;
512
513
// maximum number of atomic counter buffers in a program
514
int MaxCombinedAtomicCounterBuffers;
515
516
// maximum number of buffer object storage in machine units
517
int MaxAtomicCounterBufferSize;
518
519
// maximum number of uniform block bindings
520
int MaxUniformBufferBindings;
521
522
// maximum number of shader storage buffer bindings
523
int MaxShaderStorageBufferBindings;
524
525
// maximum point size (higher limit from ALIASED_POINT_SIZE_RANGE)
526
float MaxPointSize;
527
528
// EXT_geometry_shader constants
529
int MaxGeometryUniformComponents;
530
int MaxGeometryUniformBlocks;
531
int MaxGeometryInputComponents;
532
int MaxGeometryOutputComponents;
533
int MaxGeometryOutputVertices;
534
int MaxGeometryTotalOutputComponents;
535
int MaxGeometryTextureImageUnits;
536
int MaxGeometryAtomicCounterBuffers;
537
int MaxGeometryAtomicCounters;
538
int MaxGeometryShaderStorageBlocks;
539
int MaxGeometryShaderInvocations;
540
int MaxGeometryImageUniforms;
541
542
// EXT_tessellation_shader constants
543
int MaxTessControlInputComponents;
544
int MaxTessControlOutputComponents;
545
int MaxTessControlTextureImageUnits;
546
int MaxTessControlUniformComponents;
547
int MaxTessControlTotalOutputComponents;
548
int MaxTessControlImageUniforms;
549
int MaxTessControlAtomicCounters;
550
int MaxTessControlAtomicCounterBuffers;
551
552
int MaxTessPatchComponents;
553
int MaxPatchVertices;
554
int MaxTessGenLevel;
555
556
int MaxTessEvaluationInputComponents;
557
int MaxTessEvaluationOutputComponents;
558
int MaxTessEvaluationTextureImageUnits;
559
int MaxTessEvaluationUniformComponents;
560
int MaxTessEvaluationImageUniforms;
561
int MaxTessEvaluationAtomicCounters;
562
int MaxTessEvaluationAtomicCounterBuffers;
563
564
// Subpixel bits used in rasterization.
565
int SubPixelBits;
566
567
// APPLE_clip_distance/EXT_clip_cull_distance constant
568
int MaxClipDistances;
569
int MaxCullDistances;
570
int MaxCombinedClipAndCullDistances;
571
572
// Direct-to-metal backend constants:
573
574
// Binding index for driver uniforms:
575
int DriverUniformsBindingIndex;
576
// Binding index for default uniforms:
577
int DefaultUniformsBindingIndex;
578
// Binding index for UBO's argument buffer
579
int UBOArgumentBufferBindingIndex;
580
};
581
582
//
583
// ShHandle held by but opaque to the driver. It is allocated,
584
// managed, and de-allocated by the compiler. Its contents
585
// are defined by and used by the compiler.
586
//
587
// If handle creation fails, 0 will be returned.
588
//
589
using ShHandle = void *;
590
591
namespace sh
592
{
593
using BinaryBlob = std::vector<uint32_t>;
594
595
//
596
// Driver must call this first, once, before doing any other compiler operations.
597
// If the function succeeds, the return value is true, else false.
598
//
599
bool Initialize();
600
//
601
// Driver should call this at shutdown.
602
// If the function succeeds, the return value is true, else false.
603
//
604
bool Finalize();
605
606
//
607
// Initialize built-in resources with minimum expected values.
608
// Parameters:
609
// resources: The object to initialize. Will be comparable with memcmp.
610
//
611
void InitBuiltInResources(ShBuiltInResources *resources);
612
613
//
614
// Returns the a concatenated list of the items in ShBuiltInResources as a null-terminated string.
615
// This function must be updated whenever ShBuiltInResources is changed.
616
// Parameters:
617
// handle: Specifies the handle of the compiler to be used.
618
const std::string &GetBuiltInResourcesString(const ShHandle handle);
619
620
//
621
// Driver calls these to create and destroy compiler objects.
622
//
623
// Returns the handle of constructed compiler, null if the requested compiler is not supported.
624
// Parameters:
625
// type: Specifies the type of shader - GL_FRAGMENT_SHADER or GL_VERTEX_SHADER.
626
// spec: Specifies the language spec the compiler must conform to - SH_GLES2_SPEC or SH_WEBGL_SPEC.
627
// output: Specifies the output code type - for example SH_ESSL_OUTPUT, SH_GLSL_OUTPUT,
628
// SH_HLSL_3_0_OUTPUT or SH_HLSL_4_1_OUTPUT. Note: Each output type may only
629
// be supported in some configurations.
630
// resources: Specifies the built-in resources.
631
ShHandle ConstructCompiler(sh::GLenum type,
632
ShShaderSpec spec,
633
ShShaderOutput output,
634
const ShBuiltInResources *resources);
635
void Destruct(ShHandle handle);
636
637
//
638
// Compiles the given shader source.
639
// If the function succeeds, the return value is true, else false.
640
// Parameters:
641
// handle: Specifies the handle of compiler to be used.
642
// shaderStrings: Specifies an array of pointers to null-terminated strings containing the shader
643
// source code.
644
// numStrings: Specifies the number of elements in shaderStrings array.
645
// compileOptions: A mask containing the following parameters:
646
// SH_VALIDATE: Validates shader to ensure that it conforms to the spec
647
// specified during compiler construction.
648
// SH_VALIDATE_LOOP_INDEXING: Validates loop and indexing in the shader to
649
// ensure that they do not exceed the minimum
650
// functionality mandated in GLSL 1.0 spec,
651
// Appendix A, Section 4 and 5.
652
// There is no need to specify this parameter when
653
// compiling for WebGL - it is implied.
654
// SH_INTERMEDIATE_TREE: Writes intermediate tree to info log.
655
// Can be queried by calling sh::GetInfoLog().
656
// SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader, or SPIR-V binary.
657
// Can be queried by calling sh::GetObjectCode().
658
// SH_VARIABLES: Extracts attributes, uniforms, and varyings.
659
// Can be queried by calling ShGetVariableInfo().
660
//
661
bool Compile(const ShHandle handle,
662
const char *const shaderStrings[],
663
size_t numStrings,
664
ShCompileOptions compileOptions);
665
666
// Clears the results from the previous compilation.
667
void ClearResults(const ShHandle handle);
668
669
// Return the version of the shader language.
670
int GetShaderVersion(const ShHandle handle);
671
672
// Return the currently set language output type.
673
ShShaderOutput GetShaderOutputType(const ShHandle handle);
674
675
// Returns null-terminated information log for a compiled shader.
676
// Parameters:
677
// handle: Specifies the compiler
678
const std::string &GetInfoLog(const ShHandle handle);
679
680
// Returns null-terminated object code for a compiled shader. Only valid for output types that
681
// generate human-readable code (GLSL, ESSL or HLSL).
682
// Parameters:
683
// handle: Specifies the compiler
684
const std::string &GetObjectCode(const ShHandle handle);
685
686
// Returns object binary blob for a compiled shader. Only valid for output types that
687
// generate binary blob (SPIR-V).
688
// Parameters:
689
// handle: Specifies the compiler
690
const BinaryBlob &GetObjectBinaryBlob(const ShHandle handle);
691
692
// Returns a (original_name, hash) map containing all the user defined names in the shader,
693
// including variable names, function names, struct names, and struct field names.
694
// Parameters:
695
// handle: Specifies the compiler
696
const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle);
697
698
// Shader variable inspection.
699
// Returns a pointer to a list of variables of the designated type.
700
// (See ShaderVars.h for type definitions, included above)
701
// Returns NULL on failure.
702
// Parameters:
703
// handle: Specifies the compiler
704
const std::vector<sh::ShaderVariable> *GetUniforms(const ShHandle handle);
705
const std::vector<sh::ShaderVariable> *GetVaryings(const ShHandle handle);
706
const std::vector<sh::ShaderVariable> *GetInputVaryings(const ShHandle handle);
707
const std::vector<sh::ShaderVariable> *GetOutputVaryings(const ShHandle handle);
708
const std::vector<sh::ShaderVariable> *GetAttributes(const ShHandle handle);
709
const std::vector<sh::ShaderVariable> *GetOutputVariables(const ShHandle handle);
710
const std::vector<sh::InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle);
711
const std::vector<sh::InterfaceBlock> *GetUniformBlocks(const ShHandle handle);
712
const std::vector<sh::InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle);
713
sh::WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle);
714
// Returns the number of views specified through the num_views layout qualifier. If num_views is
715
// not set, the function returns -1.
716
int GetVertexShaderNumViews(const ShHandle handle);
717
// Returns true if compiler has injected instructions for early fragment tests as an optimization
718
bool HasEarlyFragmentTestsOptimization(const ShHandle handle);
719
720
// Returns specialization constant usage bits
721
uint32_t GetShaderSpecConstUsageBits(const ShHandle handle);
722
723
// Returns true if the passed in variables pack in maxVectors followingthe packing rules from the
724
// GLSL 1.017 spec, Appendix A, section 7.
725
// Returns false otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
726
// flag above.
727
// Parameters:
728
// maxVectors: the available rows of registers.
729
// variables: an array of variables.
730
bool CheckVariablesWithinPackingLimits(int maxVectors,
731
const std::vector<sh::ShaderVariable> &variables);
732
733
// Gives the compiler-assigned register for a shader storage block.
734
// The method writes the value to the output variable "indexOut".
735
// Returns true if it found a valid shader storage block, false otherwise.
736
// Parameters:
737
// handle: Specifies the compiler
738
// shaderStorageBlockName: Specifies the shader storage block
739
// indexOut: output variable that stores the assigned register
740
bool GetShaderStorageBlockRegister(const ShHandle handle,
741
const std::string &shaderStorageBlockName,
742
unsigned int *indexOut);
743
744
// Gives the compiler-assigned register for a uniform block.
745
// The method writes the value to the output variable "indexOut".
746
// Returns true if it found a valid uniform block, false otherwise.
747
// Parameters:
748
// handle: Specifies the compiler
749
// uniformBlockName: Specifies the uniform block
750
// indexOut: output variable that stores the assigned register
751
bool GetUniformBlockRegister(const ShHandle handle,
752
const std::string &uniformBlockName,
753
unsigned int *indexOut);
754
755
bool ShouldUniformBlockUseStructuredBuffer(const ShHandle handle,
756
const std::string &uniformBlockName);
757
const std::set<std::string> *GetSlowCompilingUniformBlockSet(const ShHandle handle);
758
759
// Gives a map from uniform names to compiler-assigned registers in the default uniform block.
760
// Note that the map contains also registers of samplers that have been extracted from structs.
761
const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle);
762
763
// Sampler, image and atomic counters share registers(t type and u type),
764
// GetReadonlyImage2DRegisterIndex and GetImage2DRegisterIndex return the first index into
765
// a range of reserved registers for image2D/iimage2D/uimage2D variables.
766
// Parameters: handle: Specifies the compiler
767
unsigned int GetReadonlyImage2DRegisterIndex(const ShHandle handle);
768
unsigned int GetImage2DRegisterIndex(const ShHandle handle);
769
770
// The method records these used function names related with image2D/iimage2D/uimage2D, these
771
// functions will be dynamically generated.
772
// Parameters:
773
// handle: Specifies the compiler
774
const std::set<std::string> *GetUsedImage2DFunctionNames(const ShHandle handle);
775
776
bool HasValidGeometryShaderInputPrimitiveType(const ShHandle handle);
777
bool HasValidGeometryShaderOutputPrimitiveType(const ShHandle handle);
778
bool HasValidGeometryShaderMaxVertices(const ShHandle handle);
779
bool HasValidTessGenMode(const ShHandle handle);
780
bool HasValidTessGenSpacing(const ShHandle handle);
781
bool HasValidTessGenVertexOrder(const ShHandle handle);
782
bool HasValidTessGenPointMode(const ShHandle handle);
783
GLenum GetGeometryShaderInputPrimitiveType(const ShHandle handle);
784
GLenum GetGeometryShaderOutputPrimitiveType(const ShHandle handle);
785
int GetGeometryShaderInvocations(const ShHandle handle);
786
int GetGeometryShaderMaxVertices(const ShHandle handle);
787
unsigned int GetShaderSharedMemorySize(const ShHandle handle);
788
int GetTessControlShaderVertices(const ShHandle handle);
789
GLenum GetTessGenMode(const ShHandle handle);
790
GLenum GetTessGenSpacing(const ShHandle handle);
791
GLenum GetTessGenVertexOrder(const ShHandle handle);
792
GLenum GetTessGenPointMode(const ShHandle handle);
793
794
//
795
// Helper function to identify specs that are based on the WebGL spec.
796
//
797
inline bool IsWebGLBasedSpec(ShShaderSpec spec)
798
{
799
return (spec == SH_WEBGL_SPEC || spec == SH_WEBGL2_SPEC || spec == SH_WEBGL3_SPEC);
800
}
801
802
//
803
// Helper function to identify DesktopGL specs
804
//
805
inline bool IsDesktopGLSpec(ShShaderSpec spec)
806
{
807
return spec == SH_GL_CORE_SPEC || spec == SH_GL_COMPATIBILITY_SPEC;
808
}
809
810
// Can't prefix with just _ because then we might introduce a double underscore, which is not safe
811
// in GLSL (ESSL 3.00.6 section 3.8: All identifiers containing a double underscore are reserved for
812
// use by the underlying implementation). u is short for user-defined.
813
extern const char kUserDefinedNamePrefix[];
814
815
namespace vk
816
{
817
818
// Specialization constant ids
819
enum class SpecializationConstantId : uint32_t
820
{
821
LineRasterEmulation = 0,
822
SurfaceRotation = 1,
823
DrawableWidth = 2,
824
DrawableHeight = 3,
825
826
InvalidEnum = 4,
827
EnumCount = InvalidEnum,
828
};
829
830
enum class SurfaceRotation : uint32_t
831
{
832
Identity,
833
Rotated90Degrees,
834
Rotated180Degrees,
835
Rotated270Degrees,
836
FlippedIdentity,
837
FlippedRotated90Degrees,
838
FlippedRotated180Degrees,
839
FlippedRotated270Degrees,
840
841
InvalidEnum,
842
EnumCount = InvalidEnum,
843
};
844
845
enum class SpecConstUsage : uint32_t
846
{
847
LineRasterEmulation = 0,
848
YFlip = 1,
849
Rotation = 2,
850
DrawableSize = 3,
851
852
InvalidEnum = 4,
853
EnumCount = InvalidEnum,
854
};
855
856
// Interface block name containing the aggregate default uniforms
857
extern const char kDefaultUniformsNameVS[];
858
extern const char kDefaultUniformsNameTCS[];
859
extern const char kDefaultUniformsNameTES[];
860
extern const char kDefaultUniformsNameGS[];
861
extern const char kDefaultUniformsNameFS[];
862
extern const char kDefaultUniformsNameCS[];
863
864
// Interface block and variable names containing driver uniforms
865
extern const char kDriverUniformsBlockName[];
866
extern const char kDriverUniformsVarName[];
867
868
// Interface block array name used for atomic counter emulation
869
extern const char kAtomicCountersBlockName[];
870
871
// Line raster emulation varying
872
extern const char kLineRasterEmulationPosition[];
873
874
// Transform feedback emulation support
875
extern const char kXfbEmulationGetOffsetsFunctionName[];
876
extern const char kXfbEmulationCaptureFunctionName[];
877
extern const char kXfbEmulationBufferBlockName[];
878
extern const char kXfbEmulationBufferName[];
879
extern const char kXfbEmulationBufferFieldName[];
880
881
// Transform feedback extension support
882
extern const char kXfbExtensionPositionOutName[];
883
884
// EXT_shader_framebuffer_fetch and EXT_shader_framebuffer_fetch_non_coherent
885
extern const char kInputAttachmentName[];
886
887
} // namespace vk
888
889
namespace mtl
890
{
891
// Specialization constant to enable GL_SAMPLE_COVERAGE_VALUE emulation.
892
extern const char kCoverageMaskEnabledConstName[];
893
894
// Specialization constant to emulate rasterizer discard.
895
extern const char kRasterizerDiscardEnabledConstName[];
896
} // namespace mtl
897
898
// For backends that use glslang (the Vulkan shader compiler), i.e. Vulkan and Metal, call these to
899
// initialize and finalize glslang itself. This can be called independently from Initialize() and
900
// Finalize().
901
void InitializeGlslang();
902
void FinalizeGlslang();
903
904
} // namespace sh
905
906
#endif // GLSLANG_SHADERLANG_H_
907
908