Commit 21203702 by Olli Etuaho Committed by Jamie Madill

Fix precision tracking of constructor return values

Precision should be set for constructor return values if they are of a built-in type. Structs should not be precision qualified. BUG=angle:787 Change-Id: Ie5efd5be25a788ff6f01c5b989254572c00231eb Reviewed-on: https://chromium-review.googlesource.com/229560Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent 30d6c255
...@@ -1605,7 +1605,7 @@ TFunction *TParseContext::addConstructorFunc(TPublicType publicType) ...@@ -1605,7 +1605,7 @@ TFunction *TParseContext::addConstructorFunc(TPublicType publicType)
// //
// Returns 0 for an error or the constructed node (aggregate or typed) for no error. // Returns 0 for an error or the constructed node (aggregate or typed) for no error.
// //
TIntermTyped *TParseContext::addConstructor(TIntermNode *arguments, const TType *type, TOperator op, TFunction *fnCall, const TSourceLoc &line) TIntermTyped *TParseContext::addConstructor(TIntermNode *arguments, TType *type, TOperator op, TFunction *fnCall, const TSourceLoc &line)
{ {
TIntermAggregate *aggregateArguments = arguments->getAsAggregate(); TIntermAggregate *aggregateArguments = arguments->getAsAggregate();
...@@ -1633,13 +1633,21 @@ TIntermTyped *TParseContext::addConstructor(TIntermNode *arguments, const TType ...@@ -1633,13 +1633,21 @@ TIntermTyped *TParseContext::addConstructor(TIntermNode *arguments, const TType
} }
// Turn the argument list itself into a constructor // Turn the argument list itself into a constructor
TIntermTyped *constructor = intermediate.setAggregateOperator(aggregateArguments, op, line); TIntermAggregate *constructor = intermediate.setAggregateOperator(aggregateArguments, op, line);
TIntermTyped *constConstructor = foldConstConstructor(constructor->getAsAggregate(), *type); TIntermTyped *constConstructor = foldConstConstructor(constructor, *type);
if (constConstructor) if (constConstructor)
{ {
return constConstructor; return constConstructor;
} }
// Structs should not be precision qualified, the individual members may be.
// Built-in types on the other hand should be precision qualified.
if (op != EOpConstructStruct)
{
constructor->setPrecisionFromChildren();
type->setPrecision(constructor->getPrecision());
}
return constructor; return constructor;
} }
......
...@@ -136,7 +136,7 @@ struct TParseContext { ...@@ -136,7 +136,7 @@ struct TParseContext {
TIntermAggregate* parseInitDeclarator(TPublicType &publicType, TIntermAggregate *declaratorList, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& initLocation, TIntermTyped *initializer); TIntermAggregate* parseInitDeclarator(TPublicType &publicType, TIntermAggregate *declaratorList, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& initLocation, TIntermTyped *initializer);
void parseGlobalLayoutQualifier(const TPublicType &typeQualifier); void parseGlobalLayoutQualifier(const TPublicType &typeQualifier);
TFunction *addConstructorFunc(TPublicType publicType); TFunction *addConstructorFunc(TPublicType publicType);
TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, const TSourceLoc&); TIntermTyped* addConstructor(TIntermNode*, TType*, TOperator, TFunction*, const TSourceLoc&);
TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type); TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type);
TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, const TSourceLoc&); TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, const TSourceLoc&);
TIntermTyped* addConstMatrixNode(int , TIntermTyped*, const TSourceLoc&); TIntermTyped* addConstMatrixNode(int , TIntermTyped*, const TSourceLoc&);
......
...@@ -215,3 +215,34 @@ TEST_F(TypeTrackingTest, TextureSizeResultTypeAndPrecision) ...@@ -215,3 +215,34 @@ TEST_F(TypeTrackingTest, TextureSizeResultTypeAndPrecision)
compile(shaderString); compile(shaderString);
ASSERT_TRUE(foundInIntermediateTree("textureSize(s21;i1; (highp 2-component vector of int)")); ASSERT_TRUE(foundInIntermediateTree("textureSize(s21;i1; (highp 2-component vector of int)"));
}; };
TEST_F(TypeTrackingTest, BuiltInConstructorResultTypeAndPrecision)
{
const std::string &shaderString =
"precision mediump float;\n"
"uniform float u1;\n"
"uniform float u2;\n"
"uniform float u3;\n"
"uniform float u4;\n"
"void main() {\n"
" vec4 a = vec4(u1, u2, u3, u4);\n"
" gl_FragColor = a;\n"
"}\n";
compile(shaderString);
ASSERT_TRUE(foundInIntermediateTree("Construct vec4 (mediump 4-component vector of float)"));
};
TEST_F(TypeTrackingTest, StructConstructorResultNoPrecision)
{
const std::string &shaderString =
"precision mediump float;\n"
"uniform vec4 u1;\n"
"uniform vec4 u2;\n"
"struct S { highp vec4 a; highp vec4 b; };\n"
"void main() {\n"
" S s = S(u1, u2);\n"
" gl_FragColor = s.a;\n"
"}\n";
compile(shaderString);
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