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

Open
github-bot wants to merge 1 commit from github-bot/gh-95 into main AGit
Owner

@⁠LastThylacine on GitHub · 2026-11-24 21:26 UTC · original
LastThylacine:perf/texture-remap-lock → main · +271 −34 · 5 files · 1 commits · open

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

  • cargo test --workspace --locked: all pass.
  • victory-gpu has a new test: reads and changes of other bytes go on, and a change that waits keeps new reads of its bytes out. The existing test now uses ranges.
  • victory-hle's read-in-place stress test of xmem (2,000 remaps under a reader) passes, also with VICTORY_MAPPING_RANGES=0.
  • cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings: clean.
  • Merges without conflicts with the open PRs touching texture.rs, host.rs or draw.rs (#28, #30, #38, #43, #45, #47, #48, #58, #59, #63, #80).

🤖 Generated with Claude Code

**@⁠LastThylacine** on GitHub · 2026-11-24 21:26 UTC · [original](https://github.com/fxceless/victory-fork/pull/95) `LastThylacine:perf/texture-remap-lock` → `main` · +271 −34 · 5 files · 1 commits · open ### 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 - `cargo test --workspace --locked`: all pass. - victory-gpu has a new test: reads and changes of other bytes go on, and a change that waits keeps new reads of its bytes out. The existing test now uses ranges. - victory-hle's read-in-place stress test of xmem (2,000 remaps under a reader) passes, also with `VICTORY_MAPPING_RANGES=0`. - `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings`: clean. - Merges without conflicts with the open PRs touching `texture.rs`, `host.rs` or `draw.rs` (#28, #30, #38, #43, #45, #47, #48, #58, #59, #63, #80). 🤖 Generated with [Claude Code](https://claude.com/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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:04 +00:00
Author
Owner

@⁠BitWuehler on GitHub · 2026-11-24 22:39 UTC · original

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.)

**@⁠BitWuehler** on GitHub · 2026-11-24 22:39 UTC · [original](https://github.com/fxceless/victory-fork/pull/95#issuecomment-7146501091) 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.)*
Author
Owner

@⁠marquezinii on GitHub · 2026-11-25 05:27 UTC · original

Measured on the 6-core setup from #612: Ryzen 5 5600X, 32 GB, RTX 5070 12 GB (driver 621.40), Windows 11, Series X profile, diag build of 310c6eb with this PR cherry-picked (no conflicts). One exe, paired runs of 480 s each with the same scripted Enter input, warm shader cache, medians of the frame lines in the last 3 minutes in the world:

VICTORY_MAPPING_RANGES=0 this PR (default)
fps 1.3 3.3
ms/frame 767 305
preparing 307 101
textures 143 ms, 104 MB 8 ms, 15 MB
on the GPU 39 29
copying back 101 92

For scale, plain 310c6eb on a cold cache: 0.6 fps, 1,709 ms/frame, 1,103 ms of textures (e.g. 3,020.6 of 3,044.2 ms of refreshes waiting for title memory to hold still). With the PR that wait is 0.0 ms in every line. No device removal in any of the three runs; cargo test -p victory-gpu watch and -p victory-hle xmem pass.

One thing I noticed in the new frame line: with ranges the changes of mapping stay under way much longer. A: 94 changes, 0.5 ms waiting for reads in place, 2.6 ms under way. B: 91 changes, 0.0 ms waiting, 228.6 ms under way (207.7 in the line before). The code under the hold is the same, so my guess is that they now run beside the refreshes and copies and get less of a 6-core CPU, or meet the reads in the kernel's address-space lock. I have not measured which yet. The frame is still 2.5x faster, but the title's streaming threads spend longer per remap.

**@⁠marquezinii** on GitHub · 2026-11-25 05:27 UTC · [original](https://github.com/fxceless/victory-fork/pull/95#issuecomment-7153800178) Measured on the 6-core setup from #612: Ryzen 5 5600X, 32 GB, RTX 5070 12 GB (driver 621.40), Windows 11, Series X profile, diag build of `310c6eb` with this PR cherry-picked (no conflicts). One exe, paired runs of 480 s each with the same scripted Enter input, warm shader cache, medians of the frame lines in the last 3 minutes in the world: | | `VICTORY_MAPPING_RANGES=0` | this PR (default) | |---|---:|---:| | fps | 1.3 | 3.3 | | ms/frame | 767 | 305 | | preparing | 307 | 101 | | textures | 143 ms, 104 MB | 8 ms, 15 MB | | on the GPU | 39 | 29 | | copying back | 101 | 92 | For scale, plain `310c6eb` on a cold cache: 0.6 fps, 1,709 ms/frame, 1,103 ms of textures (e.g. 3,020.6 of 3,044.2 ms of refreshes waiting for title memory to hold still). With the PR that wait is 0.0 ms in every line. No device removal in any of the three runs; `cargo test -p victory-gpu watch` and `-p victory-hle xmem` pass. One thing I noticed in the new frame line: with ranges the changes of mapping stay under way much longer. A: `94 changes, 0.5 ms waiting for reads in place, 2.6 ms under way`. B: `91 changes, 0.0 ms waiting, 228.6 ms under way` (207.7 in the line before). The code under the hold is the same, so my guess is that they now run beside the refreshes and copies and get less of a 6-core CPU, or meet the reads in the kernel's address-space lock. I have not measured which yet. The frame is still 2.5x faster, but the title's streaming threads spend longer per remap.
Author
Owner

@⁠JRamos1993 on GitHub · 2026-11-25 11:01 UTC · original

On an RTX 5090 with current main (9376fd6), this PR together with #108 and #809 brings the median frame of the first two minutes in the world from 2.0 s to 0.76 s, and the time texture refreshes wait for remaps from 0.4–2.6 s a frame to 0.

Setup: Windows 11, RTX 5090, diagnostics build, Series X files, warm shader cache, network off. The same save and the same scripted keys for every run, 330–420 s each, with runs of the two builds interleaved. Times count from the first frame line with 500+ draws.

  • A: 9376fd6, 4 runs.
  • B: 9376fd6 with #95, #108 and #809 merged (no conflicts), 3 runs.
per run, from entering the world A, main B, with #95, #108, #809
median frame, first 2 min 1.3, 1.9, 2.2, 5.1 s 0.65, 0.76, 0.98 s
texture refreshes waiting for title memory to hold still, median per frame 0.4, 0.7, 0.9, 2.6 s 0, 0, 0
textures, median per frame, first 2 min 0.6, 1.3, 1.4, 3.9 s 0.05, 0.10, 0.10 s
worst frame 3.2, 5.6, 6.4, 9.9 s 2.0, 2.7, 5.0 s
last frame of 1 s or more +90, +112, +117, +172 s +82, +86, +148 s
median frame after the first 2 min 267, 276, 278, 1,063 ms 255, 258, 328 ms

How long frames stay slow varies a lot from run to run on both builds. The waiting time and the texture time don't: B has no wait in any run.

No crashes in B's runs. On the merged tree, cargo test -p victory-hle -p victory-gpu --locked passes: 100 and 145 tests.

I only measured the three together, so these numbers can't be split between #95 and the other two. The VICTORY_MAPPING_RANGES=0 pairs in the description and the comments above isolate #95.

**@⁠JRamos1993** on GitHub · 2026-11-25 11:01 UTC · [original](https://github.com/fxceless/victory-fork/pull/95#issuecomment-7160485475) **On an RTX 5090 with current `main` (`9376fd6`), this PR together with #108 and #809 brings the median frame of the first two minutes in the world from 2.0 s to 0.76 s, and the time texture refreshes wait for remaps from 0.4–2.6 s a frame to 0.** Setup: Windows 11, RTX 5090, diagnostics build, Series X files, warm shader cache, network off. The same save and the same scripted keys for every run, 330–420 s each, with runs of the two builds interleaved. Times count from the first frame line with 500+ draws. - **A:** `9376fd6`, 4 runs. - **B:** `9376fd6` with #95, #108 and #809 merged (no conflicts), 3 runs. | per run, from entering the world | A, `main` | B, with #95, #108, #809 | |---|---|---| | median frame, first 2 min | 1.3, 1.9, 2.2, 5.1 s | 0.65, 0.76, 0.98 s | | texture refreshes waiting for title memory to hold still, median per frame | 0.4, 0.7, 0.9, 2.6 s | 0, 0, 0 | | textures, median per frame, first 2 min | 0.6, 1.3, 1.4, 3.9 s | 0.05, 0.10, 0.10 s | | worst frame | 3.2, 5.6, 6.4, 9.9 s | 2.0, 2.7, 5.0 s | | last frame of 1 s or more | +90, +112, +117, +172 s | +82, +86, +148 s | | median frame after the first 2 min | 267, 276, 278, 1,063 ms | 255, 258, 328 ms | How long frames stay slow varies a lot from run to run on both builds. The waiting time and the texture time don't: B has no wait in any run. No crashes in B's runs. On the merged tree, `cargo test -p victory-hle -p victory-gpu --locked` passes: 100 and 145 tests. I only measured the three together, so these numbers can't be split between #95 and the other two. The `VICTORY_MAPPING_RANGES=0` pairs in the description and the comments above isolate #95.
Author
Owner

@⁠NotADonky43 on GitHub · 2026-11-25 21:04 UTC · original

I tested the disjoint-range approach in a separate Windows reproduction, alongside an ordered GPU copy-back/remap change. The important overlap is the full existing Windows view: replacing the middle page of a three-page view had to wait for a reader on either neighbor, because Windows temporarily unmaps the view. A reader on a separate allocation continued, and all three page contents matched afterward.

The range version also passed the D3D12 readback case where an earlier GPU copy is held behind a fence and must reach the old backing before the remap. This was an adapted implementation, not a test of the exact PR head. I don't have a synchronized moving-scene benchmark for #95 and wouldn't attribute an FPS gain to it from these checks.

**@⁠NotADonky43** on GitHub · 2026-11-25 21:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/95#issuecomment-7174586877) I tested the disjoint-range approach in a separate Windows reproduction, alongside an ordered GPU copy-back/remap change. The important overlap is the full existing Windows view: replacing the middle page of a three-page view had to wait for a reader on either neighbor, because Windows temporarily unmaps the view. A reader on a separate allocation continued, and all three page contents matched afterward. The range version also passed the D3D12 readback case where an earlier GPU copy is held behind a fence and must reach the old backing before the remap. This was an adapted implementation, not a test of the exact PR head. I don't have a synchronized moving-scene benchmark for #95 and wouldn't attribute an FPS gain to it from these checks.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/watch.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/95/head:github-bot/gh-95'
git switch 'github-bot/gh-95'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-95'
git switch 'github-bot/gh-95'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-95'
git switch 'github-bot/gh-95'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-95'
git switch 'main'
git merge --squash 'github-bot/gh-95'
git switch 'main'
git merge --ff-only 'github-bot/gh-95'
git switch 'main'
git merge 'github-bot/gh-95'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.