Add support for GLSL exp, exp2, log, log2, sqrt and inversesqrt

This CL adds type determiner support for the Exp, Exp2, Log, Log2, Sqrt
and InverseSqrt GLSL methods.

Bug: tint:5
Change-Id: I3b9e799a8ebe5e8c96c1daf07131feae40e0c54e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19949
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-04-20 15:49:50 +00:00 committed by dan sinclair
parent 132b2daa19
commit a49328f60e
2 changed files with 48 additions and 26 deletions

View File

@ -585,13 +585,17 @@ ast::type::Type* TypeDeterminer::GetImportData(
// * asin, acos, atan // * asin, acos, atan
// * sinh, cosh, tanh // * sinh, cosh, tanh
// * asinh, acosh, atanh // * asinh, acosh, atanh
// * exp, exp2
// * log, log2
if (name == "round" || name == "roundeven" || name == "trunc" || if (name == "round" || name == "roundeven" || name == "trunc" ||
name == "fabs" || name == "fsign" || name == "floor" || name == "ceil" || name == "fabs" || name == "fsign" || name == "floor" || name == "ceil" ||
name == "fract" || name == "radians" || name == "degrees" || name == "fract" || name == "radians" || name == "degrees" ||
name == "sin" || name == "cos" || name == "tan" || name == "asin" || name == "sin" || name == "cos" || name == "tan" || name == "asin" ||
name == "acos" || name == "atan" || name == "sinh" || name == "cosh" || name == "acos" || name == "atan" || name == "sinh" || name == "cosh" ||
name == "tanh" || name == "asinh" || name == "acosh" || name == "atanh") { name == "tanh" || name == "asinh" || name == "acosh" || name == "atanh" ||
name == "exp" || name == "log" || name == "exp2" || name == "log2" ||
name == "sqrt" || name == "inversesqrt") {
if (params.size() != 1) { if (params.size() != 1) {
error_ = "incorrect number of parameters for " + name + error_ = "incorrect number of parameters for " + name +
". Expected 1 got " + std::to_string(params.size()); ". Expected 1 got " + std::to_string(params.size());
@ -647,6 +651,18 @@ ast::type::Type* TypeDeterminer::GetImportData(
*id = GLSLstd450Acosh; *id = GLSLstd450Acosh;
} else if (name == "atanh") { } else if (name == "atanh") {
*id = GLSLstd450Atanh; *id = GLSLstd450Atanh;
} else if (name == "exp") {
*id = GLSLstd450Exp;
} else if (name == "log") {
*id = GLSLstd450Log;
} else if (name == "exp2") {
*id = GLSLstd450Exp2;
} else if (name == "log2") {
*id = GLSLstd450Log2;
} else if (name == "sqrt") {
*id = GLSLstd450Sqrt;
} else if (name == "inversesqrt") {
*id = GLSLstd450InverseSqrt;
} }
return params[0]->result_type(); return params[0]->result_type();

View File

@ -1585,31 +1585,37 @@ TEST_P(ImportData_FloatTest, Error_MultipleParams) {
param.name + ". Expected 1 got 3"); param.name + ". Expected 1 got 3");
} }
INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest, INSTANTIATE_TEST_SUITE_P(
ImportData_FloatTest, TypeDeterminerTest,
testing::Values(GLSLData{"round", GLSLstd450Round}, ImportData_FloatTest,
GLSLData{"roundeven", testing::Values(GLSLData{"round", GLSLstd450Round},
GLSLstd450RoundEven}, GLSLData{"roundeven", GLSLstd450RoundEven},
GLSLData{"trunc", GLSLstd450Trunc}, GLSLData{"trunc", GLSLstd450Trunc},
GLSLData{"fabs", GLSLstd450FAbs}, GLSLData{"fabs", GLSLstd450FAbs},
GLSLData{"fsign", GLSLstd450FSign}, GLSLData{"fsign", GLSLstd450FSign},
GLSLData{"floor", GLSLstd450Floor}, GLSLData{"floor", GLSLstd450Floor},
GLSLData{"ceil", GLSLstd450Ceil}, GLSLData{"ceil", GLSLstd450Ceil},
GLSLData{"fract", GLSLstd450Fract}, GLSLData{"fract", GLSLstd450Fract},
GLSLData{"radians", GLSLstd450Radians}, GLSLData{"radians", GLSLstd450Radians},
GLSLData{"degrees", GLSLstd450Degrees}, GLSLData{"degrees", GLSLstd450Degrees},
GLSLData{"sin", GLSLstd450Sin}, GLSLData{"sin", GLSLstd450Sin},
GLSLData{"cos", GLSLstd450Cos}, GLSLData{"cos", GLSLstd450Cos},
GLSLData{"tan", GLSLstd450Tan}, GLSLData{"tan", GLSLstd450Tan},
GLSLData{"asin", GLSLstd450Asin}, GLSLData{"asin", GLSLstd450Asin},
GLSLData{"acos", GLSLstd450Acos}, GLSLData{"acos", GLSLstd450Acos},
GLSLData{"atan", GLSLstd450Atan}, GLSLData{"atan", GLSLstd450Atan},
GLSLData{"sinh", GLSLstd450Sinh}, GLSLData{"sinh", GLSLstd450Sinh},
GLSLData{"cosh", GLSLstd450Cosh}, GLSLData{"cosh", GLSLstd450Cosh},
GLSLData{"tanh", GLSLstd450Tanh}, GLSLData{"tanh", GLSLstd450Tanh},
GLSLData{"asinh", GLSLstd450Asinh}, GLSLData{"asinh", GLSLstd450Asinh},
GLSLData{"acosh", GLSLstd450Acosh}, GLSLData{"acosh", GLSLstd450Acosh},
GLSLData{"atanh", GLSLstd450Atanh})); GLSLData{"atanh", GLSLstd450Atanh},
GLSLData{"exp", GLSLstd450Exp},
GLSLData{"log", GLSLstd450Log},
GLSLData{"exp2", GLSLstd450Exp2},
GLSLData{"log2", GLSLstd450Log2},
GLSLData{"sqrt", GLSLstd450Sqrt},
GLSLData{"inversesqrt", GLSLstd450InverseSqrt}));
} // namespace } // namespace
} // namespace tint } // namespace tint