Keep the driver's cache of stage libraries warm, link a missing pipeline instead of skipping its draw, and count the texture cache's waits in time.

The preparation builds every stage library once so the driver's disk cache holds it and a library a draw needs later takes under a millisecond. Turning dynamic vertex input off for AMD's RDNA 3 and newer driver changed the dynamic states every library lists, which gave each one another entry in the driver's cache, and nothing built them again: an update carried the prepared shaders over without the driver step. On an RX 7900 XT (26.10.1) all 42,142 prepared libraries were cold, 93 ms a vertex and 242 ms a fragment library on average. With no pipeline recorded, a walk through a village skipped 11,180 draws while their pipelines built and made 94 draws wait 5.5 s in all, four of them 1.0 to 2.0 s; a player's session log shows up to 114,834 draws skipped in 600 frames and 181 waits of 251 ms on average. Skipped ground and walls appear and disappear, and a skipped lighting pass is a black frame with the interface intact.

- The game checks the driver's cache at every start (vk_pipeline.c lw_start): a sample of the prepared fragment libraries is built, and when their median time says the cache is cold the whole prepared list is built into it again on idle-priority threads while the game runs. shader-warm.txt records a warm in progress, so the next start goes on with one a run ended, and stops the tries on a driver that does not keep the libraries. This also covers a driver update and a cache the driver emptied.
- An update that carries the prepared shaders over runs the game's --warm-shaders (tools/make_game.py warm_driver_cache): 11 s with the libraries there, about 8 minutes with all of them cold on that card.
- A draw whose pipeline is missing waits for its fast link from a budget of 6 ms a presented frame, 3 ms at most each (NX2NAVI_PIPE_LINK_MS), before it is skipped: with warm libraries the link is done within that.
- Full-screen draws wait from their 50 ms budget again instead of being skipped (NX2NAVI_PIPE_SKIP = any is the default; fullscreen stays selectable). With warm libraries the wait is a millisecond.

The same walk afterwards: libraries 0.3 and 0.7 ms on average, 1,605 draws skipped, 1,473 of them in the scene's first 600 frames and 8 to 80 in each 600 after, and 19 waits of 60 ms in all. First visits to four other saves (a mountain pass, the Lost Woods, Kokiri Forest, a river) waited 12 to 84 ms in all except the Lost Woods, where mesh shader pipelines, which have no stage libraries, and vertex libraries that need added outputs still compiled once: 23 waits, 2.1 s in all, the longest 776 ms.

The texture cache counted its waits in presents chosen at 60 a second: at 165 presents a second the 1800 that stood for thirty seconds were 11 s, so a released render target went sooner than meant and a texture out of view for 11 s was retired and showed its stand-in for some frames when it came back. The counts are now taken times the present rate over 60 (presents_for), and a texture is retired after two minutes without a sample instead of thirty seconds.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
epicmeme546
2026-11-10 01:36:29 -05:00
parent 8d91667c28
commit e10ef60fd5
9 changed files with 381 additions and 44 deletions

View File

@@ -1425,6 +1425,36 @@ class MakeGameTest(Tmp):
self.assertIn('stay in use', buf.getvalue())
self.assertIn('shader cache packed', buf.getvalue())
def test_carried_update_warms_the_drivers_cache(self):
"""An update that carries the shaders over runs the game's --warm-shaders, in the game folder; a run that
fails is said and does not stop the build, and without a built game or a preparation nothing runs."""
calls = []
for name, value in (('shader_carry', lambda out: True),
('shader_run', lambda cmd, cwd=None: calls.append((cmd, cwd)) or self.rc)):
self.addCleanup(setattr, self.mg, name, getattr(self.mg, name))
setattr(self.mg, name, value)
self.rc = 0
self.out.mkdir(parents=True, exist_ok=True)
with contextlib.redirect_stdout(io.StringIO()):
self.mg.step_shaders(self.out, update=True)
self.assertEqual(calls, []) # no exe, no prepared list
(self.out / self.mg.EXE_NAME).write_bytes(b'MZ')
with contextlib.redirect_stdout(io.StringIO()):
self.mg.step_shaders(self.out, update=True)
self.assertEqual(calls, []) # never prepared: nothing to build again
(self.out / 'shader-prepared.bin').write_bytes(bytes(16))
buf = io.StringIO()
with contextlib.redirect_stdout(buf):
self.mg.step_shaders(self.out, update=True)
self.assertEqual(calls, [([str(self.out / self.mg.EXE_NAME), '--warm-shaders'], str(self.out))])
self.assertIn("driver's cache warm", buf.getvalue())
self.rc = 3
buf = io.StringIO()
with contextlib.redirect_stdout(buf):
self.mg.step_shaders(self.out, update=True) # no exception: the game warms it itself
self.assertIn('did not finish (3)', buf.getvalue())
self.assertEqual(len(calls), 2)
def test_romfs_failure_stops_the_build(self):
ran, lifting, failed = [], threading.Event(), threading.Event()