Texture lane: the whole cost is waiting for the remap lock, and VICTORY_TEXTURE_NO_WAIT removes it (with numbers) #178
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork#178
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@rostaddotcc on GitHub · 2026-11-24 22:13 UTC · original
The texture lane's cost during streaming is not reading, hashing or asking — it is all
waiting for title memory to hold still, andVICTORY_TEXTURE_NO_WAIT=1removes it entirely. Measured here (RX 7900 XT/RDNA3, RADV, Mesa 26.3.1, Proton Experimentalexperimental-11.0-20261112, fork4e17478, diag build, three ~3-minute runs in the same loading/streaming phase,0.1–0.5 fps, no other switches).texture refreshes per frame, all threads, four counters in the frame line:4e17478as it isVICTORY_TEXTURE_NO_WAIT=1And in the frames where
textureswas seconds, the whole of it was this wait — 5 644 of 5 645 ms in one frame, 5 220 of 5 221 in another — while asking was 26–485 ms and the texture's own lock 0.With the switch, the wait is 0 in every one of 94 windows, and the refresh either reads in place or, while the runtime holds the mapping lock, reads through the kernel: 3–7 refreshes a frame did that, and 0–2 a frame were left for the next refresh because a page was not there. So what the docstring warns about (a texture showing a frame later) is at most two textures a frame, and never a partly read one.
What this is not. I assumed first that the wait was a convoy of our own making — every refresh holding the read guard through its hashing and detiling, so the runtime's remap waited for us and then we waited for it. That is plausible from the code (
texture.rs:661-742hashed and detiled underlet _mapped), so I measured it: copying the texture out of title memory under the guard and dropping it beforeblake3anddetilechanges nothing (row 2 above — the wait is the same or worse, and the title's remap is what everyone is waiting for, not another reader). The patch is not worth merging on its own; the run that says so is the useful part.So the order of the fix is the opposite of what the wait suggests: not "make the readers quicker" but "do not take the lock to read a texture at all".
title_memory_reading_now()already exists for this,refresh_unlockedalready reads through the kernel and already counts what it defers, and the switchesVICTORY_TEXTURE_GUARDandVICTORY_TEXTURE_COPYshow the path was thought through.Proposal: make
no_waitthe default (VICTORY_TEXTURE_NO_WAIT=0to get the old behaviour), or simply alwaystry_readand fall back — the cost of a kernel read is 0.6 ms a megabyte against 0.3 in place, and 25.6 MB a frame pays 15 ms instead of waiting 1.1–5.2 s for a remap to finish. A smaller follow-up, if the remap lock turns out to matter elsewhere (it is also taken indraw.rs:2199andxmem.rs:1176): say in the frame line who held it and for how long, since that is the number nobody has.The second-order question this raises, which I have not measured: why the runtime's remap takes as long as it does. If it is one
VirtualAllocof a large region under a single lock, per-block locking (watch.rsalready tracks blocks for guards) would let a texture read proceed unless its own blocks are being remapped.Nothing from the title is in the logs; they hold only the counters above.
@rostaddotcc on GitHub · 2026-11-24 22:18 UTC · original
#175 landed the better version of this while I was writing it up: scoping the mapping lock to the affected ranges keeps the in-place read (0.3 ms a megabyte, no deferral) and takes the wait to zero, where
VICTORY_TEXTURE_NO_WAIT=1is the blunt version that reads through the kernel and defers 0–2 textures a frame. If #175 merges, the switch here is only the fallback for a remap whose extent is unknown.Keeping this open for the numbers and one thing #175 does not answer: 4 076 ms was the worst single-window wait, and my run cannot say how long one remap holds the lock, only how long everyone waited. Whoever instruments the writer side should put that in the frame line next to the reader counters.
@sawetco on GitHub · 2026-11-25 00:30 UTC · original
On native Windows I measured the deferred-read counter during the transition into the first playable scene. It can get appreciably higher than the 0–2 per frame in the Proton run.
On an RTX 5070 (621.24), Ryzen 5 7600X, Windows 11, I ran the same local build based on
90228a7twice, with the same Series X save, initial renderer cache, timed inputs, relay 2 and shader loop limit 256. OnlyVICTORY_TEXTURE_NO_WAITchanged. With it enabled, 64 of 79 fallback-counter reports between 88 and 215 seconds averaged more than two deferrals per frame. The median was 17.7. The peak report averaged 140 reads through the kernel and 83 left for a later refresh per frame. These are refresh attempts across threads. The counters do not tell us how many distinct textures were involved or how many frames any one texture waited.Peak reported mapping wait during the streaming transition fell from 4572 ms/frame across threads to zero. Once the prison scene settled, the two runs presented 550 frames in 189.0 s and 486 in 163.0 s (2.91 and 2.98 FPS). This was one run per setting on a downstream build. For a default fallback decision, the deferral distribution during streaming seems worth tracking alongside reader wait time. I did not measure writer lock duration or run #175 in this comparison.
AI-assisted local measurement and write-up (Codex).
@0xmp3 on GitHub · 2026-11-25 03:52 UTC · original
Negative result on the obvious fix for this: raising the staging budget does not drain the queue, and it destabilises the title. Recording it so nobody spends an evening on it.
Setup: Windows 11 26300, RX 9070 XT (RDNA4, driver 32.0.32015.7029), Ryzen 5 5600, 64 GB RAM, fork
c96b4f2, diag build,VICTORY_SHADER_OPT=59 VICTORY_RELAY=2 VICTORY_BVH_BUILDER=1 VICTORY_BVH_QUARANTINE=1 VICTORY_INPLACE=1.Baseline (default
VICTORY_TEXTURE_STAGE_MS=250, so 750 ms under catch-up): ten-plus minutes in the world, no crash. The queue of textures picked by index grows the whole time and never drains:So demand (~104/s) exceeds supply (~82/s) and the scene never finishes texturing — which is what "untextured surfaces slowly resolving" looks like on screen.
VICTORY_TEXTURE_STAGE_MS=500(so 1,500 ms per pass under catch-up) — two runs, both died in the title, on a read of0xffffffffffffffff(a failed lookup dereferenced unchecked):victory-image-…dll+0x4f400a9victory-image-…dll+0x108557Different offsets, same signature. Private memory through run 2:
and the operator saw system RAM approach ~40 GB with CPU around 50% before each crash.
So the budget is not the lever: more staging per pass retains more staging buffers per unit time, memory climbs faster than the backlog drains, an allocation fails, and the title dies on the null. The supply problem needs the lane to stop sharing the frame-recording thread — the code comment already says the pass costs "1.6–2.2 s of each of the world's first twenty frames" on that thread — rather than a longer pass on the same thread.
Two things I did not test, in case they are useful to whoever picks this up:
VICTORY_TEXTURE_CATCHUP=0(the plain budget, 250 ms, worth knowing whether the default catch-up is itself a stability risk at large backlogs), and whether the staging buffers seen accumulating are the per-partly-streamed-texture ones that the code notes were once kept "for good".No game data; numbers, offsets and timings from VIctory's own log. AI-assisted (Hermes Agent).
@0xmp3 on GitHub · 2026-11-25 03:54 UTC · original
One addendum from the repeat run, because it names the mechanism better than the memory curve did: the run reached the world
before it died, and its worst frame was a single frame copying 4,286.8 MB —
So it is not a gradual leak: one frame copies 4.3 GB in 5.3 s, which is exactly the RAM/CPU spike seen before the crash. At 8,490 draws with 17,846 textures still queued, the copy path is doing the work the GPU should be doing — the GPU read 365 ms in a ~9 s frame.
For contrast, the same run's ordinary frames:
199.6 ms of copies for 318.1 MB, and a menu frame with0.0 ms on the GPU. So the budget increase didn't redistribute work, it let a single frame's copy set grow until the allocation failed.Two related signals in the same frame:
225 passed over unmappedtextures andbuffer views left null as the host would refuse them: 10, both rising through the run — resources the layer wanted and could not make.No game data; numbers from VIctory's own log. AI-assisted (Hermes Agent).
@rostaddotcc on GitHub · 2026-11-25 06:40 UTC · original
@sawetco's A/B is the most useful thing in this thread and it corrects part of the proposal I opened it with, so it is worth stating plainly:
The wait counter sums across threads, and removing the wait did not shorten the frame. His two runs, same save and timed inputs, only
VICTORY_TEXTURE_NO_WAITdifferent: mapping wait 4 572 ms/frame → 0, presented frames 550 in 189.0 s against 486 in 163.0 s (2.91 and 2.98 FPS). So the lane's seconds were largely parallel waiting — fifteen threads each blocked, not the submitting thread blocked for the sum. My "makeno_waitthe default" was written as if that sum were the critical path; on his numbers it is not, and a default flip would buy the picture lag (his peak: 140 reads through the kernel and 83 deferrals per frame, median 17.7 deferrals during the transition, against 0–2 in my Proton run) for no frame rate.Two things follow, and they change what I would measure next:
"all threads" is the wrong denominator for a decision. The number that matters is the longest wait on whichever thread is on the critical path — normally the submitting one. My windows were 8 478 ms frames with 5 645 ms of summed wait across threads, which was already a hint that the sum could not all be serial.
Nobody has measured the writer. The title's remap takes the mapping lock alone, and every reader in the sum is waiting for that one writer. If the writer is slowed by readers holding the lock through their hashing and detiling — which is what my reader-guard experiment probed, with no change in this counter, as expected, since it measures readers — then the win is in remap duration, not in reader wait. A counter of "how long the title's mapping change held the lock" (and how many there were) would tell us whether that is worth anything; it does not exist today.
For the record from the same ground as the original numbers: with the switch, 3–7 refreshes a frame went through the kernel and 0–2 were left for the next frame on Linux/Proton, so the deferral cost is much smaller there than on native Windows. That still does not make it a frame-rate win.
@rostaddotcc on GitHub · 2026-11-25 06:49 UTC · original
I went and measured the writer, since I said nobody had. Numbers from a 400-second streaming run on Linux/Proton (RX 7900 XT, RADV, vkd3d-proton 3.2.0,
8dd30ab+ the counter in #766):Reading that: the title remaps thousands of times a frame, in short changes averaging about 1.5 ms, and the lock is held for most of the frame. So the readers' wait is not one long remap that could be interrupted or overlapped better — there is simply rarely a free moment — and the occasional 175 ms change is the outlier that shows up as a multi-second "textures" window.
That also explains why #175 removes the wait outright rather than shortening it: a reader's own range is only being remapped in the change that touches it, so with range scoping almost every wait disappears instead of shrinking.
Two consequences I would flag before anyone tunes this further:
XMemMapPhysicalPagesholds it fromunmapthrough mapping every run of pages again). If the title asks for many small page windows — which 3 000–5 000 changes a frame suggests — then each change pays for the view teardown and re-mapping of its own window, and the aggregate is the frame. Anything that makes one change cheaper moves everything in the lane.@iGoldenNinja on GitHub · 2026-11-25 14:50 UTC · original · edited 2026-11-25 15:15 UTC
The same remap-wait counter grew again much later in the prologue on an RTX 5080. This is a native Series X run on the Astral 16 GB, NVIDIA 617.14, Windows 11 Pro 25H2 build 26200.9974, Ryzen 9 5900X and 32 GB. Renderer
92a72df, warm caches,VICTORY_TEXTURE_NO_WAIToff. I marked the prison window and the later shop arrival in the same launch.All eight shop renderer reports exceeded 300 ms/frame of reader wait. That counter sums work across texture threads, as the earlier native RTX 5070 comparison illustrates. PresentMon separately measured 26 display intervals in the shop minute with a longest interval of 5,865.505 ms. These markers cover different scene workloads. The run shows the contention and slowdown recurring during later streaming, with the effect of enabling the fallback at that checkpoint still open. Pinned route and measurement report
November 25 fresh-process follow-up. On the same native Series X RTX 5080 setup and renderer
92a72df, two new processes loaded independent writable copies of the same checkpoint and reached the post-arrest interview. Both used the same binary and warm cache. The second enabledVICTORY_TEXTURE_NO_WAIT=1.Across eight control and nine opt-in renderer reports, median summed texture-thread read-lock wait fell from 1,504.7 to 0.0 ms per renderer frame. The opt-in build recorded median 202.5 kernel reads and 53.3 deferred refreshes per frame. Both display windows started on the interview close-up and diverged at later cuts. They averaged 0.388 and 1.476 displayed FPS respectively with different workloads. Both windows were after the shop. The opt-in run still showed a dark face before skin detail appeared. These runs verify checkpoint restoration and execution of the nonblocking fallback on the RTX 5080. The effect on shop performance is still open. Pinned report