forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgpu_tracer_gles.cc
More file actions
89 lines (73 loc) · 2.66 KB
/
gpu_tracer_gles.cc
File metadata and controls
89 lines (73 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/renderer/backend/gles/gpu_tracer_gles.h"
#include <thread>
#include "fml/trace_event.h"
namespace impeller {
GPUTracerGLES::GPUTracerGLES(const ProcTableGLES& gl, bool enable_tracing) {
#ifdef IMPELLER_DEBUG
auto desc = gl.GetDescription();
enabled_ =
enable_tracing && desc->HasExtension("GL_EXT_disjoint_timer_query");
#endif // IMPELLER_DEBUG
}
void GPUTracerGLES::MarkFrameStart(const ProcTableGLES& gl) {
if (!enabled_ || active_frame_.has_value() ||
std::this_thread::get_id() != raster_thread_) {
return;
}
// At the beginning of a frame, check the status of all pending
// previous queries.
ProcessQueries(gl);
uint32_t query = 0;
gl.GenQueriesEXT(1, &query);
if (query == 0) {
return;
}
FML_DCHECK(!active_frame_.has_value());
active_frame_ = query;
gl.BeginQueryEXT(GL_TIME_ELAPSED_EXT, query);
}
void GPUTracerGLES::RecordRasterThread() {
raster_thread_ = std::this_thread::get_id();
}
void GPUTracerGLES::ProcessQueries(const ProcTableGLES& gl) {
// For reasons unknown to me, querying the state of more than
// one query object per frame causes crashes on a Pixel 6 pro.
// It does not crash on an S10.
while (!pending_traces_.empty()) {
auto query = pending_traces_.front();
// First check if the query is complete without blocking
// on the result. Incomplete results are left in the pending
// trace vector and will not be checked again for another
// frame.
GLuint available = GL_FALSE;
gl.GetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &available);
if (available != GL_TRUE) {
// If a query is not available, then all subsequent queries will be
// unavailable.
return;
}
// Return the timer resolution in nanoseconds.
uint64_t duration = 0;
gl.GetQueryObjectui64vEXT(query, GL_QUERY_RESULT_EXT, &duration);
auto gpu_ms = duration / 1000000.0;
FML_TRACE_COUNTER("flutter", "GPUTracer",
reinterpret_cast<int64_t>(this), // Trace Counter ID
"FrameTimeMS", gpu_ms);
gl.DeleteQueriesEXT(1, &query);
pending_traces_.pop_front();
}
}
void GPUTracerGLES::MarkFrameEnd(const ProcTableGLES& gl) {
if (!enabled_ || std::this_thread::get_id() != raster_thread_ ||
!active_frame_.has_value() || !active_frame_.has_value()) {
return;
}
auto query = active_frame_.value();
gl.EndQueryEXT(GL_TIME_ELAPSED_EXT);
pending_traces_.push_back(query);
active_frame_ = std::nullopt;
}
} // namespace impeller