[ast] Change intrinsic function names to camel case

Change-Id: I227eade96ccf84a4ed006cc5e98ac9e47f44129a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28163
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
This commit is contained in:
Tomek Ponitka 2020-09-08 16:30:29 +00:00 committed by Commit Bot service account
parent cd862fdc7c
commit 4e2d2484f8
5 changed files with 58 additions and 60 deletions

View File

@ -19,12 +19,11 @@ namespace ast {
namespace intrinsic {
bool IsCoarseDerivative(const std::string& name) {
return name == "dpdx_coarse" || name == "dpdy_coarse" ||
name == "fwidth_coarse";
return name == "dpdxCoarse" || name == "dpdyCoarse" || name == "fwidthCoarse";
}
bool IsFineDerivative(const std::string& name) {
return name == "dpdx_fine" || name == "dpdy_fine" || name == "fwidth_fine";
return name == "dpdxFine" || name == "dpdyFine" || name == "fwidthFine";
}
bool IsDerivative(const std::string& name) {
@ -33,21 +32,21 @@ bool IsDerivative(const std::string& name) {
}
bool IsFloatClassificationIntrinsic(const std::string& name) {
return name == "is_finite" || name == "is_inf" || name == "is_nan" ||
name == "is_normal";
return name == "isFinite" || name == "isInf" || name == "isNan" ||
name == "isNormal";
}
bool IsTextureOperationIntrinsic(const std::string& name) {
return name == "texture_load" || name == "texture_sample" ||
name == "texture_sample_level" || name == "texture_sample_bias" ||
name == "texture_sample_compare";
return name == "textureLoad" || name == "textureSample" ||
name == "textureSampleLevel" || name == "textureSampleBias" ||
name == "textureSampleCompare";
}
bool IsIntrinsic(const std::string& name) {
return IsDerivative(name) || name == "all" || name == "any" ||
IsFloatClassificationIntrinsic(name) ||
IsTextureOperationIntrinsic(name) || name == "dot" ||
name == "outer_product" || name == "select";
name == "outerProduct" || name == "select";
}
} // namespace intrinsic

View File

@ -543,7 +543,6 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
return true;
}
// TODO(tommek): Update names to camel case
bool TypeDeterminer::DetermineIntrinsic(const std::string& name,
ast::CallExpression* expr) {
if (ast::intrinsic::IsDerivative(name)) {
@ -590,7 +589,7 @@ bool TypeDeterminer::DetermineIntrinsic(const std::string& name,
}
if (ast::intrinsic::IsTextureOperationIntrinsic(name)) {
uint32_t num_of_params =
(name == "texture_load" || name == "texture_sample") ? 3 : 4;
(name == "textureLoad" || name == "textureSample") ? 3 : 4;
if (expr->params().size() != num_of_params) {
set_error(expr->source(),
"incorrect number of parameters for " + name + ", got " +
@ -599,7 +598,7 @@ bool TypeDeterminer::DetermineIntrinsic(const std::string& name,
return false;
}
if (name == "texture_sample_compare") {
if (name == "textureSampleCompare") {
expr->func()->set_result_type(
ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>()));
return true;
@ -633,7 +632,7 @@ bool TypeDeterminer::DetermineIntrinsic(const std::string& name,
ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>()));
return true;
}
if (name == "outer_product") {
if (name == "outerProduct") {
if (expr->params().size() != 2) {
set_error(expr->source(),
"incorrect number of parameters for outer_product");

View File

@ -1676,14 +1676,14 @@ TEST_P(IntrinsicDerivativeTest, ToomManyParams) {
INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest,
IntrinsicDerivativeTest,
testing::Values("dpdx",
"dpdx_coarse",
"dpdx_fine",
"dpdxCoarse",
"dpdxFine",
"dpdy",
"dpdy_coarse",
"dpdy_fine",
"dpdyCoarse",
"dpdyFine",
"fwidth",
"fwidth_coarse",
"fwidth_fine"));
"fwidthCoarse",
"fwidthFine"));
using Intrinsic = TypeDeterminerTestWithParam<std::string>;
TEST_P(Intrinsic, Test) {
@ -1805,7 +1805,7 @@ TEST_P(Intrinsic_FloatMethod, TooManyParams) {
INSTANTIATE_TEST_SUITE_P(
TypeDeterminerTest,
Intrinsic_FloatMethod,
testing::Values("is_inf", "is_nan", "is_finite", "is_normal"));
testing::Values("isInf", "isNan", "isFinite", "isNormal"));
enum class TextureType { kF32, kI32, kU32 };
inline std::ostream& operator<<(std::ostream& out, TextureType data) {
@ -1894,7 +1894,7 @@ TEST_P(Intrinsic_StorageTextureOperation, TextureLoadRo) {
add_call_param("lod", &i32, &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_load"),
std::make_unique<ast::IdentifierExpression>("textureLoad"),
std::move(call_params));
EXPECT_TRUE(td()->Determine());
@ -1965,7 +1965,7 @@ TEST_P(Intrinsic_SampledTextureOperation, TextureLoadSampled) {
add_call_param("lod", &i32, &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_load"),
std::make_unique<ast::IdentifierExpression>("textureLoad"),
std::move(call_params));
EXPECT_TRUE(td()->Determine());
@ -2002,7 +2002,7 @@ TEST_P(Intrinsic_SampledTextureOperation, TextureSample) {
add_call_param("coords", coords_type.get(), &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample"),
std::make_unique<ast::IdentifierExpression>("textureSample"),
std::move(call_params));
EXPECT_TRUE(td()->Determine());
@ -2040,7 +2040,7 @@ TEST_P(Intrinsic_SampledTextureOperation, TextureSampleLevel) {
add_call_param("lod", &f32, &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample_level"),
std::make_unique<ast::IdentifierExpression>("textureSampleLevel"),
std::move(call_params));
EXPECT_TRUE(td()->Determine());
@ -2078,7 +2078,7 @@ TEST_P(Intrinsic_SampledTextureOperation, TextureSampleBias) {
add_call_param("bias", &f32, &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample_bias"),
std::make_unique<ast::IdentifierExpression>("textureSampleBias"),
std::move(call_params));
EXPECT_TRUE(td()->Determine());
@ -2164,7 +2164,7 @@ TEST_P(Intrinsic_DepthTextureOperation, TextureSampleCompare) {
add_call_param("depth_reference", &f32, &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample_compare"),
std::make_unique<ast::IdentifierExpression>("textureSampleCompare"),
std::move(call_params));
EXPECT_TRUE(td()->Determine());
@ -2301,7 +2301,7 @@ TEST_F(TypeDeterminerTest, Intrinsic_OuterProduct) {
call_params.push_back(std::make_unique<ast::IdentifierExpression>("v2"));
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("outer_product"),
std::make_unique<ast::IdentifierExpression>("outerProduct"),
std::move(call_params));
// Register the variable
@ -2330,7 +2330,7 @@ TEST_F(TypeDeterminerTest, Intrinsic_OuterProduct_TooFewParams) {
call_params.push_back(std::make_unique<ast::IdentifierExpression>("v2"));
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("outer_product"),
std::make_unique<ast::IdentifierExpression>("outerProduct"),
std::move(call_params));
// Register the variable
@ -2354,7 +2354,7 @@ TEST_F(TypeDeterminerTest, Intrinsic_OuterProduct_TooManyParams) {
call_params.push_back(std::make_unique<ast::IdentifierExpression>("v2"));
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("outer_product"),
std::make_unique<ast::IdentifierExpression>("outerProduct"),
std::move(call_params));
// Register the variable

View File

@ -1485,27 +1485,27 @@ uint32_t Builder::GenerateIntrinsic(const std::string& name,
op = spv::Op::OpDot;
} else if (name == "dpdx") {
op = spv::Op::OpDPdx;
} else if (name == "dpdx_coarse") {
} else if (name == "dpdxCoarse") {
op = spv::Op::OpDPdxCoarse;
} else if (name == "dpdx_fine") {
} else if (name == "dpdxFine") {
op = spv::Op::OpDPdxFine;
} else if (name == "dpdy") {
op = spv::Op::OpDPdy;
} else if (name == "dpdy_coarse") {
} else if (name == "dpdyCoarse") {
op = spv::Op::OpDPdyCoarse;
} else if (name == "dpdy_fine") {
} else if (name == "dpdyFine") {
op = spv::Op::OpDPdyFine;
} else if (name == "fwidth") {
op = spv::Op::OpFwidth;
} else if (name == "fwidth_coarse") {
} else if (name == "fwidthCoarse") {
op = spv::Op::OpFwidthCoarse;
} else if (name == "fwidth_fine") {
} else if (name == "fwidthFine") {
op = spv::Op::OpFwidthFine;
} else if (name == "is_inf") {
} else if (name == "isInf") {
op = spv::Op::OpIsInf;
} else if (name == "is_nan") {
} else if (name == "isNan") {
op = spv::Op::OpIsNan;
} else if (name == "outer_product") {
} else if (name == "outerProduct") {
op = spv::Op::OpOuterProduct;
} else if (name == "select") {
op = spv::Op::OpSelect;
@ -1529,7 +1529,7 @@ uint32_t Builder::GenerateTextureIntrinsic(const std::string& name,
->UnwrapAliasPtrAlias()
->AsTexture();
if (name == "texture_load") {
if (name == "textureLoad") {
auto spirv_params = {std::move(wgsl_params[0]),
std::move(wgsl_params[1]),
std::move(wgsl_params[2]),
@ -1551,17 +1551,17 @@ uint32_t Builder::GenerateTextureIntrinsic(const std::string& name,
std::move(wgsl_params[3]))),
std::move(wgsl_params[4])};
if (name == "texture_sample") {
if (name == "textureSample") {
op = spv::Op::OpImageSampleImplicitLod;
} else if (name == "texture_sample_level") {
} else if (name == "textureSampleLevel") {
op = spv::Op::OpImageSampleExplicitLod;
spirv_params.push_back(Operand::Int(SpvImageOperandsLodMask));
spirv_params.push_back(std::move(wgsl_params[5]));
} else if (name == "texture_sample_bias") {
} else if (name == "textureSampleBias") {
op = spv::Op::OpImageSampleImplicitLod;
spirv_params.push_back(Operand::Int(SpvImageOperandsBiasMask));
spirv_params.push_back(std::move(wgsl_params[5]));
} else if (name == "texture_sample_compare") {
} else if (name == "textureSampleCompare") {
op = spv::Op::OpImageSampleDrefExplicitLod;
spirv_params.push_back(std::move(wgsl_params[5]));

View File

@ -173,8 +173,8 @@ TEST_P(IntrinsicFloatTest, Call_Float_Vector) {
}
INSTANTIATE_TEST_SUITE_P(BuilderTest,
IntrinsicFloatTest,
testing::Values(IntrinsicData{"is_nan", "OpIsNan"},
IntrinsicData{"is_inf", "OpIsInf"}));
testing::Values(IntrinsicData{"isNan", "OpIsNan"},
IntrinsicData{"isInf", "OpIsInf"}));
TEST_F(BuilderTest, Call_Dot) {
ast::type::F32Type f32;
@ -301,14 +301,14 @@ INSTANTIATE_TEST_SUITE_P(
BuilderTest,
IntrinsicDeriveTest,
testing::Values(IntrinsicData{"dpdx", "OpDPdx"},
IntrinsicData{"dpdx_fine", "OpDPdxFine"},
IntrinsicData{"dpdx_coarse", "OpDPdxCoarse"},
IntrinsicData{"dpdxFine", "OpDPdxFine"},
IntrinsicData{"dpdxCoarse", "OpDPdxCoarse"},
IntrinsicData{"dpdy", "OpDPdy"},
IntrinsicData{"dpdy_fine", "OpDPdyFine"},
IntrinsicData{"dpdy_coarse", "OpDPdyCoarse"},
IntrinsicData{"dpdyFine", "OpDPdyFine"},
IntrinsicData{"dpdyCoarse", "OpDPdyCoarse"},
IntrinsicData{"fwidth", "OpFwidth"},
IntrinsicData{"fwidth_fine", "OpFwidthFine"},
IntrinsicData{"fwidth_coarse", "OpFwidthCoarse"}));
IntrinsicData{"fwidthFine", "OpFwidthFine"},
IntrinsicData{"fwidthCoarse", "OpFwidthCoarse"}));
TEST_F(BuilderTest, Call_OuterProduct) {
ast::type::F32Type f32;
@ -325,7 +325,7 @@ TEST_F(BuilderTest, Call_OuterProduct) {
params.push_back(std::make_unique<ast::IdentifierExpression>("v2"));
params.push_back(std::make_unique<ast::IdentifierExpression>("v3"));
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("outer_product"),
std::make_unique<ast::IdentifierExpression>("outerProduct"),
std::move(params));
Context ctx;
@ -665,7 +665,7 @@ TEST_P(Builder_TextureLoad, StorageReadonly) {
add_call_param("lod", &i32, &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_load"),
std::make_unique<ast::IdentifierExpression>("textureLoad"),
std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -724,7 +724,7 @@ TEST_P(Builder_TextureLoad, Sampled) {
add_call_param("lod", &i32, &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_load"),
std::make_unique<ast::IdentifierExpression>("textureLoad"),
std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -933,7 +933,7 @@ TEST_P(Builder_SampledTextureOperation, TextureSample) {
add_call_param("coords", coords_type.get(), &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample"),
std::make_unique<ast::IdentifierExpression>("textureSample"),
std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -994,7 +994,7 @@ TEST_P(Builder_SampledTextureOperation, TextureSampleLevel) {
add_call_param("lod", &f32, &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample_level"),
std::make_unique<ast::IdentifierExpression>("textureSampleLevel"),
std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -1055,7 +1055,7 @@ TEST_P(Builder_SampledTextureOperation, TextureSampleBias) {
add_call_param("bias", &f32, &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample_bias"),
std::make_unique<ast::IdentifierExpression>("textureSampleBias"),
std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -1176,7 +1176,7 @@ TEST_P(Builder_DepthTextureOperation, TextureSampleCompare) {
add_call_param("depth_reference", &f32, &call_params);
ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample_compare"),
std::make_unique<ast::IdentifierExpression>("textureSampleCompare"),
std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -1226,10 +1226,10 @@ TEST_F(Builder_TextureOperation, TextureSampleCompareTwice) {
add_call_param("depth_reference", &f32, &call_params_second);
ast::CallExpression expr_first(
std::make_unique<ast::IdentifierExpression>("texture_sample_compare"),
std::make_unique<ast::IdentifierExpression>("textureSampleCompare"),
std::move(call_params_first));
ast::CallExpression expr_second(
std::make_unique<ast::IdentifierExpression>("texture_sample_compare"),
std::make_unique<ast::IdentifierExpression>("textureSampleCompare"),
std::move(call_params_second));
EXPECT_TRUE(td()->DetermineResultType(&expr_first));