From 8d3d4f6fd11fb179b4c56b782e9e5ef0da1fd4a9 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Tue, 11 Oct 2022 09:52:59 +0000 Subject: [PATCH] tint/inspector: Reflect whether @builtin(frag_depth) is used. This will be used by Dawn between other factors to decide whether to use the ClampFragDepth transform. Bug: dawn:1125 Change-Id: I53be846d9c3ebb9b2d424f40fc87db89c843c81b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105220 Reviewed-by: Ben Clayton Commit-Queue: Corentin Wallez --- src/tint/inspector/entry_point.h | 2 ++ src/tint/inspector/inspector.cc | 2 ++ src/tint/inspector/inspector_test.cc | 44 ++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/tint/inspector/entry_point.h b/src/tint/inspector/entry_point.h index 5d119d4a40..7038ecc54e 100644 --- a/src/tint/inspector/entry_point.h +++ b/src/tint/inspector/entry_point.h @@ -175,6 +175,8 @@ struct EntryPoint { bool sample_index_used = false; /// Does the entry point use the num_workgroups builtin bool num_workgroups_used = false; + /// Does the entry point use the frag_depth builtin + bool frag_depth_used = false; }; } // namespace tint::inspector diff --git a/src/tint/inspector/inspector.cc b/src/tint/inspector/inspector.cc index 3520ae3259..48bae48a7f 100644 --- a/src/tint/inspector/inspector.cc +++ b/src/tint/inspector/inspector.cc @@ -192,6 +192,8 @@ EntryPoint Inspector::GetEntryPoint(const tint::ast::Function* func) { entry_point.output_sample_mask_used = ContainsBuiltin( ast::BuiltinValue::kSampleMask, sem->ReturnType(), func->return_type_attributes); + entry_point.frag_depth_used = ContainsBuiltin( + ast::BuiltinValue::kFragDepth, sem->ReturnType(), func->return_type_attributes); } for (auto* var : sem->TransitivelyReferencedGlobals()) { diff --git a/src/tint/inspector/inspector_test.cc b/src/tint/inspector/inspector_test.cc index 7e81ba04ac..32697bb795 100644 --- a/src/tint/inspector/inspector_test.cc +++ b/src/tint/inspector/inspector_test.cc @@ -852,6 +852,7 @@ TEST_F(InspectorGetEntryPointTest, BuiltinNotReferenced) { EXPECT_FALSE(result[0].front_facing_used); EXPECT_FALSE(result[0].sample_index_used); EXPECT_FALSE(result[0].num_workgroups_used); + EXPECT_FALSE(result[0].frag_depth_used); } TEST_F(InspectorGetEntryPointTest, InputSampleMaskSimpleReferenced) { @@ -1134,6 +1135,49 @@ TEST_F(InspectorGetEntryPointTest, NumWorkgroupsStructReferenced) { EXPECT_TRUE(result[0].num_workgroups_used); } +TEST_F(InspectorGetEntryPointTest, FragDepthSimpleReferenced) { + Func("ep_func", {}, ty.f32(), + utils::Vector{ + Return(Expr(0_f)), + }, + utils::Vector{ + Stage(ast::PipelineStage::kFragment), + }, + utils::Vector{ + Builtin(ast::BuiltinValue::kFragDepth), + }); + + Inspector& inspector = Build(); + + auto result = inspector.GetEntryPoints(); + + ASSERT_EQ(1u, result.size()); + EXPECT_TRUE(result[0].frag_depth_used); +} + +TEST_F(InspectorGetEntryPointTest, FragDepthStructReferenced) { + Structure("out_struct", utils::Vector{ + Member("inner_frag_depth", ty.f32(), + utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}), + }); + + Func("ep_func", utils::Empty, ty.type_name("out_struct"), + utils::Vector{ + Decl(Var("out_var", ty.type_name("out_struct"))), + Return("out_var"), + }, + utils::Vector{ + Stage(ast::PipelineStage::kFragment), + }); + + Inspector& inspector = Build(); + + auto result = inspector.GetEntryPoints(); + + ASSERT_EQ(1u, result.size()); + EXPECT_TRUE(result[0].frag_depth_used); +} + TEST_F(InspectorGetEntryPointTest, ImplicitInterpolate) { Structure("in_struct", utils::Vector{ Member("struct_inner", ty.f32(), utils::Vector{Location(0_a)}),