Path: blob/main_old/include/GLSLANG/ShaderLang.h
1693 views
//1// Copyright 2002 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5#ifndef GLSLANG_SHADERLANG_H_6#define GLSLANG_SHADERLANG_H_78#include <stddef.h>910#include "KHR/khrplatform.h"1112#include <array>13#include <map>14#include <set>15#include <string>16#include <vector>1718//19// This is the platform independent interface between an OGL driver20// and the shading language compiler.21//2223// Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h24#include "ShaderVars.h"2526// Version number for shader translation API.27// It is incremented every time the API changes.28#define ANGLE_SH_VERSION 2662930enum ShShaderSpec31{32SH_GLES2_SPEC,33SH_WEBGL_SPEC,3435SH_GLES3_SPEC,36SH_WEBGL2_SPEC,3738SH_GLES3_1_SPEC,39SH_WEBGL3_SPEC,4041SH_GLES3_2_SPEC,4243SH_GL_CORE_SPEC,44SH_GL_COMPATIBILITY_SPEC,45};4647enum ShShaderOutput48{49// ESSL output only supported in some configurations.50SH_ESSL_OUTPUT = 0x8B45,5152// GLSL output only supported in some configurations.53SH_GLSL_COMPATIBILITY_OUTPUT = 0x8B46,54// Note: GL introduced core profiles in 1.5.55SH_GLSL_130_OUTPUT = 0x8B47,56SH_GLSL_140_OUTPUT = 0x8B80,57SH_GLSL_150_CORE_OUTPUT = 0x8B81,58SH_GLSL_330_CORE_OUTPUT = 0x8B82,59SH_GLSL_400_CORE_OUTPUT = 0x8B83,60SH_GLSL_410_CORE_OUTPUT = 0x8B84,61SH_GLSL_420_CORE_OUTPUT = 0x8B85,62SH_GLSL_430_CORE_OUTPUT = 0x8B86,63SH_GLSL_440_CORE_OUTPUT = 0x8B87,64SH_GLSL_450_CORE_OUTPUT = 0x8B88,6566// Prefer using these to specify HLSL output type:67SH_HLSL_3_0_OUTPUT = 0x8B48, // D3D 968SH_HLSL_4_1_OUTPUT = 0x8B49, // D3D 1169SH_HLSL_4_0_FL9_3_OUTPUT = 0x8B4A, // D3D 11 feature level 9_37071// Output SPIR-V for the Vulkan backend.72SH_SPIRV_VULKAN_OUTPUT = 0x8B4B,7374// Output SPIR-V to be cross compiled to Metal.75SH_SPIRV_METAL_OUTPUT = 0x8B4C,7677// Output for MSL78SH_MSL_METAL_OUTPUT = 0x8B4D,79};8081// Compile options.82// The Compile options type is defined in ShaderVars.h, to allow ANGLE to import the ShaderVars83// header without needing the ShaderLang header. This avoids some conflicts with glslang.8485const ShCompileOptions SH_VALIDATE = 0;86const ShCompileOptions SH_VALIDATE_LOOP_INDEXING = UINT64_C(1) << 0;87const ShCompileOptions SH_INTERMEDIATE_TREE = UINT64_C(1) << 1;88const ShCompileOptions SH_OBJECT_CODE = UINT64_C(1) << 2;89const ShCompileOptions SH_VARIABLES = UINT64_C(1) << 3;90const ShCompileOptions SH_LINE_DIRECTIVES = UINT64_C(1) << 4;91const ShCompileOptions SH_SOURCE_PATH = UINT64_C(1) << 5;9293// If requested, validates the AST after every transformation. Useful for debugging.94const ShCompileOptions SH_VALIDATE_AST = UINT64_C(1) << 6;9596// Due to spec difference between GLSL 4.1 or lower and ESSL3, some platforms (for example, Mac OSX97// core profile) require a variable's "invariant"/"centroid" qualifiers to match between vertex and98// fragment shader. A simple solution to allow such shaders to link is to omit the two qualifiers.99// AMD driver in Linux requires invariant qualifier to match between vertex and fragment shaders,100// while ESSL3 disallows invariant qualifier in fragment shader and GLSL >= 4.2 doesn't require101// invariant qualifier to match between shaders. Remove invariant qualifier from vertex shader to102// workaround AMD driver bug.103// Note that the two flags take effect on ESSL3 input shaders translated to GLSL 4.1 or lower and to104// GLSL 4.2 or newer on Linux AMD.105// TODO(zmo): This is not a good long-term solution. Simply dropping these qualifiers may break some106// developers' content. A more complex workaround of dynamically generating, compiling, and107// re-linking shaders that use these qualifiers should be implemented.108const ShCompileOptions SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3 = UINT64_C(1) << 7;109110// This flag works around bug in Intel Mac drivers related to abs(i) where111// i is an integer.112const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 8;113114// Enforce the GLSL 1.017 Appendix A section 7 packing restrictions.115// This flag only enforces (and can only enforce) the packing116// restrictions for uniform variables in both vertex and fragment117// shaders. ShCheckVariablesWithinPackingLimits() lets embedders118// enforce the packing restrictions for varying variables during119// program link time.120const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 9;121122// This flag ensures all indirect (expression-based) array indexing123// is clamped to the bounds of the array. This ensures, for example,124// that you cannot read off the end of a uniform, whether an array125// vec234, or mat234 type.126const ShCompileOptions SH_CLAMP_INDIRECT_ARRAY_BOUNDS = UINT64_C(1) << 10;127128// This flag limits the complexity of an expression.129const ShCompileOptions SH_LIMIT_EXPRESSION_COMPLEXITY = UINT64_C(1) << 11;130131// This flag limits the depth of the call stack.132const ShCompileOptions SH_LIMIT_CALL_STACK_DEPTH = UINT64_C(1) << 12;133134// This flag initializes gl_Position to vec4(0,0,0,0) at the135// beginning of the vertex shader's main(), and has no effect in the136// fragment shader. It is intended as a workaround for drivers which137// incorrectly fail to link programs if gl_Position is not written.138const ShCompileOptions SH_INIT_GL_POSITION = UINT64_C(1) << 13;139140// This flag replaces141// "a && b" with "a ? b : false",142// "a || b" with "a ? true : b".143// This is to work around a MacOSX driver bug that |b| is executed144// independent of |a|'s value.145const ShCompileOptions SH_UNFOLD_SHORT_CIRCUIT = UINT64_C(1) << 14;146147// This flag initializes output variables to 0 at the beginning of main().148// It is to avoid undefined behaviors.149const ShCompileOptions SH_INIT_OUTPUT_VARIABLES = UINT64_C(1) << 15;150151// This flag scalarizes vec/ivec/bvec/mat constructor args.152// It is intended as a workaround for Linux/Mac driver bugs.153const ShCompileOptions SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS = UINT64_C(1) << 16;154155// This flag overwrites a struct name with a unique prefix.156// It is intended as a workaround for drivers that do not handle157// struct scopes correctly, including all Mac drivers and Linux AMD.158const ShCompileOptions SH_REGENERATE_STRUCT_NAMES = UINT64_C(1) << 17;159160// This flag works around bugs in Mac drivers related to do-while by161// transforming them into an other construct.162const ShCompileOptions SH_REWRITE_DO_WHILE_LOOPS = UINT64_C(1) << 18;163164// This flag works around a bug in the HLSL compiler optimizer that folds certain165// constant pow expressions incorrectly. Only applies to the HLSL back-end. It works166// by expanding the integer pow expressions into a series of multiplies.167const ShCompileOptions SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS = UINT64_C(1) << 19;168169// Flatten "#pragma STDGL invariant(all)" into the declarations of170// varying variables and built-in GLSL variables. This compiler171// option is enabled automatically when needed.172const ShCompileOptions SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL = UINT64_C(1) << 20;173174// Some drivers do not take into account the base level of the texture in the results of the175// HLSL GetDimensions builtin. This flag instructs the compiler to manually add the base level176// offsetting.177const ShCompileOptions SH_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL = UINT64_C(1) << 21;178179// This flag works around an issue in translating GLSL function texelFetchOffset on180// INTEL drivers. It works by translating texelFetchOffset into texelFetch.181const ShCompileOptions SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH = UINT64_C(1) << 22;182183// This flag works around condition bug of for and while loops in Intel Mac OSX drivers.184// Condition calculation is not correct. Rewrite it from "CONDITION" to "CONDITION && true".185const ShCompileOptions SH_ADD_AND_TRUE_TO_LOOP_CONDITION = UINT64_C(1) << 23;186187// This flag works around a bug in evaluating unary minus operator on integer on some INTEL188// drivers. It works by translating -(int) into ~(int) + 1.189const ShCompileOptions SH_REWRITE_INTEGER_UNARY_MINUS_OPERATOR = UINT64_C(1) << 24;190191// This flag works around a bug in evaluating isnan() on some INTEL D3D and Mac OSX drivers.192// It works by using an expression to emulate this function.193const ShCompileOptions SH_EMULATE_ISNAN_FLOAT_FUNCTION = UINT64_C(1) << 25;194195// This flag will use all uniforms of unused std140 and shared uniform blocks at the196// beginning of the vertex/fragment shader's main(). It is intended as a workaround for Mac197// drivers with shader version 4.10. In those drivers, they will treat unused198// std140 and shared uniform blocks' members as inactive. However, WebGL2.0 based on199// OpenGL ES3.0.4 requires all members of a named uniform block declared with a shared or std140200// layout qualifier to be considered active. The uniform block itself is also considered active.201const ShCompileOptions SH_USE_UNUSED_STANDARD_SHARED_BLOCKS = UINT64_C(1) << 26;202203// This flag works around a bug in unary minus operator on float numbers on Intel204// Mac OSX 10.11 drivers. It works by translating -float into 0.0 - float.205const ShCompileOptions SH_REWRITE_FLOAT_UNARY_MINUS_OPERATOR = UINT64_C(1) << 27;206207// This flag works around a bug in evaluating atan(y, x) on some NVIDIA OpenGL drivers.208// It works by using an expression to emulate this function.209const ShCompileOptions SH_EMULATE_ATAN2_FLOAT_FUNCTION = UINT64_C(1) << 28;210211// Set to initialize uninitialized local and global temporary variables. Should only be used with212// GLSL output. In HLSL output variables are initialized regardless of if this flag is set.213const ShCompileOptions SH_INITIALIZE_UNINITIALIZED_LOCALS = UINT64_C(1) << 29;214215// The flag modifies the shader in the following way:216// Every occurrence of gl_InstanceID is replaced by the global temporary variable InstanceID.217// Every occurrence of gl_ViewID_OVR is replaced by the varying variable ViewID_OVR.218// At the beginning of the body of main() in a vertex shader the following initializers are added:219// ViewID_OVR = uint(gl_InstanceID) % num_views;220// InstanceID = gl_InstanceID / num_views;221// ViewID_OVR is added as a varying variable to both the vertex and fragment shaders.222const ShCompileOptions SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW = UINT64_C(1) << 30;223224// With the flag enabled the GLSL/ESSL vertex shader is modified to include code for viewport225// selection in the following way:226// - Code to enable the extension ARB_shader_viewport_layer_array/NV_viewport_array2 is included.227// - Code to select the viewport index or layer is inserted at the beginning of main after228// ViewID_OVR's initialization.229// - A declaration of the uniform multiviewBaseViewLayerIndex.230// Note: The SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW flag also has to be enabled to have the231// temporary variable ViewID_OVR declared and initialized.232const ShCompileOptions SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER = UINT64_C(1) << 31;233234// If the flag is enabled, gl_PointSize is clamped to the maximum point size specified in235// ShBuiltInResources in vertex shaders.236const ShCompileOptions SH_CLAMP_POINT_SIZE = UINT64_C(1) << 32;237238// Bit 33 is available.239240// Don't use loops to initialize uninitialized variables. Only has an effect if some kind of241// variable initialization is turned on.242const ShCompileOptions SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES = UINT64_C(1) << 34;243244// Don't use D3D constant register zero when allocating space for uniforms. This is targeted to work245// around a bug in NVIDIA D3D driver version 388.59 where in very specific cases the driver would246// not handle constant register zero correctly. Only has an effect on HLSL translation.247const ShCompileOptions SH_SKIP_D3D_CONSTANT_REGISTER_ZERO = UINT64_C(1) << 35;248249// Clamp gl_FragDepth to the range [0.0, 1.0] in case it is statically used.250const ShCompileOptions SH_CLAMP_FRAG_DEPTH = UINT64_C(1) << 36;251252// Rewrite expressions like "v.x = z = expression;". Works around a bug in NVIDIA OpenGL drivers253// prior to version 397.31.254const ShCompileOptions SH_REWRITE_REPEATED_ASSIGN_TO_SWIZZLED = UINT64_C(1) << 37;255256// Rewrite gl_DrawID as a uniform int257const ShCompileOptions SH_EMULATE_GL_DRAW_ID = UINT64_C(1) << 38;258259// This flag initializes shared variables to 0.260// It is to avoid ompute shaders being able to read undefined values that could be coming from261// another webpage/application.262const ShCompileOptions SH_INIT_SHARED_VARIABLES = UINT64_C(1) << 39;263264// Forces the value returned from an atomic operations to be always be resolved. This is targeted to265// workaround a bug in NVIDIA D3D driver where the return value from266// RWByteAddressBuffer.InterlockedAdd does not get resolved when used in the .yzw components of a267// RWByteAddressBuffer.Store operation. Only has an effect on HLSL translation.268// http://anglebug.com/3246269const ShCompileOptions SH_FORCE_ATOMIC_VALUE_RESOLUTION = UINT64_C(1) << 40;270271// Rewrite gl_BaseVertex and gl_BaseInstance as uniform int272const ShCompileOptions SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE = UINT64_C(1) << 41;273274// Emulate seamful cube map sampling for OpenGL ES2.0. Currently only applies to the Vulkan275// backend, as is done after samplers are moved out of structs. Can likely be made to work on276// the other backends as well.277const ShCompileOptions SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING = UINT64_C(1) << 42;278279// This flag controls how to translate WEBGL_video_texture sampling function.280const ShCompileOptions SH_TAKE_VIDEO_TEXTURE_AS_EXTERNAL_OES = UINT64_C(1) << 43;281282// This flag works around a inconsistent behavior in Mac AMD driver where gl_VertexID doesn't283// include base vertex value. It replaces gl_VertexID with (gl_VertexID + angle_BaseVertex)284// when angle_BaseVertex is available.285const ShCompileOptions SH_ADD_BASE_VERTEX_TO_VERTEX_ID = UINT64_C(1) << 44;286287// This works around the dynamic lvalue indexing of swizzled vectors on various platforms.288const ShCompileOptions SH_REMOVE_DYNAMIC_INDEXING_OF_SWIZZLED_VECTOR = UINT64_C(1) << 45;289290// This flag works around a slow fxc compile performance issue with dynamic uniform indexing.291const ShCompileOptions SH_ALLOW_TRANSLATE_UNIFORM_BLOCK_TO_STRUCTUREDBUFFER = UINT64_C(1) << 46;292293// This flag indicates whether Bresenham line raster emulation code should be generated. This294// emulation is necessary if the backend uses a differnet algorithm to draw lines. Currently only295// implemented for the Vulkan backend.296const ShCompileOptions SH_ADD_BRESENHAM_LINE_RASTER_EMULATION = UINT64_C(1) << 47;297298// This flag allows disabling ARB_texture_rectangle on a per-compile basis. This is necessary299// for WebGL contexts becuase ARB_texture_rectangle may be necessary for the WebGL implementation300// internally but shouldn't be exposed to WebGL user code.301const ShCompileOptions SH_DISABLE_ARB_TEXTURE_RECTANGLE = UINT64_C(1) << 48;302303// This flag works around a driver bug by rewriting uses of row-major matrices304// as column-major in ESSL 3.00 and greater shaders.305const ShCompileOptions SH_REWRITE_ROW_MAJOR_MATRICES = UINT64_C(1) << 49;306307// Drop any explicit precision qualifiers from shader.308const ShCompileOptions SH_IGNORE_PRECISION_QUALIFIERS = UINT64_C(1) << 50;309310// Allow compiler to do early fragment tests as an optimization.311const ShCompileOptions SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION = UINT64_C(1) << 51;312313// Allow compiler to insert Android pre-rotation code.314const ShCompileOptions SH_ADD_PRE_ROTATION = UINT64_C(1) << 52;315316const ShCompileOptions SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP = UINT64_C(1) << 53;317318// Allow compiler to use specialization constant to do pre-rotation and y flip.319const ShCompileOptions SH_USE_SPECIALIZATION_CONSTANT = UINT64_C(1) << 54;320321// Ask compiler to generate Vulkan transform feedback emulation support code.322const ShCompileOptions SH_ADD_VULKAN_XFB_EMULATION_SUPPORT_CODE = UINT64_C(1) << 55;323324// Ask compiler to generate Vulkan transform feedback support code when using the325// VK_EXT_transform_feedback extension.326const ShCompileOptions SH_ADD_VULKAN_XFB_EXTENSION_SUPPORT_CODE = UINT64_C(1) << 56;327328// This flag initializes fragment shader's output variables to zero at the beginning of the fragment329// shader's main(). It is intended as a workaround for drivers which get context lost if330// gl_FragColor is not written.331const ShCompileOptions SH_INIT_FRAGMENT_OUTPUT_VARIABLES = UINT64_C(1) << 57;332333// Transitory flag to select between producing SPIR-V directly vs using glslang. Ignored in334// non-assert-enabled builds to avoid increasing ANGLE's binary size while both generators coexist.335const ShCompileOptions SH_GENERATE_SPIRV_DIRECTLY = UINT64_C(1) << 58;336337// The 64 bits hash function. The first parameter is the input string; the338// second parameter is the string length.339using ShHashFunction64 = khronos_uint64_t (*)(const char *, size_t);340341//342// Implementation dependent built-in resources (constants and extensions).343// The names for these resources has been obtained by stripping gl_/GL_.344//345struct ShBuiltInResources346{347// Constants.348int MaxVertexAttribs;349int MaxVertexUniformVectors;350int MaxVaryingVectors;351int MaxVertexTextureImageUnits;352int MaxCombinedTextureImageUnits;353int MaxTextureImageUnits;354int MaxFragmentUniformVectors;355int MaxDrawBuffers;356357// Extensions.358// Set to 1 to enable the extension, else 0.359int OES_standard_derivatives;360int OES_EGL_image_external;361int OES_EGL_image_external_essl3;362int NV_EGL_stream_consumer_external;363int ARB_texture_rectangle;364int EXT_blend_func_extended;365int EXT_draw_buffers;366int EXT_frag_depth;367int EXT_shader_texture_lod;368int EXT_shader_framebuffer_fetch;369int EXT_shader_framebuffer_fetch_non_coherent;370int NV_shader_framebuffer_fetch;371int NV_shader_noperspective_interpolation;372int ARM_shader_framebuffer_fetch;373int OVR_multiview;374int OVR_multiview2;375int EXT_multisampled_render_to_texture;376int EXT_multisampled_render_to_texture2;377int EXT_YUV_target;378int EXT_geometry_shader;379int OES_geometry_shader;380int OES_shader_io_blocks;381int EXT_shader_io_blocks;382int EXT_gpu_shader5;383int EXT_shader_non_constant_global_initializers;384int OES_texture_storage_multisample_2d_array;385int OES_texture_3D;386int ANGLE_texture_multisample;387int ANGLE_multi_draw;388int ANGLE_base_vertex_base_instance;389int WEBGL_video_texture;390int APPLE_clip_distance;391int OES_texture_cube_map_array;392int EXT_texture_cube_map_array;393int EXT_shadow_samplers;394int OES_shader_multisample_interpolation;395int OES_shader_image_atomic;396int EXT_tessellation_shader;397int OES_texture_buffer;398int EXT_texture_buffer;399int OES_sample_variables;400int EXT_clip_cull_distance;401int EXT_primitive_bounding_box;402403// Set to 1 to enable replacing GL_EXT_draw_buffers #extension directives404// with GL_NV_draw_buffers in ESSL output. This flag can be used to emulate405// EXT_draw_buffers by using it in combination with GLES3.0 glDrawBuffers406// function. This applies to Tegra K1 devices.407int NV_draw_buffers;408409// Set to 1 if highp precision is supported in the ESSL 1.00 version of the410// fragment language. Does not affect versions of the language where highp411// support is mandatory.412// Default is 0.413int FragmentPrecisionHigh;414415// GLSL ES 3.0 constants.416int MaxVertexOutputVectors;417int MaxFragmentInputVectors;418int MinProgramTexelOffset;419int MaxProgramTexelOffset;420421// Extension constants.422423// Value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT for OpenGL ES output context.424// Value of GL_MAX_DUAL_SOURCE_DRAW_BUFFERS for OpenGL output context.425// GLES SL version 100 gl_MaxDualSourceDrawBuffersEXT value for EXT_blend_func_extended.426int MaxDualSourceDrawBuffers;427428// Value of GL_MAX_VIEWS_OVR.429int MaxViewsOVR;430431// Name Hashing.432// Set a 64 bit hash function to enable user-defined name hashing.433// Default is NULL.434ShHashFunction64 HashFunction;435436// The maximum complexity an expression can be when SH_LIMIT_EXPRESSION_COMPLEXITY is turned on.437int MaxExpressionComplexity;438439// The maximum depth a call stack can be.440int MaxCallStackDepth;441442// The maximum number of parameters a function can have when SH_LIMIT_EXPRESSION_COMPLEXITY is443// turned on.444int MaxFunctionParameters;445446// GLES 3.1 constants447448// texture gather offset constraints.449int MinProgramTextureGatherOffset;450int MaxProgramTextureGatherOffset;451452// maximum number of available image units453int MaxImageUnits;454455// OES_sample_variables constant456// maximum number of available samples457int MaxSamples;458459// maximum number of image uniforms in a vertex shader460int MaxVertexImageUniforms;461462// maximum number of image uniforms in a fragment shader463int MaxFragmentImageUniforms;464465// maximum number of image uniforms in a compute shader466int MaxComputeImageUniforms;467468// maximum total number of image uniforms in a program469int MaxCombinedImageUniforms;470471// maximum number of uniform locations472int MaxUniformLocations;473474// maximum number of ssbos and images in a shader475int MaxCombinedShaderOutputResources;476477// maximum number of groups in each dimension478std::array<int, 3> MaxComputeWorkGroupCount;479// maximum number of threads per work group in each dimension480std::array<int, 3> MaxComputeWorkGroupSize;481482// maximum number of total uniform components483int MaxComputeUniformComponents;484485// maximum number of texture image units in a compute shader486int MaxComputeTextureImageUnits;487488// maximum number of atomic counters in a compute shader489int MaxComputeAtomicCounters;490491// maximum number of atomic counter buffers in a compute shader492int MaxComputeAtomicCounterBuffers;493494// maximum number of atomic counters in a vertex shader495int MaxVertexAtomicCounters;496497// maximum number of atomic counters in a fragment shader498int MaxFragmentAtomicCounters;499500// maximum number of atomic counters in a program501int MaxCombinedAtomicCounters;502503// maximum binding for an atomic counter504int MaxAtomicCounterBindings;505506// maximum number of atomic counter buffers in a vertex shader507int MaxVertexAtomicCounterBuffers;508509// maximum number of atomic counter buffers in a fragment shader510int MaxFragmentAtomicCounterBuffers;511512// maximum number of atomic counter buffers in a program513int MaxCombinedAtomicCounterBuffers;514515// maximum number of buffer object storage in machine units516int MaxAtomicCounterBufferSize;517518// maximum number of uniform block bindings519int MaxUniformBufferBindings;520521// maximum number of shader storage buffer bindings522int MaxShaderStorageBufferBindings;523524// maximum point size (higher limit from ALIASED_POINT_SIZE_RANGE)525float MaxPointSize;526527// EXT_geometry_shader constants528int MaxGeometryUniformComponents;529int MaxGeometryUniformBlocks;530int MaxGeometryInputComponents;531int MaxGeometryOutputComponents;532int MaxGeometryOutputVertices;533int MaxGeometryTotalOutputComponents;534int MaxGeometryTextureImageUnits;535int MaxGeometryAtomicCounterBuffers;536int MaxGeometryAtomicCounters;537int MaxGeometryShaderStorageBlocks;538int MaxGeometryShaderInvocations;539int MaxGeometryImageUniforms;540541// EXT_tessellation_shader constants542int MaxTessControlInputComponents;543int MaxTessControlOutputComponents;544int MaxTessControlTextureImageUnits;545int MaxTessControlUniformComponents;546int MaxTessControlTotalOutputComponents;547int MaxTessControlImageUniforms;548int MaxTessControlAtomicCounters;549int MaxTessControlAtomicCounterBuffers;550551int MaxTessPatchComponents;552int MaxPatchVertices;553int MaxTessGenLevel;554555int MaxTessEvaluationInputComponents;556int MaxTessEvaluationOutputComponents;557int MaxTessEvaluationTextureImageUnits;558int MaxTessEvaluationUniformComponents;559int MaxTessEvaluationImageUniforms;560int MaxTessEvaluationAtomicCounters;561int MaxTessEvaluationAtomicCounterBuffers;562563// Subpixel bits used in rasterization.564int SubPixelBits;565566// APPLE_clip_distance/EXT_clip_cull_distance constant567int MaxClipDistances;568int MaxCullDistances;569int MaxCombinedClipAndCullDistances;570571// Direct-to-metal backend constants:572573// Binding index for driver uniforms:574int DriverUniformsBindingIndex;575// Binding index for default uniforms:576int DefaultUniformsBindingIndex;577// Binding index for UBO's argument buffer578int UBOArgumentBufferBindingIndex;579};580581//582// ShHandle held by but opaque to the driver. It is allocated,583// managed, and de-allocated by the compiler. Its contents584// are defined by and used by the compiler.585//586// If handle creation fails, 0 will be returned.587//588using ShHandle = void *;589590namespace sh591{592using BinaryBlob = std::vector<uint32_t>;593594//595// Driver must call this first, once, before doing any other compiler operations.596// If the function succeeds, the return value is true, else false.597//598bool Initialize();599//600// Driver should call this at shutdown.601// If the function succeeds, the return value is true, else false.602//603bool Finalize();604605//606// Initialize built-in resources with minimum expected values.607// Parameters:608// resources: The object to initialize. Will be comparable with memcmp.609//610void InitBuiltInResources(ShBuiltInResources *resources);611612//613// Returns the a concatenated list of the items in ShBuiltInResources as a null-terminated string.614// This function must be updated whenever ShBuiltInResources is changed.615// Parameters:616// handle: Specifies the handle of the compiler to be used.617const std::string &GetBuiltInResourcesString(const ShHandle handle);618619//620// Driver calls these to create and destroy compiler objects.621//622// Returns the handle of constructed compiler, null if the requested compiler is not supported.623// Parameters:624// type: Specifies the type of shader - GL_FRAGMENT_SHADER or GL_VERTEX_SHADER.625// spec: Specifies the language spec the compiler must conform to - SH_GLES2_SPEC or SH_WEBGL_SPEC.626// output: Specifies the output code type - for example SH_ESSL_OUTPUT, SH_GLSL_OUTPUT,627// SH_HLSL_3_0_OUTPUT or SH_HLSL_4_1_OUTPUT. Note: Each output type may only628// be supported in some configurations.629// resources: Specifies the built-in resources.630ShHandle ConstructCompiler(sh::GLenum type,631ShShaderSpec spec,632ShShaderOutput output,633const ShBuiltInResources *resources);634void Destruct(ShHandle handle);635636//637// Compiles the given shader source.638// If the function succeeds, the return value is true, else false.639// Parameters:640// handle: Specifies the handle of compiler to be used.641// shaderStrings: Specifies an array of pointers to null-terminated strings containing the shader642// source code.643// numStrings: Specifies the number of elements in shaderStrings array.644// compileOptions: A mask containing the following parameters:645// SH_VALIDATE: Validates shader to ensure that it conforms to the spec646// specified during compiler construction.647// SH_VALIDATE_LOOP_INDEXING: Validates loop and indexing in the shader to648// ensure that they do not exceed the minimum649// functionality mandated in GLSL 1.0 spec,650// Appendix A, Section 4 and 5.651// There is no need to specify this parameter when652// compiling for WebGL - it is implied.653// SH_INTERMEDIATE_TREE: Writes intermediate tree to info log.654// Can be queried by calling sh::GetInfoLog().655// SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader, or SPIR-V binary.656// Can be queried by calling sh::GetObjectCode().657// SH_VARIABLES: Extracts attributes, uniforms, and varyings.658// Can be queried by calling ShGetVariableInfo().659//660bool Compile(const ShHandle handle,661const char *const shaderStrings[],662size_t numStrings,663ShCompileOptions compileOptions);664665// Clears the results from the previous compilation.666void ClearResults(const ShHandle handle);667668// Return the version of the shader language.669int GetShaderVersion(const ShHandle handle);670671// Return the currently set language output type.672ShShaderOutput GetShaderOutputType(const ShHandle handle);673674// Returns null-terminated information log for a compiled shader.675// Parameters:676// handle: Specifies the compiler677const std::string &GetInfoLog(const ShHandle handle);678679// Returns null-terminated object code for a compiled shader. Only valid for output types that680// generate human-readable code (GLSL, ESSL or HLSL).681// Parameters:682// handle: Specifies the compiler683const std::string &GetObjectCode(const ShHandle handle);684685// Returns object binary blob for a compiled shader. Only valid for output types that686// generate binary blob (SPIR-V).687// Parameters:688// handle: Specifies the compiler689const BinaryBlob &GetObjectBinaryBlob(const ShHandle handle);690691// Returns a (original_name, hash) map containing all the user defined names in the shader,692// including variable names, function names, struct names, and struct field names.693// Parameters:694// handle: Specifies the compiler695const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle);696697// Shader variable inspection.698// Returns a pointer to a list of variables of the designated type.699// (See ShaderVars.h for type definitions, included above)700// Returns NULL on failure.701// Parameters:702// handle: Specifies the compiler703const std::vector<sh::ShaderVariable> *GetUniforms(const ShHandle handle);704const std::vector<sh::ShaderVariable> *GetVaryings(const ShHandle handle);705const std::vector<sh::ShaderVariable> *GetInputVaryings(const ShHandle handle);706const std::vector<sh::ShaderVariable> *GetOutputVaryings(const ShHandle handle);707const std::vector<sh::ShaderVariable> *GetAttributes(const ShHandle handle);708const std::vector<sh::ShaderVariable> *GetOutputVariables(const ShHandle handle);709const std::vector<sh::InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle);710const std::vector<sh::InterfaceBlock> *GetUniformBlocks(const ShHandle handle);711const std::vector<sh::InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle);712sh::WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle);713// Returns the number of views specified through the num_views layout qualifier. If num_views is714// not set, the function returns -1.715int GetVertexShaderNumViews(const ShHandle handle);716// Returns true if compiler has injected instructions for early fragment tests as an optimization717bool HasEarlyFragmentTestsOptimization(const ShHandle handle);718719// Returns specialization constant usage bits720uint32_t GetShaderSpecConstUsageBits(const ShHandle handle);721722// Returns true if the passed in variables pack in maxVectors followingthe packing rules from the723// GLSL 1.017 spec, Appendix A, section 7.724// Returns false otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS725// flag above.726// Parameters:727// maxVectors: the available rows of registers.728// variables: an array of variables.729bool CheckVariablesWithinPackingLimits(int maxVectors,730const std::vector<sh::ShaderVariable> &variables);731732// Gives the compiler-assigned register for a shader storage block.733// The method writes the value to the output variable "indexOut".734// Returns true if it found a valid shader storage block, false otherwise.735// Parameters:736// handle: Specifies the compiler737// shaderStorageBlockName: Specifies the shader storage block738// indexOut: output variable that stores the assigned register739bool GetShaderStorageBlockRegister(const ShHandle handle,740const std::string &shaderStorageBlockName,741unsigned int *indexOut);742743// Gives the compiler-assigned register for a uniform block.744// The method writes the value to the output variable "indexOut".745// Returns true if it found a valid uniform block, false otherwise.746// Parameters:747// handle: Specifies the compiler748// uniformBlockName: Specifies the uniform block749// indexOut: output variable that stores the assigned register750bool GetUniformBlockRegister(const ShHandle handle,751const std::string &uniformBlockName,752unsigned int *indexOut);753754bool ShouldUniformBlockUseStructuredBuffer(const ShHandle handle,755const std::string &uniformBlockName);756const std::set<std::string> *GetSlowCompilingUniformBlockSet(const ShHandle handle);757758// Gives a map from uniform names to compiler-assigned registers in the default uniform block.759// Note that the map contains also registers of samplers that have been extracted from structs.760const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle);761762// Sampler, image and atomic counters share registers(t type and u type),763// GetReadonlyImage2DRegisterIndex and GetImage2DRegisterIndex return the first index into764// a range of reserved registers for image2D/iimage2D/uimage2D variables.765// Parameters: handle: Specifies the compiler766unsigned int GetReadonlyImage2DRegisterIndex(const ShHandle handle);767unsigned int GetImage2DRegisterIndex(const ShHandle handle);768769// The method records these used function names related with image2D/iimage2D/uimage2D, these770// functions will be dynamically generated.771// Parameters:772// handle: Specifies the compiler773const std::set<std::string> *GetUsedImage2DFunctionNames(const ShHandle handle);774775bool HasValidGeometryShaderInputPrimitiveType(const ShHandle handle);776bool HasValidGeometryShaderOutputPrimitiveType(const ShHandle handle);777bool HasValidGeometryShaderMaxVertices(const ShHandle handle);778bool HasValidTessGenMode(const ShHandle handle);779bool HasValidTessGenSpacing(const ShHandle handle);780bool HasValidTessGenVertexOrder(const ShHandle handle);781bool HasValidTessGenPointMode(const ShHandle handle);782GLenum GetGeometryShaderInputPrimitiveType(const ShHandle handle);783GLenum GetGeometryShaderOutputPrimitiveType(const ShHandle handle);784int GetGeometryShaderInvocations(const ShHandle handle);785int GetGeometryShaderMaxVertices(const ShHandle handle);786unsigned int GetShaderSharedMemorySize(const ShHandle handle);787int GetTessControlShaderVertices(const ShHandle handle);788GLenum GetTessGenMode(const ShHandle handle);789GLenum GetTessGenSpacing(const ShHandle handle);790GLenum GetTessGenVertexOrder(const ShHandle handle);791GLenum GetTessGenPointMode(const ShHandle handle);792793//794// Helper function to identify specs that are based on the WebGL spec.795//796inline bool IsWebGLBasedSpec(ShShaderSpec spec)797{798return (spec == SH_WEBGL_SPEC || spec == SH_WEBGL2_SPEC || spec == SH_WEBGL3_SPEC);799}800801//802// Helper function to identify DesktopGL specs803//804inline bool IsDesktopGLSpec(ShShaderSpec spec)805{806return spec == SH_GL_CORE_SPEC || spec == SH_GL_COMPATIBILITY_SPEC;807}808809// Can't prefix with just _ because then we might introduce a double underscore, which is not safe810// in GLSL (ESSL 3.00.6 section 3.8: All identifiers containing a double underscore are reserved for811// use by the underlying implementation). u is short for user-defined.812extern const char kUserDefinedNamePrefix[];813814namespace vk815{816817// Specialization constant ids818enum class SpecializationConstantId : uint32_t819{820LineRasterEmulation = 0,821SurfaceRotation = 1,822DrawableWidth = 2,823DrawableHeight = 3,824825InvalidEnum = 4,826EnumCount = InvalidEnum,827};828829enum class SurfaceRotation : uint32_t830{831Identity,832Rotated90Degrees,833Rotated180Degrees,834Rotated270Degrees,835FlippedIdentity,836FlippedRotated90Degrees,837FlippedRotated180Degrees,838FlippedRotated270Degrees,839840InvalidEnum,841EnumCount = InvalidEnum,842};843844enum class SpecConstUsage : uint32_t845{846LineRasterEmulation = 0,847YFlip = 1,848Rotation = 2,849DrawableSize = 3,850851InvalidEnum = 4,852EnumCount = InvalidEnum,853};854855// Interface block name containing the aggregate default uniforms856extern const char kDefaultUniformsNameVS[];857extern const char kDefaultUniformsNameTCS[];858extern const char kDefaultUniformsNameTES[];859extern const char kDefaultUniformsNameGS[];860extern const char kDefaultUniformsNameFS[];861extern const char kDefaultUniformsNameCS[];862863// Interface block and variable names containing driver uniforms864extern const char kDriverUniformsBlockName[];865extern const char kDriverUniformsVarName[];866867// Interface block array name used for atomic counter emulation868extern const char kAtomicCountersBlockName[];869870// Line raster emulation varying871extern const char kLineRasterEmulationPosition[];872873// Transform feedback emulation support874extern const char kXfbEmulationGetOffsetsFunctionName[];875extern const char kXfbEmulationCaptureFunctionName[];876extern const char kXfbEmulationBufferBlockName[];877extern const char kXfbEmulationBufferName[];878extern const char kXfbEmulationBufferFieldName[];879880// Transform feedback extension support881extern const char kXfbExtensionPositionOutName[];882883// EXT_shader_framebuffer_fetch and EXT_shader_framebuffer_fetch_non_coherent884extern const char kInputAttachmentName[];885886} // namespace vk887888namespace mtl889{890// Specialization constant to enable GL_SAMPLE_COVERAGE_VALUE emulation.891extern const char kCoverageMaskEnabledConstName[];892893// Specialization constant to emulate rasterizer discard.894extern const char kRasterizerDiscardEnabledConstName[];895} // namespace mtl896897// For backends that use glslang (the Vulkan shader compiler), i.e. Vulkan and Metal, call these to898// initialize and finalize glslang itself. This can be called independently from Initialize() and899// Finalize().900void InitializeGlslang();901void FinalizeGlslang();902903} // namespace sh904905#endif // GLSLANG_SHADERLANG_H_906907908