| Flutter Impeller |

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>
12 #include "impeller/base/thread.h"
13 #include "impeller/base/thread_safety.h"
14 #include "impeller/geometry/scalar.h"
15
16 namespace impeller {
17
18 class 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.
23 class 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_
impeller::GPUTracerMTL
Approximate the GPU frame time by computing a difference between the smallest GPUStartTime and larges...
Definition: gpu_tracer_mtl.h:23
impeller::GPUTracerMTL::RecordCmdBuffer
void RecordCmdBuffer(id< MTLCommandBuffer > buffer)
Record the current cmd buffer GPU execution timestamps into an aggregate frame workload metric.
Definition: gpu_tracer_mtl.mm:23
impeller::GPUTracerMTL::MarkFrameEnd
void MarkFrameEnd()
Record that the current frame has ended. Any additional cmd buffers will be attributed to the "next" ...
Definition: gpu_tracer_mtl.mm:16
impeller::GPUTracerMTL::~GPUTracerMTL
~GPUTracerMTL()=default
impeller::GPUTracerMTL::GPUTracerMTL
GPUTracerMTL()=default
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:18
scalar.h
thread.h
thread_safety.h