Commit 2f4823bf by Jamie Madill

Revert "Add constant folding support for geometric built-ins"

Breaks Mac build because of C++11 init syntax: FAILED: /b/build/goma/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/third_party/angle/src/tests/compiler_tests/angle_unittests.ConstantFolding_test.o.d -DV8_DEPRECATION_WARNINGS -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0 -DCHROMIUM_BUILD -DCR_CLANG_REVISION=238013-3 -DCOMPONENT_BUILD -DTOOLKIT_VIEWS=1 -DUSE_LIBJPEG_TURBO=1 -DENABLE_ONE_CLICK_SIGNIN -DENABLE_PRE_SYNC_BACKUP -DENABLE_REMOTING=1 -DENABLE_WEBRTC=1 -DENABLE_MEDIA_ROUTER=1 -DUSE_PROPRIETARY_CODECS -DENABLE_PEPPER_CDMS -DENABLE_CONFIGURATION_POLICY -DENABLE_NOTIFICATIONS -DENABLE_HIDPI=1 -DSYSTEM_NATIVELY_SIGNALS_MEMORY_PRESSURE -DDONT_EMBED_BUILD_METADATA -DDCHECK_ALWAYS_ON=1 -DENABLE_TASK_MANAGER=1 -DENABLE_EXTENSIONS=1 -DENABLE_PLUGIN_INSTALLATION=1 -DENABLE_PLUGINS=1 -DENABLE_SESSION_SERVICE=1 -DENABLE_THEMES=1 -DENABLE_AUTOFILL_DIALOG=1 -DENABLE_BACKGROUND=1 -DENABLE_GOOGLE_NOW=1 -DCLD_VERSION=2 -DENABLE_PRINTING=1 -DENABLE_BASIC_PRINTING=1 -DENABLE_PRINT_PREVIEW=1 -DENABLE_SPELLCHECK=1 -DENABLE_CAPTIVE_PORTAL_DETECTION=1 -DENABLE_APP_LIST=1 -DENABLE_SETTINGS_APP=1 -DENABLE_SUPERVISED_USERS=1 -DENABLE_SERVICE_DISCOVERY=1 -DENABLE_WIFI_BOOTSTRAPPING=1 -DV8_USE_EXTERNAL_STARTUP_DATA -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DSAFE_BROWSING_SERVICE -DGTEST_HAS_POSIX_RE=0 -DGTEST_LANG_CXX11=0 -DGL_APICALL= -DGL_GLEXT_PROTOTYPES= -DEGLAPI= '-DANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ "d3dcompiler_47.dll", "d3dcompiler_46.dll", "d3dcompiler_43.dll" }' -DANGLE_TRANSLATOR_STATIC -DUSE_LIBPCI=1 -DUSE_OPENSSL=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -Igen -I../.. -I../../third_party/angle/include -I../../third_party/angle/src -I../../third_party/angle/src/compiler/preprocessor -I../../third_party/angle/src/tests -Igen/angle -I../../testing/gmock/include -I../../testing/gtest/include -isysroot /Applications/Xcode5.1.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -O0 -gdwarf-2 -fvisibility=hidden -Werror -Wnewline-eof -mmacosx-version-min=10.6 -arch x86_64 -Wall -Wendif-labels -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-selector-type-mismatch -Wpartial-availability -Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration -Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing -Wno-deprecated-register -Wno-inconsistent-missing-override -std=c++11 -fno-rtti -fno-exceptions -fvisibility-inlines-hidden -fno-threadsafe-statics -Xclang -load -Xclang /b/build/slave/GPU_Mac_Builder__dbg_/build/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.dylib -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-templates -fcolor-diagnostics -fno-strict-aliasing -fstack-protector-all -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare -c ../../third_party/angle/src/tests/compiler_tests/ConstantFolding_test.cpp -o obj/third_party/angle/src/tests/compiler_tests/angle_unittests.ConstantFolding_test.o ../../third_party/angle/src/tests/compiler_tests/ConstantFolding_test.cpp:210:43: error: no matching constructor for initialization of 'std::vector<float>' ASSERT_FALSE(constantVectorFoundInAST(std::vector<float>{1.0f, 1.0f, 1.0f})); ^ ~~~~~~~~~~~~~~~~~~ BUG=angleproject:913 This reverts commit 2decb4b1. Change-Id: Iaf3c61a0c0ed591c17f50f2e3eafe2debf588c95 Reviewed-on: https://chromium-review.googlesource.com/274917Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 2decb4b1
......@@ -168,25 +168,6 @@ void UndefinedConstantFoldingError(const TSourceLoc &loc, TOperator op, TBasicTy
}
}
float VectorLength(TConstantUnion *paramArray, size_t paramArraySize)
{
float result = 0.0f;
for (size_t i = 0; i < paramArraySize; i++)
{
float f = paramArray[i].getFConst();
result += f * f;
}
return sqrtf(result);
}
float VectorDotProduct(TConstantUnion *paramArray1, TConstantUnion *paramArray2, size_t paramArraySize)
{
float result = 0.0f;
for (size_t i = 0; i < paramArraySize; i++)
result += paramArray1[i].getFConst() * paramArray2[i].getFConst();
return result;
}
} // namespace anonymous
......@@ -1182,15 +1163,14 @@ TIntermTyped *TIntermConstantUnion::fold(
return tempNode;
}
else if (op == EOpAny || op == EOpAll || op == EOpLength)
else if (op == EOpAny || op == EOpAll)
{
// Do operations where the return type is different from the operand type.
TType returnType;
TType returnType(EbtBool, EbpUndefined, EvqConst);
TConstantUnion *tempConstArray = nullptr;
switch (op)
if (op == EOpAny)
{
case EOpAny:
if (getType().getBasicType() == EbtBool)
{
tempConstArray = new TConstantUnion();
......@@ -1203,16 +1183,17 @@ TIntermTyped *TIntermConstantUnion::fold(
break;
}
}
returnType = TType(EbtBool, EbpUndefined, EvqConst);
break;
}
else
{
infoSink.info.message(EPrefixInternalError, getLine(), "Unary operation not folded into constant");
infoSink.info.message(
EPrefixInternalError, getLine(),
"Unary operation not folded into constant");
return nullptr;
}
case EOpAll:
}
else if (op == EOpAll)
{
if (getType().getBasicType() == EbtBool)
{
tempConstArray = new TConstantUnion();
......@@ -1225,33 +1206,15 @@ TIntermTyped *TIntermConstantUnion::fold(
break;
}
}
returnType = TType(EbtBool, EbpUndefined, EvqConst);
break;
}
else
{
infoSink.info.message(EPrefixInternalError, getLine(), "Unary operation not folded into constant");
return nullptr;
}
case EOpLength:
if (getType().getBasicType() == EbtFloat)
{
tempConstArray = new TConstantUnion();
tempConstArray->setFConst(VectorLength(unionArray, objectSize));
returnType = TType(EbtFloat, getType().getPrecision(), EvqConst);
break;
}
else
{
infoSink.info.message(EPrefixInternalError, getLine(), "Unary operation not folded into constant");
infoSink.info.message(
EPrefixInternalError, getLine(),
"Unary operation not folded into constant");
return nullptr;
}
default:
break;
}
TIntermConstantUnion *tempNode = new TIntermConstantUnion(tempConstArray, returnType);
tempNode->setLine(getLine());
return tempNode;
......@@ -1596,20 +1559,6 @@ TIntermTyped *TIntermConstantUnion::fold(
"Unary operation not folded into constant");
return nullptr;
case EOpNormalize:
if (getType().getBasicType() == EbtFloat)
{
float x = unionArray[i].getFConst();
float length = VectorLength(unionArray, objectSize);
if (length)
tempConstArray[i].setFConst(x / length);
else
UndefinedConstantFoldingError(getLine(), op, getType().getBasicType(), infoSink, &tempConstArray[i]);
break;
}
infoSink.info.message(EPrefixInternalError, getLine(), "Unary operation not folded into constant");
return nullptr;
default:
return nullptr;
}
......@@ -1953,70 +1902,6 @@ TIntermTyped *TIntermConstantUnion::FoldAggregateBuiltIn(TOperator op, TIntermAg
}
break;
case EOpDistance:
if (basicType == EbtFloat)
{
TConstantUnion *distanceArray = new TConstantUnion[maxObjectSize];
tempConstArray = new TConstantUnion();
for (size_t i = 0; i < maxObjectSize; i++)
{
float x = unionArrays[0][i].getFConst();
float y = unionArrays[1][i].getFConst();
distanceArray[i].setFConst(x - y);
}
tempConstArray->setFConst(VectorLength(distanceArray, maxObjectSize));
}
else
UNREACHABLE();
break;
case EOpDot:
if (basicType == EbtFloat)
{
tempConstArray = new TConstantUnion();
tempConstArray->setFConst(VectorDotProduct(unionArrays[0], unionArrays[1], maxObjectSize));
}
else
UNREACHABLE();
break;
case EOpCross:
if (basicType == EbtFloat && maxObjectSize == 3)
{
tempConstArray = new TConstantUnion[maxObjectSize];
float x0 = unionArrays[0][0].getFConst();
float x1 = unionArrays[0][1].getFConst();
float x2 = unionArrays[0][2].getFConst();
float y0 = unionArrays[1][0].getFConst();
float y1 = unionArrays[1][1].getFConst();
float y2 = unionArrays[1][2].getFConst();
tempConstArray[0].setFConst(x1 * y2 - y1 * x2);
tempConstArray[1].setFConst(x2 * y0 - y2 * x0);
tempConstArray[2].setFConst(x0 * y1 - y0 * x1);
}
else
UNREACHABLE();
break;
case EOpReflect:
if (basicType == EbtFloat)
{
// genType reflect (genType I, genType N) :
// For the incident vector I and surface orientation N, returns the reflection direction:
// I - 2 * dot(N, I) * N.
tempConstArray = new TConstantUnion[maxObjectSize];
float dotProduct = VectorDotProduct(unionArrays[1], unionArrays[0], maxObjectSize);
for (size_t i = 0; i < maxObjectSize; i++)
{
float result = unionArrays[0][i].getFConst() -
2.0f * dotProduct * unionArrays[1][i].getFConst();
tempConstArray[i].setFConst(result);
}
}
else
UNREACHABLE();
break;
default:
UNREACHABLE();
// TODO: Add constant folding support for other built-in operations that take 2 parameters and not handled above.
......@@ -2142,53 +2027,6 @@ TIntermTyped *TIntermConstantUnion::FoldAggregateBuiltIn(TOperator op, TIntermAg
}
break;
case EOpFaceForward:
if (basicType == EbtFloat)
{
// genType faceforward(genType N, genType I, genType Nref) :
// If dot(Nref, I) < 0 return N, otherwise return -N.
tempConstArray = new TConstantUnion[maxObjectSize];
float dotProduct = VectorDotProduct(unionArrays[2], unionArrays[1], maxObjectSize);
for (size_t i = 0; i < maxObjectSize; i++)
{
if (dotProduct < 0)
tempConstArray[i].setFConst(unionArrays[0][i].getFConst());
else
tempConstArray[i].setFConst(-unionArrays[0][i].getFConst());
}
}
else
UNREACHABLE();
break;
case EOpRefract:
if (basicType == EbtFloat)
{
// genType refract(genType I, genType N, float eta) :
// For the incident vector I and surface normal N, and the ratio of indices of refraction eta,
// return the refraction vector. The result is computed by
// k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
// if (k < 0.0)
// return genType(0.0)
// else
// return eta * I - (eta * dot(N, I) + sqrt(k)) * N
tempConstArray = new TConstantUnion[maxObjectSize];
float dotProduct = VectorDotProduct(unionArrays[1], unionArrays[0], maxObjectSize);
for (size_t i = 0; i < maxObjectSize; i++)
{
float eta = unionArrays[2][i].getFConst();
float k = 1.0f - eta * eta * (1.0f - dotProduct * dotProduct);
if (k < 0.0f)
tempConstArray[i].setFConst(0.0f);
else
tempConstArray[i].setFConst(eta * unionArrays[0][i].getFConst() -
(eta * dotProduct + sqrtf(k)) * unionArrays[1][i].getFConst());
}
}
else
UNREACHABLE();
break;
default:
UNREACHABLE();
// TODO: Add constant folding support for other built-in operations that take 3 parameters and not handled above.
......
......@@ -477,12 +477,6 @@ TIntermTyped *TIntermediate::foldAggregateBuiltIn(TOperator op, TIntermAggregate
case EOpGreaterThanEqual:
case EOpVectorEqual:
case EOpVectorNotEqual:
case EOpDistance:
case EOpDot:
case EOpCross:
case EOpFaceForward:
case EOpReflect:
case EOpRefract:
return TIntermConstantUnion::FoldAggregateBuiltIn(op, aggregate, mInfoSink);
default:
// Constant folding not supported for the built-in.
......
......@@ -13,46 +13,26 @@
#include "compiler/translator/PoolAlloc.h"
#include "compiler/translator/TranslatorESSL.h"
#include <vector>
template <typename T>
class ConstantFinder : public TIntermTraverser
{
public:
ConstantFinder(const std::vector<T> &constantVector)
: mConstantVector(constantVector),
mFound(false)
{}
ConstantFinder(const T &value)
: mConstantVector(std::vector<T>{value}),
ConstantFinder(TConstantUnion constToFind)
: mConstToFind(constToFind),
mFound(false)
{}
virtual void visitConstantUnion(TIntermConstantUnion *node)
{
if (node->getType().getObjectSize() == mConstantVector.size())
if (node->getUnionArrayPointer()[0] == mConstToFind)
{
bool found = true;
for (size_t i = 0; i < mConstantVector.size(); i++)
{
if (node->getUnionArrayPointer()[i] != mConstantVector[i])
{
found = false;
break;
}
}
if (found)
{
mFound = found;
}
mFound = true;
}
}
bool found() const { return mFound; }
private:
std::vector<T> mConstantVector;
TConstantUnion mConstToFind;
bool mFound;
};
......@@ -92,20 +72,18 @@ class ConstantFoldingTest : public testing::Test
}
}
template <typename T>
bool constantFoundInAST(T constant)
bool constantFoundInAST(TConstantUnion c)
{
ConstantFinder<T> finder(constant);
ConstantFinder finder(c);
mASTRoot->traverse(&finder);
return finder.found();
}
template <typename T>
bool constantVectorFoundInAST(const std::vector<T> &constantVector)
bool constantFoundInAST(int i)
{
ConstantFinder<T> finder(constantVector);
mASTRoot->traverse(&finder);
return finder.found();
TConstantUnion c;
c.setIConst(i);
return constantFoundInAST(c);
}
private:
......@@ -195,19 +173,3 @@ TEST_F(ConstantFoldingTest, FoldIntegerModulus)
ASSERT_FALSE(constantFoundInAST(5));
ASSERT_TRUE(constantFoundInAST(4));
}
TEST_F(ConstantFoldingTest, FoldVectorCrossProduct)
{
const std::string &shaderString =
"#version 300 es\n"
"precision mediump float;\n"
"out vec3 my_Vec3;"
"void main() {\n"
" const vec3 v3 = cross(vec3(1.0f, 1.0f, 1.0f), vec3(1.0f, -1.0f, 1.0f));\n"
" my_Vec3 = v3;\n"
"}\n";
compile(shaderString);
ASSERT_FALSE(constantVectorFoundInAST(std::vector<float>{1.0f, 1.0f, 1.0f}));
ASSERT_FALSE(constantVectorFoundInAST(std::vector<float>{1.0f, -1.0f, 1.0f}));
ASSERT_TRUE(constantVectorFoundInAST(std::vector<float>{2.0f, 0.0f, -2.0f}));
}
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