[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 <dsinclair@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
Ryan Harrison 2020-11-11 21:35:36 +00:00 committed by Commit Bot service account
parent f8cf585582
commit 2b706110f6
4 changed files with 91 additions and 11 deletions

View File

@ -36,6 +36,8 @@ typedef struct EntryPoint {
/// The entry point name /// The entry point name
std::string name; std::string name;
/// Remapped entry point name in the backend
std::string remapped_name;
/// The entry point stage /// The entry point stage
ast::PipelineStage stage = ast::PipelineStage::kNone; ast::PipelineStage stage = ast::PipelineStage::kNone;
/// The workgroup x size /// The workgroup x size

View File

@ -48,9 +48,9 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
continue; continue;
} }
Namer namer;
EntryPoint entry_point; 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(); entry_point.stage = func->pipeline_stage();
std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y, std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y,
entry_point.workgroup_size_z) = func->workgroup_size(); entry_point.workgroup_size_z) = func->workgroup_size();
@ -68,6 +68,15 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
return result; 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<uint32_t, Scalar> Inspector::GetConstantIDs() { std::map<uint32_t, Scalar> Inspector::GetConstantIDs() {
std::map<uint32_t, Scalar> result; std::map<uint32_t, Scalar> result;
for (auto& var : module_.global_variables()) { for (auto& var : module_.global_variables()) {

View File

@ -25,6 +25,7 @@
#include "src/ast/pipeline_stage.h" #include "src/ast/pipeline_stage.h"
#include "src/inspector/entry_point.h" #include "src/inspector/entry_point.h"
#include "src/inspector/scalar.h" #include "src/inspector/scalar.h"
#include "src/namer.h"
namespace tint { namespace tint {
namespace inspector { namespace inspector {
@ -77,6 +78,11 @@ class Inspector {
/// @returns vector of entry point information /// @returns vector of entry point information
std::vector<EntryPoint> GetEntryPoints(); std::vector<EntryPoint> 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 /// @returns map of const_id to initial value
std::map<uint32_t, Scalar> GetConstantIDs(); std::map<uint32_t, Scalar> GetConstantIDs();
@ -113,6 +119,7 @@ class Inspector {
private: private:
const ast::Module& module_; const ast::Module& module_;
std::string error_; std::string error_;
tint::Namer namer_;
/// @param name name of the entry point to find /// @param name name of the entry point to find
/// @returns a pointer to the entry point if it exists, otherwise returns /// @returns a pointer to the entry point if it exists, otherwise returns

View File

@ -643,6 +643,8 @@ class InspectorHelper {
class InspectorGetEntryPointTest : public InspectorHelper, class InspectorGetEntryPointTest : public InspectorHelper,
public testing::Test {}; public testing::Test {};
class InspectorGetRemappedNamedForEntryPointTest : public InspectorHelper,
public testing::Test {};
class InspectorGetConstantIDsTest : public InspectorHelper, class InspectorGetConstantIDsTest : public InspectorHelper,
public testing::Test {}; public testing::Test {};
class InspectorGetUniformBufferResourceBindingsTest : public InspectorHelper, class InspectorGetUniformBufferResourceBindingsTest : public InspectorHelper,
@ -694,7 +696,8 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
ASSERT_EQ(1u, result.size()); 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); EXPECT_EQ(ast::PipelineStage::kVertex, result[0].stage);
} }
@ -713,9 +716,11 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
ASSERT_EQ(2u, result.size()); 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(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); EXPECT_EQ(ast::PipelineStage::kCompute, result[1].stage);
} }
@ -737,9 +742,11 @@ TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {
EXPECT_FALSE(inspector()->has_error()); EXPECT_FALSE(inspector()->has_error());
ASSERT_EQ(2u, result.size()); 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(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); EXPECT_EQ(ast::PipelineStage::kFragment, result[1].stage);
} }
@ -937,13 +944,15 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
ASSERT_EQ(2u, result.size()); 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()); ASSERT_EQ(1u, result[0].input_variables.size());
EXPECT_EQ("in_var", result[0].input_variables[0]); EXPECT_EQ("in_var", result[0].input_variables[0]);
ASSERT_EQ(1u, result[0].output_variables.size()); ASSERT_EQ(1u, result[0].output_variables.size());
EXPECT_EQ("out2_var", result[0].output_variables[0]); 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()); ASSERT_EQ(1u, result[1].input_variables.size());
EXPECT_EQ("in2_var", result[1].input_variables[0]); EXPECT_EQ("in2_var", result[1].input_variables[0]);
ASSERT_EQ(1u, result[1].output_variables.size()); ASSERT_EQ(1u, result[1].output_variables.size());
@ -974,7 +983,8 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
ASSERT_EQ(2u, result.size()); 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_EQ(2u, result[0].input_variables.size());
EXPECT_TRUE(ContainsString(result[0].input_variables, "in_var")); EXPECT_TRUE(ContainsString(result[0].input_variables, "in_var"));
EXPECT_TRUE(ContainsString(result[0].input_variables, "in2_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, "out_var"));
EXPECT_TRUE(ContainsString(result[0].output_variables, "out2_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(1u, result[1].input_variables.size());
EXPECT_EQ("in2_var", result[1].input_variables[0]); EXPECT_EQ("in2_var", result[1].input_variables[0]);
EXPECT_EQ(1u, result[1].output_variables.size()); EXPECT_EQ(1u, result[1].output_variables.size());
EXPECT_EQ("out2_var", result[1].output_variables[0]); 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::StageDecoration>(
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::StageDecoration>(
ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(foo));
auto bar = MakeEmptyBodyFunction("bar");
bar->add_decoration(std::make_unique<ast::StageDecoration>(
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) { TEST_F(InspectorGetConstantIDsTest, Bool) {
bool val_true = true; bool val_true = true;
bool val_false = false; bool val_false = false;