Repository navigation
GPU: the compare of card copies hashes each 64 KiB piece with a group of threads (a pass 0.2-0.8 ms -> 0.002-0.11 ms on an RTX 5090) - #992
Conversation
…s-only count `cargo clippy --workspace --all-targets -- -D warnings` (CI) fails on 9376fd6 with this toolchain: unnecessary_sort_by in draw.rs, the bench's depth_written in indirect.rs never read, and placed_filler_twins unused without the diagnostics feature. No code changes.
…eads The hash and compare passes over copies in the card's memory (the pieces sent up before each submission, the declared ranges after it) gave each 64 KiB piece one thread, which walked its 4,096 16-byte steps one after the other: a pass took the time of one such walk whatever its pieces. On the RTX 5090 (a bench of the shader as it was against this form): a pass over 2 pieces 0.219 ms -> 0.002 ms, a compare of 92 pieces 0.564 -> 0.003, 580 hash passes in one list 0.44 -> 0.02, a whole 174 MB copy 0.79 -> 0.11, 16 compares 0.79 -> 0.02. The gameplay runs some 270-350 hash passes and ~100 compares a frame around its ~34 submissions, behind barriers (1,240-1,380 a frame in timing runs), and the timing run's command times never included them. Now a group of 256 threads takes a piece: each thread hashes the steps 4 KiB apart from its own (17 rounds: a piece widened to 16 bytes at both ends spans 4,097 steps), and the group folds the 256 hashes in a fixed order. A pass dispatches a group a piece. Both forms flag a piece whose widened bytes changed: tested on WARP for both (also a copy that starts 40 bytes into its first piece, whose widened last step flags both pieces), with the host device on the software adapter for 48 rounds of random changes, some at pieces' edges, both forms against the bytes themselves, and on the card in the bench (one changed byte flags its piece alone). VICTORY_CARD_WIDE_HASH=0 keeps the old form.
Flyander
left a comment
There was a problem hiding this comment.
I compared the exact CARD_COMPARE shader from c2d576c against main (085ee7c) and the parallel variants in #1014 (5557224), #997 (8f8b117), and #253 (3b0521a), all in one D3D12 executable. This reproduces the small-pass advantage of the 256-thread shader on a second Blackwell GPU (RTX 5070 Ti, driver 621.40, Windows 11 build 26300).
GPU time in µs per dispatch, mode 0 (store hashes). Each cell is the median of three run medians, with 30 timed dispatches per variant per run after four warmups. Execution order rotates between variants.
| 64 KiB pieces | Main | #1014 | This PR | #997 | #253 |
|---|---|---|---|---|---|
| 1 | 211.65 | 10.00 | 2.02 | 9.84 | 9.50 |
| 4 | 238.94 | 10.24 | 2.11 | 9.98 | 9.70 |
| 16 | 361.39 | 10.43 | 2.24 | 10.11 | 9.81 |
| 64 | 554.62 | 10.66 | 3.01 | 10.37 | 10.08 |
| 256 | 558.77 | 11.33 | 6.75 | 10.78 | 10.34 |
| 1,024 | 763.46 | 81.38 | 71.09 | 67.79 | 68.21 |
Mode 2 (compare and store) showed the same pattern. At 16 pieces, main took 361.57 µs, #1014 took 10.53 µs, and this PR took 2.34 µs. At 1,024 pieces, the run ranges for the faster variants overlap.
Method: compiled all five shaders with D3DCompile (cs_5_1), used the same GPU-local 64 MiB synthetic input and scratch buffers, and timestamped immediately before and after each dispatch on a direct queue. This measures the dispatch itself. In-game frame time, readback, and copy-back were outside the experiment.
Flyander
left a comment
There was a problem hiding this comment.
I followed up on the dispatch microbenchmark with two full D3D12 title launches on the RTX 5070 Ti (driver 621.40, Windows 11 build 26300, Ryzen 7 5800X3D). Base 085ee7c + this PR's shader commit c2d576c, one diagnostics binary, Series X, same seed save and copied 179,981,420-byte host pipeline library for each run. Only VICTORY_CARD_WIDE_HASH was changed. Both modes and the loaded library size were confirmed in the logs.
Frame-log batches fully inside 270–332 s with at least 500 mean draws. GPU times are from card timestamps, per frame.
| Metric | Serial (=0) |
Wide (=1) |
|---|---|---|
| Frames | 105 | 140 |
| Mean draws/frame | 5,314 | 5,311 |
| Send-and-hash lists | 22.69 ms (5.80 lists) | 9.64 ms (5.69 lists) |
| Compare lists | 6.38 ms (6.91 lists) | 1.16 ms (7.04 lists) |
| Other GPU lists | 129.40 ms | 122.36 ms |
| Frame median / p95 | 325 / 1,757 ms | 299 / 1,205 ms |
| Mean FPS | 1.96 | 2.40 |
The two kinds of lists went from 29.07 to 10.80 ms/frame (−63%) at similar list counts. The in-game comparison is one run per setting. Scene progression, remaining pipeline wait (55.93 vs 65.77 ms/frame) and submission work (223.32 vs 169.58 ms/frame) varied, so I would treat the card-list reduction as the confirmed result and the FPS numbers as observations from this pair.
Common switches: LEVELS_ON_DEMAND=1 ASYNC_SUBMIT=1 QUEUE2=1 INDIRECT_WINDOW=1 TEXTURE_NO_WAIT=1 MERGE_GAP=64 MERGE_RUNS=4096 STAGING_POOL=0 COPY_PLAIN=1 JOIN_PARTS=1 BACK_OWN_VIEW=1 INDIRECT_GATHER=1 CARD_REHASH_RUNS=1 FRAME_LOG=1 CARD_METER=1 (all prefixed VICTORY_). Both runs reached their timed deadline.
…apture, changed-bytes refresh, small buffers on the card and the hashed length; no conflict No conflict. Both sides changed the two hash and compare passes of host.rs, two lines apart: upstream gives the pass the bytes its hashes cover (Shadow::card_hashed: the copy's whole buffer, or with VICTORY_CARD_HASH_LEN=1 the title buffer's own bytes), this branch dispatches a group a piece (card_groups). Both forms of the compare read that length the same way: a piece ends at it, widened to 16 bytes. The rest is additions side by side.
…rt, an if joined to its let, counts tested with is_multiple_of) `cargo clippy --workspace --all-targets --locked -- -D warnings` fails on 085ee7c with the pinned toolchain (1.98.1), after the two fixes before this one too: map_entry in fpsbox.rs, collapsible_if in pipeline/library.rs, manual_is_multiple_of in queue.rs and shadow.rs, and with --all-features in draw.rs and watch.rs (twice). No change of behaviour.
|
Merged Where both sides changed the same code.
Added after the merge: one lint commit for Checked, the branch as it is (
|
|
@Flyander thanks, this is the measurement the description did not have: the pass on a second Blackwell GPU against For the record of this PR:
As you say, the card-list times are the confirmed part and the frame rate of one pair of runs is an observation. |
Based on
0b0074e0. Three commits:Two clippy fixes for
main, without whichcargo clippy --workspace --all-targets -- -D warningsfails on0b0074e0, with or without--all-features:unnecessary_sort_byindraw.rs, the bench'sdepth_writtennever read,placed_filler_twinsunused without diagnostics;manual_is_multiple_ofinshadow.rs, which came withmain's later sessions.Our other open PRs carry the same two changes, so they merge in any order.
The change, in
host.rs(CARD_COMPARE) and the tests inindirect.rs.What was wrong
The hash and compare passes over host copies in the card's memory (
CARD_COMPARE: the pieces sent up before each submission, and the declared ranges after it) gave each 64 KiB piece one thread. That thread walked the piece's 4,096 steps of 16 bytes one after the other, so a pass took as long as one such walk, however few pieces it had.The gameplay runs some 270-350 hash passes and about 100 compares a frame, around its ~34 submissions, each behind barriers (1,240-1,380 barriers a frame in timing runs). The timing run's command times never included these passes, so this card time did not show anywhere.
What changes
A group of 256 threads takes a piece:
Both forms flag a piece whose widened bytes changed.
VICTORY_CARD_WIDE_HASH=0keeps the one-thread form; every pass of a run uses the same form.Measured
RTX 5090, a bench of the shader as it was against this form:
In the bench on the card, one changed byte flagged its own piece only. The frame time was not measured with this change alone.
Switches
VICTORY_CARD_WIDE_HASH=0: one thread a piece, as before.Tested
The branch was checked as it is, on
0b0074e0, on the software adapter (the card was taken by other work):cargo test -p victory-gpu --features diagnostics -- --test-threads=1withVICTORY_D3D12_WARP=1: 185 passed, 3 failed, 6 ignored. None of the three is near this change:depth_bounds_pipeline_loads_and_filters_draws: WARP does not reject the pixels outside the depth bounds;warp_budget_saturates_without_wraparound_and_preserves_draw_fields:main's test that Indirect test: the two groups charge the budget in either order (the test failed 5 runs in 6) #849 and Warp budget test: accept either group charging first (rebased on main, +12/−1) #970 fix, in which the two groups may charge the budget in either order. Run alone three times, it failed twice;profile::tests::the_sampler_finds_threads_and_writes_its_files: run alone three times, it passed each time.Every card-compare test passed, among them the two that run both forms.
cargo clippy --workspace --all-targets --locked -- -D warnings, and the same with--all-features: clean.cargo build --release -p victory,cargo build --profile diag -p victory --features diagnosticsandcargo xtask policypass.New and changed tests:
Overlaps with open pull requests
This PR changes only the hash and compare pass: 256 threads a piece, the old form kept behind a switch, and no change to what is fetched or how.
Not tested