Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
gpu_tracer_mtl.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_GPU_TRACER_MTL_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_GPU_TRACER_MTL_H_
7
8#include <Metal/Metal.h>
9
10#include <memory>
11#include <optional>
15
16namespace impeller {
17
18class ContextMTL;
19
20/// @brief Approximate the GPU frame time by computing a difference between the
21/// smallest GPUStartTime and largest GPUEndTime for all command buffers
22/// submitted in a frame workload.
23class GPUTracerMTL : public std::enable_shared_from_this<GPUTracerMTL> {
24 public:
25 GPUTracerMTL() = default;
26
27 ~GPUTracerMTL() = default;
28
29 /// @brief Record that the current frame has ended. Any additional cmd buffers
30 /// will be attributed to the "next" frame.
31 void MarkFrameEnd();
32
33 /// @brief Record the current cmd buffer GPU execution timestamps into an
34 /// aggregate frame workload metric.
35 void RecordCmdBuffer(id<MTLCommandBuffer> buffer);
36
37 private:
38 struct GPUTraceState {
39 Scalar smallest_timestamp = std::numeric_limits<float>::max();
40 Scalar largest_timestamp = 0;
41 size_t pending_buffers = 0;
42 };
43
44 mutable Mutex trace_state_mutex_;
45 GPUTraceState trace_states_[16] IPLR_GUARDED_BY(trace_state_mutex_);
46 size_t current_state_ IPLR_GUARDED_BY(trace_state_mutex_) = 0u;
47};
48
49} // namespace impeller
50
51#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_GPU_TRACER_MTL_H_
Approximate the GPU frame time by computing a difference between the smallest GPUStartTime and larges...
void RecordCmdBuffer(id< MTLCommandBuffer > buffer)
Record the current cmd buffer GPU execution timestamps into an aggregate frame workload metric.
void MarkFrameEnd()
Record that the current frame has ended. Any additional cmd buffers will be attributed to the "next" ...
size_t current_state_ IPLR_GUARDED_BY(trace_state_mutex_)=0u
static const uint8_t buffer[]
float Scalar
Definition scalar.h:18
#define IPLR_GUARDED_BY(x)