Skip to content

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

Merged
ThatRecompDev merged 1 commit into
ThatRecompDev:mainfrom
Sr-0w:resources/refresh-settle-parallel
Nov 26, 2026
Merged

ThatRecompDev merged 1 commit into
ThatRecompDev:mainfrom
Sr-0w:resources/refresh-settle-parallel

Conversation

@Sr-0w

@Sr-0w Sr-0w commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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

…reads

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 <noreply@anthropic.com>
@ThatRecompDev
ThatRecompDev merged commit b4cd3af into ThatRecompDev:main Nov 26, 2026
2 checks passed
@ThatRecompDev

Copy link
Copy Markdown
Owner

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 added a commit that referenced this pull request Nov 26, 2026
…ad budget

The first ExecuteCommandLists of each frame checked every CPU-mapped texture (Bink
video planes, the glyph cache) one after another on the submitting thread: a read
through the kernel, the page hashes and, when they changed, an upload. That was up to
tens of ms of every w109 world frame before its first submission reached the GPU.
The queued (written) textures already settle on several threads (#57); the watched
ones did not.

RefreshWatched now refreshes them with Parallel.ForEach on TextureRefreshWorker's
SettleThreads (half the logical processors), the same budget #57 uses, still before
the submission: each texture is read and hashed under its refresh gate in its
thread's copy buffer, and the uploads take the uploader's lock in turn. No new
buffers: the per-thread copy buffers are the pool threads' that #57's settle uses.
Watched textures the registry retired are dropped from the list instead of being
walked every frame. Test: two mapped textures refreshed together each get their own
bytes, and an unchanged second check uploads nothing.
ThatRecompDev added a commit that referenced this pull request Nov 26, 2026
Every fill held GpuTextureUploader's lock from taking a slot to submitting its copy,
detile and list recording included, so the refresh worker's settle threads (#57) and
the frame's check of CPU-mapped textures read and hashed in parallel but detiled one
at a time.

The lock now covers taking a slot (its staging buffer made, the slot marked busy)
and submitting the copy (fence value and Signal in submission order). The detile
into the slot's upload buffer and the recording of its list run on the filling
thread, with that thread's footprints (thread-static, as the failure text now is);
a fill that comes round to a busy slot waits for it (Monitor.Wait), and Dispose
waits for busy slots before it lets them go. A failed detile or record drops its
slot as a failed staging did. Test: 40 fills from 8 threads round the 16 slots
are all made, and each texture ends with its own bytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants