From 3238eaa3b1dfe97a6a90e5c80692877530cf0142 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 17 Jun 2020 20:22:08 +0000 Subject: [PATCH] Add GLSL MatrixInverse type determination. This CL adds type determination for the MatrixInverse GLSL method call. Change-Id: I976beb00bb5c869407a0c9f522789112ff22bf6a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23400 Reviewed-by: David Neto --- src/type_determiner.cc | 1 + src/type_determiner_test.cc | 65 +++++++++++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/type_determiner.cc b/src/type_determiner.cc index bf8c00ffe1..eda58f2044 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -113,6 +113,7 @@ constexpr const GlslData kGlslData[] = { {"length", 1, GLSLstd450Length, GlslDataType::kFloatScalarOrVector, 0}, {"log", 1, GLSLstd450Log, GlslDataType::kFloatScalarOrVector, 0}, {"log2", 1, GLSLstd450Log2, GlslDataType::kFloatScalarOrVector, 0}, + {"matrixinverse", 1, GLSLstd450MatrixInverse, GlslDataType::kMatrix, 0}, {"nclamp", 3, GLSLstd450NClamp, GlslDataType::kFloatScalarOrVector, 0}, {"nmax", 2, GLSLstd450NMax, GlslDataType::kFloatScalarOrVector, 0}, {"nmin", 2, GLSLstd450NMin, GlslDataType::kFloatScalarOrVector, 0}, diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 8ec424fc31..b71fefdff4 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -3185,7 +3185,7 @@ INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest, GLSLData{"umax", GLSLstd450UMax}, GLSLData{"smax", GLSLstd450SMax})); -TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant_Matrix) { +TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant) { ast::type::F32Type f32; ast::type::MatrixType mat(&f32, 3, 3); @@ -3209,7 +3209,37 @@ TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant_Matrix) { EXPECT_EQ(id, GLSLstd450Determinant); } -TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant_Error_Float) { +TEST_F(TypeDeterminerTest, ImportData_GLSL_MatrixInverse) { + ast::type::F32Type f32; + ast::type::MatrixType mat(&f32, 3, 3); + + auto var = std::make_unique( + "var", ast::StorageClass::kFunction, &mat); + mod()->AddGlobalVariable(std::move(var)); + + // Register the global + ASSERT_TRUE(td()->Determine()) << td()->error(); + + ast::ExpressionList params; + params.push_back(std::make_unique("var")); + + ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error(); + + uint32_t id = 0; + auto* type = + td()->GetImportData({0, 0}, "GLSL.std.450", "matrixinverse", params, &id); + ASSERT_NE(type, nullptr); + EXPECT_TRUE(type->IsMatrix()); + EXPECT_TRUE(type->AsMatrix()->type()->IsF32()); + EXPECT_EQ(type->AsMatrix()->rows(), 3u); + EXPECT_EQ(type->AsMatrix()->columns(), 3u); + EXPECT_EQ(id, GLSLstd450MatrixInverse); +} + +using ImportData_Matrix_OneParam_Test = TypeDeterminerTestWithParam; +TEST_P(ImportData_Matrix_OneParam_Test, Error_Float) { + auto param = GetParam(); + ast::type::F32Type f32; auto var = std::make_unique( @@ -3226,24 +3256,28 @@ TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant_Error_Float) { uint32_t id = 0; auto* type = - td()->GetImportData({0, 0}, "GLSL.std.450", "determinant", params, &id); + td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id); ASSERT_EQ(type, nullptr); - EXPECT_EQ(td()->error(), - "incorrect type for determinant. Requires matrix value"); + EXPECT_EQ(td()->error(), std::string("incorrect type for ") + param.name + + ". Requires matrix value"); } -TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant_Error_NoParams) { +TEST_P(ImportData_Matrix_OneParam_Test, NoParams) { + auto param = GetParam(); + ast::ExpressionList params; uint32_t id = 0; auto* type = - td()->GetImportData({0, 0}, "GLSL.std.450", "determinant", params, &id); + td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id); ASSERT_EQ(type, nullptr); - EXPECT_EQ(td()->error(), - "incorrect number of parameters for determinant. Expected 1 got 0"); + EXPECT_EQ(td()->error(), std::string("incorrect number of parameters for ") + + param.name + ". Expected 1 got 0"); } -TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant_Error_TooManyParams) { +TEST_P(ImportData_Matrix_OneParam_Test, TooManyParams) { + auto param = GetParam(); + ast::type::F32Type f32; ast::type::MatrixType mat(&f32, 3, 3); @@ -3262,11 +3296,16 @@ TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant_Error_TooManyParams) { uint32_t id = 0; auto* type = - td()->GetImportData({0, 0}, "GLSL.std.450", "determinant", params, &id); + td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id); ASSERT_EQ(type, nullptr); - EXPECT_EQ(td()->error(), - "incorrect number of parameters for determinant. Expected 1 got 2"); + EXPECT_EQ(td()->error(), std::string("incorrect number of parameters for ") + + param.name + ". Expected 1 got 2"); } +INSTANTIATE_TEST_SUITE_P( + TypeDeterminerTest, + ImportData_Matrix_OneParam_Test, + testing::Values(GLSLData{"determinant", GLSLstd450Determinant}, + GLSLData{"matrixinverse", GLSLstd450MatrixInverse})); } // namespace } // namespace tint