Texture refresh: a submission takes the queued textures on several threads #57

Manually merged
github merged 1 commit from gh-pr/57/head into gh-pr/57/base 2026-11-27 03:16:07 +00:00
Owner

@⁠Sr-0w on GitHub · 2026-11-26 06:30 UTC · original
Sr-0w:resources/refresh-settle-parallel → main · +28 −12 · 2 files · 1 commits · merged 2026-11-26 06:49 UTC

What

TextureRefreshWorker.Settle, called before every submission, now refreshes the textures still queued on several threads: Parallel.ForEach on half the logical processors (SettleThreads). Before, it refreshed them one after another on the submitting game thread. The background worker keeps its one thread.

Why

The game thread waits for the whole queue in Settle anyway. Reading, hashing and detiling a texture run outside the uploader's lock:

  • copy buffers are [ThreadStatic];
  • the counters are Interlocked;
  • each texture has its own RefreshGate;
  • the uploader serialises its own part.

The worker and the submitting thread already ran Refresh concurrently. No lock is held around the call (XboxQueueMethods.Execute).

Through a loading screen, about 1,300 textures were queued between two summaries, mostly first fills. With --cpu-sample, the submitting thread spent its time in ContentHash.Of (33–58 %), NtReadVirtualMemory (14–17 %) and XgSwizzle.Index. Up to 16.8 s of one frame went to texture refresh, and the game's 30 s hang watchdog ended the boot.

In game (a retail game, RX 7800 XT, main + #56, untraced)

before (#56 only) after
boot the hang watchdog ends it at 1,200 presents, on the loading screen passes the loading screen, plays the intro (night street, car lights, signs, lit windows), about 1 fps
worst frame's texture refresh 16.8 s 14.6 s, no watchdog

The run with the fix later ended in a device removal with the system commit full (74.2 of 74.3 GB). The driver's pipeline compiles take up to 6 GB each, several at once, and our process stood at 29.9 GB private. The per-thread copy buffers add at most one largest-texture buffer per settle thread.

Tests

  • Loader tests: 446 passed.
  • docs/gpu-resources.md is updated.

🤖 Generated with Claude Code

**@⁠Sr-0w** on GitHub · 2026-11-26 06:30 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/57) `Sr-0w:resources/refresh-settle-parallel` → `main` · +28 −12 · 2 files · 1 commits · merged 2026-11-26 06:49 UTC ## What `TextureRefreshWorker.Settle`, called before every submission, now refreshes the textures still queued on several threads: `Parallel.ForEach` on half the logical processors (`SettleThreads`). Before, it refreshed them one after another on the submitting game thread. The background worker keeps its one thread. ## Why The game thread waits for the whole queue in `Settle` anyway. Reading, hashing and detiling a texture run outside the uploader's lock: - copy buffers are `[ThreadStatic]`; - the counters are `Interlocked`; - each texture has its own `RefreshGate`; - the uploader serialises its own part. The worker and the submitting thread already ran `Refresh` concurrently. No lock is held around the call (`XboxQueueMethods.Execute`). Through a loading screen, about 1,300 textures were queued between two summaries, mostly first fills. With `--cpu-sample`, the submitting thread spent its time in `ContentHash.Of` (33–58 %), `NtReadVirtualMemory` (14–17 %) and `XgSwizzle.Index`. Up to 16.8 s of one frame went to texture refresh, and the game's 30 s hang watchdog ended the boot. ## In game (a retail game, RX 7800 XT, main + #56, untraced) | | before (#56 only) | after | |---|---|---| | boot | the hang watchdog ends it at 1,200 presents, on the loading screen | passes the loading screen, plays the intro (night street, car lights, signs, lit windows), about 1 fps | | worst frame's texture refresh | 16.8 s | 14.6 s, no watchdog | The run with the fix later ended in a device removal with the system commit full (74.2 of 74.3 GB). The driver's pipeline compiles take up to 6 GB each, several at once, and our process stood at 29.9 GB private. The per-thread copy buffers add at most one largest-texture buffer per settle thread. ## Tests - Loader tests: 446 passed. - `docs/gpu-resources.md` is updated. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Settle refreshed every texture still queued on the submitting game thread, one after another, before the
submission could go on. Through a loading screen about 1,300 textures were queued between two summaries, mostly
first fills, and the CPU sampler showed the submitting thread in ContentHash.Of (33 to 58 %), NtReadVirtualMemory
(14 to 17 %) and the detiling: up to 16.8 s a frame in texture refresh, and the game's 30 s hang watchdog ended the
boot before the world.

The game thread waits for the whole queue there anyway, and reading, hashing and detiling run outside the uploader's
lock (copy buffers are per thread, the counters atomic, each texture behind its own gate), so Settle now drains the
queue with Parallel.ForEach on half the logical processors. The background worker keeps one thread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:16:06 +00:00
github manually merged commit 3c67d86432 into gh-pr/57/base 2026-11-27 03:16:07 +00:00
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-26 07:30 UTC · original

thanks, this lines up with what we saw on our side (texture refresh on the submitting thread was most of the CPU frame)

one thing to keep an eye on is memory, the per-thread copy buffers plus the driver compiles is where your run ran out. merged, we'll watch commit in the next boots

**@⁠ThatRecompDev** on GitHub · 2026-11-26 07:30 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/57#issuecomment-7185525488) thanks, this lines up with what we saw on our side (texture refresh on the submitting thread was most of the CPU frame) one thing to keep an eye on is memory, the per-thread copy buffers plus the driver compiles is where your run ran out. merged, we'll watch commit in the next boots
This discussion has been locked. Commenting is limited to contributors.
No description provided.