[Impeller] Add block-compressed texture format support (BC, ETC2, ASTC)#187077
Conversation
Adds BC, ETC2, and ASTC block-compressed pixel formats to Impeller, gated behind a per-family capability query, per the design in flutter#148443. - Core: new compressed PixelFormat values, IsCompressed, block dimension and bytes-per-block helpers, and block-aware TextureDescriptor sizing math. - Capabilities: SupportsTextureCompression(family) on the Capabilities interface, the builder/StandardCapabilities, and all backends. Detection uses Vulkan device features, GLES extension strings, and Metal GPU families. - Backends: format mappings for Metal, Vulkan, and GLES, plus a GLES compressed upload path (glCompressedTexImage2D) and block-aware blit byte sizes. - Compressed textures are validated as sample-only at allocation. Compressed formats are not yet exposed by the Flutter GPU API surface; that is tracked in flutter#187073.
There was a problem hiding this comment.
Code Review
This pull request introduces support for block-compressed texture formats (BC, ETC2, and ASTC) in Impeller, updating the GLES, Metal, and Vulkan backends to query device capabilities and handle compressed texture uploads. Reviewer feedback suggests improving safety and correctness by explicitly handling all compressed formats in CompressedTextureFamilyForFormat and block dimension helpers, validating that GLES compressed texture uploads target full mip levels, checking for additional GLES extensions to accurately report BC support, and simplifying GetBytesPerRow using the new BytesPerRowForTextureWidth helper.
… upload, explicit block dims
|
An existing Git SHA, To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with |
|
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 Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
| return nullptr; | ||
| } | ||
|
|
||
| if (IsCompressed(desc.format)) { |
There was a problem hiding this comment.
Does this mean users of flutter gpu will not get errors when trying to use compressed textures for writing? This seems like the sort of error we'd want to surface.
There was a problem hiding this comment.
Improved this by having the Flutter GPU Dart Texture constructor throw on creation failure instead of silently returning an invalid texture (f8ab4be). Been meaning to clean that up for a while. :)
| desc->HasExtension(kTextureCompressionRGTCExt) && | ||
| desc->HasExtension(kTextureCompressionBPTCExt); | ||
| supports_texture_compression_astc_ = | ||
| desc->HasExtension(kTextureCompressionAstcLdrExt) || |
There was a problem hiding this comment.
Is or what we want here? I'll read through the rest of the PR but it seems like it will be hard to reason about if you know you only have one of these.
There was a problem hiding this comment.
Yes, || is intended since either extension exposes the same LDR ASTC formats; clarified with a comment (f8ab4be).
| // fullscreen quad. The texture is an 8x8 image laid out as a 2x2 grid of solid | ||
| // color blocks, so the golden is four colored quadrants. BC1 is the most widely | ||
| // supported compressed family on desktop GPUs; backends without it are skipped. | ||
| TEST_P(RendererGoldenTest, CanRenderBC1CompressedTexture) { |
There was a problem hiding this comment.
Is it worth having a test for the other families of compression?
There was a problem hiding this comment.
Added ETC2 and ASTC goldens alongside BC1 via a shared helper (cbaa5d2).
|
Not supporting PVRTC and ETC1 is totally fine. But the ASTC HDR supports should be pretty cut and dry right? Was there some specific extension wrangling that made you think its best for a followup? |
The ToScreenshotFormat switch over impeller::PixelFormat has no default, so the new kASTC4x4HDR/kASTC8x8HDR enumerators must be listed explicitly to satisfy -Wswitch and -Wreturn-type.
|
cc @planetmarshall as you might be interested in reviewing this |
The Flutter GPU Texture constructor now throws 'Texture creation failed', matching GpuContext.createTexture and the gpu_test.dart expectation, instead of a divergent message. The now-redundant isValid check in createTexture is removed since the constructor throws on failure.
|
Golden file changes are available for triage from new commit, Click here to view. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
BC1, ETC2, and ASTC now all render the same red/green/blue/white quadrants. ETC2 uses individual-mode solid-color blocks and ASTC switches to 4x4 void-extent blocks so each tiles the 8x8 image as a 2x2 grid. Verified locally by building impeller_golden_tests and rendering the ETC2 and ASTC tests on the OpenGLES backend.
|
Golden file changes are available for triage from new commit, Click here to view. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
Goldens are looking correct for this, testing all 3 types. :) |
gaaclarke
left a comment
There was a problem hiding this comment.
Nice, thanks brandon. We'll try picking up the slack to make this generally accessible at some point in Flutter proper.
| if (!_valid) { | ||
| // The engine logs the specific reason (for example, a compressed format | ||
| // used with render target or shader write usage, which is sample-only). | ||
| throw Exception('Texture creation failed'); |
There was a problem hiding this comment.
I'd like to provide a more apropos failure. We can do that as a followup. I want it to say something like "format X not supported on this device".
flutter/flutter@c8f2f16...e70534d 2026-05-28 [email protected] Linux glyph gamma correction (flutter/flutter#187122) 2026-05-28 [email protected] [iOS] Eliminate strong retain cycle from VSyncClient (flutter/flutter#187164) 2026-05-28 [email protected] Revert "[pubspec] Bump Dart SDK constraint to ^3.13.0 (#186957)" (flutter/flutter#187209) 2026-05-28 [email protected] Roll Skia from f1b8ba877c07 to 32acea791248 (3 revisions) (flutter/flutter#187220) 2026-05-27 [email protected] Roll Fuchsia Linux SDK from k9EizfEGJO4WwQN9-... to SBpmmPxqx3lAvGojE... (flutter/flutter#187211) 2026-05-27 [email protected] [Impeller] Add block-compressed texture format support (BC, ETC2, ASTC) (flutter/flutter#187077) 2026-05-27 [email protected] Disable analyzer (flutter/flutter#187205) 2026-05-27 [email protected] [Flutter GPU] Add explicit draw counts (reland) (flutter/flutter#187192) 2026-05-27 [email protected] [Flutter GPU] Inject per-backend defines into shader bundle compilation (flutter/flutter#187081) 2026-05-27 [email protected] Roll Skia from fa944af10f91 to f1b8ba877c07 (13 revisions) (flutter/flutter#187194) 2026-05-27 [email protected] Fixes bug when changing accessibilityFocusBlockType doesn't update ch… (flutter/flutter#186596) 2026-05-27 [email protected] Roll pub packages (flutter/flutter#187191) 2026-05-27 [email protected] [web, tool] Support recompiling shaders and unify asset processing (2nd try) (flutter/flutter#186902) 2026-05-27 [email protected] Fix crash if FlView is destroyed during a draw. (flutter/flutter#186848) 2026-05-27 [email protected] Roll Packages from fc795e5 to 4b424d7 (4 revisions) (flutter/flutter#187174) 2026-05-27 [email protected] Stop prefetching Swift packages in pub get (flutter/flutter#187113) 2026-05-27 [email protected] Update CI with newer android sdk package (flutter/flutter#187143) 2026-05-27 [email protected] Add a tag to the Linux platform properties in .ci.yaml that specifies x64 CPUs (flutter/flutter#187124) 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 [email protected],[email protected] 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
…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.
…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.
…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
Works towards #148443. Design doc: #178632. The Flutter GPU API surface is tracked separately in #187073.
Adds block-compressed texture support to Impeller for the BC, ETC2, and ASTC format families. Compressed format support varies by device, so a new capability query,
Capabilities::SupportsTextureCompression(family), lets callers check before allocating. Detection uses Vulkan device features, OpenGLES extension strings, and Metal GPU families.Compressed textures are sample-only and are validated as such at allocation: they cannot be render targets, storage textures, or transient attachments. Texture sizing math is now block-aware on every backend, and OpenGLES gains a
glCompressedTexImage2Dupload path.The format set is BC1, BC3, BC5, BC7, ETC2 RGB8, ETC2 RGBA8, ASTC 4x4/8x8 LDR, and ASTC 4x4/8x8 HDR, with sRGB variants where applicable (HDR has no sRGB variant). PVRTC and ETC1 are left for a follow-up.
These formats are not yet exposed by the Flutter GPU API surface.
Pre-launch Checklist
///).