[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 { namespace intrinsic {
bool IsCoarseDerivative(const std::string& name) { bool IsCoarseDerivative(const std::string& name) {
return name == "dpdx_coarse" || name == "dpdy_coarse" || return name == "dpdxCoarse" || name == "dpdyCoarse" || name == "fwidthCoarse";
name == "fwidth_coarse";
} }
bool IsFineDerivative(const std::string& name) { 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) { bool IsDerivative(const std::string& name) {
@ -33,21 +32,21 @@ bool IsDerivative(const std::string& name) {
} }
bool IsFloatClassificationIntrinsic(const std::string& name) { bool IsFloatClassificationIntrinsic(const std::string& name) {
return name == "is_finite" || name == "is_inf" || name == "is_nan" || return name == "isFinite" || name == "isInf" || name == "isNan" ||
name == "is_normal"; name == "isNormal";
} }
bool IsTextureOperationIntrinsic(const std::string& name) { bool IsTextureOperationIntrinsic(const std::string& name) {
return name == "texture_load" || name == "texture_sample" || return name == "textureLoad" || name == "textureSample" ||
name == "texture_sample_level" || name == "texture_sample_bias" || name == "textureSampleLevel" || name == "textureSampleBias" ||
name == "texture_sample_compare"; name == "textureSampleCompare";
} }
bool IsIntrinsic(const std::string& name) { bool IsIntrinsic(const std::string& name) {
return IsDerivative(name) || name == "all" || name == "any" || return IsDerivative(name) || name == "all" || name == "any" ||
IsFloatClassificationIntrinsic(name) || IsFloatClassificationIntrinsic(name) ||
IsTextureOperationIntrinsic(name) || name == "dot" || IsTextureOperationIntrinsic(name) || name == "dot" ||
name == "outer_product" || name == "select"; name == "outerProduct" || name == "select";
} }
} // namespace intrinsic } // namespace intrinsic

View File

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

View File

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

View File

@ -1485,27 +1485,27 @@ uint32_t Builder::GenerateIntrinsic(const std::string& name,
op = spv::Op::OpDot; op = spv::Op::OpDot;
} else if (name == "dpdx") { } else if (name == "dpdx") {
op = spv::Op::OpDPdx; op = spv::Op::OpDPdx;
} else if (name == "dpdx_coarse") { } else if (name == "dpdxCoarse") {
op = spv::Op::OpDPdxCoarse; op = spv::Op::OpDPdxCoarse;
} else if (name == "dpdx_fine") { } else if (name == "dpdxFine") {
op = spv::Op::OpDPdxFine; op = spv::Op::OpDPdxFine;
} else if (name == "dpdy") { } else if (name == "dpdy") {
op = spv::Op::OpDPdy; op = spv::Op::OpDPdy;
} else if (name == "dpdy_coarse") { } else if (name == "dpdyCoarse") {
op = spv::Op::OpDPdyCoarse; op = spv::Op::OpDPdyCoarse;
} else if (name == "dpdy_fine") { } else if (name == "dpdyFine") {
op = spv::Op::OpDPdyFine; op = spv::Op::OpDPdyFine;
} else if (name == "fwidth") { } else if (name == "fwidth") {
op = spv::Op::OpFwidth; op = spv::Op::OpFwidth;
} else if (name == "fwidth_coarse") { } else if (name == "fwidthCoarse") {
op = spv::Op::OpFwidthCoarse; op = spv::Op::OpFwidthCoarse;
} else if (name == "fwidth_fine") { } else if (name == "fwidthFine") {
op = spv::Op::OpFwidthFine; op = spv::Op::OpFwidthFine;
} else if (name == "is_inf") { } else if (name == "isInf") {
op = spv::Op::OpIsInf; op = spv::Op::OpIsInf;
} else if (name == "is_nan") { } else if (name == "isNan") {
op = spv::Op::OpIsNan; op = spv::Op::OpIsNan;
} else if (name == "outer_product") { } else if (name == "outerProduct") {
op = spv::Op::OpOuterProduct; op = spv::Op::OpOuterProduct;
} else if (name == "select") { } else if (name == "select") {
op = spv::Op::OpSelect; op = spv::Op::OpSelect;
@ -1529,7 +1529,7 @@ uint32_t Builder::GenerateTextureIntrinsic(const std::string& name,
->UnwrapAliasPtrAlias() ->UnwrapAliasPtrAlias()
->AsTexture(); ->AsTexture();
if (name == "texture_load") { if (name == "textureLoad") {
auto spirv_params = {std::move(wgsl_params[0]), auto spirv_params = {std::move(wgsl_params[0]),
std::move(wgsl_params[1]), std::move(wgsl_params[1]),
std::move(wgsl_params[2]), 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[3]))),
std::move(wgsl_params[4])}; std::move(wgsl_params[4])};
if (name == "texture_sample") { if (name == "textureSample") {
op = spv::Op::OpImageSampleImplicitLod; op = spv::Op::OpImageSampleImplicitLod;
} else if (name == "texture_sample_level") { } else if (name == "textureSampleLevel") {
op = spv::Op::OpImageSampleExplicitLod; op = spv::Op::OpImageSampleExplicitLod;
spirv_params.push_back(Operand::Int(SpvImageOperandsLodMask)); spirv_params.push_back(Operand::Int(SpvImageOperandsLodMask));
spirv_params.push_back(std::move(wgsl_params[5])); spirv_params.push_back(std::move(wgsl_params[5]));
} else if (name == "texture_sample_bias") { } else if (name == "textureSampleBias") {
op = spv::Op::OpImageSampleImplicitLod; op = spv::Op::OpImageSampleImplicitLod;
spirv_params.push_back(Operand::Int(SpvImageOperandsBiasMask)); spirv_params.push_back(Operand::Int(SpvImageOperandsBiasMask));
spirv_params.push_back(std::move(wgsl_params[5])); spirv_params.push_back(std::move(wgsl_params[5]));
} else if (name == "texture_sample_compare") { } else if (name == "textureSampleCompare") {
op = spv::Op::OpImageSampleDrefExplicitLod; op = spv::Op::OpImageSampleDrefExplicitLod;
spirv_params.push_back(std::move(wgsl_params[5])); 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, INSTANTIATE_TEST_SUITE_P(BuilderTest,
IntrinsicFloatTest, IntrinsicFloatTest,
testing::Values(IntrinsicData{"is_nan", "OpIsNan"}, testing::Values(IntrinsicData{"isNan", "OpIsNan"},
IntrinsicData{"is_inf", "OpIsInf"})); IntrinsicData{"isInf", "OpIsInf"}));
TEST_F(BuilderTest, Call_Dot) { TEST_F(BuilderTest, Call_Dot) {
ast::type::F32Type f32; ast::type::F32Type f32;
@ -301,14 +301,14 @@ INSTANTIATE_TEST_SUITE_P(
BuilderTest, BuilderTest,
IntrinsicDeriveTest, IntrinsicDeriveTest,
testing::Values(IntrinsicData{"dpdx", "OpDPdx"}, testing::Values(IntrinsicData{"dpdx", "OpDPdx"},
IntrinsicData{"dpdx_fine", "OpDPdxFine"}, IntrinsicData{"dpdxFine", "OpDPdxFine"},
IntrinsicData{"dpdx_coarse", "OpDPdxCoarse"}, IntrinsicData{"dpdxCoarse", "OpDPdxCoarse"},
IntrinsicData{"dpdy", "OpDPdy"}, IntrinsicData{"dpdy", "OpDPdy"},
IntrinsicData{"dpdy_fine", "OpDPdyFine"}, IntrinsicData{"dpdyFine", "OpDPdyFine"},
IntrinsicData{"dpdy_coarse", "OpDPdyCoarse"}, IntrinsicData{"dpdyCoarse", "OpDPdyCoarse"},
IntrinsicData{"fwidth", "OpFwidth"}, IntrinsicData{"fwidth", "OpFwidth"},
IntrinsicData{"fwidth_fine", "OpFwidthFine"}, IntrinsicData{"fwidthFine", "OpFwidthFine"},
IntrinsicData{"fwidth_coarse", "OpFwidthCoarse"})); IntrinsicData{"fwidthCoarse", "OpFwidthCoarse"}));
TEST_F(BuilderTest, Call_OuterProduct) { TEST_F(BuilderTest, Call_OuterProduct) {
ast::type::F32Type f32; 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>("v2"));
params.push_back(std::make_unique<ast::IdentifierExpression>("v3")); params.push_back(std::make_unique<ast::IdentifierExpression>("v3"));
ast::CallExpression expr( ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("outer_product"), std::make_unique<ast::IdentifierExpression>("outerProduct"),
std::move(params)); std::move(params));
Context ctx; Context ctx;
@ -665,7 +665,7 @@ TEST_P(Builder_TextureLoad, StorageReadonly) {
add_call_param("lod", &i32, &call_params); add_call_param("lod", &i32, &call_params);
ast::CallExpression expr( ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_load"), std::make_unique<ast::IdentifierExpression>("textureLoad"),
std::move(call_params)); std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr)); EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -724,7 +724,7 @@ TEST_P(Builder_TextureLoad, Sampled) {
add_call_param("lod", &i32, &call_params); add_call_param("lod", &i32, &call_params);
ast::CallExpression expr( ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_load"), std::make_unique<ast::IdentifierExpression>("textureLoad"),
std::move(call_params)); std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr)); EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -933,7 +933,7 @@ TEST_P(Builder_SampledTextureOperation, TextureSample) {
add_call_param("coords", coords_type.get(), &call_params); add_call_param("coords", coords_type.get(), &call_params);
ast::CallExpression expr( ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample"), std::make_unique<ast::IdentifierExpression>("textureSample"),
std::move(call_params)); std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr)); EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -994,7 +994,7 @@ TEST_P(Builder_SampledTextureOperation, TextureSampleLevel) {
add_call_param("lod", &f32, &call_params); add_call_param("lod", &f32, &call_params);
ast::CallExpression expr( ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample_level"), std::make_unique<ast::IdentifierExpression>("textureSampleLevel"),
std::move(call_params)); std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr)); EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -1055,7 +1055,7 @@ TEST_P(Builder_SampledTextureOperation, TextureSampleBias) {
add_call_param("bias", &f32, &call_params); add_call_param("bias", &f32, &call_params);
ast::CallExpression expr( ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample_bias"), std::make_unique<ast::IdentifierExpression>("textureSampleBias"),
std::move(call_params)); std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr)); EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -1176,7 +1176,7 @@ TEST_P(Builder_DepthTextureOperation, TextureSampleCompare) {
add_call_param("depth_reference", &f32, &call_params); add_call_param("depth_reference", &f32, &call_params);
ast::CallExpression expr( ast::CallExpression expr(
std::make_unique<ast::IdentifierExpression>("texture_sample_compare"), std::make_unique<ast::IdentifierExpression>("textureSampleCompare"),
std::move(call_params)); std::move(call_params));
EXPECT_TRUE(td()->DetermineResultType(&expr)); EXPECT_TRUE(td()->DetermineResultType(&expr));
@ -1226,10 +1226,10 @@ TEST_F(Builder_TextureOperation, TextureSampleCompareTwice) {
add_call_param("depth_reference", &f32, &call_params_second); add_call_param("depth_reference", &f32, &call_params_second);
ast::CallExpression expr_first( ast::CallExpression expr_first(
std::make_unique<ast::IdentifierExpression>("texture_sample_compare"), std::make_unique<ast::IdentifierExpression>("textureSampleCompare"),
std::move(call_params_first)); std::move(call_params_first));
ast::CallExpression expr_second( ast::CallExpression expr_second(
std::make_unique<ast::IdentifierExpression>("texture_sample_compare"), std::make_unique<ast::IdentifierExpression>("textureSampleCompare"),
std::move(call_params_second)); std::move(call_params_second));
EXPECT_TRUE(td()->DetermineResultType(&expr_first)); EXPECT_TRUE(td()->DetermineResultType(&expr_first));