Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f2b9921

Browse files
author
Jonah Williams
authored
[Impeller] make GPU tracing off by default. (#50215)
Fixes flutter/flutter#141788 Fixes flutter/flutter#141798 Disable GPU tracing by default.
1 parent 80e5792 commit f2b9921

File tree

13 files changed

+73
-16
lines changed

13 files changed

+73
-16
lines changed

common/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ struct Settings {
232232
// Some devices claim to support the required APIs but crash on their usage.
233233
bool enable_opengl_gpu_tracing = false;
234234

235+
// Enable GPU tracing in Vulkan backends.
236+
bool enable_vulkan_gpu_tracing = false;
237+
235238
// Data set by platform-specific embedders for use in font initialization.
236239
uint32_t font_initialization_data = 0;
237240

impeller/renderer/backend/vulkan/context_vk.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ void ContextVK::Setup(Settings settings) {
452452

453453
// Create the GPU Tracer later because it depends on state from
454454
// the ContextVK.
455-
gpu_tracer_ = std::make_shared<GPUTracerVK>(weak_from_this());
455+
gpu_tracer_ = std::make_shared<GPUTracerVK>(weak_from_this(),
456+
settings.enable_gpu_tracing);
456457
gpu_tracer_->InitializeQueryPool(*this);
457458

458459
//----------------------------------------------------------------------------

impeller/renderer/backend/vulkan/context_vk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class ContextVK final : public Context,
4747
std::vector<std::shared_ptr<fml::Mapping>> shader_libraries_data;
4848
fml::UniqueFD cache_directory;
4949
bool enable_validation = false;
50+
bool enable_gpu_tracing = false;
5051

5152
Settings() = default;
5253

impeller/renderer/backend/vulkan/gpu_tracer_vk.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ namespace impeller {
2222

2323
static constexpr uint32_t kPoolSize = 128u;
2424

25-
GPUTracerVK::GPUTracerVK(std::weak_ptr<ContextVK> context)
25+
GPUTracerVK::GPUTracerVK(std::weak_ptr<ContextVK> context,
26+
bool enable_gpu_tracing)
2627
: context_(std::move(context)) {
28+
if (!enable_gpu_tracing) {
29+
return;
30+
}
2731
timestamp_period_ = context_.lock()
2832
->GetDeviceHolder()
2933
->GetPhysicalDevice()

impeller/renderer/backend/vulkan/gpu_tracer_vk.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ class GPUProbe;
1818

1919
/// @brief A class that uses timestamp queries to record the approximate GPU
2020
/// execution time.
21+
///
22+
/// To enable, add the following metadata to the application's Android manifest:
23+
/// <meta-data
24+
/// android:name="io.flutter.embedding.android.EnableVulkanGPUTracing"
25+
/// android:value="false" />
2126
class GPUTracerVK : public std::enable_shared_from_this<GPUTracerVK> {
2227
public:
23-
explicit GPUTracerVK(std::weak_ptr<ContextVK> context);
28+
GPUTracerVK(std::weak_ptr<ContextVK> context, bool enable_gpu_tracing);
2429

2530
~GPUTracerVK() = default;
2631

impeller/renderer/backend/vulkan/swapchain_impl_vk.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
443443

444444
const auto& context = ContextVK::Cast(*context_strong);
445445
const auto& sync = synchronizers_[current_frame_];
446+
context.GetGPUTracer()->MarkFrameEnd();
446447

447448
//----------------------------------------------------------------------------
448449
/// Transition the image to color-attachment-optimal.
@@ -493,8 +494,6 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
493494
}
494495
}
495496

496-
context.GetGPUTracer()->MarkFrameEnd();
497-
498497
auto task = [&, index, current_frame = current_frame_] {
499498
auto context_strong = context_.lock();
500499
if (!context_strong) {

impeller/renderer/backend/vulkan/test/gpu_tracer_unittests.cc

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,25 @@ namespace impeller {
1515
namespace testing {
1616

1717
#ifdef IMPELLER_DEBUG
18+
TEST(GPUTracerVK, CanBeDisabled) {
19+
auto const context =
20+
MockVulkanContextBuilder()
21+
.SetSettingsCallback([](ContextVK::Settings& settings) {
22+
settings.enable_gpu_tracing = false;
23+
})
24+
.Build();
25+
auto tracer = context->GetGPUTracer();
26+
27+
ASSERT_FALSE(tracer->IsEnabled());
28+
}
29+
1830
TEST(GPUTracerVK, CanTraceCmdBuffer) {
19-
auto const context = MockVulkanContextBuilder().Build();
31+
auto const context =
32+
MockVulkanContextBuilder()
33+
.SetSettingsCallback([](ContextVK::Settings& settings) {
34+
settings.enable_gpu_tracing = true;
35+
})
36+
.Build();
2037
auto tracer = context->GetGPUTracer();
2138

2239
ASSERT_TRUE(tracer->IsEnabled());
@@ -48,7 +65,12 @@ TEST(GPUTracerVK, CanTraceCmdBuffer) {
4865
}
4966

5067
TEST(GPUTracerVK, DoesNotTraceOutsideOfFrameWorkload) {
51-
auto const context = MockVulkanContextBuilder().Build();
68+
auto const context =
69+
MockVulkanContextBuilder()
70+
.SetSettingsCallback([](ContextVK::Settings& settings) {
71+
settings.enable_gpu_tracing = true;
72+
})
73+
.Build();
5274
auto tracer = context->GetGPUTracer();
5375

5476
ASSERT_TRUE(tracer->IsEnabled());
@@ -78,7 +100,12 @@ TEST(GPUTracerVK, DoesNotTraceOutsideOfFrameWorkload) {
78100
// This cmd buffer starts when there is a frame but finishes when there is none.
79101
// This should result in the same recorded work.
80102
TEST(GPUTracerVK, TracesWithPartialFrameOverlap) {
81-
auto const context = MockVulkanContextBuilder().Build();
103+
auto const context =
104+
MockVulkanContextBuilder()
105+
.SetSettingsCallback([](ContextVK::Settings& settings) {
106+
settings.enable_gpu_tracing = true;
107+
})
108+
.Build();
82109
auto tracer = context->GetGPUTracer();
83110

84111
ASSERT_TRUE(tracer->IsEnabled());

shell/common/switches.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
468468
command_line.HasOption(FlagForSwitch(Switch::EnableVulkanValidation));
469469
settings.enable_opengl_gpu_tracing =
470470
command_line.HasOption(FlagForSwitch(Switch::EnableOpenGLGPUTracing));
471+
settings.enable_vulkan_gpu_tracing =
472+
command_line.HasOption(FlagForSwitch(Switch::EnableVulkanGPUTracing));
471473

472474
settings.enable_embedder_api =
473475
command_line.HasOption(FlagForSwitch(Switch::EnableEmbedderAPI));

shell/common/switches.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ DEF_SWITCH(EnableOpenGLGPUTracing,
279279
"enable-opengl-gpu-tracing",
280280
"Enable tracing of GPU execution time when using the Impeller "
281281
"OpenGLES backend.")
282+
DEF_SWITCH(EnableVulkanGPUTracing,
283+
"enable-vulkan-gpu-tracing",
284+
"Enable tracing of GPU execution time when using the Impeller "
285+
"Vulkan backend.")
282286
DEF_SWITCH(LeakVM,
283287
"leak-vm",
284288
"When the last shell shuts down, the shared VM is leaked by default "

shell/platform/android/android_context_vulkan_impeller.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace flutter {
1818

1919
static std::shared_ptr<impeller::Context> CreateImpellerContext(
2020
const fml::RefPtr<vulkan::VulkanProcTable>& proc_table,
21-
bool enable_vulkan_validation) {
21+
bool enable_vulkan_validation,
22+
bool enable_gpu_tracing) {
2223
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
2324
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
2425
impeller_entity_shaders_vk_length),
@@ -41,6 +42,7 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
4142
settings.shader_libraries_data = std::move(shader_mappings);
4243
settings.cache_directory = fml::paths::GetCachesDirectory();
4344
settings.enable_validation = enable_vulkan_validation;
45+
settings.enable_gpu_tracing = enable_gpu_tracing;
4446

4547
auto context = impeller::ContextVK::Create(std::move(settings));
4648

@@ -56,10 +58,12 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
5658
}
5759

5860
AndroidContextVulkanImpeller::AndroidContextVulkanImpeller(
59-
bool enable_validation)
61+
bool enable_validation,
62+
bool enable_gpu_tracing)
6063
: AndroidContext(AndroidRenderingAPI::kVulkan),
6164
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {
62-
auto impeller_context = CreateImpellerContext(proc_table_, enable_validation);
65+
auto impeller_context =
66+
CreateImpellerContext(proc_table_, enable_validation, enable_gpu_tracing);
6367
SetImpellerContext(impeller_context);
6468
is_valid_ =
6569
proc_table_->HasAcquiredMandatoryProcAddresses() && impeller_context;

0 commit comments

Comments
 (0)