Commit 2feb3db5 by Shahbaz Youssefi Committed by Commit Bot

Remove unused translator option bit

SH_DONT_PRUNE_UNUSED_FUNCTIONS was only used by tests, and never used by ANGLE or chromium. Bug: angleproject:4889 Change-Id: I4926f86125e69b07e9d4d95134b7b70522e0d64f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2607491Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent 41dbfe9c
...@@ -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 255 #define ANGLE_SH_VERSION 256
enum ShShaderSpec enum ShShaderSpec
{ {
...@@ -88,6 +88,9 @@ const ShCompileOptions SH_VARIABLES = UINT64_C(1) << 3; ...@@ -88,6 +88,9 @@ const ShCompileOptions SH_VARIABLES = UINT64_C(1) << 3;
const ShCompileOptions SH_LINE_DIRECTIVES = UINT64_C(1) << 4; const ShCompileOptions SH_LINE_DIRECTIVES = UINT64_C(1) << 4;
const ShCompileOptions SH_SOURCE_PATH = UINT64_C(1) << 5; const ShCompileOptions SH_SOURCE_PATH = UINT64_C(1) << 5;
// If requested, validates the AST after every transformation. Useful for debugging.
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. // 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 // 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, // different implementations about this. Some drivers forbid invariant in fragment for GLSL>= 4.20,
...@@ -95,7 +98,7 @@ const ShCompileOptions SH_SOURCE_PATH = UINT64_C(1) << 5; ...@@ -95,7 +98,7 @@ const ShCompileOptions SH_SOURCE_PATH = UINT64_C(1) << 5;
// must match between vertex and fragment shader, e.g. AMD. The behavior on AMD is obviously wrong. // 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. // 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. // 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; 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
...@@ -109,11 +112,11 @@ const ShCompileOptions SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT = UINT64_C(1) ...@@ -109,11 +112,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) << 7; const ShCompileOptions SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3 = UINT64_C(1) << 8;
// 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) << 8; const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 9;
// 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
...@@ -121,7 +124,7 @@ const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 8; ...@@ -121,7 +124,7 @@ const ShCompileOptions SH_EMULATE_ABS_INT_FUNCTION = UINT64_C(1) << 8;
// 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) << 9; const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 10;
// 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,
...@@ -130,44 +133,39 @@ const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 9; ...@@ -130,44 +133,39 @@ const ShCompileOptions SH_ENFORCE_PACKING_RESTRICTIONS = UINT64_C(1) << 9;
// 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) << 10; const ShCompileOptions SH_CLAMP_INDIRECT_ARRAY_BOUNDS = UINT64_C(1) << 11;
// 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) << 11; const ShCompileOptions SH_LIMIT_EXPRESSION_COMPLEXITY = UINT64_C(1) << 12;
// 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) << 12; const ShCompileOptions SH_LIMIT_CALL_STACK_DEPTH = UINT64_C(1) << 13;
// 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) << 13; const ShCompileOptions SH_INIT_GL_POSITION = UINT64_C(1) << 14;
// 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) << 14; const ShCompileOptions SH_UNFOLD_SHORT_CIRCUIT = UINT64_C(1) << 15;
// 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) << 15; const ShCompileOptions SH_INIT_OUTPUT_VARIABLES = UINT64_C(1) << 16;
// 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) << 16; const ShCompileOptions SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS = UINT64_C(1) << 17;
// 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) << 17; const ShCompileOptions SH_REGENERATE_STRUCT_NAMES = UINT64_C(1) << 18;
// 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 // This flag works around a bug in NVIDIA 331 series drivers related
// to pow(x, y) where y is a constant vector. // to pow(x, y) where y is a constant vector.
...@@ -301,61 +299,56 @@ const ShCompileOptions SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING = UINT64_C(1) << 44; ...@@ -301,61 +299,56 @@ const ShCompileOptions SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING = UINT64_C(1) << 44;
// 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) << 45;
// If requested, validates the AST after every transformation. Useful for debugging.
const ShCompileOptions SH_VALIDATE_AST = UINT64_C(1) << 46;
// Bit 47 is available
// 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) << 48; const ShCompileOptions SH_ADD_BASE_VERTEX_TO_VERTEX_ID = UINT64_C(1) << 46;
// 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) << 49; const ShCompileOptions SH_REMOVE_DYNAMIC_INDEXING_OF_SWIZZLED_VECTOR = UINT64_C(1) << 47;
// 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) << 50; const ShCompileOptions SH_ALLOW_TRANSLATE_UNIFORM_BLOCK_TO_STRUCTUREDBUFFER = UINT64_C(1) << 48;
// 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) << 51; const ShCompileOptions SH_ADD_BRESENHAM_LINE_RASTER_EMULATION = UINT64_C(1) << 49;
// 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) << 52; const ShCompileOptions SH_DISABLE_ARB_TEXTURE_RECTANGLE = UINT64_C(1) << 50;
// 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) << 53; const ShCompileOptions SH_REWRITE_ROW_MAJOR_MATRICES = UINT64_C(1) << 51;
// Drop any explicit precision qualifiers from shader. // Drop any explicit precision qualifiers from shader.
const ShCompileOptions SH_IGNORE_PRECISION_QUALIFIERS = UINT64_C(1) << 54; const ShCompileOptions SH_IGNORE_PRECISION_QUALIFIERS = UINT64_C(1) << 52;
// 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) << 55; const ShCompileOptions SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION = UINT64_C(1) << 53;
// 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) << 56; const ShCompileOptions SH_ADD_PRE_ROTATION = UINT64_C(1) << 54;
const ShCompileOptions SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP = UINT64_C(1) << 57; const ShCompileOptions SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP = UINT64_C(1) << 55;
// 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) << 58; const ShCompileOptions SH_USE_SPECIALIZATION_CONSTANT = UINT64_C(1) << 56;
// 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) << 59; const ShCompileOptions SH_ADD_VULKAN_XFB_EMULATION_SUPPORT_CODE = UINT64_C(1) << 57;
// 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) << 60; const ShCompileOptions SH_ADD_VULKAN_XFB_EXTENSION_SUPPORT_CODE = UINT64_C(1) << 58;
// 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) << 61; const ShCompileOptions SH_INIT_FRAGMENT_OUTPUT_VARIABLES = UINT64_C(1) << 59;
// Defines alternate strategies for implementing array index clamping. // Defines alternate strategies for implementing array index clamping.
enum ShArrayIndexClampingStrategy enum ShArrayIndexClampingStrategy
......
...@@ -30,14 +30,14 @@ constexpr ShCompileOptions kCommonOptions = ...@@ -30,14 +30,14 @@ constexpr ShCompileOptions kCommonOptions =
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_DONT_PRUNE_UNUSED_FUNCTIONS | SH_REMOVE_POW_WITH_CONSTANT_EXPONENT | 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;
......
...@@ -634,10 +634,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -634,10 +634,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
return false; return false;
} }
if ((compileOptions & SH_DONT_PRUNE_UNUSED_FUNCTIONS) == 0) pruneUnusedFunctions(root);
{
pruneUnusedFunctions(root);
}
if (IsSpecWithFunctionBodyNewScope(mShaderSpec, mShaderVersion)) if (IsSpecWithFunctionBodyNewScope(mShaderSpec, mShaderVersion))
{ {
if (!ReplaceShadowingVariables(this, root, &mSymbolTable)) if (!ReplaceShadowingVariables(this, root, &mSymbolTable))
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
// PruneUnusedFunctions_test.cpp: // PruneUnusedFunctions_test.cpp:
// Test for the pruning of unused function with the SH_PRUNE_UNUSED_FUNCTIONS compile flag // Test for the pruning of unused functions
// //
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
...@@ -23,9 +23,9 @@ class PruneUnusedFunctionsTest : public MatchOutputCodeTest ...@@ -23,9 +23,9 @@ class PruneUnusedFunctionsTest : public MatchOutputCodeTest
PruneUnusedFunctionsTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, 0, SH_ESSL_OUTPUT) {} PruneUnusedFunctionsTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, 0, SH_ESSL_OUTPUT) {}
protected: protected:
void compile(const std::string &shaderString, bool prune) void compile(const std::string &shaderString)
{ {
int compilationFlags = SH_VARIABLES | (prune ? 0 : SH_DONT_PRUNE_UNUSED_FUNCTIONS); int compilationFlags = SH_VARIABLES;
MatchOutputCodeTest::compile(shaderString, compilationFlags); MatchOutputCodeTest::compile(shaderString, compilationFlags);
} }
}; };
...@@ -42,13 +42,9 @@ TEST_F(PruneUnusedFunctionsTest, UnusedFunctionAndProto) ...@@ -42,13 +42,9 @@ TEST_F(PruneUnusedFunctionsTest, UnusedFunctionAndProto)
"float unused(float a) {\n" "float unused(float a) {\n"
" return a;\n" " return a;\n"
"}\n"; "}\n";
compile(shaderString, true); compile(shaderString);
EXPECT_TRUE(notFoundInCode("unused(")); EXPECT_TRUE(notFoundInCode("unused("));
EXPECT_TRUE(foundInCode("main(", 1)); EXPECT_TRUE(foundInCode("main(", 1));
compile(shaderString, false);
EXPECT_TRUE(foundInCode("unused(", 2));
EXPECT_TRUE(foundInCode("main(", 1));
} }
// Check that unimplemented prototypes are removed iff the options is set // Check that unimplemented prototypes are removed iff the options is set
...@@ -60,13 +56,9 @@ TEST_F(PruneUnusedFunctionsTest, UnimplementedPrototype) ...@@ -60,13 +56,9 @@ TEST_F(PruneUnusedFunctionsTest, UnimplementedPrototype)
"void main() {\n" "void main() {\n"
" gl_FragColor = vec4(1.0);\n" " gl_FragColor = vec4(1.0);\n"
"}\n"; "}\n";
compile(shaderString, true); compile(shaderString);
EXPECT_TRUE(notFoundInCode("unused(")); EXPECT_TRUE(notFoundInCode("unused("));
EXPECT_TRUE(foundInCode("main(", 1)); EXPECT_TRUE(foundInCode("main(", 1));
compile(shaderString, false);
EXPECT_TRUE(foundInCode("unused(", 1));
EXPECT_TRUE(foundInCode("main(", 1));
} }
// Check that used functions are not pruned (duh) // Check that used functions are not pruned (duh)
...@@ -81,11 +73,7 @@ TEST_F(PruneUnusedFunctionsTest, UsedFunction) ...@@ -81,11 +73,7 @@ TEST_F(PruneUnusedFunctionsTest, UsedFunction)
"float used(float a) {\n" "float used(float a) {\n"
" return a;\n" " return a;\n"
"}\n"; "}\n";
compile(shaderString, true); compile(shaderString);
EXPECT_TRUE(foundInCode("used(", 3));
EXPECT_TRUE(foundInCode("main(", 1));
compile(shaderString, false);
EXPECT_TRUE(foundInCode("used(", 3)); EXPECT_TRUE(foundInCode("used(", 3));
EXPECT_TRUE(foundInCode("main(", 1)); EXPECT_TRUE(foundInCode("main(", 1));
} }
......
...@@ -598,33 +598,6 @@ TEST_F(RemoveUnreferencedVariablesTest, UserDefinedTypeReferencedInUnusedFunctio ...@@ -598,33 +598,6 @@ TEST_F(RemoveUnreferencedVariablesTest, UserDefinedTypeReferencedInUnusedFunctio
ASSERT_TRUE(notFoundInCode("myStructType")); ASSERT_TRUE(notFoundInCode("myStructType"));
} }
// Test that a struct type that is only referenced in an unused function is kept in case
// SH_DONT_PRUNE_UNUSED_FUNCTIONS is specified.
TEST_F(RemoveUnreferencedVariablesTest, UserDefinedTypeReferencedInUnusedFunctionThatIsNotPruned)
{
const std::string &shaderString =
R"(
struct myStructType
{
int iMember;
};
myStructType func()
{
return myStructType(0);
}
void main()
{
})";
compile(shaderString, SH_DONT_PRUNE_UNUSED_FUNCTIONS);
ASSERT_TRUE(foundInCode("struct _umyStructType"));
// Ensure that the struct isn't declared as a part of the function header.
ASSERT_TRUE(foundInCode("};"));
}
// Test that a struct type that is only referenced as a function return value is kept. // Test that a struct type that is only referenced as a function return value is kept.
TEST_F(RemoveUnreferencedVariablesTest, UserDefinedTypeReturnedFromFunction) TEST_F(RemoveUnreferencedVariablesTest, UserDefinedTypeReturnedFromFunction)
{ {
......
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