Skip to content

GPU: ask whether guarded memory is a view once per block, not per asking - #490

Closed
wbkepler wants to merge 2 commits into
Marvisak:mainfrom
wbkepler:gpu/guard-view-cache
Closed

wbkepler wants to merge 2 commits into
Marvisak:mainfrom
wbkepler:gpu/guard-view-cache

Conversation

@wbkepler

Copy link
Copy Markdown

Stacked on #464. This branch contains #464's commit; only the second commit is new. Review that commit alone, or after #464 merges.

Problem

Memory that can't be write-watched (physical-page views) goes through watch::guard. Each asking began with VirtualQuery on its start to check that the memory is a view. In the world, the 174 MB GPU heap and blocks inside it are asked about thousands of times a frame. With temporary timers on #464, that one query took 94–235 ms per world frame. By comparison, the rest of the guard took 4–7 ms of VirtualProtect and 4–10 ms of opening blocks.

Change

crates/victory-gpu/src/watch.rs only:

  • Guards gains a views set: the blocks where an asking began and that the query found to be in a view. A later asking starting in such a block skips the query.
  • The check and the insert happen under the guards' lock. title_memory_remapped takes that lock and drops the blocks in its range from views, so a block's entry can't outlive a map or unmap. The runtime calls the hook after mapping a view and before unmapping one.
  • Memory that isn't a view is never cached. It is queried every time, as before; its host copies stop asking after the first answer anyway.

Measured

Diagnostics build, RTX 5090, same save, start screen to world. One run each: #464 alone, then #464 plus this change. These are the copystat world windows. The guard time is the temporary timer around guard; the other numbers come from the existing counters.

per world frame #464 + this
guard time (temporary timer) 102–237 ms for 27–47 GB asked 24–35 ms for 21–35 GB asked
watches, total 118–264 ms 38–52 ms
preparing 195–444 ms 195–357 ms

Example world lines:

Frame-to-frame scenes vary a lot. The watch-time drop is the clear signal; preparing improves less visibly within the noise.

I also tried walking a guarded range by runs of blocks instead of looking up every block. It made no measurable difference, so it isn't included: the query was the cost, not the walk.

Tests

  • New watch::tests::views_are_queried_once_until_remapped. A test-only per-thread counter shows that a view is queried once per start block, and again after title_memory_remapped. Private memory is queried, and refused, every time.
  • The existing guard tests pass.
  • cargo fmt --check (watch.rs), cargo clippy --workspace --all-targets, cargo clippy -p victory --features diagnostics --all-targets (no new warnings), cargo test --workspace, and cargo xtask policy all pass.

🤖 Generated with Claude Code

@upipibi upipibi mentioned this pull request Nov 24, 2026
aycow added a commit to aycow/VIctory that referenced this pull request Nov 24, 2026
Plan only requested pages outside pending GPU writes. Use a verified
reservation extent for dense groups and share a fresh observation within
each group. Query journal chunks against the oldest valid shadow bytes.

Adapt the clean guarded-memory path from PR Marvisak#393 and the guarded view
lookup cache from PR Marvisak#490. Remap and allocation notifications invalidate
their proof. Preserve exact byte coverage and journal observations across
mixed allocations, including the wholly reserved case examined in Marvisak#515.

Co-authored-by: KaiserBloo <kaiserbloo@protonmail.com>
Co-authored-by: wrothgaril <211408787+wrothgaril@users.noreply.github.com>
Callimann8 added a commit to Callimann8/VIctory-fork that referenced this pull request Nov 24, 2026
…once per block)

Conflicts in watch.rs: the PR's range bookkeeping with main's
overflow-safe saturating_add; both new tests kept. World frame time on
the RTX 4070: 2,656 -> 2,285 ms (upload copies 520 -> 142 ms).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Callimann8 added a commit to Callimann8/VIctory-fork that referenced this pull request Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pablogonz12

Copy link
Copy Markdown

Measured on Linux (RX 9070 XT, RADV/Mesa 26.3.1, GE-Proton11-14, vkd3d-proton master, diagnostics build), 240 s world runs, last 8 frame-rate lines, 2 runs per side. Head e6f9159 (+#464) merged onto our tree, which also carries #393/#124 — the watch.rs conflict was resolved into one writes with #393's journal fast path over this PR's views/absent bookkeeping:

copies ms/frame write-watch ms/frame fps
before #393/#124 2431 / 2571 1338 / 1351 0.29 / 0.35
with #393/#124 2036 / 1732 942 / 829 0.35 / 0.26
+ this PR 628 / 864 459 / 573 0.46 / 0.45

No device removed, no panics. victory-gpu tests under Wine: watch 7/7, shadow 4/4.
Not tested: native Windows; in-game on this PR alone (the row above is the merged tree).

simnJS pushed a commit to MiamiGame/XTP that referenced this pull request Nov 24, 2026
Every asking about memory that cannot be write-watched called
VirtualQuery on its start to tell whether it is a view (which is then
guarded). In the world that query cost 100-230 ms per frame, more than
the rest of the guard together: the 174 MB GPU heap and blocks inside it
are asked about thousands of times a frame.

Remember the blocks found to be in a view where an asking began, under
the guards' lock, until title_memory_remapped (which the runtime calls
when it maps or unmaps views) drops them. Memory that is not a view is
asked about each time, as before (its copies stop asking after the first
answer).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ported from Marvisak/VIctory#490 (head e6f9159) by wbkepler
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…re-copying them every submission

Head 41af42e (wbkepler). Conflicts in watch.rs: Guards holds our
announced blocks, #1277's view cache and #464's absent blocks;
title_memory_remapped forgets all three for the range and keeps our
placed-texture eviction. Tests: both sides'.

#490 (one view query per block) is left out: #1277, merged before,
does the same with the query outside the lock and the unmapping
reported after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MfDev0 referenced this pull request in MfDev0/victory Nov 24, 2026
Port of upstream JMAN730#490 (the view half; JMAN730#464 is the commit before): the block an asking starts at is remembered as a view until the runtime remaps it, so the system is asked once instead of every submission (100-230 ms per world frame measured there).

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
wbkepler and others added 2 commits November 24, 2026 21:48
A copy of view memory (physical-page views, which cannot be
write-watched) guards each 64 KiB block it took read-only. A block that
is not mapped (a placeholder between views of a GPU heap) cannot be made
read-only, so it never became clean: every asking reported it written
again, and the copy read it through the per-page fallback, whose
failing kernel reads cost hundreds of ms per world frame.

Note such blocks absent (only after VirtualProtect fails and the block is
not committed). An absent block is not reported again until
title_memory_remapped, which the runtime calls after mapping or
unmapping views, clears it. The copy keeps the zeros it took.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every asking about memory that cannot be write-watched called
VirtualQuery on its start to tell whether it is a view (which is then
guarded). In the world that query cost 100-230 ms per frame, more than
the rest of the guard together: the 174 MB GPU heap and blocks inside it
are asked about thousands of times a frame.

Remember the blocks found to be in a view where an asking began, under
the guards' lock, until title_memory_remapped (which the runtime calls
when it maps or unmaps views) drops them. Memory that is not a view is
asked about each time, as before (its copies stop asking after the first
answer).

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

Copy link
Copy Markdown
Author

Rebased onto current main (ffe310e) as 1d46278, on top of the rebased #464 (9dd1507, which keeps main's saturating_add guard); no content conflicts after restacking. Gate clean.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

@wbkepler
wbkepler force-pushed the gpu/guard-view-cache branch from e6f9159 to 1d46278 Compare November 24, 2026 20:50
@Marvisak Marvisak closed this Nov 24, 2026
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…periodic saves back off

Loads and stores take one of 64 mutexes chosen by pipeline name instead of one
lock over the whole library. Stores share a RwLock that a save holds
exclusively, so loads never wait on a save. A periodic save that finds another
running is skipped, and saves back off at 20, 40, 80, then every 160 s and at
least 30x the last save's duration.

Closes Marvisak#490

Co-authored-by: JMAN730 <JMAN730@users.noreply.github.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…ary-mutex-490-111a

GPU: parallelize pipeline library loads under striped locks (Marvisak#490)
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.

3 participants