fix(vk): simulated-turf lists keep the game's size in areas without turf, so Hyrule Field no longer stalls 250 ms at a time on the way in #2174

Merged
HumanBean merged 2 commits from HumanBean/Longshot:fix/sim-turf-stock-floor into main 2026-11-22 01:21:42 +00:00
Owner

Summary

Walking from Market back into Hyrule Field drops the game to about 1 fps for 10 to 15 seconds when RX_VK_SIM_TURF_ADAPTIVE is on, as it is by default. A player's log, Windows on an RTX 4070 SUPER (NVIDIA 621.24) at main @ 9e10f6f7, shows four vk: a capture's wait for write-back N timed out lines, each followed by slow submit: 250 ms: dispatch 250. It also shows GPU time 140.3 ms a frame (the longest submission 4062.9 ms) and 1.5 fps, then 0.3 fps. With RX_VK_SIM_TURF_ADAPTIVE=0 none of this happens.

Cause. #2093 made the six simulated-turf lists' private buffers adaptive, with a floor of 0 records (SimTurfPrivate's policy, gpu/vk/vk_draw.cpp). Market has no simulated turf. After 600 quiet frames every list there is released to 0 records (the log's resized 143360 -> 0). Back in Hyrule Field:

  • the producers run on empty lists, so sim_turf_sample_demand copies nothing into the game's own records (mirror_span is 0);
  • demand reads back only when the recording slot comes round;
  • the lists then grow from 0 one at a time (resized 0 -> 21312, 0 -> 32, 0 -> 4864, ...). Each growth's first copy into the game's records is a new write-back. A capture then waits on it with no stamps to fix the page from: the log's late-pages line counts exactly 4 no stamps or shadow yet, one per 250 ms timeout.

With the switch off, the lists stay at the game's size, the copy runs on every producer dispatch, and nothing comes back from empty.

This change. The floor is the game's own size: 143360 blade records and 138240 pool records. A list still grows above that with 25 % headroom for dense settings, which is #2093's gain, and still shrinks back after the quiet window, but no further than stock. The memory given up is the space below stock, about 28 MB for all six lists. This also means a list is never 0 records, so the blade producer's max(cap, 1) - 1 guard can no longer let record 0 through on an empty list. Today that write is out of bounds wherever robust buffer access is off.

Read first: SimTurfPrivate in gpu/vk/vk_draw.cpp, then Policy::observe in gpu/vk/sim_turf_capacity.h (unchanged).

See #2093.

This pull request was written with AI assistance (Claude Code).

Testing

Tested: Linux (CachyOS, kernel 7.3), RTX 3090, NVIDIA 620.70.06, headless through the job queue (--mode shared). The route, driven by the control bridge: the market-entrance save → Hyrule Field for 1500 frames → Market for 1800 frames, long enough for the 600-frame quiet window → Hyrule Field for 1500 frames. It ran twice on main @ 9e10f6f7 (its own renderer pack: the shared base 8aa74983 predates #2093) and twice here @ 892837ad.

  • main, run 1: all six lists shrank to 0 in Market (resized 1216 -> 0 ...). Back in Hyrule Field they grew from 0 one at a time (resized 0 -> 1792, 0 -> 32, 32 -> 1664 ...). There were 2 a capture's wait for write-back ... timed out and 0.4, then 0.2 fps for about 15 s. The longest submission was 3752.8 ms.
  • main, run 2: the same shrink to 0 in Market. Back in Hyrule Field, one write-back timeout, then the GPU hung: vk: FATAL: the GPU hung: no submission finished in 30 s. The last checkpoint before the hang is dispatch of program d5a9475f2790532e, the blade list's producer.
  • Here, both runs: no list was resized, there were no write-back timeouts in Hyrule Field, the longest submission on the way in 10.9 ms, and 57–60 fps once it had loaded. Run 2 fell to 2.6 fps for 5 s while the area loaded, from texture uploads (a frame's uploads took 440 ms), with no GPU stall. In run 1 the stop in Market on the way in had 5 write-back timeouts and a 2499 ms submission. No turf list changed size there, and run 2 did not show it; main run 1 also fell to 2–6 fps at the same place. The PC was swapping heavily during those runs (about 31 GB of swap in use).
  • tests/test_sim_turf_floor.py (new) cuts SimTurfPrivate out of vk_draw.cpp and builds it against the real sim_turf_capacity.h. It plays 700 frames with no demand (Market), then Hyrule Field's 17013 blades and 10069 pool records. It expects both lists to stay at stock, with no resize on the way back in. It has not run on this PC; CI runs it. It should fail on main, with the lists at 0, and pass here.

Still to test:

  • Windows NVIDIA, the reporter's setup: Market → Hyrule Field, expecting no a capture's wait for write-back ... timed out and no drop to 1 fps (@Beanstalk Windows NVIDIA: Market to Hyrule Field with simulated turf on its defaults)
  • AMD: the same walk, expecting no change from main apart from the stalls (@Beanstalk AMD)
  • Dense settings (Turf density high in Hyrule Field): the lists still grow above stock without flicker (by hand)
  • tests/test_sim_turf_floor.py both ways and the whole suite, expecting a failure on main and passes here (by hand, or CI)

Measurements

Verdict: it removes the stall on the way back into Hyrule Field. On main the return fell to 0.2–0.4 fps with seconds-long submissions in one run, and hung the GPU in the other. Here both returns ran at 57–60 fps once loaded, with no submission over 11 ms.

Setup: Linux, RTX 3090, NVIDIA 620.70.06, the route above, headless at 1920x1080, two runs a side (main, fix, then main and fix side by side). Read from the log: a capture's wait for write-back ... timed out, GPU time ... (the longest submission ...) and vi: ... fps over the last ..., from the map change into Hyrule Field to the end of the route.

Back into Hyrule Field, by run Before: main @ 9e10f6f7 After: this PR @ 892837ad
Turf lists resized from 0 6 / the run hung first 0 / 0
Write-back timeouts (250 ms each) 2 / 1, then a 30 s GPU hang 0 / 0
The longest submission (ms) 3752.8 / the GPU hung (30 s) 10.9 / 4.8
The lowest 5 s frame rate from the map change (fps) 0.2 / the GPU hung 46.3 / 2.6 (the area's ASTC uploads while it loaded: a frame's uploads took 440 ms; no GPU stall)
The 5 s frame rate once loaded (fps) 53.5 / the GPU hung 59.5 / 57.1

Risks

  • Memory: the lists no longer go below the game's size, so up to about 28 MB of GPU memory stays held in areas without turf, or with simulated turf set to off. That is the same as RX_VK_SIM_TURF_ADAPTIVE=0 and as before #2093.
  • Turning simulated turf off in the menu (Fade start 0, Minimum blades 0) still hides it. It no longer frees the lists' memory below stock.
  • To turn it off: a revert is enough. RX_VK_SIM_TURF_ADAPTIVE=0 still keeps the lists at stock, as before.
  • Players notice nothing in their files: no settings or caches change.

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). (CI runs it; not run on this PC)
  • 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. (written; not run on this PC, its CI result both ways to come)
  • A check under tests/ that reads changed source is updated, not weakened. (the checks that read vk_draw.cpp cut other functions; SimTurfPrivate is read only by the new one)
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (built on Linux in the renderer pack; Windows by CI)
  • 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

https://claude.ai/code/session_017vw8e164QuKZTgE7GGxxT5

## Summary **Walking from Market back into Hyrule Field drops the game to about 1 fps for 10 to 15 seconds when `RX_VK_SIM_TURF_ADAPTIVE` is on, as it is by default.** A player's log, Windows on an RTX 4070 SUPER (NVIDIA 621.24) at `main` @ `9e10f6f7`, shows four `vk: a capture's wait for write-back N timed out` lines, each followed by `slow submit: 250 ms: dispatch 250`. It also shows `GPU time 140.3 ms a frame (the longest submission 4062.9 ms)` and `1.5 fps`, then `0.3 fps`. With `RX_VK_SIM_TURF_ADAPTIVE=0` none of this happens. **Cause.** #2093 made the six simulated-turf lists' private buffers adaptive, with a floor of 0 records (`SimTurfPrivate`'s policy, `gpu/vk/vk_draw.cpp`). Market has no simulated turf. After 600 quiet frames every list there is released to 0 records (the log's `resized 143360 -> 0`). Back in Hyrule Field: - the producers run on empty lists, so `sim_turf_sample_demand` copies nothing into the game's own records (`mirror_span` is 0); - demand reads back only when the recording slot comes round; - the lists then grow from 0 one at a time (`resized 0 -> 21312`, `0 -> 32`, `0 -> 4864`, ...). Each growth's first copy into the game's records is a new write-back. A capture then waits on it with no stamps to fix the page from: the log's late-pages line counts exactly `4 no stamps or shadow yet`, one per 250 ms timeout. With the switch off, the lists stay at the game's size, the copy runs on every producer dispatch, and nothing comes back from empty. **This change.** The floor is the game's own size: 143360 blade records and 138240 pool records. A list still grows above that with 25 % headroom for dense settings, which is #2093's gain, and still shrinks back after the quiet window, but no further than stock. The memory given up is the space below stock, about 28 MB for all six lists. This also means a list is never 0 records, so the blade producer's `max(cap, 1) - 1` guard can no longer let record 0 through on an empty list. Today that write is out of bounds wherever robust buffer access is off. Read first: `SimTurfPrivate` in `gpu/vk/vk_draw.cpp`, then `Policy::observe` in `gpu/vk/sim_turf_capacity.h` (unchanged). See #2093. This pull request was written with AI assistance (Claude Code). ## Testing **Tested:** Linux (CachyOS, kernel 7.3), RTX 3090, NVIDIA 620.70.06, headless through the job queue (`--mode shared`). The route, driven by the control bridge: the `market-entrance` save → Hyrule Field for 1500 frames → Market for 1800 frames, long enough for the 600-frame quiet window → Hyrule Field for 1500 frames. It ran twice on `main` @ `9e10f6f7` (its own renderer pack: the shared base `8aa74983` predates #2093) and twice here @ `892837ad`. - `main`, run 1: all six lists shrank to 0 in Market (`resized 1216 -> 0` ...). Back in Hyrule Field they grew from 0 one at a time (`resized 0 -> 1792`, `0 -> 32`, `32 -> 1664` ...). There were 2 `a capture's wait for write-back ... timed out` and 0.4, then 0.2 fps for about 15 s. The longest submission was 3752.8 ms. - `main`, run 2: the same shrink to 0 in Market. Back in Hyrule Field, one write-back timeout, then **the GPU hung**: `vk: FATAL: the GPU hung: no submission finished in 30 s`. The last checkpoint before the hang is `dispatch of program d5a9475f2790532e`, the blade list's producer. - Here, both runs: no list was resized, there were no write-back timeouts in Hyrule Field, the longest submission on the way in 10.9 ms, and 57–60 fps once it had loaded. Run 2 fell to 2.6 fps for 5 s while the area loaded, from texture uploads (`a frame's uploads took 440 ms`), with no GPU stall. In run 1 the stop in Market on the way in had 5 write-back timeouts and a 2499 ms submission. No turf list changed size there, and run 2 did not show it; `main` run 1 also fell to 2–6 fps at the same place. The PC was swapping heavily during those runs (about 31 GB of swap in use). - `tests/test_sim_turf_floor.py` (new) cuts `SimTurfPrivate` out of `vk_draw.cpp` and builds it against the real `sim_turf_capacity.h`. It plays 700 frames with no demand (Market), then Hyrule Field's 17013 blades and 10069 pool records. It expects both lists to stay at stock, with no resize on the way back in. It has not run on this PC; CI runs it. It should fail on `main`, with the lists at 0, and pass here. **Still to test:** - Windows NVIDIA, the reporter's setup: Market → Hyrule Field, expecting no `a capture's wait for write-back ... timed out` and no drop to 1 fps (@Beanstalk Windows NVIDIA: Market to Hyrule Field with simulated turf on its defaults) - AMD: the same walk, expecting no change from `main` apart from the stalls (@Beanstalk AMD) - Dense settings (Turf density high in Hyrule Field): the lists still grow above stock without flicker (by hand) - `tests/test_sim_turf_floor.py` both ways and the whole suite, expecting a failure on `main` and passes here (by hand, or CI) ## Measurements **Verdict:** it removes the stall on the way back into Hyrule Field. On `main` the return fell to 0.2–0.4 fps with seconds-long submissions in one run, and hung the GPU in the other. Here both returns ran at 57–60 fps once loaded, with no submission over 11 ms. Setup: Linux, RTX 3090, NVIDIA 620.70.06, the route above, headless at 1920x1080, two runs a side (main, fix, then main and fix side by side). Read from the log: `a capture's wait for write-back ... timed out`, `GPU time ... (the longest submission ...)` and `vi: ... fps over the last ...`, from the map change into Hyrule Field to the end of the route. | Back into Hyrule Field, by run | Before: main @ 9e10f6f7 | After: this PR @ 892837ad | |---|---|---| | Turf lists resized from 0 | 6 / the run hung first | 0 / 0 | | Write-back timeouts (250 ms each) | 2 / 1, then a 30 s GPU hang | 0 / 0 | | The longest submission (ms) | 3752.8 / the GPU hung (30 s) | 10.9 / 4.8 | | The lowest 5 s frame rate from the map change (fps) | 0.2 / the GPU hung | 46.3 / 2.6 (the area's ASTC uploads while it loaded: `a frame's uploads took 440 ms`; no GPU stall) | | The 5 s frame rate once loaded (fps) | 53.5 / the GPU hung | 59.5 / 57.1 | ## Risks - Memory: the lists no longer go below the game's size, so up to about 28 MB of GPU memory stays held in areas without turf, or with simulated turf set to off. That is the same as `RX_VK_SIM_TURF_ADAPTIVE=0` and as before #2093. - Turning simulated turf off in the menu (Fade start 0, Minimum blades 0) still hides it. It no longer frees the lists' memory below stock. - To turn it off: a revert is enough. `RX_VK_SIM_TURF_ADAPTIVE=0` still keeps the lists at stock, as before. - Players notice nothing in their files: no settings or caches change. ## 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). (CI runs it; not run on this PC) - [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. (written; not run on this PC, its CI result both ways to come) - [x] A check under `tests/` that reads changed source is updated, not weakened. (the checks that read `vk_draw.cpp` cut other functions; `SimTurfPrivate` is read only by the new one) - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (built on Linux in the renderer pack; Windows by CI) - [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) https://claude.ai/code/session_017vw8e164QuKZTgE7GGxxT5
Fails on main: SimTurfPrivate's policy has a floor of 0 records, so 700 quiet frames
release both lists to 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017vw8e164QuKZTgE7GGxxT5
fix(vk): simulated-turf lists keep the game's size in areas without turf, so Hyrule Field no longer stalls 250 ms at a time on the way in
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
Website / Website on Cloudflare (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 25s
CI / Website build and checks (pull_request) Failing after 34s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 36s
CI / Workflow lint (actionlint) (pull_request) Successful in 37s
Third-party parts / As their notes say (pull_request) Successful in 41s
PR description / Description follows the template (pull_request_target) Failing after 19s
892837ad77
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017vw8e164QuKZTgE7GGxxT5
HumanBean changed title from WIP: fix(vk): simulated-turf lists keep the game's size in areas without turf, so Hyrule Field no longer stalls 250 ms at a time on the way in to fix(vk): simulated-turf lists keep the game's size in areas without turf, so Hyrule Field no longer stalls 250 ms at a time on the way in 2026-11-22 01:21:31 +00:00
HumanBean deleted branch fix/sim-turf-stock-floor 2026-11-22 01:21:44 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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!2174
No description provided.