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 <rharrison@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Shrek Shao <shrekshao@google.com>
This commit is contained in:
parent
e7ca884b3d
commit
97c692d337
|
@ -93,6 +93,9 @@ struct OverridableConstant {
|
||||||
/// Name of the constant
|
/// Name of the constant
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
|
/// ID of the constant
|
||||||
|
uint16_t numeric_id;
|
||||||
|
|
||||||
/// Type of the scalar
|
/// Type of the scalar
|
||||||
enum class Type {
|
enum class Type {
|
||||||
kBool,
|
kBool,
|
||||||
|
@ -106,6 +109,10 @@ struct OverridableConstant {
|
||||||
|
|
||||||
/// Does this pipeline overridable constant have an initializer?
|
/// Does this pipeline overridable constant have an initializer?
|
||||||
bool is_initialized = false;
|
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.
|
/// Reflection data for an entry point in the shader.
|
||||||
|
|
|
@ -197,6 +197,7 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
|
||||||
if (global && global->IsPipelineConstant()) {
|
if (global && global->IsPipelineConstant()) {
|
||||||
OverridableConstant overridable_constant;
|
OverridableConstant overridable_constant;
|
||||||
overridable_constant.name = name;
|
overridable_constant.name = name;
|
||||||
|
overridable_constant.numeric_id = global->ConstantId();
|
||||||
auto* type = var->Type();
|
auto* type = var->Type();
|
||||||
TINT_ASSERT(Inspector, type->is_scalar());
|
TINT_ASSERT(Inspector, type->is_scalar());
|
||||||
if (type->is_bool_scalar_or_vector()) {
|
if (type->is_bool_scalar_or_vector()) {
|
||||||
|
@ -213,6 +214,10 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
|
||||||
|
|
||||||
overridable_constant.is_initialized =
|
overridable_constant.is_initialized =
|
||||||
global->Declaration()->constructor;
|
global->Declaration()->constructor;
|
||||||
|
auto* override_deco = ast::GetDecoration<ast::OverrideDecoration>(
|
||||||
|
global->Declaration()->decorations);
|
||||||
|
overridable_constant.is_numeric_id_specified =
|
||||||
|
override_deco ? override_deco->has_value : false;
|
||||||
|
|
||||||
entry_point.overridable_constants.push_back(overridable_constant);
|
entry_point.overridable_constants.push_back(overridable_constant);
|
||||||
}
|
}
|
||||||
|
|
|
@ -612,6 +612,7 @@ TEST_F(InspectorGetEntryPointTest, OverridableConstantSomeReferenced) {
|
||||||
ASSERT_EQ(1u, result.size());
|
ASSERT_EQ(1u, result.size());
|
||||||
ASSERT_EQ(1u, result[0].overridable_constants.size());
|
ASSERT_EQ(1u, result[0].overridable_constants.size());
|
||||||
EXPECT_EQ("foo", result[0].overridable_constants[0].name);
|
EXPECT_EQ("foo", result[0].overridable_constants[0].name);
|
||||||
|
EXPECT_EQ(1, result[0].overridable_constants[0].numeric_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(InspectorGetEntryPointTest, OverridableConstantTypes) {
|
TEST_F(InspectorGetEntryPointTest, OverridableConstantTypes) {
|
||||||
|
@ -682,6 +683,31 @@ TEST_F(InspectorGetEntryPointTest, OverridableConstantUninitialized) {
|
||||||
EXPECT_FALSE(result[0].overridable_constants[0].is_initialized);
|
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) {
|
TEST_F(InspectorGetEntryPointTest, NonOverridableConstantSkipped) {
|
||||||
auto* foo_struct_type = MakeUniformBufferType("foo_type", {ty.i32()});
|
auto* foo_struct_type = MakeUniformBufferType("foo_type", {ty.i32()});
|
||||||
AddUniformBuffer("foo_ub", ty.Of(foo_struct_type), 0, 0);
|
AddUniformBuffer("foo_ub", ty.Of(foo_struct_type), 0, 0);
|
||||||
|
|
Loading…
Reference in New Issue