GPU: the indirect budget is charged in record order and no longer wraps #1510

Manually merged
github merged 1 commit from gh-pr/1510/head into gh-pr/1510/base 2026-11-26 04:34:33 +00:00
Owner

@⁠rouges78 on GitHub · 2026-11-24 18:37 UTC · original
rouges78:fix/indirect-budget-in-order → main · +138 −11 · 1 files · 1 commits · merged 2026-11-25 00:17 UTC

The list's indirect budget wraps. Rejected records still add their cost to it, so 64 draw records of 2^26 bring the word back to zero and work is let in again: of 128 garbage draws four run where two fit (report, confirmed by a second reader).

This charges the budget in record order, with no word shared between groups: one group walks the records in tiles of 64, every lane clamps its own record, and the first lane charges the tile's records in order. The bounds, the root signature, the constants and the in-place clamp are unchanged; only the budget part of the shader and the dispatch count (one group) change.

Visible effect: a list whose budget is spent stays spent, so indirect work after it in the same list runs empty where main let it in again after a wrap; and the records that run are the first in the buffer, not whichever threads added first. Once the budget is spent, a record that costs nothing keeps its clamped first word where main zeroed it; it does no work either way.

One file, crates/victory-gpu/src/indirect.rs. Four tests: rejected_records_do_not_wrap_the_budget (four draws run instead of two) and a_spent_budget_stays_spent (two run again on a second execution) fail on main; the_budget_goes_to_the_first_records and a_record_that_does_not_fit_ends_the_budget pin the order and the rule. Every test also checks that the record after the last one is left as written.

Clamp alone through host.execute on an RTX 4080, N draw records that all fit, median of 5 runs, ms:

records main this
1,024 0.16 0.13
16,384 1.2 0.75
65,536 6.0 2.8
1,048,576 76 43

Not in here: the count buffer and the scratch copy, which #242 and #583 carry. #583's compare-exchange budget, and #242's before e5ec341, timed out on this RTX 4080 once many records fit (device removed at 16,384; measurements in #242); this walk is the alternative measured there. #242 walks tiles in one group too since e5ec341; run here at 6cb8fbe, it admits the same records as this PR on 614 cases (#242), except with a count below the maximum, where it does not charge the inactive tail and this PR, like main, does. So this PR is that part alone, on main's shader, in one file. #190 and #1470 replace this HLSL shader with emitted DXIL and #1279 rewrites it for Wine's compiler; all three keep the plain add, so the wrap survives them and whichever lands second has to carry the walk over. This shader is not tried under Wine's compiler, which already refuses main's (#1279).

Checked: both clippy configurations, cargo test --workspace --locked on the RTX 4080 (346 passed), the indirect tests on WARP. Not run against the title: I do not have it.

AI-assisted (Claude wrote the change and the tests with me; the numbers are from real runs on the card).

🤖 Generated with Claude Code

**@⁠rouges78** on GitHub · 2026-11-24 18:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1510) `rouges78:fix/indirect-budget-in-order` → `main` · +138 −11 · 1 files · 1 commits · merged 2026-11-25 00:17 UTC The list's indirect budget wraps. Rejected records still add their cost to it, so 64 draw records of 2^26 bring the word back to zero and work is let in again: of 128 garbage draws four run where two fit ([report](https://git.gtahub.st/github/Marvisak--VIctory/issues/597), [confirmed by a second reader](https://git.gtahub.st/github/Marvisak--VIctory/issues/597)). This charges the budget in record order, with no word shared between groups: one group walks the records in tiles of 64, every lane clamps its own record, and the first lane charges the tile's records in order. The bounds, the root signature, the constants and the in-place clamp are unchanged; only the budget part of the shader and the dispatch count (one group) change. Visible effect: a list whose budget is spent stays spent, so indirect work after it in the same list runs empty where main let it in again after a wrap; and the records that run are the first in the buffer, not whichever threads added first. Once the budget is spent, a record that costs nothing keeps its clamped first word where main zeroed it; it does no work either way. One file, `crates/victory-gpu/src/indirect.rs`. Four tests: `rejected_records_do_not_wrap_the_budget` (four draws run instead of two) and `a_spent_budget_stays_spent` (two run again on a second execution) fail on main; `the_budget_goes_to_the_first_records` and `a_record_that_does_not_fit_ends_the_budget` pin the order and the rule. Every test also checks that the record after the last one is left as written. Clamp alone through `host.execute` on an RTX 4080, N draw records that all fit, median of 5 runs, ms: | records | main | this | |---|---|---| | 1,024 | 0.16 | 0.13 | | 16,384 | 1.2 | 0.75 | | 65,536 | 6.0 | 2.8 | | 1,048,576 | 76 | 43 | Not in here: the count buffer and the scratch copy, which #242 and #583 carry. #583's compare-exchange budget, and #242's before e5ec341, timed out on this RTX 4080 once many records fit (device removed at 16,384; measurements in https://git.gtahub.st/github/Marvisak--VIctory/pulls/242); this walk is the alternative measured there. #242 walks tiles in one group too since e5ec341; run here at 6cb8fbe, it admits the same records as this PR on 614 cases (https://git.gtahub.st/github/Marvisak--VIctory/pulls/242), except with a count below the maximum, where it does not charge the inactive tail and this PR, like main, does. So this PR is that part alone, on main's shader, in one file. #190 and #1470 replace this HLSL shader with emitted DXIL and #1279 rewrites it for Wine's compiler; all three keep the plain add, so the wrap survives them and whichever lands second has to carry the walk over. This shader is not tried under Wine's compiler, which already refuses main's (#1279). Checked: both clippy configurations, `cargo test --workspace --locked` on the RTX 4080 (346 passed), the `indirect` tests on WARP. Not run against the title: I do not have it. AI-assisted (Claude wrote the change and the tests with me; the numbers are from real runs on the card). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Rejected records still added their cost to the list's budget, so the word
wrapped and let work in again: of 128 garbage draws (2^26 vertex instances
each once clamped) four ran where two fit.

One group now walks the records in tiles of 64: every lane clamps its own
record, and the first lane charges the tile's records in order. No word is
shared between groups. Reserving by compare-exchange was tried: 16,384 small
records took an RTX 4080 past the host's time-out.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:34:30 +00:00
github manually merged commit 4ab20fc863 into gh-pr/1510/base 2026-11-26 04:34:33 +00:00
Author
Owner

@⁠acetonahard-code on GitHub · 2026-11-24 22:31 UTC · original

Tested on Windows 11, RTX 4070 SUPER (driver 621.14), with the repo toolchain, merged into current main (70564ae):

cargo test -p victory-gpu passed failed ignored
main 76 2 1
main + this PR 80 2 1
main, --all-features 79 2 -
main + this PR, --all-features 83 2 -
  • The 4 new tests pass.
  • No GPU test skipped for lack of a device.
  • cargo clippy --all-targets -- -D warnings, with and without --all-features: clean.
  • Two victory-gpu tests fail on current main on this NVIDIA card: dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views. That's the 1,000,000-view heap cap, see #1744. They fail the same way with this PR, and no other test does.

I didn't test with game data.


Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.

**@⁠acetonahard-code** on GitHub · 2026-11-24 22:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1510#issuecomment-7146329728) Tested on Windows 11, RTX 4070 SUPER (driver 621.14), with the repo toolchain, merged into current `main` (70564ae): | `cargo test -p victory-gpu` | passed | failed | ignored | |---|---|---|---| | `main` | 76 | 2 | 1 | | `main` + this PR | 80 | 2 | 1 | | `main`, `--all-features` | 79 | 2 | - | | `main` + this PR, `--all-features` | 83 | 2 | - | - The 4 new tests pass. - No GPU test skipped for lack of a device. - `cargo clippy --all-targets -- -D warnings`, with and without `--all-features`: clean. - Two `victory-gpu` tests fail on current `main` on this NVIDIA card: `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`. That's the 1,000,000-view heap cap, see #1744. They fail the same way with this PR, and no other test does. I didn't test with game data. --- <sub>Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.</sub>
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1510
No description provided.