| Flutter Impeller |

Classes | Public Member Functions | Friends | List of all members
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< GPUProbe > | CreateGPUProbe ()
| 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 25 of file gpu_tracer_vk.cc.

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

## ◆ ~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 108 of file gpu_tracer_vk.cc.

108 {
109 return std::make_unique<GPUProbe>(weak_from_this());
110 }

## ◆ InitializeQueryPool()

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

Initialize the set of query pools.

Definition at line 46 of file gpu_tracer_vk.cc.

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

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

## ◆ IsEnabled()

bool impeller::GPUTracerVK::IsEnabled | ( |  | ) | const

Definition at line 74 of file gpu_tracer_vk.cc.

74 {
75 return enabled_;
76 }

## ◆ MarkFrameEnd()

void impeller::GPUTracerVK::MarkFrameEnd | ( |  | ) |

Signal the end of a frame workload.

Definition at line 87 of file gpu_tracer_vk.cc.

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

## ◆ 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 78 of file gpu_tracer_vk.cc.

78 {
79 if (!enabled_) {
80 return;
81 }
82 FML_DCHECK(!in_frame_);
83 in_frame_ = true;
84 raster_thread_id_ = std::this_thread::get_id();
85 }

## 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:

- impeller/renderer/backend/vulkan/gpu_tracer_vk.h
- impeller/renderer/backend/vulkan/gpu_tracer_vk.cc

VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::BackendCast< CommandBufferVK, CommandBuffer >::Cast
static CommandBufferVK & Cast(CommandBuffer &base)
Definition: backend_cast.h:13
impeller::kPoolSize
static constexpr uint32_t kPoolSize
Definition: gpu_tracer_vk.cc:23