Skip to content

[Impeller] Reuse and resize offscreen RenderTargetCache textures in place on OpenGLES - #194122

Closed
kevmoo wants to merge 3 commits into
flutter:masterfrom
kevmoo:wimp-track-c-rendertarget-inplace-resize
Closed

kevmoo wants to merge 3 commits into
flutter:masterfrom
kevmoo:wimp-track-c-rendertarget-inplace-resize

Conversation

@kevmoo

@kevmoo kevmoo commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Reuses cached offscreen RenderTarget entries across SaveLayer and FilterContents subpasses on OpenGL ES by resizing backing texture and renderbuffer storage in place instead of allocating a new GL texture and framebuffer object (FBO) on every subpass size change.

Rationale

RenderTargetCache::CreateOffscreen and CreateOffscreenMSAA previously required an exact ISize match (other_config == config) to reuse a retained RenderTarget. On animated SaveLayer, BackdropFilter, and ImageFilter workloads where subpass bounds change by 1–2 pixels per frame, every size change missed the cache—allocating a fresh TextureGLES and glGenFramebuffers handle during the frame and destroying the previous set after keep_alive_frame_count_ expiry (346 glCreateTexture and 440 glCreateRenderbuffer calls on a 64-node SaveLayer + ImageFilter.blur workload).

Summary of Changes

Performance & WebGL 2.0 Call Reduction

Workload (1280x720, bouncy_multipass@64 SaveLayer + ImageFilter.blur + ColorFiltered) Pre-Change Post-Change Delta
Steady-state glCreateTexture / glDeleteTexture / frame 346 0 -100%
Steady-state glCreateRenderbuffer / glDeleteRenderbuffer / frame 440 0 -100%
glBindFramebuffer calls / frame 1,747 637 -63.5%
RenderTargetCache::CreateOffscreenMSAA CPU self-time (V8 profile) 109.36 ms 14.49 ms -86.7% (7.55x faster)
Hardware GPU rasterTimeMs (AMD Radeon 780M, wimp_st / wimp_mt) 9.71 ms / 22.24 ms 5.28 ms / 12.19 ms -45.6% (1.84x) / -45.2% (1.83x)

Verification

  • Built and ran host_debug_unopt:impeller_unittests --gtest_filter="*TextureGLESMockTest*:*RenderTargetCache*/*OpenGLES*" locally (17/17 passed).
  • Built wasm_release:skwasm/wimp.js and verified WebGL2 texture/renderbuffer/FBO call counts and rendering parity on [email protected].

Towards #174980
Related to #192147

Pre-launch Checklist

…lace on OpenGLES

- Add `Texture::ResizeStorage(ISize)` virtual hook implemented on `TextureGLES` via `glTexImage2D` in-place reallocation while preserving the GL texture ID and `cached_fbo_`, re-attaching color/depth/stencil attachments via `InitializeContentsIfNecessary()` when an existing cached FBO is live.
- Update `RenderTargetCache::CreateOffscreen` and `CreateOffscreenMSAA` to adopt and grow undersized unused cached `RenderTarget` entries (`entry.size <= target.size`, high-water-mark policy) instead of allocating a fresh texture and FBO per size step.
- Quantize non-backdrop `Canvas::SaveLayer` offscreen bounds up to 32-pixel multiples (`kSubpassSizeQuantum = 32`) when transforming local content bounds on `SaveLayer`.
- Add unit tests in `RenderTargetCacheTest` verifying in-place growth, high-water-mark reuse without shrinking, and multi-target best-fit adoption.
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Oct 10, 2026
@gaaclarke

Copy link
Copy Markdown
Member

This isn't something we're interested in doing. It's actually an antipattern with respect to using opengles and will likely negatively affect android opengles. It's kind of hacking around overhead incurred by emscripten when creating new objects by mutating an existing object. I'd be more interested in a fix that addresses this for all backend.

We've investigated quantizing render targets but it doesn't' play well with how our fragment shaders are authored. It's a nontrivial change.

@gaaclarke gaaclarke closed this Oct 14, 2026
@kevmoo
kevmoo deleted the wimp-track-c-rendertarget-inplace-resize branch October 31, 2026 19:31
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.

2 participants