GPU tests: replay a world frame's copies of title memory (benchmark for the copy PRs) #1743
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!1743
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1743/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?
@marquezinii on GitHub · 2026-11-24 21:48 UTC · original
marquezinii:tests/world-frame-copies→main· +292 −0 · 2 files · 2 commits · closed without mergingCopy PRs keep competing for the same part of a world frame, the copies into and out of title memory (#400: 300–400 ms "preparing" and 50–150 ms "copying back" per frame at 1 fps; on some forks seconds). Each PR measures them with a fixture of its own, so they can't be compared. This adds one benchmark that any of them can be run against, on one machine, without the title.
What
shadow::world_bench::world_frame_copies(ignored by default) replays 6 frames of 36 submissions on a 174 MB write-watched heap, with what #400 and the forks' counters say world frames do:It goes through
update,writingandcopy_back, the calls the submission path makes, and prints the time of each part per frame. The pattern is seeded, so it is the same in every build. Each declared range is refreshed before it is declared, asgpu_writesasks.Two modes, the two ways
Host::executehandles shader-written ranges:world_frame_copies: snapshots each declared range before the submission (memory that is not tracked).world_frame_copies_marked: arms the declared ranges (writing(.., true)), sets the written-pages bit of each GPU write as a shader does, and runscopy_back_marksbefore the per-range copy-backs (tracked memory, since cd94d35/940d32f).It also asserts what copy-back must keep: the GPU's bytes reach title memory, and the title's writes during the run are not overwritten. A change that is fast but wrong fails.
On
mainat940d32f, RTX 5070, release, median frame of 5:The marked mode checks the same things, with one exception that it prints instead of asserting. A GPU write is kept out of title memory when it lands on a page that no declared range covers whole and that the title wrote since its copy last took it: 6 of up to 864 writes in this pattern. More on that in the comments.
Test-only: no change outside the new file and its
modline.Results on the open copy PRs (snapshot mode, before the marked path)
Each PR merged alone onto
ffe310ewith this file added. RTX 5070 host device, Ryzen with other work running (so expect the spread), release build. The cells give the median frame of each run, in ms.mainmain's rangemain's rangeThe snapshots and copy-back columns are frame 3 of each run.
main's range, about 2.5–3x shorter. Its snapshots, one copy per declared byte instead of the whole union again at each widening, take the largest part from ~2 s to ~0.25 s. #497 goes the same way at page granularity, with more spread.ffe310e.Tested
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, with and without--all-features, passes on940d32f.Not tested: the title; AMD hosts; a quiet machine (the spread above is between runs of the same build).
@marquezinii on GitHub · 2026-11-24 22:02 UTC · original
The red check is not this change.
mainitself (70564ae, its run) fails the same twovictory-shadertests:emit::synthetic_tests::gathers_at_a_level_match_the_hardwareandpermutes_read_the_lane_named_and_zero_from_lanes_left_out. This PR only adds an ignored test invictory-gpu.@aycow on GitHub · 2026-11-24 22:17 UTC · original
I ran your unchanged 174 MiB synthetic replay on Windows AMD with the GPU crate at opt-level 3, comparing exact 332152b on
ffe310eand its clean cherry-pick on70564ae(db1aca3, preserving your authorship). Five measured frames after warm-up gave median total CPU copy time 1,522.1 → 654.5 ms, snapshot 912.1 → 343.4 ms, copyback 515.5 → 222.0 ms, and refresh 94.5 → 87.3 ms. The checks passed and corresponding frames reported identical copied-back bytes. These samples measure the updated declared-range path. The separate 131,072-run fragmented replay remains a different case.AI-assisted using Codex.
@0xkn0wh3r3 on GitHub · 2026-11-25 03:12 UTC · original
On current
main(940d32f) this benchmark still measures the declared-range snapshot path. Sincecd94d35/940d32f, tracked memory takes the marked-page path instead, and that path is about 9× cheaper on the same pattern. Numbers are on #400; the short version, on an RTX 5070 Ti (release, 5 counted frames):Two notes for running it on
main:Shadow::writingtakes a third argument now.falsekeeps what the benchmark measures.Comparing the copy PRs in both modes would show which ones still matter for tracked memory.
@Marvisak on GitHub · 2026-11-25 03:36 UTC · original · edited 2026-11-25 07:27 UTC
Automated triage for the maintainers.
Merge candidate. Update after your reply:
005e263fixes theShadow::writing(.., marked)call, so the file builds onmain. It addsworld_frame_copies_marked, which arms the declared ranges, sets each GPU write's bit throughmark_entry/bitmap(), and runscopy_back_marks(&[])before the per-range copy-backs. Both benchmarks are#[ignore]d, seeded, test-only (#[cfg(test)] mod world_benchinshadow.rs), and assert that GPU writes reach title memory and that the title's own writes survive.The finding in your reply looks real and is worth its own issue or PR. I read the code the same way:
Shadow::updatetakes only pages it refreshed whole (the "taken, unless it holds the page in part" comment inshadow.rs), socopy_back_markedkeeps the title's page when a marked GPU write lands on a partly covered edge page that the title also wrote. The benchmark counts and prints those cases instead of asserting, which is the right call whilemainhas the gap.CI: failing, but in
victory-hle'smodules::dstorage::tests::a_page_list_filled_after_its_request_starts, which this PR does not touch. Thevictory-gputests pass.Generated by Claude Code
@marquezinii on GitHub · 2026-11-25 03:58 UTC · original
Updated in
005e263(rebased on940d32f), thanks @0xkn0wh3r3 for the sketch:writinggets the third argument, so it builds onmainagain.world_frame_copies_marked, built from your loop: it arms the ranges, marks each GPU write's page, and runscopy_back_marks(&[])before the per-range copy-backs. On an RTX 5070 the snapshot mode's median frame is 748–758 ms and the marked mode's is 86.6–92.6 ms, the same ~9× you measured.About the writes the marked mode loses. Part of it came from the benchmark itself. It refreshed some other range of the heap before declaring each range, but never the declared range, which
gpu_writesasks for. With that refresh added (both modes now do it), 6 losses remain over the run, out of up to 864 GPU writes. I printed where each one landed:That matches the code.
Shadow::updateonly takes pages it refreshed whole ("taken, unless it holds the page in part"), so an edge page the title has written stays changed, and the guard never saves its bytes.copy_back_markedthen seessaved == None && changedand keeps the title's page, because it can't tell the shaders' bytes from stale ones in the part that wasn't refreshed. The snapshot path doesn't have this problem, because it compares byte by byte against its snapshot.So on
main, a shader write through a marked view can stay out of title memory when it lands in the partly covered first or last page of a declared range, and the title touched that page during the frame. The benchmark counts these cases and prints them instead of asserting, so it passes onmainand shows the number. If you'd rather it fail until this is fixed, it's a one-line change.One way to fix it, which I haven't tried: when
writing(.., true)arms a range, save the copy's bytes of its partial edge pages that are changed. That's at most two pages per range.copy_back_markedwould then compare against those bytes as it does for a saved page. I can open that as a separate PR if it looks right.@Marvisak on GitHub · 2026-11-25 22:02 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because it no longer compiles on
main(bitmap()now takes amemory: bool, andcopy_back_markstakes(withheld, memory_withheld)), and #2134 covers the same ground more faithfully: it replays a frame's volumes throughHost::executeitself instead of calling theShadowmethods on an invented pattern.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed