[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 <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/inspector/entry_point.h b/src/inspector/entry_point.h
index 028f6d8..aac9a4c 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 @@
/// 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 @@
return std::tuple<uint32_t, uint32_t, uint32_t>(
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 170e72c..b049940 100644
--- a/src/inspector/inspector.cc
+++ b/src/inspector/inspector.cc
@@ -208,6 +208,17 @@
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 8622c8f..fe73540 100644
--- a/src/inspector/inspector_test.cc
+++ b/src/inspector/inspector_test.cc
@@ -916,10 +916,13 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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