GPU: the held-work pump reads each wait's word once, and answers its own blocked question #3245

Open
borosf wants to merge 3 commits from upstream-pr/3247 into main
borosf commented 2026-11-26 14:25:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T14:25:43Z.


The held-work pump read every wait's memory word through ReadProcessMemory on every test, and its caller immediately asked the same question again, which read them all a second time.

The shape of it

queue::pump runs Held::pump, then if held.blocked(&read).is_empty() { return; } — and blocked walks the same queue heads and calls w.holds(read) on the same waits, i.e. one ReadProcessMemory per 4–8 byte word per blocked queue, again. The pump itself runs on every submission, every fence poll, and every 2 ms tick of its timer thread; at a 1.8 s frame that is ~900 pumps.

What changes

  • Held::pump keeps each word's answer for the duration of one pump — cleared whenever work actually runs (that is what changes memory; with no run, only another thread can, and a stale answer costs at most one 2 ms timer tick of latency). Two waits on the same word in one head now cost one read.
  • Pumped gains blocked: bool, which the pump sets when it leaves a head waiting. queue::pump asks that instead of calling Held::blocked, so the second read pass is gone. Held::blocked itself is untouched — account_frame still uses it once per presented frame for the "still held" log line.

Cost removed

Arithmetic, not a title measurement: one kernel read (~1.5 µs) per blocked queue per pump, removed; at 4 blocked queues and ~900 pumps a frame that is ~6 µs/pump, ~5–6 ms per frame, plus the duplicate reads of the same word within a pump. The frame line already prints the pump's own time, so a run with this merged shows the difference directly.

Verification

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings — clean; same with --all-features.
  • cargo test -p victory-gpu --lib --locked --no-fail-fast — 231 passed, 2 failed, both the known Intel baseline failures pristine main also fails (descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views, #1744/#1829).
  • New test hold::tests::a_pump_reads_each_word_once_and_says_if_anything_is_blocked counts the reads through the pump and asserts Pumped::blocked.
  • rustfmt --edition 2024 --check hunk counts against main: hold.rs 11/11, queue.rs 10/10.

Synthetic tests only; no game data.

Part of the fifteen gaps claimed for this sweep on #1633. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5511795065 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3247). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T14:25:43Z. --- The held-work pump read every wait's memory word through `ReadProcessMemory` on every test, and its caller immediately asked the same question again, which read them all a second time. ## The shape of it `queue::pump` runs `Held::pump`, then `if held.blocked(&read).is_empty() { return; }` — and `blocked` walks the same queue heads and calls `w.holds(read)` on the same waits, i.e. one `ReadProcessMemory` per 4–8 byte word per blocked queue, again. The pump itself runs on every submission, every fence poll, and every 2 ms tick of its timer thread; at a 1.8 s frame that is ~900 pumps. ## What changes - `Held::pump` keeps each word's answer for the duration of one pump — cleared whenever work actually runs (that is what changes memory; with no run, only another thread can, and a stale answer costs at most one 2 ms timer tick of latency). Two waits on the same word in one head now cost one read. - `Pumped` gains `blocked: bool`, which the pump sets when it leaves a head waiting. `queue::pump` asks that instead of calling `Held::blocked`, so the second read pass is gone. `Held::blocked` itself is untouched — `account_frame` still uses it once per presented frame for the "still held" log line. ## Cost removed Arithmetic, not a title measurement: one kernel read (~1.5 µs) per blocked queue per pump, removed; at 4 blocked queues and ~900 pumps a frame that is ~6 µs/pump, **~5–6 ms per frame**, plus the duplicate reads of the same word within a pump. The frame line already prints the pump's own time, so a run with this merged shows the difference directly. ## Verification - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` — clean; same with `--all-features`. - `cargo test -p victory-gpu --lib --locked --no-fail-fast` — 231 passed, 2 failed, both the known Intel baseline failures pristine `main` also fails (`descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`, #1744/#1829). - New test `hold::tests::a_pump_reads_each_word_once_and_says_if_anything_is_blocked` counts the reads through the pump and asserts `Pumped::blocked`. - `rustfmt --edition 2024 --check` hunk counts against `main`: `hold.rs` 11/11, `queue.rs` 10/10. Synthetic tests only; no game data. Part of the fifteen gaps claimed for this sweep on #1633. AI-assisted.
Dukestar69 commented 2026-11-26 14:27:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T14:27:41Z.

Review: COMMENTED


Reviewed the diff and ran local verification on Windows 11 x64 (cargo test -p victory-gpu --lib hold:: -- --test-threads=1: 11/11 passed; cargo clippy -p victory-gpu --all-targets -- -D warnings: clean; cargo xtask policy: 191 files ok).

The per-pump read cache (cleared on
un/signal) looks clean, but Pumped::blocked has two behavioral regressions compared to the previous held.blocked(&read).is_empty() check in queue.rs:

  1. Sticky done.blocked across outer-loop passes (false positive): done.blocked = true is set when a Segment wait is unmet, but never reset at the start of the outer loop. If queue A is blocked on pass 1 and then unblocked and drained by queue B on pass 2 (leaving self.queues completely empty), pumped.blocked still returns rue, which unnecessarily starts the 2 ms polling timer.
  2. Item::FenceWait never sets done.blocked (false negative): Previously, held.blocked(&read) returned an entry for any non-empty queue head (including Item::FenceWait). With the new flag, if only a FenceWait remains blocked at the end of pump(), pumped.blocked is alse and the polling timer is not started.

Note that pump() already finishes with self.queues.retain(|(_, items)| !items.is_empty());, so setting done.blocked = !self.queues.is_empty() right after
etain (or using the existing held.is_empty() in queue.rs) is exact, O(1), performs zero memory reads, and avoids both edge cases.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6075815417 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3247#pullrequestreview-6075815417). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T14:27:41Z. **Review:** COMMENTED --- Reviewed the diff and ran local verification on Windows 11 x64 (cargo test -p victory-gpu --lib hold:: -- --test-threads=1: 11/11 passed; cargo clippy -p victory-gpu --all-targets -- -D warnings: clean; cargo xtask policy: 191 files ok). The per-pump read cache (cleared on un/signal) looks clean, but Pumped::blocked has two behavioral regressions compared to the previous held.blocked(&read).is_empty() check in queue.rs: 1. **Sticky done.blocked across outer-loop passes (false positive):** done.blocked = true is set when a Segment wait is unmet, but never reset at the start of the outer loop. If queue A is blocked on pass 1 and then unblocked and drained by queue B on pass 2 (leaving self.queues completely empty), pumped.blocked still returns rue, which unnecessarily starts the 2 ms polling timer. 2. **Item::FenceWait never sets done.blocked (false negative):** Previously, held.blocked(&read) returned an entry for any non-empty queue head (including Item::FenceWait). With the new flag, if only a FenceWait remains blocked at the end of pump(), pumped.blocked is alse and the polling timer is not started. Note that pump() already finishes with self.queues.retain(|(_, items)| !items.is_empty());, so setting done.blocked = !self.queues.is_empty() right after etain (or using the existing held.is_empty() in queue.rs) is exact, O(1), performs zero memory reads, and avoids both edge cases. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
borosf commented 2026-11-26 15:02:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T14:33:29Z.


Fixed at 08d821941ba0c0770459aaa29927d00c652798ed — both edge cases, exactly as you suggested.

done.blocked is no longer set when a segment's wait is found unmet. It is taken once, after self.queues.retain(|(_, items)| !items.is_empty()), as !self.queues.is_empty() — which is precisely what the old held.blocked(&read).is_empty() asked: any queue with anything left, a FenceWait included, and zero memory reads to know it. A queue drained in an earlier pass of the same pump is already gone from self.queues by then, so the flag cannot go stale within one pump.

hold::tests::a_pump_reads_each_word_once_and_says_if_anything_is_blocked now also covers both cases: a queue drained within one pump asserts !p.blocked, and a remaining Item::FenceWait(5, 9) against fence value 0 asserts p.blocked.

Local re-verification on this side (Windows 11, Intel Arc B580): cargo clippy -p victory-gpu --all-targets --locked -- -D warnings and --all-features clean; cargo test -p victory-gpu --lib --locked --no-fail-fast 230 passed, 2 failed — both the known B580 baseline failures pristine main also fails (#1744/#1829); rustfmt --edition 2024 --check hunk count for hold.rs unchanged at 11/11 against main. Synthetic tests only; no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194991383 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3247#issuecomment-7194991383). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T14:33:29Z. --- Fixed at `08d821941ba0c0770459aaa29927d00c652798ed` — both edge cases, exactly as you suggested. `done.blocked` is no longer set when a segment's wait is found unmet. It is taken once, after `self.queues.retain(|(_, items)| !items.is_empty())`, as `!self.queues.is_empty()` — which is precisely what the old `held.blocked(&read).is_empty()` asked: any queue with anything left, a `FenceWait` included, and zero memory reads to know it. A queue drained in an earlier pass of the same pump is already gone from `self.queues` by then, so the flag cannot go stale within one pump. `hold::tests::a_pump_reads_each_word_once_and_says_if_anything_is_blocked` now also covers both cases: a queue drained within one pump asserts `!p.blocked`, and a remaining `Item::FenceWait(5, 9)` against fence value 0 asserts `p.blocked`. Local re-verification on this side (Windows 11, Intel Arc B580): `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` and `--all-features` clean; `cargo test -p victory-gpu --lib --locked --no-fail-fast` 230 passed, 2 failed — both the known B580 baseline failures pristine main also fails (#1744/#1829); `rustfmt --edition 2024 --check` hunk count for hold.rs unchanged at 11/11 against main. Synthetic tests only; no game data.
cloph-dsp commented 2026-11-26 15:02:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T14:42:38Z.


Independent local verification of head 08d8219 on Windows 11, Rust 1.100.0/MSVC:

  • cargo test --locked -p victory-gpu --lib -- hold::tests::a_pump_reads_each_word_once_and_says_if_anything_is_blocked --exact — 1 passed, 0 failed.
  • git diff --check against merge base — clean.

CPU-only synthetic test; worktree-local CARGO_TARGET_DIR. AI-assisted (Hy4 flash). GPU/driver N/A. No game data, assets or DRM material used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195209424 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3247#issuecomment-7195209424). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T14:42:38Z. --- Independent local verification of head `08d8219` on Windows 11, Rust 1.100.0/MSVC: - `cargo test --locked -p victory-gpu --lib -- hold::tests::a_pump_reads_each_word_once_and_says_if_anything_is_blocked --exact` — 1 passed, 0 failed. - `git diff --check` against merge base — clean. CPU-only synthetic test; worktree-local `CARGO_TARGET_DIR`. AI-assisted (Hy4 flash). GPU/driver N/A. No game data, assets or DRM material used.
futurepro62 commented 2026-11-26 22:53:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T22:53:21Z.


NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, since none of them names a GPU run. Tested exact head 08d8219 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: a_pump_reads_each_word_once_and_says_if_anything_is_blocked.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7205071286 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3247#issuecomment-7205071286). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T22:53:21Z. --- NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, since none of them names a GPU run. Tested exact head `08d8219` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `a_pump_reads_each_word_once_and_says_if_anything_is_blocked`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
fuzeofficlal commented 2026-11-27 00:00:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:00:03Z.

Review: APPROVED


Looks good — clean, exact optimization that eliminates redundant wait-word reads during Held::pump and in queue::pump.

Checked crates/victory-gpu/src/hold.rs:140-232 and crates/victory-gpu/src/queue.rs:234-240:

  • Caching reads by (address, bytes) keeps 4-byte and 8-byte waits at the same address distinct, avoids redundant reads across repeated passes/waits, and invalidating the cache on both run (hold.rs:190, 218) and signal (hold.rs:210) ensures causal writes from either path are observed in the next pass of the same pump.
  • Computing done.blocked = !self.queues.is_empty() right after self.queues.retain(|(_, items)| !items.is_empty()) (hold.rs:227-231) is exact — matching !held.blocked(&read).is_empty() for segments, fence waits, unknown comparisons, and valve-released queues without re-reading every wait word in queue.rs.

Verification (08d82194):

  • cargo xtask policy and cargo clippy -p victory-gpu (default and --features diagnostics, --tests -- -D warnings): passed.
  • hold::tests:: (11/11) on both hardware GPU and WARP, and queue::tests:: (5/5) on hardware GPU: passed.
  • Additional probe covering same-address 4-byte vs 8-byte waits, Signal callback mutating a wait word to unblock another queue within the same pump, a shared blocked word across 3 waits on 2 queues (exactly 1 read), force_older_than + pump clearing blocked, and p.blocked == !held.blocked(&read).is_empty() equivalence across all states: passed.
<!-- greyfinch-sync:Marvisak/VIctory:review:6081795159 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3247#pullrequestreview-6081795159). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T00:00:03Z. **Review:** APPROVED --- Looks good — clean, exact optimization that eliminates redundant wait-word reads during `Held::pump` and in `queue::pump`. Checked `crates/victory-gpu/src/hold.rs:140-232` and `crates/victory-gpu/src/queue.rs:234-240`: - Caching reads by `(address, bytes)` keeps 4-byte and 8-byte waits at the same address distinct, avoids redundant reads across repeated passes/waits, and invalidating the cache on both `run` (`hold.rs:190, 218`) and `signal` (`hold.rs:210`) ensures causal writes from either path are observed in the next pass of the same pump. - Computing `done.blocked = !self.queues.is_empty()` right after `self.queues.retain(|(_, items)| !items.is_empty())` (`hold.rs:227-231`) is exact — matching `!held.blocked(&read).is_empty()` for segments, fence waits, unknown comparisons, and valve-released queues without re-reading every wait word in `queue.rs`. Verification (`08d82194`): - `cargo xtask policy` and `cargo clippy -p victory-gpu` (default and `--features diagnostics`, `--tests -- -D warnings`): passed. - `hold::tests::` (11/11) on both hardware GPU and WARP, and `queue::tests::` (5/5) on hardware GPU: passed. - Additional probe covering same-address 4-byte vs 8-byte waits, `Signal` callback mutating a wait word to unblock another queue within the same pump, a shared blocked word across 3 waits on 2 queues (exactly 1 read), `force_older_than` + `pump` clearing `blocked`, and `p.blocked == !held.blocked(&read).is_empty()` equivalence across all states: passed.
borosf commented 2026-11-27 06:38:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T06:38:45Z.


Thank you for running the full suite on the 5070 Ti — an NVIDIA green run is the data point this PR was missing, since the reports before yours were CPU-only or a single crate.

Notes for anyone reading later: the skips you list are all failures on 63bcca4 on that card too, including the victory-shader process dying at heap_direct_texture_reads_mark_their_heap_index (#2571) which would otherwise hide the rest of the crate's results — so 867 passed / 0 failed / 10 ignored with those skips is the right comparison, and a_pump_reads_each_word_once_and_says_if_anything_is_blocked passing is the one this PR adds.

Nothing further needed from my side; the head is still 08d8219 and CI is green on it. Synthetic tests only, no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7211715870 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3247#issuecomment-7211715870). Originally posted by [borosf](https://github.com/borosf) on 2026-11-27T06:38:45Z. --- Thank you for running the full suite on the 5070 Ti — an NVIDIA green run is the data point this PR was missing, since the reports before yours were CPU-only or a single crate. Notes for anyone reading later: the skips you list are all failures on `63bcca4` on that card too, including the `victory-shader` process dying at `heap_direct_texture_reads_mark_their_heap_index` (#2571) which would otherwise hide the rest of the crate's results — so 867 passed / 0 failed / 10 ignored with those skips is the right comparison, and `a_pump_reads_each_word_once_and_says_if_anything_is_blocked` passing is the one this PR adds. Nothing further needed from my side; the head is still `08d8219` and CI is green on it. Synthetic tests only, no game data.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3247:upstream-pr/3247'
git switch 'upstream-pr/3247'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3247'
git switch 'upstream-pr/3247'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3247'
git switch 'upstream-pr/3247'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3247'
git switch 'main'
git merge --squash 'upstream-pr/3247'
git switch 'main'
git merge --ff-only 'upstream-pr/3247'
git switch 'main'
git merge 'upstream-pr/3247'
git push origin 'main'
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!3245
No description provided.