Flutter Impeller
impeller::GPUTracerVK Class Referenceabstract

A class that uses timestamp queries to record the approximate GPU execution time. More...

#include <gpu_tracer_vk.h>

Inheritance diagram for impeller::GPUTracerVK:

Public Member Functions

 GPUTracerVK (std::weak_ptr< ContextVK > context, bool enable_gpu_tracing)
 
 ~GPUTracerVK ()=default
 
std::unique_ptr< GPUProbeCreateGPUProbe ()
 Create a GPUProbe to trace the execution of a command buffer on the GPU. More...
 
void MarkFrameStart ()
 Signal the start of a frame workload. More...
 
void MarkFrameEnd ()
 Signal the end of a frame workload. More...
 
bool IsEnabled () const
 
void InitializeQueryPool (const ContextVK &context)
 Initialize the set of query pools. More...
 

Friends

class GPUProbe
 

Detailed Description

A class that uses timestamp queries to record the approximate GPU execution time.

To enable, add the following metadata to the application's Android manifest: <meta-data android:name="io.flutter.embedding.android.EnableVulkanGPUTracing" android:value="false" />

Definition at line 26 of file gpu_tracer_vk.h.

Constructor & Destructor Documentation

◆ GPUTracerVK()

impeller::GPUTracerVK::GPUTracerVK ( std::weak_ptr< ContextVK context,
bool  enable_gpu_tracing 
)

Definition at line 22 of file gpu_tracer_vk.cc.

24  : context_(std::move(context)) {
25  if (!enable_gpu_tracing) {
26  return;
27  }
28  timestamp_period_ = context_.lock()
29  ->GetDeviceHolder()
30  ->GetPhysicalDevice()
31  .getProperties()
32  .limits.timestampPeriod;
33  if (timestamp_period_ <= 0) {
34  // The device does not support timestamp queries.
35  return;
36  }
37 // Disable tracing in release mode.
38 #ifdef IMPELLER_DEBUG
39  enabled_ = true;
40 #endif // IMPELLER_DEBUG
41 }

◆ ~GPUTracerVK()

impeller::GPUTracerVK::~GPUTracerVK ( )
default

Member Function Documentation

◆ CreateGPUProbe()

std::unique_ptr< GPUProbe > impeller::GPUTracerVK::CreateGPUProbe ( )

Create a GPUProbe to trace the execution of a command buffer on the GPU.

Definition at line 105 of file gpu_tracer_vk.cc.

105  {
106  return std::make_unique<GPUProbe>(weak_from_this());
107 }

◆ InitializeQueryPool()

void impeller::GPUTracerVK::InitializeQueryPool ( const ContextVK context)

Initialize the set of query pools.

Definition at line 43 of file gpu_tracer_vk.cc.

43  {
44  if (!enabled_) {
45  return;
46  }
47  Lock lock(trace_state_mutex_);
48  std::shared_ptr<CommandBuffer> buffer = context.CreateCommandBuffer();
49  CommandBufferVK& buffer_vk = CommandBufferVK::Cast(*buffer);
50 
51  for (auto i = 0u; i < kTraceStatesSize; i++) {
52  vk::QueryPoolCreateInfo info;
53  info.queryCount = kPoolSize;
54  info.queryType = vk::QueryType::eTimestamp;
55 
56  auto [status, pool] = context.GetDevice().createQueryPoolUnique(info);
57  if (status != vk::Result::eSuccess) {
58  VALIDATION_LOG << "Failed to create query pool.";
59  return;
60  }
61  trace_states_[i].query_pool = std::move(pool);
62  buffer_vk.GetCommandBuffer().resetQueryPool(
63  trace_states_[i].query_pool.get(), 0, kPoolSize);
64  }
65  if (!context.GetCommandQueue()->Submit({buffer}).ok()) {
66  VALIDATION_LOG << "Failed to reset query pool for trace events.";
67  enabled_ = false;
68  }
69 }
static CommandBufferVK & Cast(CommandBuffer &base)
Definition: backend_cast.h:13
static constexpr uint32_t kPoolSize
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::BackendCast< CommandBufferVK, CommandBuffer >::Cast(), impeller::ContextVK::CreateCommandBuffer(), impeller::CommandBufferVK::GetCommandBuffer(), impeller::ContextVK::GetCommandQueue(), impeller::ContextVK::GetDevice(), impeller::kPoolSize, and VALIDATION_LOG.

◆ IsEnabled()

bool impeller::GPUTracerVK::IsEnabled ( ) const

Definition at line 71 of file gpu_tracer_vk.cc.

71  {
72  return enabled_;
73 }

◆ MarkFrameEnd()

void impeller::GPUTracerVK::MarkFrameEnd ( )

Signal the end of a frame workload.

Definition at line 84 of file gpu_tracer_vk.cc.

84  {
85  in_frame_ = false;
86 
87  if (!enabled_) {
88  return;
89  }
90 
91  Lock lock(trace_state_mutex_);
92  current_state_ = (current_state_ + 1) % kTraceStatesSize;
93 
94  auto& state = trace_states_[current_state_];
95  // If there are still pending buffers on the trace state we're switching to,
96  // that means that a cmd buffer we were relying on to signal this likely
97  // never finished. This shouldn't happen unless there is a bug in the
98  // encoder logic. We set it to zero anyway to prevent a validation error
99  // from becoming a memory leak.
100  FML_DCHECK(state.pending_buffers == 0u);
101  state.pending_buffers = 0;
102  state.current_index = 0;
103 }

◆ MarkFrameStart()

void impeller::GPUTracerVK::MarkFrameStart ( )

Signal the start of a frame workload.

   Any cmd buffers that are created after this call and before
   [MarkFrameEnd] will be attributed to the current frame. 

Definition at line 75 of file gpu_tracer_vk.cc.

75  {
76  if (!enabled_) {
77  return;
78  }
79  FML_DCHECK(!in_frame_);
80  in_frame_ = true;
81  raster_thread_id_ = std::this_thread::get_id();
82 }

Friends And Related Function Documentation

◆ GPUProbe

friend class GPUProbe
friend

Definition at line 52 of file gpu_tracer_vk.h.


The documentation for this class was generated from the following files: