This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] GPU Tracer for GLES. #47080
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eb8b915
++
c46d3eb
++
6034da3
++
c014eba
++
bf6f77b
++
3eb2edd
add 'test'
12f86c3
licenses and cleanup.
51ad782
Add option to enable GPU tracing for OpenGL from Android Manifest
cd0c46d
++
6a93525
++
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // 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; | ||
| } | ||
|
|
||
| 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()) { | ||
| return; | ||
| } | ||
|
|
||
| auto query = active_frame_.value(); | ||
| gl.EndQueryEXT(GL_TIME_ELAPSED_EXT); | ||
|
|
||
| pending_traces_.push_back(query); | ||
| active_frame_ = std::nullopt; | ||
| } | ||
|
|
||
| } // namespace impeller | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // 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. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <deque> | ||
| #include <thread> | ||
|
|
||
| #include "impeller/renderer/backend/gles/proc_table_gles.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| /// @brief Trace GPU execution times using GL_EXT_disjoint_timer_query on GLES. | ||
| /// | ||
| /// Note: there are a substantial number of GPUs where usage of the this API is | ||
| /// known to cause crashes. As a result, this functionality is disabled by | ||
| /// default and can only be enabled in debug/profile mode via a specific opt-in | ||
| /// flag that is exposed in the Android manifest. | ||
| /// | ||
| /// To enable, add the following metadata to the application's Android manifest: | ||
| /// <meta-data | ||
| /// android:name="io.flutter.embedding.android.EnableOpenGLGPUTracing" | ||
| /// android:value="false" /> | ||
| class GPUTracerGLES { | ||
| public: | ||
| GPUTracerGLES(const ProcTableGLES& gl, bool enable_tracing); | ||
|
|
||
| ~GPUTracerGLES() = default; | ||
|
|
||
| /// @brief Record the thread id of the raster thread. | ||
| void RecordRasterThread(); | ||
|
|
||
| /// @brief Record the start of a frame workload, if one hasn't already been | ||
| /// started. | ||
| void MarkFrameStart(const ProcTableGLES& gl); | ||
|
|
||
| /// @brief Record the end of a frame workload. | ||
| void MarkFrameEnd(const ProcTableGLES& gl); | ||
|
|
||
| private: | ||
| void ProcessQueries(const ProcTableGLES& gl); | ||
|
|
||
| std::deque<uint32_t> pending_traces_; | ||
| std::optional<uint32_t> active_frame_ = std::nullopt; | ||
| std::thread::id raster_thread_; | ||
|
|
||
| bool enabled_ = false; | ||
| }; | ||
|
|
||
| } // namespace impeller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where exactly is the crash happening?
If the tracer can only consume one pending query per
MarkFrameStartcall, then that means the pending traces queue will grow unbounded each time a query result is unavailable at the nextMarkFrameStart.