Repository navigation
indirect: clamp a window's records in lane order, not scheduler order - #864
xiaotu030202 wants to merge 1 commit into
Conversation
The argument clamp charges each list's budget as it clamps a window's
records, and `victory-skips` the draws whose records did not fit. It charged
a group's whole chunk of 64 records from the group's first thread and then
marked each record's fit from that one running total, which is right only if
the groups run in order. D3D12 defines no order between the groups of one
dispatch, so they do not: with 128 records the first chunk's charges and the
second chunk's raced for the one budget word, and WARP kept the second
chunk's first two records and emptied the whole of the first chunk's.
Concretely, `warp_budget_saturates_without_wraparound_and_preserves_draw_fields`
sets two records that each charge half the budget and asserts that they are
the two that fit. On WARP it kept records 64 and 65 instead, so the
assertion failed with `left: [4194304, 16, ...]` at `i = 64`:
panicked at crates/victory-gpu/src/indirect.rs:1539:
the first two real draws fit the budget
It is not only a test: which records a window keeps decided by the
scheduler means the same list clamps differently between runs, machines
and drivers, so a scene that fits on one run can lose draws on the next.
Each record now charges the budget on its own, and the caller dispatches one
group per 64 records with a UAV barrier between them, so the chunks charge
in lane order too. A group's records were already charged in lane order
within it; the barrier is what extends that across the chunks.
The `base` root constant says which 64 a dispatch clamps. It is the seventh
32-bit constant, so the root signature gains one.
An earlier attempt looped the chunks inside one group, which HLSL 5.1
refuses around a group barrier when the bound comes from a UAV or a
constant buffer (`X3663`), and a constant bound of 4096 still failed. The
dispatch loop is what the compiler accepts.
Measured on Windows 11, RTX 5070 Ti, Rust 1.98.1 (pinned), single-threaded:
victory-gpu 158 passed, 1 FAILED -> 159 passed, 0 failed
workspace ... -> (see the run in the pull request)
No game files were involved: every test here builds its own buffers and
shaders.
Signed-off-by: xiaotu030202 <xiaotu030202@users.noreply.github.com>
|
The dispatch barriers order the 64-record chunks. Inside each chunk, Could this keep f85101b’s AI-assisted source review. This comment is based on the shader code and the ordering rules. |
|
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head AI-assisted (Claude Code); no game data. |
… in record order The clamp charged each group's chunk of 64 records from the group's first thread, in lane order within the group, but the groups of one dispatch run in no defined order: with 128 records the second chunk could take the budget before the first (warp_budget_saturates_without_wraparound_and_preserves_draw_fields failed 30 of 50 runs on WARP, alone). Keep the single-thread walk of a chunk's costs (lane order by construction, one atomic per chunk) and dispatch one group per 64 records with a UAV barrier between them, `base` saying which 64. This is the dispatch loop of fxceless#864 (xiaotu030202) without its per-record compare and swap, which lets the two 32-lane waves of a group race: on an RTX 4060 Ti that pull request kept records 32 and 33 in 50 of 50 runs. Measured on an RTX 4060 Ti and WARP: the test passes 50 of 50 on both. One clamp costs about 1.4 us more per 64 records (4096 records: 282 us against 66 without a count buffer, 94 against 5 with a count of 3). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> (cherry picked from commit ab8a96b)
Kept both sides in all 4 conflicting files: - indirect.rs: HEAD's fxceless#864 base+gi indexing and 7-constant 64-record chunk loop (extended to record_gather_as) combined with main's INDIRECT_GATHER table lookup - shadow.rs: kept both merge_tests (join_runs and changed_chunks) - watch.rs: kept fxceless#812 (views/unclean/parked) alongside main's clean(), protect_here diagnostics, and view_known() remapped handling - README.md: kept our RTX 3060 README; updated README-upstream.md from d510ee4 Co-Authored-By: Antigravity <noreply@google.com>
What this fixes
The argument clamp charges each list's budget as it clamps a window's records, and the draws whose records did not fit run empty. It charged a group's whole chunk of 64 records from the group's first thread and then marked each record's fit from that one running total — which is only right if the groups run in order. D3D12 defines no order between the groups of one dispatch, so they do not.
With 128 records, the first chunk's charges and the second chunk's raced for the one budget word. On WARP the second chunk won, and the test that asserts the lane order caught it:
Expected
i = 1, 2; goti = 64, 65. Thespentcounter was still correct (134217728 = 2^27 = BUDGET_CAP), so the budget arithmetic is fine — only which records got it was unordered.This is not only a test failure. A window that keeps a scheduler-dependent set of records means the same list clamps differently between runs, machines and drivers: a scene that fits on one run can lose draws on the next. Frames that lost the device (#59, #833) are exactly the kind of thing this class of nondeterminism produces.
Measured here (Windows 11, RTX 5070 Ti, Rust 1.98.1 pinned,
--test-threads=1):victory-gpu--workspacegit-on-PATH environment issue inxtaskThe same test passes on
Zettrox/ztrx, which never had the per-chunk optimisation — that fork charges per record, which is what this returns to.What changed
crates/victory-gpu/src/indirect.rs, one file:ztrxuses; thecosts[]/fits[]shared arrays are gone.base(a seventh 32-bit root constant) says which 64 a dispatch clamps; the root signature grows by one.largest_asked,all_asked) reset per group, which is what they were already doing implicitly.Why not loop the chunks inside one group
I tried that first, twice, and HLSL 5.1 refused both:
The bound came from a UAV read (
eff_count), then from a constant buffer (records), then from a compile-time constant4096with a uniformbreak— all three rejected, because FXC will not put a group barrier in a loop it cannot prove uniform. The dispatch loop is what the compiler accepts, and it is also a stronger guarantee: group order within a dispatch is simply not something HLSL can order.Cost: a 4,096-record window goes from 64 dispatches to 64 dispatches with a barrier between them, each a 64-thread group. The clamp is a pre-draw reflection pass on argument buffers, not the hot path, and the previous shape was wrong; I have not measured the frame-rate effect because I cannot run the title (no game files). If it shows up,
VICTORY_INDIRECT_*switches aroundbound/bound_aheadare where to turn it down.Testing
xtask'srepository_passes_policyfails in my environment becausegitis not on the PATH that run used; re-run with it on PATH it is 4 passed. Not related to this change.No game files were involved: every test here builds its own buffers and shaders.
What I could not check
Whether the clamp now picks the same records a real RDNA2 card does. The lane order is what the budget is defined by, and this restores it, but I have no AMD card and no game files — so the evidence here is the WARP test, the ztrx cross-check, and the reasoning that a single group per dispatch cannot be out of order with itself.