[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>
This commit is contained in:
Ryan Harrison 2021-03-11 16:37:32 +00:00 committed by Commit Bot service account
parent a0d48382cb
commit f1773c6700
3 changed files with 65 additions and 9 deletions

View File

@ -24,8 +24,16 @@
namespace tint { namespace tint {
namespace inspector { 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. /// Reflection data about an entry point input or output.
typedef struct { struct StageVariable {
/// Name of the variable in the shader. /// Name of the variable in the shader.
std::string name; std::string name;
/// Is Location Decoration present /// Is Location Decoration present
@ -33,10 +41,12 @@ typedef struct {
/// Value of Location Decoration, only valid if |has_location_decoration| is /// Value of Location Decoration, only valid if |has_location_decoration| is
/// true. /// true.
uint32_t location_decoration; 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. /// Reflection data for an entry point in the shader.
typedef struct EntryPoint { struct EntryPoint {
/// Constructors /// Constructors
EntryPoint(); EntryPoint();
/// Copy Constructor /// Copy Constructor
@ -67,7 +77,7 @@ typedef struct EntryPoint {
return std::tuple<uint32_t, uint32_t, uint32_t>( return std::tuple<uint32_t, uint32_t, uint32_t>(
workgroup_size_x, workgroup_size_y, workgroup_size_z); workgroup_size_x, workgroup_size_y, workgroup_size_z);
} }
} EntryPoint; };
} // namespace inspector } // namespace inspector
} // namespace tint } // namespace tint

View File

@ -208,6 +208,17 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
StageVariable stage_variable; StageVariable stage_variable;
stage_variable.name = name; 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(); auto* location_decoration = decl->GetLocationDecoration();
if (location_decoration) { if (location_decoration) {
stage_variable.has_location_decoration = true; stage_variable.has_location_decoration = true;

View File

@ -916,10 +916,13 @@ TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) {
EXPECT_EQ("in_var", result[0].input_variables[0].name); EXPECT_EQ("in_var", result[0].input_variables[0].name);
EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration);
EXPECT_EQ(0u, result[0].input_variables[0].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()); ASSERT_EQ(1u, result[0].output_variables.size());
EXPECT_EQ("out_var", result[0].output_variables[0].name); EXPECT_EQ("out_var", result[0].output_variables[0].name);
EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration);
EXPECT_EQ(1u, result[0].output_variables[0].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) { TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) {
@ -944,10 +947,13 @@ TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) {
EXPECT_EQ("in_var", result[0].input_variables[0].name); EXPECT_EQ("in_var", result[0].input_variables[0].name);
EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration);
EXPECT_EQ(0u, result[0].input_variables[0].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()); ASSERT_EQ(1u, result[0].output_variables.size());
EXPECT_EQ("out_var", result[0].output_variables[0].name); EXPECT_EQ("out_var", result[0].output_variables[0].name);
EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration);
EXPECT_EQ(1u, result[0].output_variables[0].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) { TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) {
@ -972,10 +978,13 @@ TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) {
EXPECT_EQ("in_var", result[0].input_variables[0].name); EXPECT_EQ("in_var", result[0].input_variables[0].name);
EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration);
EXPECT_EQ(0u, result[0].input_variables[0].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()); ASSERT_EQ(1u, result[0].output_variables.size());
EXPECT_EQ("out_var", result[0].output_variables[0].name); EXPECT_EQ("out_var", result[0].output_variables[0].name);
EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration);
EXPECT_EQ(1u, result[0].output_variables[0].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) { TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) {
@ -999,15 +1008,20 @@ TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) {
EXPECT_TRUE(ContainsName(result[0].input_variables, "in2_var")); EXPECT_TRUE(ContainsName(result[0].input_variables, "in2_var"));
EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration);
EXPECT_EQ(0u, result[0].input_variables[0].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_TRUE(result[0].input_variables[1].has_location_decoration);
EXPECT_EQ(2u, result[0].input_variables[1].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()); ASSERT_EQ(2u, result[0].output_variables.size());
EXPECT_TRUE(ContainsName(result[0].output_variables, "out_var")); EXPECT_TRUE(ContainsName(result[0].output_variables, "out_var"));
EXPECT_TRUE(ContainsName(result[0].output_variables, "out2_var")); EXPECT_TRUE(ContainsName(result[0].output_variables, "out2_var"));
EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration);
EXPECT_EQ(1u, result[0].output_variables[0].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_TRUE(result[0].output_variables[1].has_location_decoration);
EXPECT_EQ(3u, result[0].output_variables[1].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) { TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) {
@ -1034,16 +1048,20 @@ TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) {
EXPECT_TRUE(ContainsName(result[0].input_variables, "in2_var")); EXPECT_TRUE(ContainsName(result[0].input_variables, "in2_var"));
EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration);
EXPECT_EQ(0u, result[0].input_variables[0].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_TRUE(result[0].input_variables[1].has_location_decoration);
EXPECT_EQ(2u, result[0].input_variables[1].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()); ASSERT_EQ(2u, result[0].output_variables.size());
EXPECT_TRUE(ContainsName(result[0].output_variables, "out_var")); EXPECT_TRUE(ContainsName(result[0].output_variables, "out_var"));
EXPECT_TRUE(ContainsName(result[0].output_variables, "out2_var")); EXPECT_TRUE(ContainsName(result[0].output_variables, "out2_var"));
EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration);
EXPECT_EQ(1u, result[0].output_variables[0].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_TRUE(result[0].output_variables[1].has_location_decoration);
EXPECT_EQ(3u, result[0].output_variables[1].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) { TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
@ -1073,25 +1091,33 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
ASSERT_EQ("foo", result[0].name); ASSERT_EQ("foo", result[0].name);
ASSERT_EQ("foo", result[0].remapped_name); ASSERT_EQ("foo", 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].name); EXPECT_EQ("in_var", result[0].input_variables[0].name);
EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration);
EXPECT_EQ(0u, result[0].input_variables[0].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()); ASSERT_EQ(1u, result[0].output_variables.size());
EXPECT_EQ("out2_var", result[0].output_variables[0].name); EXPECT_EQ("out2_var", result[0].output_variables[0].name);
EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration);
EXPECT_EQ(3u, result[0].output_variables[0].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].name);
ASSERT_EQ("bar", result[1].remapped_name); ASSERT_EQ("bar", 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].name); EXPECT_EQ("in2_var", result[1].input_variables[0].name);
EXPECT_TRUE(result[1].input_variables[0].has_location_decoration); EXPECT_TRUE(result[1].input_variables[0].has_location_decoration);
EXPECT_EQ(2u, result[1].input_variables[0].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()); ASSERT_EQ(1u, result[1].output_variables.size());
EXPECT_EQ("out_var", result[1].output_variables[0].name); EXPECT_EQ("out_var", result[1].output_variables[0].name);
EXPECT_TRUE(result[1].output_variables[0].has_location_decoration); EXPECT_TRUE(result[1].output_variables[0].has_location_decoration);
EXPECT_EQ(1u, result[1].output_variables[0].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) { TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
@ -1123,33 +1149,41 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
ASSERT_EQ("foo", result[0].name); ASSERT_EQ("foo", result[0].name);
ASSERT_EQ("foo", result[0].remapped_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, "in_var"));
EXPECT_TRUE(ContainsName(result[0].input_variables, "in2_var")); EXPECT_TRUE(ContainsName(result[0].input_variables, "in2_var"));
EXPECT_TRUE(result[0].input_variables[0].has_location_decoration); EXPECT_TRUE(result[0].input_variables[0].has_location_decoration);
EXPECT_EQ(0u, result[0].input_variables[0].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_TRUE(result[0].input_variables[1].has_location_decoration);
EXPECT_EQ(2u, result[0].input_variables[1].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, "out_var"));
EXPECT_TRUE(ContainsName(result[0].output_variables, "out2_var")); EXPECT_TRUE(ContainsName(result[0].output_variables, "out2_var"));
EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration);
EXPECT_EQ(1u, result[0].output_variables[0].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_TRUE(result[0].output_variables[0].has_location_decoration);
EXPECT_EQ(3u, result[0].output_variables[1].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].name);
ASSERT_EQ("bar", result[1].remapped_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_EQ("in2_var", result[1].input_variables[0].name);
EXPECT_TRUE(result[1].input_variables[0].has_location_decoration); EXPECT_TRUE(result[1].input_variables[0].has_location_decoration);
EXPECT_EQ(2u, result[1].input_variables[0].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_EQ("out2_var", result[1].output_variables[0].name);
EXPECT_TRUE(result[1].output_variables[0].has_location_decoration); EXPECT_TRUE(result[1].output_variables[0].has_location_decoration);
EXPECT_EQ(3u, result[1].output_variables[0].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) { TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
@ -1183,6 +1217,7 @@ TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
EXPECT_TRUE(ContainsName(result[0].output_variables, "out_var")); EXPECT_TRUE(ContainsName(result[0].output_variables, "out_var"));
EXPECT_TRUE(result[0].output_variables[0].has_location_decoration); EXPECT_TRUE(result[0].output_variables[0].has_location_decoration);
EXPECT_EQ(0u, result[0].output_variables[0].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 // TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass