From 2b706110f63fd4b4c78b6dded06985b211c5fade Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 11 Nov 2020 21:35:36 +0000 Subject: [PATCH] [inspector] Add better support for remapped entry point names Add remapped_name to entry point structure, also supply method to find the remapped name for individual entry points. BUG=tint:312 Change-Id: I5f2cc02bc37c17e99c453b16108bc8e10c602fba Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32383 Reviewed-by: dan sinclair Reviewed-by: Austin Eng Commit-Queue: Ryan Harrison --- src/inspector/entry_point.h | 2 + src/inspector/inspector.cc | 13 +++++- src/inspector/inspector.h | 7 +++ src/inspector/inspector_test.cc | 80 +++++++++++++++++++++++++++++---- 4 files changed, 91 insertions(+), 11 deletions(-) diff --git a/src/inspector/entry_point.h b/src/inspector/entry_point.h index 137f41a92c..13e023429e 100644 --- a/src/inspector/entry_point.h +++ b/src/inspector/entry_point.h @@ -36,6 +36,8 @@ typedef struct EntryPoint { /// The entry point name std::string name; + /// Remapped entry point name in the backend + std::string remapped_name; /// The entry point stage ast::PipelineStage stage = ast::PipelineStage::kNone; /// The workgroup x size diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index b170d87165..61016fbc16 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -48,9 +48,9 @@ std::vector Inspector::GetEntryPoints() { continue; } - Namer namer; EntryPoint entry_point; - entry_point.name = namer.NameFor(func->name()); + entry_point.name = func->name(); + entry_point.remapped_name = namer_.NameFor(func->name()); entry_point.stage = func->pipeline_stage(); std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y, entry_point.workgroup_size_z) = func->workgroup_size(); @@ -68,6 +68,15 @@ std::vector Inspector::GetEntryPoints() { return result; } +std::string Inspector::GetRemappedNamedForEntryPoint( + const std::string& entry_point) { + auto* func = FindEntryPointByName(entry_point); + if (!func) { + return {}; + } + return namer_.NameFor(entry_point); +} + std::map Inspector::GetConstantIDs() { std::map result; for (auto& var : module_.global_variables()) { diff --git a/src/inspector/inspector.h b/src/inspector/inspector.h index da49ff1382..f3c9b11311 100644 --- a/src/inspector/inspector.h +++ b/src/inspector/inspector.h @@ -25,6 +25,7 @@ #include "src/ast/pipeline_stage.h" #include "src/inspector/entry_point.h" #include "src/inspector/scalar.h" +#include "src/namer.h" namespace tint { namespace inspector { @@ -77,6 +78,11 @@ class Inspector { /// @returns vector of entry point information std::vector GetEntryPoints(); + /// @param entry_point name of the entry point to get the remapped version of + /// @returns the remapped name of the entry point, or the empty string if it + /// isn't a known entry point. + std::string GetRemappedNamedForEntryPoint(const std::string& entry_point); + /// @returns map of const_id to initial value std::map GetConstantIDs(); @@ -113,6 +119,7 @@ class Inspector { private: const ast::Module& module_; std::string error_; + tint::Namer namer_; /// @param name name of the entry point to find /// @returns a pointer to the entry point if it exists, otherwise returns diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index d4803a56a7..f15b058747 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -643,6 +643,8 @@ class InspectorHelper { class InspectorGetEntryPointTest : public InspectorHelper, public testing::Test {}; +class InspectorGetRemappedNamedForEntryPointTest : public InspectorHelper, + public testing::Test {}; class InspectorGetConstantIDsTest : public InspectorHelper, public testing::Test {}; class InspectorGetUniformBufferResourceBindingsTest : public InspectorHelper, @@ -694,7 +696,8 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) { ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_EQ(1u, result.size()); - EXPECT_EQ("tint_666f6f", result[0].name); + EXPECT_EQ("foo", result[0].name); + EXPECT_EQ("tint_666f6f", result[0].remapped_name); EXPECT_EQ(ast::PipelineStage::kVertex, result[0].stage); } @@ -713,9 +716,11 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) { ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_EQ(2u, result.size()); - EXPECT_EQ("tint_666f6f", result[0].name); + EXPECT_EQ("foo", result[0].name); + EXPECT_EQ("tint_666f6f", result[0].remapped_name); EXPECT_EQ(ast::PipelineStage::kVertex, result[0].stage); - EXPECT_EQ("tint_626172", result[1].name); + EXPECT_EQ("bar", result[1].name); + EXPECT_EQ("tint_626172", result[1].remapped_name); EXPECT_EQ(ast::PipelineStage::kCompute, result[1].stage); } @@ -737,9 +742,11 @@ TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) { EXPECT_FALSE(inspector()->has_error()); ASSERT_EQ(2u, result.size()); - EXPECT_EQ("tint_666f6f", result[0].name); + EXPECT_EQ("foo", result[0].name); + EXPECT_EQ("tint_666f6f", result[0].remapped_name); EXPECT_EQ(ast::PipelineStage::kVertex, result[0].stage); - EXPECT_EQ("tint_626172", result[1].name); + EXPECT_EQ("bar", result[1].name); + EXPECT_EQ("tint_626172", result[1].remapped_name); EXPECT_EQ(ast::PipelineStage::kFragment, result[1].stage); } @@ -937,13 +944,15 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) { ASSERT_EQ(2u, result.size()); - ASSERT_EQ("tint_666f6f", result[0].name); + ASSERT_EQ("foo", result[0].name); + ASSERT_EQ("tint_666f6f", result[0].remapped_name); ASSERT_EQ(1u, result[0].input_variables.size()); EXPECT_EQ("in_var", result[0].input_variables[0]); ASSERT_EQ(1u, result[0].output_variables.size()); EXPECT_EQ("out2_var", result[0].output_variables[0]); - ASSERT_EQ("tint_626172", result[1].name); + ASSERT_EQ("bar", result[1].name); + ASSERT_EQ("tint_626172", result[1].remapped_name); ASSERT_EQ(1u, result[1].input_variables.size()); EXPECT_EQ("in2_var", result[1].input_variables[0]); ASSERT_EQ(1u, result[1].output_variables.size()); @@ -974,7 +983,8 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) { ASSERT_EQ(2u, result.size()); - ASSERT_EQ("tint_666f6f", result[0].name); + ASSERT_EQ("foo", result[0].name); + ASSERT_EQ("tint_666f6f", result[0].remapped_name); EXPECT_EQ(2u, result[0].input_variables.size()); EXPECT_TRUE(ContainsString(result[0].input_variables, "in_var")); EXPECT_TRUE(ContainsString(result[0].input_variables, "in2_var")); @@ -982,13 +992,65 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) { EXPECT_TRUE(ContainsString(result[0].output_variables, "out_var")); EXPECT_TRUE(ContainsString(result[0].output_variables, "out2_var")); - ASSERT_EQ("tint_626172", result[1].name); + ASSERT_EQ("bar", result[1].name); + ASSERT_EQ("tint_626172", result[1].remapped_name); EXPECT_EQ(1u, result[1].input_variables.size()); EXPECT_EQ("in2_var", result[1].input_variables[0]); EXPECT_EQ(1u, result[1].output_variables.size()); EXPECT_EQ("out2_var", result[1].output_variables[0]); } +TEST_F(InspectorGetRemappedNamedForEntryPointTest, NoFunctions) { + auto result = inspector()->GetRemappedNamedForEntryPoint("foo"); + ASSERT_TRUE(inspector()->has_error()); + + EXPECT_EQ("", result); +} + +TEST_F(InspectorGetRemappedNamedForEntryPointTest, NoEntryPoints) { + mod()->AddFunction(MakeEmptyBodyFunction("foo")); + + auto result = inspector()->GetRemappedNamedForEntryPoint("foo"); + ASSERT_TRUE(inspector()->has_error()); + + EXPECT_EQ("", result); +} + +TEST_F(InspectorGetRemappedNamedForEntryPointTest, OneEntryPoint) { + auto foo = MakeEmptyBodyFunction("foo"); + foo->add_decoration(std::make_unique( + ast::PipelineStage::kVertex, Source{})); + mod()->AddFunction(std::move(foo)); + + auto result = inspector()->GetRemappedNamedForEntryPoint("foo"); + ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); + + EXPECT_EQ("tint_666f6f", result); +} + +TEST_F(InspectorGetRemappedNamedForEntryPointTest, MultipleEntryPoints) { + auto foo = MakeEmptyBodyFunction("foo"); + foo->add_decoration(std::make_unique( + ast::PipelineStage::kVertex, Source{})); + mod()->AddFunction(std::move(foo)); + + auto bar = MakeEmptyBodyFunction("bar"); + bar->add_decoration(std::make_unique( + ast::PipelineStage::kCompute, Source{})); + mod()->AddFunction(std::move(bar)); + + { + auto result = inspector()->GetRemappedNamedForEntryPoint("foo"); + ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); + EXPECT_EQ("tint_666f6f", result); + } + { + auto result = inspector()->GetRemappedNamedForEntryPoint("bar"); + ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); + EXPECT_EQ("tint_626172", result); + } +} + TEST_F(InspectorGetConstantIDsTest, Bool) { bool val_true = true; bool val_false = false;