Add GLSL umin, umax, smin and smax support.
This CL adds type determination for the umin, umax, smin and smax GLSL methods. Change-Id: Ib301da41baf718e309a940f4a3560088daa10741 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22841 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
5e5fb9cf37
commit
92bb55777c
|
@ -107,11 +107,12 @@ bool Type::is_integer_scalar() {
|
|||
return IsU32() || IsI32();
|
||||
}
|
||||
|
||||
bool Type::is_integer_vector() {
|
||||
if (!IsVector()) {
|
||||
return false;
|
||||
}
|
||||
return AsVector()->type()->IsU32() || AsVector()->type()->IsI32();
|
||||
bool Type::is_unsigned_integer_vector() {
|
||||
return IsVector() && AsVector()->type()->IsU32();
|
||||
}
|
||||
|
||||
bool Type::is_signed_integer_vector() {
|
||||
return IsVector() && AsVector()->type()->IsI32();
|
||||
}
|
||||
|
||||
bool Type::is_unsigned_scalar_or_vector() {
|
||||
|
|
|
@ -79,8 +79,10 @@ class Type {
|
|||
bool is_float_scalar_or_vector();
|
||||
/// @returns ture if this type is an integer scalar
|
||||
bool is_integer_scalar();
|
||||
/// @returns ture if this type is an integer vector
|
||||
bool is_integer_vector();
|
||||
/// @returns true if this type is a signed integer vector
|
||||
bool is_signed_integer_vector();
|
||||
/// @returns true if this type is an unsigned vector
|
||||
bool is_unsigned_integer_vector();
|
||||
/// @returns true if this type is an unsigned scalar or vector
|
||||
bool is_unsigned_scalar_or_vector();
|
||||
/// @returns true if this type is a signed scalar or vector
|
||||
|
|
|
@ -679,6 +679,8 @@ constexpr const GlslData kGlslData[] = {
|
|||
{"sabs", 1, GLSLstd450SAbs, GlslDataType::kIntScalarOrVector},
|
||||
{"sin", 1, GLSLstd450Sin, GlslDataType::kFloatScalarOrVector},
|
||||
{"sinh", 1, GLSLstd450Sinh, GlslDataType::kFloatScalarOrVector},
|
||||
{"smax", 2, GLSLstd450SMax, GlslDataType::kIntScalarOrVector},
|
||||
{"smin", 2, GLSLstd450SMin, GlslDataType::kIntScalarOrVector},
|
||||
{"smoothstep", 3, GLSLstd450SmoothStep, GlslDataType::kFloatScalarOrVector},
|
||||
{"sqrt", 1, GLSLstd450Sqrt, GlslDataType::kFloatScalarOrVector},
|
||||
{"ssign", 1, GLSLstd450SSign, GlslDataType::kIntScalarOrVector},
|
||||
|
@ -686,6 +688,8 @@ constexpr const GlslData kGlslData[] = {
|
|||
{"tan", 1, GLSLstd450Tan, GlslDataType::kFloatScalarOrVector},
|
||||
{"tanh", 1, GLSLstd450Tanh, GlslDataType::kFloatScalarOrVector},
|
||||
{"trunc", 1, GLSLstd450Trunc, GlslDataType::kFloatScalarOrVector},
|
||||
{"umax", 2, GLSLstd450UMax, GlslDataType::kIntScalarOrVector},
|
||||
{"umin", 2, GLSLstd450UMin, GlslDataType::kIntScalarOrVector},
|
||||
};
|
||||
constexpr const uint32_t kGlslDataCount = sizeof(kGlslData) / sizeof(GlslData);
|
||||
|
||||
|
|
|
@ -49,8 +49,10 @@
|
|||
#include "src/ast/type/matrix_type.h"
|
||||
#include "src/ast/type/pointer_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type/u32_type.h"
|
||||
#include "src/ast/type/vector_type.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/ast/uint_literal.h"
|
||||
#include "src/ast/unary_op_expression.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
|
||||
|
@ -2651,7 +2653,7 @@ TEST_P(ImportData_Int_SingleParamTest, Vector) {
|
|||
auto* type =
|
||||
td()->GetImportData({0, 0}, "GLSL.std.450", param.name, params, &id);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->is_integer_vector());
|
||||
EXPECT_TRUE(type->is_signed_integer_vector());
|
||||
EXPECT_EQ(type->AsVector()->size(), 3u);
|
||||
EXPECT_EQ(id, param.value);
|
||||
}
|
||||
|
@ -2715,5 +2717,274 @@ INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest,
|
|||
testing::Values(GLSLData{"sabs", GLSLstd450SAbs},
|
||||
GLSLData{"ssign", GLSLstd450SSign}));
|
||||
|
||||
using ImportData_Int_TwoParamTest = TypeDeterminerTestWithParam<GLSLData>;
|
||||
TEST_P(ImportData_Int_TwoParamTest, 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)));
|
||||
|
||||
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_Int_TwoParamTest, 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, 1)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 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->IsU32());
|
||||
EXPECT_EQ(id, param.value);
|
||||
}
|
||||
|
||||
TEST_P(ImportData_Int_TwoParamTest, 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 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)));
|
||||
|
||||
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_Int_TwoParamTest, 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, 1)));
|
||||
vals_1.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals_1.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 3)));
|
||||
|
||||
ast::ExpressionList vals_2;
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals_2.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 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)));
|
||||
|
||||
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_Int_TwoParamTest, 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)));
|
||||
|
||||
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_Int_TwoParamTest, 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 2 got 0");
|
||||
}
|
||||
|
||||
TEST_P(ImportData_Int_TwoParamTest, 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 2 got 1");
|
||||
}
|
||||
|
||||
TEST_P(ImportData_Int_TwoParamTest, 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 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)));
|
||||
|
||||
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_Int_TwoParamTest, 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::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_Int_TwoParamTest, 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)));
|
||||
|
||||
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 2 got 3");
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest,
|
||||
ImportData_Int_TwoParamTest,
|
||||
testing::Values(GLSLData{"umin", GLSLstd450UMin},
|
||||
GLSLData{"smin", GLSLstd450SMin},
|
||||
GLSLData{"umax", GLSLstd450UMax},
|
||||
GLSLData{"smax", GLSLstd450SMax}));
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
||||
|
|
Loading…
Reference in New Issue