Skip to content

Page-mapping copies: the locks taken once a call (VICTORY_MAP_ONCE, opt-in): worst frame while the world streams 170-210 ms where it was 300-555 ms - #3850

Merged
trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
duckey-dev:page-mapping-once
Nov 30, 2026
Merged

trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
duckey-dev:page-mapping-once

Conversation

@duckey-dev

Copy link
Copy Markdown
Contributor

What was wrong

While the open world streams, the title's render thread spends a long time in our CopyPageMappings (queue.rs copy_page_mappings, then xmem::map_aliases, then alias for each range). One call took up to 64 ms, and these calls took 433 ms in 3.2 s of a timeline capture. Every other title thread was waiting on the render thread meanwhile.

On the one-mapping-thread path, each range of a call took these again, one after another:

  • The change of mapping. victory_gpu::title_memory_remapping (or _of with VICTORY_RANGE_LOCK=1) waits for every read of title memory in place to end.
  • PHYSICAL, the views.
  • The guards, through title_memory_remapped / title_memory_unmapping.
  • REMAPPED, the texture pass's queue, taken once for each note. The 16 DirectStorage workers take the same lock for every request they write (watch::writing).

Constant-source ranges (kind 1 in CopyPageMappingsBatchX: n destination pages that all show one pool page) arrive as n ranges of one page each. Each of those pages went through the whole sequence on its own: the locks, one unmapping and one mapping.

The one-mapping-thread path is the one players use. It runs when VICTORY_MAP_THREADS=1, which scripts/play.ps1, Play-VIctory.cmd and the foxhound settings set, or whenever soft views are on (side_by_side() returns 1 then).

What changes

Everything is behind VICTORY_MAP_ONCE=1. Off (the default), the code paths are exactly as before.

crates/victory-hle/src/modules/xmem.rs:

  • map_aliases, one-thread path (one_after_another): calls the new alias_all instead of alias for each range.
  • alias_all:
    • Joins destinations that sit side by side.
    • Takes the change of mapping and PHYSICAL once for all of them, through remapping_and_views(&wanted). That is the same helper and the same order one range uses.
    • Then does each range in order, exactly as alias_as did it alone. The first range that fails ends the call, as before.
  • alias_held: the body of alias_as, moved out unchanged, with the locks taken by the caller. alias_as now takes the locks and calls it, so the path with the switch off is the same code.
  • aliases_of: joins pages that sit side by side and are mapped from one and the same pool page into one "constant" range. It has a unit test.
  • alias_constant:
    • Leaves alone the pages that already show the source page (VICTORY_REMAP_SAME).
    • Unmaps the rest as one range for each run of consecutive pages. A view spanning several of them goes away in one unmapping instead of being cut down a page at a time.
    • Then gives each page its own view, as before.
    • If the source page lies inside the destinations, it falls back to the old page-by-page alias_held.
  • map_aliases, several-thread path (VICTORY_MAP_THREADS over 1): only the notes are gathered. The groups take their locks as before.
  • VICTORY_REMAP_TIMING=1: also logs the new path's lock wait (locks_us) and mapping time (map_us) for calls over 5 ms. This is next to the existing whole-call line in queue.rs.

crates/victory-gpu/src/descriptor/host.rs, watch.rs, lib.rs:

  • remapped_gathered(f): while f runs on this thread, remapped keeps its ranges in a thread-local list instead of taking REMAPPED.
    • The hooked heap's slots are still told at once (heap_hooks::changed, which takes no lock).
    • At the end, or on a panic, the kept ranges go into the queue in order under one taking of the lock (record_ranges).
    • A nested call just runs inside the outer one.
  • remapped_ranges: split into the heap_hooks::changed step and record_ranges. Its behaviour is unchanged.
  • victory_gpu::title_memory_notes_gathered: the public wrapper for remapped_gathered, re-exported from lib.rs.

Why opt-in

  • Readers wait longer. Readers of title memory in place (the GPU side's copies) now wait for the whole call where they used to wait for one range of it. The measurement below says this is a net win on one route, but it changes who waits, and other places (cutscenes, fast travel, other titles) are not measured.
  • The texture pass sees the notes later. Its notes for this call reach the queue at the end of the call, not range by range. Nothing reads the queue for these ranges before the title gets its call back: the pass that takes them runs at a later submission. But this is a change in timing.
  • A failed view inside a constant run leaves more pages unmapped. If the host refuses a view partway through a constant run, the later pages of that run are already unmapped, where page by page they would have kept what they showed. The call returns failure in both cases, and the title gets the same result.

Lock order

  • Same order as one range. alias_all takes the locks through remapping_and_views: the change of mapping first, then PHYSICAL. That is what alias_as and XMemMapPhysicalPages do, so no new order is introduced. It is the same pair, taken once and held longer.
  • Range lock. With VICTORY_RANGE_LOCK=1, the change is taken for what the views say every destination of the call touches, re-checked after PHYSICAL is held, exactly as for one range. A reader outside every destination still does not wait.
  • REMAPPED. While gathering, REMAPPED is taken once at the end, with the change and PHYSICAL still held. That is the same place it was taken before (inside title_memory_remapped / title_memory_unmapping, under the same locks), only once instead of once a range. remapped was already documented as being called with the runtime's locks held and calling nothing.
  • Other threads are not affected. The gathered list is thread-local. DirectStorage workers and the landing threads (watch::writing, land) still record directly.

How it was tested

  • GPU and profile: RX 7900 XTX, Ryzen 7 7800X3D, Windows 11, Series X, native 1440p, no DLSS/FSR, no frame generation, ray tracing off, VICTORY_MAP_THREADS=1 (the launcher's play settings). A scripted walk in the open world right after loading a save. 6 runs with the switch, 5 without.
VICTORY_MAP_ONCE=1 off
Worst frame of the run 170-210 ms 300-555 ms
99.9th percentile frame 113-153 ms 213-256 ms
Settled frame rate unchanged unchanged

The ranges do not overlap, but the limits are real:

  • 11 runs in all.

  • One machine.

  • One route.

  • Measured on a branch that combined this change with other open pull requests, not on main alone.

  • cargo test passed for the crates it touches: no failure that main does not have on this machine (main fails a_read_by_range_waits_only_for_a_remapping_that_meets_it and three bcpack oracle tests here, with or without this change). Both of CI's clippy runs add no warning over main.

Not tested

  • In the game on main alone. This branch (the change cherry-picked onto main without conflicts) was built and checked with CI's commands on Windows, but not run in the game by itself; the measurement is from the combined branch.
  • Several mapping threads with the switch on. Only the gathered notes apply on that path.
  • Ray tracing on, other GPUs (NVIDIA, Intel), Linux/Proton, Series S settings.
  • The new paths have no unit tests of their own. The existing map_aliases tests run with the switch off, so they cover only the unchanged path and alias_held (which now holds the moved body). alias_all, alias_constant and remapped_gathered are not unit-tested. Only aliases_of, the joining rule, has a test.
  • Soft views with the switch on. Soft views send copies through alias_held and place with Soft::NotedCopies, as before, and their notes are gathered.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.

None of these replaces this change. As far as I can tell, each one changes something else that the same calls contend on. I test-merged each against this branch with git merge-tree: #2439, #2650, #3292, #3480, #3553, #3603, #3621, #3650, #3733 and #3760 merge cleanly.

🤖 Generated with Claude Code

…notes recorded at its end, constant-source pages unmapped as one range (VICTORY_MAP_ONCE)

Off by default. With VICTORY_MAP_ONCE=1, map_aliases on its one-thread
path takes the change of mapping and PHYSICAL once for every destination
of the call (remapping_and_views, same order as one range), does each
range as alias_as did alone (alias_held), joins pages mapped from one
constant pool page into one range (alias_constant: one unmapping for the
run, a view a page), and gathers the descriptor queue's notes
(descriptor::host::remapped) into one taking of REMAPPED at the end
(victory_gpu::title_memory_notes_gathered). With several mapping threads
only the notes are gathered. VICTORY_REMAP_TIMING=1 also logs the lock
wait and mapping time of the new path.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added the pr-performance Pull request: makes it faster or use less memory label Nov 30, 2026
@github-actions github-actions Bot changed the title [pr-performance] Page-mapping copies: the locks taken once a call (VICTORY_MAP_ONCE, opt-in): worst frame while the world streams 170-210 ms where it was 300-555 ms Page-mapping copies: the locks taken once a call (VICTORY_MAP_ONCE, opt-in): worst frame while the world streams 170-210 ms where it was 300-555 ms Nov 30, 2026
@akimfomin

Copy link
Copy Markdown

@duckey-dev Thanks for publishing both A/B ranges and the failure-path difference. Our native 1440p Series X walk with original RT on RTX 4070 Ti SUPER still has long frames and a heavily occupied submit thread. Did you capture the split between locks_us and map_us, or try gathering REMAPPED notes while keeping the original per-page map/unmap order? That variant would help us isolate lock contention with the existing partial-failure behavior. We can cross-check the timing on RTX once we have that comparison pinned.

@duckey-dev

Copy link
Copy Markdown
Contributor Author

@akimfomin I had not captured the split: my measuring script filtered that log target out, so the runs in the description only compared whole-run frame times. I have now run the walk once each way with VICTORY_REMAP_TIMING=1 (same machine, RX 7900 XTX, ray tracing off, 164 s each, calls of 5 ms and over):

calls >= 5 ms their total longest waiting for the locks mapping
off 180 2,077 ms 111.5 ms not split on this path 2,075 ms
VICTORY_MAP_ONCE=1 150 1,724 ms 145.8 ms 6 ms 1,718 ms

So on this machine the wait for the change of mapping and PHYSICAL is next to nothing (6 ms of 1,724), and the time is in the map/unmap work itself (map_us here covers everything after the locks are held: the unmappings, the views, the guards' notes). What the switch saves is about a sixth of the total in this pair, which fits fewer unmappings for constant-source runs and one taking of REMAPPED, not less lock waiting. The description leans on the locks more than this supports; I'll correct it.

Two more caveats from this pair. It ran on a branch with about 30 more open PRs merged than the runs in the description (#3733 among them), and there the worst frame was 181 ms off against 143 ms on, far closer than the 300-555 against 170-210 in the description. So treat the size of the gain as unsettled until I have repeats on one tree.

The variant you describe exists here only on the several-thread path (VICTORY_MAP_THREADS over 1 with the switch on gathers just the notes and keeps the per-page order and locks); I have not measured it by itself. Given the split above I would expect little from notes alone on one thread, but if it helps your RTX cross-check I can add it as a second value of the switch.

moritz-eckhard-nickel added a commit to moritz-eckhard-nickel/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
… taken once a call, the texture pass's notes recorded at its end, constant-source pages unmapped as one range (VICTORY_MAP_ONCE))

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FormulaChenZen added a commit to FormulaChenZen/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
…ng paths

Wake only draws waiting for the affected pipeline and stop waiting when its compile is deferred. Publish placed-view shapes through immutable numbered slots. Handle adjacent soft copies of the same physical page under bounded remapping locks. Keep large gaps out of initial write-watch queries, retain full in-flight hazard checks, and publish the exact observed pages using word masks.

Based in part on upstream profiles and changes in VIctory-NVIDIA trustno1-coder#2188, trustno1-coder#2804, trustno1-coder#3760 and trustno1-coder#3850.
@trustno1-coder
trustno1-coder merged commit 281c6ba into trustno1-coder:main Nov 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request: makes it faster or use less memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants