Skip to content

Fix WebGL texture atlas background cache churn on per-cell background colors - #6075

Open
s-celles wants to merge 2 commits into
xtermjs:masterfrom
s-celles:fix/webgl-atlas-bg-cache
Open

Fix WebGL texture atlas background cache churn on per-cell background colors#6075
s-celles wants to merge 2 commits into
xtermjs:masterfrom
s-celles:fix/webgl-atlas-bg-cache

Conversation

@s-celles

Copy link
Copy Markdown

Fixes #6074.

Problem

The WebGL glyph atlas is keyed on the full bg value, colour bits included
(cacheMap.get(key, bg, fg, ext)). But _drawToCache only reads the
background colour in three cases — _getBackgroundColor (unless
allowTransparency), _getMinimumContrastColor (unless minimumContrastRatio
is 1), and the inverse swap. When none apply, every background colour rasterizes
a pixel-identical tile, yet each gets its own atlas entry. Content that varies
the background per cell (animated backgrounds, heatmaps, diffs, ANSI art) then
misses on every cell of every frame and grows the never-evicted atlas without
bound.

Fix

Introduce a cacheKeyBg that drops the background colour bits when they cannot
change the tile, keeping the BgFlags that do (ITALIC, DIM, OVERLINE).
INVERSE (read from fg) stays in the key, since the inverse swap depends on
the colour. Same glyph over different background colours now reuses one atlas
entry.

Testing

  • CharAtlasUtils.test.ts — unit coverage for cacheKeyBg (colour dropped;
    rasterizing flags and the transparency / contrast / inverse exceptions kept).
  • WebglAtlasBackgroundChurn.test.ts — regression test that a per-cell
    background-colour sweep no longer multiplies atlas entries.

Assisted-by: AI

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.

WebGL: glyph atlas grows unbounded when the background color varies per cell (animated backgrounds, heatmaps, diffs)

1 participant