Commit 90892fbd by Olli Etuaho Committed by Commit Bot

Refine swizzle/indexing constant folding code

Fix constant folding of subscripting non-square matrices. Previously constant folding would offset the pointer into the matrix in multiples of the number of columns, when it should offset the pointer in multiples of the number of rows. Also change the MalformedShaderTest so that it only succeeds if vector swizzle is being checked correctly. Previously compilation would fail in the test either way because the shader code contained a call to an undefined function. Also refactor indexing checks and constant folding so that constant folding is done entirely separately from out-of-range checks. Bogus comments are removed from the constant folding functions. BUG=angleproject:1444 TEST=angle_unittests, angle_end2end_tests Change-Id: I7073b38f759e9b3635ee05947df4f6d8e23a39d5 Reviewed-on: https://chromium-review.googlesource.com/360112Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 313d9447
...@@ -253,18 +253,7 @@ class TParseContext : angle::NonCopyable ...@@ -253,18 +253,7 @@ class TParseContext : angle::NonCopyable
TOperator op, TOperator op,
TFunction *fnCall, TFunction *fnCall,
const TSourceLoc &line); const TSourceLoc &line);
TIntermTyped *addConstVectorNode(TVectorFields &fields,
TIntermConstantUnion *node,
const TSourceLoc &line,
bool outOfRangeIndexIsError);
TIntermTyped *addConstMatrixNode(int index,
TIntermConstantUnion *node,
const TSourceLoc &line,
bool outOfRangeIndexIsError);
TIntermTyped *addConstArrayNode(int index,
TIntermConstantUnion *node,
const TSourceLoc &line,
bool outOfRangeIndexIsError);
TIntermTyped *addConstStruct( TIntermTyped *addConstStruct(
const TString &identifier, TIntermTyped *node, const TSourceLoc& line); const TString &identifier, TIntermTyped *node, const TSourceLoc& line);
TIntermTyped *addIndexExpression(TIntermTyped *baseExpression, TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
...@@ -342,6 +331,26 @@ class TParseContext : angle::NonCopyable ...@@ -342,6 +331,26 @@ class TParseContext : angle::NonCopyable
TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
private: private:
// Returns a clamped index.
int checkIndexOutOfRange(bool outOfRangeIndexIsError,
const TSourceLoc &location,
int index,
int arraySize,
const char *reason,
const char *token);
// Constant folding for element access. Note that the returned node does not have the correct
// type - it is expected to be fixed later.
TIntermConstantUnion *foldVectorSwizzle(TVectorFields &fields,
TIntermConstantUnion *baseNode,
const TSourceLoc &location);
TIntermConstantUnion *foldMatrixSubscript(int index,
TIntermConstantUnion *baseNode,
const TSourceLoc &location);
TIntermConstantUnion *foldArraySubscript(int index,
TIntermConstantUnion *baseNode,
const TSourceLoc &location);
bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable); bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
bool nonInitErrorCheck(const TSourceLoc &line, const TString &identifier, TPublicType *type); bool nonInitErrorCheck(const TSourceLoc &line, const TString &identifier, TPublicType *type);
......
...@@ -744,3 +744,20 @@ TEST_F(ConstantFoldingTest, FoldNestedIdenticalStructEqualityComparison) ...@@ -744,3 +744,20 @@ TEST_F(ConstantFoldingTest, FoldNestedIdenticalStructEqualityComparison)
compile(shaderString); compile(shaderString);
ASSERT_TRUE(constantFoundInAST(1.0f)); ASSERT_TRUE(constantFoundInAST(1.0f));
} }
// Test that right elements are chosen from non-square matrix
TEST_F(ConstantFoldingTest, FoldNonSquareMatrixIndexing)
{
const std::string &shaderString =
"#version 300 es\n"
"precision mediump float;\n"
"out vec4 my_FragColor;\n"
"void main()\n"
"{\n"
" my_FragColor = mat3x4(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)[1];\n"
"}\n";
compile(shaderString);
float outputElements[] = {4.0f, 5.0f, 6.0f, 7.0f};
std::vector<float> result(outputElements, outputElements + 4);
ASSERT_TRUE(constantVectorFoundInAST(result));
}
...@@ -1611,12 +1611,12 @@ TEST_F(MalformedShaderTest, CompoundMultiplyMatrixValidNonSquareDimensions) ...@@ -1611,12 +1611,12 @@ TEST_F(MalformedShaderTest, CompoundMultiplyMatrixValidNonSquareDimensions)
} }
} }
// Covers a bug where we would set the incorrect result size on an out-of-bounds vector sizzle. // Covers a bug where we would set the incorrect result size on an out-of-bounds vector swizzle.
TEST_F(MalformedShaderTest, OutOfBoundsVectorSwizzle) TEST_F(MalformedShaderTest, OutOfBoundsVectorSwizzle)
{ {
const std::string &shaderString = const std::string &shaderString =
"void main() {\n" "void main() {\n"
" vec2(0).qq * a(b);\n" " vec2(0).qq;\n"
"}\n"; "}\n";
if (compile(shaderString)) if (compile(shaderString))
{ {
......
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