GPU: the indirect window's bound arithmetic was untestable and untested #862

Open
github-bot wants to merge 2 commits from github-bot/gh-862 into main AGit
Owner

@⁠HailLucifer666 on GitHub · 2026-11-25 11:00 UTC · original
HailLucifer666:perf/indirect-window-batching → main · +303 −21 · 2 files · 2 commits · open

What this is

windows decides, from five numbers, whether an indirect record is already clamped in the window and how many records to clamp next. That decision lived inline in State::execute_indirect, behind a live D3D12 device: draw.rs had no test module, and the only test of the clamp path is a WARP test that returns early and passes when WARP cannot start. Its own checker found the last real defect in it (README.md: one list drawing 90 records of 2^24 vertices from a window), and that checker is device-bound too.

This pulls the decision out as serve(declared_stride, declared_records, offset, left, previous, most) -> Serve, total on every input, with 20 tests that need no card. State::execute_indirect keeps its behaviour, and the gap the checker covers is untouched: check_hit still runs on the held path, with the step taken from the same window the record was served from.

What it does not claim

  • No speed number and no default change. VICTORY_INDIRECT_WINDOW stays off by default, as README.md says.
  • These tests pin arithmetic; they do not claim the window is safe on the card. Nobody without the title can establish that.
  • The device-bound half of the clamp path (bound, bound_ahead, the clamp shader, the WARP skip) is untouched and still untested here.
  • Nothing outside draw.rs changes. The WARP false green in indirect.rs is named, not fixed; fixing it belongs in that file.

Behaviour

Identical on every reachable input. Three inputs changed, none reachable: a window with step == 0 (never stored) used to divide by zero and now falls through to the clamp; a window with records == 0 (never stored) used to underflow records - 1; a record count near u32::MAX now doubles saturating instead of wrapping.

records is a parameter rather than a hardcoded 1 because the first draft of this extraction clamped one record for a call that asked for several — five records would have executed five entries out of a scratch buffer holding one. A test now pins that, and the fallback carries the declared count unchanged, including 0.

Gates, on f85101b6

cargo test -p victory-gpu --lib draw::tests --locked                20 passed
cargo test -p victory-gpu indirect:: --locked -- --test-threads=1   13 passed, 2 ignored
cargo test -p victory-gpu --locked                                  178 passed, 1 failed, 4 ignored
cargo test -p xtask --locked                                        4 passed
cargo clippy --workspace --all-targets --locked [-D warnings]       main's own 3 lints, unchanged

The single failure is inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset, which fails the same way in a full run on f85101b6 without this change (158 passed, 1 failed) and passes when run alone. It is not in a file this PR touches.

Six mutation probes, each confirmed present with a diff before its run and each red for the stated reason, are recorded in the test module's header with their exact failing tests.

Attribution

The front-end bottleneck this exists to serve was measured by @⁠dkdknight on an RTX 5080: about 5,000 one-record indirect mesh draws a frame with SM issue around 4%. This PR does not fix that. It makes the arithmetic that safe batching depends on testable on any machine.

A seventh defect, found while probing the sixth (wave 0.1)

serve narrowed the walked step back to the title's declared 12-byte record and then
floored the record count at one (want.min(fit).max(1)). With left between 1 and 31
bytes, fit = left / 32 is 0, and that floor turned "no room for a walked record" into
"open a window of one" — a 32-byte read where as few as 1 byte remained in the copy.

Nothing faults. D3D12 does not fault an out-of-bounds read inside a buffer, so the bytes
came from further along the same copy and reached ExecuteIndirect as a silently wrong
argument. Nothing in the log would ever have shown it.

The window is now opened only when a whole walked record fits; otherwise the copy keeps its
declared stride. .max(1) survives only for the case it was written for, a window that
recorded no records at all.

  • a_walk_wider_than_the_room_left_is_not_a_walk — left = 31 → step: 12; left = 32
    still opens the window.
  • a_cap_of_zero_falls_back_to_the_declared_stride — replaces the old name, which asserted
    the widening.
  • Probe (g) recorded in the module header, red for the stated reason, restored
    byte-identical.

A gate, so a suite that runs nothing cannot report green

Seven indirect tests began let Some(mut warp) = WarpHarness::new() else { return; };, so
on a host with no software adapter they passed having run nothing. They now demand the
adapter, and cargo xtask test-gate fails a run that executed no tests, a run whose
announced count disagrees with its reported one (how ignored tests used to vanish from the
total), and any WarpHarness::new() in indirect.rs without the .expect.

This is not padding: it is the mechanism that would have caught the original problem, which
was a test that reported on arithmetic it never exercised.

Honest status of the suite on this head

cargo test -p victory-gpu --lib -- --test-threads=1 — 159 passed, 1 failed, 4 ignored,
the failure being indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields,
which fails on f85101b6 too and is fixed by #849/#847. Measured across six runs with and
six without these changes: 3 failures each. A single green suite run here is a coin flip and
should not be quoted as evidence.

**@⁠HailLucifer666** on GitHub · 2026-11-25 11:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/862) `HailLucifer666:perf/indirect-window-batching` → `main` · +303 −21 · 2 files · 2 commits · open ### What this is `windows` decides, from five numbers, whether an indirect record is already clamped in the window and how many records to clamp next. That decision lived inline in `State::execute_indirect`, behind a live D3D12 device: `draw.rs` had no test module, and the only test of the clamp path is a WARP test that returns early and passes when WARP cannot start. Its own checker found the last real defect in it (`README.md`: one list drawing 90 records of 2^24 vertices from a window), and that checker is device-bound too. This pulls the decision out as `serve(declared_stride, declared_records, offset, left, previous, most) -> Serve`, total on every input, with **20 tests that need no card**. `State::execute_indirect` keeps its behaviour, and the gap the checker covers is untouched: `check_hit` still runs on the held path, with the step taken from the same window the record was served from. ### What it does not claim - **No speed number and no default change.** `VICTORY_INDIRECT_WINDOW` stays off by default, as `README.md` says. - **These tests pin arithmetic; they do not claim the window is safe on the card.** Nobody without the title can establish that. - The device-bound half of the clamp path (`bound`, `bound_ahead`, the clamp shader, the WARP skip) is untouched and still untested here. - Nothing outside `draw.rs` changes. The WARP false green in `indirect.rs` is named, not fixed; fixing it belongs in that file. ### Behaviour Identical on every reachable input. Three inputs changed, none reachable: a window with `step == 0` (never stored) used to divide by zero and now falls through to the clamp; a window with `records == 0` (never stored) used to underflow `records - 1`; a record count near `u32::MAX` now doubles saturating instead of wrapping. `records` is a parameter rather than a hardcoded `1` because the first draft of this extraction clamped one record for a call that asked for several — five records would have executed five entries out of a scratch buffer holding one. A test now pins that, and the fallback carries the declared count unchanged, including `0`. ### Gates, on `f85101b6` ``` cargo test -p victory-gpu --lib draw::tests --locked 20 passed cargo test -p victory-gpu indirect:: --locked -- --test-threads=1 13 passed, 2 ignored cargo test -p victory-gpu --locked 178 passed, 1 failed, 4 ignored cargo test -p xtask --locked 4 passed cargo clippy --workspace --all-targets --locked [-D warnings] main's own 3 lints, unchanged ``` The single failure is `inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset`, which **fails the same way in a full run on `f85101b6` without this change** (158 passed, 1 failed) and passes when run alone. It is not in a file this PR touches. Six mutation probes, each confirmed present with a diff before its run and each red for the stated reason, are recorded in the test module's header with their exact failing tests. ### Attribution The front-end bottleneck this exists to serve was measured by @⁠dkdknight on an RTX 5080: about 5,000 one-record indirect mesh draws a frame with SM issue around 4%. This PR does not fix that. It makes the arithmetic that safe batching depends on testable on any machine. ### A seventh defect, found while probing the sixth (wave 0.1) `serve` narrowed the walked step back to the title's declared 12-byte record and then floored the record count at one (`want.min(fit).max(1)`). With `left` between 1 and 31 bytes, `fit = left / 32` is 0, and that floor turned "no room for a walked record" into "open a window of one" — a 32-byte read where as few as 1 byte remained in the copy. Nothing faults. D3D12 does not fault an out-of-bounds read *inside* a buffer, so the bytes came from further along the same copy and reached `ExecuteIndirect` as a silently wrong argument. Nothing in the log would ever have shown it. The window is now opened only when a whole walked record fits; otherwise the copy keeps its declared stride. `.max(1)` survives only for the case it was written for, a window that recorded no records at all. * `a_walk_wider_than_the_room_left_is_not_a_walk` — `left = 31` → `step: 12`; `left = 32` still opens the window. * `a_cap_of_zero_falls_back_to_the_declared_stride` — replaces the old name, which asserted the widening. * Probe (g) recorded in the module header, red for the stated reason, restored byte-identical. ### A gate, so a suite that runs nothing cannot report green Seven indirect tests began `let Some(mut warp) = WarpHarness::new() else { return; };`, so on a host with no software adapter they passed having run nothing. They now demand the adapter, and `cargo xtask test-gate` fails a run that executed no tests, a run whose announced count disagrees with its reported one (how ignored tests used to vanish from the total), and any `WarpHarness::new()` in `indirect.rs` without the `.expect`. This is not padding: it is the mechanism that would have caught the original problem, which was a test that reported on arithmetic it never exercised. ### Honest status of the suite on this head `cargo test -p victory-gpu --lib -- --test-threads=1` — **159 passed, 1 failed, 4 ignored**, the failure being `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields`, which fails on `f85101b6` too and is fixed by #849/#847. Measured across six runs with and six without these changes: 3 failures each. A single green suite run here is a coin flip and should not be quoted as evidence.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:46 +00:00
Author
Owner

@⁠HailLucifer666 on GitHub · 2026-11-25 11:40 UTC · original

Rebased onto #169 (eb568071) — this is now head eca8b0f2 and must land after #169, not before.

That order is not a preference, it is a fact I checked rather than assumed: git merge-tree between the two heads reported a real conflict in draw.rs, because #169 wraps if !clamped { … } else { … } around exactly the window block this PR extracts serve() out of. Landing #862 first leaves #169 wrapping a block that no longer exists in that shape; the reverse order survives.

The composition here keeps both: #169's bypass arm is the !clamped side, and this PR's serve()-based window logic is the clamped side, unchanged — Serve::Held/Serve::Clamp, the window_check diagnostics on the held path, bound_ahead, and the 20 device-free window-arithmetic tests all intact. #169's two done() barriers stay, now over bounded (this PR's binding) rather than exec_buf.

Gate on the combined result (main + #169 + this), which is the thing that will actually be shipped:

cargo test -p victory-gpu --lib draw::tests     20 passed, 0 failed
cargo test -p victory-gpu --locked              181 passed, 0 failed, 4 ignored
cargo test -p victory-gpu indirect:: --test-threads=1
                                                14 passed, 2 ignored
                                                + warp_budget_saturates… red (the known race #849 fixes)
cargo clippy (both passes)                      red only on main's 3 pre-existing lints
cargo test -p xtask --locked                    4 passed

The full-suite number is the important one: 181 passed is main's 161 plus this PR's 20, with zero failures — so the extraction and the bypass do compose at runtime, not just at merge time.

**@⁠HailLucifer666** on GitHub · 2026-11-25 11:40 UTC · [original](https://github.com/fxceless/victory-fork/pull/862#issuecomment-7161354649) Rebased onto #169 (`eb568071`) — this is now head `eca8b0f2` and **must land after #169**, not before. That order is not a preference, it is a fact I checked rather than assumed: `git merge-tree` between the two heads reported a real conflict in `draw.rs`, because #169 wraps `if !clamped { … } else { … }` around exactly the window block this PR extracts `serve()` out of. Landing #862 first leaves #169 wrapping a block that no longer exists in that shape; the reverse order survives. The composition here keeps both: #169's bypass arm is the `!clamped` side, and this PR's `serve()`-based window logic is the `clamped` side, unchanged — `Serve::Held`/`Serve::Clamp`, the `window_check` diagnostics on the held path, `bound_ahead`, and the 20 device-free window-arithmetic tests all intact. #169's two `done()` barriers stay, now over `bounded` (this PR's binding) rather than `exec_buf`. Gate on the **combined result** (`main` + `#169` + this), which is the thing that will actually be shipped: ``` cargo test -p victory-gpu --lib draw::tests 20 passed, 0 failed cargo test -p victory-gpu --locked 181 passed, 0 failed, 4 ignored cargo test -p victory-gpu indirect:: --test-threads=1 14 passed, 2 ignored + warp_budget_saturates… red (the known race #849 fixes) cargo clippy (both passes) red only on main's 3 pre-existing lints cargo test -p xtask --locked 4 passed ``` The full-suite number is the important one: 181 passed is `main`'s 161 plus this PR's 20, with zero failures — so the extraction and the bypass do compose at runtime, not just at merge time.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 12:23 UTC · original

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 eca8b0f into main f85101b in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings fails with exactly the errors main itself has on this machine (placed_filler_twins, depth_written, a sort; PR #841 fixes them), also with --all-features; this PR adds none. cargo test --workspace --locked: run 1: 577 passed, 0 failed, 11 ignored; run 2: stopped at indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields (the one that fails on main itself most runs here (PR #849 and #847 fix its assertion)) (main alone: 555 passed, 0 failed, 11 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 12:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/862#issuecomment-7162306914) 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 `eca8b0f` into `main` `f85101b` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings` fails with exactly the errors `main` itself has on this machine (`placed_filler_twins`, `depth_written`, a sort; PR #841 fixes them), also with `--all-features`; this PR adds none. `cargo test --workspace --locked`: run 1: 577 passed, 0 failed, 11 ignored; run 2: stopped at `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields` (the one that fails on `main` itself most runs here (PR #849 and #847 fix its assertion)) (`main` alone: 555 passed, 0 failed, 11 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
github-bot force-pushed github-bot/gh-862 from d21c08ba4d to f63b279bf1 2026-11-26 14:05:55 +00:00 Compare
Author
Owner

@⁠HailLucifer666 on GitHub · 2026-11-26 14:03 UTC · original

Rebased onto the new #169 head (d41db98d); this head is now f63b279b. One conflict, in the draw.rs test module: main added a_bake_draw_names_the_indices_of_its_constants_and_records where this PR adds its serve() tests, so both are kept. Verified: victory-gpu draw::tests 23 passed, 0 failed; clippy -D warnings on victory-gpu clean. Merge after #169, as the description says.

**@⁠HailLucifer666** on GitHub · 2026-11-26 14:03 UTC · [original](https://github.com/fxceless/victory-fork/pull/862#issuecomment-7194224422) Rebased onto the new `#169` head (`d41db98d`); this head is now `f63b279b`. One conflict, in the `draw.rs` test module: main added `a_bake_draw_names_the_indices_of_its_constants_and_records` where this PR adds its `serve()` tests, so both are kept. Verified: `victory-gpu draw::tests` 23 passed, 0 failed; `clippy -D warnings` on victory-gpu clean. Merge after `#169`, as the description says.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/862/head:github-bot/gh-862'
git switch 'github-bot/gh-862'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-862'
git switch 'github-bot/gh-862'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-862'
git switch 'github-bot/gh-862'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-862'
git switch 'main'
git merge --squash 'github-bot/gh-862'
git switch 'main'
git merge --ff-only 'github-bot/gh-862'
git switch 'main'
git merge 'github-bot/gh-862'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.