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
...@@ -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