[Flutter GPU] Add block-compressed texture format support (BC, ETC2, ASTC LDR)#187281
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for block-compressed texture formats in the Flutter GPU API, adding capability queries, block-aware mip level size calculations, and validation checks during texture allocation. The review feedback suggests refining the capability and validation checks to ensure compressed formats require shader read usage, and adding documentation to the public 'PixelFormatProperties' extension to comply with the style guide.
68b6bdf to
b29f090
Compare
…ASTC LDR) Builds on the Impeller-side support landed in flutter#187077. Adds the BC, ETC2, and ASTC LDR pixel formats to the Flutter GPU public API along with two capability queries (`supportsTextureCompression` per family, `supportsTextureFormat` per format) on `GpuContext`. Validation in `createTexture` enforces compressed = sample-only and block-aligned dimensions; `Texture.overwrite` accepts block-packed compressed bytes. `PixelFormat` now exposes `isCompressed`, `blockWidth`, `blockHeight`, `bytesPerBlock`, and `compressionFamily` extension getters. `Texture`'s `bytesPerTexel` getter is removed in favor of `format.bytesPerBlock`, which is well-defined for both compressed and uncompressed formats, and `getMipLevelSizeInBytes` is now block-aware. HDR variants, PVRTC, and ETC1 are deferred. KTX2/Basis transcoding lives above Flutter GPU (in Flutter Scene or a sibling package); this PR just exposes the hardware formats and the capability surface.
b29f090 to
6a947c0
Compare
| !enableShaderReadUsage || | ||
| sampleCount != 1 || | ||
| storageMode == StorageMode.deviceTransient) { | ||
| throw Exception( |
There was a problem hiding this comment.
These should be errors, not exceptions https://groups.google.com/a/dartlang.org/g/misc/c/lx9CXiV3o30/m/s5l_PwpHUGAJ
| // For uncompressed formats, today's Impeller capability surface does not | ||
| // expose a per-format usage query, so this returns true. As that surface | ||
| // grows it should be wired in here. | ||
| (void)shader_read; |
There was a problem hiding this comment.
did you mean to leave this in?
|
|
||
| test('GpuContext.createTexture allocates a compressed texture when supported', () async { | ||
| if (!gpu.gpuContext.supportsTextureCompression(gpu.TextureCompressionFamily.bc)) { | ||
| return; |
There was a problem hiding this comment.
Skipping would be preferable so that there is a note that the test didn't run.
|
|
||
| test('Texture.overwrite uploads block-aligned compressed data', () async { | ||
| if (!gpu.gpuContext.supportsTextureCompression(gpu.TextureCompressionFamily.bc)) { | ||
| return; |
|
|
||
| test('Texture.overwrite rejects wrong size for compressed format', () async { | ||
| if (!gpu.gpuContext.supportsTextureCompression(gpu.TextureCompressionFamily.bc)) { | ||
| return; |
… cast, mark tests skipped Addresses inline review feedback on PR flutter#187281: - Throw `ArgumentError` from `createTexture` compressed-format validation instead of `Exception`, since these are programmer errors (caller misuse), not runtime conditions. - Remove the now-unused `(void)shader_read;` cast in `Context_SupportsTextureFormat`: `shader_read` is read in the compressed branch, so the parameter is no longer unused. - Replace the runtime `return;` early-out in compressed-capability-gated tests with `markTestSkipped(...)` so the test runner reports them as skipped rather than silently passing.
flutter/flutter@54e199a...701665b 2026-06-02 engine-flutter-autoroll@skia.org Roll Skia from c97e939eb5c9 to 279b17fe9fc1 (16 revisions) (flutter/flutter#187425) 2026-06-02 bdero@google.com [Flutter GPU] Add block-compressed texture format support (BC, ETC2, ASTC LDR) (flutter/flutter#187281) 2026-06-02 bdero@google.com [Impeller] Allow attaching specific texture mip levels and slices (flutter/flutter#187066) 2026-06-02 bdero@google.com [Impeller] Fix GLES command submission status before context is current (flutter/flutter#187293) 2026-06-02 engine-flutter-autoroll@skia.org Roll Dart SDK from 3cdc25e8ffe9 to d39850bf4a01 (9 revisions) (flutter/flutter#187409) 2026-06-01 jason-simmons@users.noreply.github.com [Impeller] Use glVertexAttribDivisor on GLES3 and glVertexAttribDivisorEXT on GLES2 with the extension (flutter/flutter#187313) 2026-06-01 matt.boetger@gmail.com [Android] Add Javadoc documentation to TextInputChannel (flutter/flutter#186018) 2026-06-01 mvincentong@gmail.com Read FLTEnableWideGamut from Dart bundle (flutter/flutter#186509) 2026-06-01 matt.boetger@gmail.com [flutter_tools] Remove obsolete AndroidX console warning during Gradle builds (flutter/flutter#186077) 2026-06-01 kjlubick@users.noreply.github.com [skia] Update gni file list name hsw -> ml3 (flutter/flutter#184892) 2026-06-01 zhongliu88889@gmail.com [web] Always sync slider input attrs regardless of gesture mode (flutter/flutter#187217) 2026-06-01 zhongliu88889@gmail.com [flutter_driver] Don't throw when stderr is unavailable on web (flutter/flutter#187190) 2026-06-01 116356835+AbdeMohlbi@users.noreply.github.com Remove unused code in `FlutterPluginUtils.kt` (flutter/flutter#187012) 2026-06-01 taak140@gmail.com [flutter_tools] Fix `flutter drive --chrome-binary` being ignored on web (flutter/flutter#185481) 2026-06-01 davidmartos96@gmail.com Eager failure when building and no XCode build settings (flutter/flutter#184726) 2026-06-01 goung123@gmail.com Fix Windows Korean IME caret position during composition (flutter/flutter#186353) 2026-06-01 okorohelijah@google.com iOS: update provisioning profile for 2026-2027 cert (flutter/flutter#187280) 2026-06-01 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#187380) 2026-06-01 jason-simmons@users.noreply.github.com Reland "Move dart-lang/ai to a top level third party dependency in engine (#187268)" (flutter/flutter#187378) 2026-06-01 stuartmorgan@google.com Add vector_math to Framework triage (flutter/flutter#187389) 2026-06-01 engine-flutter-autoroll@skia.org Roll Packages from e930ced to f5d50ca (4 revisions) (flutter/flutter#187381) 2026-06-01 mr_nadeem_iqbal@yahoo.com [flutter_tools] Reject archive entries that escape into a sibling directory by name prefix (#185794) (flutter/flutter#186647) 2026-06-01 bkonyi@google.com [flutter_tools] Fix widget_preview unawaited async write race condition (flutter/flutter#187177) 2026-06-01 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#187375) 2026-06-01 engine-flutter-autoroll@skia.org Roll Skia from 0aee4675e0ad to c97e939eb5c9 (7 revisions) (flutter/flutter#187371) 2026-06-01 mr_nadeem_iqbal@yahoo.com docs: Stack.clipBehavior = Clip.none does not extend hit testing (#160787) (flutter/flutter#186643) 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 stuartmorgan@google.com,tarrinneal@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
…r#11822) flutter/flutter@54e199a...701665b 2026-06-02 engine-flutter-autoroll@skia.org Roll Skia from c97e939eb5c9 to 279b17fe9fc1 (16 revisions) (flutter/flutter#187425) 2026-06-02 bdero@google.com [Flutter GPU] Add block-compressed texture format support (BC, ETC2, ASTC LDR) (flutter/flutter#187281) 2026-06-02 bdero@google.com [Impeller] Allow attaching specific texture mip levels and slices (flutter/flutter#187066) 2026-06-02 bdero@google.com [Impeller] Fix GLES command submission status before context is current (flutter/flutter#187293) 2026-06-02 engine-flutter-autoroll@skia.org Roll Dart SDK from 3cdc25e8ffe9 to d39850bf4a01 (9 revisions) (flutter/flutter#187409) 2026-06-01 jason-simmons@users.noreply.github.com [Impeller] Use glVertexAttribDivisor on GLES3 and glVertexAttribDivisorEXT on GLES2 with the extension (flutter/flutter#187313) 2026-06-01 matt.boetger@gmail.com [Android] Add Javadoc documentation to TextInputChannel (flutter/flutter#186018) 2026-06-01 mvincentong@gmail.com Read FLTEnableWideGamut from Dart bundle (flutter/flutter#186509) 2026-06-01 matt.boetger@gmail.com [flutter_tools] Remove obsolete AndroidX console warning during Gradle builds (flutter/flutter#186077) 2026-06-01 kjlubick@users.noreply.github.com [skia] Update gni file list name hsw -> ml3 (flutter/flutter#184892) 2026-06-01 zhongliu88889@gmail.com [web] Always sync slider input attrs regardless of gesture mode (flutter/flutter#187217) 2026-06-01 zhongliu88889@gmail.com [flutter_driver] Don't throw when stderr is unavailable on web (flutter/flutter#187190) 2026-06-01 116356835+AbdeMohlbi@users.noreply.github.com Remove unused code in `FlutterPluginUtils.kt` (flutter/flutter#187012) 2026-06-01 taak140@gmail.com [flutter_tools] Fix `flutter drive --chrome-binary` being ignored on web (flutter/flutter#185481) 2026-06-01 davidmartos96@gmail.com Eager failure when building and no XCode build settings (flutter/flutter#184726) 2026-06-01 goung123@gmail.com Fix Windows Korean IME caret position during composition (flutter/flutter#186353) 2026-06-01 okorohelijah@google.com iOS: update provisioning profile for 2026-2027 cert (flutter/flutter#187280) 2026-06-01 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#187380) 2026-06-01 jason-simmons@users.noreply.github.com Reland "Move dart-lang/ai to a top level third party dependency in engine (#187268)" (flutter/flutter#187378) 2026-06-01 stuartmorgan@google.com Add vector_math to Framework triage (flutter/flutter#187389) 2026-06-01 engine-flutter-autoroll@skia.org Roll Packages from e930ced to f5d50ca (4 revisions) (flutter/flutter#187381) 2026-06-01 mr_nadeem_iqbal@yahoo.com [flutter_tools] Reject archive entries that escape into a sibling directory by name prefix (#185794) (flutter/flutter#186647) 2026-06-01 bkonyi@google.com [flutter_tools] Fix widget_preview unawaited async write race condition (flutter/flutter#187177) 2026-06-01 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#187375) 2026-06-01 engine-flutter-autoroll@skia.org Roll Skia from 0aee4675e0ad to c97e939eb5c9 (7 revisions) (flutter/flutter#187371) 2026-06-01 mr_nadeem_iqbal@yahoo.com docs: Stack.clipBehavior = Clip.none does not extend hit testing (#160787) (flutter/flutter#186643) 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 stuartmorgan@google.com,tarrinneal@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
Follow-up to flutter#187281, which added the block-compressed formats (BC, ETC2, ASTC LDR) but intentionally left the ASTC HDR variants out of the Dart API. This exposes the ASTC HDR pixel formats (`astc4x4HDR`, `astc8x8HDR`) and the `astcHdr` compression family to Flutter GPU. Impeller already supports these end to end across Metal, Vulkan, and GLES, so this is only the Dart-facing plumbing in `formats.dart` and `formats.h` plus block-introspection and capability-query tests. ## 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
…ASTC LDR) (flutter#187281) Addresses flutter#187073. Builds on the Impeller-side support landed in flutter#187077 and the `PixelFormat` cleanup in flutter#187069. Adds BC, ETC2, and ASTC LDR pixel formats to the Flutter GPU public API along with capability queries for selecting a hardware-supported family at runtime. KTX2 / Basis transcoding is intentionally above Flutter GPU. Flutter Scene or a companion package picks a hardware target via the capability query, transcodes on the CPU, and uploads opaque block bytes via `Texture.overwrite`. This is a small breaking change to an experimental API: callers using `texture.bytesPerTexel` should switch to `texture.format.bytesPerBlock`. ## 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. - [ ] 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
Follow-up to flutter#187281, which added the block-compressed formats (BC, ETC2, ASTC LDR) but intentionally left the ASTC HDR variants out of the Dart API. This exposes the ASTC HDR pixel formats (`astc4x4HDR`, `astc8x8HDR`) and the `astcHdr` compression family to Flutter GPU. Impeller already supports these end to end across Metal, Vulkan, and GLES, so this is only the Dart-facing plumbing in `formats.dart` and `formats.h` plus block-introspection and capability-query tests. ## 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
Addresses #187073. Builds on the Impeller-side support landed in #187077 and the
PixelFormatcleanup in #187069.Adds BC, ETC2, and ASTC LDR pixel formats to the Flutter GPU public API along with capability queries for selecting a hardware-supported family at runtime.
KTX2 / Basis transcoding is intentionally above Flutter GPU. Flutter Scene or a companion package picks a hardware target via the capability query, transcodes on the CPU, and uploads opaque block bytes via
Texture.overwrite.This is a small breaking change to an experimental API: callers using
texture.bytesPerTexelshould switch totexture.format.bytesPerBlock.Pre-launch Checklist
///).