Scope title memory mapping locks to affected ranges #175
No reviewers
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!175
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/175/head"
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?
@Kamiloj9 on GitHub · 2026-11-24 22:10 UTC · original
Kamiloj9:codex/range-mapped-texture-reads→main· +226 −36 · 4 files · 1 commits · closed without mergingSummary
Verification
@rostaddotcc on GitHub · 2026-11-24 22:17 UTC · original
Independent confirmation of the diagnosis, from a different ground (Linux/Proton, RX 7900 XT, RADV, fork
4e17478, diag build, three 3-minute runs in the streaming phase).The counters you are moving are the ones I measured before touching anything:
texture refreshes per frame, all threadssplits into waiting for the texture's own lock, asking the write watch and the guards, and waiting for title memory to hold still — and the third is the whole of it: median 20.2 ms, max 4 076 ms, while asking was 7.3 ms and the texture's own lock 0.Your 671 ms median to 0.0 ms matches my direction (mine: 20.2 ms to 0.0 ms with
VICTORY_TEXTURE_NO_WAIT=1, which is the blunt version of what you did —try_read, and read through the kernel while the runtime holds the lock). Yours is the better fix, because it keeps the in-place read at 0.3 ms a megabyte instead of the kernel's 0.6, and it does not defer anything: with the switch, 3–7 refreshes a frame went through the kernel and 0–2 were left for the next frame, so my version pays a small lag that yours should not.One thing that may be useful to you: I first assumed the wait was a convoy of our making — every refresh holding the read guard through its blake3 hashing and detiling, so the runtime's remap waited for us and then we waited for it — and measured it. Copying the texture out under the guard and dropping it before
blake3/detilechanges nothing (median 34.0 ms, max 5 221 ms, i.e. slightly worse). So the hold is the writer's, one remap under one global lock, which is exactly what scoping to ranges fixes.A question on the design, since you are the one who knows: for a mapping change whose extent cannot be determined (the "unknown extents" case you keep global exclusion for), how often does that happen in practice, and is the nonblocking read path still reachable then? In our runs the deferral rate with
try_readwas 0–2 textures a frame, so a nonblocking fallback for that case seems cheap to keep.@rostaddotcc on GitHub · 2026-11-24 22:35 UTC · original
Verified on the other ground this fork is used on: Linux/Proton (CachyOS, RX 7900 XT, Mesa 26.3.1 RADV, vkd3d-proton 3.2.0, Proton Experimental
experimental-11.0-20261112), diag build of8e0e7b6, 430-second run,d3d12served by vkd3d-proton. The mapping-lock wait is 0.0 ms in all 113 sampled windows, and the run went deeper into streaming than the control: 0.2–0.3 fps, 3 478–4 223 ms a frame.Same counter from
texture refreshes per frame, all threads, five runs on this box (medians over the windows each run sampled, so the phase differs between rows):4e17478(first baseline)4e17478(control today, same session as the #175 run)VICTORY_TEXTURE_NO_WAIT=18e0e7b6)So on a backend you did not test on, the property you claim holds: no window waited at all, and it does not pay the deferred-texture price the
NO_WAITswitch pays (0–2 a frame there).What it hands over to is worth writing down: with the wait gone, the lane is now asking — 62.9 ms median, 936 ms in the worst window (write watch and guards). That is #177's target, and on this box it is the largest remaining item in the texture lane.
@AKA0GHOST on GitHub · 2026-11-24 23:38 UTC · original
Tested on Windows 11 D3D12, RTX 5070 (driver 621.14), Ryzen 5 5600, 16 GB: fork main + this PR at
8e0e7b6, diag build,VICTORY_RELAY=2, 10-minute runs. Thanks, this one made a visible difference here.World frames only (samples over 1,000 draws), one run each:
The texture refresh time is where it shows: down by about 8x, which matches the mapping-lock waits going away. In game, walls and surfaces that stayed blank or stale before now fill in while streaming, and the prison interior is playable at 1–2 fps. No hangs or device removals in either 10-minute run (also with #220 on top). The lock tests pass here.
Caveat: one run per setup, and the run with this PR started on a cold shader cache.
AI-assisted (Claude Code); no game files attached.
@relativespace2K on GitHub · 2026-11-25 01:06 UTC · original
Native Windows D3D12 / AMD RDNA2 data point, if useful.
Setup: Windows 11 26100, RX 6800 XT 16 GB (RDNA2), driver 32.0.21045.29003, Ryzen 5 5600, 32 GB, Series X profile, diag build at
8e0e7b6, 1920x1080, noVICTORY_TEXTURE_NO_WAIT.Two runs: 180 s from the checkpoint (prologue), and 300 s from a fresh data dir (first boot/streaming).
texture refreshes per frame, all threads, sampled windows in the fresh run:2119b0e)8e0e7b6)Before the PR the frame line was 0.2 fps, 4.4-5.7 s/frame, textures 3.1-5.0 s; 14 of the 25 windows waited over 100 ms, the worst 7.9 s. With the PR the prologue runs at 1.2-1.5 fps, 669-822 ms/frame, 4,980-5,114 draws/frame, ~16-17 GB working set, with no device loss. The texture lane is 3.1 ms median, and the mapping wait is 0.0 ms in all but two windows (2.4 and 35.5 ms).
This matches the Linux/RX 7900 XT and RTX 5070 reports, and it keeps the in-place read rather than deferring textures. My earlier #393 (defaulting
VICTORY_TEXTURE_NO_WAIT) is superseded by this; I am closing it.AI-assisted: the runs above were made with an AI agent on my machine; I reviewed the logs and the result. No game files or captures are attached.
@LeonardoS11 on GitHub · 2026-11-25 03:07 UTC · original
A measurement from another NVIDIA card, for what it is worth.
diagbuild withdiagnostics, the title's world while it streams.mainat2119b0ethe per-frame line read "texture refreshes per frame … 170.0 ms waiting for title memory to hold still (the runtime remapping it)", and 229.7 ms in another sample; "textures" in the fps line was 40–300 ms a frame.Caveats: the "with" runs carried #191 and #154 too, so the attribution to this PR is by the counter it changes, not by an isolated A/B; and those runs did not go through exactly the same scene. I have not yet checked the picture of this PR alone against
main(doing that for each PR of the stack now, after finding that one of them, #158, breaks lighting here — details will go on that PR).(Runs by me on the hardware above; numbers read from the logs and this note written with Claude Code.)
@rostaddotcc on GitHub · 2026-11-25 07:32 UTC · original
Two things from a Linux machine this morning, and the second one is the reason to rebase rather than close.
The branch no longer applies to
main. Ona26859fit isdirty: one hunk, incrates/victory-gpu/src/lib.rs, the re-export list —mainaddedtitle_memory_reading_nowwhile this addstitle_memory_reading_rangeandtitle_memory_remapping_range. The union is all four plus what was there:Nothing else conflicts, and it builds and runs after that.
And it does exactly what it says on the newest
main, on Linux/Proton (RX 7900 XT, RADV, vkd3d-proton 3.2.0, both runs entering the world with scripted keys, ~7 minutes each, 4 000-odd draws in the heaviest frames):maina26859fZero, not "smaller": in 136 out of 136 windows the readers never waited at all. That matters more since this morning's measurement (#178) that the title holds the mapping lock for 3 844–8 020 ms a frame across 1 721–5 041 separate changes — there is almost never a free moment for a global lock to be acquired, which is why scoping it per range removes the wait rather than shortening it.
I have the rebased commit (your change, the one-hunk resolution above) and can push it to my fork as a fresh PR if you would rather not force-push here — say which and I will.
@alpz1000 on GitHub · 2026-11-25 16:43 UTC · original
Independent Windows 11 run (build 26200, i5-8400, RTX 3060 12 GiB with driver 610.88, 32 GiB RAM). I compared the same warm-cache Series S checkpoint on local build
03c9405and with8e0e7b6integrated asf33fa0a. Both builds had the same local display integration and idle-cache trim. The range-lock integration preserved main's existing remap counters, and all fourwatch::mapping_testspassed.The same heavier bin had a maximum reported wait of 257.2 ms before and 0.1 ms after. In later 50-second windows around 4,500 draws, actual presents averaged 4.33 FPS before (222 frames) and 4.94 FPS after (253 frames). There was one launch per build and the later windows were sampled at different times after loading, so the frame-rate comparison is directional. No device removal was logged in either run.
AI-assisted with OpenAI Codex.
@rostaddotcc on GitHub · 2026-11-25 18:18 UTC · original
Reading
d510ee4a(two attempts on the title's page mapping, both taken back out) — two costs in that area get treated as one, and this PR only addresses the second.The 32 ms of every cutscene frame in that note is the kernel map/unmap calls themselves. This PR does not touch them:
unmapand the mapping are unchanged, the same pages end up mapped. There is no path here to the failure you hit — coalescing several pool pages into one view changes the shape of the mapping; scoping the lock does not.What it changes is who waits. On
9376fd6the write lock was held across the whole map operation (XMemMapPhysicalPages, from the unmap until every run is mapped again): 1 721–5 041 mapping changes per frame, lock held 3 844–8 020 ms of each frame, longest single change 46–175 ms. Readers' summed wait in those windows was 194–2 475 ms. Textures ask through the same lock, so the texture lane waited 430.6 ms median / 2 977.7 max and totalled 599 ms of the lane's 7 minutes.With the diff, on the same save and scripted input, 7 minutes a side: texture wait 0.0 ms in 136 of 136 windows, lane total 599 → 59 ms median. Again as a caution: that is a wait figure, not a frame-rate one, and each side is a single run. Two runs of the same binary on this rig have differed by 2–4x at matched draw counts, so I would not put a fps number next to it.
The case worth checking when reviewing: a view reaching past the requested range, where
unmaptakes the other half away from a reader that asked about a range not overlapping the request. That is whatmapping_extentwidens to, andmapping_extent_includes_the_entire_old_viewcovers it; overflow, an unaligned base and an empty range all fall back to the global lock rather than guessing.@rostaddotcc on GitHub · 2026-11-25 18:54 UTC · original
Rebased onto
d510ee4a, with the frame log's counters kept.Conflict in
watch.rsresolved by keeping everything upstream added since2119b0e4(viewtracking, the guards,
ask_ahead) and replacing only the locking primitive: the plainRwLockbecomes the range-aware queue from this PR, andRemapUs/Remaps/RemapWaitUsarenow added by the new guard, so the frame log keeps measuring the same thing.
lib.rs: theunion of the re-exports.
Measured on
d510ee4aagainstd510ee4a+ this, 330 s each, same save, scripted input, bothwith
VICTORY_FRAME_LOG=1(Proton/Proton Experimental, RX 7900 XT, vkd3d-proton):The texture lane moved 33 MB in 1,701 ms on the base and 161 MB in 330 ms here (19 MB/s
against 488 MB/s). By draw count, the frames the wait was bounding:
So the wait is gone everywhere it was measured, and it is worth about 1.3 s a frame in the
lighter scenes; above 3,000 draws something else sets the frame, which is the next thing to
look at.
@rostaddotcc on GitHub · 2026-11-25 19:58 UTC · original
Measured the same way as my earlier comment, on the same rig, and this one corrects it: the wait goes away, but above 3,000 draws the queue costs more than the wait it saves.
Rig: RX 7900 XT (RDNA3), Mesa 26.3.1 RADV, Proton experimental,
WINEDLLOVERRIDES="d3d12=n;d3d12core=n;dxgi=n",VICTORY_FRAME_LOG=1, 330 s a run, diag profile. Based510ee4aagainstd510ee4aplus this PR.The win is real and it is in the lane that waits:
texture refreshes per frame, all threads: 893 ms, of which 540 ms "waiting for title memory to hold still" (n=137) -> 100 ms with 0 ms of waiting (n=146).Bucked on draws and texture megabytes per frame, so the two runs are in comparable scenes, the same frames above 3,000 draws go the other way:
Inside those frames the movement is copies 213 -> 672, copying back 323 -> 1,240 ms, everything else 559 -> 1,020 ms, textures 1,613 -> 330 ms, GPU 104 -> 78 ms. Whatever the copying back does when the readers are no longer serialised, it is not the wait.
What I think the cause is: a read in place does not take a shared lock, it takes one global mutex, twice - once to push a reader into a
Vec, once to prune it withretain, thennotify_all. A frame above 3,000 draws has thousands of reads in place, and they are serialised on that mutex. The 540 ms of wait it removes is smaller than what the registration costs at that rate.I tried the cheap-reader version of this idea to see whether the shape is the problem: the address space cut into 512 stripes of 64 KiB, a read or a change taking only the stripes its range covers, ascending, all of them when the extent is unknown. The regression goes away -
3,000-6,000 draws, < 50 MB: 4,466 and 7,032 ms on base, 2,857 ms striped - so the shape is right. It also drops the property your testwaiting_overlapping_writer_prevents_new_readersexists for, and that showed:host GPU device removed 0x887A0005in 2 of 3 striped runs (at 1,129 and 5,860 draws), against none in 7 runs of base and of this PR at 7,096-10,360 draws. A read gets through a change of mapping, so I would not take that version anywhere near main, and I am not offering it as a patch.So: the wait removal is worth having, and the read path has to be cheap before it can be had at every draw count. Worth knowing before this is merged as an improvement to frame time in general.
Pull request closed