Skip to content

[Impeller] Attach multisampled textures single sampled for GLES readbacks - #195887

Draft
WessimBetclic wants to merge 1 commit into
flutter:masterfrom
WessimBetclic:impeller_gles_readback_single_sampled
Draft

WessimBetclic wants to merge 1 commit into
flutter:masterfrom
WessimBetclic:impeller_gles_readback_single_sampled

Conversation

@WessimBetclic

@WessimBetclic WessimBetclic commented Nov 3, 2026 •

Copy link
Copy Markdown

TL;DR. The problem: on Android phones where Impeller runs on OpenGL ES, reading pixels back from an image (Image.toByteData) can crash the app; it is our top crash across five apps. The regression: #174668 (September 2025) moved the readback off the path that #163345 had made safe, and 3.47 then put most MediaTek phones on OpenGL ES, so it went from rare to constant. The fix: the readback now says it only reads the image, so it is attached the safe way again. Nothing changes for drawing.

Fixes #195319: on Impeller OpenGL ES, Image.toByteData on a Picture.toImage result crashes on Mali and PowerVR phones, either inside the driver or on the FML_CHECK in BlitPassGLES::EncodeCommands. It is our top crash since 3.47 moved MediaTek phones to GLES (#186405): about 7,600 users a week across our five Android apps (Crashlytics, 7 days to 2026-11-03), 30 to 60 percent of all our crashed Android users.

Cause: the readback attaches the snapshot texture with glFramebufferTexture2DMultisampleEXT. With EXT_multisampled_render_to_texture the snapshot texture is multisampled, and ComputeTypeForBinding only attaches such a texture single sampled on GL_READ_FRAMEBUFFER (#163345). #174668 moved the readback to GL_FRAMEBUFFER for GLES 2, which bypassed that.

Fix: SetAsFramebufferAttachment gets a for_reading flag that attaches a multisampled texture single sampled whatever the target. The readback passes it and still binds GL_FRAMEBUFFER.

Test: BlitCommandGLESTest.BlitCopyTextureToBufferCommandGLESReadsMultisampledTextureSingleSampled with the mock GL, fails on master. The mock gains glFramebufferTexture2DMultisampleEXT.

Related: #163345, #174668, #193428

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

…acks

BlitCopyTextureToBufferCommandGLES binds GL_FRAMEBUFFER for glReadPixels
since flutter#174668, so ComputeTypeForBinding no longer attaches a multisampled
texture single sampled as it does for GL_READ_FRAMEBUFFER (flutter#163345). With
EXT_multisampled_render_to_texture the texture Picture.toImage hands to
toByteData is multisampled, and attaching it with
glFramebufferTexture2DMultisampleEXT only to read it crashes some drivers
or fails the framebuffer, which aborts on the blit pass FML_CHECK.

SetAsFramebufferAttachment takes a for_reading flag. The readback passes it
and keeps binding GL_FRAMEBUFFER.

Fixes flutter#195319
@google-cla

google-cla Bot commented Nov 3, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

1 participant