Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[fuchsia] Allow multiple vsync requests before the first Present#31316

Merged
fluttergithubbot merged 2 commits intoflutter:mainfrom
uysalere:multiple-vsyncs-before-present
Feb 8, 2022
Merged

[fuchsia] Allow multiple vsync requests before the first Present#31316
fluttergithubbot merged 2 commits intoflutter:mainfrom
uysalere:multiple-vsyncs-before-present

Conversation

@uysalere
Copy link
Contributor

@uysalere uysalere commented Feb 8, 2022

This CL changes the flatland render loop so that we fire vsync callbacks immediately before the first present.

Bug: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=93179

@uysalere uysalere force-pushed the multiple-vsyncs-before-present branch 2 times, most recently from c450820 to 6827c1e Compare February 8, 2022 01:31
@uysalere
Copy link
Contributor Author

uysalere commented Feb 8, 2022

@arbreng @akbiggs PTAL.

@akbiggs akbiggs requested review from akbiggs and arbreng February 8, 2022 02:17
Copy link
Contributor

@arbreng arbreng left a comment

Choose a reason for hiding this comment

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

Looks great! All the stuff we talked about

@uysalere uysalere force-pushed the multiple-vsyncs-before-present branch 2 times, most recently from 2769021 to 8d44dab Compare February 8, 2022 02:48
Copy link
Contributor

@akbiggs akbiggs left a comment

Choose a reason for hiding this comment

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

Just wondering, were you able to test this change and confirm that it fixed the problem?


// This method is called from the raster thread.
void FlatlandConnection::Present() {
if (!threadsafe_state_.first_present_called_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering what first_present_called_ represents since it doesn't seem to care about whether DoPresent() actually did the presentation.

Will OnGetLayout() return the correct value if DoPresent wasn't called yet (either because this thread didn't reach DoPresent() or because present_credits_ == 0 on this call)?

Copy link
Contributor Author

@uysalere uysalere Feb 8, 2022

Choose a reason for hiding this comment

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

Flutter animator waits for a Vsync signal from Flatland before starting to render a frame, see Animator::RequestFrame(). Flatland returns Vsync signal to the client through OnNextFrameBegin(), but only after they send their first Present(). |first_present_called_| was used to fake the first vsync signal in AwaitVsync(). We then follow Present()-OnNextFrame() sequence for the render loop.

Flatland's OnGetLayout() returns values to Flutter on a separate protocol and platform thread. Ideally, the clients should wait for it before their first Present() so they know how big their content should be. Flutter does that and even skips render if size isn't there yet in Engine::Render(). However, it can take a couple AwaitVsync calls to have the size, so we fake vsync signals until the first Present().

All Flatland clients start with 1 present credit, so we know the first Present goes through.

@uysalere
Copy link
Contributor Author

uysalere commented Feb 8, 2022

Yes, I tested that this works 1) with the injected sleep() that makes it a consistent repro 2) 40 runs on OOBE app.

@uysalere uysalere force-pushed the multiple-vsyncs-before-present branch from 8d44dab to 8657794 Compare February 8, 2022 08:24
Copy link
Contributor

@akbiggs akbiggs left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation, looks good.

// Immediately fire callbacks until the first Present. We might receive
// multiple requests for AwaitVsync() until the first Present, which relies on
// receiving size on FlatlandPlatformView::OnGetLayout() at an uncertain time.
bool first_present_called;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is acquiring and releasing this lock a second time on every frame expensive? It seems like we're adding additional work to every frame to handle a case that's only true for the first couple of vsyncs and never afterwards.

If this is cheap ignore this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! I am changing so that we keep the lock. I was trying to handle the case that FlatlandConnectionTest.PresentCreditExhaustion exercises where FireCallbackCallback runs Present(). But it is not applicable in production code as we have a thread jump. AwaitVsync is always on UI thread and Present() is on raster thread. I am modifying the test.

@akbiggs akbiggs added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Feb 8, 2022
Copy link
Contributor

@akbiggs akbiggs left a comment

Choose a reason for hiding this comment

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

New changes LGTM. Added label to submit when presubmits are green again.

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Mac Host Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux Host Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Feb 8, 2022
@uysalere uysalere force-pushed the multiple-vsyncs-before-present branch from 9d91847 to bd34283 Compare February 8, 2022 19:17
@uysalere uysalere force-pushed the multiple-vsyncs-before-present branch from bd34283 to 44de155 Compare February 8, 2022 19:28
@akbiggs akbiggs added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Feb 8, 2022
@fluttergithubbot fluttergithubbot merged commit d05d681 into flutter:main Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 8, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 8, 2022
@uysalere uysalere deleted the multiple-vsyncs-before-present branch February 9, 2022 16:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

platform-fuchsia waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants