Add support for sclamp and uclamp GLSL methods.
This CL adds support for type determination of the SClamp and UClamp GLSL methods. Change-Id: I974e80127f0e256285f126136270ac5131334a92 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23500 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
8b48b26f73
commit
e9598d697a
|
@ -126,6 +126,7 @@ constexpr const GlslData kGlslData[] = {
|
|||
{"roundeven", 1, GLSLstd450RoundEven, GlslDataType::kFloatScalarOrVector,
|
||||
0},
|
||||
{"sabs", 1, GLSLstd450SAbs, GlslDataType::kIntScalarOrVector, 0},
|
||||
{"sclamp", 3, GLSLstd450SClamp, GlslDataType::kIntScalarOrVector, 0},
|
||||
{"sin", 1, GLSLstd450Sin, GlslDataType::kFloatScalarOrVector, 0},
|
||||
{"sinh", 1, GLSLstd450Sinh, GlslDataType::kFloatScalarOrVector, 0},
|
||||
{"smax", 2, GLSLstd450SMax, GlslDataType::kIntScalarOrVector, 0},
|
||||
|
@ -138,6 +139,7 @@ constexpr const GlslData kGlslData[] = {
|
|||
{"tan", 1, GLSLstd450Tan, GlslDataType::kFloatScalarOrVector, 0},
|
||||
{"tanh", 1, GLSLstd450Tanh, GlslDataType::kFloatScalarOrVector, 0},
|
||||
{"trunc", 1, GLSLstd450Trunc, GlslDataType::kFloatScalarOrVector, 0},
|
||||
{"uclamp", 3, GLSLstd450UClamp, GlslDataType::kIntScalarOrVector, 0},
|
||||
{"umax", 2, GLSLstd450UMax, GlslDataType::kIntScalarOrVector, 0},
|
||||
{"umin", 2, GLSLstd450UMin, GlslDataType::kIntScalarOrVector, 0},
|
||||
};
|
||||
|
|
|
@ -3307,5 +3307,332 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
testing::Values(GLSLData{"determinant", GLSLstd450Determinant},
|
||||
GLSLData{"matrixinverse", GLSLstd450MatrixInverse}));
|
||||
|
||||
using ImportData_IntThreeParamTest = TypeDeterminerTestWithParam<GLSLData>;
|
||||
TEST_P(ImportData_IntThreeParamTest, Scalar_Signed) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32Type i32;
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->IsI32());
|
||||
EXPECT_EQ(id, param.value);
|
||||
}
|
||||
|
||||
TEST_P(ImportData_IntThreeParamTest, Scalar_Unsigned) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::U32Type u32;
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->IsU32());
|
||||
EXPECT_EQ(id, param.value);
|
||||
}
|
||||
|
||||
TEST_P(ImportData_IntThreeParamTest, Vector_Signed) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32Type i32;
|
||||
ast::type::VectorType vec(&i32, 3);
|
||||
|
||||
ast::ExpressionList vals_1;
|
||||
vals_1.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_1.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_1.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3)));
|
||||
|
||||
ast::ExpressionList vals_2;
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3)));
|
||||
|
||||
ast::ExpressionList vals_3;
|
||||
vals_3.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_3.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_3.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3)));
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(vals_1)));
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(vals_2)));
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(vals_3)));
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->is_signed_integer_vector());
|
||||
EXPECT_EQ(type->AsVector()->size(), 3u);
|
||||
EXPECT_EQ(id, param.value);
|
||||
}
|
||||
|
||||
TEST_P(ImportData_IntThreeParamTest, Vector_Unsigned) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::U32Type u32;
|
||||
ast::type::VectorType vec(&u32, 3);
|
||||
|
||||
ast::ExpressionList vals_1;
|
||||
vals_1.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
||||
vals_1.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
||||
vals_1.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 3u)));
|
||||
|
||||
ast::ExpressionList vals_2;
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 3u)));
|
||||
|
||||
ast::ExpressionList vals_3;
|
||||
vals_3.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
||||
vals_3.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
||||
vals_3.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 3u)));
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(vals_1)));
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(vals_2)));
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(vals_3)));
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->is_unsigned_integer_vector());
|
||||
EXPECT_EQ(type->AsVector()->size(), 3u);
|
||||
EXPECT_EQ(id, param.value);
|
||||
}
|
||||
|
||||
TEST_P(ImportData_IntThreeParamTest, Error_Float) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::F32Type f32;
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.f)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.f)));
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_EQ(type, nullptr);
|
||||
EXPECT_EQ(td()->error(),
|
||||
std::string("incorrect type for ") + param.name +
|
||||
". Requires integer scalar or integer vector values");
|
||||
}
|
||||
|
||||
TEST_P(ImportData_IntThreeParamTest, Error_NoParams) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::ExpressionList params;
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_EQ(type, nullptr);
|
||||
EXPECT_EQ(td()->error(), std::string("incorrect number of parameters for ") +
|
||||
param.name + ". Expected 3 got 0");
|
||||
}
|
||||
|
||||
TEST_P(ImportData_IntThreeParamTest, Error_OneParam) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32Type i32;
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_EQ(type, nullptr);
|
||||
EXPECT_EQ(td()->error(), std::string("incorrect number of parameters for ") +
|
||||
param.name + ". Expected 3 got 1");
|
||||
}
|
||||
|
||||
TEST_P(ImportData_IntThreeParamTest, Error_TwoParams) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32Type i32;
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_EQ(type, nullptr);
|
||||
EXPECT_EQ(td()->error(), std::string("incorrect number of parameters for ") +
|
||||
param.name + ". Expected 3 got 2");
|
||||
}
|
||||
|
||||
TEST_P(ImportData_IntThreeParamTest, Error_MismatchedParamCount) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32Type i32;
|
||||
ast::type::VectorType vec2(&i32, 2);
|
||||
ast::type::VectorType vec3(&i32, 3);
|
||||
|
||||
ast::ExpressionList vals_1;
|
||||
vals_1.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_1.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
ast::ExpressionList vals_2;
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3)));
|
||||
|
||||
ast::ExpressionList vals_3;
|
||||
vals_3.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_3.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals_3.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3)));
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec2, std::move(vals_1)));
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec3, std::move(vals_2)));
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec3, std::move(vals_3)));
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_EQ(type, nullptr);
|
||||
EXPECT_EQ(td()->error(),
|
||||
std::string("mismatched parameter types for ") + param.name);
|
||||
}
|
||||
|
||||
TEST_P(ImportData_IntThreeParamTest, Error_MismatchedParamType) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32Type i32;
|
||||
ast::type::VectorType vec(&i32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3)));
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals)));
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_EQ(type, nullptr);
|
||||
EXPECT_EQ(td()->error(),
|
||||
std::string("mismatched parameter types for ") + param.name);
|
||||
}
|
||||
|
||||
TEST_P(ImportData_IntThreeParamTest, Error_TooManyParams) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32Type i32;
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(params)) << td()->error();
|
||||
|
||||
uint32_t id = 0;
|
||||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_EQ(type, nullptr);
|
||||
EXPECT_EQ(td()->error(), std::string("incorrect number of parameters for ") +
|
||||
param.name + ". Expected 3 got 4");
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest,
|
||||
ImportData_IntThreeParamTest,
|
||||
testing::Values(GLSLData{"sclamp", GLSLstd450SClamp},
|
||||
GLSLData{"uclamp", GLSLstd450UClamp}));
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
||||
|
|
Loading…
Reference in New Issue