fix(vk): a finalized render target goes once the game has written over its storage #1462

Merged
HumanBean merged 2 commits from mooki/Longshot:fix/finalized-target-obsolete into main 2026-11-17 21:22:16 +00:00
Member

Type: fix · Risk: medium · Tested on: Linux, RTX 4090 (a 6 GB card's allowance by switch); game-free checks · Needs: Windows, any GPU; an 8 GB card; a long walk over Hyrule Field

TL;DR

In long sessions the game's video memory slowly fills up until it stutters or closes (#1443). The cause: small terrain tiles the renderer keeps after the game has already reused their memory, so they are never let go. This PR lets those stale tiles go. Walking the same route on a simulated 6 GB card, main climbs from 129 to 166 to 221 render images; with this PR it stays at 128, 131, 129. One rule in the texture eviction pass and one new test; nothing that is still in use is touched.

Breakdown

  • Who it helps: anyone playing for a long time, most of all on cards with 8 GB or less, where video memory runs out first.
  • What was wrong: the renderer keeps a finished terrain tile "in case it is drawn again". When the game later writes something else into that tile's memory, the tile is useless, but nothing ever removed it while the game was under its memory budget.
  • What changes: a finished tile of 32 KB or more whose memory the game has mostly (three quarters) rewritten is let go, whatever the budget says. Partly rewritten or small ones stay.
  • What does not change: everything still in use; the cache limit for kept tiles; the other cleanup passes (#1255); #943's case.
  • How it was checked: a test built from the renderer's own code (main keeps all 1,800 tiles over 30 laps, this PR 120); the whole test suite (same failures as main); the Windows compile check; and walking laps in the game on this PR's exact build next to main, with pictures of the walk looked at for missing or striped ground.
  • What is still open: Windows, AMD and real small cards; hours-long sessions; whether "three quarters" is the right line; a closer look for ground streaks on a long walk.
  • Risk: medium. If the game still needed a partly rewritten tile, the ground could show streaks; the three-quarters rule is there to avoid that, and none were seen in the pictures.

Why

In a long session the game's video memory keeps growing until it slows down, runs out, or closes (#1443 collects the reports). Players' logs show the render-target images climbing by about 200 an hour while walking, and about 84 % of them (median over 151 logs) are small terrain tiles the renderer keeps after the game has finished with them. The renderer does not lose them; it never lets them go: inside the texture budget it retires a render target only when another target was drawn over it, and a tile whose slot the game later reuses with CPU writes is never drawn over.

Refs #1443.

How to reproduce

Seen on: Linux, Arch, RTX 4090, NVIDIA 615.78.08 (a 6 GB card's allowance set by RX_VK_TEST_ALLOWED_MB=5200)
Settings and switches: defaults, plus RX_VK_TEST_ALLOWED_MB=5200
Steps: load a save in Kokiri Forest, then three or more laps of: teleport to Hyrule Field, walk about 200 m over open ground for 6000 presents along a planned route, teleport back; read the "image blocks (render targets)" line every 600 presents
Expected: the render-target images stay flat from lap to lap
Actual: on main they climb every lap: 129, 166, 221 images at the ends of the first three marks (arrival, lap 1, lap 2); other runs on main with a diagnostic build: 171, 237, 209, 297 at the default allowance

What changed

A finalized render target whose storage the game has written over since it finalized it goes, within the budget as over it. The terrain tiles (260 x 260 RG8, nine levels) are drawn once, written back into memory, finalized, and the game later reuses their slots; the image of each stayed for good.

  • vk: finalized_obsolete() in gpu/vk/vk_texture.cpp: a texture the GPU drew and the game finalized, in a pool's own memory, of 32 KB or more, with three quarters of its storage written by the CPU since it was finalized (memory_written_runs from its release_gen). texture_frame's pass lets such a texture go whatever the budget says: the sweep (if (sweep && !overwritten) continue;) no longer keeps it, keep_finalized no longer counts it, and the compaction's hold treats it as it treats a drawn-over target. Nothing is written back (its texels are gone from that memory on the console too).
  • tests: tests/test_target_retention.py and .cpp cut that pass and finalized_obsolete out of vk_texture.cpp and run 30 laps of 60 tile-sized targets; tests/test_vram_compact.py follows the changed hold_live line.

Unchanged: the cap on kept finalized textures (RX_VK_KEEP_FINALIZED_MB, 128 MB: it is still applied over the budget only and still counts texels, not the allocator's padding), the dead-target sweep (#1255), the target pool. #943's summed overlap is a different class (single-level targets) and is not touched.

Measurements

Verdict: on this head the render-target images stay flat across the two walking laps that ended (128, 131, 129) while main's climb (129, 166, 221); the finalized tiles the renderer keeps are 60 and 41 against 93 and 131. Only lap 1 is a clean comparison (131 against 166 images, 60 against 93 kept): in lap 2 of both runs a Deku Baba killed Link in Hyrule Field (the pictures show Game Over; the game restarts him at the arrival point). It is two laps of one route, not hours of walking, so it shows the direction, not the size, of the field's growth.

Hardware: Linux, RTX 4090, NVIDIA 615.78.08, i9-13900K, 96 GB; other games on the card (ordinary run, not a timing measurement)
Scene: Kokiri Forest and Hyrule Field (child), DLAA 2048x1152, 6 GB allowance by switch
Method: the lap script (LapleakDriver), 3 laps, longshot_log.txt lines every 600 presents; the diagnostic that counted the kinds and owners (RX_VK_LOG_TARGETS) is not in this PR
How to reproduce: as above

At the end of Before: main @ 645d58e68 After: this PR @ 1c09f9d12
mark 0 (arrival, about 20 m walked) 129 images 128 images
lap 1 (about 200 m walked) 166 images 131 images
lap 2 (about 200 m, Link killed) 221 images 129 images
finalized kept for being made again, n (MB), marks 0, 1, 2 3 (0), 93 (21), 131 (20) 3 (0), 60 (15), 41 (5)
render-target blocks and images at the last 600-present line 25 blocks 800 MB, 225 images 315 MB, 100 free ranges 22 blocks 704 MB, 133 images 276 MB, 63 free ranges
VRAM used by the game (MB, from the log) marks 0, 1, 2 4778, 5138, 4752 4586, 4658, 4762
process RSS (MB) marks 0, 1, 2 10241, 12094, 12212 10220, 12316, 6438 (the restart after Game Over)
run health exit 0, fatal 0, crash 0, device lost 0, kernel Xid/NVRM lines 0 the same

Supporting runs with the diagnostic (not this exact head: the diagnostic build plus the same single rule, 50eaceee8, against the diagnostic build on main; 24 GB card, no allowance switch, a longer route in open Hyrule Field): main's images 171, 237, 209, 297 and finalized tiles unused 600+ presents 1, 50, 79, 105; with the rule 101, 120, 131 and 0, 19, 14, of which written over by the CPU 1, 1, 1. At the 6 GB allowance on main with the diagnostic: 144, 152, 198, 240 images, tiles 1, 22, 77, 93, of which written over 1, 18, 44, 70.

vk: image blocks (render targets): 25 blocks 800 MB, 225 images 315 MB; 100 free ranges, the largest 30 MB      (main, last line of lap 2)
vk: finalized textures the GPU drew once, kept for being made again: 132 (20812 KB): ...                         (main)
vk: image blocks (render targets): 22 blocks 704 MB, 133 images 276 MB; 63 free ranges, the largest 26 MB        (this PR, last line of lap 2)
vk: finalized textures the GPU drew once, kept for being made again: 41 (4800 KB): ...                           (this PR)
run summary, this PR: exit=0 wall=371.3s frames=22373(headless-renderer) fatal=0 crash=0 devlost=0 kernel=0 nvrm=0
run summary, main:    exit=0 wall=375.7s frames=22289(headless-renderer) fatal=0 crash=0 devlost=0 kernel=0 nvrm=0

On main, with the diagnostic: 0 orphans in 95 samples (every image in the render-target blocks owned by a live texture, the dead list or the pool); at lap ends the finalized 260 x 260 tiles unused 600+ presents were 1, 22, 77, 93 of which 1, 18, 44, 70 had their storage written over by the CPU.

Fixture: tests/test_target_retention.py, main @ 645d58e68: storage written over two laps on, within the budget 1800 of 1800 tiles alive after 30 laps, over the budget 744 of 1800 (the keep cap), and the three-quarters case fails; this PR: 120 of 1800 in both, the quarter, half and 16 KB cases keep all.

Pictures of the walk

this PR @ 1c09f9d12, 13 frames of the walk, one every 20 s (the arrival at Hyrule Field's forest exit, the road and grass, a cliff path, a tree, two Game Over screens after the Deku Baba): the ground, rock faces and the castle in the distance draw normally; no streaks, black patches or missing tiles at this size
main @ 645d58e68, the same walk: the same scenes draw alike (a Deku Baba close in one frame and one Game Over screen)

Flags and settings

None.

How it was tested

Everything here was run by an AI agent (Claude Sonnet 5.5) working for me; commands are given so anyone can rerun them. The game run described in section 3 is one run of this head and one of main, the same afternoon; its files are named below.

1. What was looked for, and how the cause was found

  1. Reading. Every place in gpu/vk where a render target's image can be made, replaced, destroyed, pooled or erased (create(), destroy_later, the dead list drain in texture_frame, pool_put/pool_take/pool_trim, the compaction's image swap, the upscalers' and frame generation's images) was read at main 50170f819 (later 645d58e68, which did not touch these files). No path loses an image.
  2. Existing logs. Every longshot_log.txt and hookshot_log.txt attached to the issues of this tracker that had 20 or more samples of "image blocks (render targets)" was downloaded (151 logs from 393 files, v3.0.0-rc.3 to nightlies) and read by a small Python script (regular expressions over four log lines every 600 presents: "image blocks (render targets): N blocks .. MB, M images .. MB", "render target images: .. made new, .. destroyed from it; it holds ..", "VRAM: .. textures .. MB (budget .. MB)", "finalized textures the GPU drew once, kept for being made again: N (KB)"). Check 1: images == made new - destroyed in every sample (92 % of 14,447 samples exact). Check 2: kept count against image count at the end of each log (median 0.84).
  3. A diagnostic, not part of this PR. A logging switch (RX_VK_LOG_TARGETS=<presents>) was added on a separate branch. Every N presents it matches every image in the render-target blocks (VMA's pool statistics) with its owner (a live Texture, the dead list, the target pool), counts the live render-target textures by kind (never written, live, finalized, one level or many) and by presents unused, and counts how many finalized ones have had their storage written by the CPU since the game finalized them (memory_written_runs from the texture's release_gen). It was run on main in the game (section 3) and showed: 0 orphans in 95 samples, and the unused finalized tiles' storage written over by the CPU (17/17, 36/37, 38/38 in the older buckets; in the walking run 70 of 93).

2. Game-free checks (anyone can rerun)

  • Environment: the same machine as below, no GPU used. The fixture is plain C++ compiled by the Python test.
  • python -I -B tests/test_target_retention.py (the pinned build Python; --cxx g++ is the default). It cuts, by their text, texture_frame's choice of which textures go (from order to the end of its loop) and the new finalized_obsolete() out of gpu/vk/vk_texture.cpp (tests/srccut.py), compiles them into tests/test_target_retention.cpp with stand-ins for the Texture fields they read, and runs 30 laps of 60 render targets the size of the terrain tiles (260 x 260 RG8, nine levels, 176 KB of texels, 325 KB as the allocator gives it: the numbers come from the diagnostic's lines). Each lap's targets are drawn once, finalized, never used again, and no later target is drawn over them; the game writes over a lap's storage two laps on (all of it, a quarter, half, three quarters; a 16 KB texture as well). Pass: the tiles whose storage was written over (three quarters or more, 32 KB or more) are gone and the others stay.
  • Result on main 645d58e68 with the test copied in: within the budget 1800 of 1800 tiles alive after 30 laps, over the budget 744 of 1800 (the keep cap), the three-quarters case fails. On this PR's head: 120 of 1800 in both cases; a quarter, half and the 16 KB texture keep all.
  • Whole suite: python -I -B tests/run_all.py --jobs 6 --strict through the workbench's idle-class gate (https://github.com/mooki000/ls-workbench: the idle wrapper, three slots, core dumps off, a fresh HOME), once on this head and once on main 645d58e68, outputs compared by test name. 669 passed / 38 failed / 17 skipped here, 668 / 38 / 17 on main; the same 38 names fail on both (listed in the checklist).
  • Windows-target syntax: the workbench's Windows fixture check (https://github.com/mooki000/ls-workbench/tree/main/skills/ls-pr-evidence/scripts, with llvm-mingw 20261104 ucrt-x86_64) compiles the new C++ fixture for the Windows target: PASS, 2 translation units, 0 failures, 0 unjudged. Windows execution was not run.

3. In the game (Linux, headless)

  • Machine: Arch Linux, kernel 7.2.15, i9-13900K, 96 GB RAM, RTX 4090 with NVIDIA 615.78.08, one monitor not used (HOS_HEADLESS: frames render to an offscreen image, no window). The machine runs other games and builds at the same time: the load average was 50 to 95 during the runs, so every frame time is an ordinary-run diagnostic and no speed claim is made; the memory and image counts are not affected by load.
  • Build: main 645d58e68 and this head 1c09f9d12 built the same way for the game: a native Linux build with the workbench's build wrapper through the build gate, release profile (RX_RELEASE=1, the shipped profile data), no diagnostic code, over a finished donor build of main 36de9b0ce whose 42 lifted-code inputs and 517 HLE names were checked identical (the changes are renderer-only). This head: 123 s, 418 objects new and 100 from the cache, source stamp d08d307d; main 645d58e68: 87 s, source stamp 35eea065; both exit 0. (The build receipts stay on my PC: they hold local paths.)
  • Save and scene: a save in Kokiri Forest (child) made with the workbench's save tool, played from a disposable copy for every run. Settings: defaults (DLAA at 2048 x 1152, 60 fps cap) plus RX_VK_TEST_ALLOWED_MB=5200, which makes the renderer see a driver allowance of 5200 MB, so the 24 GB card plays the budget and pressure paths of a 6 GB card (see gpu/vk/vram_compact.h, gpu/vk/texture_budget.h).
  • How the game was driven: the control bridge (docs/control.md in this repository: https://git.magicbean.dev/MagicBeanDev/Longshot/src/branch/main/docs/control.md) on a private socket, by a lap script (the workbench's scripted-play drivers, hsap, https://github.com/mooki000/ls-workbench). A lap: debug teleport to Hyrule Field (child), a planned route of open-ground walking (a stick held toward the next waypoint, the pad's analog axes through the bridge, 6000 presents a lap), debug teleport back to Kokiri Forest, wait. The script marks each lap's start and end in a CSV with the present count. The plan asked for 3 laps of the walking leg (6000 presents, about 100 s) and a 300-present leg back in Kokiri Forest; the run's time budget stopped it after two completed laps, so each run has the arrival mark and two laps. One run per build, the head first and main 7 minutes later, same save, same plan, same settings. A planned route over open ground (waypoints chosen from the workbench's local world notes, not shipped) is followed by the script holding the stick toward the next waypoint and checking the position the bridge reports.
  • What was sampled: the game's own log every 600 presents ("image blocks (render targets)", "render target images", "VRAM", "textures"), and the lap script every 5 s: process RSS and anonymous memory from /proc, the card's memory from nvidia-smi, and the game's frame log. A picture of the game's frame every 20 s of walking through the bridge's shot (1280 x 720). At each lap end the table takes the last value of each log line seen before the lap's end mark.
  • Pass: render-target images at the lap ends flat on the head (no rise from one mark to the next beyond the spread seen between the head's own marks) while main's climb; no empty or striped ground in the pictures (I looked at them at contact-sheet size; a closer look by a person is under Must be tested).
  • Kernel and driver check: the workbench's run wrapper read the kernel journal for each run (Xid, kmemsysDoCacheOp, any NVRM line): 0 for both runs, journal coverage complete; a game exit code 0, no crash, no device lost, no core dump.
  • Rerun: the lap script is attached as text to the comment (leak-fix-pr-lapleak.py.txt, 776 lines, standard library only: it starts the game through the workbench's run wrapper with a save and switches, drives it through the bridge, writes marks.csv with the present count at each lap mark and samples.csv every 5 s, and takes the bridge's pictures). Its way of use: the workbench's scripted-play skill. Each run's own files (laps.md, samples.csv, memlines.log with every game log line of the run, the pictures) are named in the comment.

4. What was not tested

See "Not tested" under Testing: hours of walking, Windows, AMD, 8 GB cards, any speed claim, and the process-memory (RAM) creep of the 2-hour co-op soak.

Testing

Tested: tests/test_target_retention.py (red on main, green here); the whole suite by name against main (python -I -B tests/run_all.py --jobs 6 --strict: this PR @ 1c09f9d12 669 passed, 38 failed, 17 skipped; main @ 645d58e68 668 passed, 38 failed, 17 skipped; the failing set is the same 38 names on both, none of them touches the render targets' eviction); the Windows-target syntax check of the new fixture (the workbench's Windows fixture check, llvm-mingw 20261104: PASS, 2 translation units, 0 failures, 0 unjudged; Windows execution NOT TESTED); one game run of this head through the lane (one run each of this head and main through the workbench's lane, 13:01 to 13:15 on 2026-11-17, exit 0, no fatal, crash, device lost or kernel lines; only two laps completed, and Link died in lap 2 of both); pictures of a long Hyrule Field walk (pictures of the walk: two contact sheets, 13 frames each, taken every 20 s).

Not tested: that the field's growth (about 200 images an hour, walking through terrain) is all this kind (the laps here are 6000-present walks, about 100 s each, not hours); whether three quarters is the right line for a tile whose slot the game only partly reused; a long walk for ground streaks (issues 107 and 386) beyond the 13 pictures a build here (I looked at them at contact-sheet size: a subtle streak would not show); the third lap of the plan (the time budget ended the run); Windows, AMD, an 8 GB card; the RAM growth in the 2-hour soak (it follows time, not area, and is not render targets).

Must be tested:

  • Windows, any GPU, and an 8 GB or smaller card: walk Hyrule Field for 20 minutes and return to Kokiri Forest, expecting no empty or striped ground tiles and the "image blocks (render targets)" images not climbing (by hand: look at the ground; the log lines).

Risks

What could break: a tile the renderer lets go of is made again when the game next uses its storage and is then filled from memory; if the game still relied on the image's texels for a slot it only partly rewrote, the ground could show streaks (issues 107 and 386). The rule requires three quarters of the storage written after finalization and 32 KB or more, to avoid that.

Cost: the rule reads the written ranges of a finalized texture's storage (memory_written_runs) when the eviction pass looks at that texture, and only for textures the GPU drew, finalized and of 32 KB or more (the first checks return before the read). The texture pass's own time (the frame trace's tex_frame_ms) was not measured on either build; the runs above were ordinary runs on a shared machine, no speed claim.

Turning it off: revert the commit.

Compatibility: Nothing changes.

Issues

Refs #1443.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what
    can't be run by hand is in Testing's Not testable by hand, with why.
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and
    in Risks. Not ticked yet: Risks says the texture pass's own time cost was not measured on either build.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named): 38 tests fail on both main and this PR: test_bug_report_defaults.py, test_cpu_report.py, test_crash_record.py, test_crt_options.py, test_damage_debug_menu.py, test_display_startup_failure.py, test_dlss_feature_size.py, test_failed_compile_keeps_objects.py, test_framegen_preset.py, test_fsr_uniform_ownership.py, test_guest_imported.py, test_hud_layout_row.py, test_import_reach.py, test_invalidate_vcore.py, test_linux_preflight.py, test_linux_pressure.py, test_linux_update.py, test_mirror_budget.py, test_missing_nup.py, test_mods_size_table.py, test_nonuniform_image_arrays.py, test_parallel_init_order.py, test_pending_guest_import.py, test_pipeline_play_cache.py, test_present_thread.py, test_profiling_mode.py, test_readback_timeout_source.py, test_replay_write_order.py, test_rumble_menu.py, test_run_all_changed.py, test_slow_frames.py, test_staging_burst.py, test_target_image_pool.py, test_upscaler_round_trip.py, test_upscaler_rows.py, test_vcore_escape.py, test_vk_occlusion_queries.py, test_walk_key.py.
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • A check under tests/ that reads changed source updated in this PR, not weakened (tests/test_vram_compact.py follows the changed hold_live line; nothing removed).
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths (the Windows-target syntax check of the new fixture passed; the renderer change is plain C++ the Linux build compiled).

New on this forge; not opened on GitHub.

**Type:** fix · **Risk:** medium · **Tested on:** Linux, RTX 4090 (a 6 GB card's allowance by switch); game-free checks · **Needs:** Windows, any GPU; an 8 GB card; a long walk over Hyrule Field ## TL;DR In long sessions the game's video memory slowly fills up until it stutters or closes (#1443). The cause: small terrain tiles the renderer keeps after the game has already reused their memory, so they are never let go. This PR lets those stale tiles go. Walking the same route on a simulated 6 GB card, main climbs from 129 to 166 to 221 render images; with this PR it stays at 128, 131, 129. One rule in the texture eviction pass and one new test; nothing that is still in use is touched. ## Breakdown - **Who it helps:** anyone playing for a long time, most of all on cards with 8 GB or less, where video memory runs out first. - **What was wrong:** the renderer keeps a finished terrain tile "in case it is drawn again". When the game later writes something else into that tile's memory, the tile is useless, but nothing ever removed it while the game was under its memory budget. - **What changes:** a finished tile of 32 KB or more whose memory the game has mostly (three quarters) rewritten is let go, whatever the budget says. Partly rewritten or small ones stay. - **What does not change:** everything still in use; the cache limit for kept tiles; the other cleanup passes (#1255); #943's case. - **How it was checked:** a test built from the renderer's own code (main keeps all 1,800 tiles over 30 laps, this PR 120); the whole test suite (same failures as main); the Windows compile check; and walking laps in the game on this PR's exact build next to main, with pictures of the walk looked at for missing or striped ground. - **What is still open:** Windows, AMD and real small cards; hours-long sessions; whether "three quarters" is the right line; a closer look for ground streaks on a long walk. - **Risk:** medium. If the game still needed a partly rewritten tile, the ground could show streaks; the three-quarters rule is there to avoid that, and none were seen in the pictures. ## Why In a long session the game's video memory keeps growing until it slows down, runs out, or closes (#1443 collects the reports). Players' logs show the render-target images climbing by about 200 an hour while walking, and about 84 % of them (median over 151 logs) are small terrain tiles the renderer keeps after the game has finished with them. The renderer does not lose them; it never lets them go: inside the texture budget it retires a render target only when another target was drawn over it, and a tile whose slot the game later reuses with CPU writes is never drawn over. Refs #1443. ## How to reproduce **Seen on:** Linux, Arch, RTX 4090, NVIDIA 615.78.08 (a 6 GB card's allowance set by `RX_VK_TEST_ALLOWED_MB=5200`) **Settings and switches:** defaults, plus `RX_VK_TEST_ALLOWED_MB=5200` **Steps:** load a save in Kokiri Forest, then three or more laps of: teleport to Hyrule Field, walk about 200 m over open ground for 6000 presents along a planned route, teleport back; read the "image blocks (render targets)" line every 600 presents **Expected:** the render-target images stay flat from lap to lap **Actual:** on main they climb every lap: 129, 166, 221 images at the ends of the first three marks (arrival, lap 1, lap 2); other runs on main with a diagnostic build: 171, 237, 209, 297 at the default allowance ## What changed A finalized render target whose storage the game has written over since it finalized it goes, within the budget as over it. The terrain tiles (260 x 260 RG8, nine levels) are drawn once, written back into memory, finalized, and the game later reuses their slots; the image of each stayed for good. - vk: `finalized_obsolete()` in `gpu/vk/vk_texture.cpp`: a texture the GPU drew and the game finalized, in a pool's own memory, of 32 KB or more, with three quarters of its storage written by the CPU since it was finalized (`memory_written_runs` from its `release_gen`). `texture_frame`'s pass lets such a texture go whatever the budget says: the sweep (`if (sweep && !overwritten) continue;`) no longer keeps it, `keep_finalized` no longer counts it, and the compaction's hold treats it as it treats a drawn-over target. Nothing is written back (its texels are gone from that memory on the console too). - tests: `tests/test_target_retention.py` and `.cpp` cut that pass and `finalized_obsolete` out of `vk_texture.cpp` and run 30 laps of 60 tile-sized targets; `tests/test_vram_compact.py` follows the changed `hold_live` line. Unchanged: the cap on kept finalized textures (`RX_VK_KEEP_FINALIZED_MB`, 128 MB: it is still applied over the budget only and still counts texels, not the allocator's padding), the dead-target sweep (#1255), the target pool. #943's summed overlap is a different class (single-level targets) and is not touched. ## Measurements **Verdict:** on this head the render-target images stay flat across the two walking laps that ended (128, 131, 129) while main's climb (129, 166, 221); the finalized tiles the renderer keeps are 60 and 41 against 93 and 131. Only lap 1 is a clean comparison (131 against 166 images, 60 against 93 kept): in lap 2 of both runs a Deku Baba killed Link in Hyrule Field (the pictures show Game Over; the game restarts him at the arrival point). It is two laps of one route, not hours of walking, so it shows the direction, not the size, of the field's growth. Hardware: Linux, RTX 4090, NVIDIA 615.78.08, i9-13900K, 96 GB; other games on the card (ordinary run, not a timing measurement) Scene: Kokiri Forest and Hyrule Field (child), DLAA 2048x1152, 6 GB allowance by switch Method: the lap script (`LapleakDriver`), 3 laps, `longshot_log.txt` lines every 600 presents; the diagnostic that counted the kinds and owners (`RX_VK_LOG_TARGETS`) is not in this PR How to reproduce: as above | At the end of | Before: main @ 645d58e68 | After: this PR @ 1c09f9d12 | |---|---|---| | mark 0 (arrival, about 20 m walked) | 129 images | 128 images | | lap 1 (about 200 m walked) | 166 images | 131 images | | lap 2 (about 200 m, Link killed) | 221 images | 129 images | | finalized kept for being made again, n (MB), marks 0, 1, 2 | 3 (0), 93 (21), 131 (20) | 3 (0), 60 (15), 41 (5) | | render-target blocks and images at the last 600-present line | 25 blocks 800 MB, 225 images 315 MB, 100 free ranges | 22 blocks 704 MB, 133 images 276 MB, 63 free ranges | | VRAM used by the game (MB, from the log) marks 0, 1, 2 | 4778, 5138, 4752 | 4586, 4658, 4762 | | process RSS (MB) marks 0, 1, 2 | 10241, 12094, 12212 | 10220, 12316, 6438 (the restart after Game Over) | | run health | exit 0, fatal 0, crash 0, device lost 0, kernel Xid/NVRM lines 0 | the same | Supporting runs with the diagnostic (not this exact head: the diagnostic build plus the same single rule, `50eaceee8`, against the diagnostic build on main; 24 GB card, no allowance switch, a longer route in open Hyrule Field): main's images 171, 237, 209, 297 and finalized tiles unused 600+ presents 1, 50, 79, 105; with the rule 101, 120, 131 and 0, 19, 14, of which written over by the CPU 1, 1, 1. At the 6 GB allowance on main with the diagnostic: 144, 152, 198, 240 images, tiles 1, 22, 77, 93, of which written over 1, 18, 44, 70. ``` vk: image blocks (render targets): 25 blocks 800 MB, 225 images 315 MB; 100 free ranges, the largest 30 MB (main, last line of lap 2) vk: finalized textures the GPU drew once, kept for being made again: 132 (20812 KB): ... (main) vk: image blocks (render targets): 22 blocks 704 MB, 133 images 276 MB; 63 free ranges, the largest 26 MB (this PR, last line of lap 2) vk: finalized textures the GPU drew once, kept for being made again: 41 (4800 KB): ... (this PR) run summary, this PR: exit=0 wall=371.3s frames=22373(headless-renderer) fatal=0 crash=0 devlost=0 kernel=0 nvrm=0 run summary, main: exit=0 wall=375.7s frames=22289(headless-renderer) fatal=0 crash=0 devlost=0 kernel=0 nvrm=0 ``` On main, with the diagnostic: 0 orphans in 95 samples (every image in the render-target blocks owned by a live texture, the dead list or the pool); at lap ends the finalized 260 x 260 tiles unused 600+ presents were 1, 22, 77, 93 of which 1, 18, 44, 70 had their storage written over by the CPU. Fixture: `tests/test_target_retention.py`, main @ 645d58e68: storage written over two laps on, within the budget 1800 of 1800 tiles alive after 30 laps, over the budget 744 of 1800 (the keep cap), and the three-quarters case fails; this PR: 120 of 1800 in both, the quarter, half and 16 KB cases keep all. ### Pictures of the walk ![this PR @ 1c09f9d12, 13 frames of the walk, one every 20 s (the arrival at Hyrule Field's forest exit, the road and grass, a cliff path, a tree, two Game Over screens after the Deku Baba): the ground, rock faces and the castle in the distance draw normally; no streaks, black patches or missing tiles at this size](https://git.magicbean.dev/attachments/3ee09073-2afb-41fc-99d9-8a89b8d0ffc3) ![main @ 645d58e68, the same walk: the same scenes draw alike (a Deku Baba close in one frame and one Game Over screen)](https://git.magicbean.dev/attachments/c0a8dee7-9455-40fc-9505-da9c3f4d28df) ### Flags and settings None. ## How it was tested Everything here was run by an AI agent (Claude Sonnet 5.5) working for me; commands are given so anyone can rerun them. The game run described in section 3 is one run of this head and one of main, the same afternoon; its files are named below. ### 1. What was looked for, and how the cause was found 1. **Reading.** Every place in `gpu/vk` where a render target's image can be made, replaced, destroyed, pooled or erased (`create()`, `destroy_later`, the dead list drain in `texture_frame`, `pool_put`/`pool_take`/`pool_trim`, the compaction's image swap, the upscalers' and frame generation's images) was read at main `50170f819` (later `645d58e68`, which did not touch these files). No path loses an image. 2. **Existing logs.** Every `longshot_log.txt` and `hookshot_log.txt` attached to the issues of this tracker that had 20 or more samples of "image blocks (render targets)" was downloaded (151 logs from 393 files, v3.0.0-rc.3 to nightlies) and read by a small Python script (regular expressions over four log lines every 600 presents: "image blocks (render targets): N blocks .. MB, M images .. MB", "render target images: .. made new, .. destroyed from it; it holds ..", "VRAM: .. textures .. MB (budget .. MB)", "finalized textures the GPU drew once, kept for being made again: N (KB)"). Check 1: images == made new - destroyed in every sample (92 % of 14,447 samples exact). Check 2: kept count against image count at the end of each log (median 0.84). 3. **A diagnostic, not part of this PR.** A logging switch (`RX_VK_LOG_TARGETS=<presents>`) was added on a separate branch. Every N presents it matches every image in the render-target blocks (VMA's pool statistics) with its owner (a live Texture, the dead list, the target pool), counts the live render-target textures by kind (never written, live, finalized, one level or many) and by presents unused, and counts how many finalized ones have had their storage written by the CPU since the game finalized them (`memory_written_runs` from the texture's `release_gen`). It was run on main in the game (section 3) and showed: 0 orphans in 95 samples, and the unused finalized tiles' storage written over by the CPU (17/17, 36/37, 38/38 in the older buckets; in the walking run 70 of 93). ### 2. Game-free checks (anyone can rerun) - Environment: the same machine as below, no GPU used. The fixture is plain C++ compiled by the Python test. - `python -I -B tests/test_target_retention.py` (the pinned build Python; `--cxx g++` is the default). It cuts, by their text, `texture_frame`'s choice of which textures go (from `order` to the end of its loop) and the new `finalized_obsolete()` out of `gpu/vk/vk_texture.cpp` (`tests/srccut.py`), compiles them into `tests/test_target_retention.cpp` with stand-ins for the Texture fields they read, and runs 30 laps of 60 render targets the size of the terrain tiles (260 x 260 RG8, nine levels, 176 KB of texels, 325 KB as the allocator gives it: the numbers come from the diagnostic's lines). Each lap's targets are drawn once, finalized, never used again, and no later target is drawn over them; the game writes over a lap's storage two laps on (all of it, a quarter, half, three quarters; a 16 KB texture as well). Pass: the tiles whose storage was written over (three quarters or more, 32 KB or more) are gone and the others stay. - Result on main `645d58e68` with the test copied in: within the budget 1800 of 1800 tiles alive after 30 laps, over the budget 744 of 1800 (the keep cap), the three-quarters case fails. On this PR's head: 120 of 1800 in both cases; a quarter, half and the 16 KB texture keep all. - Whole suite: `python -I -B tests/run_all.py --jobs 6 --strict` through the workbench's idle-class gate (https://github.com/mooki000/ls-workbench: the idle wrapper, three slots, core dumps off, a fresh HOME), once on this head and once on main `645d58e68`, outputs compared by test name. 669 passed / 38 failed / 17 skipped here, 668 / 38 / 17 on main; the same 38 names fail on both (listed in the checklist). - Windows-target syntax: the workbench's Windows fixture check (https://github.com/mooki000/ls-workbench/tree/main/skills/ls-pr-evidence/scripts, with llvm-mingw 20261104 `ucrt-x86_64`) compiles the new C++ fixture for the Windows target: PASS, 2 translation units, 0 failures, 0 unjudged. Windows execution was not run. ### 3. In the game (Linux, headless) - **Machine:** Arch Linux, kernel 7.2.15, i9-13900K, 96 GB RAM, RTX 4090 with NVIDIA 615.78.08, one monitor not used (HOS_HEADLESS: frames render to an offscreen image, no window). The machine runs other games and builds at the same time: the load average was 50 to 95 during the runs, so every frame time is an ordinary-run diagnostic and **no speed claim is made**; the memory and image counts are not affected by load. - **Build:** main `645d58e68` and this head `1c09f9d12` built the same way for the game: a native Linux build with the workbench's build wrapper through the build gate, release profile (`RX_RELEASE=1`, the shipped profile data), no diagnostic code, over a finished donor build of main `36de9b0ce` whose 42 lifted-code inputs and 517 HLE names were checked identical (the changes are renderer-only). This head: 123 s, 418 objects new and 100 from the cache, source stamp d08d307d; main `645d58e68`: 87 s, source stamp 35eea065; both exit 0. (The build receipts stay on my PC: they hold local paths.) - **Save and scene:** a save in Kokiri Forest (child) made with the workbench's save tool, played from a disposable copy for every run. Settings: defaults (DLAA at 2048 x 1152, 60 fps cap) plus `RX_VK_TEST_ALLOWED_MB=5200`, which makes the renderer see a driver allowance of 5200 MB, so the 24 GB card plays the budget and pressure paths of a 6 GB card (see `gpu/vk/vram_compact.h`, `gpu/vk/texture_budget.h`). - **How the game was driven:** the control bridge (`docs/control.md` in this repository: https://git.magicbean.dev/MagicBeanDev/Longshot/src/branch/main/docs/control.md) on a private socket, by a lap script (the workbench's scripted-play drivers, `hsap`, https://github.com/mooki000/ls-workbench). A lap: debug teleport to Hyrule Field (child), a planned route of open-ground walking (a stick held toward the next waypoint, the pad's analog axes through the bridge, 6000 presents a lap), debug teleport back to Kokiri Forest, wait. The script marks each lap's start and end in a CSV with the present count. The plan asked for 3 laps of the walking leg (6000 presents, about 100 s) and a 300-present leg back in Kokiri Forest; the run's time budget stopped it after two completed laps, so each run has the arrival mark and two laps. One run per build, the head first and main 7 minutes later, same save, same plan, same settings. A planned route over open ground (waypoints chosen from the workbench's local world notes, not shipped) is followed by the script holding the stick toward the next waypoint and checking the position the bridge reports. - **What was sampled:** the game's own log every 600 presents ("image blocks (render targets)", "render target images", "VRAM", "textures"), and the lap script every 5 s: process RSS and anonymous memory from `/proc`, the card's memory from nvidia-smi, and the game's frame log. A picture of the game's frame every 20 s of walking through the bridge's `shot` (1280 x 720). At each lap end the table takes the last value of each log line seen before the lap's end mark. - **Pass:** render-target images at the lap ends flat on the head (no rise from one mark to the next beyond the spread seen between the head's own marks) while main's climb; no empty or striped ground in the pictures (I looked at them at contact-sheet size; a closer look by a person is under Must be tested). - **Kernel and driver check:** the workbench's run wrapper read the kernel journal for each run (Xid, `kmemsysDoCacheOp`, any NVRM line): 0 for both runs, journal coverage complete; a game exit code 0, no crash, no device lost, no core dump. - **Rerun:** the lap script is attached as text to the comment (`leak-fix-pr-lapleak.py.txt`, 776 lines, standard library only: it starts the game through the workbench's run wrapper with a save and switches, drives it through the bridge, writes `marks.csv` with the present count at each lap mark and `samples.csv` every 5 s, and takes the bridge's pictures). Its way of use: the workbench's scripted-play skill. Each run's own files (`laps.md`, `samples.csv`, `memlines.log` with every game log line of the run, the pictures) are named in the comment. ### 4. What was not tested See "Not tested" under Testing: hours of walking, Windows, AMD, 8 GB cards, any speed claim, and the process-memory (RAM) creep of the 2-hour co-op soak. ## Testing **Tested:** `tests/test_target_retention.py` (red on main, green here); the whole suite by name against main (`python -I -B tests/run_all.py --jobs 6 --strict`: this PR @ 1c09f9d12 669 passed, 38 failed, 17 skipped; main @ 645d58e68 668 passed, 38 failed, 17 skipped; the failing set is the same 38 names on both, none of them touches the render targets' eviction); the Windows-target syntax check of the new fixture (the workbench's Windows fixture check, llvm-mingw 20261104: PASS, 2 translation units, 0 failures, 0 unjudged; Windows execution NOT TESTED); one game run of this head through the lane (one run each of this head and main through the workbench's lane, 13:01 to 13:15 on 2026-11-17, exit 0, no fatal, crash, device lost or kernel lines; only two laps completed, and Link died in lap 2 of both); pictures of a long Hyrule Field walk (pictures of the walk: two contact sheets, 13 frames each, taken every 20 s). **Not tested:** that the field's growth (about 200 images an hour, walking through terrain) is all this kind (the laps here are 6000-present walks, about 100 s each, not hours); whether three quarters is the right line for a tile whose slot the game only partly reused; a long walk for ground streaks (issues 107 and 386) beyond the 13 pictures a build here (I looked at them at contact-sheet size: a subtle streak would not show); the third lap of the plan (the time budget ended the run); Windows, AMD, an 8 GB card; the RAM growth in the 2-hour soak (it follows time, not area, and is not render targets). **Must be tested:** - Windows, any GPU, and an 8 GB or smaller card: walk Hyrule Field for 20 minutes and return to Kokiri Forest, expecting no empty or striped ground tiles and the "image blocks (render targets)" images not climbing (by hand: look at the ground; the log lines). ## Risks **What could break:** a tile the renderer lets go of is made again when the game next uses its storage and is then filled from memory; if the game still relied on the image's texels for a slot it only partly rewrote, the ground could show streaks (issues 107 and 386). The rule requires three quarters of the storage written after finalization and 32 KB or more, to avoid that. **Cost:** the rule reads the written ranges of a finalized texture's storage (`memory_written_runs`) when the eviction pass looks at that texture, and only for textures the GPU drew, finalized and of 32 KB or more (the first checks return before the read). The texture pass's own time (the frame trace's `tex_frame_ms`) was not measured on either build; the runs above were ordinary runs on a shared machine, no speed claim. **Turning it off:** revert the commit. **Compatibility:** Nothing changes. ## Issues Refs #1443. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [ ] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. Not ticked yet: Risks says the texture pass's own time cost was not measured on either build. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named): 38 tests fail on both main and this PR: test_bug_report_defaults.py, test_cpu_report.py, test_crash_record.py, test_crt_options.py, test_damage_debug_menu.py, test_display_startup_failure.py, test_dlss_feature_size.py, test_failed_compile_keeps_objects.py, test_framegen_preset.py, test_fsr_uniform_ownership.py, test_guest_imported.py, test_hud_layout_row.py, test_import_reach.py, test_invalidate_vcore.py, test_linux_preflight.py, test_linux_pressure.py, test_linux_update.py, test_mirror_budget.py, test_missing_nup.py, test_mods_size_table.py, test_nonuniform_image_arrays.py, test_parallel_init_order.py, test_pending_guest_import.py, test_pipeline_play_cache.py, test_present_thread.py, test_profiling_mode.py, test_readback_timeout_source.py, test_replay_write_order.py, test_rumble_menu.py, test_run_all_changed.py, test_slow_frames.py, test_staging_burst.py, test_target_image_pool.py, test_upscaler_round_trip.py, test_upscaler_rows.py, test_vcore_escape.py, test_vk_occlusion_queries.py, test_walk_key.py. - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened (`tests/test_vram_compact.py` follows the changed `hold_live` line; nothing removed). - [x] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths (the Windows-target syntax check of the new fixture passed; the renderer change is plain C++ the Linux build compiled). --- New on this forge; not opened on GitHub.
Cuts texture_frame's choice of which textures go out of vk_texture.cpp and runs it over 30 laps of 60 terrain-tile render targets
(260 x 260 RG8, nine levels) the GPU draws once and the game finalizes, then reuses the storage of (the CPU writes over it). Within the
budget the pass is a sweep that lets go of a target only when another was drawn over it: none goes.

Assisted-by: Claude Sonnet 5.5
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
fix(vk): a finalized render target goes once the game has written over its storage, within the budget too
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 9s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 15s
CI / Workflow lint (actionlint) (pull_request) Successful in 21s
Third-party parts / As their notes say (pull_request) Successful in 27s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Failing after 5s
beanstalk/approval approved by llun (reviewed)
beanstalk/windows 1/1 fail
beanstalk/vram8gb 1/1 pass
1c09f9d120
Within the texture budget texture_frame's pass is a sweep that lets go of a render target only when another target was drawn over its
storage. The terrain tiles (260 x 260 RG8, nine levels) are drawn once, written back into memory, finalized, and the game later reuses
their slots; the image of each stayed for good: in a tour with a 6 GB card's allowance about 80 were alive and unused for 600 presents or
more, nearly every one with its storage written over by the CPU since (the diagnostic's "finalized and the CPU has written their storage
since" line). A finalized texture of 32 KB or more with three quarters of its storage written since it was finalized now goes at once:
its texels are gone from that memory on the console too. Refs #1443.

Assisted-by: Claude Sonnet 5.5
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
mooki changed title from WIP: fix(vk): a finalized render target goes once the game has written over its storage to fix(vk): a finalized render target goes once the game has written over its storage 2026-11-17 19:33:43 +00:00
Author
Member

The lap scripts used for the game runs in the description, attached as text (rename to .py): lapleak.py drives the game over the control bridge (docs/control.md) and samples every 4 s; lapsumm.py turns a run's samples.csv, memlines.log and marks.csv into the per-lap tables. Both are standard library only. The planned walking route is a file of waypoints I made from my own game files, so it is not attached; without it the walk turns at obstacles and stays near the arrival point. The 24 GB laps and the first form of the fix are in #1443 (comment).

The lap scripts used for the game runs in the description, attached as text (rename to .py): [lapleak.py](https://git.magicbean.dev/attachments/6fa97894-e332-4603-837f-a05a7c782b08) drives the game over the control bridge (`docs/control.md`) and samples every 4 s; [lapsumm.py](https://git.magicbean.dev/attachments/d1034e07-0f89-4ad1-914e-b79c11befc0e) turns a run's `samples.csv`, `memlines.log` and `marks.csv` into the per-lap tables. Both are standard library only. The planned walking route is a file of waypoints I made from my own game files, so it is not attached; without it the walk turns at obstacles and stays near the arrival point. The 24 GB laps and the first form of the fix are in https://git.magicbean.dev/MagicBeanDev/Longshot/issues/1443#issuecomment-43665.
Member

@Beanstalk

@Beanstalk
Member

Beanstalk test farm

Commit 1c09f9d · tier reviewed · approved by llun · dashboard

What will be tested · AI plan (gpt-6.1-terra)

On Windows and on an 8 GB GPU, the plan repeats short Hyrule Field walks and returns to Kokiri Forest under a simulated 6 GB allowance, then checks the Deku Tree interior. Each target takes roughly 15 minutes, comparing VRAM, frame times and pictures against main; crashes, device loss, substantial performance or VRAM regressions, and visual differences fail. The VRAM probe is a proxy for retention: this plan cannot count render-target images or establish long-session growth.

  • Where: windows (1-2 reports), vram8gb (any PC with 8 GB VRAM, 1-2 reports).
  • field-retention: from a new save (switches RX_VK_TEST_ALLOWED_MB=5200), then 3 times: teleport to Hyrule Field, move the stick, teleport to Kokiri Forest, teleport to Hyrule Field, take the picture field-after-laps to compare with main, measure field for 20 s (after 5 s warm-up), teleport to Inside the Deku Tree, take the picture deku-interior to compare with main, measure deku for 20 s (after 5 s warm-up); 1 run on each side.
  • Measured: crashes, frame times, stutters and hitches, VRAM use, the game's log.
  • The PR fails if: it crashes; or a picture differs from main by more than 3%; or peak VRAM is more than 10% above main; or frame time (p99) is more than 20% above main; or forbidden log lines is above 0.
  • Time: about 14 min of game runs per tester (2 game starts), plus the two builds.

Done (started 20:01 UTC, last report 20:56 UTC). Comment @Beanstalk to run it again.

Target Reports Crash Frame p99 (ms) vs main VRAM peak (MB) vs main Result
windows · 1: windows+amd+amd-proprietary+dgpu AMD Radeon RX 9070 XT, 2.0.416; 2: windows+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 4070, 621.1.0 2/1 1 2 none 24.8 vs 24.4 (+2%) 4,980 vs 4,854 (+3%) fail ⚠ outlier
vram8gb · 1: windows+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 3070, 621.24.0 1/1 1 none 24.2 vs 25.5 (−5%) 4,640 vs 4,564 (+2%) pass

Measurements · windows

Verdict: fail on windows (2/1 report): field-retention field.frametime_p99_ms.max_delta_pct (+26.9%) failed.

Hardware: 1: windows+amd+amd-proprietary+dgpu AMD Radeon RX 9070 XT, 2.0.416 AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAM; 2: windows+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 4070, 621.1.0 13th Gen Intel(R) Core(TM) i7-13700F, 32 GB RAM
Scene: field-retention, from a new save (RX_VK_TEST_ALLOWED_MB=5200); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); field-retention: 1 game start a side, field 20 s after 5 s warm-up, deku 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (@Beanstalk on this PR runs it again)

Before: main @ 645d58e After: this PR @ 1c09f9d
field-retention · deku · peak VRAM (MB) 4,854 4,980 (+3%)
field-retention · field · peak VRAM (MB) 4,930 4,970 (+1%)
field-retention · deku · frame time (p99) (ms) 24.4 24.8 (+2%)
field-retention · field · frame time (p99) (ms) 19.1 21.9 (+15%)
field-retention · forbidden log lines 0.0 0.0

Flags and settings

None: the plan varied no setting, switch or build option.

Markdown for the PR description
## Measurements

**Verdict:** fail on windows (2/1 report): `field-retention field.frametime_p99_ms.max_delta_pct (+26.9%)` failed.

Hardware: 1: windows+amd+amd-proprietary+dgpu `AMD Radeon RX 9070 XT, 2.0.416` `AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAM`; 2: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 4070, 621.1.0` `13th Gen Intel(R) Core(TM) i7-13700F, 32 GB RAM`  
Scene: field-retention, from a new save (RX_VK_TEST_ALLOWED_MB=5200); each cell's settings and switches as the table names them  
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); field-retention: 1 game start a side, field 20 s after 5 s warm-up, deku 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports  
How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again)

| | Before: main @ 645d58e | After: this PR @ 1c09f9d |
|---|---|---|
| field-retention · deku · peak VRAM (MB) | 4,854 | 4,980 (+3%) |
| field-retention · field · peak VRAM (MB) | 4,930 | 4,970 (+1%) |
| field-retention · deku · frame time (p99) (ms) | 24.4 | 24.8 (+2%) |
| field-retention · field · frame time (p99) (ms) | 19.1 | 21.9 (+15%) |
| field-retention · forbidden log lines | 0.0 | 0.0 |

### Flags and settings

None: the plan varied no setting, switch or build option.

Measurements · vram8gb

Verdict: pass on vram8gb (1/1 report): no rule failed and no PR run crashed.

Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 3070, 621.24.0 AMD Ryzen 5 5600X3D 6-Core Processor, 32 GB RAM
Scene: field-retention, from a new save (RX_VK_TEST_ALLOWED_MB=5200); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); field-retention: 1 game start a side, field 20 s after 5 s warm-up, deku 20 s after 5 s warm-up; each number the median of the runs, then of 1 report
How to reproduce: the farm's plan above (@Beanstalk on this PR runs it again)

Before: main @ 645d58e After: this PR @ 1c09f9d
field-retention · deku · peak VRAM (MB) 4,564 4,640 (+2%)
field-retention · field · peak VRAM (MB) 4,561 4,563 (+0%)
field-retention · deku · frame time (p99) (ms) 25.5 24.2 (−5%)
field-retention · field · frame time (p99) (ms) 19.9 19.9 (+0%)
field-retention · forbidden log lines 0.0 0.0

Flags and settings

None: the plan varied no setting, switch or build option.

Markdown for the PR description
## Measurements

**Verdict:** pass on vram8gb (1/1 report): no rule failed and no PR run crashed.

Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3070, 621.24.0` `AMD Ryzen 5 5600X3D 6-Core Processor, 32 GB RAM`  
Scene: field-retention, from a new save (RX_VK_TEST_ALLOWED_MB=5200); each cell's settings and switches as the table names them  
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); field-retention: 1 game start a side, field 20 s after 5 s warm-up, deku 20 s after 5 s warm-up; each number the median of the runs, then of 1 report  
How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again)

| | Before: main @ 645d58e | After: this PR @ 1c09f9d |
|---|---|---|
| field-retention · deku · peak VRAM (MB) | 4,564 | 4,640 (+2%) |
| field-retention · field · peak VRAM (MB) | 4,561 | 4,563 (+0%) |
| field-retention · deku · frame time (p99) (ms) | 25.5 | 24.2 (−5%) |
| field-retention · field · frame time (p99) (ms) | 19.9 | 19.9 (+0%) |
| field-retention · forbidden log lines | 0.0 | 0.0 |

### Flags and settings

None: the plan varied no setting, switch or build option.
<!-- beanstalk:sticky --> ### Beanstalk test farm Commit `1c09f9d` · tier **reviewed** · approved by llun · [dashboard](https://beanstalk.magicbean.dev/prs/1462) **What will be tested** · AI plan (`gpt-6.1-terra`) On Windows and on an 8 GB GPU, the plan repeats short Hyrule Field walks and returns to Kokiri Forest under a simulated 6 GB allowance, then checks the Deku Tree interior. Each target takes roughly 15 minutes, comparing VRAM, frame times and pictures against main; crashes, device loss, substantial performance or VRAM regressions, and visual differences fail. The VRAM probe is a proxy for retention: this plan cannot count render-target images or establish long-session growth. - **Where:** windows (1-2 reports), vram8gb (any PC with 8 GB VRAM, 1-2 reports). - **field-retention:** from a new save (switches `RX_VK_TEST_ALLOWED_MB=5200`), then 3 times: teleport to Hyrule Field, move the stick, teleport to Kokiri Forest, teleport to Hyrule Field, take the picture field-after-laps to compare with main, measure field for 20 s (after 5 s warm-up), teleport to Inside the Deku Tree, take the picture deku-interior to compare with main, measure deku for 20 s (after 5 s warm-up); 1 run on each side. - **Measured:** crashes, frame times, stutters and hitches, VRAM use, the game's log. - **The PR fails if:** it crashes; or a picture differs from main by more than 3%; or peak VRAM is more than 10% above main; or frame time (p99) is more than 20% above main; or forbidden log lines is above 0. - **Time:** about 14 min of game runs per tester (2 game starts), plus the two builds. Done (started 20:01 UTC, last report 20:56 UTC). Comment `@Beanstalk` to run it again. | Target | Reports | Crash | Frame p99 (ms) vs main | VRAM peak (MB) vs main | Result | | --- | --- | --- | --- | --- | --- | | windows · 1: windows+amd+amd-proprietary+dgpu `AMD Radeon RX 9070 XT, 2.0.416`; 2: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 4070, 621.1.0` | 2/1 [1](https://beanstalk.magicbean.dev/reports/rp_3bf0c27753c32bd8) [2](https://beanstalk.magicbean.dev/reports/rp_d9fcb86c4d6a4e5d) | none | 24.8 vs 24.4 (+2%) | 4,980 vs 4,854 (+3%) | fail ⚠ outlier | | vram8gb · 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3070, 621.24.0` | 1/1 [1](https://beanstalk.magicbean.dev/reports/rp_e5373935df9cb509) | none | 24.2 vs 25.5 (−5%) | 4,640 vs 4,564 (+2%) | pass | #### Measurements · windows **Verdict:** fail on windows (2/1 report): `field-retention field.frametime_p99_ms.max_delta_pct (+26.9%)` failed. Hardware: 1: windows+amd+amd-proprietary+dgpu `AMD Radeon RX 9070 XT, 2.0.416` `AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAM`; 2: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 4070, 621.1.0` `13th Gen Intel(R) Core(TM) i7-13700F, 32 GB RAM` Scene: field-retention, from a new save (RX_VK_TEST_ALLOWED_MB=5200); each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); field-retention: 1 game start a side, field 20 s after 5 s warm-up, deku 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) | | Before: main @ 645d58e | After: this PR @ 1c09f9d | |---|---|---| | field-retention · deku · peak VRAM (MB) | 4,854 | 4,980 (+3%) | | field-retention · field · peak VRAM (MB) | 4,930 | 4,970 (+1%) | | field-retention · deku · frame time (p99) (ms) | 24.4 | 24.8 (+2%) | | field-retention · field · frame time (p99) (ms) | 19.1 | 21.9 (+15%) | | field-retention · forbidden log lines | 0.0 | 0.0 | ### Flags and settings None: the plan varied no setting, switch or build option. <details><summary>Markdown for the PR description</summary> ```markdown ## Measurements **Verdict:** fail on windows (2/1 report): `field-retention field.frametime_p99_ms.max_delta_pct (+26.9%)` failed. Hardware: 1: windows+amd+amd-proprietary+dgpu `AMD Radeon RX 9070 XT, 2.0.416` `AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAM`; 2: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 4070, 621.1.0` `13th Gen Intel(R) Core(TM) i7-13700F, 32 GB RAM` Scene: field-retention, from a new save (RX_VK_TEST_ALLOWED_MB=5200); each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); field-retention: 1 game start a side, field 20 s after 5 s warm-up, deku 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) | | Before: main @ 645d58e | After: this PR @ 1c09f9d | |---|---|---| | field-retention · deku · peak VRAM (MB) | 4,854 | 4,980 (+3%) | | field-retention · field · peak VRAM (MB) | 4,930 | 4,970 (+1%) | | field-retention · deku · frame time (p99) (ms) | 24.4 | 24.8 (+2%) | | field-retention · field · frame time (p99) (ms) | 19.1 | 21.9 (+15%) | | field-retention · forbidden log lines | 0.0 | 0.0 | ### Flags and settings None: the plan varied no setting, switch or build option. ``` </details> #### Measurements · vram8gb **Verdict:** pass on vram8gb (1/1 report): no rule failed and no PR run crashed. Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3070, 621.24.0` `AMD Ryzen 5 5600X3D 6-Core Processor, 32 GB RAM` Scene: field-retention, from a new save (RX_VK_TEST_ALLOWED_MB=5200); each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); field-retention: 1 game start a side, field 20 s after 5 s warm-up, deku 20 s after 5 s warm-up; each number the median of the runs, then of 1 report How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) | | Before: main @ 645d58e | After: this PR @ 1c09f9d | |---|---|---| | field-retention · deku · peak VRAM (MB) | 4,564 | 4,640 (+2%) | | field-retention · field · peak VRAM (MB) | 4,561 | 4,563 (+0%) | | field-retention · deku · frame time (p99) (ms) | 25.5 | 24.2 (−5%) | | field-retention · field · frame time (p99) (ms) | 19.9 | 19.9 (+0%) | | field-retention · forbidden log lines | 0.0 | 0.0 | ### Flags and settings None: the plan varied no setting, switch or build option. <details><summary>Markdown for the PR description</summary> ```markdown ## Measurements **Verdict:** pass on vram8gb (1/1 report): no rule failed and no PR run crashed. Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3070, 621.24.0` `AMD Ryzen 5 5600X3D 6-Core Processor, 32 GB RAM` Scene: field-retention, from a new save (RX_VK_TEST_ALLOWED_MB=5200); each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); field-retention: 1 game start a side, field 20 s after 5 s warm-up, deku 20 s after 5 s warm-up; each number the median of the runs, then of 1 report How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) | | Before: main @ 645d58e | After: this PR @ 1c09f9d | |---|---|---| | field-retention · deku · peak VRAM (MB) | 4,564 | 4,640 (+2%) | | field-retention · field · peak VRAM (MB) | 4,561 | 4,563 (+0%) | | field-retention · deku · frame time (p99) (ms) | 25.5 | 24.2 (−5%) | | field-retention · field · frame time (p99) (ms) | 19.9 | 19.9 (+0%) | | field-retention · forbidden log lines | 0.0 | 0.0 | ### Flags and settings None: the plan varied no setting, switch or build option. ``` </details>
HumanBean left a comment

Code review (read only: nothing was built or run here). Verdict: comment. The code is correct as far as I can read it and I would approve it, but its own Must be tested asks for an 8 GB card and a 20-minute Hyrule Field walk, and nobody has posted those yet.

What it does for players: in long sessions, mostly while walking through terrain, the renderer stops keeping the finalized 260 x 260 terrain normal tiles after the game has reused their memory with CPU writes. Before this, within the texture budget, nothing ever let them go. It is one rule in texture_frame's eviction pass, plus a game-free test.

Checked, no problem found

  • GPU work still in flight: an obsolete texture still has to pass frame_no - last >= need_unused (120 presents in a sweep) and tex->last_value > completed before it is chosen. After that it goes through the usual destroy_later / forget_gpu path, so its images, views and descriptors have the same lifetime as any other eviction. Nothing new here.
  • Write-back: flush is !released && ..., so an obsolete texture is never written back. That is right: writing old texels over memory the game has reused is the crash that write_back_stale and the CPU-runs clip exist to prevent.
  • "Written over" means the same thing as in texture_touch: finalized_obsolete reads memory_written_runs(t.guest, t.guest_size, t.release_gen) for a pool texture (gpu < 1<<40). That is exactly what texture_dirty(*tex, max(upload_gen, release_gen)) would re-upload if the old Texture were sampled again. So evicting it and making it again over that storage (gpu_owned_since plus dirty runs: a full upload from memory) gives the same texels for the rewritten part. A different format or view at the same start is still drawn_over's case, and obsolete is only computed when !overwritten.
  • Our own write-back can't cause false positives that matter: drawn_writeback writes back through nvn_gpu_write, which calls HOS_WRITTEN, so a tile written back after it was finalized also counts as CPU-written. But in that case memory holds the tile's own texels, so the texture made again from it is correct. No picture risk, at most an earlier eviction.
  • Budget, hold and keep cap: the obsolete texture is taken out of all three places consistently (the hold's continue, hold_live, keep_finalized and its pre-count, the sweep's continue). The over-budget pass's break still applies. tests/test_vram_compact.py follows its line rather than being weakened.
  • The test cuts the real pass and finalized_obsolete with srccut and runs them. It fails on main for the bug's reason: 1800 of 1800 within the budget, the cap's 744 over it. Undoing either !obsolete in the sweep line or the one in keep_finalized makes a case fail. The 1/4, 1/2 and 16 KB cases pin the thresholds. What it doesn't model: page granularity (its stub hands back one byte run) and the generation itself (release_gen is always 1, and the stub ignores gen). That is fine for a pass-level test, since memory_written_runs is main's code.
  • No API, generated or third_party/ change. No new switch.

Evidence

The numbers are from the PR's own head 1c09f9d12 against its base 645d58e68. Same save, route, settings and RX_VK_TEST_ALLOWED_MB=5200, the same afternoon, and the log lines are pasted. One run per side, with the clean comparison in lap 1 only (131 vs 166 images, 60 vs 93 kept). The 24 GB laps in #1443 (update 3) are the first form of the fix plus the logging commit, not this head. The description says so. "Refs #1443", not "Fixes", is right. At lap 2 the game's VRAM is about the same on both sides (4762 vs 4752 MB) and the render-target blocks are 704 vs 800 MB, so this is one contributor to the issue's growth, and the issue stays open.

Test Farm so far: Windows, AMD RX 9070 XT: pass (pictures within 3%; field VRAM peak 4917 vs 4918 MB; Deku interior peak +6% and p99 +5%, one run each, which I read as noise). vram8gb: still running. Neither is the 20-minute walk the description asks for. Everything else is NVIDIA Linux only. No Intel.

Suggestions (not blocking)

  1. vk_texture.cpp:4580, a texture that was never written back. For the terrain tiles the untouched quarter is in memory already (drawn_writeback covers them: up to 1 MB, levels > 1). finalized_obsolete has no size cap and no write-back condition, though. So a finalized single-level target, or one over 1 MB, whose storage the game rewrote by 3/4 now goes within the budget, and if it is made again the remaining quarter comes from memory that never held its texels. Before this PR, within the budget, that quarter stayed in the kept image and texture_touch patched only the dirty runs. Over the budget the old pass let it go anyway, so the exposure is small. Still, || (t.written_back_for == t.last_written) as a condition for the 3/4 line (and requiring all of it otherwise), or the 4 MB cap keep_finalized uses, would keep the rule to what was measured.
  2. vk_texture.cpp:5273, the retired line's reason: passing overwritten || obsolete makes evict_reason::classify count these as DRAWN_OVER ("a render target another image has drawn over"). A reader of the "textures retired" line will look for a drawing that never happened. A reason of their own, or at least the comment at evict_reason.h:15, would help the next leak hunt.
  3. vk_texture.cpp:5225, cost: when obsolete is false, keep_finalized(tex) runs finalized_obsolete a second time, and the pre-count loop runs it for every kept finalized texture on every pass (about 50 page lookups per tile). That is cheap, but caching it per pass (or reading obsolete inside the lambda) would avoid walking the page generations three times. tex_frame_ms wasn't measured.

Overlaps and merge order

  • #1339 (WIP) changes the same eviction loop: the evict.push_back line and the RX_VK_EVICT_NO_FLUSH switch. It also widens memory generations to uint64_t (memory_written_runs, upload_gen, gpu_gen). Textual conflict on that line. finalized_obsolete and the fixture's memory_written_runs stub (uint32_t gen) need to follow the type there. Merge this first; 1339 rebases over it.
  • #1162 and #1223 (WIP, re-uploads) touch vk_texture.cpp, but not this pass. No conflict, and no change of meaning: they change what is uploaded, not what is kept.
  • #637 (the target pool) and #1359 (sparse mirror buffers) are merged and in the base. 1359 doesn't touch this path. This PR's images go through destroy_later into that pool like any other eviction.

Before approval: the Test Farm's vram8gb report, and someone's 20-minute walk over Hyrule Field on an 8 GB or smaller card (any OS; Windows preferred). Look at the ground for streaks and check that the "image blocks (render targets)" images stay flat. With that posted and clean, I'd approve as it is.

Code review (read only: nothing was built or run here). Verdict: **comment**. The code is correct as far as I can read it and I would approve it, but its own *Must be tested* asks for an 8 GB card and a 20-minute Hyrule Field walk, and nobody has posted those yet. **What it does for players:** in long sessions, mostly while walking through terrain, the renderer stops keeping the finalized 260 x 260 terrain normal tiles after the game has reused their memory with CPU writes. Before this, within the texture budget, nothing ever let them go. It is one rule in `texture_frame`'s eviction pass, plus a game-free test. ### Checked, no problem found - **GPU work still in flight:** an obsolete texture still has to pass `frame_no - last >= need_unused` (120 presents in a sweep) and `tex->last_value > completed` before it is chosen. After that it goes through the usual `destroy_later` / `forget_gpu` path, so its images, views and descriptors have the same lifetime as any other eviction. Nothing new here. - **Write-back:** `flush` is `!released && ...`, so an obsolete texture is never written back. That is right: writing old texels over memory the game has reused is the crash that `write_back_stale` and the CPU-runs clip exist to prevent. - **"Written over" means the same thing as in `texture_touch`:** `finalized_obsolete` reads `memory_written_runs(t.guest, t.guest_size, t.release_gen)` for a pool texture (`gpu < 1<<40`). That is exactly what `texture_dirty(*tex, max(upload_gen, release_gen))` would re-upload if the old Texture were sampled again. So evicting it and making it again over that storage (`gpu_owned_since` plus dirty runs: a full upload from memory) gives the same texels for the rewritten part. A different format or view at the same start is still `drawn_over`'s case, and `obsolete` is only computed when `!overwritten`. - **Our own write-back can't cause false positives that matter:** `drawn_writeback` writes back through `nvn_gpu_write`, which calls `HOS_WRITTEN`, so a tile written back *after* it was finalized also counts as CPU-written. But in that case memory holds the tile's own texels, so the texture made again from it is correct. No picture risk, at most an earlier eviction. - **Budget, hold and keep cap:** the obsolete texture is taken out of all three places consistently (the hold's `continue`, `hold_live`, `keep_finalized` and its pre-count, the sweep's `continue`). The over-budget pass's `break` still applies. `tests/test_vram_compact.py` follows its line rather than being weakened. - **The test** cuts the real pass and `finalized_obsolete` with `srccut` and runs them. It fails on main for the bug's reason: 1800 of 1800 within the budget, the cap's 744 over it. Undoing either `!obsolete` in the sweep line or the one in `keep_finalized` makes a case fail. The 1/4, 1/2 and 16 KB cases pin the thresholds. What it doesn't model: page granularity (its stub hands back one byte run) and the generation itself (`release_gen` is always 1, and the stub ignores `gen`). That is fine for a pass-level test, since `memory_written_runs` is main's code. - No API, generated or `third_party/` change. No new switch. ### Evidence The numbers are from the PR's own head `1c09f9d12` against its base `645d58e68`. Same save, route, settings and `RX_VK_TEST_ALLOWED_MB=5200`, the same afternoon, and the log lines are pasted. One run per side, with the clean comparison in lap 1 only (131 vs 166 images, 60 vs 93 kept). The 24 GB laps in https://git.magicbean.dev/MagicBeanDev/Longshot/issues/1443 (update 3) are the first form of the fix plus the logging commit, not this head. The description says so. "Refs #1443", not "Fixes", is right. At lap 2 the game's VRAM is about the same on both sides (4762 vs 4752 MB) and the render-target blocks are 704 vs 800 MB, so this is one contributor to the issue's growth, and the issue stays open. Test Farm so far: **Windows, AMD RX 9070 XT: pass** (pictures within 3%; field VRAM peak 4917 vs 4918 MB; Deku interior peak +6% and p99 +5%, one run each, which I read as noise). **vram8gb: still running.** Neither is the 20-minute walk the description asks for. Everything else is NVIDIA Linux only. No Intel. ### Suggestions (not blocking) 1. `vk_texture.cpp:4580`, a texture that was never written back. For the terrain tiles the untouched quarter is in memory already (`drawn_writeback` covers them: up to 1 MB, levels > 1). `finalized_obsolete` has no size cap and no write-back condition, though. So a finalized single-level target, or one over 1 MB, whose storage the game rewrote by 3/4 now goes within the budget, and if it is made again the remaining quarter comes from memory that never held its texels. Before this PR, within the budget, that quarter stayed in the kept image and `texture_touch` patched only the dirty runs. Over the budget the old pass let it go anyway, so the exposure is small. Still, `|| (t.written_back_for == t.last_written)` as a condition for the 3/4 line (and requiring all of it otherwise), or the 4 MB cap `keep_finalized` uses, would keep the rule to what was measured. 2. `vk_texture.cpp:5273`, the retired line's reason: passing `overwritten || obsolete` makes `evict_reason::classify` count these as `DRAWN_OVER` ("a render target another image has drawn over"). A reader of the "textures retired" line will look for a drawing that never happened. A reason of their own, or at least the comment at `evict_reason.h:15`, would help the next leak hunt. 3. `vk_texture.cpp:5225`, cost: when `obsolete` is false, `keep_finalized(tex)` runs `finalized_obsolete` a second time, and the pre-count loop runs it for every kept finalized texture on every pass (about 50 page lookups per tile). That is cheap, but caching it per pass (or reading `obsolete` inside the lambda) would avoid walking the page generations three times. `tex_frame_ms` wasn't measured. ### Overlaps and merge order - https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1339 (WIP) changes the same eviction loop: the `evict.push_back` line and the `RX_VK_EVICT_NO_FLUSH` switch. It also widens memory generations to `uint64_t` (`memory_written_runs`, `upload_gen`, `gpu_gen`). Textual conflict on that line. `finalized_obsolete` and the fixture's `memory_written_runs` stub (`uint32_t gen`) need to follow the type there. Merge this first; 1339 rebases over it. - https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1162 and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1223 (WIP, re-uploads) touch `vk_texture.cpp`, but not this pass. No conflict, and no change of meaning: they change what is uploaded, not what is kept. - https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/637 (the target pool) and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1359 (sparse mirror buffers) are merged and in the base. 1359 doesn't touch this path. This PR's images go through `destroy_later` into that pool like any other eviction. **Before approval:** the Test Farm's vram8gb report, and someone's 20-minute walk over Hyrule Field on an 8 GB or smaller card (any OS; Windows preferred). Look at the ground for streaks and check that the "image blocks (render targets)" images stay flat. With that posted and clean, I'd approve as it is.
@ -4569,0 +4577,4 @@
memory_written_runs(t.guest, t.guest_size, t.release_gen, written);
uint64_t sum = 0;
for (const auto& r : written) sum += r.second - r.first;
return sum * 4 >= t.guest_size * 3;
Owner

Suggestion: for a texture drawn_writeback never covered (single level, or over 1 MB), the quarter the game didn't rewrite comes back from memory that never held its texels when the texture is made again. Before this PR, within the budget, the kept image held it. Requiring t.written_back_for == t.last_written for the 3/4 line (all of it otherwise), or keep_finalized's 4 MB cap, would keep the rule to the tiles that were measured.

Suggestion: for a texture `drawn_writeback` never covered (single level, or over 1 MB), the quarter the game didn't rewrite comes back from memory that never held its texels when the texture is made again. Before this PR, within the budget, the kept image held it. Requiring `t.written_back_for == t.last_written` for the 3/4 line (all of it otherwise), or `keep_finalized`'s 4 MB cap, would keep the rule to the tiles that were measured.
@ -5209,0 +5222,4 @@
// held is gone from that memory on the console too, and a draw that sampled it would take the memory's contents over its
// texels (texture_touch). Within the budget the pass is a sweep that lets go of nothing the GPU did not draw over, and these
// were never drawn over by a target: the game's own writes to the memory they stood in kept every one for good (issue 1443)
const bool obsolete = !overwritten && finalized_obsolete(*tex);
Owner

Nit: when this is false, keep_finalized(tex) below computes finalized_obsolete again, and the pre-count loop computes it once more for each kept finalized texture. That is cheap (about 50 page lookups per tile), but it could be computed once per texture per pass.

Nit: when this is false, `keep_finalized(tex)` below computes `finalized_obsolete` again, and the pre-count loop computes it once more for each kept finalized texture. That is cheap (about 50 page lookups per tile), but it could be computed once per texture per pass.
@ -5253,3 +5271,3 @@
// tiled pattern over the Deku Tree's planks and Hyrule Field's path, with a 16 GB card's textures at the 6 GB budget
// (issue 386))
evict.push_back({tex, !overwritten && tex->gpu_written && !tex->released && flushable(*tex), shifted, overwritten});
evict.push_back({tex, !overwritten && tex->gpu_written && !tex->released && flushable(*tex), shifted, overwritten || obsolete});
Owner

Nit: overwritten || obsolete makes evict_reason::classify count these as DRAWN_OVER in the "textures retired" line, though nothing was drawn over them. A reason of their own would make the next leak hunt easier.

Nit: `overwritten || obsolete` makes `evict_reason::classify` count these as DRAWN_OVER in the "textures retired" line, though nothing was drawn over them. A reason of their own would make the next leak hunt easier.
Owner

Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).

  • Tested on my own PC: ticked: Testing's Tested: a game run of this head on Linux with an RTX 4090 through the lane, with the author's own hardware named.
  • Nothing gets worse that I know of: not ticked: Risks says the texture pass's own time cost was not measured on either build. Measure that cost and state it in Risks, then tick it.
Brought up to the [ready-for-review standard](https://git.magicbean.dev/MagicBeanDev/Longshot/src/branch/main/CONTRIBUTING.md#ready-for-review-out-of-wip) (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know). - *Tested on my own PC*: ticked: Testing's Tested: a game run of this head on Linux with an RTX 4090 through the lane, with the author's own hardware named. - *Nothing gets worse that I know of*: not ticked: Risks says the texture pass's own time cost was not measured on either build. Measure that cost and state it in Risks, then tick it.
mooki changed title from fix(vk): a finalized render target goes once the game has written over its storage to WIP: fix(vk): a finalized render target goes once the game has written over its storage 2026-11-17 20:51:50 +00:00
Author
Member

Thank you for adding the two boxes; they match what I know. Under the ready-for-review list (#1454) I have moved this back to WIP until one cost is measured and named in Risks: the texture pass's own time (tex_frame_ms), main against this head; I am answering the review separately. I will tick the box and mark it ready again when that number is in.

Thank you for adding the two boxes; they match what I know. Under the ready-for-review list (#1454) I have moved this back to WIP until one cost is measured and named in Risks: the texture pass's own time (`tex_frame_ms`), main against this head; I am answering the review separately. I will tick the box and mark it ready again when that number is in.
HumanBean left a comment

Verdict: Comment: would approve once out of WIP, because the code still reads correct and the Test Farm's one failure looks like noise from a single run, not this change. Two runs are still missing before I'd approve: the tex_frame_ms number you are measuring now, and the 20-minute Hyrule Field walk on an 8 GB or smaller card that this PR's Must be tested asks for.

For players: in long sessions, mostly while walking through terrain, the renderer stops keeping finalized 260 x 260 terrain tiles once the game has reused their memory, so render-target VRAM stops climbing lap after lap. The code is better for it: one rule in texture_frame's pass and a game-free test. No regression is shown.

Reviewed: 1c09f9d1 against 645d58e6 (its merge base). The head is unchanged since my last review, so jj interdiff is empty. I read gpu/vk/vk_texture.cpp's changed pass in full again, along with the code it relies on: the pre-count loop, keep_finalized, the sweep cadence (dead_every, sweep = total_bytes <= budget) and memory_written_runs. I skimmed tests/test_target_retention.* and tests/test_vram_compact.py. I read the three Test Farm reports in full. Nothing was run (a code review).
Fixed in this review: nothing. Both commits rebase onto current main (e8e92f97) with no conflict at all, and the interdiff against this head is empty. I didn't push that rebase, for three reasons: it resolves nothing, maintainer edits are off on this branch, and you are measuring on this head. Rebase it when you push the tex_frame_ms numbers (CONTRIBUTING's point 7).
Checked and fine: everything in my earlier review still holds (in-flight lifetime, no write-back of an obsolete texture, "written over" meaning what texture_touch re-uploads, the hold, keep cap and sweep handled consistently, the test failing on main for the bug's reason). The added CPU work is bounded. finalized_obsolete returns before reading memory for anything that isn't a released, GPU-drawn pool texture of 32 KB or more. For a tile it walks about 80 page generations, up to three times a pass. With the 20 to 130 kept tiles the logs show, that comes to tens of microseconds a pass, not milliseconds. Main's newer commits don't touch this pass (texture_alive at :2711 is the only change to vk_texture.cpp), and the description has the TL;DR and Breakdown that #1470 now asks for.

The Test Farm's failure: noise, not this PR (my reading)
The Windows target failed on one rule in one report: RTX 4070 (futondestroyer), Hyrule Field frame time p99 18.27 to 23.19 ms (+26.9%). I don't read it as a regression:

  • It is one run a side, 20 s each. Main's side of that run was unusually smooth: field max 20.7 ms, against 47 to 88 ms on main for the other two PCs. That leaves a very low p99 to compare against. p50 didn't move (16.67 to 16.62), and there were no stutters or hitches on either side.
  • The same scenario on the other two PCs doesn't show it: RX 9070 XT field p99 +3.5% (19.93 to 20.63), RTX 3070 8 GB +0% (19.88 to 19.89). The farm itself marks the 4070's report as disagreeing with its peers. The sticky's median over the two Windows reports is +15%, under the 20% line.
  • No mechanism in the diff fits a 5 ms p99 shift with no stutters. The work added per pass is tens of microseconds (above). Field VRAM is flat on all three PCs (+0% to +1.7%), so the PR isn't letting go of more than before in that window and making it again.
  • The Deku interior's numbers on the 9070 XT (max 148 ms, 1% low +75%) come from one long frame in one run. That report's p99 is +5.3%, and the other two PCs show -2.8% and -4.9%.

A rerun with more runs a side on the 4070 (@Beanstalk, runs: 3 for field-retention) would clear the beanstalk: failed label. I don't hold approval on it. Your tex_frame_ms measurement is the direct check of this PR's own cost, so it matters more than the farm's p99 here.

Suggestions (unchanged from my last review, the author may take or leave)

  • vk_texture.cpp:4580: limit the 3/4 rule to textures drawn_writeback covered (t.written_back_for == t.last_written), or apply keep_finalized's 4 MB cap, so the quarter the game didn't rewrite still has its texels in memory when the texture is made again.
  • vk_texture.cpp:5273: give these their own evict_reason instead of counting them as DRAWN_OVER.
  • vk_texture.cpp:5225: compute finalized_obsolete once per texture per pass.

Testing: what exists: the author's two-lap Linux run (RTX 4090 at a 6 GB allowance, 131 against 166 images in the clean lap), the game-free test, the suite by name against main, and the Test Farm. The farm passed on the RTX 3070 8 GB, passed on the RX 9070 XT (pictures 0 diff, VRAM flat) and failed on the RTX 4070 on field p99 (noise, above). The farm's plan can't count render-target images or show long-session growth, as it says itself. Still missing, and holding approval: tex_frame_ms main against this head (the unticked Nothing gets worse box), and a 20-minute Hyrule Field walk on an 8 GB or smaller card (Windows preferred) with the "image blocks (render targets)" line staying flat and no streaked ground. No Intel run either. That isn't required, since nothing here is vendor-specific.
Overlaps and merge order: #1339 (WIP) touches the same evict.push_back line and widens memory generations to uint64_t. Merge this first, and 1339 rebases over it (finalized_obsolete and the fixture's memory_written_runs stub follow the type). #1162 and #1223 touch vk_texture.cpp outside this pass: no conflict.

**Verdict: Comment: would approve once out of WIP, because** the code still reads correct and the Test Farm's one failure looks like noise from a single run, not this change. Two runs are still missing before I'd approve: the `tex_frame_ms` number you are measuring now, and the 20-minute Hyrule Field walk on an 8 GB or smaller card that this PR's *Must be tested* asks for. For players: in long sessions, mostly while walking through terrain, the renderer stops keeping finalized 260 x 260 terrain tiles once the game has reused their memory, so render-target VRAM stops climbing lap after lap. The code is better for it: one rule in `texture_frame`'s pass and a game-free test. No regression is shown. **Reviewed:** 1c09f9d1 against 645d58e6 (its merge base). The head is unchanged since my last review, so `jj interdiff` is empty. I read `gpu/vk/vk_texture.cpp`'s changed pass in full again, along with the code it relies on: the pre-count loop, `keep_finalized`, the sweep cadence (`dead_every`, `sweep = total_bytes <= budget`) and `memory_written_runs`. I skimmed `tests/test_target_retention.*` and `tests/test_vram_compact.py`. I read the three Test Farm reports in full. Nothing was run (a code review). **Fixed in this review:** nothing. Both commits rebase onto current main (e8e92f97) with no conflict at all, and the interdiff against this head is empty. I didn't push that rebase, for three reasons: it resolves nothing, maintainer edits are off on this branch, and you are measuring on this head. Rebase it when you push the `tex_frame_ms` numbers (CONTRIBUTING's point 7). **Checked and fine:** everything in my earlier review still holds (in-flight lifetime, no write-back of an obsolete texture, "written over" meaning what `texture_touch` re-uploads, the hold, keep cap and sweep handled consistently, the test failing on main for the bug's reason). The added CPU work is bounded. `finalized_obsolete` returns before reading memory for anything that isn't a released, GPU-drawn pool texture of 32 KB or more. For a tile it walks about 80 page generations, up to three times a pass. With the 20 to 130 kept tiles the logs show, that comes to tens of microseconds a pass, not milliseconds. Main's newer commits don't touch this pass (`texture_alive` at :2711 is the only change to `vk_texture.cpp`), and the description has the TL;DR and Breakdown that https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1470 now asks for. **The Test Farm's failure: noise, not this PR (my reading)** The Windows target failed on one rule in one report: RTX 4070 (futondestroyer), Hyrule Field frame time p99 18.27 to 23.19 ms (+26.9%). I don't read it as a regression: - It is one run a side, 20 s each. Main's side of that run was unusually smooth: field max 20.7 ms, against 47 to 88 ms on main for the other two PCs. That leaves a very low p99 to compare against. p50 didn't move (16.67 to 16.62), and there were no stutters or hitches on either side. - The same scenario on the other two PCs doesn't show it: RX 9070 XT field p99 +3.5% (19.93 to 20.63), RTX 3070 8 GB +0% (19.88 to 19.89). The farm itself marks the 4070's report as disagreeing with its peers. The sticky's median over the two Windows reports is +15%, under the 20% line. - No mechanism in the diff fits a 5 ms p99 shift with no stutters. The work added per pass is tens of microseconds (above). Field VRAM is flat on all three PCs (+0% to +1.7%), so the PR isn't letting go of more than before in that window and making it again. - The Deku interior's numbers on the 9070 XT (max 148 ms, 1% low +75%) come from one long frame in one run. That report's p99 is +5.3%, and the other two PCs show -2.8% and -4.9%. A rerun with more runs a side on the 4070 (`@Beanstalk`, `runs: 3` for field-retention) would clear the `beanstalk: failed` label. I don't hold approval on it. Your `tex_frame_ms` measurement is the direct check of this PR's own cost, so it matters more than the farm's p99 here. **Suggestions** (unchanged from my last review, the author may take or leave) - `vk_texture.cpp:4580`: limit the 3/4 rule to textures `drawn_writeback` covered (`t.written_back_for == t.last_written`), or apply `keep_finalized`'s 4 MB cap, so the quarter the game didn't rewrite still has its texels in memory when the texture is made again. - `vk_texture.cpp:5273`: give these their own `evict_reason` instead of counting them as DRAWN_OVER. - `vk_texture.cpp:5225`: compute `finalized_obsolete` once per texture per pass. **Testing:** what exists: the author's two-lap Linux run (RTX 4090 at a 6 GB allowance, 131 against 166 images in the clean lap), the game-free test, the suite by name against main, and the Test Farm. The farm passed on the RTX 3070 8 GB, passed on the RX 9070 XT (pictures 0 diff, VRAM flat) and failed on the RTX 4070 on field p99 (noise, above). The farm's plan can't count render-target images or show long-session growth, as it says itself. Still missing, and holding approval: `tex_frame_ms` main against this head (the unticked *Nothing gets worse* box), and a 20-minute Hyrule Field walk on an 8 GB or smaller card (Windows preferred) with the "image blocks (render targets)" line staying flat and no streaked ground. No Intel run either. That isn't required, since nothing here is vendor-specific. **Overlaps and merge order:** https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1339 (WIP) touches the same `evict.push_back` line and widens memory generations to `uint64_t`. Merge this first, and 1339 rebases over it (`finalized_obsolete` and the fixture's `memory_written_runs` stub follow the type). https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1162 and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1223 touch `vk_texture.cpp` outside this pass: no conflict.
HumanBean changed title from WIP: fix(vk): a finalized render target goes once the game has written over its storage to fix(vk): a finalized render target goes once the game has written over its storage 2026-11-17 21:22:06 +00:00
HumanBean deleted branch fix/finalized-target-obsolete 2026-11-17 21:22:16 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1462
No description provided.