WIP: perf(vk): an evicted GPU-drawn texture's write-back waits for nothing, so an area change no longer stalls the frame for it #2789

Draft
HumanBean wants to merge 1 commit from HumanBean/Longshot:perf/evict-writeback-no-wait into main
Owner

Summary

Evicting a texture the GPU drew could freeze the game for a third of a second. To evict such a texture, the renderer first copies its texels back into the game's memory. It recorded that copy, submitted it, and waited for it (readback_submit_wait) inside the present job. That drained the whole GPU queue, and the game's main thread waited the whole time on the present's fence. On an RX 580 (8 GB, RADV, at 6.6 of 7.4 GB of VRAM), one such frame took 320 ms: tex_frame_ms 318.7, main_blocked_ms 317.8. A comment at readback_submit_wait already noted a 317 ms wait at an area change.

Now the eviction write-back works the way the small drawn textures' write-backs already did (drawn_writeback_frame): nothing waits.

  • retire_record puts the texture's copies into this present's uploads, and the texture stays in the cache, retiring.
  • On a later frame, once the GPU is past the copies, retire_finish decides each texture's fate (evict_retire::step):
    • Write: the texels go into its memory, then it is destroyed.
    • Cancel: it was used, drawn into or finalized meanwhile, so it is live again and keeps its image.
    • Stale: another image drew over its storage since, so it goes without writing old texels over the newer ones.
    • Gone: it was destroyed another way; only its staging buffer is freed.
  • The budget counts retiring bytes as already going (evict_retire::pending), so it doesn't evict again for the same excess.
  • At most 512 MB of staging is out at once, as a batch held before.

RX_VK_EVICT_WRITEBACK_WAIT=1 restores the old wait unchanged (a kill switch, off by default).

Read first: gpu/vk/evict_retire.h, then retire_record/retire_finish and the eviction pass in gpu/vk/vk_texture.cpp.

Testing

Tested:

  • Through the job queue, --mode build:
    • Linux dev.py vk: the renderer builds.
    • RX_TARGET=windows with llvm-mingw: longshot_vk.dll links. Its exports check was skipped, because dev.py vk looks for a .so afterwards.
  • run_all.py --strict evict_ readback_timeout target_retention drawn_writeback: 6 of 6 pass. That includes the new tests/test_evict_retire.py (the rules and the source) and the updated stand-ins in test_readback_timeout_reuse.py (which now drives the switch-on path) and test_target_retention.cpp.
  • A full run_all.py had 15 failures outside this change (launcher switch table, guest holes, lifter, input, …). Whether each also fails on main isn't checked yet.
  • No game-free test can show the bug: it is a GPU fence wait in the present job.
  • In the game: Linux (CachyOS), AMD RX 580 8 GB, Mesa 26.2.6 RADV, i7-9700K at about 4.6 GHz. Build: main 894683cf with this branch (and #2790) merged. 2560x1440 output, 1920x1080 internal, no upscaler, uncapped. Each run is 3 laps of: warp to the Market, walk back into Hyrule Field, forward for 30 s (about 6 min). Runs went new, old, new, old, with the old side set by RX_VK_EVICT_WRITEBACK_WAIT=1.
    • The new path ran cleanly. vk: 7 evicted textures the GPU drew retired after their copies, 7 written into their memory in 2.5 ms, 1 frames after. Each run had 7–9 such textures, 3–15 ms in all, with 0 failed and 0 gone meanwhile.
    • The 320 ms stall didn't reproduce on this route on either side. tex_frame_ms stayed ≤ 0.6 ms in every worst frame, so this route can't show the gain. The stall was seen in free play, at about 6.6 of 7.4 GB of VRAM.
    • "goes with no copy of its texels" lines: about 70 per run on both sides. They are render targets unused for 192+ frames and over the budget, so they don't come from this change.
    • Screenshots after each area change are still to be checked for garbled textures.

Still to test:

  • Linux, AMD RX 580 8 GB: a route that hits the eviction stall (free play into heavy areas at about 6.6/7.4 GB of VRAM). Expect no 300 ms tex_frame_ms frames, against RX_VK_EVICT_WRITEBACK_WAIT=1 (by hand).
  • The same PC: the run's screenshots after area changes, for garbled or empty textures (by hand).
  • Windows, NVIDIA and AMD: the same area change; no garbled or empty textures (@Beanstalk).

Measurements

Verdict: no change on this route, inside the run-to-run spread both ways. The stall it removes didn't happen in these runs. It is a correctness-neutral removal of a wait that was seen at 320 ms in free play.

Setup: as in Tested; 2 runs each side, interleaved; frames.csv (RX_VK_FRAME_TRACE=1) and the log.

Before: RX_VK_EVICT_WRITEBACK_WAIT=1 (main's path) After: this PR @ f6f32217
median fps (run 1 / run 2) 41.1 / 40.7 39.9 / 40.9
1% low fps 13.3 / 11.4 11.7 / 9.9
frames ≥50 / ≥100 / ≥250 ms 73/26/4, 84/33/10 76/33/9, 79/45/10
worst frame 415 / 401 ms 399 / 616 ms
worst frames' tex_frame_ms ≤ 0.6 ms ≤ 0.6 ms

The ≥250 ms frames on both sides are area-change texture uploads (about 100–200 MB in one frame) and the game's own loading, not evictions.

Risks

  • Texels later: an evicted texture's texels reach the game's memory 2 or more frames later. Guest writes in that gap are kept by memory_written_runs, at page granularity.
  • VRAM later: VRAM is released a few frames later, which matters on 8 GB cards. Retiring bytes are counted as pending so the budget doesn't over-evict.
  • Shutdown: retiring staging buffers are not freed at shutdown, as the drawn write-back batches already aren't.
  • Turning it off: RX_VK_EVICT_WRITEBACK_WAIT=1, or revert.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (15 failures outside this change, not yet checked against main.)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here. (No game-free test can show a GPU fence wait; the rules have their own test.)
  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def. (A kill switch, off.)
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary Evicting a texture the GPU drew could freeze the game for a third of a second. To evict such a texture, the renderer first copies its texels back into the game's memory. It recorded that copy, submitted it, and waited for it (`readback_submit_wait`) inside the present job. That drained the whole GPU queue, and the game's main thread waited the whole time on the present's fence. On an RX 580 (8 GB, RADV, at 6.6 of 7.4 GB of VRAM), one such frame took **320 ms**: `tex_frame_ms 318.7, main_blocked_ms 317.8`. A comment at `readback_submit_wait` already noted a 317 ms wait at an area change. Now the eviction write-back works the way the small drawn textures' write-backs already did (`drawn_writeback_frame`): nothing waits. - `retire_record` puts the texture's copies into this present's uploads, and the texture stays in the cache, retiring. - On a later frame, once the GPU is past the copies, `retire_finish` decides each texture's fate (`evict_retire::step`): - **Write:** the texels go into its memory, then it is destroyed. - **Cancel:** it was used, drawn into or finalized meanwhile, so it is live again and keeps its image. - **Stale:** another image drew over its storage since, so it goes without writing old texels over the newer ones. - **Gone:** it was destroyed another way; only its staging buffer is freed. - The budget counts retiring bytes as already going (`evict_retire::pending`), so it doesn't evict again for the same excess. - At most 512 MB of staging is out at once, as a batch held before. `RX_VK_EVICT_WRITEBACK_WAIT=1` restores the old wait unchanged (a kill switch, off by default). Read first: `gpu/vk/evict_retire.h`, then `retire_record`/`retire_finish` and the eviction pass in `gpu/vk/vk_texture.cpp`. ## Testing **Tested:** - Through the job queue, `--mode build`: - Linux `dev.py vk`: the renderer builds. - `RX_TARGET=windows` with llvm-mingw: `longshot_vk.dll` links. Its exports check was skipped, because `dev.py vk` looks for a `.so` afterwards. - `run_all.py --strict evict_ readback_timeout target_retention drawn_writeback`: 6 of 6 pass. That includes the new `tests/test_evict_retire.py` (the rules and the source) and the updated stand-ins in `test_readback_timeout_reuse.py` (which now drives the switch-on path) and `test_target_retention.cpp`. - A full `run_all.py` had 15 failures outside this change (launcher switch table, guest holes, lifter, input, …). Whether each also fails on `main` isn't checked yet. - No game-free test can show the bug: it is a GPU fence wait in the present job. - **In the game:** Linux (CachyOS), AMD RX 580 8 GB, Mesa 26.2.6 RADV, i7-9700K at about 4.6 GHz. Build: main `894683cf` with this branch (and #2790) merged. 2560x1440 output, 1920x1080 internal, no upscaler, uncapped. Each run is 3 laps of: warp to the Market, walk back into Hyrule Field, forward for 30 s (about 6 min). Runs went new, old, new, old, with the old side set by `RX_VK_EVICT_WRITEBACK_WAIT=1`. - **The new path ran cleanly.** `vk: 7 evicted textures the GPU drew retired after their copies, 7 written into their memory in 2.5 ms, 1 frames after`. Each run had 7–9 such textures, 3–15 ms in all, with 0 failed and 0 gone meanwhile. - **The 320 ms stall didn't reproduce on this route on either side.** `tex_frame_ms` stayed ≤ 0.6 ms in every worst frame, so this route can't show the gain. The stall was seen in free play, at about 6.6 of 7.4 GB of VRAM. - **"goes with no copy of its texels" lines:** about 70 per run on both sides. They are render targets unused for 192+ frames and over the budget, so they don't come from this change. - **Screenshots** after each area change are still to be checked for garbled textures. **Still to test:** - Linux, AMD RX 580 8 GB: a route that hits the eviction stall (free play into heavy areas at about 6.6/7.4 GB of VRAM). Expect no 300 ms `tex_frame_ms` frames, against `RX_VK_EVICT_WRITEBACK_WAIT=1` (by hand). - The same PC: the run's screenshots after area changes, for garbled or empty textures (by hand). - Windows, NVIDIA and AMD: the same area change; no garbled or empty textures (@Beanstalk). ## Measurements **Verdict:** no change on this route, inside the run-to-run spread both ways. The stall it removes didn't happen in these runs. It is a correctness-neutral removal of a wait that was seen at 320 ms in free play. Setup: as in Tested; 2 runs each side, interleaved; frames.csv (`RX_VK_FRAME_TRACE=1`) and the log. | | Before: `RX_VK_EVICT_WRITEBACK_WAIT=1` (main's path) | After: this PR @ f6f32217 | |---|---|---| | median fps (run 1 / run 2) | 41.1 / 40.7 | 39.9 / 40.9 | | 1% low fps | 13.3 / 11.4 | 11.7 / 9.9 | | frames ≥50 / ≥100 / ≥250 ms | 73/26/4, 84/33/10 | 76/33/9, 79/45/10 | | worst frame | 415 / 401 ms | 399 / 616 ms | | worst frames' `tex_frame_ms` | ≤ 0.6 ms | ≤ 0.6 ms | The ≥250 ms frames on both sides are area-change texture uploads (about 100–200 MB in one frame) and the game's own loading, not evictions. ## Risks - **Texels later:** an evicted texture's texels reach the game's memory 2 or more frames later. Guest writes in that gap are kept by `memory_written_runs`, at page granularity. - **VRAM later:** VRAM is released a few frames later, which matters on 8 GB cards. Retiring bytes are counted as pending so the budget doesn't over-evict. - **Shutdown:** retiring staging buffers are not freed at shutdown, as the drawn write-back batches already aren't. - **Turning it off:** `RX_VK_EVICT_WRITEBACK_WAIT=1`, or revert. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). (15 failures outside this change, not yet checked against `main`.) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [ ] A fix: a game-free test that fails on `main` and passes here. (No game-free test can show a GPU fence wait; the rules have their own test.) - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. (A kill switch, off.) - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
perf(vk): an evicted GPU-drawn texture's write-back waits for nothing: its copies go with the present's uploads and a later present writes it back
Some checks failed
CI / What the change needs (pull_request) Successful in 13s
CI / Third-party parts and guide screenshots (pull_request) Failing after 16s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 16s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 2m12s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 4m4s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m28s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m37s
CI / Website build and checks (pull_request) Successful in 1m37s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 18m58s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 39m22s
PR description / Title and description (pull_request_target) Successful in 4s
f6f3221773
texture_frame's eviction submitted its write-backs and waited for them in the present job (readback_submit_wait), the
queue drained behind it: a 320 ms frame on an RX 580 (tex_frame_ms 318.7, main_blocked_ms 317.8) for one texture.
Now the copies are recorded into upload_cmd() and the texture stays in the cache, retiring (evict_retire.h), its bytes
counted as pending, until completed_value passes the copies' value: then retire_finish writes it back (as before, the
CPU's pages since kept) and destroys it. One used, drawn into or finalized meanwhile is live again; one drawn over by
another image since is not written back. RX_VK_EVICT_WRITEBACK_WAIT=1 keeps the old wait (a kill switch).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member

Possibly related, for context:

  • PR #282 WIP: perf(vk): re-upload only the part of a texture a GPU write covered — Open Vulkan texture write-back/performance work; check shared texture code and conflict overlap
  • PR #941 WIP: fix(vk): a remap's write-back no longer puts an older target's texels over an image drawn inside it — Open Vulkan write-back stale-storage handling intersects eviction retirement rules
  • PR #2054 WIP: perf(vk): dead render targets are let go as they die, and a texture's end invalidates handles only when it must (RX_VK_RETIRE_LAZY=0 to disable) — Open texture retirement/eviction-pass work may overlap retire logic
  • PR #875 WIP: perf(vk): below 60 fps the eviction's waits are seconds, not presents: the compaction's hold and the GPU-drawn textures' keep — Open PR changes GPU-drawn texture eviction retention and related waits
Possibly related, for context: - PR #282 WIP: perf(vk): re-upload only the part of a texture a GPU write covered — Open Vulkan texture write-back/performance work; check shared texture code and conflict overlap - PR #941 WIP: fix(vk): a remap's write-back no longer puts an older target's texels over an image drawn inside it — Open Vulkan write-back stale-storage handling intersects eviction retirement rules - PR #2054 WIP: perf(vk): dead render targets are let go as they die, and a texture's end invalidates handles only when it must (RX_VK_RETIRE_LAZY=0 to disable) — Open texture retirement/eviction-pass work may overlap retire logic - PR #875 WIP: perf(vk): below 60 fps the eviction's waits are seconds, not presents: the compaction's hold and the GPU-drawn textures' keep — Open PR changes GPU-drawn texture eviction retention and related waits
Author
Owner
@review
BeanBot left a comment

Recommendation: Request changes. A retiring write-back can outlive a guest-memory remap and write the old texture into the new mapping. The claimed reduction in the eviction stall also remains unproven on the measured route.

The change moves eviction copies into the present submission and defers their write-back and destruction, avoiding an explicit GPU wait in the eviction pass. It keeps images and staging memory alive longer and adds a kill switch; the delayed write-back needs to account for memory remapping.

Blocking (1): must change before merging.

  1. L1 gpu/vk/vk_texture.cpp:5989: A pending retirement is not cancelled or completed when the texture's guest pages are remapped. (more on the line) Do: Resolve or cancel overlapping retirement entries before the mapping changes, and add a test covering a remap between recording and retirement completion.

Should fix (1): not blocking, but worth doing before merging.

  • L2 tests/test_evict_retire.py:8: The new check hard-codes g++ instead of using the compiler selected by the test runner. (more on the line) Do: Use the runner's {cxx} placeholder and make the standalone default respect the configured compiler.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L3 gpu/vk/vk_texture.cpp:6833: The measured route did not exercise the stall this change is intended to remove. (more on the line) Do: Run interleaved base and branch measurements on a reproducible eviction-heavy route, including frame-time tails and RAM and VRAM usage.
  • L4 gpu/vk/vk_texture.cpp:5950: The deferred write-back and image lifetime have not been checked on the supported Tier 1 systems. (more on the line) Do: Check the recorded screenshots and run eviction-heavy area changes on the affected Tier 1 Windows and Linux hardware and Steam Deck, checking texture correctness and memory pressure.

@fix can do L1 and L2.

Checks: Failing on this head, which is behind its base, where they pass: CI / Third-party parts and guide screenshots (pull_request), CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request), CI / Game-free checks (run_all.py, part 1/2) (pull_request), CI / Game-free checks (run_all.py, part 2/2) (pull_request). @rebase (or @fix) brings it up to date and runs them again; not held against it.

More: does it help, other systems, switches, what was read

Does it help: Unproven. The PR reports a 320 ms eviction stall in free play, but it did not recur on either side of the two interleaved runs. Median fps was 40.7–41.1 before and 39.9–40.9 after; the reported 1% lows were 11.4–13.3 before and 9.9–11.7 after.

Other systems: The default path affects texture eviction, guest-memory write-back, GPU submissions and memory pressure on both Windows and Linux and across GPU vendors. The reported game run covers Linux RADV on an RX 580; screenshots and Tier 1 Windows, Linux and Steam Deck coverage remain outstanding.

Switches: RX_VK_EVICT_WRITEBACK_WAIT is added, default off; setting it to 1 restores the synchronous path. It has a switches.def row, but measurements have not yet established the default's benefit or costs across supported systems.

Reviewed: f6f3221773 against 3ab4db6e91: Read the repository rules, PR template, standards, diff, commit, new retirement header and tests, and the changed eviction and read-back code with its relevant callers. Skimmed the remaining portions of the large changed files and existing test fixtures; ../Tooling/AGENTS.md and docs/review-checklist.md were absent.; nothing run (a code review).

Checked and fine:

  • The commit records AI assistance.
  • The switch has a table entry, and the diff does not change the renderer API or shader sources.
  • The existing synchronous read-back timeout fixture explicitly selects the switch-on path.

Testing: No commands from the project were run, as requested. The PR reports successful Linux and Windows renderer builds and six targeted checks; its full test run had 15 failures not yet compared with the base.

Overlaps and merge order: Not checked; network access is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** A retiring write-back can outlive a guest-memory remap and write the old texture into the new mapping. The claimed reduction in the eviction stall also remains unproven on the measured route. The change moves eviction copies into the present submission and defers their write-back and destruction, avoiding an explicit GPU wait in the eviction pass. It keeps images and staging memory alive longer and adds a kill switch; the delayed write-back needs to account for memory remapping. **Blocking (1)**: must change before merging. 1. **L1** `gpu/vk/vk_texture.cpp:5989`: A pending retirement is not cancelled or completed when the texture's guest pages are remapped. (more on the line) **Do:** Resolve or cancel overlapping retirement entries before the mapping changes, and add a test covering a remap between recording and retirement completion. **Should fix (1)**: not blocking, but worth doing before merging. - **L2** `tests/test_evict_retire.py:8`: The new check hard-codes g++ instead of using the compiler selected by the test runner. (more on the line) **Do:** Use the runner's {cxx} placeholder and make the standalone default respect the configured compiler. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L3** `gpu/vk/vk_texture.cpp:6833`: The measured route did not exercise the stall this change is intended to remove. (more on the line) **Do:** Run interleaved base and branch measurements on a reproducible eviction-heavy route, including frame-time tails and RAM and VRAM usage. - **L4** `gpu/vk/vk_texture.cpp:5950`: The deferred write-back and image lifetime have not been checked on the supported Tier 1 systems. (more on the line) **Do:** Check the recorded screenshots and run eviction-heavy area changes on the affected Tier 1 Windows and Linux hardware and Steam Deck, checking texture correctness and memory pressure. `@fix` can do L1 and L2. **Checks:** Failing on this head, which is behind its base, where they pass: `CI / Third-party parts and guide screenshots (pull_request)`, `CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request)`, `CI / Game-free checks (run_all.py, part 1/2) (pull_request)`, `CI / Game-free checks (run_all.py, part 2/2) (pull_request)`. `@rebase` (or `@fix`) brings it up to date and runs them again; not held against it. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The PR reports a 320 ms eviction stall in free play, but it did not recur on either side of the two interleaved runs. Median fps was 40.7–41.1 before and 39.9–40.9 after; the reported 1% lows were 11.4–13.3 before and 9.9–11.7 after. **Other systems:** The default path affects texture eviction, guest-memory write-back, GPU submissions and memory pressure on both Windows and Linux and across GPU vendors. The reported game run covers Linux RADV on an RX 580; screenshots and Tier 1 Windows, Linux and Steam Deck coverage remain outstanding. **Switches:** RX_VK_EVICT_WRITEBACK_WAIT is added, default off; setting it to 1 restores the synchronous path. It has a switches.def row, but measurements have not yet established the default's benefit or costs across supported systems. **Reviewed:** f6f32217731d against 3ab4db6e9154: Read the repository rules, PR template, standards, diff, commit, new retirement header and tests, and the changed eviction and read-back code with its relevant callers. Skimmed the remaining portions of the large changed files and existing test fixtures; ../Tooling/AGENTS.md and docs/review-checklist.md were absent.; nothing run (a code review). **Checked and fine:** - The commit records AI assistance. - The switch has a table entry, and the diff does not change the renderer API or shader sources. - The existing synchronous read-back timeout fixture explicitly selects the switch-on path. **Testing:** No commands from the project were run, as requested. The PR reports successful Linux and Windows renderer builds and six targeted checks; its full test run had 15 failures not yet compared with the base. **Overlaps and merge order:** Not checked; network access is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -5895,0 +5947,4 @@
}
/// The retiring textures the GPU is done copying: their texels into their memory where the texture is still as it was chosen,
/// then their end; the ones used since live again
void retire_finish() {
Member

L4 (should fix): The deferred write-back and image lifetime have not been checked on the supported Tier 1 systems.

When: The only reported game run uses Linux RADV on an RX 580, and its screenshots have not yet been checked; the changed GPU copy and memory-pressure behavior also runs on Windows, other drivers and Steam Deck.

Do: Check the recorded screenshots and run eviction-heavy area changes on the affected Tier 1 Windows and Linux hardware and Steam Deck, checking texture correctness and memory pressure.

**L4** (should fix): The deferred write-back and image lifetime have not been checked on the supported Tier 1 systems. *When:* The only reported game run uses Linux RADV on an RX 580, and its screenshots have not yet been checked; the changed GPU copy and memory-pressure behavior also runs on Windows, other drivers and Steam Deck. **Do:** Check the recorded screenshots and run eviction-heavy area changes on the affected Tier 1 Windows and Linux hardware and Steam Deck, checking texture correctness and memory pressure.
@ -5895,0 +5986,4 @@
}
bool ok = false;
if (s == evict_retire::Step::Write) {
ok = flush_finish(r.f, true); // (frees its staging buffer)
Member

L1 (blocking): A pending retirement is not cancelled or completed when the texture's guest pages are remapped.

When: After retire_record captures a texture, vmap_changing can call texture_flush_to_guest for an overlapping range before the GPU copy completes. That writes the old mapping before the remap, but leaves the retirement entry alive; retire_finish later writes its captured texels through the same GPU address into the replacement mapping, corrupting its contents.

Do: Resolve or cancel overlapping retirement entries before the mapping changes, and add a test covering a remap between recording and retirement completion.

**L1** (blocking): A pending retirement is not cancelled or completed when the texture's guest pages are remapped. *When:* After retire_record captures a texture, vmap_changing can call texture_flush_to_guest for an overlapping range before the GPU copy completes. That writes the old mapping before the remap, but leaves the retirement entry alive; retire_finish later writes its captured texels through the same GPU address into the replacement mapping, corrupting its contents. **Do:** Resolve or cancel overlapping retirement entries before the mapping changes, and add a test covering a remap between recording and retirement completion.
@ -6691,2 +6831,3 @@
// which go once the GPU is past their copies: retire_finish)
std::unordered_set<const Texture*> flush_later;
{ // (the write-backs: batches of up to 64 textures or ~512 MB of staging memory, each one submission and one wait)
if (!evict_writeback_wait()) { // (the write-backs: their copies with this present's uploads, finished later: retire_finish)
Member

L3 (should fix): The measured route did not exercise the stall this change is intended to remove.

When: Both paths stayed at or below 0.6 ms of texture-frame time in their worst frames, so the reported runs cannot show whether the asynchronous path removes the observed 320 ms eviction stall.

Do: Run interleaved base and branch measurements on a reproducible eviction-heavy route, including frame-time tails and RAM and VRAM usage.

**L3** (should fix): The measured route did not exercise the stall this change is intended to remove. *When:* Both paths stayed at or below 0.6 ms of texture-frame time in their worst frames, so the reported runs cannot show whether the asynchronous path removes the observed 320 ms eviction stall. **Do:** Run interleaved base and branch measurements on a reproducible eviction-heavy route, including frame-time tails and RAM and VRAM usage.
@ -0,0 +5,4 @@
import tempfile
from pathlib import Path
RUN_ALL_ARGS = ["--cxx", "g++"]
Member

L2 (should fix): The new check hard-codes g++ instead of using the compiler selected by the test runner.

When: On a supported Windows or Linux test machine with clang++ selected and no g++ installed, run_all skips this check, or fails it in strict mode, even though a supported C++ compiler is available.

Do: Use the runner's {cxx} placeholder and make the standalone default respect the configured compiler.

**L2** (should fix): The new check hard-codes g++ instead of using the compiler selected by the test runner. *When:* On a supported Windows or Linux test machine with clang++ selected and no g++ installed, run_all skips this check, or fails it in strict mode, even though a supported C++ compiler is available. **Do:** Use the runner's {cxx} placeholder and make the standalone default respect the configured compiler.
HumanBean force-pushed perf/evict-writeback-no-wait from f6f3221773
Some checks failed
CI / What the change needs (pull_request) Successful in 13s
CI / Third-party parts and guide screenshots (pull_request) Failing after 16s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 16s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 2m12s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 4m4s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m28s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m37s
CI / Website build and checks (pull_request) Successful in 1m37s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 18m58s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 39m22s
PR description / Title and description (pull_request_target) Successful in 4s
to 2d07f9f257
Some checks failed
PR description / Title and description (pull_request_target) Successful in 14s
CI / What the change needs (pull_request) Successful in 14s
CI / Third-party parts and guide screenshots (pull_request) Failing after 24s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 23s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 4m10s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 2m1s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 3m50s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 3m39s
CI / Website build and checks (pull_request) Successful in 2m0s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 18m23s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 39m24s
2026-11-29 16:44:10 +00:00
Compare
Author
Owner

Review addressed in 2d07f9f2 (amended into the one commit).

L1 (remap between recording and retirement): fixed. texture_flush_to_guest (what vmap_changing calls) now first calls retire_cancel_remapped(lo, hi): every retirement whose storage overlaps the range is marked remapped, and its texture, if still in the cache under the same id, is live again (retiring = false), so the loop below writes it into the old mapping right then. evict_retire::step takes remapped and returns a new Step::Remapped once the GPU is past the copies: only the staging buffer is freed, nothing goes through the GPU address into the new mapping. The staging buffer still waits for the copies (Wait comes first). retire_finish also skips a remapped entry's texture lookup, so a texture chosen again after the remap gets a fresh entry and the old one can't act on it. tests/test_evict_retire.cpp gets the remap cases (remapped and copies still running → Wait; remapped → Remapped, also when gone meanwhile or drawn over), and the Python source check pins the call in texture_flush_to_guest. The architecture page says what a remap does to a retiring texture.

L2 (hard-coded g++): fixed. RUN_ALL_ARGS = ["--cxx", "{cxx}"]; standalone, the default is $CXX, else c++. Passes with g++ and clang++.

L3 / L4 (eviction-heavy A/B, Tier 1 hardware): not done in this push. They need game runs, and none were run for this update. The open measurement and the Windows, Linux and Steam Deck coverage still stand; the PR stays WIP until they're done.

Checks: test_evict_retire.py (g++ and clang++), test_readback_timeout_reuse.py and test_target_retention.py pass; the renderer compiles for Linux (a pack on the shared base).

Review addressed in 2d07f9f2 (amended into the one commit). **L1 (remap between recording and retirement): fixed.** `texture_flush_to_guest` (what `vmap_changing` calls) now first calls `retire_cancel_remapped(lo, hi)`: every retirement whose storage overlaps the range is marked `remapped`, and its texture, if still in the cache under the same id, is live again (`retiring = false`), so the loop below writes it into the old mapping right then. `evict_retire::step` takes `remapped` and returns a new `Step::Remapped` once the GPU is past the copies: only the staging buffer is freed, nothing goes through the GPU address into the new mapping. The staging buffer still waits for the copies (`Wait` comes first). `retire_finish` also skips a remapped entry's texture lookup, so a texture chosen again after the remap gets a fresh entry and the old one can't act on it. `tests/test_evict_retire.cpp` gets the remap cases (remapped and copies still running → Wait; remapped → Remapped, also when gone meanwhile or drawn over), and the Python source check pins the call in `texture_flush_to_guest`. The architecture page says what a remap does to a retiring texture. **L2 (hard-coded g++): fixed.** `RUN_ALL_ARGS = ["--cxx", "{cxx}"]`; standalone, the default is `$CXX`, else `c++`. Passes with g++ and clang++. **L3 / L4 (eviction-heavy A/B, Tier 1 hardware): not done in this push.** They need game runs, and none were run for this update. The open measurement and the Windows, Linux and Steam Deck coverage still stand; the PR stays WIP until they're done. Checks: `test_evict_retire.py` (g++ and clang++), `test_readback_timeout_reuse.py` and `test_target_retention.py` pass; the renderer compiles for Linux (a pack on the shared base).
Some checks failed
PR description / Title and description (pull_request_target) Successful in 14s
CI / What the change needs (pull_request) Successful in 14s
CI / Third-party parts and guide screenshots (pull_request) Failing after 24s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 23s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 4m10s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 2m1s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 3m50s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 3m39s
CI / Website build and checks (pull_request) Successful in 2m0s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 18m23s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 39m24s
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/evict-writeback-no-wait:HumanBean-perf/evict-writeback-no-wait'
git switch 'HumanBean-perf/evict-writeback-no-wait'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 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!2789
No description provided.