Stop position-only animations from invalidating the texture caches

ChromePassElement::draw() rounded its device-space box with CBox::round(),
which derives the size from the two rounded corners - round(x + w) -
round(x) - making the rounded width and height a function of the
*position's* fractional part. A box merely sliding at a constant size
therefore has its size flip by a pixel every few frames.

Every one of those flips misses the cachedTexSize check in
GetBorderTexture, GetShadowTexture and GetTitleTexture alike, and each
miss is a full cairo re-render plus a fresh GPU texture allocation and
upload for content that did not change appearance at all. That is exactly
what a workspace switch, a window move, or any other position-only
animation does - every frame, for every window on screen - and it is why
those animations stutter. Measured against hyprutils, a sliding window
resized nothing yet rebuilt its textures on 18-40% of frames at scale
1.0/1.25/1.5/1.6 (integer scales happened to be stable); rounding the
size on its own takes all of those to zero.

What round()'s coupling buys is a far edge landing on the same device
pixel as an adjacent box's near edge. Nothing abuts this box - it is a
free-floating decoration drawn over everything - so there is no seam here
to keep closed.

damageEntire() gains a one-pixel margin to match: with position and size
now rounded separately, the drawn box's far edge can land up to a device
pixel past where the logical damage box scales to.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-02 14:16:26 +02:00
co-authored by Claude Opus 5
parent 7c6d98b0ba
commit 74ec7c89f0
2 changed files with 26 additions and 2 deletions
+6 -1
View File
@@ -460,7 +460,12 @@ void ChromeDecoration::damageEntire() {
// The shadow hangs outside the decoration's own box (it's drawn, not // The shadow hangs outside the decoration's own box (it's drawn, not
// reserved - see ShadowMarginLogical), so damaging just that box would // reserved - see ShadowMarginLogical), so damaging just that box would
// leave its outer reaches stale. // leave its outer reaches stale.
g_pHyprRenderer->damageBox(FullDecorationExtentGlobal().expand(ShadowMarginLogical())); //
// The extra pixel covers the gap ChromePassElement::draw()'s rounding can
// open: it rounds the device-space position and size separately, so the
// box's far edge can land up to a device pixel past where this logical box
// scales to. One logical px is at least that much on any scale >= 1.
g_pHyprRenderer->damageBox(FullDecorationExtentGlobal().expand(ShadowMarginLogical() + 1.0));
} }
double ChromeDecoration::ShadowMarginLogical() { double ChromeDecoration::ShadowMarginLogical() {
+20 -1
View File
@@ -21,7 +21,26 @@ std::vector<UP<IPassElement>> ChromePassElement::draw() {
return {}; return {};
auto box = data.decoration->FullDecorationExtentGlobal(); auto box = data.decoration->FullDecorationExtentGlobal();
box.translate(-monitor->m_position).scale(monitor->m_scale).round(); box.translate(-monitor->m_position).scale(monitor->m_scale);
// Round the position and the size independently, rather than via
// CBox::round(). That derives the size from the two *rounded corners*
// (round(x + w) - round(x)), which makes it a function of the position's
// fractional part - so a box that is merely sliding, at a perfectly
// constant size, has its rounded w/h flip by a pixel every few frames.
// Every one of those flips misses the caches in GetBorderTexture /
// GetShadowTexture / GetTitleTexture, each miss being a full cairo
// re-render plus a GPU re-upload of a texture that didn't actually change
// appearance - which is precisely what a workspace switch, a window move,
// or any other position-only animation does, every frame, for every window
// on screen. Rounded on its own, the size stays a pure function of the
// window's own size and can't be perturbed by translation at all.
//
// What round()'s coupling buys is a far edge that lands on the same device
// pixel as an adjacent box's near edge. Nothing abuts this box - it's a
// free-floating decoration drawn over everything - so there is no seam here
// to keep closed.
box = CBox{box.pos().round(), box.size().round()};
if (box.w < 1 || box.h < 1) if (box.w < 1 || box.h < 1)
return {}; return {};