Skip to content

GPU tests: a world frame's preparing at the published volumes (benchmark) - #2134

Open
r4tedx wants to merge 5 commits into
Marvisak:mainfrom
r4tedx:gpu/prepare-bench
Open

r4tedx wants to merge 5 commits into
Marvisak:mainfrom
r4tedx:gpu/prepare-bench

Conversation

@r4tedx

@r4tedx r4tedx commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The title run on 940d32f in #400 (comment, RX 6700 XT) put 774–1,198 ms of a 1.2–2.0 s world frame into preparing submissions on the CPU, and published the volumes behind it: 21,974 refreshes asking for 20.6 GB, 254,139 change checks over 92.8 GB of which 99.7 % was unchanged, 7,147 protect calls, 698,986 page faults. Nothing in the tree replays those volumes, so a change to the refresh, guard or arming code can only be measured in the title.

This adds an ignored benchmark, host::frame_bench::world_frame_preparing, that does. It needs no title and no hardware GPU: it runs on the software adapter.

What it does

It makes 4,100 host copies of 1.6 GB of made-up title memory of the two kinds the runtime gives a title: write-watched pools, and physical pages shown through two views (one view per run, and again page by page through placeholders, reported with title_memory_aliased as xmem reports them). Then it records and runs frames of 33 submissions of 12 lists through Host::execute itself, so the refresh batch, Shadow::update, the guards and their fault handler, arming, snapshots, the page table's prepare and both copy-backs are the real ones. The lists record no GPU commands.

Per frame it asks for what the published line asks for. The left column is this benchmark on main 63bcca4 (WARP, diag profile, median of 5 frames), the right the title run on 940d32f:

per frame benchmark published
refreshes 22,499 21,974
asking for 21.0 GB 20.6 GB
change checks 1,325 254,139
checked 6.7 GB 92.8 GB
changed and copied 244 MB 240 MB
protect calls 7,900 7,147
snapshots 577 MB 563 MB
marked pages compared 983 1,996
title copies 75 75

It prints the frame's parts next to the published numbers (with the diagnostics feature, every counter of the copies per frame line), and then what each mechanism costs on its own: a check of a copy nothing wrote, a check of the heap under declared ranges, declaring a range as written, a guard's round (the title's write, the fault, the next refresh) on each kind of memory with the page faults it causes, and a copy through the kernel against one in user mode.

What the published line does not say is made up, and the file says so at each constant: how many copies there are and how large (4,100 of 365 KB on average follows from the checks; memory.rs names the count), which lists use title memory, how many ranges shaders declare, and whether the title writes the same pages every submission. Not modelled: title threads writing while a submission is prepared (the title's writes come between submissions, on the same thread), heap-indexed views (Step::Heap), textures.

What it showed on 940d32f (synthetic)

Ryzen 7 7800X3D, WARP, diag profile with diagnostics, median of 5 frames after 2 warm-up frames, three runs:

benchmark published
preparing 168–225 ms 1,198 ms
of it: refresh batches (checks and copies) 115–156 ms
of it: snapshots 29–37 ms 31.7 ms
of it: naming every copy for title memory 17–22 ms 109 ms
in the kernel's copies 22–27 ms
protecting 10–13 ms
copying back 115–135 ms 122 ms
page faults 962 698,986
  • Checking copies nothing wrote was the largest part on 940d32f. A check costs 138–146 ns on its own and 332–354 ns through a refresh batch, 274,094 times a frame: about 90 ms, half of preparing here. A separate PR removes it.
  • On current main the refresh batch no longer checks copies that nothing wrote: a frame makes 1,325 change checks, not the 274,094 this benchmark made on 940d32f and not the title's published 254,139. JoeY54 and xndbogdan got the same counters on four hardware adapters. distant_refreshes_preparing adds one batch with ranges a page apart and 8 MiB apart in one copy, and prints how many bytes it checks and copies. That tells apart a batch that keeps one span, one that joins ranges a page apart, and one that keeps exactly what was asked.
  • "GPU writes" is mostly the refresh batch it flushes. The step shows 147–197 ms here as it shows 563 ms in the title, and nearly all of it is the batch a root UAV's declaration flushes, plus the snapshots. Declaring a range through marked views costs 31–36 µs when it runs from the start of a 174 MB copy to its end (a set entry per page) and 0.1 µs for its last megabyte.
  • The guards cause no page faults. A guard's round costs 3.2–6.0 µs for the title's write and 4.0–6.6 µs for the refresh, on either kind of memory, with 0.0 page faults a page. The 700,000 page faults a frame of the title run are not the guards' and not the refresh of memory already copied once: the first frame here, which touches every copy for the first time, has 800,000.
  • Copies through the kernel run at 14–24 GB/s, in user mode at 37–53 GB/s (GPU: copy title memory into host memory without a system call #1010 makes them in user mode).
  • The same volumes cost a sixth of the title's time here. So either each operation costs several times more in the title (the published handler time is 74.8 ms; here 14–18 ms for 3,638 faults), or the time is in work these counters do not count. The parts of the copies per frame line the comment did not quote would tell: guard faults, pages opened, pages written, page faults while preparing, protecting, moves.

These are wall times of a made-up pattern on an idle process. They say which change moves which part, not what frame rate the title gets.

Next to the other benchmarks

#1743 (world_frame_copies) and #2051 (world_frame_refreshes) replay one 174 MB heap through update, writing and copy_back, to compare copy and snapshot changes. This one is about what those leave out: thousands of copies asked for many times over, the guards, the page table's prepare, and the submission path around them. It goes through Host::execute and reports the diagnostics counters, so its output lines up with a tester's log.

Changes outside the new file

  • host.rs: the mod line.
  • shadow.rs: Shadow::mark_written (tests only), which sets a page's bit in the views' written-pages bitmap as a shader does.
  • copystat.rs: take() (tests only), the counters since they were last read.

Running it

$env:VICTORY_D3D12_WARP = 1
cargo test --profile diag -p victory-gpu --features diagnostics -- --ignored --nocapture --test-threads 1 world_frame_preparing

About 4 s after the build; it takes 1.6 GB of memory twice (title memory and host copies). Without diagnostics it runs on the default adapter and prints the times without the counters.

Tested

  • The benchmark itself, on WARP only (diagnostics build, VICTORY_D3D12_WARP=1): three runs on 940d32f, and once more at 35eac210 (merged with main 63bcca4) together with distant_refreshes_preparing.
  • cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1 at 35eac210 on WARP: 246 passed, 0 failed, 3 ignored.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, with and without --features diagnostics: clean.

Not run: the title; any hardware GPU (everything above is the software adapter); distant_refreshes_preparing on #2428, #1555 or #1818. The title was not used in these tests.

AI-assisted

🤖 Generated with Claude Code

…ark)

An ignored test that runs the submissions of a made-up world frame through
Host::execute on made-up title memory (write-watched pools, physical pages
shown through two views), at the per-frame volumes a title run published
on issue Marvisak#400, and prints the parts next to the published numbers and the
cost of each mechanism on its own. No title, no hardware GPU needed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib frame_bench — compiles cleanly and respects #[ignore]
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (184 files ok)

Clean opt-in world-frame preparation benchmark harness in host/frame_bench.rs. Looks good.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

GPU tests: world frame preparing at published volume — test-only PR for GPU paths; can't run on macOS, relies on Windows CI.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
…at the published volumes, head efb35b5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
…sak#2115 in; Marvisak#2150 left out for now

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

Copy link
Copy Markdown
Contributor

Confirmed working on Windows 11 x64 / AMD Radeon RX 7600 (driver 32.0.32029.2010, rustc 1.98.1), head efb35b560c51147c37ac30617b7928a56db40df1 merged onto main (940d32f69b):

  • cargo test -p victory-gpu --lib -- --test-threads=1: 143 passed, 0 failed.
  • cargo test --profile diag -p victory-gpu --features diagnostics --locked --lib -- --ignored --nocapture --test-threads=1 world_frame_preparing (with VICTORY_D3D12_WARP unset -> runs on AMD Radeon RX 7600 hardware with full counters; 2 independent runs, median of 5 scored frames):
    • preparing, ms: 244.1 / 227.2
    • copying back, ms: 181.9 / 173.3
    • change checks: 274,094.0 (checked, MB: 102,722.0, changed (copied), MB: 159.1)
    • unit_costs — declaring the heap from its start to its end as written (marked): 73.0 us (ending it 9.1 us); unchanged copy through refresh batch: 437 ns.

Clean, deterministic synthetic baseline for hardware comparisons.

AI-assisted; synthetic tests only, no game files, dumps, or captures used.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (with the earlier size caveat). The new head 35eac21 addresses the last review. Shadow::mark_written (test-only, crates/victory-gpu/src/shadow.rs) now calls bitmap(false), which matches main's fn bitmap(memory: bool). The figures in the description are refreshed for current main. The new distant_refreshes_preparing case in host/frame_bench.rs asks one batch for ranges far apart and a page apart in one copy, so it can tell main, #2428/#1555 and #1818 apart. Everything outside frame_bench.rs is #[cfg(test)] (copystat::take, mark_written), and both benches are #[ignore].

On your reply: the three points are done as agreed. The table for the three refresh PRs is expected, not measured, so someone should run the case on them before it is used to choose between them.

The earlier caveat still stands. It is about 750 lines of synthetic benchmark that needs about 3 GB when run, so whether to carry it in the tree is the maintainer's decision.

CI: check passing on this head.


Generated by Claude Code

@shortselow-byte

Copy link
Copy Markdown

Two limits I ran into while using world_frame_preparing to compare the copy-back PRs, at head efb35b5 on main 940d32f (Windows 11, Rust 1.98.1 MSVC, Ryzen 5 5600X, diag profile with diagnostics, WARP):

1. The frame never reaches the byte-merge loop of the copy-back. With temporary counters in Shadow::copy_back_or_not, the per-piece part from host != old on (the read_into, the merge loop, write_mapped) ran for 0 pieces over the whole benchmark, and with #2054 merged its merge_writeback was called 0 times. So PRs that change that loop (#2054, #1867 and others) cannot show a difference here either way. A case that makes the GPU change a few bytes of an unmarked declared range would cover it.

2. copying back moves by about half with code layout alone. Five builds of the same tree, each in its own target directory, three runs each, interleaved, nothing else running (median of 5 frames, ms):

build copying back
unchanged, build 1 143.8, 121.4, 122.1
unchanged, build 2 126.6, 121.8, 122.8
+ a never-called function (1 loop) 124.9, 121.4, 124.4
+ a never-called function (4 loops) 186.4, 176.9, 179.7
+ a never-called function (12 loops) 186.9, 184.6, 176.5

The function is reached only behind an AtomicBool that is never set, at the top of copy_back_or_not, so the code that runs is the same in all five. Identical sources give the same time, but adding dead code moves copying back from ~122 to ~180 ms. That is how this first showed up: #2054 looked ~45 % slower here although none of its code runs.

So a single build per side can show a ±50 % difference that has nothing to do with the change. Comparing PRs with this benchmark needs either a check that the changed code runs at all, or several builds per side (e.g. with a trivial unrelated change) before reading a difference.

… copy-back

Every range the benchmark declared was either marked (copied back by page)
or stayed out of title memory (root UAVs in lists that read memory with no
copy), so the byte merge of a declared range's copy-back never ran (the
Marvisak#2134 review). Now one list a submission declares a two-page copy unmarked
and the shaders' part changes 8 bytes of one of its pieces, without marking
it: 33 pieces merged and written back a frame, a made-up volume. In its
place that list makes one refresh fewer, so the refresh count stays as it
was. The output prints the pieces changed, merged and the bytes written
back, the bytes compared, and a unit cost of one such copy-back.

A note at the top of the file and a line in the output say how to compare
builds: code layout alone moved `copying back` by about half in the
review, so check with the counters that the changed code runs and compare
several builds per side.

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

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@shortselow-byte thank you. Both points held up when I read the code, and the head is now 934da01b, one commit on efb35b5 (only host/frame_bench.rs).

1. The merge loop. You're right that nothing reached it, and it happens even before the host != old test. Every declared range was either marked or kept out of title memory:

  • Marked ranges keep no snapshot, because Shadow::writing arms the pages and returns first (shadow.rs:288-291).
  • The root-UAV ranges are in lists that call defer_missed(|| true), so goes_back is false (host.rs:967-975). They go through keep_writes, which never copies back.

The fix: once per submission, list 7 refreshes one 128 KiB copy declared unmarked, and the shaders' part of list 11 changes 8 bytes of one of its pieces without a mark. That's 33 pieces a frame through read_into, the merge and write_mapped. The list makes one refresh fewer in its place, so the refresh count is unchanged. The output now prints the pieces changed and merged, the bytes written back, the bytes compared, and the unit cost of one such copy-back.

  • The volume is made up, not taken from the title.
  • Snapshots grow by about 4 MB a frame.
  • The extra random draws shift the sequence after list 7, so runs can't be paired by seed with efb35b5.

2. Layout noise. A note at the top of the file and a line in the output say what your table shows. On your setup (diag profile, WARP), adding never-called functions moved copying back from ~122 to ~180 ms, though not every such change does. So a comparison should first check with the counters that the changed code runs, then use several builds per side.

What ran here, WARP only: clippy clean, the victory-gpu lib tests 146 passed, and the benchmark passed with 33 pieces merged and 2.2 MB written back a frame. That benchmark run used the unoptimized test profile, so its times aren't comparable with your diag figures. I haven't made a diag run of the new head yet; I'll add it here when it's done. Synthetic only; no title data used.

AI-assisted

@xndbogdan

Copy link
Copy Markdown

I ran this on two machines to compare open copy PRs, and found three things.

1. It doesn't build on current main (842b0cb). Shadow::mark_written calls bitmap(), which now takes memory: bool (one bitmap for shaders that use title memory, one for the others). I used bitmap(false), since the benchmark imitates writes through views. That was the only change needed; everything else built and every run passed its checks.

2. main has moved a lot since your description. Same benchmark, diag with diagnostics, hardware adapter, median of 5 frames, three runs each:

Ryzen 7 9800X3D, RTX 5080 Xeon E5-2670 v3, RX 9070 XT
preparing 48.1–50.2 ms 159.3–163.6 ms
copying back 39.0–42.0 ms 143.3–147.3 ms
change checks 1,325 1,325
checked / copied 6,657.8 MB / 243.7 MB same

That's 1,325 change checks against the 274,094 in the description.

3. It can't compare the refresh-range PRs. #2428, #1555 and #1818 each stop a batch from refreshing one [min, max] span over distant ranges of a copy (main's Batch::add still does that). In this benchmark, all three check and copy exactly what main does: 6,657.8 MB checked and 243.7 MB copied, on both machines, in all runs. Their preparing times sit 0–6 ms from main's on the Ryzen and within main's range on the Xeon, which is layout noise as your note describes. So the frame never asks for two distant ranges of the same copy within one batch. A list that refreshes, say, two small ranges at opposite ends of one large copy would let these three be told apart.

In the same rounds, #2051 (copies on several threads) took preparing to 33.9–37.6 ms and 131.4–134.0 ms with identical counters. Details on #2051.

AI-assisted (Claude Code). Synthetic benchmark only, no game data.

@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@xndbogdan thank you. All three hold, and the third is the most useful: the benchmark's frame never asks one batch for two distant ranges of the same copy, so it can't tell the refresh-range PRs apart.

  1. The build: confirmed. main now has fn bitmap(memory: bool) in shadow.rs, while this branch still calls bitmap(). Since the benchmark imitates writes through views, bitmap(false) is the right choice, as you did.
  2. The description's numbers are from 940d32f, before the tracking changes main has had since. I'll mark them as such and put current-main numbers next to them.
  3. A case for GPU: a submission refreshes a copy's ranges disjoint, not their span #2428, GPU: coalesce nearby shadow-buffer refreshes without spanning huge heap gaps #1555 and GPU: preserve disjoint shadow refresh ranges #1818: I'll add one list that, in one batch, refreshes two small ranges at opposite ends of one large copy. A whole-span refresh then checks and copies the span between them, and a per-range refresh doesn't. The counters show which one ran.

I'll post the head here when it's updated: main merged in, the build fixed, the new case added, and the WARP run results. Checked here by reading the code at main 63bcca4; no title data used.

AI-assisted

@JoeY54

JoeY54 commented Nov 26, 2026

Copy link
Copy Markdown

Hardware verification of world_frame_preparing on RTX 5090 and the Ryzen 9 9950X3D iGPU, as claimed on #1633. This complements my earlier WARP run.

Setup. 934da01 merged onto main 63bcca4 (no conflicts). One build fix, as xndbogdan describes: bitmap(false) in Shadow::mark_written. Windows 11 build 26300, Rust 1.98.1, Ryzen 9 9950X3D.

To put the host device on a chosen adapter I used a local test-only patch: VICTORY_ADAPTER matches the adapter description.

cargo test --profile diag -p victory-gpu --features diagnostics --locked --lib -- --ignored --nocapture --test-threads=1 world_frame_preparing

Correctness. Every run passes its checks. The counters are identical on both adapters, in every run, and match xndbogdan's RTX 5080 / RX 9070 XT numbers:

  • 1,325 change checks
  • 6,657.8 MB checked / 243.7 MB copied
  • 22,499 refreshes
  • 33 declared pieces merged (2.2 MB)

Timings (median of 5 frames per run):

run RTX 5090 (32.0.16.2124) preparing / copying back, ms 9950X3D iGPU (32.0.21045.29003) preparing / copying back, ms
1 85.3 / 67.0 114.3 / 83.6
2 80.8 / 61.5 86.2 / 63.1
3 96.2 / 74.3 80.4 / 60.9
4 (adapter picked explicitly) 68.0 / 50.3 –

GPU time is about 1 ms a frame on both adapters, so the frame is almost entirely CPU work. That's why the two adapters overlap. The run-to-run spread (68–96 ms on the same build) is larger than the adapter difference, so these runs can't rank the GPUs. Possible causes: the 9950X3D's two CCDs and where the scheduler puts the thread, and the layout effect the bench's notes describe.

Compared with xndbogdan's Ryzen 7 9800X3D + RTX 5080 (48.1–50.2 / 39.0–42.0 ms on 842b0cb), this host is slower. The differences are a newer main and a different CPU. Since the GPU barely enters, the gap says more about the CPU and main than about the GPU.

Synthetic benchmark only, no game data. The merge and test patch are local, not pushed. AI-assisted (Claude Code).

r4tedx and others added 3 commits November 26, 2026 08:22
Two 64 KiB ranges 8 MiB apart only show whether a batch keeps one span:
every change that keeps ranges apart keeps these apart. Pages 0 and 2
are asked for as well, with page 1 written and not asked for, so the
bytes checked and copied also show whether ranges a page apart are
joined (copying page 1) or kept as asked.

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

r4tedx commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Updated the head to 35eac210, as the triage asked:

  • Builds on current main. bd2ddfde merges main 63bcca4 (no conflicts; nothing outside the branch's four files changes), and the test-only Shadow::mark_written now calls bitmap(false), since the bench imitates writes through views that do not use title memory.

  • New case distant_refreshes_preparing (07f6fd60, extended in 35eac210). One list refreshes three 64 KiB ranges of one 8 MiB write-watched copy in one batch: pages 0 and 2 (one page apart), and page 127 (8 MiB away). The title also wrote page 1, which nobody asks for. The list then declares the three ranges as written and changes one dword in each. The case asserts that the refreshes reached the copy and that the GPU's dwords reached title memory, and prints the counters.

    On main (WARP, diag profile):

    3 refreshes, 196608 bytes requested; 1 change checks, 8388608 bytes checked, 262144 bytes copied
    196608 bytes snapshotted, 196608 bytes compared for copy-back; 196608 bytes merged
    

    The batch keeps one span from page 0 to page 127, so it checks the whole 8 MiB copy and copies every written page in it, page 1 included.

    What the three PRs should print, going by their merge rules (expected, not measured: I did not run the case on any of them):

    change checks bytes checked bytes copied
    main (measured) 1 8,388,608 262,144
    GPU: a submission refreshes a copy's ranges disjoint, not their span #2428 (joins ranges within a page: a <= to + COALESCE) 2 262,144 262,144
    GPU: coalesce nearby shadow-buffer refreshes without spanning huge heap gaps #1555 (joins within COALESCE_GAP = one page: from <= cur_to + gap) 2 262,144 262,144
    GPU: preserve disjoint shadow refresh ranges #1818 (keeps the union; joins only touching ranges) 3 196,608 196,608

    So the case separates main, the two PRs that join ranges a page apart, and GPU: preserve disjoint shadow refresh ranges #1818. It does not separate GPU: a submission refreshes a copy's ranges disjoint, not their span #2428 from GPU: coalesce nearby shadow-buffer refreshes without spanning huge heap gaps #1555: at this gap they follow the same rule. None of the three changes the copy-back, so its line should read the same on all of them.

  • The frame on current main. world_frame_preparing at 35eac210 on WARP prints 22,499 refreshes asking for 21.0 GB, 1,325 change checks (not the 274,094 measured on 940d32f) over 6,657.8 MB, of which 243.7 MB changed and was copied, and 33 declared pieces merged (2.2 MB). The description is refreshed below.

Thanks @JoeY54 for the hardware run (comment). They ran world_frame_preparing at 934da01 merged onto 63bcca4 with bitmap(false), on an RTX 5090 and on the Ryzen 9 9950X3D's iGPU. Their counters were identical on both adapters and matched xndbogdan's: 1,325 checks, 6,657.8 MB checked / 243.7 MB copied, 22,499 refreshes, 33 merged pieces of 2.2 MB. Preparing took 68–96 ms on the 5090 and 80–114 ms on the iGPU. The run-to-run spread was larger than the gap between the adapters. My WARP run at 35eac210 gives the same counters.

The earlier caveat still stands. This is about 680 lines of synthetic constants and needs about 3 GB to run, so whether to carry it in the tree is your call.

Tested at 35eac210, all on the software adapter (VICTORY_D3D12_WARP=1):

  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings, with and without --features diagnostics: clean.
  • cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1: 246 passed, 0 failed, 3 ignored (the two benches and an existing release benchmark).
  • Both benches once, diag profile: both pass. Counters as above.

Not run: any hardware GPU, the title, and the new case on #2428, #1555 or #1818. Only synthetic data was used. No title data was used.

AI-assisted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants