Skip to content

[Impeller] Fix GLES command submission status before context is current#187293

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
bdero:bdero/gles-queue-parity
Jun 2, 2026
Merged

[Impeller] Fix GLES command submission status before context is current#187293
auto-submit[bot] merged 1 commit into
flutter:masterfrom
bdero:bdero/gles-queue-parity

Conversation

@bdero

@bdero bdero commented May 29, 2026

Copy link
Copy Markdown
Member

Fixes #187290

This fixes another issue that makes the GLES backend behave quite differently from Metal/Vulkan.

This makes GLES command submission accept work when no reactor worker can currently react. Previously, that path returned failure even though encoded reactor operations remained queued, which made stuff like Flutter GPU Texture.overwrite erroneously fail if used before the first frame on GLES.

The GLES completion callback is now queued behind existing reactor work and fires after the deferred work drains. If a GL context is current and the reaction fails, submission still reports an error.

Adds GLES unit coverage for deferred submit acceptance, callback ordering, later draining by a current submit, and a buffer-to-texture blit submitted before a context is current.

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 labels May 29, 2026
@bdero bdero changed the title [Flutter GPU] Defer GLES command submission until context is current [Impeller] Defer GLES command submission until context is current May 29, 2026
@bdero bdero marked this pull request as ready for review May 29, 2026 07:30
@bdero bdero force-pushed the bdero/gles-queue-parity branch from 9e2eadc to 313a8a7 Compare May 29, 2026 07:30
@github-actions github-actions Bot removed the CICD Run CI/CD label May 29, 2026
@bdero bdero marked this pull request as draft May 29, 2026 07:31
@bdero bdero marked this pull request as ready for review May 29, 2026 07:31

@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 enables GLES command buffer submission when no GL context is current on the thread by deferring the completion callback as an operation in the GLES reactor. It also adds comprehensive unit tests for this deferred submission behavior. Feedback suggests using an RAII guard pattern for the deferred callback to guarantee its invocation and prevent potential resource leaks or thread hangs if the reactor is destroyed before the deferred operations are executed.

@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 updates 'CommandBufferGLES::OnSubmitCommands' to support submitting commands when no OpenGL context is current on the thread by deferring the completion callback via the reactor. It also exposes 'CanReactOnCurrentThread' publicly in 'ReactorGLES' and adds comprehensive unit tests. Feedback points out a potential issue where the deferred callback might never be invoked if the reactor is destroyed or operations are discarded, and suggests wrapping the callback in a helper struct to guarantee execution upon destruction.

Comment thread engine/src/flutter/impeller/renderer/backend/gles/command_buffer_gles.cc Outdated
@bdero bdero force-pushed the bdero/gles-queue-parity branch from 313a8a7 to 19a5a28 Compare May 29, 2026 07:39
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 29, 2026
@bdero bdero marked this pull request as draft May 29, 2026 07:39
@bdero bdero force-pushed the bdero/gles-queue-parity branch from 19a5a28 to 1c886e5 Compare May 29, 2026 11:14
@github-actions github-actions Bot removed the CICD Run CI/CD label May 29, 2026
@bdero bdero marked this pull request as ready for review May 29, 2026 11:16
@bdero bdero added the CICD Run CI/CD label May 29, 2026

@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 enables submitting GLES command buffers even when no OpenGL context is current on the thread, deferring the completion callbacks until a context becomes available. It introduces a DeferredCompletionCallback helper, updates CommandBufferGLES::OnSubmitCommands to queue deferred operations when necessary, and adds comprehensive unit tests. The review feedback suggests using nullptr instead of {} in std::exchange to prevent template deduction issues, and replacing std::atomic_bool with std::atomic<bool> to align with modern C++ standards.

Comment thread engine/src/flutter/impeller/renderer/backend/gles/command_buffer_gles.cc Outdated
@bdero bdero force-pushed the bdero/gles-queue-parity branch from 1c886e5 to 292a38a Compare May 29, 2026 11:19
@github-actions github-actions Bot removed the CICD Run CI/CD label May 29, 2026
@bdero bdero marked this pull request as draft May 29, 2026 11:19
@bdero bdero added the CICD Run CI/CD label May 29, 2026
@bdero bdero force-pushed the bdero/gles-queue-parity branch from 292a38a to 1a71fb7 Compare May 29, 2026 18:33
@github-actions github-actions Bot removed the CICD Run CI/CD label May 29, 2026
@bdero bdero marked this pull request as ready for review May 29, 2026 18:36

@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 updates CommandBufferGLES::OnSubmitCommands to support deferred command buffer submission when the OpenGL context is not current on the active thread, utilizing a new DeferredCompletionCallback helper class. It also adds comprehensive unit tests for these scenarios and exposes CanReactOnCurrentThread publicly in ReactorGLES. The review feedback suggests explicitly deleting the copy and move constructors and assignment operators for DeferredCompletionCallback to prevent accidental duplication or movement of the callback wrapper, in line with the Google C++ Style Guide.

@bdero bdero force-pushed the bdero/gles-queue-parity branch from 1a71fb7 to 133ca3d Compare May 29, 2026 22:16
@bdero bdero requested a review from gaaclarke May 29, 2026 22:18
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 29, 2026

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

Instead of queueing up these operations, can you just make sure this situation doesn't exist? Like creating a gpu context doesn't return until the context is current?

return allowed_.load();
}

void SetAllowed(bool allowed) { allowed_ = allowed; }

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.

Suggested change
void SetAllowed(bool allowed) { allowed_ = allowed; }
void SetAllowed(bool allowed) { allowed_.store(allowed); }

Google's convention is to use load/store functions with atomics.

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.

done

auto gl = std::make_unique<ProcTableGLES>(kMockResolverGLES);
return ContextGLES::Create(Flags{}, std::move(gl),
std::vector<std::shared_ptr<fml::Mapping>>{},
false);

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.

argument comment please

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.

done

auto command_buffer = context_base->CreateCommandBuffer();
ASSERT_TRUE(command_buffer);
auto status = context_base->GetCommandQueue()->Submit(
{command_buffer}, [&](CommandBuffer::Status status) {

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.

no action required: This should have used absl::Status

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.

Acknowledged; leaving this as-is because it follows the existing Submit API.

@bdero bdero changed the title [Impeller] Defer GLES command submission until context is current [Impeller] Fix GLES command submission status before context is current May 30, 2026
@bdero

bdero commented May 30, 2026

Copy link
Copy Markdown
Member Author

Instead of queueing up these operations, can you just make sure this situation doesn't exist? Like creating a gpu context doesn't return until the context is current?

@gaaclarke My bad, the title of this PR was waaaay overstating what this change is doing. GLES reactor operations are already able to be queued before a GL context is current, and this PR just fixes a bug where CommandBufferGLES::OnSubmitCommands incorrectly reports failure in that existing deferred-reactor state. Forcing context creation to wait until a GL context is current would be a broader platform/lifecycle change and would fight the reactor’s existing design, where handles and operations are intentionally able to be created before a worker can react.

@bdero bdero force-pushed the bdero/gles-queue-parity branch from 133ca3d to 9196861 Compare May 30, 2026 00:09
@github-actions github-actions Bot removed the CICD Run CI/CD label May 30, 2026
@bdero bdero added the CICD Run CI/CD label May 30, 2026
@bdero bdero requested a review from gaaclarke May 31, 2026 07:42

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

lgtm, thanks

@bdero bdero added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 2, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jun 2, 2026
Merged via the queue into flutter:master with commit 1365d5b Jun 2, 2026
206 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 2, 2026
@bdero bdero deleted the bdero/gles-queue-parity branch June 2, 2026 07:28
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jun 2, 2026
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
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…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
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
…nt (flutter#187293)

Fixes flutter#187290

This fixes another issue that makes the GLES backend behave quite
differently from Metal/Vulkan.

This makes GLES command submission accept work when no reactor worker
can currently react. Previously, that path returned failure even though
encoded reactor operations remained queued, which made stuff like
Flutter GPU `Texture.overwrite` erroneously fail if used before the
first frame on GLES.

The GLES completion callback is now queued behind existing reactor work
and fires after the deferred work drains. If a GL context is current and
the reaction fails, submission still reports an error.

Adds GLES unit coverage for deferred submit acceptance, callback
ordering, later draining by a current submit, and a buffer-to-texture
blit submitted before a context is current.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flutter GPU] Make GLES command submission before first frame behave like Metal/Vulkan

2 participants