GPU: flush buffered segment piece before evaluating queue memory waits #2609

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/2611 into main
fuzeofficlal commented 2026-11-25 16:46:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T16:46:47Z.


Summary

In crates/victory-gpu/src/hold.rs, Held::pump batches consecutive ready segments on a queue into piece and evaluates the next segment's ValueWaits against w.read before flushing piece.

Because piece has not run yet (including its bottom-of-pipe writes), evaluating waits against pre-piece memory causes two ordering bugs:

  1. If an earlier segment in piece overwrites a word (for example 7 -> 8) and the next segment on the same queue waits for == 7, the wait reads the stale 7 and passes immediately in the same piece instead of blocking.
  2. If an earlier segment in piece writes the value (8) that the next segment waits for (>= 8), the wait reads the stale value, blocks on the first check, and falsely records a wait in Pumped::waited.

Changes

  • crates/victory-gpu/src/hold.rs:
    • In Held::pump, flush piece ((w.run)(*queue, std::mem::take(&mut piece)); done.pieces += 1;) before evaluating a segment's waits when !waits.is_empty() && !piece.is_empty(). Consecutive wait-free segments (waits.is_empty()) continue batching into a single piece.
    • Add unit tests a_wait_for_the_value_overwritten_by_its_queue_stays_held and a_wait_for_its_queues_write_holds_on_the_first_check.

Verification

  • Negative control (before fix): both new unit tests fail (overwritten value passes erroneously; self-written value falsely marks the segment as waited).
  • cargo test -p victory-gpu --lib hold::tests — 12/12 pass.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings and --features diagnostics — pass (0 warnings).
  • cargo xtask policy — pass (184 files ok).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6609262251 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2611). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T16:46:47Z. --- ## Summary In `crates/victory-gpu/src/hold.rs`, `Held::pump` batches consecutive ready segments on a queue into `piece` and evaluates the next segment's `ValueWait`s against `w.read` before flushing `piece`. Because `piece` has not run yet (including its bottom-of-pipe writes), evaluating waits against pre-`piece` memory causes two ordering bugs: 1. If an earlier segment in `piece` overwrites a word (for example `7 -> 8`) and the next segment on the same queue waits for `== 7`, the wait reads the stale `7` and passes immediately in the same piece instead of blocking. 2. If an earlier segment in `piece` writes the value (`8`) that the next segment waits for (`>= 8`), the wait reads the stale value, blocks on the first check, and falsely records a wait in `Pumped::waited`. ## Changes - `crates/victory-gpu/src/hold.rs`: - In `Held::pump`, flush `piece` (`(w.run)(*queue, std::mem::take(&mut piece)); done.pieces += 1;`) before evaluating a segment's `waits` when `!waits.is_empty() && !piece.is_empty()`. Consecutive wait-free segments (`waits.is_empty()`) continue batching into a single piece. - Add unit tests `a_wait_for_the_value_overwritten_by_its_queue_stays_held` and `a_wait_for_its_queues_write_holds_on_the_first_check`. ## Verification - Negative control (before fix): both new unit tests fail (overwritten value passes erroneously; self-written value falsely marks the segment as waited). - `cargo test -p victory-gpu --lib hold::tests` — 12/12 pass. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` and `--features diagnostics` — pass (0 warnings). - `cargo xtask policy` — pass (`184 files ok`).
oni-swr commented 2026-11-25 18:02:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T17:15:49Z.


WARP verification of 922b89b merged cleanly onto origin/main 13f91ca (detached checkout).

Environment: Windows 11. No physical GPU device was created: VICTORY_D3D12_WARP=1, VICTORY_WARP=1, cargo -j 4, separate CARGO_TARGET_DIR.

Commands and results:

  • cargo clippy -j 4 -p victory-gpu --features diagnostics --all-targets: clean.
  • cargo test -j 4 -p victory-gpu --features diagnostics --lib: 200 passed, 0 failed, 1 ignored (origin/main: 198 passed). Both new hold:: tests pass.
  • Negative control: removing the added pre-wait flush makes both new tests fail (10 passed, 2 failed in hold::).

Review notes:

  • Overlap with #2608 (hold.rs pump): textually clean and complementary; together 204 passed, 0 failed, 1 ignored. #2611 also covers wait-bearing segments that follow a segment without a read-back, which #2608 does not.
  • Overlap with #2605: textually clean with this PR. (#2605 conflicts at compile time with #2608's World change, see my #2608 comment.)
  • No bug found. The extra run call only happens when a segment has waits and the buffered piece is non-empty.
  • Pre-existing flake (not from this PR): memory::a_submission_that_missed_leaves_the_copies_at_once failed in roughly 4 of 20 full runs on both origin/main and the merged PRs, and frame::waits_end_on_ticks_and_count_frames failed once on origin/main.

Not tested: physical GPU, or a retail title.

Independent review and WARP verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or retail data were used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169245833 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2611#issuecomment-7169245833). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T17:15:49Z. --- **WARP verification** of `922b89b` merged cleanly onto `origin/main` `13f91ca` (detached checkout). Environment: Windows 11. No physical GPU device was created: `VICTORY_D3D12_WARP=1`, `VICTORY_WARP=1`, `cargo -j 4`, separate `CARGO_TARGET_DIR`. Commands and results: - `cargo clippy -j 4 -p victory-gpu --features diagnostics --all-targets`: clean. - `cargo test -j 4 -p victory-gpu --features diagnostics --lib`: **200 passed, 0 failed, 1 ignored** (`origin/main`: 198 passed). Both new `hold::` tests pass. - Negative control: removing the added pre-wait flush makes both new tests fail (10 passed, 2 failed in `hold::`). Review notes: - Overlap with #2608 (`hold.rs` pump): textually clean and complementary; together 204 passed, 0 failed, 1 ignored. #2611 also covers wait-bearing segments that follow a segment without a read-back, which #2608 does not. - Overlap with #2605: textually clean with this PR. (#2605 conflicts at compile time with #2608's `World` change, see my #2608 comment.) - No bug found. The extra `run` call only happens when a segment has waits and the buffered piece is non-empty. - Pre-existing flake (not from this PR): `memory::a_submission_that_missed_leaves_the_copies_at_once` failed in roughly 4 of 20 full runs on both `origin/main` and the merged PRs, and `frame::waits_end_on_ticks_and_count_frames` failed once on `origin/main`. Not tested: physical GPU, or a retail title. _Independent review and WARP verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or retail data were used._
kotekompotek commented 2026-11-25 18:02:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:50:58Z.


Reviewed: running the buffered piece before evaluating the next segment's waits is correct — a queue's own earlier writes must be visible to its later waits (both tests pin the two sides: wait-for-own-write passes on first check, wait-for-overwritten-value stays held). Complements #2608 (post-submission writes) and #2605 (unreadable memory). CI green.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170085493 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2611#issuecomment-7170085493). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T17:50:58Z. --- Reviewed: running the buffered piece before evaluating the next segment's waits is correct — a queue's own earlier writes must be visible to its later waits (both tests pin the two sides: wait-for-own-write passes on first check, wait-for-overwritten-value stays held). Complements #2608 (post-submission writes) and #2605 (unreadable memory). CI green.
Machad3x commented 2026-11-25 19:06:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Machad3x on 2026-11-25T18:26:37Z.


Setup: RTX 3080 Ti (driver 621.24), Windows 11, a local stack of open PRs merged with main 67e8ae1.

Applied cleanly on that stack, together with #2601, #2598, #2576, #2626. One 10-minute game run reached gameplay with no device removal. These five PRs were not tested one by one, so nothing in that run is attributed to this PR alone.

Written with Claude Code; tested locally.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170914088 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2611#issuecomment-7170914088). Originally posted by [Machad3x](https://github.com/Machad3x) on 2026-11-25T18:26:37Z. --- Setup: RTX 3080 Ti (driver 621.24), Windows 11, a local stack of open PRs merged with main 67e8ae1. Applied cleanly on that stack, together with #2601, #2598, #2576, #2626. One 10-minute game run reached gameplay with no device removal. These five PRs were not tested one by one, so nothing in that run is attributed to this PR alone. Written with Claude Code; tested locally.
upstream-sync closed this pull request 2026-11-26 00:02:00 +00:00
Marvisak commented 2026-11-26 00:03:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:21:26Z.


Automated triage for the maintainers.

The change in Held::pump (crates/victory-gpu/src/hold.rs) runs the buffered piece before evaluating any segment that has waits, so a wait sees the memory its own queue's earlier segments wrote. The code does what it says and the two tests cover it, but it changes queue ordering behaviour without stated evidence: on hardware, a memory wait after a bottom-of-pipe write on the same queue is not automatically ordered after that write lands, so whether the wait in a_wait_for_the_value_overwritten_by_its_queue_stays_held should block is exactly what needs a reference (public RDNA2/PM4 documentation, D3D12 queue-ordering docs, or the title's own use that depends on it). It also has a cost: every wait-bearing segment that follows buffered work now forces a separate run-to-completion submission where before the segments were batched, and the second test only changes the waited diagnostic. Please add the evidence and say which title pattern it fixes; a narrower flush (only when a wait would otherwise pass) would also reduce the extra submissions. CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177449561 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2611#issuecomment-7177449561). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:21:26Z. --- <!-- victory-triage v1 head=922b89bee02c64a7378145be2168e5e05c242b6b verdict=needs-work at=2026-11-25T23:21:17Z --> Automated triage for the maintainers. The change in `Held::pump` (crates/victory-gpu/src/hold.rs) runs the buffered piece before evaluating any segment that has waits, so a wait sees the memory its own queue's earlier segments wrote. The code does what it says and the two tests cover it, but it changes queue ordering behaviour without stated evidence: on hardware, a memory wait after a bottom-of-pipe write on the same queue is not automatically ordered after that write lands, so whether the wait in `a_wait_for_the_value_overwritten_by_its_queue_stays_held` should block is exactly what needs a reference (public RDNA2/PM4 documentation, D3D12 queue-ordering docs, or the title's own use that depends on it). It also has a cost: every wait-bearing segment that follows buffered work now forces a separate run-to-completion submission where before the segments were batched, and the second test only changes the `waited` diagnostic. Please add the evidence and say which title pattern it fixes; a narrower flush (only when a wait would otherwise pass) would also reduce the extra submissions. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 00:03:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:24:38Z.


Good point on both the hardware EOP-write vs CP-wait ordering (a bottom-of-pipe RELEASE_MEM write on the same queue isn't automatically ordered ahead of a subsequent WAIT_REG_MEM) and the extra submission cost.

Since there's no confirmed title pattern depending on blocking an already-satisfied wait behind an unsubmitted same-queue segment, and Held::pump already flushes piece and re-checks when a wait isn't yet satisfied, I'll close this rather than adding unnecessary submission splits. Thanks for the review!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177521527 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2611#issuecomment-7177521527). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:24:38Z. --- Good point on both the hardware EOP-write vs CP-wait ordering (a bottom-of-pipe `RELEASE_MEM` write on the same queue isn't automatically ordered ahead of a subsequent `WAIT_REG_MEM`) and the extra submission cost. Since there's no confirmed title pattern depending on blocking an already-satisfied wait behind an unsubmitted same-queue segment, and `Held::pump` already flushes `piece` and re-checks when a wait isn't yet satisfied, I'll close this rather than adding unnecessary submission splits. Thanks for the review!

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
Marvisak/VIctory!2609
No description provided.