GPU: copy into title memory without asking for its region first #322
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!322
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/322/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?
@jsthope on GitHub · 2026-11-24 02:16 UTC · original
jsthope:gpu/title-copies-without-region-queries→main· +124 −19 · 1 files · 1 commits · merged 2026-11-25 00:16 UTCWhat
Two copies into title memory ask the host about the destination before every copy:
copy_mappedwith a title destination (a list's buffer copies) first checks that the whole destination is committed, withVirtualQuery(texture::committed).write_mapped(the copy-back of what shaders wrote) usesWriteProcessMemory, which asks for the destination's region before it writes, for every 64 KiB piece.copy_mapped's comment already says what such a query costs when it was asked about the source ("about 2 ms per copy in the title's big pools"): it walks the page tables to the end of the region with the same state, whatever the size of the copy. In the world the destinations were private pools of about 600 MiB.Change
Both use the kernel copy the other copies already go through (
ReadProcessMemoryon our own process). It fails on a destination page that is not mapped writable as it does on a source page it cannot read, without faulting.copy_mapped: the copy runs first. A title destination is asked for its region only once its copy has failed, which keeps the page retries (they write their zeros themselves) off unmapped memory.write_mapped: the same pieces as before, written by the kernel copy.One file,
crates/victory-gpu/src/host.rs.Behaviour
write_mapped: unchanged. Mapped pages are written, unmapped and read-only pages are not. Compared withWriteProcessMemoryon reserved, partly committed and read-only memory: same result, same partial copy.copy_mapped: one difference. A title destination that was not all mapped used to be left alone. Now the bytes before its first unmapped page may arrive, because the kernel copy stops at that page; nothing is written from that page on. In the run below none of the 3,274 title copies had such a destination, and none failed.Numbers
World (first mission's intro); i7-13650HX, RTX 4060 Laptop, Windows 11, diagnostics build. Temporary counters, not in this PR, timed the old and the new call on the same copies of one run, 41 frames of about 1.15 s each:
That is 98 ms of a frame (8.6 %) down to about 1 ms.
Stacks of the submitting thread sampled at 10 Hz (
VICTORY_STACKS):VirtualQueryunder these two calls was 47 of 462 samples before and 0 of 189 after. TheVirtualQueryleft in that profile is the one inwatch::guard, which #119 addresses. This merges cleanly with #119, #202 and #124.Synthetic, same machine: writing a 64 KiB piece into a committed view of 64 MiB / 512 MiB / 2 GiB takes 118 µs / 1.1 ms / 8.0 ms with
WriteProcessMemory, and 6 µs with the kernel copy whatever the view.Tested
cargo test -p victory-gpu: 45 passed, 1 ignored, also with--features diagnostics. Two new tests run both copies against reserved memory with a committed block on each side of a hole (no GPU, no game data).cargo clippy -p victory-gpu --all-targets: no new warning.cargo xtask policy: ok.main(five runs out of five) as with this change.No game assets or derived data are included.
AI-Assisted
@ifBars on GitHub · 2026-11-24 02:31 UTC · original
On Windows 10 I compared this with Causeway's previous destination-region query on the same buffers. Median time for a 64 KiB write-back into a touched, committed 64 MiB mapping fell from 205 to 3.86 µs. On a 512 MiB mapping it fell from 4,890 to 3.75 µs. A sparse write spanning a reserved 64 KiB hole went the other way, from 27.6 to 81.9 µs.
Our adaptation also exercises a read-only destination with an unaligned source. The fallback stops the title copy at the inaccessible page and preserves the unmapped-hole behavior on write-back. These are synthetic CPU measurements. We haven't measured story frame time on this change.
@tcurtsinger on GitHub · 2026-11-24 02:41 UTC · original · edited 2026-11-24 02:55 UTC
Tested
f7bfa64againstd2a4baeon Windows 11 build 26300, Ryzen 9 9950X3D. Each value is microseconds per 64 KiB piece copied by the production function into a fully committed, pre-touched pool.Four fresh processes per revision ran in interleaved order. In each process a batch used 32 disjoint destinations, with three warm-up batches and nine timed batches. The table shows medians of the four process medians. We changed the input pattern each batch, verified every copied byte and checked a sentinel on either side. The two title-copy tests in this PR also passed on this machine.
We have since run the user-controlled intro on the RTX 4080 with this PR. The local build also included #87's reporting fix and the free-slot diagnostics on #251. The menu held 30 FPS. The single detailed report above 1,000 draws per frame registered 0.8 FPS at 3,795 draws, including 111.7 ms in the whole copy-back phase for 10.7 MB. The window later reported 433.9 ms per frame (about 2.3 FPS) at 1,925 draws. The game exited after a GPU hang 64.3 seconds after launch. Peak process memory was 22.85 GiB private and 12.84 GiB resident.
The previous build logged four busy samples at 1,205–2,248 draws with 48.5–68.5 ms of copy-back time. The workloads differed, and the phase timer includes both comparing snapshots and writing changed bytes. This single run did not establish a change in intro FPS attributable to this PR. Previous native run.
AI-assisted testing (Codex).
@Kadthicu on GitHub · 2026-11-24 09:33 UTC · original
Small documentation suggestion for
copy_mapped: could its doc comment explicitly mention that a failed copy may already have modified the destination prefix? The test with the unmapped middle block checks that the third block stays untouched and leaves the first block unspecified.read()already mentions possible partial copies, so this would make the same contract clear at the caller-facing helper. Reviewed the diff with OpenAI Codex (GPT-6 family). No Windows test run.@elamriz on GitHub · 2026-11-24 12:01 UTC · original · edited 2026-11-24 12:10 UTC
Windows RTX 4070 Ti A/B for
b58d198. I applied #322 to the same local6aa72a6+ #454 integration used for the baseline. The title watchdog was enabled for both runs. Both used the hardware adapter (driver 621.14), D3D12 Debug and DRED, a fresh cache, the same scripted input, and the same offline AppContainer setup. Both reached the 300-second harness limit without a device removal or unhandled exception.Medians of the logged samples below 2 FPS, one run per build:
This run agrees in direction with #400, with a larger effect on this setup. The reported workload varies, and I have not verified visual playability or run-to-run variance. AI-assisted testing and reporting. No raw logs or title files attached.
Cold-cache repeat with a few local frame captures: 40 logged samples below 2 FPS, median 1,366.4 ms per frame, 340.3 ms copying back, and 361.8 ms on the GPU. The run reached the same 300-second limit without device removal or an unhandled exception. The captures show loading art fading to a black frame. Later black-frame warnings continue while draws are submitted. 3D gameplay remains unverified.
@AgneyaK on GitHub · 2026-11-24 16:37 UTC · original
Test report on an RTX 3050 6 GB Laptop (i7-13700H, 16 GB RAM, Windows 11 26300), diag build, title 1.0.2.1, Series X profile. Base tree:
mainffe310e+ #208 + #223 #233 #320 #439 + #452 + #579 (VICTORY_SKIP_WAVE64=mesh), from #1232. #472, #322 and #1024 merge cleanly onto it.So about 12% shorter frames, mostly copies (−36%) and copy-back (−18%). One run each, and the three were
not separated.
On this 16 GB machine much of the rest looks like paging: private bytes reach 22.9 GB and the working set is trimmed to 2-5 GB (numbers in #1232).
AI use: Claude Code (Claude Opus 5.5) merged and built the trees, ran the title on my machine and drafted this note; results are from the runs described.
@EgoraWyn on GitHub · 2026-11-24 15:13 UTC · original · edited 2026-11-24 17:09 UTC
Test report: NVIDIA RTX 3060 Laptop 6 GB, process held to 4 CPUs. With this PR copy-back drops from 531 ms to 125 ms per world frame; the call it replaces cost 2.35 ms per 64 KiB piece here.
Setup: Windows 11 build 26300, driver 596.21 (32.0.15.9621), i5-12450H, 32 GB RAM, title 1.0.2.1 (own copy), Rust 1.98.1, diag build.
Base:
mainffe310e+ #493 (c48b240) + #206 (05981dd) + #189 (b472733) + #454 (d2c93fa) + #211 (24a387d) + #492 (b57e10d) + #431 (23ced70) +MIN_DYNAMIC = 1 << 18(#747) + the log line of #952, plus local timers around the steps ofcopy_backand the refresh (measuring code only, not for upstream). This PR atb58d198merges onto it without conflicts. Series S mode,VICTORY_NO_WATCHDOG=1 VICTORY_SHADER_LOOP_LIMIT=32 VICTORY_D3D12_DRED=1, 420 s per run. Figures are for the world phase: from 20 s after the first 5-second log line with more than 100 draws per frame, to the end of the run.write_mappedWriteProcessMemorykept as the second try, gave 132 ms of copy-back per frame and a median of 0.60 fps on the same tree. This PR makes that unnecessary.One run per column.
Correction, later the same day. The runs above had
VICTORY_D3D12_DRED=1, and DRED makes Windows' write-watch queries several times slower on this machine. On a later tree (the base above with this PR, #189 at54b333fin its emulate mode, the lane fix of #940 and a local change to when refreshes are flushed), the same world run with and without DRED, one run each:write_mapped, mean per 5 sSo the bullet above about the refresh ("the write-watch queries take 1.7–2.2 s of every 5 s") describes DRED, not what is left of a frame. This PR's effect is not touched by that: the write call stays at a few milliseconds per 5 s either way. Without DRED the larger costs here are, per 5 s: the snapshots for copy-back 1.2 s (6.0 GB copied), the stale-page copies of the refresh 1.2 s, and the copy-back loop 0.5 s.
AI use: Claude Code (Claude Fable 5.2) built the trees, wrote the local timers, ran the runs and wrote this report from the logs; a second tool (Codex) checked the numbers against the logs. The hardware, the title copy and the runs are the user's.
@Daniel333313131 on GitHub · 2026-11-24 20:29 UTC · original
The AMD side of the #400 measurement for this PR. As on the RTX 5070 Ti, copying back clearly drops. Whole frames are not clearly shorter.
Setup: AMD Radeon RX 7900 XTX 24 GB, driver 32.0.32029.2010; Ryzen 7 9800X3D, 32 GB; Windows 11 10.0.26300. Diag build of this PR's head
b58d198merged alone ontomainffe310e. Each run used its own emptyVICTORY_CACHE_DIR,VICTORY_D3D12_DRED=1, andVICTORY_KEYSset to Enter every 3 s from 8 s to 47 s. Each run was stopped after 180 s. The method and themainnumbers are in #400.mainmainmainmain, outsidemain's range in every run. That matches what #400 saw on NVIDIA.main's spread.mainon this GPU. That one is addressed by #431, not by this PR. Because removal came early, there are only 5, 10 and 5 world lines per run.AI use: Claude Code (Claude Opus 5.5) merged and built the commits, ran the title, summarised the log lines and wrote this comment. The numbers come from the runs above.
@Daniel333313131 on GitHub · 2026-11-24 20:43 UTC · original
Follow-up to my comment above: the same test with #431 merged too. #431 keeps the title in the world for longer on this GPU. With both PRs, whole frames are now shorter than with #431 alone.
Setup: as above (RX 7900 XTX, driver 32.0.32029.2010, Ryzen 7 9800X3D, diag build).
mainffe310ewith #43123ced70and this PRb58d198merged. Each run used its own emptyVICTORY_CACHE_DIR,VICTORY_D3D12_DRED=1, andVICTORY_KEYSset to Enter every 3 s from 8 s to 47 s. Each run was stopped after 180 s.mainAI use: Claude Code (Claude Opus 5.5) merged and built the commits, ran the title, summarised the log lines and wrote this comment. The numbers come from the runs above.