Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] Add GPU frame time to Vulkan backend using timestamp queries. #46796

Merged
merged 13 commits into from
Oct 13, 2023

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Oct 11, 2023

For flutter/flutter#136408 ,

Approximate the GPU frame time by measuring the difference between a timestamp query recorded at the beginning of the frame and a timestamp query recorded at the end of the frame.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie or stuartmorgan on the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@chinmaygarde chinmaygarde changed the title [Impeller] add GPU start/end trace events. [Impeller] Add GPU start/end trace events. Oct 11, 2023
@chinmaygarde
Copy link
Member

I don't think this measures anything useful does it? Command buffers may complete in any order. Even if you depend on queue submission order, thats only when commands are consumed, not when they are completed.

I'd rather not expose this information as it seems borderline meaningless.

@jonahwilliams
Copy link
Member Author

Fair enough, We can do this for real with timestamp queries.

GPUTracerVK::GPUTracerVK(const std::shared_ptr<ContextVK>& context)
: context_(context) {
timestamp_period_ =
context_->GetPhysicalDevice().getProperties().limits.timestampPeriod;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to check if this is actually supported right? Otherwise the value might be meaningless.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cmd itself is in 1.0, but I need to check that the queue supports timestamp queries. I think this will always be supported on graphics queues though, just might not have as much resolution as we'd like.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some tests failed due to queue contruction issues so I added some logs to see what this value ends up as ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, this can be zero. Good call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@jonahwilliams jonahwilliams changed the title [Impeller] Add GPU start/end trace events. [Impeller] Add GOU frame time to Vulkan backend using timestamp queries. Oct 12, 2023
@jonahwilliams jonahwilliams changed the title [Impeller] Add GOU frame time to Vulkan backend using timestamp queries. [Impeller] Add GPU frame time to Vulkan backend using timestamp queries. Oct 12, 2023
private:
void ResetQueryPool(size_t pool);

const std::shared_ptr<ContextVK> context_;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a smart C++ guy. Is the ContextVK owning a shared_ptr to the GPUTracerVK and the GPUTracerVK also having a shared_ptr to the ContextVK going to cause problems? Feels a bit like a cycle. Could use weakptrs...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

// timeline event but that is a job for a future Jonah.
auto gpu_ms = (((bits[1] - bits[0]) * timestamp_period_) / 1000000);
FML_TRACE_COUNTER("flutter", "GPUTracer",
1234, // Trace Counter ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably just be reinterpret_cast<int64_t>(this), or at least a named constant somewhere.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit about the trace counter ID

@jonahwilliams
Copy link
Member Author

Trying this out on the old flutter gallery perf benchmark is triggering some crash in the driver. I'm going to investigate this a bit more :(

@jonahwilliams
Copy link
Member Author

This patch is triggering a crash, but only on a particular benchmark: the old gallery with the old zoom page transition enabled. There currently isn't a stack, so I'm rebuilding with validation layers to investigate.

@jonahwilliams
Copy link
Member Author

No validation warnings.

@jonahwilliams
Copy link
Member Author

Here is the crash. This is it. No symbols since it seems to be in the driver.

10-13 16:16:58.192 14612 14612 F DEBUG   : Build fingerprint: 'google/cheetah/cheetah:13/TQ3A.230901.001/10750268:user/release-keys'
10-13 16:16:58.192 14612 14612 F DEBUG   : Revision: 'MP1.0'
10-13 16:16:58.192 14612 14612 F DEBUG   : ABI: 'arm64'
10-13 16:16:58.192 14612 14612 F DEBUG   : Timestamp: 2023-10-13 16:16:57.980346150-0400
10-13 16:16:58.192 14612 14612 F DEBUG   : Process uptime: 28s
10-13 16:16:58.192 14612 14612 F DEBUG   : Cmdline: io.flutter.demo.gallery
10-13 16:16:58.192 14612 14612 F DEBUG   : pid: 14504, tid: 14560, name: mali-event-hand  >>> io.flutter.demo.gallery <<<
10-13 16:16:58.192 14612 14612 F DEBUG   : uid: 10282
10-13 16:16:58.192 14612 14612 F DEBUG   : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
10-13 16:16:58.192 14612 14612 F DEBUG   : signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0x0000007ce09f4601
10-13 16:16:58.192 14612 14612 F DEBUG   :     x0  b400007c26126b40  x1  0000000000000000  x2  0000007d609abf30  x3  0000007c33361a98
10-13 16:16:58.192 14612 14612 F DEBUG   :     x4  00000000000000c0  x5  0000007cc09669c0  x6  00004cc8000057aa  x7  00005c3400005056
10-13 16:16:58.192 14612 14612 F DEBUG   :     x8  b400007ce09f4601  x9  00000000000fdb30  x10 00000000000000e0  x11 0000000000000014
10-13 16:16:58.192 14612 14612 F DEBUG   :     x12 000000000000f20e  x13 0000000000000009  x14 0000000000005f52  x15 000012761f9f9ad1
10-13 16:16:58.192 14612 14612 F DEBUG   :     x16 0000007c9bcc5748  x17 0000007f62b4b050  x18 0000007c29236000  x19 b400007d7097f3c0
10-13 16:16:58.192 14612 14612 F DEBUG   :     x20 b400007d7097f3b0  x21 b400007c26126b30  x22 0000000000000001  x23 0000000000000001
10-13 16:16:58.192 14612 14612 F DEBUG   :     x24 b400007c26029000  x25 b400007c3d56f300  x26 b400007cf0a02850  x27 00000000000fc000
10-13 16:16:58.192 14612 14612 F DEBUG   :     x28 00000000000fe000  x29 0000007c33361c50
10-13 16:16:58.192 14612 14612 F DEBUG   :     lr  0000007c9ab66c34  sp  0000007c33361b10  pc  0000007ce09f4601  pst 0000000080001000
10-13 16:16:58.192 14612 14612 F DEBUG   : backtrace:
10-13 16:16:58.192 14612 14612 F DEBUG   :       #00 pc 000000000001c601  [anon:scudo:primary]
10-13 16:16:58.192 14612 14612 F DEBUG   :       #01 pc 00000000016e7c30  /vendor/lib64/egl/libGLES_mali.so (basep_cpu_queue_process+192) (BuildId: 5482e3b181443d3b)
10-13 16:16:58.192 14612 14612 F DEBUG   :       #02 pc 00000000016e6174  /vendor/lib64/egl/libGLES_mali.so (basep_process_command_queues+180) (BuildId: 5482e3b181443d3b)
10-13 16:16:58.192 14612 14612 F DEBUG   :       #03 pc 00000000016e4ac4  /vendor/lib64/egl/libGLES_mali.so (basep_event_thread+228) (BuildId: 5482e3b181443d3b)
10-13 16:16:58.192 14612 14612 F DEBUG   :       #04 pc 00000000000c226c  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+204) (BuildId: dc4001c2ef2dfc23467040797a96840c)
10-13 16:16:58.192 14612 14612 F DEBUG   :       #05 pc 0000000000054a30  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: dc4001c2ef2dfc23467040797a96840c)

@jonahwilliams
Copy link
Member Author

This is pretty easy to repro. Run the old flutter gallery with --dart-define=flutter.benchmarks.force_disable_snapshot=true and navigate back and forth between pages that do the android zoom transition.

@jonahwilliams
Copy link
Member Author

The full command I'm using is:

flutter drive --local-engine=android_profile_arm64 --local-engine-host=host_profile --enable-impeller -t test_driver/transitions_perf.dart --driver test_driver/transitions_perf_test.dart --profile --dart-define=flutter.benchmarks.force_disable_snapshot=true

in flutter/dev/integration_tests/flutter_gallery

@jonahwilliams
Copy link
Member Author

Okay I fixed this by switching both queries to bottom of pipe. One day I'll learn what these do.

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 13, 2023
@auto-submit auto-submit bot merged commit 4801184 into flutter:main Oct 13, 2023
27 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 13, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 14, 2023
…136566)

flutter/engine@a4e6258...cd1a5ed

2023-10-13 skia-flutter-autoroll@skia.org Roll Skia from 4bc4b4d22866 to 9affbebb459a (2 revisions) (flutter/engine#46913)
2023-10-13 jonahwilliams@google.com [Impeller] Add GPU frame time to Vulkan backend using timestamp queries. (flutter/engine#46796)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
fluttermirroringbot pushed a commit to flutter/flutter that referenced this pull request Oct 14, 2023
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
…es. (#46796)

For flutter/flutter#136408 ,

Approximate the GPU frame time by measuring the difference between a timestamp query recorded at the beginning of the frame and a timestamp query recorded at the end of the frame.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants