GPU: flush queued segments before evaluating memory and fence waits #3141

Open
github-bot wants to merge 1 commit from github-bot/gh-3141 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 09:57 UTC · original
fuzeofficlal:fix/gpu-hold-flush-before-wait → main · +183 −0 · 2 files · 1 commits · open

Problem

In crates/victory-gpu/src/hold.rs, Held::pump accumulates consecutive ready segments on a queue into piece and flushes piece via (w.run) before executing Item::Signal, as its comment notes (A Signal or Wait keeps its place: the piece before it runs first). However, neither Item::Segment (with non-empty ValueWaits) nor Item::FenceWait flushed piece before testing their wait condition.

Because an earlier segment on the same queue can modify the waited memory (via Write32/64BitValueBottomOfPipeX, shader writebacks, or direct writes to fence::gpu_address), evaluating waits against pre-segment memory causes two ordering bugs:

  1. Missed wait / synchronization bypass: when a command list resets a previously-set flag (e.g. Write64BitValueBottomOfPipeX(flag, 0)), then waits for another queue to set it back (Wait64BitValueX(flag == 1)), list::wait splits the list into two segments. Held::pump queues segment 0 in piece and immediately checks segment 1's wait against stale memory (flag == 1), erroneously passes, and submits both segments together before the peer queue runs. The same happens if a segment rewrites a fence's memory before an Item::FenceWait.
  2. Spurious wait accounting: when segment 0 writes the value that segment 1 waits on, segment 1 initially reads the stale value, marks itself blocked (fresh = false), and records a false stall in Pumped::waited.

Fix

Flush any pending piece on the current queue before evaluating non-empty ValueWaits on Item::Segment and before evaluating Item::FenceWait. Consecutive wait-free segments (waits.is_empty()) are unaffected and continue to batch into a single host submission.

Verification

Added four regression tests (all four confirmed failing on main 63bcca43 before the fix and passing after):

  • hold::tests::a_wait_runs_the_work_before_it_first
  • hold::tests::a_wait_for_an_earlier_segment_on_the_same_queue_does_not_stall
  • hold::tests::a_fence_wait_runs_the_work_before_it_first
  • queue::tests::in_list_wait_sees_bottom_of_pipe_writes_before_it (end-to-end guest command list using Write64BitValueBottomOfPipeX + Wait64BitValueX + ExecuteCommandLists, verified on both hardware D3D12 and VICTORY_D3D12_WARP=1)

Full checks passed:

  • hold::tests (13/13), queue::tests (6/6), and resource::tests::a_list_waiting_for_another_queues_write_reads_what_it_wrote on both native D3D12 and VICTORY_D3D12_WARP=1
  • cargo clippy --workspace --all-targets --locked -- -D warnings and --all-features (0 warnings)
  • rustfmt --edition 2024 --check (0 diffs on all modified/added lines)
  • cargo test -p xtask --locked policy::tests::repository_passes_policy (asset policy: 191 files ok)
**@⁠fuzeofficlal** on GitHub · 2026-11-26 09:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/3141) `fuzeofficlal:fix/gpu-hold-flush-before-wait` → `main` · +183 −0 · 2 files · 1 commits · open ### Problem In `crates/victory-gpu/src/hold.rs`, `Held::pump` accumulates consecutive ready segments on a queue into `piece` and flushes `piece` via `(w.run)` before executing `Item::Signal`, as its comment notes (`A Signal or Wait keeps its place: the piece before it runs first`). However, neither `Item::Segment` (with non-empty `ValueWait`s) nor `Item::FenceWait` flushed `piece` before testing their wait condition. Because an earlier segment on the same queue can modify the waited memory (via `Write32/64BitValueBottomOfPipeX`, shader writebacks, or direct writes to `fence::gpu_address`), evaluating waits against pre-segment memory causes two ordering bugs: 1. **Missed wait / synchronization bypass**: when a command list resets a previously-set flag (e.g. `Write64BitValueBottomOfPipeX(flag, 0)`), then waits for another queue to set it back (`Wait64BitValueX(flag == 1)`), `list::wait` splits the list into two segments. `Held::pump` queues segment 0 in `piece` and immediately checks segment 1's wait against stale memory (`flag == 1`), erroneously passes, and submits both segments together before the peer queue runs. The same happens if a segment rewrites a fence's memory before an `Item::FenceWait`. 2. **Spurious wait accounting**: when segment 0 writes the value that segment 1 waits on, segment 1 initially reads the stale value, marks itself blocked (`fresh = false`), and records a false stall in `Pumped::waited`. ### Fix Flush any pending `piece` on the current queue before evaluating non-empty `ValueWait`s on `Item::Segment` and before evaluating `Item::FenceWait`. Consecutive wait-free segments (`waits.is_empty()`) are unaffected and continue to batch into a single host submission. ### Verification Added four regression tests (all four confirmed failing on `main` `63bcca43` before the fix and passing after): - `hold::tests::a_wait_runs_the_work_before_it_first` - `hold::tests::a_wait_for_an_earlier_segment_on_the_same_queue_does_not_stall` - `hold::tests::a_fence_wait_runs_the_work_before_it_first` - `queue::tests::in_list_wait_sees_bottom_of_pipe_writes_before_it` (end-to-end guest command list using `Write64BitValueBottomOfPipeX` + `Wait64BitValueX` + `ExecuteCommandLists`, verified on both hardware D3D12 and `VICTORY_D3D12_WARP=1`) Full checks passed: - `hold::tests` (13/13), `queue::tests` (6/6), and `resource::tests::a_list_waiting_for_another_queues_write_reads_what_it_wrote` on both native D3D12 and `VICTORY_D3D12_WARP=1` - `cargo clippy --workspace --all-targets --locked -- -D warnings` and `--all-features` (0 warnings) - `rustfmt --edition 2024 --check` (0 diffs on all modified/added lines) - `cargo test -p xtask --locked policy::tests::repository_passes_policy` (`asset policy: 191 files ok`)
In Held::pump, Item::Signal flushed the accumulated piece on the current queue before running, while Item::Segment (with non-empty ValueWaits) and Item::FenceWait evaluated their wait conditions while earlier segments on the same queue were still unexecuted in piece.

Because an earlier segment on the same queue can modify the waited memory (via Write32/64BitValueBottomOfPipeX, GPU writebacks, or direct writes to fence::gpu_address), evaluating a wait against stale pre-segment memory caused two bugs:
- A wait after a segment that clears or rewrites a previously satisfied flag read the stale value, erroneously passed, and batched the waiting segment into the same host submission instead of holding it until a peer queue satisfied it.
- A wait satisfied by an earlier segment on the same queue initially read the stale value, falsely marked itself blocked, and recorded a spurious wait entry.

Flush any pending piece before testing non-empty ValueWaits on Item::Segment and before testing Item::FenceWait. Consecutive wait-free segments continue to batch into a single host submission.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:08:24 +00:00
Author
Owner

@⁠smaxxey on GitHub · 2026-11-26 10:13 UTC · original

Ran this on an RTX 4060 Laptop GPU (Ada, 8 GB, driver 32.0.16.1742), Windows 11 26300, Rust 1.98.1. No game files. Head 469d7a6 merged locally onto main 63bcca4.

  • The four new tests pass, cargo test -p victory-gpu --lib --locked -- --test-threads=1: the three hold::tests cases and queue::tests::in_list_wait_sees_bottom_of_pipe_writes_before_it on the hardware device.
  • cargo test -p victory-gpu --lib --locked: 233 passed, 2 failed, same as main 63bcca4 on this card: only the two NVIDIA failures of #1835 (descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views), nothing new.

Tested with Claude Code's help.

**@⁠smaxxey** on GitHub · 2026-11-26 10:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/3141#issuecomment-7189070625) Ran this on an **RTX 4060 Laptop GPU** (Ada, 8 GB, driver 32.0.16.1742), Windows 11 26300, Rust 1.98.1. No game files. Head `469d7a6` merged locally onto `main` 63bcca4. - The four new tests pass, `cargo test -p victory-gpu --lib --locked -- --test-threads=1`: the three `hold::tests` cases and `queue::tests::in_list_wait_sees_bottom_of_pipe_writes_before_it` on the hardware device. - `cargo test -p victory-gpu --lib --locked`: 233 passed, 2 failed, same as `main` 63bcca4 on this card: only the two NVIDIA failures of #1835 (`descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`), nothing new. Tested with Claude Code's help.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 12:11 UTC · original · approved these changes

Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib queue:: -- --test-threads=1: 6/6 passed (including in_list_wait_sees_bottom_of_pipe_writes_before_it).
  • cargo test -p victory-gpu --lib hold:: -- --test-threads=1: passed.
  • cargo test -p victory-gpu --lib fence:: -- --test-threads=1: 2/2 passed; draw::: 20/20 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly flushes queued segments before evaluating in-list memory and fence waits.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 12:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/3141#pullrequestreview-6073917500) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib queue:: -- --test-threads=1`: 6/6 passed (including `in_list_wait_sees_bottom_of_pipe_writes_before_it`). - `cargo test -p victory-gpu --lib hold:: -- --test-threads=1`: passed. - `cargo test -p victory-gpu --lib fence:: -- --test-threads=1`: 2/2 passed; `draw::`: 20/20 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly flushes queued segments before evaluating in-list memory and fence waits. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/3141/head:github-bot/gh-3141'
git switch 'github-bot/gh-3141'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3141'
git switch 'github-bot/gh-3141'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3141'
git switch 'github-bot/gh-3141'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3141'
git switch 'main'
git merge --squash 'github-bot/gh-3141'
git switch 'main'
git merge --ff-only 'github-bot/gh-3141'
git switch 'main'
git merge 'github-bot/gh-3141'
git push origin 'main'
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!3141
No description provided.