Skip to content

[flutter_tools] Hot reload Flutter GPU shader bundles#187654

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
bdero:bdero/shader-bundle-hot-reload
Jun 9, 2026
Merged

[flutter_tools] Hot reload Flutter GPU shader bundles#187654
auto-submit[bot] merged 2 commits into
flutter:masterfrom
bdero:bdero/shader-bundle-hot-reload

Conversation

@bdero

@bdero bdero commented Jun 7, 2026

Copy link
Copy Markdown
Member

Fixes #186345

After a DevFS sync, dispatch ext.ui.gpu.reinitializeShaderLibrary for changed .shaderbundle assets so the engine reloads the compiled Flutter GPU shader library in place. Gated by the .shaderbundle suffix (the engine no-ops on a registry miss), tolerant of the lazily-registered extension being absent, and skipped on web (where the bundle falls back to the generic asset eviction).

Pre-launch Checklist

Fixes flutter#186345

After a DevFS sync, dispatch ext.ui.gpu.reinitializeShaderLibrary for each
changed asset path ending in .shaderbundle, so the engine reloads the compiled
Flutter GPU shader library in place instead of keeping the old shaders until a
restart. The suffix is only a filter; the engine no-ops on a registry miss, and
the lazily-registered extension is tolerated when absent. Skipped on web, where
the bundle falls back to the generic asset eviction.
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 7, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jun 7, 2026
@bdero bdero marked this pull request as ready for review June 7, 2026 05:08

@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 introduces support for reinitializing Flutter GPU shader libraries for .shaderbundle assets during hot reload, instead of using generic asset eviction, except on the web platform. Feedback suggests adding a null check for device.targetPlatform before comparing it to prevent potential null pointer issues, and adding a test case to verify the fallback behavior on the web platform.

Comment thread packages/flutter_tools/lib/src/resident_runner.dart
Comment thread packages/flutter_tools/test/general.shard/resident_runner_test.dart
Cover the web path of evictDirtyAssets, where a changed .shaderbundle asset
falls back to ext.flutter.evict instead of the Flutter GPU shader-library
reload extension (unavailable on the web engine).
@dcharkes

dcharkes commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

I don't think I know enough about what Flutter GPU exactly is and where shaders fit in to review if having custom handing in flutter_tool is the right step.

  • Flutter GPU exposes bindings to the C functions in the flutter engine to be used via dart:ffi?
  • Flutter GPU exposes access to the the bytes of the compiled shaders via the Flutter asset bundle, and passes those to the GPU C code via the dart:ffi bindings.

If the bytes are shipped via Flutter asset bundle, then hot restart and hot reload should already work?

So then my next hypothesis is that Flutter GPU has a bit more than just dart:ffi to internals and shipping compiled shaders via the flutter assets manifest. Could you elaborate the larger picture?

@bdero

bdero commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

Right that the bytes ship via the asset bundle, but they aren't read each frame. ShaderLibrary.fromAsset reads them once and builds a long-lived native shader object that survives hot reload, so syncing new bytes to the device doesn't rebuild it. The app keeps the old shaders until a restart.

This is the same case as FragmentProgram (flutter.shaders:). A few lines up, a changed .frag gets ext.ui.window.reinitializeShader instead of the generic evict, which tells the engine to re-read the bytes and rebuild in place. This PR does the same for Flutter GPU bundles via ext.ui.gpu.reinitializeShaderLibrary (engine half shipped in #186344). The tool stays format-agnostic, dispatching by asset path so the engine no-ops on a miss.

@bdero bdero added the CICD Run CI/CD label Jun 8, 2026
@bdero bdero added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 9, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jun 9, 2026
Merged via the queue into flutter:master with commit 5de7570 Jun 9, 2026
166 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 9, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jun 11, 2026
flutter/flutter@66aaa9a...c0a1129

2026-06-10 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#187740)
2026-06-09 burak.karahan@mail.ru Remove Material import from view chrome style test (flutter/flutter#186994)
2026-06-09 jason-simmons@users.noreply.github.com [Impeller] Remove unused DeviceHolderVK reference from CommandBufferVK (flutter/flutter#187705)
2026-06-09 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from KNe93cf5wU4xG2d-m... to 8azSyvz57mKcPqTwk... (flutter/flutter#187745)
2026-06-09 1063596+reidbaker@users.noreply.github.com Add android-agent agent.json and update reidbaker-agent skills (flutter/flutter#187746)
2026-06-09 engine-flutter-autoroll@skia.org Roll Skia from aeed11c35004 to 9f02102df298 (9 revisions) (flutter/flutter#187744)
2026-06-09 bdero@google.com [Impeller] Remove the texture coordinate system Y-flip workaround (flutter/flutter#187686)
2026-06-09 41687333+rlueders@users.noreply.github.com [Impeller] Retry uncompressed when fixed-rate compression is exhausted (flutter/flutter#187586)
2026-06-09 burak.karahan@mail.ru Remove Material import from implicit animation tests (flutter/flutter#186673)
2026-06-09 engine-flutter-autoroll@skia.org Roll Packages from 13b49f4 to bd297cf (4 revisions) (flutter/flutter#187739)
2026-06-09 30870216+gaaclarke@users.noreply.github.com Updates dia_dll.py to support vs2026 (flutter/flutter#187714)
2026-06-09 bdero@google.com [Flutter GPU] Allow attaching specific texture mip levels and slices for rendering (flutter/flutter#187685)
2026-06-09 engine-flutter-autoroll@skia.org Roll Dart SDK from 39f1c44e294f to f3441f2067ae (1 revision) (flutter/flutter#187711)
2026-06-09 bdero@google.com [flutter_tools] Hot reload Flutter GPU shader bundles (flutter/flutter#187654)
2026-06-09 katelovett@google.com Update triage links (flutter/flutter#187709)
2026-06-09 engine-flutter-autoroll@skia.org Roll Skia from 43f135735152 to aeed11c35004 (11 revisions) (flutter/flutter#187721)
2026-06-09 jason-simmons@users.noreply.github.com Use workspace resolution for the meta package in dev/integration_tests/record_use_test_package (flutter/flutter#187733)

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 louisehsu@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

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
Fixes flutter#186345

After a DevFS sync, dispatch `ext.ui.gpu.reinitializeShaderLibrary` for
changed `.shaderbundle` assets so the engine reloads the compiled
Flutter GPU shader library in place. Gated by the `.shaderbundle` suffix
(the engine no-ops on a registry miss), tolerant of the
lazily-registered extension being absent, and skipped on web (where the
bundle falls back to the generic asset eviction).

## 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/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[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 tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_tools] Hot reload Flutter GPU shader bundles by dispatching the shader-library reinitialize extension

3 participants