Commit 07e57df7 by Alexis Hetu Committed by Geoff Lang

Added non square matrix construction

Added new construction operations for non square matrices, along with the required changes to the related translation functions. Change-Id: I04ae7d4b2d1bb363b35d088cea45c0e7c4bc8a13 Reviewed-on: https://chromium-review.googlesource.com/277729Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent ea60af6c
...@@ -179,11 +179,50 @@ const char *getFloatTypeStr(const TType& type) ...@@ -179,11 +179,50 @@ const char *getFloatTypeStr(const TType& type)
case 1: case 1:
return "float"; return "float";
case 2: case 2:
return type.getSecondarySize() > 1 ? "mat2" : "vec2"; switch(type.getSecondarySize())
{
case 1:
return "vec2";
case 2:
return "mat2";
case 3:
return "mat2x3";
case 4:
return "mat2x4";
default:
UNREACHABLE();
return NULL;
}
case 3: case 3:
return type.getSecondarySize() > 1 ? "mat3" : "vec3"; switch(type.getSecondarySize())
{
case 1:
return "vec3";
case 2:
return "mat3x2";
case 3:
return "mat3";
case 4:
return "mat3x4";
default:
UNREACHABLE();
return NULL;
}
case 4: case 4:
return type.getSecondarySize() > 1 ? "mat4" : "vec4"; switch(type.getSecondarySize())
{
case 1:
return "vec4";
case 2:
return "mat4x2";
case 3:
return "mat4x3";
case 4:
return "mat4";
default:
UNREACHABLE();
return NULL;
}
default: default:
UNREACHABLE(); UNREACHABLE();
return NULL; return NULL;
......
...@@ -454,7 +454,13 @@ bool TIntermOperator::isConstructor() const ...@@ -454,7 +454,13 @@ bool TIntermOperator::isConstructor() const
case EOpConstructVec3: case EOpConstructVec3:
case EOpConstructVec4: case EOpConstructVec4:
case EOpConstructMat2: case EOpConstructMat2:
case EOpConstructMat2x3:
case EOpConstructMat2x4:
case EOpConstructMat3x2:
case EOpConstructMat3: case EOpConstructMat3:
case EOpConstructMat3x4:
case EOpConstructMat4x2:
case EOpConstructMat4x3:
case EOpConstructMat4: case EOpConstructMat4:
case EOpConstructFloat: case EOpConstructFloat:
case EOpConstructIVec2: case EOpConstructIVec2:
......
...@@ -164,7 +164,13 @@ const char *GetOperatorString(TOperator op) ...@@ -164,7 +164,13 @@ const char *GetOperatorString(TOperator op)
case EOpConstructUVec3: return "uvec3"; case EOpConstructUVec3: return "uvec3";
case EOpConstructUVec4: return "uvec4"; case EOpConstructUVec4: return "uvec4";
case EOpConstructMat2: return "mat2"; case EOpConstructMat2: return "mat2";
case EOpConstructMat2x3: return "mat2x3";
case EOpConstructMat2x4: return "mat2x4";
case EOpConstructMat3x2: return "mat3x2";
case EOpConstructMat3: return "mat3"; case EOpConstructMat3: return "mat3";
case EOpConstructMat3x4: return "mat3x4";
case EOpConstructMat4x2: return "mat4x2";
case EOpConstructMat4x3: return "mat4x3";
case EOpConstructMat4: return "mat4"; case EOpConstructMat4: return "mat4";
// Note: EOpConstructStruct can't be handled here // Note: EOpConstructStruct can't be handled here
......
...@@ -192,7 +192,13 @@ enum TOperator ...@@ -192,7 +192,13 @@ enum TOperator
EOpConstructUVec3, EOpConstructUVec3,
EOpConstructUVec4, EOpConstructUVec4,
EOpConstructMat2, EOpConstructMat2,
EOpConstructMat2x3,
EOpConstructMat2x4,
EOpConstructMat3x2,
EOpConstructMat3, EOpConstructMat3,
EOpConstructMat3x4,
EOpConstructMat4x2,
EOpConstructMat4x3,
EOpConstructMat4, EOpConstructMat4,
EOpConstructStruct, EOpConstructStruct,
......
...@@ -924,9 +924,27 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -924,9 +924,27 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpConstructMat2: case EOpConstructMat2:
writeConstructorTriplet(visit, node->getType(), "mat2"); writeConstructorTriplet(visit, node->getType(), "mat2");
break; break;
case EOpConstructMat2x3:
writeConstructorTriplet(visit, node->getType(), "mat2x3");
break;
case EOpConstructMat2x4:
writeConstructorTriplet(visit, node->getType(), "mat2x4");
break;
case EOpConstructMat3x2:
writeConstructorTriplet(visit, node->getType(), "mat3x2");
break;
case EOpConstructMat3: case EOpConstructMat3:
writeConstructorTriplet(visit, node->getType(), "mat3"); writeConstructorTriplet(visit, node->getType(), "mat3");
break; break;
case EOpConstructMat3x4:
writeConstructorTriplet(visit, node->getType(), "mat3x4");
break;
case EOpConstructMat4x2:
writeConstructorTriplet(visit, node->getType(), "mat4x2");
break;
case EOpConstructMat4x3:
writeConstructorTriplet(visit, node->getType(), "mat4x3");
break;
case EOpConstructMat4: case EOpConstructMat4:
writeConstructorTriplet(visit, node->getType(), "mat4"); writeConstructorTriplet(visit, node->getType(), "mat4");
break; break;
......
...@@ -2227,7 +2227,13 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -2227,7 +2227,13 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpConstructUVec3: outputConstructor(visit, node->getType(), "uvec3", node->getSequence()); break; case EOpConstructUVec3: outputConstructor(visit, node->getType(), "uvec3", node->getSequence()); break;
case EOpConstructUVec4: outputConstructor(visit, node->getType(), "uvec4", node->getSequence()); break; case EOpConstructUVec4: outputConstructor(visit, node->getType(), "uvec4", node->getSequence()); break;
case EOpConstructMat2: outputConstructor(visit, node->getType(), "mat2", node->getSequence()); break; case EOpConstructMat2: outputConstructor(visit, node->getType(), "mat2", node->getSequence()); break;
case EOpConstructMat2x3: outputConstructor(visit, node->getType(), "mat2x3", node->getSequence()); break;
case EOpConstructMat2x4: outputConstructor(visit, node->getType(), "mat2x4", node->getSequence()); break;
case EOpConstructMat3x2: outputConstructor(visit, node->getType(), "mat3x2", node->getSequence()); break;
case EOpConstructMat3: outputConstructor(visit, node->getType(), "mat3", node->getSequence()); break; case EOpConstructMat3: outputConstructor(visit, node->getType(), "mat3", node->getSequence()); break;
case EOpConstructMat3x4: outputConstructor(visit, node->getType(), "mat3x4", node->getSequence()); break;
case EOpConstructMat4x2: outputConstructor(visit, node->getType(), "mat4x2", node->getSequence()); break;
case EOpConstructMat4x3: outputConstructor(visit, node->getType(), "mat4x3", node->getSequence()); break;
case EOpConstructMat4: outputConstructor(visit, node->getType(), "mat4", node->getSequence()); break; case EOpConstructMat4: outputConstructor(visit, node->getType(), "mat4", node->getSequence()); break;
case EOpConstructStruct: case EOpConstructStruct:
{ {
......
...@@ -536,7 +536,13 @@ bool TParseContext::constructorErrorCheck(const TSourceLoc &line, TIntermNode *n ...@@ -536,7 +536,13 @@ bool TParseContext::constructorErrorCheck(const TSourceLoc &line, TIntermNode *n
switch(op) switch(op)
{ {
case EOpConstructMat2: case EOpConstructMat2:
case EOpConstructMat2x3:
case EOpConstructMat2x4:
case EOpConstructMat3x2:
case EOpConstructMat3: case EOpConstructMat3:
case EOpConstructMat3x4:
case EOpConstructMat4x2:
case EOpConstructMat4x3:
case EOpConstructMat4: case EOpConstructMat4:
constructingMatrix = true; constructingMatrix = true;
break; break;
...@@ -1815,12 +1821,32 @@ TFunction *TParseContext::addConstructorFunc(const TPublicType &publicTypeIn) ...@@ -1815,12 +1821,32 @@ TFunction *TParseContext::addConstructorFunc(const TPublicType &publicTypeIn)
case EbtFloat: case EbtFloat:
if (publicType.isMatrix()) if (publicType.isMatrix())
{ {
// TODO: non-square matrices
switch(publicType.getCols()) switch(publicType.getCols())
{ {
case 2: op = EOpConstructMat2; break; case 2:
case 3: op = EOpConstructMat3; break; switch(publicType.getRows())
case 4: op = EOpConstructMat4; break; {
case 2: op = EOpConstructMat2; break;
case 3: op = EOpConstructMat2x3; break;
case 4: op = EOpConstructMat2x4; break;
}
break;
case 3:
switch(publicType.getRows())
{
case 2: op = EOpConstructMat3x2; break;
case 3: op = EOpConstructMat3; break;
case 4: op = EOpConstructMat3x4; break;
}
break;
case 4:
switch(publicType.getRows())
{
case 2: op = EOpConstructMat4x2; break;
case 3: op = EOpConstructMat4x3; break;
case 4: op = EOpConstructMat4; break;
}
break;
} }
} }
else else
......
...@@ -109,7 +109,13 @@ bool ScalarizeVecAndMatConstructorArgs::visitAggregate(Visit visit, TIntermAggre ...@@ -109,7 +109,13 @@ bool ScalarizeVecAndMatConstructorArgs::visitAggregate(Visit visit, TIntermAggre
scalarizeArgs(node, false, true); scalarizeArgs(node, false, true);
break; break;
case EOpConstructMat2: case EOpConstructMat2:
case EOpConstructMat2x3:
case EOpConstructMat2x4:
case EOpConstructMat3x2:
case EOpConstructMat3: case EOpConstructMat3:
case EOpConstructMat3x4:
case EOpConstructMat4x2:
case EOpConstructMat4x3:
case EOpConstructMat4: case EOpConstructMat4:
if (ContainsVectorNode(*(node->getSequence()))) if (ContainsVectorNode(*(node->getSequence())))
scalarizeArgs(node, true, false); scalarizeArgs(node, true, false);
...@@ -144,9 +150,21 @@ void ScalarizeVecAndMatConstructorArgs::scalarizeArgs( ...@@ -144,9 +150,21 @@ void ScalarizeVecAndMatConstructorArgs::scalarizeArgs(
case EOpConstructMat2: case EOpConstructMat2:
size = 4; size = 4;
break; break;
case EOpConstructMat2x3:
case EOpConstructMat3x2:
size = 6;
break;
case EOpConstructMat2x4:
case EOpConstructMat4x2:
size = 8;
break;
case EOpConstructMat3: case EOpConstructMat3:
size = 9; size = 9;
break; break;
case EOpConstructMat3x4:
case EOpConstructMat4x3:
size = 12;
break;
case EOpConstructMat4: case EOpConstructMat4:
size = 16; size = 16;
break; break;
......
...@@ -106,7 +106,13 @@ bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate *node) ...@@ -106,7 +106,13 @@ bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate *node)
break; break;
} }
case EOpConstructMat2: case EOpConstructMat2:
case EOpConstructMat2x3:
case EOpConstructMat2x4:
case EOpConstructMat3x2:
case EOpConstructMat3: case EOpConstructMat3:
case EOpConstructMat3x4:
case EOpConstructMat4x2:
case EOpConstructMat4x3:
case EOpConstructMat4: case EOpConstructMat4:
{ {
const TIntermSequence &sequence = *(node->getSequence()); const TIntermSequence &sequence = *(node->getSequence());
......
...@@ -417,7 +417,13 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -417,7 +417,13 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpConstructUVec3: out << "Construct uvec3"; break; case EOpConstructUVec3: out << "Construct uvec3"; break;
case EOpConstructUVec4: out << "Construct uvec4"; break; case EOpConstructUVec4: out << "Construct uvec4"; break;
case EOpConstructMat2: out << "Construct mat2"; break; case EOpConstructMat2: out << "Construct mat2"; break;
case EOpConstructMat2x3: out << "Construct mat2x3"; break;
case EOpConstructMat2x4: out << "Construct mat2x4"; break;
case EOpConstructMat3x2: out << "Construct mat3x2"; break;
case EOpConstructMat3: out << "Construct mat3"; break; case EOpConstructMat3: out << "Construct mat3"; break;
case EOpConstructMat3x4: out << "Construct mat3x4"; break;
case EOpConstructMat4x2: out << "Construct mat4x2"; break;
case EOpConstructMat4x3: out << "Construct mat4x3"; break;
case EOpConstructMat4: out << "Construct mat4"; break; case EOpConstructMat4: out << "Construct mat4"; break;
case EOpConstructStruct: out << "Construct structure"; break; case EOpConstructStruct: out << "Construct structure"; break;
......
...@@ -124,6 +124,32 @@ TEST_F(TypeTrackingTest, BuiltInVecFunctionResultTypeAndPrecision) ...@@ -124,6 +124,32 @@ TEST_F(TypeTrackingTest, BuiltInVecFunctionResultTypeAndPrecision)
ASSERT_TRUE(foundInIntermediateTree("distance (mediump float)")); ASSERT_TRUE(foundInIntermediateTree("distance (mediump float)"));
} }
TEST_F(TypeTrackingTest, BuiltInMatFunctionResultTypeAndPrecision)
{
const std::string &shaderString =
"#version 300 es\n"
"precision mediump float;\n"
"out vec4 my_FragColor;\n"
"uniform mat4 m;\n"
"void main() {\n"
" mat3x2 tmp32 = mat3x2(m);\n"
" mat2x3 tmp23 = mat2x3(m);\n"
" mat4x2 tmp42 = mat4x2(m);\n"
" mat2x4 tmp24 = mat2x4(m);\n"
" mat4x3 tmp43 = mat4x3(m);\n"
" mat3x4 tmp34 = mat3x4(m);\n"
" my_FragColor = vec4(tmp32[2][1] * tmp23[1][2], tmp42[3][1] * tmp24[1][3], tmp43[3][2] * tmp34[2][3], 1.0);\n"
"}\n";
compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("Construct mat2x3 (mediump 2X3 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct mat3x2 (mediump 3X2 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct mat2x4 (mediump 2X4 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct mat4x2 (mediump 4X2 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct mat3x4 (mediump 3X4 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct mat4x3 (mediump 4X3 matrix of float)"));
}
TEST_F(TypeTrackingTest, BuiltInFunctionChoosesHigherPrecision) TEST_F(TypeTrackingTest, BuiltInFunctionChoosesHigherPrecision)
{ {
const std::string &shaderString = const std::string &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