indirect: warp_budget test accepts either group order (fixes #1100, #1118) #1131

Closed
DominicBrett wants to merge 1 commit from upstream-pr/1134 into main
DominicBrett commented 2026-11-25 21:17:19 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by DominicBrett on 2026-11-25T21:17:19Z.


Fixes #1100 and #1118: indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields fails intermittently, and on some machines nearly every time.

Cause

The cause is the test, not the shader. The test sends 128 records, which the clamp runs as two groups of 64. Each group adds up its own records' cost in lane order, then charges that sum to the one budget word with a compare-and-swap. Every real draw costs 2^26, so the group that charges first takes the whole 2^27 budget with its first two real draws, and every draw in the other group runs empty.

D3D12 gives no order between thread groups, and WARP (which this test always uses, whatever GPU is installed) runs groups on CPU threads. Either group can win. The test hard-coded the first group winning (assert!(i == 1 || i == 2)), so it fails whenever the second group charges first (records 64 and 65 kept).

This also answers the question in #1118: the GPU's wave width isn't involved. The harness runs on WARP, and the clamp's numthreads(64) plus groupshared walk is the same on every adapter. That explains why it "passed twice, then failed three times" on the same machine.

Fix (test only, shader unchanged)

The test now accepts either [1, 2] or [64, 65] as the kept pair. It still requires:

  • exactly one group wins, keeping its first two real draws in lane order, and nothing from the other group;
  • every other draw zeroed, and the budget saturated at exactly BUDGET (no wraparound);
  • every pass-through field and the source buffer unchanged.

Evidence

Windows 11 26200, RTX 4070 SUPER (driver 617.42), Rust 1.98.1 MSVC, on 085ee7c. The test binary was run 100 times, with a temporary eprintln! of the kept record indices (removed before committing):

runs pass fail kept [1, 2] kept [64, 65]
before (085ee7c) 100 7 93 7 93
after (this PR) 100 100 0 8 92

Every failure before the fix is a run where the second group won. After the fix, both orders still occur and both pass.

The test still catches a real bug: with the shader's fit check broken on purpose (fit = 1u;, so nothing is ever cut by the budget), the updated test fails: kept [1, 2, 3, …, 127].

Other checks:

  • cargo test -p victory-gpu: 183 passed, 0 failed, 5 ignored.
  • cargo clippy -p victory-gpu --all-targets: same 11 existing warnings before and after, none in the changed lines.
  • rustfmt --check: the changed hunk is clean (the file has existing rustfmt diffs elsewhere, left alone).

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6613935252 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1134). Originally posted by [DominicBrett](https://github.com/DominicBrett) on 2026-11-25T21:17:19Z. --- Fixes #1100 and #1118: `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields` fails intermittently, and on some machines nearly every time. ## Cause The cause is the test, not the shader. The test sends 128 records, which the clamp runs as **two groups of 64**. Each group adds up its own records' cost in lane order, then charges that sum to the one budget word with a compare-and-swap. Every real draw costs 2^26, so the group that charges first takes the whole 2^27 budget with its first two real draws, and every draw in the other group runs empty. D3D12 gives **no order between thread groups**, and WARP (which this test always uses, whatever GPU is installed) runs groups on CPU threads. Either group can win. The test hard-coded the first group winning (`assert!(i == 1 || i == 2)`), so it fails whenever the second group charges first (records 64 and 65 kept). This also answers the question in #1118: the GPU's wave width isn't involved. The harness runs on WARP, and the clamp's `numthreads(64)` plus groupshared walk is the same on every adapter. That explains why it "passed twice, then failed three times" on the same machine. ## Fix (test only, shader unchanged) The test now accepts **either** `[1, 2]` or `[64, 65]` as the kept pair. It still requires: - exactly one group wins, keeping its first two real draws in lane order, and nothing from the other group; - every other draw zeroed, and the budget saturated at exactly `BUDGET` (no wraparound); - every pass-through field and the source buffer unchanged. ## Evidence Windows 11 26200, RTX 4070 SUPER (driver 617.42), Rust 1.98.1 MSVC, on `085ee7c`. The test binary was run 100 times, with a temporary `eprintln!` of the kept record indices (removed before committing): | | runs | pass | fail | kept `[1, 2]` | kept `[64, 65]` | |---|---|---|---|---|---| | before (`085ee7c`) | 100 | 7 | **93** | 7 | 93 | | after (this PR) | 100 | **100** | 0 | 8 | 92 | Every failure before the fix is a run where the second group won. After the fix, both orders still occur and both pass. **The test still catches a real bug:** with the shader's fit check broken on purpose (`fit = 1u;`, so nothing is ever cut by the budget), the updated test fails: `kept [1, 2, 3, …, 127]`. **Other checks:** - `cargo test -p victory-gpu`: 183 passed, 0 failed, 5 ignored. - `cargo clippy -p victory-gpu --all-targets`: same 11 existing warnings before and after, none in the changed lines. - `rustfmt --check`: the changed hunk is clean (the file has existing rustfmt diffs elsewhere, left alone). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-26 12:07:14 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!1131
No description provided.