Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Impeller] add GPU start/end trace events.
  • Loading branch information
jonahwilliams committed Oct 11, 2023
commit 4df93fc1947437cfc0e0d1e203e036e3f6e1d277
3 changes: 3 additions & 0 deletions impeller/renderer/backend/vulkan/command_buffer_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const std::shared_ptr<CommandEncoderVK>& CommandBufferVK::GetEncoder() {
}

bool CommandBufferVK::OnSubmitCommands(CompletionCallback callback) {
if (!encoder_) {
encoder_ = encoder_factory_->Create();
}
if (!callback) {
return encoder_->Submit();
}
Expand Down
31 changes: 31 additions & 0 deletions impeller/renderer/backend/vulkan/swapchain_impl_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,40 @@

#include "impeller/renderer/backend/vulkan/swapchain_impl_vk.h"

#include "fml/trace_event.h"
#include "impeller/base/validation.h"
#include "impeller/renderer/backend/vulkan/command_buffer_vk.h"
#include "impeller/renderer/backend/vulkan/command_encoder_vk.h"
#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "impeller/renderer/backend/vulkan/surface_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain_image_vk.h"
#include "impeller/renderer/context.h"
#include "vulkan/vulkan_structs.hpp"

namespace impeller {

// Submit an empty cmd buffer and track its completion so that we can record
// the approximate time that the GPU workload started/ended in the Dart
// timeline.
static void RunGPUCompletionTracking(const ContextVK& context, bool start) {
auto cmd_buffer = context.CreateCommandBuffer();
if (!cmd_buffer->SubmitCommands([start](CommandBuffer::Status status) {
if (status == CommandBuffer::Status::kPending) {
return;
}
if (start) {
TRACE_EVENT0("flutter", "GPUStart");
} else {
TRACE_EVENT0("flutter", "GPUEnd");
}
// We report this event regardless of the status to simplify the tracing
// code required to process the event.
})) {
VALIDATION_LOG << "Failed to submit tracking cmd buffer.";
}
}

static constexpr size_t kMaxFramesInFlight = 3u;

// Number of frames to poll for orientation changes. For example `1u` means
Expand Down Expand Up @@ -374,6 +398,9 @@ SwapchainImplVK::AcquireResult SwapchainImplVK::AcquireNextDrawable() {
*sync->render_ready, // signal semaphore
nullptr // fence
);
#ifdef IMPELLER_DEBUG
RunGPUCompletionTracking(context, /*start=*/true);
#endif // IMPELLER_DEBUG

switch (acq_result) {
case vk::Result::eSuccess:
Expand Down Expand Up @@ -421,6 +448,10 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
const auto& context = ContextVK::Cast(*context_strong);
const auto& sync = synchronizers_[current_frame_];

#ifdef IMPELLER_DEBUG
RunGPUCompletionTracking(context, /*start=*/false);
#endif // IMPELLER_DEBUG

//----------------------------------------------------------------------------
/// Transition the image to color-attachment-optimal.
///
Expand Down