Skip to content

[Impeller] Add block-compressed texture format support (BC, ETC2, ASTC)#187077

Merged
auto-submit[bot] merged 10 commits into
flutter:masterfrom
bdero:bdero/texture-compression
May 28, 2026
Merged

[Impeller] Add block-compressed texture format support (BC, ETC2, ASTC)#187077
auto-submit[bot] merged 10 commits into
flutter:masterfrom
bdero:bdero/texture-compression

Conversation

@bdero

@bdero bdero commented May 26, 2026

Copy link
Copy Markdown
Member

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 glCompressedTexImage2D upload 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

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.
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 26, 2026
@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 May 26, 2026
@github-project-automation github-project-automation Bot moved this to 🤔 Needs Triage in Flutter GPU May 26, 2026
@bdero bdero marked this pull request as ready for review May 26, 2026 04:38

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

Comment thread engine/src/flutter/impeller/core/formats.h
Comment thread engine/src/flutter/impeller/core/formats.h Outdated
Comment thread engine/src/flutter/impeller/core/texture_descriptor.h Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bdero bdero added the CICD Run CI/CD label May 26, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bdero bdero added the CICD Run CI/CD label May 26, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bdero bdero added the CICD Run CI/CD label May 26, 2026
@bdero bdero requested a review from gaaclarke May 26, 2026 05:51
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bdero bdero added CICD Run CI/CD and removed CICD Run CI/CD labels May 26, 2026
@fluttergithubbot

Copy link
Copy Markdown
Contributor

An existing Git SHA, 5a0938ab95b09e459f8666c3613f3358dbc86a47, was detected, and no actions were taken.

To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with --force) that already was pushed before, push a blank commit (git commit --allow-empty -m "Trigger Build") or rebase to continue.

@flutter-dashboard

Copy link
Copy Markdown

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 #187077 at sha 5a0938a

@flutter-dashboard flutter-dashboard Bot added the will affect goldens Changes to golden files label May 26, 2026
return nullptr;
}

if (IsCompressed(desc.format)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@bdero bdero May 26, 2026

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.

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) ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

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.

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it worth having a test for the other families of compression?

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.

Added ETC2 and ASTC goldens alongside BC1 via a shared helper (cbaa5d2).

@chinmaygarde

Copy link
Copy Markdown
Contributor

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.
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bdero bdero added the CICD Run CI/CD label May 26, 2026
@loic-sharma

loic-sharma commented May 26, 2026

Copy link
Copy Markdown
Member

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.
@bdero bdero added CICD Run CI/CD and removed CICD Run CI/CD labels May 26, 2026
@flutter-dashboard

Copy link
Copy Markdown

Golden file changes are available for triage from new commit, Click here to view.

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 #187077 at sha 8c5aebb

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.
@bdero bdero added CICD Run CI/CD and removed CICD Run CI/CD labels May 27, 2026
@flutter-dashboard

Copy link
Copy Markdown

Golden file changes are available for triage from new commit, Click here to view.

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 #187077 at sha 6213df4

@bdero bdero requested a review from gaaclarke May 27, 2026 19:54
@bdero

bdero commented May 27, 2026

Copy link
Copy Markdown
Member Author

Goldens are looking correct for this, testing all 3 types. :)

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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".

@bdero bdero added the autosubmit Merge PR when tree becomes green via auto submit App label May 27, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue May 27, 2026
Merged via the queue into flutter:master with commit fe96572 May 28, 2026
207 checks passed
@github-project-automation github-project-automation Bot moved this from 🤔 Needs Triage to ✅ Done in Flutter GPU May 28, 2026
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 28, 2026
@bdero bdero deleted the bdero/texture-compression branch May 28, 2026 03:22
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request May 28, 2026
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
bdero added a commit to bdero/flutter that referenced this pull request May 29, 2026
…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.
bdero added a commit to bdero/flutter that referenced this pull request May 29, 2026
…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.
pull Bot pushed a commit to AbhiShake1/flutter that referenced this pull request Jun 2, 2026
…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
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 will affect goldens Changes to golden files

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

5 participants