Skip to content

Adds flush to metal screenshotter.#183758

Merged
auto-submit[bot] merged 1 commit intoflutter:masterfrom
gaaclarke:flush-screenshotter
Mar 17, 2026
Merged

Adds flush to metal screenshotter.#183758
auto-submit[bot] merged 1 commit intoflutter:masterfrom
gaaclarke:flush-screenshotter

Conversation

@gaaclarke
Copy link
Member

fixes: #183746

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@gaaclarke gaaclarke requested a review from flar March 16, 2026 21:58
@github-actions github-actions bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Mar 16, 2026
@gaaclarke gaaclarke requested a review from walley892 March 16, 2026 21:58
@gaaclarke gaaclarke added the CICD Run CI/CD label Mar 16, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a GPU flush to the Metal screenshotter before capturing a screenshot. This is achieved by submitting an empty command buffer and waiting for its completion, which should prevent capturing incomplete frames. The change also refactors how the Context is obtained, now consistently using the one from AiksContext.

Comment on lines +28 to +38
if (auto cmd_buffer = context->CreateCommandBuffer()) {
if (context->GetCommandQueue()
->Submit({cmd_buffer},
[&latch](CommandBuffer::Status status) {
FML_CHECK(status == CommandBuffer::Status::kCompleted);
latch.Signal();
})
.ok()) {
latch.Wait();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current implementation silently ignores failures when creating or submitting the flush command buffer. If CreateCommandBuffer returns nullptr or Submit fails, the code proceeds to take a screenshot without waiting for GPU commands to finish. This could lead to capturing an incomplete or incorrect frame, causing flaky tests.

It's better to explicitly handle these failures. Using FML_CHECK would make the failure obvious and prevent proceeding with a likely incorrect state.

    if (auto cmd_buffer = context->CreateCommandBuffer()) {
      if (context->GetCommandQueue()
              ->Submit({cmd_buffer},
                       [&latch](CommandBuffer::Status status) {
                         FML_CHECK(status == CommandBuffer::Status::kCompleted);
                         latch.Signal();
                       })
              .ok()) {
        latch.Wait();
      } else {
        FML_CHECK(false && "Failed to submit flush command buffer.");
      }
    } else {
      FML_CHECK(false && "Failed to create command buffer for flush.");
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

Any value in the bot's suggestion? I'm guessing it's pretty hard to get here if there is no command queue or if it will fail to Submit?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would turn a failed test into a crash. I don't know that that is necessary. It doesn't seem that likely, probably best to just print something out?

Copy link
Contributor

@flar flar Mar 17, 2026

Choose a reason for hiding this comment

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

return nullptr and let the caller fail the test?

That would require too much re-plumbing throughout the unit and golden tests...

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

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

Changes reported for pull request #183758 at sha 5724736

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Mar 16, 2026
Copy link
Contributor

@flar flar 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 questions that are probably moot...

AiksContext& aiks_context,
const std::shared_ptr<Texture> texture) {
@autoreleasepool {
std::shared_ptr<Context> context = aiks_context.GetContext();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll take your word that this is the same as the context returned from the playground (where it used to be fetched from below).

Comment on lines +28 to +38
if (auto cmd_buffer = context->CreateCommandBuffer()) {
if (context->GetCommandQueue()
->Submit({cmd_buffer},
[&latch](CommandBuffer::Status status) {
FML_CHECK(status == CommandBuffer::Status::kCompleted);
latch.Signal();
})
.ok()) {
latch.Wait();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Any value in the bot's suggestion? I'm guessing it's pretty hard to get here if there is no command queue or if it will fail to Submit?

@gaaclarke
Copy link
Member Author

Oh wow, look at the golden changes. There was a test before that would reliably create a magenta image it seems. I wonder how that happened.

@flar
Copy link
Contributor

flar commented Mar 16, 2026

It looks like the new flushes caught an old test that was failing to return an answer every time it ran. (Oops, comments crossed in the ether...)

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 16, 2026
@flar
Copy link
Contributor

flar commented Mar 16, 2026

Oh wow, look at the golden changes. There was a test before that would reliably create a magenta image it seems. I wonder how that happened.

It's a huge downscale of a huge saveLayer content. It probably took a long time to run and didn't return an answer before we pushed the golden result...

@auto-submit auto-submit bot added this pull request to the merge queue Mar 17, 2026
Merged via the queue into flutter:master with commit c9dd8a2 Mar 17, 2026
190 of 191 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 17, 2026
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Mar 18, 2026
Roll Flutter from 732e05dd483c to d117642c18e0 (47 revisions)

flutter/flutter@732e05d...d117642

2026-03-17 [email protected] Roll Skia from fa3bb1f60d99 to dba893a44d7a (1 revision) (flutter/flutter#183783)
2026-03-17 [email protected] [ios][pv]fix admob banner scrollable on ios 18.2 (flutter/flutter#183274)
2026-03-17 [email protected] Roll Packages from 0f2eeae to a9d36fb (2 revisions) (flutter/flutter#183782)
2026-03-17 [email protected] Update goldctl version (flutter/flutter#183538)
2026-03-17 [email protected] Roll Skia from 69be1087807b to fa3bb1f60d99 (1 revision) (flutter/flutter#183779)
2026-03-17 [email protected] Roll Dart SDK from 38dedf00c2cd to 30cdd2634429 (1 revision) (flutter/flutter#183778)
2026-03-17 [email protected] Roll Fuchsia Linux SDK from s7rq9m8tH2aZtX-kP... to zYBvfzIH95BY3cCzL... (flutter/flutter#183777)
2026-03-17 [email protected] Roll Skia from 4ea039236580 to 69be1087807b (2 revisions) (flutter/flutter#183772)
2026-03-17 [email protected] Roll Skia from fb402093cfb5 to 4ea039236580 (1 revision) (flutter/flutter#183770)
2026-03-17 [email protected] Roll Skia from d6bc6d17d637 to fb402093cfb5 (8 revisions) (flutter/flutter#183765)
2026-03-17 [email protected] Roll Dart SDK from ff50ab8ecea4 to 38dedf00c2cd (2 revisions) (flutter/flutter#183764)
2026-03-17 [email protected] Wrap EGL image usage in a GObject (flutter/flutter#183539)
2026-03-17 [email protected] Adds platform_view_test_macos_impeller (flutter/flutter#183760)
2026-03-17 [email protected] Adds flush to metal screenshotter. (flutter/flutter#183758)
2026-03-16 [email protected] Add a platform OpenGL context. (flutter/flutter#183715)
2026-03-16 [email protected] Fix formatting, capitalization, and grammar in activation issue template (flutter/flutter#183061)
2026-03-16 [email protected] Roll Dart SDK from 4a6febbf882e to ff50ab8ecea4 (2 revisions) (flutter/flutter#183739)
2026-03-16 [email protected] docs: add code review guidance to CONTRIBUTING.md (flutter/flutter#182778)
2026-03-16 [email protected] Filter 'waiting for customer response' issues from macOS triage (flutter/flutter#183552)
2026-03-16 [email protected] Adds github action to reset cicd when new branches come (flutter/flutter#183675)
2026-03-16 [email protected] Adds macos impeller complex layout performance test (flutter/flutter#183669)
2026-03-16 [email protected] Roll Dart SDK from b74e5b537d71 to 4a6febbf882e (2 revisions) (flutter/flutter#183695)
2026-03-16 [email protected] Use properties to configure leak_tracking and test_randomization_off in .ci.yaml (flutter/flutter#183605)
2026-03-16 [email protected] [flutter_tools] Avoid File.exists and File.stat, as per enforced lint rule (flutter/flutter#183463)
2026-03-16 [email protected] Properly parse URIs for testPath when the host is running on Windows. (flutter/flutter#176881)
2026-03-16 [email protected] Roll Packages from 91f7c33 to 0f2eeae (6 revisions) (flutter/flutter#183730)
2026-03-16 [email protected] Roll Skia from a6ccaf95c6e0 to d6bc6d17d637 (5 revisions) (flutter/flutter#183726)
2026-03-16 [email protected] Roll Fuchsia Linux SDK from WOfyEFkxf9JX26VS-... to s7rq9m8tH2aZtX-kP... (flutter/flutter#183723)
2026-03-15 [email protected] Roll Skia from 34ace196b838 to a6ccaf95c6e0 (2 revisions) (flutter/flutter#183712)
2026-03-14 [email protected] Roll Fuchsia Linux SDK from vAWG8mRvsQHblDBsy... to WOfyEFkxf9JX26VS-... (flutter/flutter#183694)
2026-03-14 [email protected] Roll Skia from 06106120c6bf to 34ace196b838 (1 revision) (flutter/flutter#183677)
2026-03-14 [email protected] Roll Dart SDK from 6a3dc9d4f881 to b74e5b537d71 (2 revisions) (flutter/flutter#183676)
2026-03-14 [email protected] Add some quality of life improvements to the release GitHub workflows. (flutter/flutter#183658)
2026-03-14 [email protected] Fix RouteAware.didPushNext documentation inaccuracy (flutter/flutter#183097)
2026-03-13 [email protected] Adds complex layout impeller startup benchmark (flutter/flutter#183655)
2026-03-13 [email protected] Adds switch for sdf rendering plus golden tests (flutter/flutter#183543)
2026-03-13 [email protected] Made complex_layout_scroll_perf explicitly skia (flutter/flutter#183663)
2026-03-13 [email protected] Update android integration test to match the current android semantics (flutter/flutter#183548)
2026-03-13 [email protected] Roll Skia from 6c0346103c24 to 06106120c6bf (3 revisions) (flutter/flutter#183654)
2026-03-13 [email protected] Roll Dart SDK from d5f6d3c17499 to 6a3dc9d4f881 (1 revision) (flutter/flutter#183652)
2026-03-13 [email protected] Fix PinnedHeaderSliver semantics focus capture (flutter/flutter#179023)
2026-03-13 [email protected] [a11y][android] In Android 16, sendWindowContentChangeEvent when check state changes (flutter/flutter#183606)
2026-03-13 [email protected] Update gradle utils to know about kgp 2.3.10 constraints (flutter/flutter#183416)
2026-03-13 [email protected] Roll Skia from 029229d8be91 to 6c0346103c24 (5 revisions) (flutter/flutter#183648)
2026-03-13 [email protected] Roll Fuchsia Linux SDK from jJbpv4J_tjW-wuKDq... to vAWG8mRvsQHblDBsy... (flutter/flutter#183646)
2026-03-13 [email protected] [flutter_tools] Support flavors and transformers for shaders (flutter/flutter#181889)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test DlGoldenTest.ShimmerTest is flaky and blocking some of the rollers

2 participants