diff options
author | Miguel Costa <miguel.costa@qt.io> | 2018-06-26 16:56:45 +0200 |
---|---|---|
committer | Andre de la Rocha <andre.rocha@qt.io> | 2018-10-13 21:36:35 +0000 |
commit | 0a7aebadfbb3534284546aa3ca8612314c08f136 (patch) | |
tree | e94ee33ae3bb9b96fc3047c6455d47ac4920bfbf /src/3rdparty/angle/include/GLSLANG | |
parent | 656e89f875ad2008ca16cc673b687a22daa294c9 (diff) |
Update ANGLE to chromium/3280
Change-Id: I0802c0d7486f772d361f87a544d6c5af937f4ca1
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/3rdparty/angle/include/GLSLANG')
-rw-r--r-- | src/3rdparty/angle/include/GLSLANG/ShaderLang.h | 667 | ||||
-rw-r--r-- | src/3rdparty/angle/include/GLSLANG/ShaderVars.h | 161 |
2 files changed, 534 insertions, 294 deletions
diff --git a/src/3rdparty/angle/include/GLSLANG/ShaderLang.h b/src/3rdparty/angle/include/GLSLANG/ShaderLang.h index d02723e760..1468bb1464 100644 --- a/src/3rdparty/angle/include/GLSLANG/ShaderLang.h +++ b/src/3rdparty/angle/include/GLSLANG/ShaderLang.h @@ -6,27 +6,11 @@ #ifndef GLSLANG_SHADERLANG_H_ #define GLSLANG_SHADERLANG_H_ -#if defined(COMPONENT_BUILD) && !defined(ANGLE_TRANSLATOR_STATIC) -#if defined(_WIN32) || defined(_WIN64) - -#if defined(ANGLE_TRANSLATOR_IMPLEMENTATION) -#define COMPILER_EXPORT __declspec(dllexport) -#else -#define COMPILER_EXPORT __declspec(dllimport) -#endif // defined(ANGLE_TRANSLATOR_IMPLEMENTATION) - -#else // defined(_WIN32) || defined(_WIN64) -#define COMPILER_EXPORT __attribute__((visibility("default"))) -#endif - -#else // defined(COMPONENT_BUILD) && !defined(ANGLE_TRANSLATOR_STATIC) -#define COMPILER_EXPORT -#endif - #include <stddef.h> #include "KHR/khrplatform.h" +#include <array> #include <map> #include <string> #include <vector> @@ -36,51 +20,26 @@ // and the shading language compiler. // -namespace sh -{ -// GLenum alias -typedef unsigned int GLenum; -} - -// Must be included after GLenum proxy typedef // Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h #include "ShaderVars.h" // Version number for shader translation API. // It is incremented every time the API changes. -#define ANGLE_SH_VERSION 143 - -typedef enum { - SH_GLES2_SPEC = 0x8B40, - SH_WEBGL_SPEC = 0x8B41, - - SH_GLES3_SPEC = 0x8B86, - SH_WEBGL2_SPEC = 0x8B87, - - // The CSS Shaders spec is a subset of the WebGL spec. - // - // In both CSS vertex and fragment shaders, ANGLE: - // (1) Reserves the "css_" prefix. - // (2) Renames the main function to css_main. - // (3) Disables the gl_MaxDrawBuffers built-in. - // - // In CSS fragment shaders, ANGLE: - // (1) Disables the gl_FragColor built-in. - // (2) Disables the gl_FragData built-in. - // (3) Enables the css_MixColor built-in. - // (4) Enables the css_ColorMatrix built-in. - // - // After passing a CSS shader through ANGLE, the browser is expected to append - // a new main function to it. - // This new main function will call the css_main function. - // It may also perform additional operations like varying assignment, texture - // access, and gl_FragColor assignment in order to implement the CSS Shaders - // blend modes. - // - SH_CSS_SHADERS_SPEC = 0x8B42 -} ShShaderSpec; - -typedef enum +#define ANGLE_SH_VERSION 190 + +enum ShShaderSpec +{ + SH_GLES2_SPEC, + SH_WEBGL_SPEC, + + SH_GLES3_SPEC, + SH_WEBGL2_SPEC, + + SH_GLES3_1_SPEC, + SH_WEBGL3_SPEC, +}; + +enum ShShaderOutput { // ESSL output only supported in some configurations. SH_ESSL_OUTPUT = 0x8B45, @@ -99,147 +58,224 @@ typedef enum SH_GLSL_440_CORE_OUTPUT = 0x8B87, SH_GLSL_450_CORE_OUTPUT = 0x8B88, - // HLSL output only supported in some configurations. - // Deprecated: - SH_HLSL_OUTPUT = 0x8B48, - SH_HLSL9_OUTPUT = 0x8B48, - SH_HLSL11_OUTPUT = 0x8B49, - // Prefer using these to specify HLSL output type: SH_HLSL_3_0_OUTPUT = 0x8B48, // D3D 9 SH_HLSL_4_1_OUTPUT = 0x8B49, // D3D 11 - SH_HLSL_4_0_FL9_3_OUTPUT = 0x8B4A // D3D 11 feature level 9_3 -} ShShaderOutput; + SH_HLSL_4_0_FL9_3_OUTPUT = 0x8B4A, // D3D 11 feature level 9_3 + + // Output specialized GLSL to be fed to glslang for Vulkan SPIR. + SH_GLSL_VULKAN_OUTPUT = 0x8B4B, +}; // Compile options. -typedef enum { - SH_VALIDATE = 0, - SH_VALIDATE_LOOP_INDEXING = 0x0001, - SH_INTERMEDIATE_TREE = 0x0002, - SH_OBJECT_CODE = 0x0004, - SH_VARIABLES = 0x0008, - SH_LINE_DIRECTIVES = 0x0010, - SH_SOURCE_PATH = 0x0020, - SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX = 0x0040, - // If a sampler array index happens to be a loop index, - // 1) if its type is integer, unroll the loop. - // 2) if its type is float, fail the shader compile. - // This is to work around a mac driver bug. - SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX = 0x0080, - - // This is needed only as a workaround for certain OpenGL driver bugs. - SH_EMULATE_BUILT_IN_FUNCTIONS = 0x0100, - - // This is an experimental flag to enforce restrictions that aim to prevent - // timing attacks. - // It generates compilation errors for shaders that could expose sensitive - // texture information via the timing channel. - // To use this flag, you must compile the shader under the WebGL spec - // (using the SH_WEBGL_SPEC flag). - SH_TIMING_RESTRICTIONS = 0x0200, - - // This flag prints the dependency graph that is used to enforce timing - // restrictions on fragment shaders. - // This flag only has an effect if all of the following are true: - // - The shader spec is SH_WEBGL_SPEC. - // - The compile options contain the SH_TIMING_RESTRICTIONS flag. - // - The shader type is GL_FRAGMENT_SHADER. - SH_DEPENDENCY_GRAPH = 0x0400, - - // Enforce the GLSL 1.017 Appendix A section 7 packing restrictions. - // This flag only enforces (and can only enforce) the packing - // restrictions for uniform variables in both vertex and fragment - // shaders. ShCheckVariablesWithinPackingLimits() lets embedders - // enforce the packing restrictions for varying variables during - // program link time. - SH_ENFORCE_PACKING_RESTRICTIONS = 0x0800, - - // This flag ensures all indirect (expression-based) array indexing - // is clamped to the bounds of the array. This ensures, for example, - // that you cannot read off the end of a uniform, whether an array - // vec234, or mat234 type. The ShArrayIndexClampingStrategy enum, - // specified in the ShBuiltInResources when constructing the - // compiler, selects the strategy for the clamping implementation. - SH_CLAMP_INDIRECT_ARRAY_BOUNDS = 0x1000, - - // This flag limits the complexity of an expression. - SH_LIMIT_EXPRESSION_COMPLEXITY = 0x2000, - - // This flag limits the depth of the call stack. - SH_LIMIT_CALL_STACK_DEPTH = 0x4000, - - // This flag initializes gl_Position to vec4(0,0,0,0) at the - // beginning of the vertex shader's main(), and has no effect in the - // fragment shader. It is intended as a workaround for drivers which - // incorrectly fail to link programs if gl_Position is not written. - SH_INIT_GL_POSITION = 0x8000, - - // This flag replaces - // "a && b" with "a ? b : false", - // "a || b" with "a ? true : b". - // This is to work around a MacOSX driver bug that |b| is executed - // independent of |a|'s value. - SH_UNFOLD_SHORT_CIRCUIT = 0x10000, - - // This flag initializes varyings without static use in vertex shader - // at the beginning of main(), and has no effects in the fragment shader. - // It is intended as a workaround for drivers which incorrectly optimize - // out such varyings and cause a link failure. - SH_INIT_VARYINGS_WITHOUT_STATIC_USE = 0x20000, - - // This flag scalarizes vec/ivec/bvec/mat constructor args. - // It is intended as a workaround for Linux/Mac driver bugs. - SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS = 0x40000, - - // This flag overwrites a struct name with a unique prefix. - // It is intended as a workaround for drivers that do not handle - // struct scopes correctly, including all Mac drivers and Linux AMD. - SH_REGENERATE_STRUCT_NAMES = 0x80000, - - // This flag makes the compiler not prune unused function early in the - // compilation process. Pruning coupled with SH_LIMIT_CALL_STACK_DEPTH - // helps avoid bad shaders causing stack overflows. - SH_DONT_PRUNE_UNUSED_FUNCTIONS = 0x100000, - - // This flag works around a bug in NVIDIA 331 series drivers related - // to pow(x, y) where y is a constant vector. - SH_REMOVE_POW_WITH_CONSTANT_EXPONENT = 0x200000, - - // This flag works around bugs in Mac drivers related to do-while by - // transforming them into an other construct. - SH_REWRITE_DO_WHILE_LOOPS = 0x400000, -} ShCompileOptions; +// The Compile options type is defined in ShaderVars.h, to allow ANGLE to import the ShaderVars +// header without needing the ShaderLang header. This avoids some conflicts with glslang. + +const ShCompileOptions SH_VALIDATE = 0; +const ShCompileOptions SH_VALIDATE_LOOP_INDEXING = UINT64_C(1) << 0; +const ShCompileOptions SH_INTERMEDIATE_TREE = UINT64_C(1) << 1; +const ShCompileOptions SH_OBJECT_CODE = UINT64_C(1) << 2; +const ShCompileOptions SH_VARIABLES = UINT64_C(1) << 3; +const ShCompileOptions SH_LINE_DIRECTIVES = UINT64_C(1) << 4; +const ShCompileOptions SH_SOURCE_PATH = UINT64_C(1) << 5; + +// This flag will keep invariant declaration for input in fragment shader for GLSL >=4.20 on AMD. +// From GLSL >= 4.20, it's optional to add invariant for fragment input, but GPU vendors have +// different implementations about this. Some drivers forbid invariant in fragment for GLSL>= 4.20, +// e.g. Linux Mesa, some drivers treat that as optional, e.g. NVIDIA, some drivers require invariant +// must match between vertex and fragment shader, e.g. AMD. The behavior on AMD is obviously wrong. +// Remove invariant for input in fragment shader to workaround the restriction on Intel Mesa. +// But don't remove on AMD Linux to avoid triggering the bug on AMD. +const ShCompileOptions SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT = UINT64_C(1) << 6; + +// Due to spec difference between GLSL 4.1 or lower and ESSL3, some platforms (for example, Mac OSX +// core profile) require a variable's "invariant"/"centroid" qualifiers to match between vertex and +// fragment shader. A simple solution to allow such shaders to link is to omit the two qualifiers. +// AMD driver in Linux requires invariant qualifier to match between vertex and fragment shaders, +// while ESSL3 disallows invariant qualifier in fragment shader and GLSL >= 4.2 doesn't require +// invariant qualifier to match between shaders. Remove invariant qualifier from vertex shader to +// workaround AMD driver bug. +// Note that the two flags take effect on ESSL3 input shaders translated to GLSL 4.1 or lower and to +// GLSL 4.2 or newer on Linux AMD. +// TODO(zmo): This is not a good long-term solution. Simply dropping these qualifiers may break some +// developers' content. A more complex workaround of dynamically generating, compiling, and +// re-linking shaders that use these qualifiers should be implemented. +const ShCompileOptions SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3 = UINT64_C(1) << 7; + +// This flag works around bug in Intel Mac drivers related to abs(i) where +// i is an integer. +const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 8; + +// Enforce the GLSL 1.017 Appendix A section 7 packing restrictions. +// This flag only enforces (and can only enforce) the packing +// restrictions for uniform variables in both vertex and fragment +// shaders. ShCheckVariablesWithinPackingLimits() lets embedders +// enforce the packing restrictions for varying variables during +// program link time. +const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 9; + +// This flag ensures all indirect (expression-based) array indexing +// is clamped to the bounds of the array. This ensures, for example, +// that you cannot read off the end of a uniform, whether an array +// vec234, or mat234 type. The ShArrayIndexClampingStrategy enum, +// specified in the ShBuiltInResources when constructing the +// compiler, selects the strategy for the clamping implementation. +const ShCompileOptions SH_CLAMP_INDIRECT_ARRAY_BOUNDS = UINT64_C(1) << 10; + +// This flag limits the complexity of an expression. +const ShCompileOptions SH_LIMIT_EXPRESSION_COMPLEXITY = UINT64_C(1) << 11; + +// This flag limits the depth of the call stack. +const ShCompileOptions SH_LIMIT_CALL_STACK_DEPTH = UINT64_C(1) << 12; + +// This flag initializes gl_Position to vec4(0,0,0,0) at the +// beginning of the vertex shader's main(), and has no effect in the +// fragment shader. It is intended as a workaround for drivers which +// incorrectly fail to link programs if gl_Position is not written. +const ShCompileOptions SH_INIT_GL_POSITION = UINT64_C(1) << 13; + +// This flag replaces +// "a && b" with "a ? b : false", +// "a || b" with "a ? true : b". +// This is to work around a MacOSX driver bug that |b| is executed +// independent of |a|'s value. +const ShCompileOptions SH_UNFOLD_SHORT_CIRCUIT = UINT64_C(1) << 14; + +// This flag initializes output variables to 0 at the beginning of main(). +// It is to avoid undefined behaviors. +const ShCompileOptions SH_INIT_OUTPUT_VARIABLES = UINT64_C(1) << 15; + +// This flag scalarizes vec/ivec/bvec/mat constructor args. +// It is intended as a workaround for Linux/Mac driver bugs. +const ShCompileOptions SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS = UINT64_C(1) << 16; + +// This flag overwrites a struct name with a unique prefix. +// It is intended as a workaround for drivers that do not handle +// struct scopes correctly, including all Mac drivers and Linux AMD. +const ShCompileOptions SH_REGENERATE_STRUCT_NAMES = UINT64_C(1) << 17; + +// This flag makes the compiler not prune unused function early in the +// compilation process. Pruning coupled with SH_LIMIT_CALL_STACK_DEPTH +// helps avoid bad shaders causing stack overflows. +const ShCompileOptions SH_DONT_PRUNE_UNUSED_FUNCTIONS = UINT64_C(1) << 18; + +// This flag works around a bug in NVIDIA 331 series drivers related +// to pow(x, y) where y is a constant vector. +const ShCompileOptions SH_REMOVE_POW_WITH_CONSTANT_EXPONENT = UINT64_C(1) << 19; + +// This flag works around bugs in Mac drivers related to do-while by +// transforming them into an other construct. +const ShCompileOptions SH_REWRITE_DO_WHILE_LOOPS = UINT64_C(1) << 20; + +// This flag works around a bug in the HLSL compiler optimizer that folds certain +// constant pow expressions incorrectly. Only applies to the HLSL back-end. It works +// by expanding the integer pow expressions into a series of multiplies. +const ShCompileOptions SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS = UINT64_C(1) << 21; + +// Flatten "#pragma STDGL invariant(all)" into the declarations of +// varying variables and built-in GLSL variables. This compiler +// option is enabled automatically when needed. +const ShCompileOptions SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL = UINT64_C(1) << 22; + +// Some drivers do not take into account the base level of the texture in the results of the +// HLSL GetDimensions builtin. This flag instructs the compiler to manually add the base level +// offsetting. +const ShCompileOptions SH_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL = UINT64_C(1) << 23; + +// This flag works around an issue in translating GLSL function texelFetchOffset on +// INTEL drivers. It works by translating texelFetchOffset into texelFetch. +const ShCompileOptions SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH = UINT64_C(1) << 24; + +// This flag works around condition bug of for and while loops in Intel Mac OSX drivers. +// Condition calculation is not correct. Rewrite it from "CONDITION" to "CONDITION && true". +const ShCompileOptions SH_ADD_AND_TRUE_TO_LOOP_CONDITION = UINT64_C(1) << 25; + +// This flag works around a bug in evaluating unary minus operator on integer on some INTEL +// drivers. It works by translating -(int) into ~(int) + 1. +const ShCompileOptions SH_REWRITE_INTEGER_UNARY_MINUS_OPERATOR = UINT64_C(1) << 26; + +// This flag works around a bug in evaluating isnan() on some INTEL D3D and Mac OSX drivers. +// It works by using an expression to emulate this function. +const ShCompileOptions SH_EMULATE_ISNAN_FLOAT_FUNCTION = UINT64_C(1) << 27; + +// This flag will use all uniforms of unused std140 and shared uniform blocks at the +// beginning of the vertex/fragment shader's main(). It is intended as a workaround for Mac +// drivers with shader version 4.10. In those drivers, they will treat unused +// std140 and shared uniform blocks' members as inactive. However, WebGL2.0 based on +// OpenGL ES3.0.4 requires all members of a named uniform block declared with a shared or std140 +// layout qualifier to be considered active. The uniform block itself is also considered active. +const ShCompileOptions SH_USE_UNUSED_STANDARD_SHARED_BLOCKS = UINT64_C(1) << 28; + +// This flag works around a bug in unary minus operator on float numbers on Intel +// Mac OSX 10.11 drivers. It works by translating -float into 0.0 - float. +const ShCompileOptions SH_REWRITE_FLOAT_UNARY_MINUS_OPERATOR = UINT64_C(1) << 29; + +// This flag works around a bug in evaluating atan(y, x) on some NVIDIA OpenGL drivers. +// It works by using an expression to emulate this function. +const ShCompileOptions SH_EMULATE_ATAN2_FLOAT_FUNCTION = UINT64_C(1) << 30; + +// Set to 1 to translate gl_ViewID_OVR to an uniform so that the extension can be emulated. +// "uniform highp uint ViewID_OVR". +const ShCompileOptions SH_TRANSLATE_VIEWID_OVR_TO_UNIFORM = UINT64_C(1) << 31; + +// Set to initialize uninitialized local and global temporary variables. Should only be used with +// GLSL output. In HLSL output variables are initialized regardless of if this flag is set. +const ShCompileOptions SH_INITIALIZE_UNINITIALIZED_LOCALS = UINT64_C(1) << 32; + +// The flag modifies the shader in the following way: +// Every occurrence of gl_InstanceID is replaced by the global temporary variable InstanceID. +// Every occurrence of gl_ViewID_OVR is replaced by the varying variable ViewID_OVR. +// At the beginning of the body of main() in a vertex shader the following initializers are added: +// ViewID_OVR = uint(gl_InstanceID) % num_views; +// InstanceID = gl_InstanceID / num_views; +// ViewID_OVR is added as a varying variable to both the vertex and fragment shaders. +const ShCompileOptions SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW = UINT64_C(1) << 33; + +// With the flag enabled the GLSL/ESSL vertex shader is modified to include code for viewport +// selection in the following way: +// - Code to enable the extension NV_viewport_array2 is included. +// - Code to select the viewport index or layer is inserted at the beginning of main after +// ViewID_OVR's initialization. +// - A declaration of the uniform multiviewBaseViewLayerIndex. +// Note: The SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW flag also has to be enabled to have the +// temporary variable ViewID_OVR declared and initialized. +const ShCompileOptions SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER = UINT64_C(1) << 34; + +// If the flag is enabled, gl_PointSize is clamped to the maximum point size specified in +// ShBuiltInResources in vertex shaders. +const ShCompileOptions SH_CLAMP_POINT_SIZE = UINT64_C(1) << 35; + +// Turn some arithmetic operations that operate on a float vector-scalar pair into vector-vector +// operations. This is done recursively. Some scalar binary operations inside vector constructors +// are also turned into vector operations. +// +// This is targeted to work around a bug in NVIDIA OpenGL drivers that was reproducible on NVIDIA +// driver version 387.92. It works around the most common occurrences of the bug. +const ShCompileOptions SH_REWRITE_VECTOR_SCALAR_ARITHMETIC = UINT64_C(1) << 36; -// Defines alternate strategies for implementing array index clamping. -typedef enum { - // Use the clamp intrinsic for array index clamping. - SH_CLAMP_WITH_CLAMP_INTRINSIC = 1, +// Don't use loops to initialize uninitialized variables. Only has an effect if some kind of +// variable initialization is turned on. +const ShCompileOptions SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES = UINT64_C(1) << 37; - // Use a user-defined function for array index clamping. - SH_CLAMP_WITH_USER_DEFINED_INT_CLAMP_FUNCTION -} ShArrayIndexClampingStrategy; +// Defines alternate strategies for implementing array index clamping. +enum ShArrayIndexClampingStrategy +{ + // Use the clamp intrinsic for array index clamping. + SH_CLAMP_WITH_CLAMP_INTRINSIC = 1, -// -// Driver must call this first, once, before doing any other -// compiler operations. -// If the function succeeds, the return value is true, else false. -// -COMPILER_EXPORT bool ShInitialize(); -// -// Driver should call this at shutdown. -// If the function succeeds, the return value is true, else false. -// -COMPILER_EXPORT bool ShFinalize(); + // Use a user-defined function for array index clamping. + SH_CLAMP_WITH_USER_DEFINED_INT_CLAMP_FUNCTION +}; // The 64 bits hash function. The first parameter is the input string; the // second parameter is the string length. -typedef khronos_uint64_t (*ShHashFunction64)(const char*, size_t); +using ShHashFunction64 = khronos_uint64_t (*)(const char *, size_t); // // Implementation dependent built-in resources (constants and extensions). // The names for these resources has been obtained by stripping gl_/GL_. // -typedef struct +struct ShBuiltInResources { // Constants. int MaxVertexAttribs; @@ -255,6 +291,8 @@ typedef struct // Set to 1 to enable the extension, else 0. int OES_standard_derivatives; int OES_EGL_image_external; + int OES_EGL_image_external_essl3; + int NV_EGL_stream_consumer_external; int ARB_texture_rectangle; int EXT_blend_func_extended; int EXT_draw_buffers; @@ -264,6 +302,9 @@ typedef struct int EXT_shader_framebuffer_fetch; int NV_shader_framebuffer_fetch; int ARM_shader_framebuffer_fetch; + int OVR_multiview; + int EXT_YUV_target; + int OES_geometry_shader; // Set to 1 to enable replacing GL_EXT_draw_buffers #extension directives // with GL_NV_draw_buffers in ESSL output. This flag can be used to emulate @@ -290,6 +331,9 @@ typedef struct // GLES SL version 100 gl_MaxDualSourceDrawBuffersEXT value for EXT_blend_func_extended. int MaxDualSourceDrawBuffers; + // Value of GL_MAX_VIEWS_OVR. + int MaxViewsOVR; + // Name Hashing. // Set a 64 bit hash function to enable user-defined name hashing. // Default is NULL. @@ -299,19 +343,107 @@ typedef struct // Default is SH_CLAMP_WITH_CLAMP_INTRINSIC. ShArrayIndexClampingStrategy ArrayIndexClampingStrategy; - // The maximum complexity an expression can be. + // The maximum complexity an expression can be when SH_LIMIT_EXPRESSION_COMPLEXITY is turned on. int MaxExpressionComplexity; // The maximum depth a call stack can be. int MaxCallStackDepth; -} ShBuiltInResources; -// -// Initialize built-in resources with minimum expected values. -// Parameters: -// resources: The object to initialize. Will be comparable with memcmp. -// -COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources); + // The maximum number of parameters a function can have when SH_LIMIT_EXPRESSION_COMPLEXITY is + // turned on. + int MaxFunctionParameters; + + // GLES 3.1 constants + + // texture gather offset constraints. + int MinProgramTextureGatherOffset; + int MaxProgramTextureGatherOffset; + + // maximum number of available image units + int MaxImageUnits; + + // maximum number of image uniforms in a vertex shader + int MaxVertexImageUniforms; + + // maximum number of image uniforms in a fragment shader + int MaxFragmentImageUniforms; + + // maximum number of image uniforms in a compute shader + int MaxComputeImageUniforms; + + // maximum total number of image uniforms in a program + int MaxCombinedImageUniforms; + + // maximum number of uniform locations + int MaxUniformLocations; + + // maximum number of ssbos and images in a shader + int MaxCombinedShaderOutputResources; + + // maximum number of groups in each dimension + std::array<int, 3> MaxComputeWorkGroupCount; + // maximum number of threads per work group in each dimension + std::array<int, 3> MaxComputeWorkGroupSize; + + // maximum number of total uniform components + int MaxComputeUniformComponents; + + // maximum number of texture image units in a compute shader + int MaxComputeTextureImageUnits; + + // maximum number of atomic counters in a compute shader + int MaxComputeAtomicCounters; + + // maximum number of atomic counter buffers in a compute shader + int MaxComputeAtomicCounterBuffers; + + // maximum number of atomic counters in a vertex shader + int MaxVertexAtomicCounters; + + // maximum number of atomic counters in a fragment shader + int MaxFragmentAtomicCounters; + + // maximum number of atomic counters in a program + int MaxCombinedAtomicCounters; + + // maximum binding for an atomic counter + int MaxAtomicCounterBindings; + + // maximum number of atomic counter buffers in a vertex shader + int MaxVertexAtomicCounterBuffers; + + // maximum number of atomic counter buffers in a fragment shader + int MaxFragmentAtomicCounterBuffers; + + // maximum number of atomic counter buffers in a program + int MaxCombinedAtomicCounterBuffers; + + // maximum number of buffer object storage in machine units + int MaxAtomicCounterBufferSize; + + // maximum number of uniform block bindings + int MaxUniformBufferBindings; + + // maximum number of shader storage buffer bindings + int MaxShaderStorageBufferBindings; + + // maximum point size (higher limit from ALIASED_POINT_SIZE_RANGE) + float MaxPointSize; + + // OES_geometry_shader constants + int MaxGeometryUniformComponents; + int MaxGeometryUniformBlocks; + int MaxGeometryInputComponents; + int MaxGeometryOutputComponents; + int MaxGeometryOutputVertices; + int MaxGeometryTotalOutputComponents; + int MaxGeometryTextureImageUnits; + int MaxGeometryAtomicCounterBuffers; + int MaxGeometryAtomicCounters; + int MaxGeometryShaderStorageBlocks; + int MaxGeometryShaderInvocations; + int MaxGeometryImageUniforms; +}; // // ShHandle held by but opaque to the driver. It is allocated, @@ -320,43 +452,60 @@ COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources); // // If handle creation fails, 0 will be returned. // -typedef void *ShHandle; +using ShHandle = void *; + +namespace sh +{ + +// +// Driver must call this first, once, before doing any other compiler operations. +// If the function succeeds, the return value is true, else false. +// +bool Initialize(); +// +// Driver should call this at shutdown. +// If the function succeeds, the return value is true, else false. +// +bool Finalize(); + +// +// Initialize built-in resources with minimum expected values. +// Parameters: +// resources: The object to initialize. Will be comparable with memcmp. +// +void InitBuiltInResources(ShBuiltInResources *resources); // -// Returns the a concatenated list of the items in ShBuiltInResources as a -// null-terminated string. +// Returns the a concatenated list of the items in ShBuiltInResources as a null-terminated string. // This function must be updated whenever ShBuiltInResources is changed. // Parameters: // handle: Specifies the handle of the compiler to be used. -COMPILER_EXPORT const std::string &ShGetBuiltInResourcesString(const ShHandle handle); +const std::string &GetBuiltInResourcesString(const ShHandle handle); // // Driver calls these to create and destroy compiler objects. // -// Returns the handle of constructed compiler, null if the requested compiler is -// not supported. +// Returns the handle of constructed compiler, null if the requested compiler is not supported. // Parameters: // type: Specifies the type of shader - GL_FRAGMENT_SHADER or GL_VERTEX_SHADER. -// spec: Specifies the language spec the compiler must conform to - -// SH_GLES2_SPEC or SH_WEBGL_SPEC. +// spec: Specifies the language spec the compiler must conform to - SH_GLES2_SPEC or SH_WEBGL_SPEC. // output: Specifies the output code type - for example SH_ESSL_OUTPUT, SH_GLSL_OUTPUT, // SH_HLSL_3_0_OUTPUT or SH_HLSL_4_1_OUTPUT. Note: Each output type may only // be supported in some configurations. // resources: Specifies the built-in resources. -COMPILER_EXPORT ShHandle ShConstructCompiler( - sh::GLenum type, - ShShaderSpec spec, - ShShaderOutput output, - const ShBuiltInResources *resources); -COMPILER_EXPORT void ShDestruct(ShHandle handle); +ShHandle ConstructCompiler(sh::GLenum type, + ShShaderSpec spec, + ShShaderOutput output, + const ShBuiltInResources *resources); +void Destruct(ShHandle handle); // // Compiles the given shader source. // If the function succeeds, the return value is true, else false. // Parameters: // handle: Specifies the handle of compiler to be used. -// shaderStrings: Specifies an array of pointers to null-terminated strings -// containing the shader source code. +// shaderStrings: Specifies an array of pointers to null-terminated strings containing the shader +// source code. // numStrings: Specifies the number of elements in shaderStrings array. // compileOptions: A mask containing the following parameters: // SH_VALIDATE: Validates shader to ensure that it conforms to the spec @@ -368,45 +517,41 @@ COMPILER_EXPORT void ShDestruct(ShHandle handle); // There is no need to specify this parameter when // compiling for WebGL - it is implied. // SH_INTERMEDIATE_TREE: Writes intermediate tree to info log. -// Can be queried by calling ShGetInfoLog(). +// Can be queried by calling sh::GetInfoLog(). // SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader. -// Can be queried by calling ShGetObjectCode(). +// Can be queried by calling sh::GetObjectCode(). // SH_VARIABLES: Extracts attributes, uniforms, and varyings. // Can be queried by calling ShGetVariableInfo(). // -COMPILER_EXPORT bool ShCompile( - const ShHandle handle, - const char * const shaderStrings[], - size_t numStrings, - int compileOptions); +bool Compile(const ShHandle handle, + const char *const shaderStrings[], + size_t numStrings, + ShCompileOptions compileOptions); // Clears the results from the previous compilation. -COMPILER_EXPORT void ShClearResults(const ShHandle handle); +void ClearResults(const ShHandle handle); // Return the version of the shader language. -COMPILER_EXPORT int ShGetShaderVersion(const ShHandle handle); +int GetShaderVersion(const ShHandle handle); // Return the currently set language output type. -COMPILER_EXPORT ShShaderOutput ShGetShaderOutputType( - const ShHandle handle); +ShShaderOutput GetShaderOutputType(const ShHandle handle); // Returns null-terminated information log for a compiled shader. // Parameters: // handle: Specifies the compiler -COMPILER_EXPORT const std::string &ShGetInfoLog(const ShHandle handle); +const std::string &GetInfoLog(const ShHandle handle); // Returns null-terminated object code for a compiled shader. // Parameters: // handle: Specifies the compiler -COMPILER_EXPORT const std::string &ShGetObjectCode(const ShHandle handle); +const std::string &GetObjectCode(const ShHandle handle); -// Returns a (original_name, hash) map containing all the user defined -// names in the shader, including variable names, function names, struct -// names, and struct field names. +// Returns a (original_name, hash) map containing all the user defined names in the shader, +// including variable names, function names, struct names, and struct field names. // Parameters: // handle: Specifies the compiler -COMPILER_EXPORT const std::map<std::string, std::string> *ShGetNameHashingMap( - const ShHandle handle); +const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle); // Shader variable inspection. // Returns a pointer to a list of variables of the designated type. @@ -414,52 +559,50 @@ COMPILER_EXPORT const std::map<std::string, std::string> *ShGetNameHashingMap( // Returns NULL on failure. // Parameters: // handle: Specifies the compiler -COMPILER_EXPORT const std::vector<sh::Uniform> *ShGetUniforms(const ShHandle handle); -COMPILER_EXPORT const std::vector<sh::Varying> *ShGetVaryings(const ShHandle handle); -COMPILER_EXPORT const std::vector<sh::Attribute> *ShGetAttributes(const ShHandle handle); -COMPILER_EXPORT const std::vector<sh::OutputVariable> *ShGetOutputVariables(const ShHandle handle); -COMPILER_EXPORT const std::vector<sh::InterfaceBlock> *ShGetInterfaceBlocks(const ShHandle handle); - -typedef struct -{ - sh::GLenum type; - int size; -} ShVariableInfo; - -// Returns true if the passed in variables pack in maxVectors following -// the packing rules from the GLSL 1.017 spec, Appendix A, section 7. +const std::vector<sh::Uniform> *GetUniforms(const ShHandle handle); +const std::vector<sh::Varying> *GetVaryings(const ShHandle handle); +const std::vector<sh::Varying> *GetInputVaryings(const ShHandle handle); +const std::vector<sh::Varying> *GetOutputVaryings(const ShHandle handle); +const std::vector<sh::Attribute> *GetAttributes(const ShHandle handle); +const std::vector<sh::OutputVariable> *GetOutputVariables(const ShHandle handle); +const std::vector<sh::InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle); +const std::vector<sh::InterfaceBlock> *GetUniformBlocks(const ShHandle handle); +const std::vector<sh::InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle); +sh::WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle); +// Returns the number of views specified through the num_views layout qualifier. If num_views is +// not set, the function returns -1. +int GetVertexShaderNumViews(const ShHandle handle); + +// Returns true if the passed in variables pack in maxVectors followingthe packing rules from the +// GLSL 1.017 spec, Appendix A, section 7. // Returns false otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS // flag above. // Parameters: // maxVectors: the available rows of registers. -// varInfoArray: an array of variable info (types and sizes). -// varInfoArraySize: the size of the variable array. -COMPILER_EXPORT bool ShCheckVariablesWithinPackingLimits( - int maxVectors, - ShVariableInfo *varInfoArray, - size_t varInfoArraySize); - -// Gives the compiler-assigned register for an interface block. -// The method writes the value to the output variable "indexOut". -// Returns true if it found a valid interface block, false otherwise. -// Parameters: -// handle: Specifies the compiler -// interfaceBlockName: Specifies the interface block -// indexOut: output variable that stores the assigned register -COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle, - const std::string &interfaceBlockName, - unsigned int *indexOut); +// variables: an array of variables. +bool CheckVariablesWithinPackingLimits(int maxVectors, + const std::vector<sh::ShaderVariable> &variables); -// Gives the compiler-assigned register for uniforms in the default -// interface block. +// Gives the compiler-assigned register for a uniform block. // The method writes the value to the output variable "indexOut". -// Returns true if it found a valid default uniform, false otherwise. +// Returns true if it found a valid uniform block, false otherwise. // Parameters: // handle: Specifies the compiler -// interfaceBlockName: Specifies the uniform +// uniformBlockName: Specifies the uniform block // indexOut: output variable that stores the assigned register -COMPILER_EXPORT bool ShGetUniformRegister(const ShHandle handle, - const std::string &uniformName, - unsigned int *indexOut); +bool GetUniformBlockRegister(const ShHandle handle, + const std::string &uniformBlockName, + unsigned int *indexOut); + +// Gives a map from uniform names to compiler-assigned registers in the default uniform block. +// Note that the map contains also registers of samplers that have been extracted from structs. +const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle); + +GLenum GetGeometryShaderInputPrimitiveType(const ShHandle handle); +GLenum GetGeometryShaderOutputPrimitiveType(const ShHandle handle); +int GetGeometryShaderInvocations(const ShHandle handle); +int GetGeometryShaderMaxVertices(const ShHandle handle); + +} // namespace sh #endif // GLSLANG_SHADERLANG_H_ diff --git a/src/3rdparty/angle/include/GLSLANG/ShaderVars.h b/src/3rdparty/angle/include/GLSLANG/ShaderVars.h index af9b65b7f5..709428aebf 100644 --- a/src/3rdparty/angle/include/GLSLANG/ShaderVars.h +++ b/src/3rdparty/angle/include/GLSLANG/ShaderVars.h @@ -10,15 +10,18 @@ #ifndef GLSLANG_SHADERVARS_H_ #define GLSLANG_SHADERVARS_H_ +#include <algorithm> +#include <array> #include <string> #include <vector> -#include <algorithm> -// Assume ShaderLang.h is included before ShaderVars.h, for sh::GLenum -// Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h +// This type is defined here to simplify ANGLE's integration with glslang for SPIRv. +using ShCompileOptions = uint64_t; namespace sh { +// GLenum alias +typedef unsigned int GLenum; // Varying interpolation qualifier, see section 4.3.9 of the ESSL 3.00.4 spec enum InterpolationType @@ -29,30 +32,65 @@ enum InterpolationType }; // Validate link & SSO consistency of interpolation qualifiers -COMPILER_EXPORT bool InterpolationTypesMatch(InterpolationType a, InterpolationType b); +bool InterpolationTypesMatch(InterpolationType a, InterpolationType b); // Uniform block layout qualifier, see section 4.3.8.3 of the ESSL 3.00.4 spec enum BlockLayoutType { BLOCKLAYOUT_STANDARD, + BLOCKLAYOUT_STD140 = BLOCKLAYOUT_STANDARD, + BLOCKLAYOUT_STD430, // Shader storage block layout qualifier BLOCKLAYOUT_PACKED, BLOCKLAYOUT_SHARED }; +// Interface Blocks, see section 4.3.9 of the ESSL 3.10 spec +enum class BlockType +{ + BLOCK_UNIFORM, + BLOCK_BUFFER, + + // Required in OpenGL ES 3.1 extension GL_OES_shader_io_blocks. + // TODO(jiawei.shao@intel.com): add BLOCK_OUT. + BLOCK_IN +}; + // Base class for all variables defined in shaders, including Varyings, Uniforms, etc // Note: we must override the copy constructor and assignment operator so we can // work around excessive GCC binary bloating: // See https://code.google.com/p/angleproject/issues/detail?id=697 -struct COMPILER_EXPORT ShaderVariable +struct ShaderVariable { ShaderVariable(); + ShaderVariable(GLenum typeIn); ShaderVariable(GLenum typeIn, unsigned int arraySizeIn); ~ShaderVariable(); ShaderVariable(const ShaderVariable &other); ShaderVariable &operator=(const ShaderVariable &other); - bool isArray() const { return arraySize > 0; } - unsigned int elementCount() const { return std::max(1u, arraySize); } + bool isArrayOfArrays() const { return arraySizes.size() >= 2u; } + bool isArray() const { return !arraySizes.empty(); } + unsigned int getArraySizeProduct() const; + + // Array size 0 means not an array when passed to or returned from these functions. + // Note that setArraySize() is deprecated and should not be used inside ANGLE. + unsigned int getOutermostArraySize() const { return isArray() ? arraySizes.back() : 0; } + void setArraySize(unsigned int size); + + // Turn this ShaderVariable from an array into a specific element in that array. Will update + // flattenedOffsetInParentArrays. + void indexIntoArray(unsigned int arrayIndex); + + // Get the nth nested array size from the top. Caller is responsible for range checking + // arrayNestingIndex. + unsigned int getNestedArraySize(unsigned int arrayNestingIndex) const; + + // This function should only be used with variables that are of a basic type or an array of a + // basic type. Shader interface variables that are enumerated according to rules in GLES 3.1 + // spec section 7.3.1.1 page 77 are fine. For those variables the return value should match the + // ARRAY_SIZE value that can be queried through the API. + unsigned int getBasicTypeElementCount() const; + bool isStruct() const { return !fields.empty(); } // All of the shader's variables are described using nested data @@ -70,20 +108,32 @@ struct COMPILER_EXPORT ShaderVariable const ShaderVariable **leafVar, std::string* originalFullName) const; - bool isBuiltIn() const { return name.compare(0, 3, "gl_") == 0; } + bool isBuiltIn() const; GLenum type; GLenum precision; std::string name; std::string mappedName; - unsigned int arraySize; + + // Used to make an array type. Outermost array size is stored at the end of the vector. + std::vector<unsigned int> arraySizes; + + // Offset of this variable in parent arrays. In case the parent is an array of arrays, the + // offset is outerArrayElement * innerArraySize + innerArrayElement. + // For example, if there's a variable declared as size 3 array of size 4 array of int: + // int a[3][4]; + // then the flattenedOffsetInParentArrays of a[2] would be 2. + // and flattenedOffsetInParentArrays of a[2][1] would be 2*4 + 1 = 9. + unsigned int flattenedOffsetInParentArrays; + bool staticUse; std::vector<ShaderVariable> fields; std::string structName; protected: bool isSameVariableAtLinkTime(const ShaderVariable &other, - bool matchPrecision) const; + bool matchPrecision, + bool matchName) const; bool operator==(const ShaderVariable &other) const; bool operator!=(const ShaderVariable &other) const @@ -92,7 +142,21 @@ struct COMPILER_EXPORT ShaderVariable } }; -struct COMPILER_EXPORT Uniform : public ShaderVariable +// A variable with an integer location to pass back to the GL API: either uniform (can have location +// in GLES3.1+), vertex shader input or fragment shader output. +struct VariableWithLocation : public ShaderVariable +{ + VariableWithLocation(); + ~VariableWithLocation(); + VariableWithLocation(const VariableWithLocation &other); + VariableWithLocation &operator=(const VariableWithLocation &other); + bool operator==(const VariableWithLocation &other) const; + bool operator!=(const VariableWithLocation &other) const { return !operator==(other); } + + int location; +}; + +struct Uniform : public VariableWithLocation { Uniform(); ~Uniform(); @@ -104,28 +168,17 @@ struct COMPILER_EXPORT Uniform : public ShaderVariable return !operator==(other); } + int binding; + int offset; + // Decide whether two uniforms are the same at shader link time, // assuming one from vertex shader and the other from fragment shader. - // See GLSL ES Spec 3.00.3, sec 4.3.5. + // GLSL ES Spec 3.00.3, section 4.3.5. + // GLSL ES Spec 3.10.4, section 4.4.5 bool isSameUniformAtLinkTime(const Uniform &other) const; }; -// An interface variable is a variable which passes data between the GL data structures and the -// shader execution: either vertex shader inputs or fragment shader outputs. These variables can -// have integer locations to pass back to the GL API. -struct COMPILER_EXPORT InterfaceVariable : public ShaderVariable -{ - InterfaceVariable(); - ~InterfaceVariable(); - InterfaceVariable(const InterfaceVariable &other); - InterfaceVariable &operator=(const InterfaceVariable &other); - bool operator==(const InterfaceVariable &other) const; - bool operator!=(const InterfaceVariable &other) const { return !operator==(other); } - - int location; -}; - -struct COMPILER_EXPORT Attribute : public InterfaceVariable +struct Attribute : public VariableWithLocation { Attribute(); ~Attribute(); @@ -135,7 +188,7 @@ struct COMPILER_EXPORT Attribute : public InterfaceVariable bool operator!=(const Attribute &other) const { return !operator==(other); } }; -struct COMPILER_EXPORT OutputVariable : public InterfaceVariable +struct OutputVariable : public VariableWithLocation { OutputVariable(); ~OutputVariable(); @@ -145,7 +198,7 @@ struct COMPILER_EXPORT OutputVariable : public InterfaceVariable bool operator!=(const OutputVariable &other) const { return !operator==(other); } }; -struct COMPILER_EXPORT InterfaceBlockField : public ShaderVariable +struct InterfaceBlockField : public ShaderVariable { InterfaceBlockField(); ~InterfaceBlockField(); @@ -167,7 +220,7 @@ struct COMPILER_EXPORT InterfaceBlockField : public ShaderVariable bool isRowMajorLayout; }; -struct COMPILER_EXPORT Varying : public ShaderVariable +struct Varying : public VariableWithLocation { Varying(); ~Varying(); @@ -193,7 +246,7 @@ struct COMPILER_EXPORT Varying : public ShaderVariable bool isInvariant; }; -struct COMPILER_EXPORT InterfaceBlock +struct InterfaceBlock { InterfaceBlock(); ~InterfaceBlock(); @@ -202,6 +255,15 @@ struct COMPILER_EXPORT InterfaceBlock // Fields from blocks with non-empty instance names are prefixed with the block name. std::string fieldPrefix() const; + std::string fieldMappedPrefix() const; + + // Decide whether two interface blocks are the same at shader link time. + bool isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other) const; + + bool isBuiltIn() const; + + bool isArray() const { return arraySize > 0; } + unsigned int elementCount() const { return std::max(1u, arraySize); } std::string name; std::string mappedName; @@ -209,10 +271,45 @@ struct COMPILER_EXPORT InterfaceBlock unsigned int arraySize; BlockLayoutType layout; bool isRowMajorLayout; + int binding; bool staticUse; + BlockType blockType; std::vector<InterfaceBlockField> fields; }; +struct WorkGroupSize +{ + // Must have a trivial default constructor since it is used in YYSTYPE. + WorkGroupSize() = default; + explicit constexpr WorkGroupSize(int initialSize) + : localSizeQualifiers{initialSize, initialSize, initialSize} + { + } + + void fill(int fillValue); + void setLocalSize(int localSizeX, int localSizeY, int localSizeZ); + + int &operator[](size_t index); + int operator[](size_t index) const; + size_t size() const; + + // Checks whether two work group size declarations match. + // Two work group size declarations are the same if the explicitly specified elements are the + // same or if one of them is specified as one and the other one is not specified + bool isWorkGroupSizeMatching(const WorkGroupSize &right) const; + + // Checks whether any of the values are set. + bool isAnyValueSet() const; + + // Checks whether all of the values are set. + bool isDeclared() const; + + // Checks whether either all of the values are set, or none of them are. + bool isLocalSizeValid() const; + + std::array<int, 3> localSizeQualifiers; +}; + } // namespace sh #endif // GLSLANG_SHADERVARS_H_ |