Skip to content

Textures no longer wait for remappings of other title memory - #95

Open
LastThylacine wants to merge 1 commit into
fxceless:mainfrom
LastThylacine:perf/texture-remap-lock
Open

LastThylacine wants to merge 1 commit into
fxceless:mainfrom
LastThylacine:perf/texture-remap-lock

Conversation

@LastThylacine

Copy link
Copy Markdown

Problem

Texture refreshes at submission read title memory in place under watch::MAPPING, a lock over all of title memory that the runtime takes alone while it changes a mapping (XMemMapPhysicalPages, XMemMapPhysicalPagesScatter page by page, map_alias). While the world streams in, the title changes mappings 650-1,100 times a frame. Every refresh waited for changes anywhere in memory, and every change waited for the refresh under way. On an RTX 5070 Ti that was 203 ms of an 801 ms frame (median; mean 389 ms) spent "waiting for title memory to hold still".

Change

  • watch.rs: reads in place and changes of mapping hold only the bytes they touch (a mutex and a condvar over the ranges under way). They wait for each other only where those bytes meet. A change that waits for a read keeps new reads of its bytes out, as the writers of the old lock did. title_memory_reading, title_memory_reading_now and title_memory_remapping now take (at, len).
  • xmem.rs: reach() gives the bytes a change touches: the range, plus the whole of the views unmap takes away and maps again.
  • Callers pass their ranges: the texture refresh, rectangle vertices, and the xmem stress test.
  • VICTORY_MAPPING_RANGES=0 holds all of title memory, as before.
  • New frame line: changes of mapping per frame, the time they waited for reads in place, and the time they were under way.

Measurements

Pair of runs on one exe (1684989 + this change), warm shader cache, RTX 5070 Ti + i5-13600KF, 8 min each, medians over the world. A = VICTORY_MAPPING_RANGES=0, B = default.

A (one lock) B (by range)
frame, median 801 ms 486 ms
frame, mean / p90 1,099 / 2,199 ms 524 / 670 ms
textures 371 ms 47 ms
waiting for title memory to hold still (median / mean) 203 / 389 ms 0 / 0.6 ms
texture bytes read 233 MB/s 288 MB/s
changes of mapping waiting for reads 37 ms/frame 0
GPU / copies / copy back 150 / 44 / 79 ms 135 / 45 / 72 ms
draws dropped 375 /frame 363 /frame
device removed no no

A matches plain main 1684989 (768 ms frame, 191 ms waiting). The captured frames show the same lit opening scenes, and B gets further into them in the same time. Nothing is skipped: B reads more texture bytes per second.

For comparison, VICTORY_TEXTURE_NO_WAIT=1 on main 1684989 (same exe, warm) gives 768 → 530 ms. It reads 91 MB/s of textures against 228 and leaves about 61 refreshes a frame for later, because pages of streaming textures are missing when it reads through the kernel. This change gets the frame time without skipping refreshes. The switch still works and now only gives up when the texture's own bytes are being remapped.

Tests

🤖 Generated with Claude Code

Reads of title memory in place (texture refreshes at submission, rectangle
vertices) and the runtime's changes of its mapping (XMemMapPhysicalPages,
its scatter form, map_alias) shared one lock over all of title memory.
While the world streams in the title changes mappings 650-1,100 times a
frame, many a page at a time, so every refresh waited for changes anywhere
and every change for the refresh under way.

Now a read holds the bytes it reads and a change the bytes whose mapping it
changes (the range, and the whole of the views unmap takes away and maps
again); they wait for each other only where those meet. A change waiting
for a read keeps new reads of its bytes out, as the lock's writers did.
VICTORY_MAPPING_RANGES=0 holds all of title memory, as before. A new frame
line gives the changes per frame, the time they waited for reads in place
and the time they were under way.

Paired runs on one exe (1684989 + this change) with a warm shader cache,
RTX 5070 Ti, 8 min each, medians over the world; A with
VICTORY_MAPPING_RANGES=0, B without:
- frame 801 -> 486 ms (mean 1,099 -> 524, p90 2,199 -> 670)
- textures 371 -> 47 ms, of them waiting for title memory to hold still
  203 -> 0 ms (mean 389 -> 0.6)
- texture bytes read 233 -> 288 MB/s: nothing is left out
- the runtime's changes waiting for reads 37 -> 0 ms a frame
- GPU 150 -> 135 ms, copies 44 -> 45, copy back 79 -> 72; drops 375 -> 363
- no device removal in either; slow submissions 4 and 5
- frames: the same lit opening scenes, B further into them in the time
For comparison, VICTORY_TEXTURE_NO_WAIT=1 on 1684989 (pair 768 -> 530 ms)
reads 91 MB/s against 228 and leaves ~61 refreshes a frame for later.

Tests: victory-gpu (new: reads and changes of other bytes go on, and a
change that waits keeps new reads of its bytes out), victory-hle (the
read-in-place stress test of xmem), the workspace; clippy in both CI
configurations. Rebased onto 4e17478 without conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BitWuehler

Copy link
Copy Markdown

Verified on Linux/Proton (CachyOS, Ryzen 7 9800X3D, RTX 5080 620.73.04, GE-Proton11-14, release profile, Series X files), combined on 4e17478 with #454, #127, #154, #92, #108, and #159 (vs the same local stack without #95/#108/#92/#159 immediately beforehand):

Metric (world intervals, draws >= 100) Before (230242, n=38) After adding #95 + #108 + #92 + #159 (232121, n=41)
waiting for title memory to hold still (med / mean / max) 22.25 ms / 280.66 ms / 3,536.60 ms 0.00 ms / 0.00 ms / 0.00 ms
textures inside preparing (med / mean / max) 596.55 ms / 892.66 ms / 3,865.10 ms 91.30 ms / 122.55 ms / 561.60 ms
ms/frame (med / mean) 1,190.20 ms (0.85 fps) / 1,845.95 ms 867.10 ms (1.20 fps, max 6.10 fps) / 1,312.95 ms
indirect dropped draws (mean / max) 207.89 / 2,073 3.49 / 10
gpu median 67.55 ms 50.90 ms
  • Final world interval (5,426 draws/frame): 1.9 fps (521.4 ms/frame: 102.4 preparing with textures 10.5 ms 8.1 MB, 75.6 GPU, 16.6 copy-back 42.3 MB; 49–67 mapping changes/frame, 0.0 ms waiting for reads in place).
  • victory-gpu (114/115 non-ignored pass; only known vkd3d-proton CreatePipelineLibrary stub fails) and victory-hle xmem tests pass under GE-Proton11-14. Clean 353 s world session with 0 crashes or device removals.

(Note: measured as a bundle alongside #108, #92, #159, so overall gains reflect the bundle; the 0.00 ms elimination of waiting for title memory to hold still directly reflects #95. AI-assisted log extraction.)

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