Compare commits

...
Author SHA1 Message Date
maxjivi05 4d0d2957bc fix(mesa): drop the patch comment and keep the description generic 2026-11-30 13:31:38 -05:00
Kurt Himebauch 3e49eac7e1 Merge remote-tracking branch 'origin/main' into HEAD 2026-11-29 16:22:18 -05:00
LarzVader 078664947f fix(mesa): renumber the Zink slab patch after 0006 landed on main 2026-11-29 14:15:31 +01:00
LarzVader b8b99168d3 Merge remote-tracking branch 'origin/main' into fix/zink-slab-reclaim 2026-11-29 14:15:31 +01:00
LarzVader 1ffacb6698 fix(mesa): Zink no longer leaks 2 MB of GPU memory every few frames until Android kills the session
Add a Mesa patch that clears the batch usage of freed Zink slab entries.
Stale usage kept entries out of slab reclaim for good, so every small
buffer got a fresh 2 MB slab. Upstream fixed this in Mesa 26.2
(fa867cf18); the patch is a minimal alternative for 26.0.8.
2026-11-24 21:22:30 +01:00
@@ -0,0 +1,42 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Subject: [PATCH] zink: clear batch usage of freed slab entries
bo_destroy_or_cache() drops a real BO's batch usage before the BO goes into
the cache, but bo_slab_destroy() hands slab entries to pb_slab_free() with
their reads/writes usage still set. Zink only frees a BO once no batch holds a
reference any more, so whatever usage is left at that point is stale: it
points at a batch state the BO is no longer tracked by.
A stale pointer can name a batch state that is never submitted again, for
example the recording batch of a context that was destroyed (its unflushed
flag stays set while it waits in the screen's free list) or of a context that
another thread keeps current without ever flushing. bo_can_reclaim() then
returns false for that entry forever. pb_slabs_reclaim_locked() walks the
reclaim list from the oldest entry and stops after MAX_FAILED_RECLAIMS (2)
failures, so two such entries at the head stop all slab reclaim for the
screen: every later small buffer gets a fresh 2 MB slab and nothing is ever
freed.
WineD3D through Proton 11 with Zink on Venus can hit this
as soon as it enters the 3D world: about 0.2 new slabs per frame,
gigabytes of GPU memory after a few minutes, until Android kills the
session. Clear the usage the same way bo_destroy_or_cache() does.
Upstream fixed the same ballooning in Mesa 26.2 with commit fa867cf18
("zink/bo: check for usage before completion when reclaiming bos",
MR !41936), which relies on the per-BO submit_count tracking added in
26.1 and does not apply to 26.0. This is a minimal alternative for the
26.0 series; drop it once DroidDeck moves to Mesa >= 26.2.
---
diff --git a/src/gallium/drivers/zink/zink_bo.c b/src/gallium/drivers/zink/zink_bo.c
--- a/src/gallium/drivers/zink/zink_bo.c
+++ b/src/gallium/drivers/zink/zink_bo.c
@@ -185,6 +185,8 @@
struct zink_bo *bo = zink_bo(pbuf);
assert(!bo->mem);
+ bo->reads.u = NULL;
+ bo->writes.u = NULL;
//if (bo->base.usage & RADEON_FLAG_ENCRYPTED)
//pb_slab_free(get_slabs(screen, bo->base.size, RADEON_FLAG_ENCRYPTED), &bo->u.slab.entry);