From f1773c6700d8a11d0d614d25a54260529280454a Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 11 Mar 2021 16:37:32 +0000 Subject: [PATCH] [inspector] Include component type information for stage variables BUG=tint:630 Change-Id: Ib30221e7a2d35e77a164969428ed6bfc07bc2a8e Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44340 Auto-Submit: Ryan Harrison Reviewed-by: Ben Clayton Commit-Queue: Ben Clayton --- src/inspector/entry_point.h | 18 ++++++++++--- src/inspector/inspector.cc | 11 ++++++++ src/inspector/inspector_test.cc | 45 +++++++++++++++++++++++++++++---- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/inspector/entry_point.h b/src/inspector/entry_point.h index 028f6d8992..aac9a4c34e 100644 --- a/src/inspector/entry_point.h +++ b/src/inspector/entry_point.h @@ -24,8 +24,16 @@ namespace tint { namespace inspector { +/// Base component type of a stage variable. +enum class ComponentType { + kUnknown = -1, + kFloat, + kUInt, + kSInt, +}; + /// Reflection data about an entry point input or output. -typedef struct { +struct StageVariable { /// Name of the variable in the shader. std::string name; /// Is Location Decoration present @@ -33,10 +41,12 @@ typedef struct { /// Value of Location Decoration, only valid if |has_location_decoration| is /// true. uint32_t location_decoration; -} StageVariable; + /// Scalar type that the variable is composed of. + ComponentType component_type; +}; /// Reflection data for an entry point in the shader. -typedef struct EntryPoint { +struct EntryPoint { /// Constructors EntryPoint(); /// Copy Constructor @@ -67,7 +77,7 @@ typedef struct EntryPoint { return std::tuple( workgroup_size_x, workgroup_size_y, workgroup_size_z); } -} EntryPoint; +}; } // namespace inspector } // namespace tint diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index 170e72c920..b049940d2d 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -208,6 +208,17 @@ std::vector Inspector::GetEntryPoints() { StageVariable stage_variable; stage_variable.name = name; + + stage_variable.component_type = ComponentType::kUnknown; + auto* type = var->Declaration()->type()->UnwrapAll(); + if (type->is_float_scalar_or_vector() || type->is_float_matrix()) { + stage_variable.component_type = ComponentType::kFloat; + } else if (type->is_unsigned_scalar_or_vector()) { + stage_variable.component_type = ComponentType::kUInt; + } else if (type->is_signed_scalar_or_vector()) { + stage_variable.component_type = ComponentType::kSInt; + } + auto* location_decoration = decl->GetLocationDecoration(); if (location_decoration) { stage_variable.has_location_decoration = true; diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index 8622c8f9fa..fe735405d5 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -916,10 +916,13 @@ TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) { EXPECT_EQ("in_var", result[0].input_variables[0].name); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_EQ(0u, result[0].input_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].input_variables[0].component_type); + ASSERT_EQ(1u, result[0].output_variables.size()); EXPECT_EQ("out_var", result[0].output_variables[0].name); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_EQ(1u, result[0].output_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[0].component_type); } TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) { @@ -944,10 +947,13 @@ TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) { EXPECT_EQ("in_var", result[0].input_variables[0].name); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_EQ(0u, result[0].input_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].input_variables[0].component_type); + ASSERT_EQ(1u, result[0].output_variables.size()); EXPECT_EQ("out_var", result[0].output_variables[0].name); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_EQ(1u, result[0].output_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[0].component_type); } TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) { @@ -972,10 +978,13 @@ TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) { EXPECT_EQ("in_var", result[0].input_variables[0].name); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_EQ(0u, result[0].input_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].input_variables[0].component_type); + ASSERT_EQ(1u, result[0].output_variables.size()); EXPECT_EQ("out_var", result[0].output_variables[0].name); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_EQ(1u, result[0].output_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[0].component_type); } TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) { @@ -999,15 +1008,20 @@ TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) { EXPECT_TRUE(ContainsName(result[0].input_variables, "in2_var")); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_EQ(0u, result[0].input_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].input_variables[0].component_type); EXPECT_TRUE(result[0].input_variables[1].has_location_decoration); EXPECT_EQ(2u, result[0].input_variables[1].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].input_variables[1].component_type); + ASSERT_EQ(2u, result[0].output_variables.size()); EXPECT_TRUE(ContainsName(result[0].output_variables, "out_var")); EXPECT_TRUE(ContainsName(result[0].output_variables, "out2_var")); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_EQ(1u, result[0].output_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[0].component_type); EXPECT_TRUE(result[0].output_variables[1].has_location_decoration); EXPECT_EQ(3u, result[0].output_variables[1].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[1].component_type); } TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) { @@ -1034,16 +1048,20 @@ TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) { EXPECT_TRUE(ContainsName(result[0].input_variables, "in2_var")); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_EQ(0u, result[0].input_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].input_variables[0].component_type); EXPECT_TRUE(result[0].input_variables[1].has_location_decoration); EXPECT_EQ(2u, result[0].input_variables[1].location_decoration); - ASSERT_EQ(2u, result[0].output_variables.size()); + EXPECT_EQ(ComponentType::kUInt, result[0].input_variables[1].component_type); + ASSERT_EQ(2u, result[0].output_variables.size()); EXPECT_TRUE(ContainsName(result[0].output_variables, "out_var")); EXPECT_TRUE(ContainsName(result[0].output_variables, "out2_var")); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_EQ(1u, result[0].output_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[0].component_type); EXPECT_TRUE(result[0].output_variables[1].has_location_decoration); EXPECT_EQ(3u, result[0].output_variables[1].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[1].component_type); } TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) { @@ -1073,25 +1091,33 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) { ASSERT_EQ("foo", result[0].name); ASSERT_EQ("foo", result[0].remapped_name); + ASSERT_EQ(1u, result[0].input_variables.size()); EXPECT_EQ("in_var", result[0].input_variables[0].name); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_EQ(0u, result[0].input_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].input_variables[0].component_type); + ASSERT_EQ(1u, result[0].output_variables.size()); EXPECT_EQ("out2_var", result[0].output_variables[0].name); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_EQ(3u, result[0].output_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[0].component_type); ASSERT_EQ("bar", result[1].name); ASSERT_EQ("bar", result[1].remapped_name); + ASSERT_EQ(1u, result[1].input_variables.size()); EXPECT_EQ("in2_var", result[1].input_variables[0].name); EXPECT_TRUE(result[1].input_variables[0].has_location_decoration); EXPECT_EQ(2u, result[1].input_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[1].input_variables[0].component_type); + ASSERT_EQ(1u, result[1].output_variables.size()); EXPECT_EQ("out_var", result[1].output_variables[0].name); EXPECT_TRUE(result[1].output_variables[0].has_location_decoration); EXPECT_EQ(1u, result[1].output_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[1].output_variables[0].component_type); } TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) { @@ -1123,33 +1149,41 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) { ASSERT_EQ("foo", result[0].name); ASSERT_EQ("foo", result[0].remapped_name); - EXPECT_EQ(2u, result[0].input_variables.size()); + + ASSERT_EQ(2u, result[0].input_variables.size()); EXPECT_TRUE(ContainsName(result[0].input_variables, "in_var")); EXPECT_TRUE(ContainsName(result[0].input_variables, "in2_var")); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_EQ(0u, result[0].input_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].input_variables[0].component_type); EXPECT_TRUE(result[0].input_variables[1].has_location_decoration); EXPECT_EQ(2u, result[0].input_variables[1].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].input_variables[1].component_type); - EXPECT_EQ(2u, result[0].output_variables.size()); + ASSERT_EQ(2u, result[0].output_variables.size()); EXPECT_TRUE(ContainsName(result[0].output_variables, "out_var")); EXPECT_TRUE(ContainsName(result[0].output_variables, "out2_var")); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_EQ(1u, result[0].output_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[0].component_type); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_EQ(3u, result[0].output_variables[1].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[1].component_type); ASSERT_EQ("bar", result[1].name); ASSERT_EQ("bar", result[1].remapped_name); - EXPECT_EQ(1u, result[1].input_variables.size()); + + ASSERT_EQ(1u, result[1].input_variables.size()); EXPECT_EQ("in2_var", result[1].input_variables[0].name); EXPECT_TRUE(result[1].input_variables[0].has_location_decoration); EXPECT_EQ(2u, result[1].input_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[1].input_variables[0].component_type); - EXPECT_EQ(1u, result[1].output_variables.size()); + ASSERT_EQ(1u, result[1].output_variables.size()); EXPECT_EQ("out2_var", result[1].output_variables[0].name); EXPECT_TRUE(result[1].output_variables[0].has_location_decoration); EXPECT_EQ(3u, result[1].output_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[1].output_variables[0].component_type); } TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) { @@ -1183,6 +1217,7 @@ TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) { EXPECT_TRUE(ContainsName(result[0].output_variables, "out_var")); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_EQ(0u, result[0].output_variables[0].location_decoration); + EXPECT_EQ(ComponentType::kUInt, result[0].output_variables[0].component_type); } // TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass