Skip to content

Fewer stutters from the second start on: what a game needed last time is ready before it starts - #710

Open
davdxpx wants to merge 6 commits into
igawa6:mainfrom
davdxpx:shaderwatch
Open

davdxpx wants to merge 6 commits into
igawa6:mainfrom
davdxpx:shaderwatch

Conversation

@davdxpx

@davdxpx davdxpx commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Every pipeline a game makes while you play is already kept in its prewarm list, and the next start makes the list ahead. On Qualcomm's own driver before 512.800, the AYN Thor's system driver, that has always been off: the driver keeps memory outside the app for each pipeline, so making a game's whole list ahead ran games out of memory. So on that driver every start made the same pipelines again while you played, with objects missing for a moment and hitches each time, and the next start forgot it again.

Smoother next start (a switch per game in the quick menu's Peanuts tab, Experimental, off by default) fixes that from the second start on, for every game. This PR is the part behind the switch; the Peanuts tab itself comes in its own PR.

Goes straight onto main. The first commit, "Peanuts tab: the contract for learning shaders while playing (ShaderWatch)", is the Peanuts tab's contract with this backend: one file, dev.peanuts.shaders.ShaderWatch, which the tab's own PR carries the same way. The commits after it are this PR's own.

What players get

  • The second start is ready before it starts. Peanuts keeps which pipelines this game used in its last runs, on this GPU driver, and the next start makes exactly those first, behind the Preparing shaders screen, before the game shows its first frame. On the Thor's own driver only those are made, never the whole list, and it stops by itself when memory runs short.
  • Fewer objects that pop in, fewer hitches on the routes you played before.
  • Also what a game captures. Pipelines that record transform feedback (Pokémon Legends: Arceus skins its people and Pokémon this way) were in no list at all, because what they capture is only known once the game runs. They are learned too, with what they capture, and made before the next start like the others; the first draw checks that the game still asks for the same capture, else it is made again as before.
  • Kept per game and per driver, small (at most 4,096 entries, 64 KB a game and driver), and it cleans itself: what a game update or a new shader library no longer has is skipped and ages out; what you have not used for 8 starts is dropped.
  • Real numbers in the tab: the pipelines learned this session and how many the next start makes ahead on this driver.
  • Off means off: nothing is read or written, and the game starts as before.

Where it helps (AYN Thor, Pokémon Legends: Z-A)

On a copy of a save, each start the same: load the save, then 60 s standing in Lumiose.

The Thor's own driver (512.676) Switch off On, first start On, second start
Made before the game starts none none 226 pipelines in 0.17 s
Pipelines made on the frame path 15 15 0
Pipelines made in the background while playing 233 223 7
Draws skipped waiting for a pipeline 510 439 23
Frames of 50 ms or more, of them with a new pipeline 6, 2 6, 2 5, 0

The first start with the switch on plays as before and learns; from the second start on, what it used is there before the game shows its first frame. Of the 226, 2 are Z-A's capture pipelines, and the second start drew with the ones made ahead.

On Turnip T30 nothing gets worse: 642 or 643 pipelines made ahead in 0.1 to 0.2 s and no draw skipped, with the switch on or off. The one pipeline still made on the frame path without the switch, Z-A's capture pipeline, is made ahead from the second start on.

Earlier logs without the switch, on the Thor's own driver: Z-A skipped 11,253 draws in 70 s of one start's play; Tomodachi Life 2,300 to 2,700 at each of 8 starts, with a warm pipeline cache.

How it is built

  • dm/gfx/vk_android/vka_pso.c: one PEANUTS begin/end block (sw_*) and marked one-line hooks. A run with learning on (PN_SHADERWATCH=1) notes the list record of every pipeline it makes while the game plays (pw_note) and the first use of every pipeline the prewarm made for it (gfx_obtain, cs_obtain: one field test, no hashing on the frame path). The saver writes them beside the list; the next start orders those records first in the prewarm and waits for them alone.
  • dm/peanuts/peanuts_swhot.h: the file (record hashes and runs since used), its check, the merge with aging and the cap, the order. Free of Vulkan: dm/host/tests/t_peanuts_swhot.c.
  • Transform feedback: pw_note hands a capture variant's pipeline to sw_tf_note (record, key bytes and the capture layout, <list>.<driver>.tf, dm/peanuts/peanuts_swtf.h: at most 64, each with an entry in the .hot file so it ages out with it; dm/host/tests/t_peanuts_swtf.c). The next start's prewarm takes those first (sw_tf_make): vka_tf.c vka_tf_learned makes the variant with the stored layout and the draw's own checks, and a draw's first use checks this run's layout (learned_holds); a mismatch makes it again as before.
  • dev.peanuts.shaders.HostWatch: the backend of the tab's ShaderWatch contract, registered in the game's process (GameActivity.settingsEnv, one line), its numbers from the list (Bridge.shaderWatch), the switch applied live (Bridge.shaderWatchLearn).
  • Docs: docs/reference/rendering.md "Pipelines made again while playing at every start (Android)", PEANUTS.md, peanuts/UPSTREAM-EDITS.md.

Tested

  • peanuts/tests/test_shader_watch.py (with HostCountsJvmTest, t_peanuts_swhot.c and t_peanuts_swtf.c under ASan and UBSan), the prewarm and docs tests, upstream-update.sh --check, check-publish.sh, check-min-api.py on the APK (nothing newer than API 33).
  • AYN Thor, the test app built from this branch, Pokémon Legends: Z-A on a copy of a save: the six starts above, on the Thor's own driver and on Turnip T30. With the switch off no .hot or .tf file is read or written; with it on both are written while the game plays and read by the next start.
  • Not tested here: the Peanuts tab (its own PR), Pokémon Legends: Arceus (not on the test device), a start that runs short of memory.

@davdxpx
davdxpx marked this pull request as ready for review November 25, 2026 11:18
…atch)

The quick menu's coming Peanuts tab shows Smoother next start, marked
experimental: stutters counted from the frame times the tab reads anyway, and
shaders learned during play so the next start prepares them. This class is the
contract between the tab and the backend that records the host's run-time
shader builds; until a backend registers, the feature says it is not active.
… again

The host learns every pipeline a run makes (the prewarm list), but on Qualcomm's driver before 512.800, the AYN Thor's own, the list is never made ahead:
each pipeline holds memory outside the process there, so every start made its pipelines again while the game played and skipped their draws meanwhile.
With Learn shaders while playing on for a game (the Peanuts tab, PN_SHADERWATCH=1), each run keeps the list's records it used, per game and driver
(dm/peanuts/peanuts_swhot.h: hashes and the runs since each was used, at most 4,096, 64 KB), and the next start makes those first and before the game
starts, behind Preparing shaders; where the driver does not prewarm, only those, by two threads that stop when memory is short. Records a game update or
another shader library no longer has match nothing and age out. Off, nothing of it is read or written.

dev.peanuts.shaders.HostWatch is the ShaderWatch backend, registered at the game's start: its numbers are the list's (vka_pso_watch through
Bridge.shaderWatch), and the switch turned while the game runs applies at once (Bridge.shaderWatchLearn).

Tests: peanuts/tests/test_shader_watch.py, HostCountsJvmTest, dm/host/tests/t_peanuts_swhot.c (make peanuts-swhot).
…edits

docs/reference/rendering.md "Pipelines made again while playing at every start (Android)" with its symptom line, the Found on lines of Pokémon Legends: Z-A
and Tomodachi Life: Living the Dream, the hook sites in PEANUTS.md and the section in peanuts/UPSTREAM-EDITS.md.
…in words

The class comment of dev.peanuts.shaders.ShaderWatch named a page and a board of the design canvas, which readers of the repository cannot see
(test_no_canvas_pointers). It now says what it means: a switch per game in the quick menu's Peanuts tab.
… and made ahead too

The prewarm list never holds a capture pipeline: it draws with its vertex shader's capture variant (vka_tf.c), whose modules carry the layout the game's
program declares at nvnProgramSetShaders, and a start that makes pipelines before the game has no layout noted yet. So every start made them again while
the game played. With learning on, pw_note hands such a pipeline to sw_tf_note, which keeps its record (the variant's base vertex shader), key bytes and
layout in a file of the game and driver beside the .hot file (<list>.<driver>.tf, dm/peanuts/peanuts_swtf.h: at most 64 entries, each with an entry in the
.hot file, so it ages out with it). The next start makes those first, before the list's records, and waits for them with the others: vka_tf_learned makes the
variant with the stored layout and the same checks as a draw's, then sw_tf_make asks for its pipeline as the frame path will. A draw's first use of such a
variant checks that this run's program declares the same layout; else the variant is dead and the draw makes its own as before. Entries whose shaders are
gone, of the other vertex input form, or on a device without transform feedback are skipped and age out. Off, pw_note returns at a capture variant as before
and nothing is read or written. vka_tf.c's variants are appended under its lock (a prewarm thread adds them now too), caps() runs once.
…nd the startup line counts what the start waits for
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