Hoisted clamps: a draw whose shaders store ends the run; the pieces of a cut list share one budget (#209) #227

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

@⁠MamaLeVrai on GitHub · 2026-11-26 04:58 UTC · original
MamaLeVrai:hoist-run-rules → main · +432 −7 · 6 files · 2 commits · open

What

Two correctness rules for the hoisted indirect-argument clamps (VICTORY_HOIST_CLAMPS, on by default as mode 7):

  1. A draw whose shaders store ends the run. A plain draw, indexed draw, mesh dispatch or indirect draw whose pipeline has a stage that may write memory (Translated::writes_memory) now counts as a write (HostList::count_write), the same as dispatches and copies already do. The next indirect draw then starts a new run, so its clamp is recorded after that draw and not before it in the list ahead. Before this, a run kept going past such a draw, so a later draw's arguments were clamped before work that might write them.
  2. The pieces of one title list share one budget. When a title list is cut for hoisting, the clamps list and the piece after it now charge the first piece's budget (HostList::budget_to_lend / lend_budget) instead of a fresh 2^27 each. This keeps the cap where the single host list had it before the cut. A cut at a wait and a reset of the title list start a budget of their own again, as before hoisting.

Files: draw.rs (count_stores after each draw that ran, State::budget_of), host.rs (Deferred::lent_budget, budget() returns the lent address, budget_to_lend, lend_budget), list.rs (hoist() lends the first piece's budget to the clamps list and the next piece, cut() clears it).

Why

This comes from issue #209 by Marukooh. After the correction comment there, the timing claim is withdrawn (the 982f slowdown matched the card's memory budget, not hoisting), but the two correctness points still apply. I adapted the change from fxceless/victory-fork#1184 to this fork's code:

  • This fork has no indirect windows and no translated().stores. The equivalent rule here is Translated::writes_memory: buffer, image, flat or global stores and atomics, and also true when the code is not fully known.
  • This fork's budget is one mapped word per list, zeroed by a CPU step at submission, with no copy on the card. A lent budget is therefore the owner's buffer and address, kept alive by each borrower until its reset. The owner zeroes it once, and no state transitions are needed.

Tests

Both tests are new, in indirect::tests. They drive a title list through its method table, as the game does, on the host device:

  • a_draw_whose_shaders_store_ends_a_run_of_hoisted_clamps uses two test pipelines (pipeline::test_pipeline), with writes_memory false and true. It checks how many host lists a submission runs before and after a second indirect draw. A non-storing draw in between leaves the run as it is. A storing plain draw ends it (2 to 4 pieces), and so does a storing indirect draw.
  • pieces_cut_for_hoisted_clamps_charge_the_first_pieces_budget saturates the first piece's budget with clamps of three records of 65,535 x 16 groups. After the title's indirect draw cuts the list, it records a hoisted clamp in the clamps list and an inline clamp in the piece after, each of one 1x1x1 record, and a worker shader counts the groups that run. It then resets the title list and checks that the new pieces charge a budget of their own.

Results (release, cargo test --release -p victory-gpu --lib hoisted):

rule 1 test rule 2 test
with the change ok ok
rule 1 taken out (the count_stores calls) FAILED: left: 2, right: 4 (a storing draw ends the run) ok
only the indirect-draw count_stores taken out FAILED: left: 2, right: 4 (a storing indirect draw ends its own run) ok
rule 2 taken out (list.rs as on main) ok FAILED: left: 2, right: 0 (hits: each later piece had a fresh budget)

Full crate (cargo test --release -p victory-gpu --lib): 114 passed, 1 failed, 4 ignored. The failure is list::tests::lists_are_cut_at_waits_that_follow_work. It is known to fail in release runs on main and is fixed separately in #210. I did not rerun it on main here.

cargo clippy --release -p victory-gpu --all-targets --no-deps: none of its warnings is in the changed lines.

Not measured

  • Not run in the game. Nothing here was measured for timing or picture.
  • Rule 1 may cut runs more often: every draw whose shaders may write memory now ends a run. How often that happens in the game is not known.
  • Still not counted as writes, as on main: query resolves, texture copies and bottom-of-pipe writes. The fxceless change counts some of them.

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

🤖 Generated with Claude Code

**@⁠MamaLeVrai** on GitHub · 2026-11-26 04:58 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/227) `MamaLeVrai:hoist-run-rules` → `main` · +432 −7 · 6 files · 2 commits · open ## What Two correctness rules for the hoisted indirect-argument clamps (`VICTORY_HOIST_CLAMPS`, on by default as mode 7): 1. **A draw whose shaders store ends the run.** A plain draw, indexed draw, mesh dispatch or indirect draw whose pipeline has a stage that may write memory (`Translated::writes_memory`) now counts as a write (`HostList::count_write`), the same as dispatches and copies already do. The next indirect draw then starts a new run, so its clamp is recorded after that draw and not before it in the list ahead. Before this, a run kept going past such a draw, so a later draw's arguments were clamped before work that might write them. 2. **The pieces of one title list share one budget.** When a title list is cut for hoisting, the clamps list and the piece after it now charge the first piece's budget (`HostList::budget_to_lend` / `lend_budget`) instead of a fresh 2^27 each. This keeps the cap where the single host list had it before the cut. A cut at a wait and a reset of the title list start a budget of their own again, as before hoisting. Files: `draw.rs` (`count_stores` after each draw that ran, `State::budget_of`), `host.rs` (`Deferred::lent_budget`, `budget()` returns the lent address, `budget_to_lend`, `lend_budget`), `list.rs` (`hoist()` lends the first piece's budget to the clamps list and the next piece, `cut()` clears it). ## Why This comes from issue #209 by Marukooh. After the correction comment there, the timing claim is withdrawn (the 982f slowdown matched the card's memory budget, not hoisting), but the two correctness points still apply. I adapted the change from fxceless/victory-fork#1184 to this fork's code: - This fork has no indirect windows and no `translated().stores`. The equivalent rule here is `Translated::writes_memory`: buffer, image, flat or global stores and atomics, and also true when the code is not fully known. - This fork's budget is one mapped word per list, zeroed by a CPU step at submission, with no copy on the card. A lent budget is therefore the owner's buffer and address, kept alive by each borrower until its reset. The owner zeroes it once, and no state transitions are needed. ## Tests Both tests are new, in `indirect::tests`. They drive a title list through its method table, as the game does, on the host device: - `a_draw_whose_shaders_store_ends_a_run_of_hoisted_clamps` uses two test pipelines (`pipeline::test_pipeline`), with `writes_memory` false and true. It checks how many host lists a submission runs before and after a second indirect draw. A non-storing draw in between leaves the run as it is. A storing plain draw ends it (2 to 4 pieces), and so does a storing indirect draw. - `pieces_cut_for_hoisted_clamps_charge_the_first_pieces_budget` saturates the first piece's budget with clamps of three records of 65,535 x 16 groups. After the title's indirect draw cuts the list, it records a hoisted clamp in the clamps list and an inline clamp in the piece after, each of one 1x1x1 record, and a worker shader counts the groups that run. It then resets the title list and checks that the new pieces charge a budget of their own. Results (release, `cargo test --release -p victory-gpu --lib hoisted`): | | rule 1 test | rule 2 test | |---|---|---| | with the change | ok | ok | | rule 1 taken out (the `count_stores` calls) | FAILED: `left: 2, right: 4` (a storing draw ends the run) | ok | | only the indirect-draw `count_stores` taken out | FAILED: `left: 2, right: 4` (a storing indirect draw ends its own run) | ok | | rule 2 taken out (`list.rs` as on main) | ok | FAILED: `left: 2, right: 0` (hits: each later piece had a fresh budget) | Full crate (`cargo test --release -p victory-gpu --lib`): 114 passed, 1 failed, 4 ignored. The failure is `list::tests::lists_are_cut_at_waits_that_follow_work`. It is known to fail in release runs on main and is fixed separately in #210. I did not rerun it on main here. `cargo clippy --release -p victory-gpu --all-targets --no-deps`: none of its warnings is in the changed lines. ## Not measured - Not run in the game. Nothing here was measured for timing or picture. - Rule 1 may cut runs more often: every draw whose shaders may write memory now ends a run. How often that happens in the game is not known. - Still not counted as writes, as on main: query resolves, texture copies and bottom-of-pipe writes. The fxceless change counts some of them. AI-assisted (Claude Code); no game data. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Two correctness rules from issue #209 (Marukooh), adapted from
fxceless/victory-fork#1184:

- A draw, indexed draw, mesh dispatch or indirect draw whose pipeline
  has a stage that may write memory (Translated::writes_memory) counts
  as a write, like dispatches and copies, so the next indirect draw
  starts a new run and its clamp is recorded after that draw.
- The pieces a title list is cut into for hoisted clamps charge the
  first piece's budget (HostList::lend_budget) instead of a fresh 2^27
  each, so the cap stays where the one host list had it. A wait cut and
  a reset start a budget of their own again, as before.

Tests: indirect::tests::a_draw_whose_shaders_store_ends_a_run_of_hoisted_clamps
and pieces_cut_for_hoisted_clamps_charge_the_first_pieces_budget fail
with either rule taken out and pass with it. Not run in the game.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:01:43 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-26 04:59 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-26 04:59 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/227#pullrequestreview-6068772116) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:55 UTC · original

Tested natively on Windows 11, RX 7900 XT (RDNA3, driver 32.0.32029.2010). Head acedbae, base 4f62c2a. Debug builds. Other heavy jobs were running on the machine.

Tests:

  • cargo test -p victory-gpu --lib: 6 runs each of base and PR, alternating. PR: 115 passed in all 6. Base: 113 passed in 4. The other 2 each had one watch::tests flake (a_write_is_reported_at_every_checked_view, written_pages_are_reported_to_every_asker).
  • With only the test changes applied to base, both new tests fail (left: 2, right: 4 and left: 2, right: 0). They fail on the 7900 XT and on WARP (--features diagnostics, VICTORY_D3D12_WARP=1). With the PR both pass on both.
  • Clippy (-p victory-gpu --all-targets --no-deps): the same 47 warning lines on base and PR.

Overlap with #212 (point 1):

  • Both use the same flag: any stage of the bound pipeline with Translated::writes_memory. Both count it after the draw on the plain, indexed, mesh and indirect paths.
  • Cross-check: #212's code passes this PR's rule 1 test. This PR's code passes #212's storing_draw_counts_as_a_write.
  • One difference: this PR counts only while hoisting() is on, and #212 counts always. With VICTORY_HOIST_CLAMPS=0, #212's test fails on this PR (writes 0). Only hoisting reads the count, so this should not change behaviour.
  • The two PRs conflict in draw.rs (5 hunks: the four draw paths and the Hoist doc comment) and in host.rs (3 doc-comment hunks). All conflicts are in point 1. Point 2 does not touch #212's lines.
  • I have a local branch with #212 plus only this PR's point 2, with the conflicts resolved to #212's draw code. It passes the full lib suite (117 passed), including both PRs' tests.

Point 2, one more test:
None of the PR's tests covers the new state.budget_of = None in cut(), which gives a new budget after a wait. I wrote a local test for it:

  • The first piece spends the budget and a run is hoisted.
  • The list is cut at a wait that is already met.
  • A second run is hoisted, and an inline clamp in the last piece must run 1 group.

The test passes with the PR (7900 XT and WARP), and it also passes on base. With that line removed it fails (left: 0, right: 1): the run after the wait charges the budget that was spent before the wait. I can share it.

How often rule 1 will end a run: it keys on the same flag as #212, so the archive census in my #212 comment applies here unchanged. For example, 1496 of 1996 VS-only containers and 1546 of 12056 pixel containers count as storing, and 0 of 8765 mesh containers do.

On point 2's effect:
The mode 7 comment in indirect.rs says the mesh flicker came from records past the list's budget. So some lists in the game seem to reach the budget on main, where each piece has its own budget. With one shared budget per title list (until a wait), more records may run empty. That is the cap the list had before hoisting, but I did not measure it.

Not tested: no game run, no timing, no release-mode tests. The census counts containers, not the pipelines or draws a scene uses. I did not measure how many extra runs rule 1 ends or how often a shared budget runs out.

**@⁠adrianmjim** on GitHub · 2026-11-26 19:55 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/227#issuecomment-7202099041) Tested natively on Windows 11, RX 7900 XT (RDNA3, driver 32.0.32029.2010). Head acedbae, base 4f62c2a. Debug builds. Other heavy jobs were running on the machine. Tests: - `cargo test -p victory-gpu --lib`: 6 runs each of base and PR, alternating. PR: 115 passed in all 6. Base: 113 passed in 4. The other 2 each had one `watch::tests` flake (`a_write_is_reported_at_every_checked_view`, `written_pages_are_reported_to_every_asker`). - With only the test changes applied to base, both new tests fail (`left: 2, right: 4` and `left: 2, right: 0`). They fail on the 7900 XT and on WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`). With the PR both pass on both. - Clippy (`-p victory-gpu --all-targets --no-deps`): the same 47 warning lines on base and PR. Overlap with #212 (point 1): - Both use the same flag: any stage of the bound pipeline with `Translated::writes_memory`. Both count it after the draw on the plain, indexed, mesh and indirect paths. - Cross-check: #212's code passes this PR's rule 1 test. This PR's code passes #212's `storing_draw_counts_as_a_write`. - One difference: this PR counts only while `hoisting()` is on, and #212 counts always. With `VICTORY_HOIST_CLAMPS=0`, #212's test fails on this PR (writes 0). Only hoisting reads the count, so this should not change behaviour. - The two PRs conflict in `draw.rs` (5 hunks: the four draw paths and the `Hoist` doc comment) and in `host.rs` (3 doc-comment hunks). All conflicts are in point 1. Point 2 does not touch #212's lines. - I have a local branch with #212 plus only this PR's point 2, with the conflicts resolved to #212's draw code. It passes the full lib suite (117 passed), including both PRs' tests. Point 2, one more test: None of the PR's tests covers the new `state.budget_of = None` in `cut()`, which gives a new budget after a wait. I wrote a local test for it: - The first piece spends the budget and a run is hoisted. - The list is cut at a wait that is already met. - A second run is hoisted, and an inline clamp in the last piece must run 1 group. The test passes with the PR (7900 XT and WARP), and it also passes on base. With that line removed it fails (`left: 0, right: 1`): the run after the wait charges the budget that was spent before the wait. I can share it. How often rule 1 will end a run: it keys on the same flag as #212, so the archive census in my #212 comment applies here unchanged. For example, 1496 of 1996 VS-only containers and 1546 of 12056 pixel containers count as storing, and 0 of 8765 mesh containers do. On point 2's effect: The mode 7 comment in indirect.rs says the mesh flicker came from records past the list's budget. So some lists in the game seem to reach the budget on main, where each piece has its own budget. With one shared budget per title list (until a wait), more records may run empty. That is the cap the list had before hoisting, but I did not measure it. Not tested: no game run, no timing, no release-mode tests. The census counts containers, not the pipelines or draws a scene uses. I did not measure how many extra runs rule 1 ends or how often a shared budget runs out.
Covers the one line of rule 2 no test reached (state.budget_of = None in
cut()): with it taken out the run past the wait charges the budget spent
before it (hits 0 instead of 1). Suggested by adrianmjim on #227.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 23:28 UTC · original

Thanks @⁠adrianmjim, the cross-check with #212 and the census are very useful. Yes, please share the cut() test (a gist or a branch is fine). It covers the one line of point 2 that nothing tests, and I'll add it to this PR with credit. On #212: since both PRs use the same flag and #212 counts always, keeping #212's draw code for point 1 and only this PR's point 2 on top, as in your local branch, is the cleaner merge. If the maintainer takes #212, I'll cut this PR down to point 2.

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

**@⁠MamaLeVrai** on GitHub · 2026-11-26 23:28 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/227#issuecomment-7205577542) Thanks @⁠adrianmjim, the cross-check with #212 and the census are very useful. Yes, please share the `cut()` test (a gist or a branch is fine). It covers the one line of point 2 that nothing tests, and I'll add it to this PR with credit. On #212: since both PRs use the same flag and #212 counts always, keeping #212's draw code for point 1 and only this PR's point 2 on top, as in your local branch, is the cleaner merge. If the maintainer takes #212, I'll cut this PR down to point 2. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 23:35 UTC · original

Added in 272d9b3, in the shape you described (credit in the commit). pieces_cut_for_hoisted_clamps_charge_the_first_pieces_budget now also cuts the list at a met 64-bit wait (wait_value, slot 0x240, or 0x250 on newer tables) after the spent first piece and the hoisted run. The next run's inline clamp must run its record (hits 1). With state.budget_of = None in cut() commented out it fails with left: 0, right: 1; with it, it passes. RX 6950 XT, release, cargo test -p victory-gpu --lib twice: 114 passed, 1 failed (lists_are_cut_at_waits_that_follow_work, the release-only failure #210 fixes), 4 ignored.

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

**@⁠MamaLeVrai** on GitHub · 2026-11-26 23:35 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/227#issuecomment-7205673670) Added in `272d9b3`, in the shape you described (credit in the commit). `pieces_cut_for_hoisted_clamps_charge_the_first_pieces_budget` now also cuts the list at a met 64-bit wait (`wait_value`, slot 0x240, or 0x250 on newer tables) after the spent first piece and the hoisted run. The next run's inline clamp must run its record (hits 1). With `state.budget_of = None` in `cut()` commented out it fails with `left: 0, right: 1`; with it, it passes. RX 6950 XT, release, `cargo test -p victory-gpu --lib` twice: 114 passed, 1 failed (`lists_are_cut_at_waits_that_follow_work`, the release-only failure #210 fixes), 4 ignored. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 23:37 UTC · original

Thanks @⁠MamaLeVrai, that's the test I had, and failing with that one line out is what matters. Nothing to share separately then.

**@⁠adrianmjim** on GitHub · 2026-11-26 23:37 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/227#issuecomment-7205707087) Thanks @⁠MamaLeVrai, that's the test I had, and failing with that one line out is what matters. Nothing to share separately then.
This pull request can be merged automatically.
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/227/head:github-bot/gh-227'
git switch 'github-bot/gh-227'

Merge

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