Skip to content

[Flutter GPU] Add blit operations#187289

Merged
auto-submit[bot] merged 6 commits into
flutter:masterfrom
bdero:bdero/flutter-gpu-blits
Jun 12, 2026
Merged

[Flutter GPU] Add blit operations#187289
auto-submit[bot] merged 6 commits into
flutter:masterfrom
bdero:bdero/flutter-gpu-blits

Conversation

@bdero

@bdero bdero commented May 29, 2026

Copy link
Copy Markdown
Member

Adds explicit Flutter GPU texture copy commands on CommandBuffer:

  • copyBufferToTexture
  • copyTextureToBuffer
  • copyTextureToTexture

This makes texture uploads and copies part of command-buffer recording, so renderers can order transfer work with render passes and batch adjacent copy commands internally. Texture.overwrite is now deprecated and implemented through a staging DeviceBuffer plus CommandBuffer.copyBufferToTexture.

This also fixes the GLES texture-to-texture blit encoder to pass right and bottom coordinates to glBlitFramebuffer, instead of width and height. The new Flutter GPU copy tests cover this case.

Examples

Upload pixels from a staging buffer into a texture:

final gpu.CommandBuffer commandBuffer = gpu.gpuContext.createCommandBuffer();
commandBuffer.copyBufferToTexture(
  gpu.BufferView(stagingBuffer, offsetInBytes: 0, lengthInBytes: byteLength),
  gpu.TextureRegion(texture, width: width, height: height),
);
commandBuffer.submit();

Read pixels from a texture into a buffer:

final gpu.CommandBuffer commandBuffer = gpu.gpuContext.createCommandBuffer();
commandBuffer.copyTextureToBuffer(
  gpu.TextureRegion(texture, width: width, height: height),
  gpu.BufferView(readbackBuffer, offsetInBytes: 0, lengthInBytes: byteLength),
);
commandBuffer.submit();

Copy a region between two textures:

final gpu.CommandBuffer commandBuffer = gpu.gpuContext.createCommandBuffer();
commandBuffer.copyTextureToTexture(
  gpu.TextureRegion(sourceTexture, width: width, height: height),
  gpu.TextureDestinationRegion(destinationTexture, x: destinationX, y: destinationY),
);
commandBuffer.submit();

Pre-launch Checklist

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 29, 2026
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests team-engine Owned by Engine team flutter-gpu d: docs/ flutter/flutter/docs, for contributors team-fluttergpu Owned by Flutter GPU team labels May 29, 2026
@github-project-automation github-project-automation Bot moved this to 🤔 Needs Triage in Flutter GPU May 29, 2026
@bdero bdero changed the title [flutter_gpu] Add command buffer texture copy APIs [Flutter GPU] Add blit operations May 30, 2026
@bdero bdero force-pushed the bdero/flutter-gpu-blits branch from 0d23fd7 to 908db40 Compare May 30, 2026 08:24
@github-actions github-actions Bot removed CICD Run CI/CD team-engine Owned by Engine team d: docs/ flutter/flutter/docs, for contributors labels May 30, 2026
@bdero bdero force-pushed the bdero/flutter-gpu-blits branch from 908db40 to 4d43ff3 Compare May 31, 2026 08:35
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 31, 2026
@bdero bdero marked this pull request as ready for review May 31, 2026 08:35

@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 texture and buffer copy operations to the Flutter GPU API, including copyBufferToTexture, copyTextureToBuffer, and copyTextureToTexture on CommandBuffer, while deprecating Texture.overwrite. It also updates the GLES blit command to use correct coordinate bounds. Feedback highlights that the asynchronous submit path in CommandBuffer ignores the return value of EncodeCommands(), and that mip_level and slice parameters lack non-negative validation before casting. Additionally, the newly added public methods getMipLevelWidth and getMipLevelHeight in texture.dart require documentation to comply with the style guide.

Comment thread engine/src/flutter/lib/gpu/command_buffer.cc
Comment thread engine/src/flutter/lib/gpu/command_buffer.cc Outdated
Comment thread engine/src/flutter/lib/gpu/lib/src/texture.dart
Comment thread engine/src/flutter/lib/gpu/lib/src/texture.dart
@bdero bdero force-pushed the bdero/flutter-gpu-blits branch from 4d43ff3 to d4eef29 Compare May 31, 2026 11:08
@github-actions github-actions Bot removed the CICD Run CI/CD label May 31, 2026
@bdero bdero added the CICD Run CI/CD label May 31, 2026
@bdero bdero requested a review from gaaclarke May 31, 2026 23:44
@gaaclarke gaaclarke requested review from walley892 and removed request for gaaclarke June 1, 2026 21:46
@gaaclarke

Copy link
Copy Markdown
Member

hey @walley892 can you give these a look please?

@bdero fyi the ci is broken.

@bdero bdero force-pushed the bdero/flutter-gpu-blits branch from d4eef29 to b639abf Compare June 2, 2026 02:04
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 2, 2026
@walley892 walley892 added the CICD Run CI/CD label Jun 2, 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.

@walley892

Copy link
Copy Markdown
Contributor

/gemini review

walley892
walley892 previously approved these changes Jun 9, 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 removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 9, 2026
@auto-submit

auto-submit Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/187289, Failed to enqueue flutter/flutter/187289 with HTTP 400: Pull request Required status check "Merge Queue Guard" is expected..

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 9, 2026
@bdero bdero requested a review from walley892 June 9, 2026 23:17
@bdero

bdero commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

Another conflict lol. I just so happen to be landing a lot of stuff that touches textures today.

@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
@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 commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

Looks like this is ready for another attempt at merging @walley892

@bdero bdero added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 11, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jun 11, 2026
Merged via the queue into flutter:master with commit bb5ef59 Jun 12, 2026
206 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 12, 2026
@github-project-automation github-project-automation Bot moved this from 🤔 Needs Triage to ✅ Done in Flutter GPU Jun 12, 2026
@bdero bdero deleted the bdero/flutter-gpu-blits branch June 12, 2026 00:51
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jun 12, 2026
flutter/flutter@8bdce07...b7cb925

2026-06-12 engine-flutter-autoroll@skia.org Roll Skia from cadbde1ec4b7 to 8c89bf2b0ee3 (5 revisions) (flutter/flutter#187926)
2026-06-12 engine-flutter-autoroll@skia.org Roll Packages from 1b56cde to b78ad83 (5 revisions) (flutter/flutter#187928)
2026-06-12 engine-flutter-autoroll@skia.org Roll Dart SDK from f3441f2067ae to f6c31f4c3a63 (17 revisions) (flutter/flutter#187924)
2026-06-12 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from 2KosSR4ONUjIB7tP_... to A3eaUn9mQ_EkSNxVI... (flutter/flutter#187923)
2026-06-12 engine-flutter-autoroll@skia.org Roll Skia from a2228b926c68 to cadbde1ec4b7 (9 revisions) (flutter/flutter#187921)
2026-06-12 kustermann@google.com Remove dynamic module loading code in flutter web engine (flutter/flutter#187777)
2026-06-12 matt.kosarek@canonical.com Remove EnableTransparentWindowBackground because it did nothing important and because Windows 10 does not support DWMWA_SYSTEMBACKDROP_TYPE (flutter/flutter#187848)
2026-06-12 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from dQ4PjIJB5kZFU8Y32... to EmfiOMUge_nnNS33B... (flutter/flutter#187912)
2026-06-12 mvincentong@gmail.com Clarify RichText selection docs (flutter/flutter#186844)
2026-06-12 1063596+reidbaker@users.noreply.github.com Custom KGP task and migration to AGP api for geting kgp version (flutter/flutter#182788)
2026-06-12 engine-flutter-autoroll@skia.org Roll Skia from f61acb31edf8 to a2228b926c68 (5 revisions) (flutter/flutter#187896)
2026-06-12 bdero@google.com [Flutter GPU] Expose ASTC HDR texture formats (flutter/flutter#187715)
2026-06-12 awolff@google.com Expand coverage of android_hardware_smoke_test. Add image, text, blend mode, and blur tests. (flutter/flutter#187600)
2026-06-11 bdero@google.com [Flutter GPU] Add blit operations (flutter/flutter#187289)
2026-06-11 bkonyi@google.com [flutter_tools] Fix version cache git fallback performance regression (flutter/flutter#187400)
2026-06-11 nshahan@google.com Rewrite `-d web-server` hot reload/restart tests (flutter/flutter#187453)
2026-06-11 bdero@google.com [Impeller] Allow sampling textures with manually-uploaded mip levels (flutter/flutter#187729)
2026-06-11 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#187884)
2026-06-11 47866232+chunhtai@users.noreply.github.com iOS a11y sets header trait based on heading level (flutter/flutter#186916)
2026-06-11 engine-flutter-autoroll@skia.org Roll Skia from 9f02102df298 to f61acb31edf8 (19 revisions) (flutter/flutter#187869)
2026-06-11 engine-flutter-autoroll@skia.org Roll ICU from ee5f27adc28b to d578f2e8b7bd (8 revisions) (flutter/flutter#187829)

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
Adds explicit Flutter GPU texture copy commands on `CommandBuffer`:

- `copyBufferToTexture`
- `copyTextureToBuffer`
- `copyTextureToTexture`

This makes texture uploads and copies part of command-buffer recording,
so renderers can order transfer work with render passes and batch
adjacent copy commands internally. `Texture.overwrite` is now deprecated
and implemented through a staging `DeviceBuffer` plus
`CommandBuffer.copyBufferToTexture`.

This also fixes the GLES texture-to-texture blit encoder to pass right
and bottom coordinates to `glBlitFramebuffer`, instead of width and
height. The new Flutter GPU copy tests cover this case.

## Examples

Upload pixels from a staging buffer into a texture:

```dart
final gpu.CommandBuffer commandBuffer = gpu.gpuContext.createCommandBuffer();
commandBuffer.copyBufferToTexture(
  gpu.BufferView(stagingBuffer, offsetInBytes: 0, lengthInBytes: byteLength),
  gpu.TextureRegion(texture, width: width, height: height),
);
commandBuffer.submit();
```

Read pixels from a texture into a buffer:

```dart
final gpu.CommandBuffer commandBuffer = gpu.gpuContext.createCommandBuffer();
commandBuffer.copyTextureToBuffer(
  gpu.TextureRegion(texture, width: width, height: height),
  gpu.BufferView(readbackBuffer, offsetInBytes: 0, lengthInBytes: byteLength),
);
commandBuffer.submit();
```

Copy a region between two textures:

```dart
final gpu.CommandBuffer commandBuffer = gpu.gpuContext.createCommandBuffer();
commandBuffer.copyTextureToTexture(
  gpu.TextureRegion(sourceTexture, width: width, height: height),
  gpu.TextureDestinationRegion(destinationTexture, x: destinationX, y: destinationY),
);
commandBuffer.submit();
```

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

[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