Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shell/platform/fuchsia/flutter/session_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SessionConnection final {
// The maximum number of frames Flutter sent to Scenic that it can have
// outstanding at any time. This is equivalent to how many times it has
// called Present2() before receiving an OnFramePresented() event.
static constexpr int kMaxFramesInFlight = 2;
static constexpr int kMaxFramesInFlight = 3;
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure about the nature of scheduling flexibility offered by this change. But, in the past, we have found that increasing the pipeline depth has adverse effects when it comes to render frames with inconsistent rasterizer times.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's important to note that this doesn't actually impact the Flutter pipeline as you normally think of it, but rather how Flutter Present()s content to Scenic.

Right now Flutter only has two frames in flight, which means that if we are effectively "double buffered." If we then miss frame A Flutter can't submit frame C, because B is also in flight. By changing this to 3, we can miss frame A and still have frames B and C in flight too, ensuring that one frame miss won't result in another one.

If we were targeting <=16ms Scenic+Flutter frame build times then this wouldn't matter. But by increasing how many frames in flight we can have we can target 32ms frame build times and not suffer a double penalty for missing a frame.

Copy link
Member

Choose a reason for hiding this comment

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

It's important to note that this doesn't actually impact the Flutter pipeline as you normally think of it, but rather how Flutter Present()s content to Scenic.

I realize that. Just wanted to know the reasoning behind this change. Thanks for the clarifications.

int frames_in_flight_ = 0;

int frames_in_flight_allowed_ = 0;
Expand Down
11 changes: 10 additions & 1 deletion shell/platform/fuchsia/flutter/vsync_waiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ void VsyncWaiter::AwaitVSync() {
VsyncRecorder::GetInstance().GetLastPresentationTime();
fml::TimePoint next_vsync = SnapToNextPhase(now, last_presentation_time,
vsync_info.presentation_interval);

auto next_vsync_start_time = next_vsync - vsync_offset;

if (now >= next_vsync_start_time)
next_vsync_start_time =
next_vsync_start_time + vsync_info.presentation_interval;

fml::TimeDelta delta = next_vsync_start_time - now;

task_runners_.GetUITaskRunner()->PostDelayedTask(
[& weak_factory_ui = this->weak_factory_ui_] {
if (!weak_factory_ui) {
Expand All @@ -143,7 +152,7 @@ void VsyncWaiter::AwaitVSync() {
self->FireCallbackWhenSessionAvailable();
}
},
next_vsync - now);
delta);
}

void VsyncWaiter::FireCallbackWhenSessionAvailable() {
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/fuchsia/flutter/vsync_waiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class VsyncWaiter final : public flutter::VsyncWaiter {
async::Wait session_wait_;
fml::WeakPtrFactory<VsyncWaiter> weak_factory_;

static constexpr fml::TimeDelta vsync_offset =
fml::TimeDelta::FromNanoseconds(0);

// For accessing the VsyncWaiter via the UI thread, necessary for the callback
// for AwaitVSync()
std::unique_ptr<fml::WeakPtrFactory<VsyncWaiter>> weak_factory_ui_;
Expand Down