fix(host): a CPU read or write of texels gives the thread's virtual core up while it waits for the GPU (no ~1 s freeze at area changes) #1827

Merged
HumanBean merged 1 commit from GummiNaomi/Longshot:fix/texels-give-core-up into main 2026-11-20 06:49:16 +00:00
Member

Summary

At some area changes, and once at boot, the game froze for about a second. A background thread of the game (SceneLowPriority at an area change, BootupBackgroundWorkThread at boot) wrote a texture's texels; Longshot's write waits in the Vulkan back end for the GPU to finish the work submitted before it, and that thread kept its virtual core through the wait. A worker the frame needed (ModuleSystemWorker2) could run only on that core and waited for it, the frame's signal never came, the GPU work being waited for could not finish, and only the present's one-second wait for the frame (RX_VK_FRAME_GATE_MS) broke the cycle.

This gives the virtual core up for the back end's call in both texel wrappers, read and write, as Longshot already does for its other waits for the GPU on a game thread (an invalidate, a remap). In four interleaved tours of seven areas, the one-second freezes went from 3 and 5 a tour (the core kept, as on main) to none.

How to see it on main: teleport between areas (Castle Town's market, Hyrule Field, Kakariko, Kokiri Forest, the Lost Woods, Zora's River) with the next frame's work held at OoT's frame limiter (HOS_NVN_FRAME_OVERLAP=1, #1811); at some arrivals a frame takes about 1010 ms and the log's virtual-core waits name SceneLowPriority holding about a second. My runs all had that overlap on (it makes the cycle easy to reach); whether main alone reaches it was not tested. The change is right either way: the thread does no game work while it waits.

Read first: rx_nvn_read_texels and rx_nvn_write_texels in host/rx_backend.c, then tests/test_texels_vcore.py.

See #1811, #1646 (FreeAddressRegion gives its virtual core up while it discards: another wait, another fix).

Testing

Tested: Windows 11, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off. Four teleport tours of seven areas from the kokiri-start save, interleaved (kept, given up, given up, kept), on a build of main @ f505340b with #1810-#1813's changes and this fix, my play settings (HOS_NVN_FRAME_OVERLAP=1, RX_VK_TEX_MOVE=1, RX_VK_TEX_AHEAD=2, RX_VK_LATE_FIX=1), 2560x1440, no window: with the core given up, no virtual-core hold of 300 ms or more, no frame of 500 ms or more after the first arrival and no time-out of the present's wait in either tour; 0 errors in every log. The bug's steps no longer show it.
Checks: tests/test_texels_vcore.py passes on this head on Windows (clang) and Linux (g++ 13.3, WSL Ubuntu 24.04), its four cases each; on main's wrappers its four default cases fail ("core held during the call") and the two HOS_TEXELS_KEEP_CORE=1 cases pass.
Suite: tests/run_all.py with every check on main @ 068fb8eb in WSL Ubuntu 24.04 (740 pass, 61 fail, 69 skipped: no clang or spirv-val there), then this head's --changed checks in WSL (42 pass, 8 fail, 4 skipped) and on Windows (49 run, 17 fail). Every failure also fails on main @ 068fb8eb on the same OS: in WSL test_crash_dialog, test_dev_ab, test_frame_overlap, test_host_guest_writes, test_linux_pressure, test_present_queue_default, test_slow_frames, test_vk_occlusion_queries; on Windows those eight and test_audio_output_devices, test_collect_wide, test_dev_build, test_driver_env_choose, test_hud_layout, test_invalidate_vcore, test_mesh_fallback_layout, test_pipeline_tour, test_wide_ui (most of them this PC's compiler wrapper or a missing tool).

Still to test:

  • Windows, any GPU, current main without #1811: the seven-area teleport tour twice with HOS_TEXELS_KEEP_CORE=1 and twice unset, expecting no frame near 1 s unset and no virtual-core wait of 300 ms or more in the log (by hand)
  • Linux, any GPU: one tour unset, expecting the same (by hand)

Measurements

Verdict: fixed where it showed: virtual-core holds of about a second, 3 and 5 a tour with the core kept, 0 and 0 with it given up; frames of 500 ms or more, 4 and 4 against 0 and 0 (the longest 1010 and 1008 ms against 296 and 320 ms).

Setup: Windows 11 Pro 26200, RTX 4070 SUPER 12 GB (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB, 16 cores; a teleport tour of seven areas from the kokiri-start save, 2560x1440, uncapped, no window (HOS_HEADLESS=1), my play settings above in every tour; measured: the log's virtual-core waits (holds of 300 ms or more, with the holder), the frame trace's frames after the first arrival, the log's lines where the present's wait timed out; two tours a side, interleaved.

Baseline: one build, main @ f505340b (11 commits before 0de25c3e, on which this was first written) with #1810-#1813's changes and this fix; HOS_TEXELS_KEEP_CORE=1 gives main's behaviour (the core kept) and unset this PR's. None of the commits since touches the two texel wrappers.

Before: the core kept (HOS_TEXELS_KEEP_CORE=1) @ f505340b After: the core given up (this PR) @ f505340b
virtual-core holds of 300 ms or more (tour a / b) 3 / 5 (SceneLowPriority 1010-1016 ms; once BootupBackgroundWorkThread 990 ms) 0 / 0
frames of 500 ms or more after the first arrival 4 / 4 (max 1010 / 1008 ms) 0 / 0 (max 296 / 320 ms)
frames of 250 ms or more after the first arrival 4 / 7 2 / 1
the present's wait timed out (RX_VK_FRAME_GATE_MS) 3 / 5 0 / 0
errors in the log 0 / 0 0 / 0

HOS_TEXELS_KEEP_CORE (new, a kill switch) ships unset, the core given up, chosen by the table above; =1 keeps the core through the wait, as before.

Risks

What could break: after the GPU wait the thread may wait for a core again, as after an invalidate or a remap; nothing it does while it waits touches game state. Turning it off: HOS_TEXELS_KEEP_CORE=1. After updating, a player notices nothing apart from the freeze gone: no change to saves, longshot_options.ini or the caches.

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).
  • 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.
  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • 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. (The changed wrappers and the switch's reader compiled and run by their test with clang on Windows and g++ 13.3 on WSL Ubuntu 24.04; not a whole Linux build.)
  • 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 At some area changes, and once at boot, the game froze for about a second. A background thread of the game (SceneLowPriority at an area change, BootupBackgroundWorkThread at boot) wrote a texture's texels; Longshot's write waits in the Vulkan back end for the GPU to finish the work submitted before it, and that thread kept its virtual core through the wait. A worker the frame needed (ModuleSystemWorker2) could run only on that core and waited for it, the frame's signal never came, the GPU work being waited for could not finish, and only the present's one-second wait for the frame (`RX_VK_FRAME_GATE_MS`) broke the cycle. This gives the virtual core up for the back end's call in both texel wrappers, read and write, as Longshot already does for its other waits for the GPU on a game thread (an invalidate, a remap). In four interleaved tours of seven areas, the one-second freezes went from 3 and 5 a tour (the core kept, as on main) to none. How to see it on main: teleport between areas (Castle Town's market, Hyrule Field, Kakariko, Kokiri Forest, the Lost Woods, Zora's River) with the next frame's work held at OoT's frame limiter (`HOS_NVN_FRAME_OVERLAP=1`, #1811); at some arrivals a frame takes about 1010 ms and the log's virtual-core waits name SceneLowPriority holding about a second. My runs all had that overlap on (it makes the cycle easy to reach); whether main alone reaches it was not tested. The change is right either way: the thread does no game work while it waits. Read first: `rx_nvn_read_texels` and `rx_nvn_write_texels` in `host/rx_backend.c`, then `tests/test_texels_vcore.py`. See #1811, #1646 (FreeAddressRegion gives its virtual core up while it discards: another wait, another fix). ## Testing **Tested:** Windows 11, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off. Four teleport tours of seven areas from the `kokiri-start` save, interleaved (kept, given up, given up, kept), on a build of main @ f505340b with #1810-#1813's changes and this fix, my play settings (`HOS_NVN_FRAME_OVERLAP=1`, `RX_VK_TEX_MOVE=1`, `RX_VK_TEX_AHEAD=2`, `RX_VK_LATE_FIX=1`), 2560x1440, no window: with the core given up, no virtual-core hold of 300 ms or more, no frame of 500 ms or more after the first arrival and no time-out of the present's wait in either tour; 0 errors in every log. The bug's steps no longer show it. Checks: `tests/test_texels_vcore.py` passes on this head on Windows (clang) and Linux (g++ 13.3, WSL Ubuntu 24.04), its four cases each; on main's wrappers its four default cases fail ("core held during the call") and the two `HOS_TEXELS_KEEP_CORE=1` cases pass. Suite: `tests/run_all.py` with every check on main @ 068fb8eb in WSL Ubuntu 24.04 (740 pass, 61 fail, 69 skipped: no clang or spirv-val there), then this head's `--changed` checks in WSL (42 pass, 8 fail, 4 skipped) and on Windows (49 run, 17 fail). Every failure also fails on main @ 068fb8eb on the same OS: in WSL `test_crash_dialog`, `test_dev_ab`, `test_frame_overlap`, `test_host_guest_writes`, `test_linux_pressure`, `test_present_queue_default`, `test_slow_frames`, `test_vk_occlusion_queries`; on Windows those eight and `test_audio_output_devices`, `test_collect_wide`, `test_dev_build`, `test_driver_env_choose`, `test_hud_layout`, `test_invalidate_vcore`, `test_mesh_fallback_layout`, `test_pipeline_tour`, `test_wide_ui` (most of them this PC's compiler wrapper or a missing tool). **Still to test:** - Windows, any GPU, current `main` without #1811: the seven-area teleport tour twice with `HOS_TEXELS_KEEP_CORE=1` and twice unset, expecting no frame near 1 s unset and no virtual-core wait of 300 ms or more in the log (by hand) - Linux, any GPU: one tour unset, expecting the same (by hand) ## Measurements **Verdict:** fixed where it showed: virtual-core holds of about a second, 3 and 5 a tour with the core kept, 0 and 0 with it given up; frames of 500 ms or more, 4 and 4 against 0 and 0 (the longest 1010 and 1008 ms against 296 and 320 ms). Setup: Windows 11 Pro 26200, RTX 4070 SUPER 12 GB (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB, 16 cores; a teleport tour of seven areas from the `kokiri-start` save, 2560x1440, uncapped, no window (`HOS_HEADLESS=1`), my play settings above in every tour; measured: the log's virtual-core waits (holds of 300 ms or more, with the holder), the frame trace's frames after the first arrival, the log's lines where the present's wait timed out; two tours a side, interleaved. Baseline: one build, main @ f505340b (11 commits before 0de25c3e, on which this was first written) with #1810-#1813's changes and this fix; `HOS_TEXELS_KEEP_CORE=1` gives main's behaviour (the core kept) and unset this PR's. None of the commits since touches the two texel wrappers. | | Before: the core kept (`HOS_TEXELS_KEEP_CORE=1`) @ f505340b | After: the core given up (this PR) @ f505340b | |---|---|---| | virtual-core holds of 300 ms or more (tour a / b) | 3 / 5 (SceneLowPriority 1010-1016 ms; once BootupBackgroundWorkThread 990 ms) | 0 / 0 | | frames of 500 ms or more after the first arrival | 4 / 4 (max 1010 / 1008 ms) | 0 / 0 (max 296 / 320 ms) | | frames of 250 ms or more after the first arrival | 4 / 7 | 2 / 1 | | the present's wait timed out (`RX_VK_FRAME_GATE_MS`) | 3 / 5 | 0 / 0 | | errors in the log | 0 / 0 | 0 / 0 | `HOS_TEXELS_KEEP_CORE` (new, a kill switch) ships unset, the core given up, chosen by the table above; `=1` keeps the core through the wait, as before. ## Risks What could break: after the GPU wait the thread may wait for a core again, as after an invalidate or a remap; nothing it does while it waits touches game state. Turning it off: `HOS_TEXELS_KEEP_CORE=1`. After updating, a player notices nothing apart from the freeze gone: no change to saves, `longshot_options.ini` or the caches. ## 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. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [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 - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [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. (The changed wrappers and the switch's reader compiled and run by their test with clang on Windows and g++ 13.3 on WSL Ubuntu 24.04; not a whole Linux build.) - [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)
fix(host): a CPU read or write of texels gives the thread's virtual core up while it waits for the GPU (no ~1 s freeze at area changes)
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 10s
Website / Website on Cloudflare (pull_request_target) Has been skipped
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 18s
CI / Workflow lint (actionlint) (pull_request) Successful in 19s
Third-party parts / As their notes say (pull_request) Successful in 22s
PR description / Description follows the template (pull_request_target) Successful in 3s
CI / Website build and checks (pull_request) Failing after 4m12s
0e1eab0013
nvnTextureReadTexels / WriteTexels wait in the Vulkan back end for the GPU to finish
the work submitted before, and that work can wait for a signal the game's main thread
makes later. The calling thread kept its virtual core through the wait: at an area
change SceneLowPriority's WriteTexels held core 2 for about a second while
ModuleSystemWorker2, which the frame needed, waited for that core, until the present's
wait (RX_VK_FRAME_GATE_MS) gave up: a freeze of about a second.

The core is now given up for the call, as rx_nvn_invalidate and a remap already do.
HOS_TEXELS_KEEP_CORE=1 keeps it, as before.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
HumanBean changed title from WIP: fix(host): a CPU read or write of texels gives the thread's virtual core up while it waits for the GPU (no ~1 s freeze at area changes) to fix(host): a CPU read or write of texels gives the thread's virtual core up while it waits for the GPU (no ~1 s freeze at area changes) 2026-11-20 06:49:10 +00:00
HumanBean deleted branch fix/texels-give-core-up 2026-11-20 06:49:17 +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!1827
No description provided.