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

migrate flutter runner to present2 #14162

Merged
merged 2 commits into from
Feb 5, 2020

Conversation

farchond
Copy link
Contributor

@farchond farchond commented Dec 6, 2019

No change in behavior expected. We have 2 frames in flight as before.

By switching to Present2 and specifying a kMaxFramesInFlight however, we
allow us greater flexibility to change how Flutter schedules which will be
changed in the coming CLs.

@auto-assign auto-assign bot requested a review from GaryQian December 6, 2019 21:59
@farchond farchond changed the title migrate to flutter runner to present2 migrate flutter runner to present2 Dec 6, 2019
@iskakaushik
Copy link
Contributor

I have only glanced at this PR, noticed that it doesn't have any tests. I realize that the existing implementation is untested, but our current infra should support testing this change. Let me know if you need support writing them.

Comment on lines 39 to 40
// Since this event is fired on a per-presentation not per-submission
// basis, we may have had multiple Present2() calls all end here.
Copy link

Choose a reason for hiding this comment

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

This is a bit confusing. How about something along the the lines:
// Frame presented: update presents in flight with the remaining unhandled present requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it look more like yours, PTAL.

@@ -92,6 +128,12 @@ void SessionConnection::EnqueueClearOps() {

void SessionConnection::PresentSession() {
Copy link

Choose a reason for hiding this comment

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

+1 for adding tests on when a present should / should not be called.

@iskakaushik
Copy link
Contributor

Caught up with @farchond , we need to account for the following scenario. Flutter uses the presentation_time as the scheduling mechanism in VsyncWaiter. I'm worried about the following scenario:

  1. have 2 frames in flight. We get back 2 future times back . Lets say (16 ms, 32 ms).
  2. we update VsyncRecorder to 16 as it is the smallest time in the future.
  3. Vsync recorder would never record 32 as a vsync time as during the next present call we would presumably get 48, ..

We agreed on a couple of ways to work around this problem.

Copy link
Contributor

@gw280 gw280 left a comment

Choose a reason for hiding this comment

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

Really good to see this!

One overall comment is whether we really need FML_CHECK for all these cases, or if we can get away with FML_DCHECK instead.

@@ -452,3 +453,134 @@ fuchsia_archive("flutter_runner_tzdata_tests") {
},
]
}

executable("flutter_runner_scenic_unittests") {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we just make these tests part of the flutter_runner_tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC, because of dependencies on session_connection, Kaushik and I made flutter_runner_scenic_tests a separate target as it was not possible to do so otherwise.

@@ -0,0 +1,36 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly, we can just add these services and features to the existing flutter_runner_tests cmx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto above comment, we can discuss there if necessary.

session_wrapper_.set_on_frame_presented_handler(
[this, handle = vsync_event_handle_](
fuchsia::scenic::scheduling::FramePresentedInfo info) {
FML_LOG(INFO) << "OnFramePresented";
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we TRACE_EVENT here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was for debugging - removed.

// A frame was presented: Update our |frames_in_flight| to match the
// updated unfinalized present requests.
frames_in_flight_ -= num_presents_handled;
FML_CHECK(frames_in_flight_ >= 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

can we get away with only checking this in debug builds, or is this a catastrophic condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made into a DCHECK.

frames_in_flight_allowed_ = info.remaining_presents_in_flight_allowed;

// If Scenic alloted us 0 frames to begin with, we should fail here.
FML_CHECK(frames_in_flight_allowed_ > 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have to actually abort here or can we just early return and not present?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there is such an error at startup, I thought it'd be best to fail immediately. If we can't even Present() at the beginning, then there won't be a time when we can.

"isolate_configurator.h",
"logging.h",
"loop.cc",
"loop.h",
Copy link
Contributor

Choose a reason for hiding this comment

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

loop, task_observers, task_runner_adapter etc are all gone in master

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

async::Loop loop(&kAsyncLoopConfigAttachToCurrentThread);
thrd_t fidl_thread;
ZX_ASSERT(ZX_OK ==
loop.StartThread("SessionConnectionTestThread", &fidl_thread));
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see anywhere that we use this thread? Also, can we use FML's Thread classes instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment explaining this in the code: basically we need an async_dispatcher in order to have a ComponentContext. Using a Fuchsia async::Loop gives us one.

# Flutter testing.
alias fltestbuild='autoninja -C $FLUTTER_DIR/src/out/fuchsia_release_arm64 flutter_runner_tests-0.far'
alias fltestpub='$FLUTTER_DIR/src/fuchsia/sdk/linux/tools/pm publish -a -r $FUCHSIA_DIR/out/astro/amber-files/ -f $FLUTTER_DIR/src/out/fuchsia_release_arm64/flutter_runner_tests-0.far'
alias fltestrun='fx shell run fuchsia-pkg://fuchsia.com/flutter_runner_tests#meta/flutter_runner_tests.cmx'
Copy link
Contributor

Choose a reason for hiding this comment

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

is this file supposed to be in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No :) done

#include <lib/sys/cpp/component_context.h>

//#include <fuchsia/sys/component_context/cpp/fidl.h>
//#include <fuchsia/sys/index/cpp/fidl.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: commented out lines of code

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

}

// IMPORTANT NOTE: Because there only exists one VsyncRecorder, the order of
// these tests matter.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we isolate each test using SetUp() and TearDown()?

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

// These InterfacePtrs can be initialized any time after |context_|, but must
// be member variables so they remain in scope for the duration of the test.
fidl::InterfacePtr<fuchsia::ui::scenic::Scenic> scenic_ =
context_->svc()->Connect<fuchsia::ui::scenic::Scenic>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we initialize these in SetUp? I was confused until I saw them here

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


namespace flutter_runner_test {

class SessionConnectionTest : public ::testing::Test {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this hermetic? We are using the actual system Scenic here. Let's file an issue to track making this hermetic via TestWithEnvironment (for the hackathon)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed issue fxb/44542

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@farchond farchond force-pushed the present_migration branch 3 times, most recently from 421eb32 to 0cab201 Compare January 28, 2020 00:08
No change in behavior expected. We have 2 frames in flight as before.
By switching to Present2 and specifying a kMaxFramesInFlight however, we
allow us greater flexibility to change how Flutter schedules. This
change also adds tests for SessionConnection and VsyncRecorder.
@farchond farchond force-pushed the present_migration branch 2 times, most recently from 4d724d9 to 2a0e694 Compare February 5, 2020 01:49
Copy link
Contributor

@iskakaushik iskakaushik left a comment

Choose a reason for hiding this comment

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

LGTM

@iskakaushik iskakaushik merged commit 11b7704 into flutter:master Feb 5, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 5, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 6, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 6, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 6, 2020
jason-simmons pushed a commit to flutter/flutter that referenced this pull request Feb 6, 2020
* 9347c93 Roll src/third_party/dart c8ed304e979a..3414b5167554 (52 commits) (flutter/engine#16362)

* 16cd6f0 Roll fuchsia/sdk/core/mac-amd64 from 6h3IH... to Ke00Y... (flutter/engine#16360)

* 8c6cc65 Fix runtime type errors when running with canvaskit (flutter/engine#16312)

* 677b563 Refactor of Vulkan GPUSurface code (flutter/engine#16224)

* 7ca44d3 Kill the test harness if any test exceeds a timeout. (flutter/engine#16349)

* 7f6149c Revert "Remove use of the deprecated AccessibilityNodeInfo boundsInPa… (flutter/engine#16355)

* 488f489 Roll fuchsia/sdk/core/linux-amd64 from Tszo5... to VJv0H... (flutter/engine#16363)

* 7c9b11a Roll src/third_party/skia 71ce449d2814..2aee7d24da8f (5 commits) (flutter/engine#16364)

* 7e1d144 Expose enable-service-port-fallback switch (flutter/engine#16366)

* 4cda916 Expose the dart kernel snapshot target and copied assets as a public dependency (flutter/engine#16266)

* 73c5130 Roll src/third_party/dart 3414b5167554..68e904e444dc (17 commits) (flutter/engine#16367)

* 1cd8f3b Fix and consolidate wstring conversion utils (flutter/engine#16342)

* b98a39e Add docs (flutter/engine#16368)

* e3e6de2 Roll buildroot to c44791c89d2b51bfce864ab2cf5228d41ece1fcc (flutter/engine#16371)

* e24ec59 Fuchsia a11y actions (flutter/engine#16321)

* d8400c9 Roll src/third_party/skia 2aee7d24da8f..14d64afaa8a3 (10 commits) (flutter/engine#16374)

* eeabd4d Roll src/third_party/dart 68e904e444dc..48808f7dce81 (17 commits) (flutter/engine#16377)

* 22b994c Roll fuchsia/sdk/core/mac-amd64 from Ke00Y... to ubThi... (flutter/engine#16378)

* 0471f44 Roll src/third_party/skia 14d64afaa8a3..6c9b1fd6663e (7 commits) (flutter/engine#16380)

* 852d824 Roll src/third_party/dart 48808f7dce81..34893faa6079 (7 commits) (flutter/engine#16381)

* 4aa2083 Roll src/third_party/skia 6c9b1fd6663e..bc3307c395e2 (1 commits) (flutter/engine#16383)

* 036c370 Copied Apple's semantics for switches, made checkboxes the same. (flutter/engine#16211)

* c107969 fix build_id logic for fuchsia symbols (flutter/engine#16397)

* 11b7704 [fuchsia] Migrate flutter runner to use Present2 (flutter/engine#14162)

* 646ec35 Update license output (flutter/engine#16379)

* 925c60b Fix Windows embedding issues caught by clang (flutter/engine#16369)

* 31bf3e1 Roll src/third_party/dart 34893faa6079..b3396cbdcae1 (36 commits) (flutter/engine#16422)

* 8f89bac [web] Fixes incorrect transform when context save and transforms are deferred. (flutter/engine#16412)

* f34bc65 use percent for golden diff rates; tighten the values (flutter/engine#16430)
NoamDev pushed a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
No change in behavior expected. We have 2 frames in flight as before. By switching to Present2 and specifying a kMaxFramesInFlight however, we allow us greater flexibility to change how Flutter schedules its frames.

This change also adds tests for SessionConnection and VsyncRecorder.
NoamDev added a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
8 participants