Commit 795d7543 by Shahbaz Youssefi Committed by Commit Bot

Remove unused translator option bits

Usage of SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT is removed from ANGLE by [1], and from the validating command decoder by [2]. The flag is only ever disabled in Firefox. SH_REMOVE_POW_WITH_CONSTANT_EXPONENT is removed from the validating command decoder by [3]. Not used in Firefox. [1]: https://chromium-review.googlesource.com/c/angle/angle/+/1558678 [2]: https://chromium-review.googlesource.com/c/chromium/src/+/2810880 [3]: https://chromium-review.googlesource.com/c/chromium/src/+/2810879 Bug: angleproject:4889 Change-Id: If7d9c31c48510b1486a2285a88475b3c01a77527 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2810806Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent 82cc2d21
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
// Version number for shader translation API. // Version number for shader translation API.
// It is incremented every time the API changes. // It is incremented every time the API changes.
#define ANGLE_SH_VERSION 256 #define ANGLE_SH_VERSION 257
enum ShShaderSpec enum ShShaderSpec
{ {
...@@ -91,15 +91,6 @@ const ShCompileOptions SH_SOURCE_PATH = UINT64_C(1) << 5; ...@@ -91,15 +91,6 @@ const ShCompileOptions SH_SOURCE_PATH = UINT64_C(1) << 5;
// If requested, validates the AST after every transformation. Useful for debugging. // If requested, validates the AST after every transformation. Useful for debugging.
const ShCompileOptions SH_VALIDATE_AST = UINT64_C(1) << 6; const ShCompileOptions SH_VALIDATE_AST = UINT64_C(1) << 6;
// 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) << 7;
// Due to spec difference between GLSL 4.1 or lower and ESSL3, some platforms (for example, Mac OSX // 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 // 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. // fragment shader. A simple solution to allow such shaders to link is to omit the two qualifiers.
...@@ -112,11 +103,11 @@ const ShCompileOptions SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT = UINT64_C(1) ...@@ -112,11 +103,11 @@ const ShCompileOptions SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT = UINT64_C(1)
// TODO(zmo): This is not a good long-term solution. Simply dropping these qualifiers may break some // 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 // developers' content. A more complex workaround of dynamically generating, compiling, and
// re-linking shaders that use these qualifiers should be implemented. // re-linking shaders that use these qualifiers should be implemented.
const ShCompileOptions SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3 = UINT64_C(1) << 8; 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 // This flag works around bug in Intel Mac drivers related to abs(i) where
// i is an integer. // i is an integer.
const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 9; const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 8;
// Enforce the GLSL 1.017 Appendix A section 7 packing restrictions. // Enforce the GLSL 1.017 Appendix A section 7 packing restrictions.
// This flag only enforces (and can only enforce) the packing // This flag only enforces (and can only enforce) the packing
...@@ -124,7 +115,7 @@ const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 9; ...@@ -124,7 +115,7 @@ const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 9;
// shaders. ShCheckVariablesWithinPackingLimits() lets embedders // shaders. ShCheckVariablesWithinPackingLimits() lets embedders
// enforce the packing restrictions for varying variables during // enforce the packing restrictions for varying variables during
// program link time. // program link time.
const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 10; const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 9;
// This flag ensures all indirect (expression-based) array indexing // This flag ensures all indirect (expression-based) array indexing
// is clamped to the bounds of the array. This ensures, for example, // is clamped to the bounds of the array. This ensures, for example,
...@@ -133,78 +124,74 @@ const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 10; ...@@ -133,78 +124,74 @@ const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 10;
// specified in the ShBuiltInResources when constructing the // specified in the ShBuiltInResources when constructing the
// compiler, selects the strategy for the clamping implementation. // compiler, selects the strategy for the clamping implementation.
// TODO(http://anglebug.com/4361): fix for compute shaders. // TODO(http://anglebug.com/4361): fix for compute shaders.
const ShCompileOptions SH_CLAMP_INDIRECT_ARRAY_BOUNDS = UINT64_C(1) << 11; const ShCompileOptions SH_CLAMP_INDIRECT_ARRAY_BOUNDS = UINT64_C(1) << 10;
// This flag limits the complexity of an expression. // This flag limits the complexity of an expression.
const ShCompileOptions SH_LIMIT_EXPRESSION_COMPLEXITY = UINT64_C(1) << 12; const ShCompileOptions SH_LIMIT_EXPRESSION_COMPLEXITY = UINT64_C(1) << 11;
// This flag limits the depth of the call stack. // This flag limits the depth of the call stack.
const ShCompileOptions SH_LIMIT_CALL_STACK_DEPTH = UINT64_C(1) << 13; const ShCompileOptions SH_LIMIT_CALL_STACK_DEPTH = UINT64_C(1) << 12;
// This flag initializes gl_Position to vec4(0,0,0,0) at the // 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 // beginning of the vertex shader's main(), and has no effect in the
// fragment shader. It is intended as a workaround for drivers which // fragment shader. It is intended as a workaround for drivers which
// incorrectly fail to link programs if gl_Position is not written. // incorrectly fail to link programs if gl_Position is not written.
const ShCompileOptions SH_INIT_GL_POSITION = UINT64_C(1) << 14; const ShCompileOptions SH_INIT_GL_POSITION = UINT64_C(1) << 13;
// This flag replaces // This flag replaces
// "a && b" with "a ? b : false", // "a && b" with "a ? b : false",
// "a || b" with "a ? true : b". // "a || b" with "a ? true : b".
// This is to work around a MacOSX driver bug that |b| is executed // This is to work around a MacOSX driver bug that |b| is executed
// independent of |a|'s value. // independent of |a|'s value.
const ShCompileOptions SH_UNFOLD_SHORT_CIRCUIT = UINT64_C(1) << 15; const ShCompileOptions SH_UNFOLD_SHORT_CIRCUIT = UINT64_C(1) << 14;
// This flag initializes output variables to 0 at the beginning of main(). // This flag initializes output variables to 0 at the beginning of main().
// It is to avoid undefined behaviors. // It is to avoid undefined behaviors.
const ShCompileOptions SH_INIT_OUTPUT_VARIABLES = UINT64_C(1) << 16; const ShCompileOptions SH_INIT_OUTPUT_VARIABLES = UINT64_C(1) << 15;
// This flag scalarizes vec/ivec/bvec/mat constructor args. // This flag scalarizes vec/ivec/bvec/mat constructor args.
// It is intended as a workaround for Linux/Mac driver bugs. // It is intended as a workaround for Linux/Mac driver bugs.
const ShCompileOptions SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS = UINT64_C(1) << 17; const ShCompileOptions SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS = UINT64_C(1) << 16;
// This flag overwrites a struct name with a unique prefix. // This flag overwrites a struct name with a unique prefix.
// It is intended as a workaround for drivers that do not handle // It is intended as a workaround for drivers that do not handle
// struct scopes correctly, including all Mac drivers and Linux AMD. // struct scopes correctly, including all Mac drivers and Linux AMD.
const ShCompileOptions SH_REGENERATE_STRUCT_NAMES = UINT64_C(1) << 18; const ShCompileOptions SH_REGENERATE_STRUCT_NAMES = UINT64_C(1) << 17;
// 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 // This flag works around bugs in Mac drivers related to do-while by
// transforming them into an other construct. // transforming them into an other construct.
const ShCompileOptions SH_REWRITE_DO_WHILE_LOOPS = UINT64_C(1) << 20; const ShCompileOptions SH_REWRITE_DO_WHILE_LOOPS = UINT64_C(1) << 18;
// This flag works around a bug in the HLSL compiler optimizer that folds certain // 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 // constant pow expressions incorrectly. Only applies to the HLSL back-end. It works
// by expanding the integer pow expressions into a series of multiplies. // by expanding the integer pow expressions into a series of multiplies.
const ShCompileOptions SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS = UINT64_C(1) << 21; const ShCompileOptions SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS = UINT64_C(1) << 19;
// Flatten "#pragma STDGL invariant(all)" into the declarations of // Flatten "#pragma STDGL invariant(all)" into the declarations of
// varying variables and built-in GLSL variables. This compiler // varying variables and built-in GLSL variables. This compiler
// option is enabled automatically when needed. // option is enabled automatically when needed.
const ShCompileOptions SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL = UINT64_C(1) << 22; const ShCompileOptions SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL = UINT64_C(1) << 20;
// Some drivers do not take into account the base level of the texture in the results of the // 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 // HLSL GetDimensions builtin. This flag instructs the compiler to manually add the base level
// offsetting. // offsetting.
const ShCompileOptions SH_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL = UINT64_C(1) << 23; const ShCompileOptions SH_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL = UINT64_C(1) << 21;
// This flag works around an issue in translating GLSL function texelFetchOffset on // This flag works around an issue in translating GLSL function texelFetchOffset on
// INTEL drivers. It works by translating texelFetchOffset into texelFetch. // INTEL drivers. It works by translating texelFetchOffset into texelFetch.
const ShCompileOptions SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH = UINT64_C(1) << 24; const ShCompileOptions SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH = UINT64_C(1) << 22;
// This flag works around condition bug of for and while loops in Intel Mac OSX drivers. // 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". // 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; const ShCompileOptions SH_ADD_AND_TRUE_TO_LOOP_CONDITION = UINT64_C(1) << 23;
// This flag works around a bug in evaluating unary minus operator on integer on some INTEL // 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. // drivers. It works by translating -(int) into ~(int) + 1.
const ShCompileOptions SH_REWRITE_INTEGER_UNARY_MINUS_OPERATOR = UINT64_C(1) << 26; const ShCompileOptions SH_REWRITE_INTEGER_UNARY_MINUS_OPERATOR = UINT64_C(1) << 24;
// This flag works around a bug in evaluating isnan() on some INTEL D3D and Mac OSX drivers. // 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. // It works by using an expression to emulate this function.
const ShCompileOptions SH_EMULATE_ISNAN_FLOAT_FUNCTION = UINT64_C(1) << 27; const ShCompileOptions SH_EMULATE_ISNAN_FLOAT_FUNCTION = UINT64_C(1) << 25;
// This flag will use all uniforms of unused std140 and shared uniform blocks at the // 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 // beginning of the vertex/fragment shader's main(). It is intended as a workaround for Mac
...@@ -212,19 +199,19 @@ const ShCompileOptions SH_EMULATE_ISNAN_FLOAT_FUNCTION = UINT64_C(1) << 27; ...@@ -212,19 +199,19 @@ const ShCompileOptions SH_EMULATE_ISNAN_FLOAT_FUNCTION = UINT64_C(1) << 27;
// std140 and shared uniform blocks' members as inactive. However, WebGL2.0 based on // 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 // 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. // 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; const ShCompileOptions SH_USE_UNUSED_STANDARD_SHARED_BLOCKS = UINT64_C(1) << 26;
// This flag works around a bug in unary minus operator on float numbers on Intel // 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. // 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; const ShCompileOptions SH_REWRITE_FLOAT_UNARY_MINUS_OPERATOR = UINT64_C(1) << 27;
// This flag works around a bug in evaluating atan(y, x) on some NVIDIA OpenGL drivers. // 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. // It works by using an expression to emulate this function.
const ShCompileOptions SH_EMULATE_ATAN2_FLOAT_FUNCTION = UINT64_C(1) << 30; const ShCompileOptions SH_EMULATE_ATAN2_FLOAT_FUNCTION = UINT64_C(1) << 28;
// Set to initialize uninitialized local and global temporary variables. Should only be used with // 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. // GLSL output. In HLSL output variables are initialized regardless of if this flag is set.
const ShCompileOptions SH_INITIALIZE_UNINITIALIZED_LOCALS = UINT64_C(1) << 31; const ShCompileOptions SH_INITIALIZE_UNINITIALIZED_LOCALS = UINT64_C(1) << 29;
// The flag modifies the shader in the following way: // 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_InstanceID is replaced by the global temporary variable InstanceID.
...@@ -233,7 +220,7 @@ const ShCompileOptions SH_INITIALIZE_UNINITIALIZED_LOCALS = UINT64_C(1) << 31; ...@@ -233,7 +220,7 @@ const ShCompileOptions SH_INITIALIZE_UNINITIALIZED_LOCALS = UINT64_C(1) << 31;
// ViewID_OVR = uint(gl_InstanceID) % num_views; // ViewID_OVR = uint(gl_InstanceID) % num_views;
// InstanceID = gl_InstanceID / num_views; // InstanceID = gl_InstanceID / num_views;
// ViewID_OVR is added as a varying variable to both the vertex and fragment shaders. // 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) << 32; const ShCompileOptions SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW = UINT64_C(1) << 30;
// With the flag enabled the GLSL/ESSL vertex shader is modified to include code for viewport // With the flag enabled the GLSL/ESSL vertex shader is modified to include code for viewport
// selection in the following way: // selection in the following way:
...@@ -243,11 +230,11 @@ const ShCompileOptions SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW = UINT64_C ...@@ -243,11 +230,11 @@ const ShCompileOptions SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW = UINT64_C
// - A declaration of the uniform multiviewBaseViewLayerIndex. // - A declaration of the uniform multiviewBaseViewLayerIndex.
// Note: The SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW flag also has to be enabled to have the // Note: The SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW flag also has to be enabled to have the
// temporary variable ViewID_OVR declared and initialized. // temporary variable ViewID_OVR declared and initialized.
const ShCompileOptions SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER = UINT64_C(1) << 33; const ShCompileOptions SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER = UINT64_C(1) << 31;
// If the flag is enabled, gl_PointSize is clamped to the maximum point size specified in // If the flag is enabled, gl_PointSize is clamped to the maximum point size specified in
// ShBuiltInResources in vertex shaders. // ShBuiltInResources in vertex shaders.
const ShCompileOptions SH_CLAMP_POINT_SIZE = UINT64_C(1) << 34; const ShCompileOptions SH_CLAMP_POINT_SIZE = UINT64_C(1) << 32;
// Turn some arithmetic operations that operate on a float vector-scalar pair into vector-vector // 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 // operations. This is done recursively. Some scalar binary operations inside vector constructors
...@@ -255,100 +242,100 @@ const ShCompileOptions SH_CLAMP_POINT_SIZE = UINT64_C(1) << 34; ...@@ -255,100 +242,100 @@ const ShCompileOptions SH_CLAMP_POINT_SIZE = UINT64_C(1) << 34;
// //
// This is targeted to work around a bug in NVIDIA OpenGL drivers that was reproducible on NVIDIA // 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. // driver version 387.92. It works around the most common occurrences of the bug.
const ShCompileOptions SH_REWRITE_VECTOR_SCALAR_ARITHMETIC = UINT64_C(1) << 35; const ShCompileOptions SH_REWRITE_VECTOR_SCALAR_ARITHMETIC = UINT64_C(1) << 33;
// Don't use loops to initialize uninitialized variables. Only has an effect if some kind of // Don't use loops to initialize uninitialized variables. Only has an effect if some kind of
// variable initialization is turned on. // variable initialization is turned on.
const ShCompileOptions SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES = UINT64_C(1) << 36; const ShCompileOptions SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES = UINT64_C(1) << 34;
// Don't use D3D constant register zero when allocating space for uniforms. This is targeted to work // Don't use D3D constant register zero when allocating space for uniforms. This is targeted to work
// around a bug in NVIDIA D3D driver version 388.59 where in very specific cases the driver would // around a bug in NVIDIA D3D driver version 388.59 where in very specific cases the driver would
// not handle constant register zero correctly. Only has an effect on HLSL translation. // not handle constant register zero correctly. Only has an effect on HLSL translation.
const ShCompileOptions SH_SKIP_D3D_CONSTANT_REGISTER_ZERO = UINT64_C(1) << 37; const ShCompileOptions SH_SKIP_D3D_CONSTANT_REGISTER_ZERO = UINT64_C(1) << 35;
// Clamp gl_FragDepth to the range [0.0, 1.0] in case it is statically used. // Clamp gl_FragDepth to the range [0.0, 1.0] in case it is statically used.
const ShCompileOptions SH_CLAMP_FRAG_DEPTH = UINT64_C(1) << 38; const ShCompileOptions SH_CLAMP_FRAG_DEPTH = UINT64_C(1) << 36;
// Rewrite expressions like "v.x = z = expression;". Works around a bug in NVIDIA OpenGL drivers // Rewrite expressions like "v.x = z = expression;". Works around a bug in NVIDIA OpenGL drivers
// prior to version 397.31. // prior to version 397.31.
const ShCompileOptions SH_REWRITE_REPEATED_ASSIGN_TO_SWIZZLED = UINT64_C(1) << 39; const ShCompileOptions SH_REWRITE_REPEATED_ASSIGN_TO_SWIZZLED = UINT64_C(1) << 37;
// Rewrite gl_DrawID as a uniform int // Rewrite gl_DrawID as a uniform int
const ShCompileOptions SH_EMULATE_GL_DRAW_ID = UINT64_C(1) << 40; const ShCompileOptions SH_EMULATE_GL_DRAW_ID = UINT64_C(1) << 38;
// This flag initializes shared variables to 0. // This flag initializes shared variables to 0.
// It is to avoid ompute shaders being able to read undefined values that could be coming from // It is to avoid ompute shaders being able to read undefined values that could be coming from
// another webpage/application. // another webpage/application.
const ShCompileOptions SH_INIT_SHARED_VARIABLES = UINT64_C(1) << 41; const ShCompileOptions SH_INIT_SHARED_VARIABLES = UINT64_C(1) << 39;
// Forces the value returned from an atomic operations to be always be resolved. This is targeted to // Forces the value returned from an atomic operations to be always be resolved. This is targeted to
// workaround a bug in NVIDIA D3D driver where the return value from // workaround a bug in NVIDIA D3D driver where the return value from
// RWByteAddressBuffer.InterlockedAdd does not get resolved when used in the .yzw components of a // RWByteAddressBuffer.InterlockedAdd does not get resolved when used in the .yzw components of a
// RWByteAddressBuffer.Store operation. Only has an effect on HLSL translation. // RWByteAddressBuffer.Store operation. Only has an effect on HLSL translation.
// http://anglebug.com/3246 // http://anglebug.com/3246
const ShCompileOptions SH_FORCE_ATOMIC_VALUE_RESOLUTION = UINT64_C(1) << 42; const ShCompileOptions SH_FORCE_ATOMIC_VALUE_RESOLUTION = UINT64_C(1) << 40;
// Rewrite gl_BaseVertex and gl_BaseInstance as uniform int // Rewrite gl_BaseVertex and gl_BaseInstance as uniform int
const ShCompileOptions SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE = UINT64_C(1) << 43; const ShCompileOptions SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE = UINT64_C(1) << 41;
// Emulate seamful cube map sampling for OpenGL ES2.0. Currently only applies to the Vulkan // Emulate seamful cube map sampling for OpenGL ES2.0. Currently only applies to the Vulkan
// backend, as is done after samplers are moved out of structs. Can likely be made to work on // backend, as is done after samplers are moved out of structs. Can likely be made to work on
// the other backends as well. // the other backends as well.
const ShCompileOptions SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING = UINT64_C(1) << 44; const ShCompileOptions SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING = UINT64_C(1) << 42;
// This flag controls how to translate WEBGL_video_texture sampling function. // This flag controls how to translate WEBGL_video_texture sampling function.
const ShCompileOptions SH_TAKE_VIDEO_TEXTURE_AS_EXTERNAL_OES = UINT64_C(1) << 45; const ShCompileOptions SH_TAKE_VIDEO_TEXTURE_AS_EXTERNAL_OES = UINT64_C(1) << 43;
// This flag works around a inconsistent behavior in Mac AMD driver where gl_VertexID doesn't // This flag works around a inconsistent behavior in Mac AMD driver where gl_VertexID doesn't
// include base vertex value. It replaces gl_VertexID with (gl_VertexID + angle_BaseVertex) // include base vertex value. It replaces gl_VertexID with (gl_VertexID + angle_BaseVertex)
// when angle_BaseVertex is available. // when angle_BaseVertex is available.
const ShCompileOptions SH_ADD_BASE_VERTEX_TO_VERTEX_ID = UINT64_C(1) << 46; const ShCompileOptions SH_ADD_BASE_VERTEX_TO_VERTEX_ID = UINT64_C(1) << 44;
// This works around the dynamic lvalue indexing of swizzled vectors on various platforms. // This works around the dynamic lvalue indexing of swizzled vectors on various platforms.
const ShCompileOptions SH_REMOVE_DYNAMIC_INDEXING_OF_SWIZZLED_VECTOR = UINT64_C(1) << 47; const ShCompileOptions SH_REMOVE_DYNAMIC_INDEXING_OF_SWIZZLED_VECTOR = UINT64_C(1) << 45;
// This flag works around a slow fxc compile performance issue with dynamic uniform indexing. // This flag works around a slow fxc compile performance issue with dynamic uniform indexing.
const ShCompileOptions SH_ALLOW_TRANSLATE_UNIFORM_BLOCK_TO_STRUCTUREDBUFFER = UINT64_C(1) << 48; const ShCompileOptions SH_ALLOW_TRANSLATE_UNIFORM_BLOCK_TO_STRUCTUREDBUFFER = UINT64_C(1) << 46;
// This flag indicates whether Bresenham line raster emulation code should be generated. This // This flag indicates whether Bresenham line raster emulation code should be generated. This
// emulation is necessary if the backend uses a differnet algorithm to draw lines. Currently only // emulation is necessary if the backend uses a differnet algorithm to draw lines. Currently only
// implemented for the Vulkan backend. // implemented for the Vulkan backend.
const ShCompileOptions SH_ADD_BRESENHAM_LINE_RASTER_EMULATION = UINT64_C(1) << 49; const ShCompileOptions SH_ADD_BRESENHAM_LINE_RASTER_EMULATION = UINT64_C(1) << 47;
// This flag allows disabling ARB_texture_rectangle on a per-compile basis. This is necessary // This flag allows disabling ARB_texture_rectangle on a per-compile basis. This is necessary
// for WebGL contexts becuase ARB_texture_rectangle may be necessary for the WebGL implementation // for WebGL contexts becuase ARB_texture_rectangle may be necessary for the WebGL implementation
// internally but shouldn't be exposed to WebGL user code. // internally but shouldn't be exposed to WebGL user code.
const ShCompileOptions SH_DISABLE_ARB_TEXTURE_RECTANGLE = UINT64_C(1) << 50; const ShCompileOptions SH_DISABLE_ARB_TEXTURE_RECTANGLE = UINT64_C(1) << 48;
// This flag works around a driver bug by rewriting uses of row-major matrices // This flag works around a driver bug by rewriting uses of row-major matrices
// as column-major in ESSL 3.00 and greater shaders. // as column-major in ESSL 3.00 and greater shaders.
const ShCompileOptions SH_REWRITE_ROW_MAJOR_MATRICES = UINT64_C(1) << 51; const ShCompileOptions SH_REWRITE_ROW_MAJOR_MATRICES = UINT64_C(1) << 49;
// Drop any explicit precision qualifiers from shader. // Drop any explicit precision qualifiers from shader.
const ShCompileOptions SH_IGNORE_PRECISION_QUALIFIERS = UINT64_C(1) << 52; const ShCompileOptions SH_IGNORE_PRECISION_QUALIFIERS = UINT64_C(1) << 50;
// Allow compiler to do early fragment tests as an optimization. // Allow compiler to do early fragment tests as an optimization.
const ShCompileOptions SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION = UINT64_C(1) << 53; const ShCompileOptions SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION = UINT64_C(1) << 51;
// Allow compiler to insert Android pre-rotation code. // Allow compiler to insert Android pre-rotation code.
const ShCompileOptions SH_ADD_PRE_ROTATION = UINT64_C(1) << 54; const ShCompileOptions SH_ADD_PRE_ROTATION = UINT64_C(1) << 52;
const ShCompileOptions SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP = UINT64_C(1) << 55; const ShCompileOptions SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP = UINT64_C(1) << 53;
// Allow compiler to use specialization constant to do pre-rotation and y flip. // Allow compiler to use specialization constant to do pre-rotation and y flip.
const ShCompileOptions SH_USE_SPECIALIZATION_CONSTANT = UINT64_C(1) << 56; const ShCompileOptions SH_USE_SPECIALIZATION_CONSTANT = UINT64_C(1) << 54;
// Ask compiler to generate Vulkan transform feedback emulation support code. // Ask compiler to generate Vulkan transform feedback emulation support code.
const ShCompileOptions SH_ADD_VULKAN_XFB_EMULATION_SUPPORT_CODE = UINT64_C(1) << 57; const ShCompileOptions SH_ADD_VULKAN_XFB_EMULATION_SUPPORT_CODE = UINT64_C(1) << 55;
// Ask compiler to generate Vulkan transform feedback support code when using the // Ask compiler to generate Vulkan transform feedback support code when using the
// VK_EXT_transform_feedback extension. // VK_EXT_transform_feedback extension.
const ShCompileOptions SH_ADD_VULKAN_XFB_EXTENSION_SUPPORT_CODE = UINT64_C(1) << 58; const ShCompileOptions SH_ADD_VULKAN_XFB_EXTENSION_SUPPORT_CODE = UINT64_C(1) << 56;
// This flag initializes fragment shader's output variables to zero at the beginning of the fragment // This flag initializes fragment shader's output variables to zero at the beginning of the fragment
// shader's main(). It is intended as a workaround for drivers which get context lost if // shader's main(). It is intended as a workaround for drivers which get context lost if
// gl_FragColor is not written. // gl_FragColor is not written.
const ShCompileOptions SH_INIT_FRAGMENT_OUTPUT_VARIABLES = UINT64_C(1) << 59; const ShCompileOptions SH_INIT_FRAGMENT_OUTPUT_VARIABLES = UINT64_C(1) << 57;
// Defines alternate strategies for implementing array index clamping. // Defines alternate strategies for implementing array index clamping.
enum ShArrayIndexClampingStrategy enum ShArrayIndexClampingStrategy
......
...@@ -150,8 +150,6 @@ angle_translator_sources = [ ...@@ -150,8 +150,6 @@ angle_translator_sources = [
"src/compiler/translator/tree_ops/RemoveDynamicIndexing.h", "src/compiler/translator/tree_ops/RemoveDynamicIndexing.h",
"src/compiler/translator/tree_ops/RemoveInvariantDeclaration.cpp", "src/compiler/translator/tree_ops/RemoveInvariantDeclaration.cpp",
"src/compiler/translator/tree_ops/RemoveInvariantDeclaration.h", "src/compiler/translator/tree_ops/RemoveInvariantDeclaration.h",
"src/compiler/translator/tree_ops/RemovePow.cpp",
"src/compiler/translator/tree_ops/RemovePow.h",
"src/compiler/translator/tree_ops/RemoveUnreferencedVariables.cpp", "src/compiler/translator/tree_ops/RemoveUnreferencedVariables.cpp",
"src/compiler/translator/tree_ops/RemoveUnreferencedVariables.h", "src/compiler/translator/tree_ops/RemoveUnreferencedVariables.h",
"src/compiler/translator/tree_ops/RewriteTexelFetchOffset.cpp", "src/compiler/translator/tree_ops/RewriteTexelFetchOffset.cpp",
......
...@@ -25,19 +25,17 @@ namespace ...@@ -25,19 +25,17 @@ namespace
// Options supported by any output // Options supported by any output
constexpr ShCompileOptions kCommonOptions = constexpr ShCompileOptions kCommonOptions =
SH_VALIDATE | SH_VALIDATE_LOOP_INDEXING | SH_INTERMEDIATE_TREE | SH_OBJECT_CODE | SH_VARIABLES | SH_VALIDATE | SH_VALIDATE_LOOP_INDEXING | SH_INTERMEDIATE_TREE | SH_OBJECT_CODE | SH_VARIABLES |
SH_LINE_DIRECTIVES | SH_SOURCE_PATH | SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT | SH_LINE_DIRECTIVES | SH_SOURCE_PATH | SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3 |
SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3 | SH_EMULATE_ABS_INT_FUNCTION | SH_EMULATE_ABS_INT_FUNCTION | SH_ENFORCE_PACKING_RESTRICTIONS | SH_CLAMP_INDIRECT_ARRAY_BOUNDS |
SH_ENFORCE_PACKING_RESTRICTIONS | SH_CLAMP_INDIRECT_ARRAY_BOUNDS |
SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH | SH_INIT_GL_POSITION | SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH | SH_INIT_GL_POSITION |
SH_INIT_OUTPUT_VARIABLES | SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS | SH_INIT_OUTPUT_VARIABLES | SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS |
SH_REMOVE_POW_WITH_CONSTANT_EXPONENT | SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL | SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL | SH_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL |
SH_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL | SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH | SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH | SH_EMULATE_ISNAN_FLOAT_FUNCTION |
SH_EMULATE_ISNAN_FLOAT_FUNCTION | SH_INITIALIZE_UNINITIALIZED_LOCALS | SH_INITIALIZE_UNINITIALIZED_LOCALS | SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW |
SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW | SH_CLAMP_POINT_SIZE | SH_CLAMP_POINT_SIZE | SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES |
SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES | SH_SKIP_D3D_CONSTANT_REGISTER_ZERO | SH_SKIP_D3D_CONSTANT_REGISTER_ZERO | SH_EMULATE_GL_DRAW_ID | SH_INIT_SHARED_VARIABLES |
SH_EMULATE_GL_DRAW_ID | SH_INIT_SHARED_VARIABLES | SH_FORCE_ATOMIC_VALUE_RESOLUTION | SH_FORCE_ATOMIC_VALUE_RESOLUTION | SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE |
SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE | SH_TAKE_VIDEO_TEXTURE_AS_EXTERNAL_OES | SH_TAKE_VIDEO_TEXTURE_AS_EXTERNAL_OES | SH_VALIDATE_AST | SH_ADD_BASE_VERTEX_TO_VERTEX_ID |
SH_VALIDATE_AST | SH_ADD_BASE_VERTEX_TO_VERTEX_ID |
SH_REMOVE_DYNAMIC_INDEXING_OF_SWIZZLED_VECTOR | SH_DISABLE_ARB_TEXTURE_RECTANGLE | SH_REMOVE_DYNAMIC_INDEXING_OF_SWIZZLED_VECTOR | SH_DISABLE_ARB_TEXTURE_RECTANGLE |
SH_IGNORE_PRECISION_QUALIFIERS | SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP; SH_IGNORE_PRECISION_QUALIFIERS | SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP;
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "compiler/translator/tree_ops/RemoveArrayLengthMethod.h" #include "compiler/translator/tree_ops/RemoveArrayLengthMethod.h"
#include "compiler/translator/tree_ops/RemoveDynamicIndexing.h" #include "compiler/translator/tree_ops/RemoveDynamicIndexing.h"
#include "compiler/translator/tree_ops/RemoveInvariantDeclaration.h" #include "compiler/translator/tree_ops/RemoveInvariantDeclaration.h"
#include "compiler/translator/tree_ops/RemovePow.h"
#include "compiler/translator/tree_ops/RemoveUnreferencedVariables.h" #include "compiler/translator/tree_ops/RemoveUnreferencedVariables.h"
#include "compiler/translator/tree_ops/ScalarizeVecAndMatConstructorArgs.h" #include "compiler/translator/tree_ops/ScalarizeVecAndMatConstructorArgs.h"
#include "compiler/translator/tree_ops/SeparateDeclarations.h" #include "compiler/translator/tree_ops/SeparateDeclarations.h"
...@@ -721,14 +720,6 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -721,14 +720,6 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
} }
} }
if ((compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT) != 0)
{
if (!RemovePow(this, root, &mSymbolTable))
{
return false;
}
}
if ((compileOptions & SH_REGENERATE_STRUCT_NAMES) != 0) if ((compileOptions & SH_REGENERATE_STRUCT_NAMES) != 0)
{ {
if (!RegenerateStructNames(this, root, &mSymbolTable)) if (!RegenerateStructNames(this, root, &mSymbolTable))
......
//
// Copyright 2002 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RemovePow is an AST traverser to convert pow(x, y) built-in calls where y is a
// constant to exp2(y * log2(x)). This works around an issue in NVIDIA 311 series
// OpenGL drivers.
//
#include "compiler/translator/tree_ops/RemovePow.h"
#include "compiler/translator/InfoSink.h"
#include "compiler/translator/tree_util/IntermNode_util.h"
#include "compiler/translator/tree_util/IntermTraverse.h"
namespace sh
{
namespace
{
bool IsProblematicPow(TIntermTyped *node)
{
TIntermAggregate *agg = node->getAsAggregate();
if (agg != nullptr && agg->getOp() == EOpPow)
{
ASSERT(agg->getSequence()->size() == 2);
return agg->getSequence()->at(1)->getAsConstantUnion() != nullptr;
}
return false;
}
// Traverser that converts all pow operations simultaneously.
class RemovePowTraverser : public TIntermTraverser
{
public:
RemovePowTraverser(TSymbolTable *symbolTable);
bool visitAggregate(Visit visit, TIntermAggregate *node) override;
void nextIteration() { mNeedAnotherIteration = false; }
bool needAnotherIteration() const { return mNeedAnotherIteration; }
protected:
bool mNeedAnotherIteration;
};
RemovePowTraverser::RemovePowTraverser(TSymbolTable *symbolTable)
: TIntermTraverser(true, false, false, symbolTable), mNeedAnotherIteration(false)
{}
bool RemovePowTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
{
if (IsProblematicPow(node))
{
TIntermTyped *x = node->getSequence()->at(0)->getAsTyped();
TIntermTyped *y = node->getSequence()->at(1)->getAsTyped();
TIntermSequence logArgs;
logArgs.push_back(x);
TIntermTyped *log = CreateBuiltInFunctionCallNode("log2", &logArgs, *mSymbolTable, 100);
log->setLine(node->getLine());
TOperator op = TIntermBinary::GetMulOpBasedOnOperands(y->getType(), log->getType());
TIntermBinary *mul = new TIntermBinary(op, y, log);
mul->setLine(node->getLine());
TIntermSequence expArgs;
expArgs.push_back(mul);
TIntermTyped *exp = CreateBuiltInFunctionCallNode("exp2", &expArgs, *mSymbolTable, 100);
exp->setLine(node->getLine());
queueReplacement(exp, OriginalNode::IS_DROPPED);
// If the x parameter also needs to be replaced, we need to do that in another traversal,
// since it's parent node will change in a way that's not handled correctly by updateTree().
if (IsProblematicPow(x))
{
mNeedAnotherIteration = true;
return false;
}
}
return true;
}
} // namespace
bool RemovePow(TCompiler *compiler, TIntermNode *root, TSymbolTable *symbolTable)
{
RemovePowTraverser traverser(symbolTable);
// Iterate as necessary, and reset the traverser between iterations.
do
{
traverser.nextIteration();
root->traverse(&traverser);
if (!traverser.updateTree(compiler, root))
{
return false;
}
} while (traverser.needAnotherIteration());
return true;
}
} // namespace sh
//
// Copyright 2002 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RemovePow is an AST traverser to convert pow(x, y) built-in calls where y is a
// constant to exp2(y * log2(x)). This works around an issue in NVIDIA 311 series
// OpenGL drivers.
//
#ifndef COMPILER_TRANSLATOR_TREEOPS_REMOVEPOW_H_
#define COMPILER_TRANSLATOR_TREEOPS_REMOVEPOW_H_
#include "common/angleutils.h"
namespace sh
{
class TCompiler;
class TIntermNode;
class TSymbolTable;
ANGLE_NO_DISCARD bool RemovePow(TCompiler *compiler, TIntermNode *root, TSymbolTable *symbolTable);
} // namespace sh
#endif // COMPILER_TRANSLATOR_TREEOPS_REMOVEPOW_H_
...@@ -124,7 +124,6 @@ angle_unittests_compiler_tests_sources = [ ...@@ -124,7 +124,6 @@ angle_unittests_compiler_tests_sources = [
"compiler_tests/QualificationOrder_test.cpp", "compiler_tests/QualificationOrder_test.cpp",
"compiler_tests/RecordConstantPrecision_test.cpp", "compiler_tests/RecordConstantPrecision_test.cpp",
"compiler_tests/RegenerateStructNames_test.cpp", "compiler_tests/RegenerateStructNames_test.cpp",
"compiler_tests/RemovePow_test.cpp",
"compiler_tests/RemoveUnreferencedVariables_test.cpp", "compiler_tests/RemoveUnreferencedVariables_test.cpp",
"compiler_tests/SamplerMultisample_test.cpp", "compiler_tests/SamplerMultisample_test.cpp",
"compiler_tests/SamplerVideoWEBGL_test.cpp", "compiler_tests/SamplerVideoWEBGL_test.cpp",
......
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RemovePow_test.cpp:
// Tests for removing pow() function calls from the AST.
//
#include "GLSLANG/ShaderLang.h"
#include "angle_gl.h"
#include "compiler/translator/TranslatorGLSL.h"
#include "compiler/translator/tree_util/NodeSearch.h"
#include "gtest/gtest.h"
using namespace sh;
class RemovePowTest : public testing::Test
{
public:
RemovePowTest() {}
protected:
void SetUp() override
{
allocator.push();
SetGlobalPoolAllocator(&allocator);
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslatorGLSL =
new sh::TranslatorGLSL(GL_FRAGMENT_SHADER, SH_GLES2_SPEC, SH_GLSL_COMPATIBILITY_OUTPUT);
ASSERT_TRUE(mTranslatorGLSL->Init(resources));
}
void TearDown() override
{
SafeDelete(mTranslatorGLSL);
SetGlobalPoolAllocator(nullptr);
allocator.pop();
}
void compile(const std::string &shaderString)
{
const char *shaderStrings[] = {shaderString.c_str()};
mASTRoot = mTranslatorGLSL->compileTreeForTesting(
shaderStrings, 1, SH_OBJECT_CODE | SH_REMOVE_POW_WITH_CONSTANT_EXPONENT);
if (!mASTRoot)
{
TInfoSink &infoSink = mTranslatorGLSL->getInfoSink();
FAIL() << "Shader compilation into ESSL failed " << infoSink.info.c_str();
}
}
template <class T>
bool foundInAST()
{
return T::search(mASTRoot);
}
private:
sh::TranslatorGLSL *mTranslatorGLSL;
TIntermNode *mASTRoot;
angle::PoolAllocator allocator;
};
// Check if there's a pow() node anywhere in the tree.
class FindPow : public sh::NodeSearchTraverser<FindPow>
{
public:
bool visitBinary(Visit visit, TIntermBinary *node) override
{
if (node->getOp() == EOpPow)
{
mFound = true;
}
return !mFound;
}
};
// Check if the tree starting at node corresponds to exp2(y * log2(x))
// If the tree matches, set base to the node corresponding to x.
bool IsPowWorkaround(TIntermNode *node, TIntermNode **base)
{
TIntermUnary *exp = node->getAsUnaryNode();
if (exp != nullptr && exp->getOp() == EOpExp2)
{
TIntermBinary *mul = exp->getOperand()->getAsBinaryNode();
if (mul != nullptr && mul->isMultiplication())
{
TIntermUnary *log = mul->getRight()->getAsUnaryNode();
if (mul->getLeft()->getAsConstantUnion() && log != nullptr)
{
if (log->getOp() == EOpLog2)
{
if (base)
*base = log->getOperand();
return true;
}
}
}
}
return false;
}
// Check if there's a node with the correct workaround to pow anywhere in the tree.
class FindPowWorkaround : public sh::NodeSearchTraverser<FindPowWorkaround>
{
public:
bool visitUnary(Visit visit, TIntermUnary *node) override
{
mFound = IsPowWorkaround(node, nullptr);
return !mFound;
}
};
// Check if there's a node with the correct workaround to pow with another workaround to pow
// nested within it anywhere in the tree.
class FindNestedPowWorkaround : public sh::NodeSearchTraverser<FindNestedPowWorkaround>
{
public:
bool visitUnary(Visit visit, TIntermUnary *node) override
{
TIntermNode *base = nullptr;
bool oneFound = IsPowWorkaround(node, &base);
if (oneFound && base)
mFound = IsPowWorkaround(base, nullptr);
return !mFound;
}
};
TEST_F(RemovePowTest, PowWithConstantExponent)
{
const std::string &shaderString =
"precision mediump float;\n"
"uniform float u;\n"
"void main() {\n"
" gl_FragColor = pow(vec4(u), vec4(0.5));\n"
"}\n";
compile(shaderString);
ASSERT_FALSE(foundInAST<FindPow>());
ASSERT_TRUE(foundInAST<FindPowWorkaround>());
ASSERT_FALSE(foundInAST<FindNestedPowWorkaround>());
}
TEST_F(RemovePowTest, NestedPowWithConstantExponent)
{
const std::string &shaderString =
"precision mediump float;\n"
"uniform float u;\n"
"void main() {\n"
" gl_FragColor = pow(pow(vec4(u), vec4(2.0)), vec4(0.5));\n"
"}\n";
compile(shaderString);
ASSERT_FALSE(foundInAST<FindPow>());
ASSERT_TRUE(foundInAST<FindNestedPowWorkaround>());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment