From 97c692d337e2daa61aad4445b207d6803675f561 Mon Sep 17 00:00:00 2001 From: Shrek Shao Date: Wed, 27 Oct 2021 19:33:37 +0000 Subject: [PATCH] Support reflecting if pipeline overrideable constants has numeric ID specified Bug: tint:1155 Change-Id: I362adf36a84ed470fa1bf7ab2c9a1fbe0a54da5a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67602 Reviewed-by: Ryan Harrison Kokoro: Kokoro Commit-Queue: Shrek Shao --- src/inspector/entry_point.h | 7 +++++++ src/inspector/inspector.cc | 5 +++++ src/inspector/inspector_test.cc | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/inspector/entry_point.h b/src/inspector/entry_point.h index cf386a16f9..12cb4da7cf 100644 --- a/src/inspector/entry_point.h +++ b/src/inspector/entry_point.h @@ -93,6 +93,9 @@ struct OverridableConstant { /// Name of the constant std::string name; + /// ID of the constant + uint16_t numeric_id; + /// Type of the scalar enum class Type { kBool, @@ -106,6 +109,10 @@ struct OverridableConstant { /// Does this pipeline overridable constant have an initializer? bool is_initialized = false; + + /// Does this pipeline overridable constant have a numeric ID specified + /// explicitly? + bool is_numeric_id_specified = false; }; /// Reflection data for an entry point in the shader. diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index ca2a968abf..19cf595330 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -197,6 +197,7 @@ std::vector Inspector::GetEntryPoints() { if (global && global->IsPipelineConstant()) { OverridableConstant overridable_constant; overridable_constant.name = name; + overridable_constant.numeric_id = global->ConstantId(); auto* type = var->Type(); TINT_ASSERT(Inspector, type->is_scalar()); if (type->is_bool_scalar_or_vector()) { @@ -213,6 +214,10 @@ std::vector Inspector::GetEntryPoints() { overridable_constant.is_initialized = global->Declaration()->constructor; + auto* override_deco = ast::GetDecoration( + global->Declaration()->decorations); + overridable_constant.is_numeric_id_specified = + override_deco ? override_deco->has_value : false; entry_point.overridable_constants.push_back(overridable_constant); } diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index 2c84340557..e2c0eae0b3 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -612,6 +612,7 @@ TEST_F(InspectorGetEntryPointTest, OverridableConstantSomeReferenced) { ASSERT_EQ(1u, result.size()); ASSERT_EQ(1u, result[0].overridable_constants.size()); EXPECT_EQ("foo", result[0].overridable_constants[0].name); + EXPECT_EQ(1, result[0].overridable_constants[0].numeric_id); } TEST_F(InspectorGetEntryPointTest, OverridableConstantTypes) { @@ -682,6 +683,31 @@ TEST_F(InspectorGetEntryPointTest, OverridableConstantUninitialized) { EXPECT_FALSE(result[0].overridable_constants[0].is_initialized); } +TEST_F(InspectorGetEntryPointTest, OverridableConstantNumericIDSpecified) { + AddOverridableConstantWithoutID("foo_no_id", ty.f32(), nullptr); + AddOverridableConstantWithID("foo_id", 1234, ty.f32(), nullptr); + + MakePlainGlobalReferenceBodyFunction("no_id_func", "foo_no_id", ty.f32(), {}); + MakePlainGlobalReferenceBodyFunction("id_func", "foo_id", ty.f32(), {}); + + MakeCallerBodyFunction( + "ep_func", {"no_id_func", "id_func"}, + {Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)}); + + Inspector& inspector = Build(); + + auto result = inspector.GetEntryPoints(); + + ASSERT_EQ(1u, result.size()); + ASSERT_EQ(2u, result[0].overridable_constants.size()); + EXPECT_EQ("foo_no_id", result[0].overridable_constants[0].name); + EXPECT_EQ("foo_id", result[0].overridable_constants[1].name); + EXPECT_EQ(1234, result[0].overridable_constants[1].numeric_id); + + EXPECT_FALSE(result[0].overridable_constants[0].is_numeric_id_specified); + EXPECT_TRUE(result[0].overridable_constants[1].is_numeric_id_specified); +} + TEST_F(InspectorGetEntryPointTest, NonOverridableConstantSkipped) { auto* foo_struct_type = MakeUniformBufferType("foo_type", {ty.i32()}); AddUniformBuffer("foo_ub", ty.Of(foo_struct_type), 0, 0);