Commit 60305f14 by Jamie Madill

Fix error in dumping direct struct indexes.

The parser would become confused over the purported array size of struct indexes. In reality they were always a single direct index into a struct, but it would take the object size of the represented type (EG, a vec4 would have size 4) and deference out-of-bounds memory. BUG=434033 Change-Id: I92349aa04e6faadc766cb28c04e28d5f19c4e1ec Reviewed-on: https://chromium-review.googlesource.com/230530Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org>
parent 53a1f4a0
...@@ -211,6 +211,36 @@ bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary *node) ...@@ -211,6 +211,36 @@ bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary *node)
out << "\n"; out << "\n";
// Special handling for direct indexes. Because constant
// unions are not aware they are struct indexes, treat them
// here where we have that contextual knowledge.
if (node->getOp() == EOpIndexDirectStruct ||
node->getOp() == EOpIndexDirectInterfaceBlock)
{
mDepth++;
node->getLeft()->traverse(this);
mDepth--;
TIntermConstantUnion *intermConstantUnion = node->getRight()->getAsConstantUnion();
ASSERT(intermConstantUnion);
OutputTreeText(out, intermConstantUnion, mDepth + 1);
// The following code finds the field name from the constant union
const ConstantUnion *constantUnion = intermConstantUnion->getUnionArrayPointer();
const TStructure *structure = node->getLeft()->getType().getStruct();
const TInterfaceBlock *interfaceBlock = node->getLeft()->getType().getInterfaceBlock();
ASSERT(structure || interfaceBlock);
const TFieldList &fields = structure ? structure->fields() : interfaceBlock->fields();
const TField *field = fields[constantUnion->getIConst()];
out << constantUnion->getIConst() << " (field '" << field->name() << "')";
return false;
}
return true; return true;
} }
......
...@@ -43,7 +43,12 @@ class TypeTrackingTest : public testing::Test ...@@ -43,7 +43,12 @@ class TypeTrackingTest : public testing::Test
FAIL() << "Shader compilation failed " << mInfoLog; FAIL() << "Shader compilation failed " << mInfoLog;
} }
bool foundInIntermediateTree(const char* stringToFind) bool foundErrorInIntermediateTree() const
{
return foundInIntermediateTree("ERROR:");
}
bool foundInIntermediateTree(const char* stringToFind) const
{ {
return mInfoLog.find(stringToFind) != std::string::npos; return mInfoLog.find(stringToFind) != std::string::npos;
} }
...@@ -67,6 +72,7 @@ TEST_F(TypeTrackingTest, FunctionPrototypeMangling) ...@@ -67,6 +72,7 @@ TEST_F(TypeTrackingTest, FunctionPrototypeMangling)
" return a * 2.0;\n" " return a * 2.0;\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("Function Prototype: fun(f1;")); ASSERT_TRUE(foundInIntermediateTree("Function Prototype: fun(f1;"));
ASSERT_TRUE(foundInIntermediateTree("Function Definition: fun(f1;")); ASSERT_TRUE(foundInIntermediateTree("Function Definition: fun(f1;"));
}; };
...@@ -81,6 +87,7 @@ TEST_F(TypeTrackingTest, BuiltInFunctionResultPrecision) ...@@ -81,6 +87,7 @@ TEST_F(TypeTrackingTest, BuiltInFunctionResultPrecision)
" gl_FragColor = vec4(ff);\n" " gl_FragColor = vec4(ff);\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("sine (mediump float)")); ASSERT_TRUE(foundInIntermediateTree("sine (mediump float)"));
}; };
...@@ -94,6 +101,7 @@ TEST_F(TypeTrackingTest, BinaryMathResultPrecision) ...@@ -94,6 +101,7 @@ TEST_F(TypeTrackingTest, BinaryMathResultPrecision)
" gl_FragColor = vec4(ff);\n" " gl_FragColor = vec4(ff);\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("multiply (mediump float)")); ASSERT_TRUE(foundInIntermediateTree("multiply (mediump float)"));
}; };
...@@ -109,6 +117,7 @@ TEST_F(TypeTrackingTest, BuiltInVecFunctionResultTypeAndPrecision) ...@@ -109,6 +117,7 @@ TEST_F(TypeTrackingTest, BuiltInVecFunctionResultTypeAndPrecision)
" gl_FragColor = vec4(b, c, d, 1.0);\n" " gl_FragColor = vec4(b, c, d, 1.0);\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("length (mediump float)")); ASSERT_TRUE(foundInIntermediateTree("length (mediump float)"));
ASSERT_TRUE(foundInIntermediateTree("dot-product (mediump float)")); ASSERT_TRUE(foundInIntermediateTree("dot-product (mediump float)"));
ASSERT_TRUE(foundInIntermediateTree("distance (mediump float)")); ASSERT_TRUE(foundInIntermediateTree("distance (mediump float)"));
...@@ -126,6 +135,7 @@ TEST_F(TypeTrackingTest, BuiltInFunctionChoosesHigherPrecision) ...@@ -126,6 +135,7 @@ TEST_F(TypeTrackingTest, BuiltInFunctionChoosesHigherPrecision)
" gl_FragColor = vec4(c, d, 0.0, 1.0);\n" " gl_FragColor = vec4(c, d, 0.0, 1.0);\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("dot-product (mediump float)")); ASSERT_TRUE(foundInIntermediateTree("dot-product (mediump float)"));
ASSERT_TRUE(foundInIntermediateTree("distance (mediump float)")); ASSERT_TRUE(foundInIntermediateTree("distance (mediump float)"));
}; };
...@@ -141,6 +151,7 @@ TEST_F(TypeTrackingTest, BuiltInBoolFunctionResultType) ...@@ -141,6 +151,7 @@ TEST_F(TypeTrackingTest, BuiltInBoolFunctionResultType)
" gl_FragColor = vec4(b ? 1.0 : 0.0, c ? 1.0 : 0.0, d.x ? 1.0 : 0.0, 1.0);\n" " gl_FragColor = vec4(b ? 1.0 : 0.0, c ? 1.0 : 0.0, d.x ? 1.0 : 0.0, 1.0);\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("any (bool)")); ASSERT_TRUE(foundInIntermediateTree("any (bool)"));
ASSERT_TRUE(foundInIntermediateTree("all (bool)")); ASSERT_TRUE(foundInIntermediateTree("all (bool)"));
ASSERT_TRUE(foundInIntermediateTree("Negate conditional (4-component vector of bool)")); ASSERT_TRUE(foundInIntermediateTree("Negate conditional (4-component vector of bool)"));
...@@ -160,6 +171,7 @@ TEST_F(TypeTrackingTest, BuiltInVecToBoolFunctionResultType) ...@@ -160,6 +171,7 @@ TEST_F(TypeTrackingTest, BuiltInVecToBoolFunctionResultType)
" gl_FragColor = vec4(any(a) ? 1.0 : 0.0, any(b) ? 1.0 : 0.0, 0.0, 1.0);\n" " gl_FragColor = vec4(any(a) ? 1.0 : 0.0, any(b) ? 1.0 : 0.0, 0.0, 1.0);\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("Less Than (2-component vector of bool)")); ASSERT_TRUE(foundInIntermediateTree("Less Than (2-component vector of bool)"));
ASSERT_TRUE(foundInIntermediateTree("Greater Than (2-component vector of bool)")); ASSERT_TRUE(foundInIntermediateTree("Greater Than (2-component vector of bool)"));
}; };
...@@ -177,6 +189,7 @@ TEST_F(TypeTrackingTest, Texture2DResultTypeAndPrecision) ...@@ -177,6 +189,7 @@ TEST_F(TypeTrackingTest, Texture2DResultTypeAndPrecision)
" gl_FragColor = c;\n" " gl_FragColor = c;\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("texture2D(s21;vf2; (lowp 4-component vector of float)")); ASSERT_TRUE(foundInIntermediateTree("texture2D(s21;vf2; (lowp 4-component vector of float)"));
}; };
...@@ -193,6 +206,7 @@ TEST_F(TypeTrackingTest, TextureCubeResultTypeAndPrecision) ...@@ -193,6 +206,7 @@ TEST_F(TypeTrackingTest, TextureCubeResultTypeAndPrecision)
" gl_FragColor = c;\n" " gl_FragColor = c;\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("textureCube(sC1;vf3; (lowp 4-component vector of float)")); ASSERT_TRUE(foundInIntermediateTree("textureCube(sC1;vf3; (lowp 4-component vector of float)"));
}; };
...@@ -213,6 +227,7 @@ TEST_F(TypeTrackingTest, TextureSizeResultTypeAndPrecision) ...@@ -213,6 +227,7 @@ TEST_F(TypeTrackingTest, TextureSizeResultTypeAndPrecision)
" }\n" " }\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("textureSize(s21;i1; (highp 2-component vector of int)")); ASSERT_TRUE(foundInIntermediateTree("textureSize(s21;i1; (highp 2-component vector of int)"));
}; };
...@@ -229,6 +244,7 @@ TEST_F(TypeTrackingTest, BuiltInConstructorResultTypeAndPrecision) ...@@ -229,6 +244,7 @@ TEST_F(TypeTrackingTest, BuiltInConstructorResultTypeAndPrecision)
" gl_FragColor = a;\n" " gl_FragColor = a;\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("Construct vec4 (mediump 4-component vector of float)")); ASSERT_TRUE(foundInIntermediateTree("Construct vec4 (mediump 4-component vector of float)"));
}; };
...@@ -244,5 +260,6 @@ TEST_F(TypeTrackingTest, StructConstructorResultNoPrecision) ...@@ -244,5 +260,6 @@ TEST_F(TypeTrackingTest, StructConstructorResultNoPrecision)
" gl_FragColor = s.a;\n" " gl_FragColor = s.a;\n"
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("Construct structure (structure)")); ASSERT_TRUE(foundInIntermediateTree("Construct structure (structure)"));
}; };
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