Skip to content

[Flutter GPU] Make ShaderLibrary.fromAsset asynchronous#187716

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
bdero:bdero/flutter-gpu-shader-library-async-from-asset
Jun 13, 2026
Merged

[Flutter GPU] Make ShaderLibrary.fromAsset asynchronous#187716
auto-submit[bot] merged 2 commits into
flutter:masterfrom
bdero:bdero/flutter-gpu-shader-library-async-from-asset

Conversation

@bdero

@bdero bdero commented Jun 9, 2026

Copy link
Copy Markdown
Member

ShaderLibrary.fromAsset now returns a Future<ShaderLibrary?> instead of loading synchronously.

Asset reads can only be asynchronous on some platforms, so a synchronous loader cannot work everywhere. Making the single loader async gives every platform one consistent entry point and removes the need for downstream code to keep a separate async loading path. flutter_gpu is experimental, so this breaking change is cheap to make now.

On platforms that read synchronously the returned Future still completes in the same turn, and the library is still cached by asset path, so hot reload is unaffected.

The engine Dart tests and the renderer fixture harness are updated to await the loader. The fixture harness drains the microtask queue after invoking an entry point so the now-async fixtures run to completion.

This is a breaking change to an experimental API, so no flutter/tests migration guide is needed.

Pre-launch Checklist

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 9, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request is not mergeable in its current state, likely because of a merge conflict. Pre-submit CI jobs were not triggered. Pushing a new commit to this branch that resolves the issue will result in pre-submit jobs being scheduled.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests flutter-gpu team-fluttergpu Owned by Flutter GPU team labels Jun 9, 2026
@github-project-automation github-project-automation Bot moved this to 🤔 Needs Triage in Flutter GPU Jun 9, 2026
@bdero bdero force-pushed the bdero/flutter-gpu-shader-library-async-from-asset branch from 341f8c0 to 832ce51 Compare June 9, 2026 03:15
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 9, 2026
@bdero bdero added the CICD Run CI/CD label Jun 9, 2026
}
queue->RunMicrotasks();
return queue->GetLastError() == tonic::kNoError;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I'll delete this whole test file/corresponding fixtures in a follow-up... This is an ancient harness I added way back when I was just barely getting Flutter GPU to render anything at all. It's largely redundant these days given all the tests under testing/dart/gpu_test.dart.

@bdero bdero marked this pull request as ready for review June 9, 2026 03:36

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

Copy link
Copy Markdown
Contributor

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 refactors ShaderLibrary.fromAsset to be asynchronous, returning a Future<ShaderLibrary?> to ensure consistent asset loading across platforms. Consequently, related Dart tests, fixtures, and helper functions are updated to be asynchronous and await the shader library loading. In the C++ test runner, a DrainMicrotasks helper is introduced to run Dart microtasks to completion. A review comment points out that tonic::DartMicrotaskQueue lacks a GetLastError() method, suggesting that the last error should instead be retrieved from tonic::DartState::Current().

Comment thread engine/src/flutter/impeller/renderer/renderer_dart_unittests.cc
@bdero bdero requested a review from gaaclarke June 9, 2026 19:58
@gaaclarke gaaclarke requested a review from andywolff June 9, 2026 20:03
@gaaclarke

Copy link
Copy Markdown
Member

@andywolff can you give this PR a look, please?

andywolff
andywolff previously approved these changes Jun 10, 2026

@andywolff andywolff left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with one nit

Tests are all passing on my local checkout on my apple silicon mac at least. I'm curious, which specific platforms are fixed by this change? The PR description just says some platforms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: You've placed your new test between this comment and its corresponding test body, please fix

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in c8225d6.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 10, 2026
@bdero bdero added the CICD Run CI/CD label Jun 10, 2026
andywolff
andywolff previously approved these changes Jun 10, 2026

@andywolff andywolff left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, LGTM

@bdero

bdero commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

@andywolff It's actually for web. We can't get away with loading stuff from the asset bundle synchronously on web, so it'll be a problem down the road once Impeller on Web (wimp) comes to fruition. My web shim has to contend with this blemish today.

I actually wrote the initial web shim two years ago in effort to discover these kinds of API design flaws. :)

image

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 10, 2026
@bdero bdero added the CICD Run CI/CD label Jun 10, 2026
@flutter-dashboard

This comment was marked as outdated.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 11, 2026
@bdero bdero added the CICD Run CI/CD label Jun 11, 2026
@bdero bdero force-pushed the bdero/flutter-gpu-shader-library-async-from-asset branch from 135b27f to fdd690c Compare June 11, 2026 19:32

@andywolff andywolff left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@bdero bdero added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 12, 2026
@auto-submit

auto-submit Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/187716, Failed to enqueue flutter/flutter/187716 with HTTP 400: Pull request 2 of 3 required status checks are expected..

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 12, 2026
@bdero bdero added the CICD Run CI/CD label Jun 12, 2026
Return a Future so the loader works on platforms that can only read
assets asynchronously, giving every platform one consistent entry
point. Native loading still completes in the same turn and the asset
cache is unchanged, so hot reload still works. Tests and the renderer
fixture harness await the loader and drain microtasks.
@bdero bdero force-pushed the bdero/flutter-gpu-shader-library-async-from-asset branch from e233d4f to 79ef824 Compare June 12, 2026 19:04
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 12, 2026
@bdero bdero added the CICD Run CI/CD label Jun 12, 2026
@bdero

bdero commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

Google testing failed on this one too, so need to push a new commit to rerun the entire test suite again.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 12, 2026
@bdero bdero added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Jun 12, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jun 13, 2026
Merged via the queue into flutter:master with commit ee89c03 Jun 13, 2026
206 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 13, 2026
@github-project-automation github-project-automation Bot moved this from 🤔 Needs Triage to ✅ Done in Flutter GPU Jun 13, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jun 15, 2026
Roll Flutter from b7cb925419e6 to 5827d5fd2b8d (35 revisions)

flutter/flutter@b7cb925...5827d5f

2026-06-15 engine-flutter-autoroll@skia.org Roll Skia from 7128af60575a to c8d9f80f13e4 (1 revision) (flutter/flutter#188015)
2026-06-15 jason-simmons@users.noreply.github.com In the APNG decoder, validate the chunk data length before calling GetChunkSize to avoid potential overflow in the chunk size calculation (flutter/flutter#187949)
2026-06-15 engine-flutter-autoroll@skia.org Roll Skia from 6b4ac3bfb39d to 7128af60575a (1 revision) (flutter/flutter#188011)
2026-06-15 engine-flutter-autoroll@skia.org Roll Skia from 0a3b8549cbf0 to 6b4ac3bfb39d (7 revisions) (flutter/flutter#188007)
2026-06-15 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[a11y] Map some framework semantics roles to android classes.  (#185217)" (flutter/flutter#188008)
2026-06-15 chris@bracken.jp [ios] Filter UIScene events to those relating to Flutter VC scene (flutter/flutter#187987)
2026-06-15 jhy03261997@gmail.com [a11y] Map some framework semantics roles to android classes.  (flutter/flutter#185217)
2026-06-15 engine-flutter-autoroll@skia.org Roll Skia from f46928e7f50c to 0a3b8549cbf0 (1 revision) (flutter/flutter#188004)
2026-06-14 stuartmorgan@google.com Rework docs for flutter/packages changelogs (flutter/flutter#187666)
2026-06-14 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from nvzMQAmuRSzo7-wAP... to TbB86Po_HDe1dvXvT... (flutter/flutter#187997)
2026-06-14 engine-flutter-autoroll@skia.org Roll Skia from 4e2c9b5e4dad to f46928e7f50c (1 revision) (flutter/flutter#187996)
2026-06-14 engine-flutter-autoroll@skia.org Roll Skia from c52667607242 to 4e2c9b5e4dad (1 revision) (flutter/flutter#187990)
2026-06-14 737941+loic-sharma@users.noreply.github.com Improve RenderTargetCache docs (flutter/flutter#187893)
2026-06-13 brackenavaron@gmail.com [Test cross_imports] Check cross imports in flutter_test/** (flutter/flutter#187587)
2026-06-13 matt.kosarek@canonical.com Fixing corrupted window size OnEmptyFrameGenerated due to transpsed width/height (flutter/flutter#187954)
2026-06-13 engine-flutter-autoroll@skia.org Roll Skia from 42355271a335 to c52667607242 (2 revisions) (flutter/flutter#187979)
2026-06-13 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from A3eaUn9mQ_EkSNxVI... to nvzMQAmuRSzo7-wAP... (flutter/flutter#187975)
2026-06-13 engine-flutter-autoroll@skia.org Roll Skia from 9ef46390c2d1 to 42355271a335 (1 revision) (flutter/flutter#187974)
2026-06-13 bdero@google.com [Flutter GPU] Make ShaderLibrary.fromAsset asynchronous (flutter/flutter#187716)
2026-06-13 engine-flutter-autoroll@skia.org Roll Skia from 8c89bf2b0ee3 to 9ef46390c2d1 (6 revisions) (flutter/flutter#187968)
2026-06-12 bdero@google.com [Flutter GPU] Add surface API for framework presentation (flutter/flutter#187358)
2026-06-12 bkonyi@google.com [gen_l10n] Exclude inherited keys from untranslated-messages-file (flutter/flutter#187950)
2026-06-12 31859944+LongCatIsLooong@users.noreply.github.com Update `MediaQueryData` docs for devicePixelRatio overriding (flutter/flutter#187542)
2026-06-12 bdero@google.com [Impeller] Fix dirty-range race in DeviceBufferGLES uploads (flutter/flutter#187932)
2026-06-12 pascal@phntm.xyz Compare isModifiedAfter against the given time (flutter/flutter#187727)
2026-06-12 planetmarshall@users.noreply.github.com Enable unit tests for compilation of compute shaders on non-metal backends (flutter/flutter#179683)
2026-06-12 matt.boetger@gmail.com [flutter_tools] Add doctor validator warning for multiple adb installations (flutter/flutter#186031)
2026-06-12 matt.boetger@gmail.com Optimize SHA hash calculation of generated APK (flutter/flutter#187184)
2026-06-12 mu7ammadkamel@hotmail.com Scope widget inspector overlay to the selected widget's modal route (flutter/flutter#186784)
2026-06-12 30870216+gaaclarke@users.noreply.github.com Switches Windows to OpenGLESSDF (flutter/flutter#187877)
2026-06-12 matt.boetger@gmail.com [integration_test] Update README to support modern Kotlin-based setups by default (flutter/flutter#186080)
2026-06-12 jason-simmons@users.noreply.github.com Convert the PNG signature constant in APNGImageGenerator to a std::array and use it in the APNG tests (flutter/flutter#187930)
2026-06-12 matt.boetger@gmail.com Correct backoff retry time cap unit and add regression tests (flutter/flutter#187250)
2026-06-12 chingjun@google.com Fix std::vector out-of-bounds access in Flutter Android JNI and Delegate (flutter/flutter#187218)
2026-06-12 matt.boetger@gmail.com [Android] Adding 30-second timeouts to adb stopApp and uninstallApp (flutter/flutter#187876)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622
...
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
`ShaderLibrary.fromAsset` now returns a `Future<ShaderLibrary?>` instead
of loading synchronously.

Asset reads can only be asynchronous on some platforms, so a synchronous
loader cannot work everywhere. Making the single loader async gives
every platform one consistent entry point and removes the need for
downstream code to keep a separate async loading path. flutter_gpu is
experimental, so this breaking change is cheap to make now.

On platforms that read synchronously the returned Future still completes
in the same turn, and the library is still cached by asset path, so hot
reload is unaffected.

The engine Dart tests and the renderer fixture harness are updated to
await the loader. The fixture harness drains the microtask queue after
invoking an entry point so the now-async fixtures run to completion.

This is a breaking change to an experimental API, so no `flutter/tests`
migration guide is needed.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
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. flutter-gpu team-fluttergpu Owned by Flutter GPU team

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants