Skip to content

GPU tests: what marking written title pages costs, per way of marking (benchmark for #2167, #2175, #2465, #2755) - #2804

Open
0xkn0wh3r3 wants to merge 4 commits into
Marvisak:mainfrom
0xkn0wh3r3:bench/write-marks
Open

0xkn0wh3r3 wants to merge 4 commits into
Marvisak:mainfrom
0xkn0wh3r3:bench/write-marks

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Five open PRs change how translated programs mark the title-memory pages they write:

This PR measures each approach on hardware, so they can be compared. It is tests only: nothing outside tests changes.

What it adds

crates/victory-gpu/src/marks_bench.rs has HLSL compute shaders that do what translated stores to title memory do:

  1. look the address up in the page table, which sits in an upload heap as in crate::memory;
  2. set the bit for the page written, with atomics, in a bitmap;
  3. store into the host copy.

There is one shader for each way of marking:

Variant What it does
main Two unconditional atomics per store (first and last byte's page); the table's null entry loaded per access.
test-first (#2167's approach) Load the word, issue the atomic only for a clear bit, skip the second mark for a store within one page; entry in one load, null entry once per program.
wave (#2755's approach) Lanes of a wave that mark the same bitmap word OR their bits in one atomic from the first lane, after a load finds a bit missing.
wave+test-first Both.
none No marks: the floor.

Each runs with the bitmap in system memory (the custom L0 write-back heap of Host::shared_buffer, as on main) and in video memory. Each runs over four ways of writing: all in one page, linear, a page per lane (32 pages per bitmap word), and scattered.

Times are GPU timestamps around one dispatch on a queue of the benchmark's own: 2,048 groups of 64 threads, 16 dword stores each. Each figure is the median of five runs, once with the bitmap cleared before each run ("first touch") and once with it already set.

Results (RTX 5070 Ti, driver 621.24), ms per dispatch, first touch / already set

one page linear page per lane scattered
main, system bitmap 79.8 / 76.5 75.8 / 75.0 1595 / 1583 336 / 337
test-first, system 1.6 / 0.33 11.5 / 0.35 21 / 20 13.0 / 6.7
wave, system 1.7 / 0.33 11.4 / 0.36 22 / 22 13.5 / 6.8
wave+test-first, system 1.7 / 0.32 12.6 / 0.35 21 / 20 12.8 / 6.7
main, video bitmap 0.31 / 0.31 0.32 / 0.32 20 / 20 6.4 / 6.5
test-first, video 0.30 / 0.30 0.32 / 0.32 20 / 21 6.8 / 6.7
none 0.30 / 0.29 0.32 / 0.32 20 / 19 6.5 / 6.5

What the results show:

A second benchmark times what a video-memory bitmap adds at a list's end: copying 256.5 KiB into read-back memory, then clearing it from zeros. That takes 12.2 µs per list (median of 20).

Recommendation: a video-memory bitmap (#2175 for page-table marks, #2465 for view marks) gives the full gain on its own. #2167's check-the-bit-first still helps wherever the bitmap stays in system memory, for example when the card has no room, but adds nothing on top of video memory.

Tests

  • every_variant_marks_the_pages_main_marks: every variant, with the bitmap in either place, sets exactly the bits main sets, over every pattern. Those bits are what copy-back copies.
  • The benchmarks are #[ignore]d:
cargo test -p victory-gpu --release --lib marks_bench -- --ignored --nocapture
  • The shaders are compiled in the test process by the Windows SDK's dxcompiler.dll (found under the Windows Kits bin folder) through IDxcCompiler3; no process is spawned. D3DCompile can't be used because the wave variant needs shader model 6. Without the SDK, or without a GPU, the tests do nothing.
  • Each case runs as four submissions of a quarter of the groups, with their times summed: the slowest case takes about 1.6 s in all, close to the host's 2 s device reset.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings is clean, with and without --features diagnostics.
  • cargo test -p victory-gpu --lib fails only dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views. These fail the same way on main on NVIDIA (the 1,000,000-descriptor cap, fixed by GPU: page view heaps a host caps below the slots shaders index #2121).

Limits

  • The shaders reproduce what each PR's emitted code does; they are not the translator's own output. The data store goes through one root UAV instead of a heap view, which is the same in every variant.
  • Measured on one NVIDIA GPU. AMD hosts may differ, especially for the wave variant.
  • Not run with the title.

A version of #2175's approach rebased on current main, with the bitmaps pooled, is on branch 0xkn0wh3r3:gpu/marks-in-video-memory (dd65e98) for anyone who wants to try it while #2175 conflicts.

A benchmark (ignored by default) and a check, in HLSL that does what
translated programs do when they store to title memory: look the address
up in the page table (an upload heap), set the bits of the pages written
in the list's bitmap with atomics, store into the host copy. Variants:
main's two unconditional atomics per store; a load first and an atomic
only for a clear bit (Marvisak#2167's approach); one atomic per wave for lanes
sharing a bitmap word (Marvisak#2755's); both; none. Each with the bitmap in
system memory, as now, and in video memory; four ways of writing.

RTX 5070 Ti, driver 621.24, ms per dispatch of 131,072 threads storing
16 dwords each (bitmap clear before the dispatch / already set):

                            one page      linear  page/lane  scattered
  main, system bitmap      79.8/76.5   75.8/75.0  1595/1583  336/337
  test-first, system         1.6/0.33   11.5/0.35    21/20    13.0/6.7
  wave, system               1.7/0.33   11.4/0.36    22/22    13.5/6.8
  main, video bitmap        0.31/0.31   0.32/0.32    20/20     6.4/6.5
  test-first, video         0.30/0.30   0.32/0.32    20/21     6.8/6.7
  no marks                  0.30/0.29   0.32/0.32    20/19     6.5/6.5

Atomics on a bitmap in system memory are what cost: up to 250 times the
dispatch without marks. Loading first removes them once a page is marked;
one atomic per wave adds nothing on this GPU. A bitmap in video memory
costs nothing even with main's unconditional atomics, first marks
included. What is left in "page per lane" and "scattered" is the stores
into the host copy in system memory.

`every_variant_marks_the_pages_main_marks` checks every variant, in both
places, sets exactly main's bits. `dxc.exe` comes from the Windows SDK;
without it or a GPU both tests do nothing.

    cargo test -p victory-gpu --release --lib marks_bench -- --ignored --nocapture
Two 256.5 KiB copies, the bitmap into read-back memory and zeros over
it, as the video-memory bitmaps of Marvisak#2175 and Marvisak#2465 record at a list's
end or after a submission: 12.2 µs on an RTX 5070 Ti (median of 20).

@kotekompotek kotekompotek 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.

Good benchmark design — five marking strategies x system/video bitmap placement x four write patterns, GPU timestamps on a private queue, and it answers exactly the question #2167/#2175/#2465 need for the wave-reduction work. The correctness gate is the important part and it's done right: every variant must set the identical bitmap as main for every pattern and placement (a wave-reduction that drops or double-counts a bit fails), plus the main marks nothing sanity check. #[ignore]d + dxc/GPU-gated. LGTM.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Reviewed and benchmarked ec830b56 on Windows 11 + NVIDIA GeForce RTX 5090 (Blackwell) (+ WARP) against main (13f91ca).

Review & correctness

  • Clean benchmark harness: dedicated queue + D3D12_QUERY_TYPE_TIMESTAMP around single dispatches (1 warmup + median of 5 / 20), identical page-table lookup and data.Store across none and all marking variants, Drop closes event handles (system_bitmap relies on D3D12 release-time unmap; an explicit Unmap in Drop would be a minor polish).
  • every_variant_marks_the_pages_main_marks passed on both RTX 5090 and WARP; cargo clippy --locked -p victory-gpu --all-targets (default & diagnostics): 0 warnings; cargo xtask policy: 185 files ok.

RTX 5090 --release results (marks_bench --ignored --nocapture)

  • bitmap_copy_out_bench (262,656 bytes): 6.5 µs median.
  • Dispatch time (2,048 groups × 64 threads × 16 stores, median ms, clear / set):
variant bitmap one page linear page per lane scattered
main system 70.129 / 69.926 71.398 / 68.767 1421.602 / 1411.691 296.981 / 298.548
main video 0.175 / 0.166 0.159 / 0.159 74.801 / 74.930 4.692 / 4.943
test-first system 1.520 / 0.235 16.534 / 0.232 76.975 / 77.243 11.575 / 5.003
test-first video 0.166 / 0.169 0.159 / 0.160 75.115 / 75.307 4.684 / 4.699
wave system 1.506 / 0.234 16.491 / 0.231 76.726 / 76.175 11.177 / 5.003
wave video 0.166 / 0.175 0.159 / 0.159 75.846 / 75.360 4.948 / 6.206
wave+test-first system 1.263 / 0.240 16.284 / 0.232 77.303 / 78.210 11.477 / 4.891
wave+test-first video 0.171 / 0.166 0.159 / 0.159 76.147 / 76.490 4.787 / 4.696
none system 0.169 / 0.172 0.159 / 0.160 75.937 / 75.488 4.628 / 5.066

Even on RTX 5090, putting the bitmap in video memory matches the none floor even with main's unconditional atomics (401×–449× on one page/linear, 19× on page per lane, 60×–63× on scattered) for 6.5 µs of copy-out/clear overhead.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This adds a test-only, #[ignore]d benchmark module, crates/victory-gpu/src/marks_bench.rs, that compares ways of marking written title pages (the approaches in #2167, #2175, #2465 and #2755). The measurements in the description and the thread are useful for choosing between those PRs whatever happens to the module.

Update for 02912f9: thanks, the benchmark no longer spawns dxc.exe. It now finds the newest Windows SDK under ProgramFiles(x86)\Windows Kits\10\bin, loads dxil.dll and dxcompiler.dll from there with LoadLibraryW and compiles through DxcCreateInstance/IDxcCompiler3, and crates/victory-gpu/Cargo.toml gains a windows dev-dependency entry with the Win32_Graphics_Direct3D_Dxc feature. Loading an external compiler DLL into the test process and the Cargo.toml change are still things this triage leaves to the maintainer, so this stays needs work: needs the maintainer's decision, not a code defect. Checked-in DXIL would be generated code in the repo, so I would not switch to that without the maintainer either. CI (check) passes.


Generated by Claude Code

Review: the benchmark spawned the SDK's dxc.exe. It now loads the SDK's
dxcompiler.dll and compiles through IDxcCompiler3 in the test process
(D3DCompile has no shader model 6, which the wave variant needs), signed
by the SDK's dxil.dll where there is one. Without the SDK the tests still
do nothing.

The benchmark also times each case as four submissions of a quarter of
the groups, summed: main's slowest case takes about 1.6 s for all of
them, near the host's 2 s device reset, and a busy GPU pushed it over.
@0xkn0wh3r3

0xkn0wh3r3 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Understood. On compiling in-process: the shaders target cs_6_6, and the wave variants use WaveActiveBitOr, WaveActiveAllEqual and WaveIsFirstLane, which need SM 6.0 or later. D3DCompile stops at SM 5.1, so they can't be built with it. If running the SDK's dxc.exe from a test isn't acceptable, the alternative is to check in the compiled DXIL for the handful of benchmark shaders. That's small, but it's generated code in the repo, so it's your call which you prefer. The measurements in the description stand for choosing between #2167, #2175, #2465 and #2755 whatever happens to the module.

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

Update to my reply above: at 02912f9 the benchmark no longer spawns anything. It compiles its SM 6.6 shaders in-process through the SDK's dxcompiler.dll (IDxcCompiler3), so the process question no longer applies. The Cargo.toml change only adds a feature to an existing dependency. #2806, which shares the harness, does the same at 5dfeaf6.

@Anzymanz

Copy link
Copy Markdown

From a tester working with Claude (AI-assisted, Claude Code): the same comparison in the title on an AMD card under Linux, for the two kernels that cost the most GPU time in our world runs.

Setup: RX 9070 XT (RDNA4), RADV / Mesa 26.3.1 through vkd3d-proton (GE-Proton 11-14), resizable BAR on. Diagnostics builds of one base (13f91ca + #1997 + #454 + #2644), each arm = base + one change, warm shader cache, opening cutscene, 30 s in the world, VICTORY_GPU_TIMING=1 (per-command timestamps), one run per arm.

The two kernels are XboxBvhBuilder.dll compute programs that read and write title memory (memory and memory_writes set): caa78b8ca62bc3d6 (~90-150 dispatches a frame) and 28918b7150a7aad5 (~40-70). In the base they are 108 of 249 ms of timed commands per frame. Their DXIL has 156 and 74 atomicBinOps, of which 108 and 74 are ORs into the page bitmap.

GPU ms per dispatch (stable across arms, unlike per-frame totals, which follow the scene):

arm caa78b8ca62bc3d6 28918b7150a7aad5
base 0.37 0.77
+ #2703 (control: unrelated to marks) 0.35 0.81
+ #2175 (bitmaps in video memory) 0.42 0.83
+ #2484 + #2755 (wave-merged marks) 0.36 0.57

So on this card, for these two kernels, moving the bitmap to video memory changes nothing, and merging a wave's marks takes about a quarter off one of them. That doesn't match the 5070 Ti numbers above, where the system-memory bitmap is the whole cost. My guess, not measured yet: here the cost is their stores and atomics into the host copies of title buffers, which are in system memory too. I'm running #2870's chain next (same binary, VICTORY_GPU_UPLOAD=0 against the default) and will post it.

No game data: hashes, counts and timings only.

@liandraraiane

Copy link
Copy Markdown

NVIDIA numbers for this bench: RTX 3060 12 GB, driver 610.88, Windows 11 26200, dxc 10.0.26100.0, on ec830b5 (before the in-process compile commit). Median of 7 runs (each the bench's own median of 5), ms per dispatch, clear bitmap:

variant bitmap one page linear page per lane scattered
main system 2942.7 2945.0 2119.2 401.9
main video 2.34 2.33 10.6 5.9
test-first system 20.9 270.5 29.4 8.8
wave system 0.87 15.7 11.0 8.5
wave+test-first system 0.88 16.4 11.2 8.8
none — 0.27 0.64 11.1 5.6

On this GPU, system-memory atomics on the bitmap cost about 1000x the video-memory ones (main: ~3 s per dispatch). wave stays within ~3x of the floor with the bitmap clear and at the floor once it is set. With the bitmap in video memory every variant is at the floor. bitmap_copy_out_bench: 45.2 µs (45.1–45.6). every_variant_marks_the_pages_main_marks passes.

AI use: Claude Code ran the benchmarks on this machine and drafted this comment.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
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.

6 participants