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

Closed
github-bot wants to merge 1 commit from gh-pr/2611/head into gh-pr/2611/base
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 16:46 UTC · original
fuzeofficlal:fix/gpu-hold-flush-piece-before-wait → main · +41 −0 · 1 files · 1 commits · closed without merging

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).
**@⁠fuzeofficlal** on GitHub · 2026-11-25 16:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2611) `fuzeofficlal:fix/gpu-hold-flush-piece-before-wait` → `main` · +41 −0 · 1 files · 1 commits · closed without merging ## 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`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:17 +00:00
github-bot closed this pull request 2026-11-26 05:10:17 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 17:15 UTC · original

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.

**@⁠oni-swr** on GitHub · 2026-11-25 17:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2611#issuecomment-7169245833) **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._
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:50 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2611#issuecomment-7170085493) 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.
Author
Owner

@⁠Machad3x on GitHub · 2026-11-25 18:26 UTC · original

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.

**@⁠Machad3x** on GitHub · 2026-11-25 18:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2611#issuecomment-7170914088) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:21 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 23:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2611#issuecomment-7177449561) <!-- 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)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 23:24 UTC · original

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!

**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2611#issuecomment-7177521527) 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

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!2611
No description provided.