GPU test: the budget test does not decide which two records fit #1098

Open
github-bot wants to merge 1 commit from github-bot/gh-1098 into main AGit
Owner

@⁠HoLa-Lee on GitHub · 2026-11-25 19:23 UTC · original
HoLa-Lee:tests/budget-charges-any-two → main · +16 −5 · 1 files · 1 commits · open

What this fixes

warp_budget_saturates_without_wraparound_and_preserves_draw_fields in crates/victory-gpu/src/indirect.rs fails intermittently, for a reason that is not a bug in the clamp:

if rec[0] == (1 << 22) && rec[1] == 16 {
    assert!(i == 1 || i == 2, "the first two real draws fit the budget");

The clamp charges records with an atomic add from parallel lanes, so which records reach the budget first is the GPU's to choose. On the software adapter, this test alone, 15 runs: records 1 and 2 kept theirs 4 times, records 64 and 65 kept theirs 11 times - and spent == BUDGET_CAP in all 15. The records are grouped 64 at a time, and which group runs first is not fixed.

So the assertion was pinning an order the GPU never promised: 13 of 20 runs of this single test failed on this machine before the change (RTX 4080 SUPER + Microsoft Basic Render Driver WARP).

What it asserts now

The facts that are fixed, and the ones the test exists for:

  • two records of 1 << 26 fit a budget of 1 << 27, and exactly two keep their draws;
  • every other record is zeroed whole ((0, 0)), and the empty first record charges nothing;
  • spent == BUDGET_CAP - the budget saturates without wrapping (this is the regression the test was written for: the old InterlockedAdd wrapped at 64 lanes);
  • the source arguments are untouched, and no other word of any record (StartIndexLocation, BaseVertexLocation, StartInstanceLocation, the trailing word) is lost.

The failure message now names the records that did keep theirs, so a future failure says what happened rather than only that the order was unexpected.

Measured

run before after
this test alone 13 of 20 failed 25 of 25 passed
victory-gpu lib, --test-threads=1 intermittent 198 passed, 0 failed, 6 ignored, 4 runs
victory-gpu lib, parallel ~1 in 8-14 198 passed, 0 failed, 6 ignored, 4 runs

cargo test -p victory-gpu --lib --profile diag --features diagnostics, Rust 1.98.1. Clippy in this tree reports the same pre-existing manual_is_multiple_of and dead-code lints before and after; the changed lines add none.

Where this came from

This is the failure filed under FIND-20 in the coordination thread (#1633). It had been described as "watch tests are flaky, WARP tests contend for process-level caches", then corrected to "not concurrency, not the shader cache" - both of those were disproven there. What was left was the guess that some runs got a non-WARP adapter. Instrumenting the harness shows the adapter is always WARP (Microsoft Basic Render Driver, vendor 0x1414, device 0x8c, flags 0x2), and the assertion that fires is this one, not spent. The other candidate (inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset, VirtualFree(MEM_DECOMMIT) refused) passed 20 of 20 runs on its own with the OS state printed, so it is not implicated either.

The four warp_* tests that used to take turns behind a test-only mutex no longer need to: with this fix the suite is green single-threaded and in parallel.

**@⁠HoLa-Lee** on GitHub · 2026-11-25 19:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/1098) `HoLa-Lee:tests/budget-charges-any-two` → `main` · +16 −5 · 1 files · 1 commits · open ## What this fixes `warp_budget_saturates_without_wraparound_and_preserves_draw_fields` in `crates/victory-gpu/src/indirect.rs` fails intermittently, for a reason that is not a bug in the clamp: ``` if rec[0] == (1 << 22) && rec[1] == 16 { assert!(i == 1 || i == 2, "the first two real draws fit the budget"); ``` The clamp charges records with an atomic add from parallel lanes, so **which** records reach the budget first is the GPU's to choose. On the software adapter, this test alone, 15 runs: records 1 and 2 kept theirs **4 times**, records 64 and 65 kept theirs **11 times** - and `spent == BUDGET_CAP` in **all 15**. The records are grouped 64 at a time, and which group runs first is not fixed. So the assertion was pinning an order the GPU never promised: **13 of 20 runs of this single test failed** on this machine before the change (RTX 4080 SUPER + `Microsoft Basic Render Driver` WARP). ## What it asserts now The facts that are fixed, and the ones the test exists for: - two records of `1 << 26` fit a budget of `1 << 27`, and exactly two keep their draws; - every other record is zeroed whole (`(0, 0)`), and the empty first record charges nothing; - `spent == BUDGET_CAP` - the budget saturates without wrapping (this is the regression the test was written for: the old `InterlockedAdd` wrapped at 64 lanes); - the source arguments are untouched, and no other word of any record (`StartIndexLocation`, `BaseVertexLocation`, `StartInstanceLocation`, the trailing word) is lost. The failure message now names the records that did keep theirs, so a future failure says what happened rather than only that the order was unexpected. ## Measured | run | before | after | |---|---|---| | this test alone | 13 of 20 failed | **25 of 25 passed** | | `victory-gpu` lib, `--test-threads=1` | intermittent | **198 passed, 0 failed, 6 ignored**, 4 runs | | `victory-gpu` lib, parallel | ~1 in 8-14 | **198 passed, 0 failed, 6 ignored**, 4 runs | `cargo test -p victory-gpu --lib --profile diag --features diagnostics`, Rust 1.98.1. Clippy in this tree reports the same pre-existing `manual_is_multiple_of` and dead-code lints before and after; the changed lines add none. ## Where this came from This is the failure filed under `FIND-20` in the coordination thread (#1633). It had been described as "watch tests are flaky, WARP tests contend for process-level caches", then corrected to "not concurrency, not the shader cache" - both of those were disproven there. What was left was the guess that some runs got a non-WARP adapter. Instrumenting the harness shows the adapter is always WARP (`Microsoft Basic Render Driver`, vendor `0x1414`, device `0x8c`, flags `0x2`), and the assertion that fires is this one, not `spent`. The other candidate (`inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset`, `VirtualFree(MEM_DECOMMIT)` refused) passed 20 of 20 runs on its own with the OS state printed, so it is not implicated either. The four `warp_*` tests that used to take turns behind a test-only mutex no longer need to: with this fix the suite is green single-threaded and in parallel.
`warp_budget_saturates_without_wraparound_and_preserves_draw_fields` asserted
that records 1 and 2 are the ones that keep their draws when a budget of
1 << 27 is spent by records of 1 << 26. The clamp charges records with an
atomic add from parallel lanes, so which records are charged first is the
GPU's to choose: on the software adapter, this test alone, 15 runs, records 1
and 2 kept theirs 4 times and records 64 and 65 11 times, with
`spent == BUDGET_CAP` in all 15. The assertion therefore failed for a
behaviour the GPU never promised - 13 of 20 runs of this test alone on this
machine before the change.

The test now asserts what is in fact fixed: two records of 1 << 26 fit a
budget of 1 << 27, exactly two keep their draws and every other record is
zeroed whole, the budget saturates without wrapping, the empty first record
charges nothing, and no other word of any record is lost. The wraparound this
test exists to catch is still caught by `spent == BUDGET_CAP`.

Measured after: this test alone, 25 runs, 25 passed; the whole `victory-gpu`
library 8 times - four with `--test-threads=1` and four in parallel - 198
passed, 0 failed, 6 ignored each time. Clippy in this tree reports the same
pre-existing `manual_is_multiple_of` and dead-code lints before and after the
change; the changed lines add none.

Found while working FIND-20 in the coordination thread: those failures had
been blamed on concurrency, on the shader cache, and on a non-WARP adapter.
The adapter is WARP (the harness prints "Microsoft Basic Render Driver",
vendor 0x1414, flags 0x2), and the assertion that failed was never `spent`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:27 +00:00
Author
Owner

@⁠liuycsbxbxn on GitHub · 2026-11-25 22:06 UTC · original

The shape of the fix here is right, and putting kept_at in the failure message is exactly what a future failure needs.

One thing worth recording while both PRs are open: #1110 asserts kept == [1, 2] || kept == [64, 65]. That fixes the cross-wave order but still assumes the lanes within a wave charge the budget in lane order. Lane order inside a wave is not part of the contract either -- it happens to hold on WARP today, but another adapter (or a future WARP change) can hand the budget to two arbitrary records of the filling wave and that assertion goes red again. The invariant form here -- exactly two records keep their draw, record 0 charges nothing, everything else is zeroed whole, spent == BUDGET_CAP -- is the one that survives that. So if only one of the two can land (they touch the same lines), this is the safer one.

Two small things if you touch it again:

  • assert_eq!(kept_at.len(), 2, ...) before the .contains(&0) check makes the "exactly two" fact its own assertion with its own message, instead of being implied by (kept, zeroed) == (2, N - 2).
  • The measured table is doing a lot of the convincing: 13 of 20 before, 25 of 25 after, plus the --test-threads=1 row. Worth keeping it in the body rather than only in review.

Not something I can run here (no Rust toolchain on this machine, and an Intel iGPU rather than the 4080), so this is reasoning from the clamp and the two diffs, not a measurement.

**@⁠liuycsbxbxn** on GitHub · 2026-11-25 22:06 UTC · [original](https://github.com/fxceless/victory-fork/pull/1098#issuecomment-7175952909) The shape of the fix here is right, and putting `kept_at` in the failure message is exactly what a future failure needs. One thing worth recording while both PRs are open: #1110 asserts `kept == [1, 2] || kept == [64, 65]`. That fixes the cross-wave order but still assumes the lanes *within* a wave charge the budget in lane order. Lane order inside a wave is not part of the contract either -- it happens to hold on WARP today, but another adapter (or a future WARP change) can hand the budget to two arbitrary records of the filling wave and that assertion goes red again. The invariant form here -- exactly two records keep their draw, record 0 charges nothing, everything else is zeroed whole, `spent == BUDGET_CAP` -- is the one that survives that. So if only one of the two can land (they touch the same lines), this is the safer one. Two small things if you touch it again: - `assert_eq!(kept_at.len(), 2, ...)` before the `.contains(&0)` check makes the "exactly two" fact its own assertion with its own message, instead of being implied by `(kept, zeroed) == (2, N - 2)`. - The measured table is doing a lot of the convincing: 13 of 20 before, 25 of 25 after, plus the `--test-threads=1` row. Worth keeping it in the body rather than only in review. Not something I can run here (no Rust toolchain on this machine, and an Intel iGPU rather than the 4080), so this is reasoning from the clamp and the two diffs, not a measurement.
Author
Owner

@⁠HoLa-Lee on GitHub · 2026-11-25 22:25 UTC · original

Thanks - both points are in, bfbb167.

The invariant form is what the test asserts now, and the record names are gone. Your reasoning about lane order inside a group is in the comment verbatim: only the count (exactly two), the empty first record charging nothing, every other record zeroed whole, spent == BUDGET_CAP, and no word of any record lost. Nothing names a record number, so a future adapter handing the budget to two arbitrary records of the filling group still passes.

The two small things:

  • assert_eq!(kept_at.len(), 2, "… {kept_at:?}") is now its own assertion, before the "record 0 charges nothing" one, and zeroed has its own assert_eq! next to it - so a failure says which fact broke rather than which tuple was wrong.
  • The measured table stays, and the lane-order caveat is now stated in the same comment as the measurements: 15 runs of this test alone on the software adapter, records 1 and 2 kept theirs 4 times, 64 and 65 11 times, spent == BUDGET_CAP in all 15; 20 of 20 runs of the current version pass, and the full victory-gpu library is 198 passed / 0 failed / 6 ignored in four parallel and four single-threaded runs.

On #1110: your reading matches mine - it fixes the cross-group order but still says kept == [1, 2] || kept == [64, 65], which pins lane order inside a group. They touch the same lines, so if the maintainer prefers #1110 I'll close this one; the intent here was to leave the assertion on the contract and not on today's scheduling, and that is the only difference between the two.

**@⁠HoLa-Lee** on GitHub · 2026-11-25 22:25 UTC · [original](https://github.com/fxceless/victory-fork/pull/1098#issuecomment-7176346660) Thanks - both points are in, `bfbb167`. **The invariant form is what the test asserts now**, and the record names are gone. Your reasoning about lane order inside a group is in the comment verbatim: only the count (exactly two), the empty first record charging nothing, every other record zeroed whole, `spent == BUDGET_CAP`, and no word of any record lost. Nothing names a record number, so a future adapter handing the budget to two arbitrary records of the filling group still passes. **The two small things:** - `assert_eq!(kept_at.len(), 2, "… {kept_at:?}")` is now its own assertion, before the "record 0 charges nothing" one, and `zeroed` has its own `assert_eq!` next to it - so a failure says which fact broke rather than which tuple was wrong. - The measured table stays, and the lane-order caveat is now stated in the same comment as the measurements: 15 runs of this test alone on the software adapter, records 1 and 2 kept theirs 4 times, 64 and 65 11 times, `spent == BUDGET_CAP` in all 15; 20 of 20 runs of the current version pass, and the full `victory-gpu` library is 198 passed / 0 failed / 6 ignored in four parallel and four single-threaded runs. **On #1110:** your reading matches mine - it fixes the cross-group order but still says `kept == [1, 2] || kept == [64, 65]`, which pins lane order inside a group. They touch the same lines, so if the maintainer prefers #1110 I'll close this one; the intent here was to leave the assertion on the contract and not on today's scheduling, and that is the only difference between the two.
Author
Owner

@⁠ishan-2025 on GitHub · 2026-11-26 00:04 UTC · original

Checked against current main (dc4c0fc), since this was opened on an older base.

Tree warp_budget test, 30 runs of the built test binary
main dc4c0fc as is 6 pass, 24 fail (the first two real draws fit the budget)
dc4c0fc + this PR's diff (applies cleanly) 30 pass, 0 fail
dc4c0fc + #1134's diff (applies cleanly) 30 pass, 0 fail

Machine: Windows 11 26200, i9-12900H, RTX 3070 Ti Laptop 8 GB + Iris Xe. The test runs on WARP, so this only adds one more machine where main fails most of the time and the change holds.

Either PR closes #1118. This one states the invariant without naming the pair, as discussed above, so it stays correct if lane order inside a group ever differs.

Test output only, no game data. AI-assisted (Claude Code).

**@⁠ishan-2025** on GitHub · 2026-11-26 00:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/1098#issuecomment-7178357816) Checked against current main (`dc4c0fc`), since this was opened on an older base. | Tree | `warp_budget` test, 30 runs of the built test binary | |---|---| | main `dc4c0fc` as is | 6 pass, 24 fail (`the first two real draws fit the budget`) | | `dc4c0fc` + this PR's diff (applies cleanly) | 30 pass, 0 fail | | `dc4c0fc` + #1134's diff (applies cleanly) | 30 pass, 0 fail | Machine: Windows 11 26200, i9-12900H, RTX 3070 Ti Laptop 8 GB + Iris Xe. The test runs on WARP, so this only adds one more machine where main fails most of the time and the change holds. Either PR closes #1118. This one states the invariant without naming the pair, as discussed above, so it stays correct if lane order inside a group ever differs. Test output only, no game data. AI-assisted (Claude Code).
Author
Owner

@⁠HoLa-Lee on GitHub · 2026-11-26 00:15 UTC · original

Thank you - that is the most useful shape of evidence for this one: the same binary, 30 runs, on a machine that is not mine, 6/30 on main and 30/30 with the diff. It also settles the question the two PRs were competing over: #1134 (kept == [1, 2] || kept == [64, 65]) and this one (the invariant, no record named) are both green today, so the difference only shows the day an adapter hands the budget to two arbitrary records of the filling group - and then only this one stays green.

Two notes back:

  • I am deliberately not rebasing onto the newer main you tested against (dc4c0fc): rebasing would invalidate the exact sha your 30 runs stand for, and the diff applies cleanly as it is. If a maintainer asks for a rebase I will do it and re-run the 30 there.
  • spent == BUDGET_CAP is still asserted, so the wraparound the test was written for (the old InterlockedAdd wrapping at 64 lanes) is still caught even though no record number appears anywhere now.

If the maintainer would rather have #1134, I will close this one without argument - the point was to leave the assertion on the contract, and that is the only thing this PR adds.

**@⁠HoLa-Lee** on GitHub · 2026-11-26 00:15 UTC · [original](https://github.com/fxceless/victory-fork/pull/1098#issuecomment-7178570228) Thank you - that is the most useful shape of evidence for this one: **the same binary, 30 runs, on a machine that is not mine**, 6/30 on main and 30/30 with the diff. It also settles the question the two PRs were competing over: #1134 (kept == [1, 2] || kept == [64, 65]) and this one (the invariant, no record named) are both green today, so the difference only shows the day an adapter hands the budget to two arbitrary records of the filling group - and then only this one stays green. Two notes back: - I am deliberately **not** rebasing onto the newer main you tested against (dc4c0fc): rebasing would invalidate the exact sha your 30 runs stand for, and the diff applies cleanly as it is. If a maintainer asks for a rebase I will do it and re-run the 30 there. - spent == BUDGET_CAP is still asserted, so the wraparound the test was written for (the old InterlockedAdd wrapping at 64 lanes) is still caught even though no record number appears anywhere now. If the maintainer would rather have #1134, I will close this one without argument - the point was to leave the assertion on the contract, and that is the only thing this PR adds.
Author
Owner

@⁠liuycsbxbxn on GitHub · 2026-11-26 13:22 UTC · original

One more data point, from a machine that is neither yours nor ishan-2025's: GitHub's windows-latest runner, WARP (Microsoft Basic Render Driver), a clean fork of main at 9c184b3 (before this PR), the test binary built once and then run 20 times.

19 of 20 runs failed.

Run: https://github.com/liuycsbxbxn/victory-fork/actions/runs/45712712377 - the count is in the run's notice and step summary. Workflow: .github/workflows/flake-repro.yml on liuycsbxbxn/victory-fork; the job exits 0 on purpose so all 20 runs execute, the count is the datum, not the job's colour.

That is three machines now: 13/20 on yours, 6/30 on ishan-2025's main, 19/20 on GitHub's runner. That spread is what a test pinning an order the device never promised looks like - the ratio is whatever the adapter's scheduling gives you that day, so the fix is to stop asserting the order rather than to tune the ratio.

Nothing needed from you on this; it is here so the next person searching for this test finds the spread.

**@⁠liuycsbxbxn** on GitHub · 2026-11-26 13:22 UTC · [original](https://github.com/fxceless/victory-fork/pull/1098#issuecomment-7193255098) One more data point, from a machine that is neither yours nor ishan-2025's: GitHub's `windows-latest` runner, WARP (Microsoft Basic Render Driver), a clean fork of `main` at `9c184b3` (before this PR), the test binary built once and then run 20 times. **19 of 20 runs failed.** Run: https://github.com/liuycsbxbxn/victory-fork/actions/runs/45712712377 - the count is in the run's notice and step summary. Workflow: `.github/workflows/flake-repro.yml` on `liuycsbxbxn/victory-fork`; the job exits 0 on purpose so all 20 runs execute, the count is the datum, not the job's colour. That is three machines now: 13/20 on yours, 6/30 on ishan-2025's main, 19/20 on GitHub's runner. That spread is what a test pinning an order the device never promised looks like - the ratio is whatever the adapter's scheduling gives you that day, so the fix is to stop asserting the order rather than to tune the ratio. Nothing needed from you on this; it is here so the next person searching for this test finds the spread.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/indirect.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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