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

Conversation

@uysalere
Copy link
Contributor

@uysalere uysalere commented Sep 7, 2023

This CL restructures Flatland vsync loop to fire for each vsync instead of each OnNextFrameBegin. As shown in the traces attached to the bug, the current implementation of firing callbacks on each OnNextFrameBegin causes skips when Flutter has longer draw calls. By scheduling frames in between, we are increasing the chance of sending one before the latch point. OnNextFrameBegin is now used to keep track of present credits and future presentation times as well as when to start frame, replacing the need for max_frames_in_flight and vsync_offset fields.

Bug: b/296272449

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.

LGTM % comments


} // namespace

// This function takes in all relevant information to determining when should
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Does this comment belong on the constructor or somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh leftover comment from an old helper function that is removed now. Erased it.

threadsafe_state_.on_next_frame_pending_ = true;
}
threadsafe_state_.next_presentation_time_ = next_presentation_time;
// Update vsync_interval_ by calculating.
Copy link
Contributor

Choose a reason for hiding this comment

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

Calculating how? For future readers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it.

}
threadsafe_state_.next_presentation_time_ = next_presentation_time;
// Update vsync_interval_ by calculating.
FML_CHECK(values.has_future_presentation_infos() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we CHECK here? Is it possible to warn instead and then use an approximation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a warning in case.

view_protocols = std::move(view_protocols),
request = parent_viewport_watcher.NewRequest(),
view_ref_pair = std::move(view_ref_pair),
max_frames_in_flight = product_config.get_max_frames_in_flight(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I think this means we can get rid of the product config file soon.

Please remove these fields from the flutter_runner_product_config.h

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

bool first_feedback_received_ = false;
FireCallbackCallback pending_fire_callback_;
uint32_t present_credits_ = 1;
std::queue<fml::TimePoint> next_presentation_times_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: queue first, then other fields, then boolean last (more readable, and fields pack into structure better)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// Throttle case.
if (threadsafe_state_.pending_fire_callback_ &&
threadsafe_state_.present_credits_ > 0) {
RunVsyncCallback(now, threadsafe_state_.pending_fire_callback_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Make a note here or below (at the definition of RunVsyncCallback) this is run on the Raster thread, but it is safe b/c the Vsync callback will be posted to the UI thread

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to the definition of RunVsyncCallback.

@uysalere uysalere merged commit 633ba42 into flutter:main Sep 7, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 7, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Sep 7, 2023
…134240)

flutter/engine@f0b718e...8d07c29

2023-09-07 [email protected] [Impeller] Document and slightly refactor `ResourceManagerVK` & friends. (flutter/engine#45474)
2023-09-07 [email protected] [fuchsia] Restructure Flatland vsync loop (flutter/engine#45531)
2023-09-07 [email protected] Roll Skia from 16df0c27bc0e to c3d6534b0ac3 (3 revisions) (flutter/engine#45543)

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 [email protected],[email protected] 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
uysalere added a commit that referenced this pull request Sep 11, 2023
This CL restructures Flatland vsync loop to fire for each vsync instead
of each OnNextFrameBegin. As shown in the traces attached to the bug,
the current implementation of firing callbacks on each OnNextFrameBegin
causes skips when Flutter has longer draw calls. By scheduling frames in
between, we are increasing the chance of sending one before the latch
point. OnNextFrameBegin is now used to keep track of present credits and
future presentation times as well as when to start frame, replacing the
need for max_frames_in_flight and vsync_offset fields.

Bug: b/296272449
(cherry picked from commit 633ba42)
uysalere added a commit to uysalere/engine that referenced this pull request Sep 12, 2023
This CL restructures Flatland vsync loop to fire for each vsync instead
of each OnNextFrameBegin. As shown in the traces attached to the bug,
the current implementation of firing callbacks on each OnNextFrameBegin
causes skips when Flutter has longer draw calls. By scheduling frames in
between, we are increasing the chance of sending one before the latch
point. OnNextFrameBegin is now used to keep track of present credits and
future presentation times as well as when to start frame, replacing the
need for max_frames_in_flight and vsync_offset fields.

Bug: b/296272449
tarobins pushed a commit that referenced this pull request Sep 13, 2023
This CL restructures Flatland vsync loop to fire for each vsync instead
of each OnNextFrameBegin. As shown in the traces attached to the bug,
the current implementation of firing callbacks on each OnNextFrameBegin
causes skips when Flutter has longer draw calls. By scheduling frames in
between, we are increasing the chance of sending one before the latch
point. OnNextFrameBegin is now used to keep track of present credits and
future presentation times as well as when to start frame, replacing the
need for max_frames_in_flight and vsync_offset fields.

Bug: b/296272449
(cherry picked from commit
633ba42)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants