Skip to content

fix(2d): free GPU resources a canvas has stopped using (GL, Metal, Vulkan) - #193

Merged
triniwiz merged 2 commits into
masterfrom
fix/android-gl-gpu-trim
Nov 8, 2026
Merged

triniwiz merged 2 commits into
masterfrom
fix/android-gl-gpu-trim

Conversation

@triniwiz

@triniwiz triniwiz commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Skia's GPU resource cache was never trimmed on the GL, Metal and Vulkan paths. Everything a canvas had drawn stayed in GPU memory, up to Skia's 256 MB default.

After each flush (at most once a second per canvas), these canvases now free resources unused for 5 s, as the D3D path already does. Anything drawn every frame stays cached, so steady rendering pays nothing. A resource that comes back after more than 5 s unused is uploaded again. D3D canvases keep their own trim in present_d3d.

Verified

GL, on an Android emulator, with a temporary log of resource_cache_usage() (not part of this PR): sprites drawn from two sheets, then from one. The unused 8 MB sheet left the cache about 6 s after its last draw, and the sheet still in use stayed.

The emulator's process stats show no GPU memory, so the effect was checked through Skia's counter rather than dumpsys meminfo.

Not tested

  • Metal: no iOS build here.
  • Vulkan: Android only gives a 2D canvas a Vulkan context when the device reports a Vulkan major version above 1, so the emulator stays on GL.

Both reach the same code after their flushes.

Skia's GPU resource cache on the GL path was never trimmed, so everything a canvas had ever
drawn stayed in GPU memory up to Skia's 256 MB default. After each flush (at most once a
second per canvas) the GL path now frees resources unused for 5 s, as the D3D path already
does; Chrome trims the same way. Anything drawn every frame stays cached, so steady
rendering pays nothing.

In apps/demo-leak (8192 sprites from two sheets, then only one), the unused 8 MB sheet left
the cache about 7 s after its last draw while the sheet still in use stayed.
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6266523c-e429-4645-ac28-9eb356d26f03

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

The 5 s trim moves from the GL surface to Context, so it runs after the flushes of GL, Metal and
Vulkan canvases alike. D3D canvases keep their own (present_d3d).

On an Android emulator (GL), an unused 8 MB sheet left the cache about 6 s after its last draw,
as before. Metal and Vulkan are not exercised here: no iOS build, and Android only gives 2D a
Vulkan context for Vulkan versions above 1.
@triniwiz triniwiz changed the title fix(2d): free GPU resources a GL canvas has stopped using fix(2d): free GPU resources a canvas has stopped using (GL, Metal, Vulkan) Nov 8, 2026
@triniwiz
triniwiz merged commit 9ed0d0a into master Nov 8, 2026
22 of 25 checks passed
@triniwiz
triniwiz deleted the fix/android-gl-gpu-trim branch November 8, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant