From 4e2d2484f8caf6ed48218ca4489b437204586904 Mon Sep 17 00:00:00 2001 From: Tomek Ponitka Date: Tue, 8 Sep 2020 16:30:29 +0000 Subject: [PATCH] [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 Reviewed-by: David Neto Commit-Queue: David Neto --- src/ast/intrinsic.cc | 17 +++++------ src/type_determiner.cc | 7 ++--- src/type_determiner_test.cc | 32 ++++++++++---------- src/writer/spirv/builder.cc | 28 +++++++++--------- src/writer/spirv/builder_intrinsic_test.cc | 34 +++++++++++----------- 5 files changed, 58 insertions(+), 60 deletions(-) diff --git a/src/ast/intrinsic.cc b/src/ast/intrinsic.cc index 164632ae0e..da5a855dce 100644 --- a/src/ast/intrinsic.cc +++ b/src/ast/intrinsic.cc @@ -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 diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 04ec17b30d..d2d3810205 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -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())); return true; @@ -633,7 +632,7 @@ bool TypeDeterminer::DetermineIntrinsic(const std::string& name, ctx_.type_mgr().Get(std::make_unique())); 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"); diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 0ba43ef732..52541c23d6 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -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; 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("texture_load"), + std::make_unique("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("texture_load"), + std::make_unique("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("texture_sample"), + std::make_unique("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("texture_sample_level"), + std::make_unique("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("texture_sample_bias"), + std::make_unique("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("texture_sample_compare"), + std::make_unique("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("v2")); ast::CallExpression expr( - std::make_unique("outer_product"), + std::make_unique("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("v2")); ast::CallExpression expr( - std::make_unique("outer_product"), + std::make_unique("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("v2")); ast::CallExpression expr( - std::make_unique("outer_product"), + std::make_unique("outerProduct"), std::move(call_params)); // Register the variable diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index a36b22e40e..3ac075124e 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -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])); diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc index dc1cbefbe6..1adfbb1c2e 100644 --- a/src/writer/spirv/builder_intrinsic_test.cc +++ b/src/writer/spirv/builder_intrinsic_test.cc @@ -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("v2")); params.push_back(std::make_unique("v3")); ast::CallExpression expr( - std::make_unique("outer_product"), + std::make_unique("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("texture_load"), + std::make_unique("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("texture_load"), + std::make_unique("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("texture_sample"), + std::make_unique("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("texture_sample_level"), + std::make_unique("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("texture_sample_bias"), + std::make_unique("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("texture_sample_compare"), + std::make_unique("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("texture_sample_compare"), + std::make_unique("textureSampleCompare"), std::move(call_params_first)); ast::CallExpression expr_second( - std::make_unique("texture_sample_compare"), + std::make_unique("textureSampleCompare"), std::move(call_params_second)); EXPECT_TRUE(td()->DetermineResultType(&expr_first));