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

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

@⁠borosf on GitHub · 2026-11-26 14:25 UTC · original
borosf:vibe/pump-reads-once-842ca5 → main · +97 −7 · 2 files · 2 commits · open

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.

**@⁠borosf** on GitHub · 2026-11-26 14:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/3247) `borosf:vibe/pump-reads-once-842ca5` → `main` · +97 −7 · 2 files · 2 commits · open 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.
A pump tested every queue's head, and the caller right after asked
`Held::blocked`, which walked the same heads and read the same memory words
again through `ReadProcessMemory` — one kernel transition per 4-8 byte
word, per blocked queue, per pump. The pump runs on every submission, every
fence poll and every 2 ms tick of its timer, so a frame polls it ~900 times.

`Held::pump` now keeps the answers for the duration of one pump (dropped
whenever work runs, since that is what changes them; without a run only
another thread can, and a stale answer costs at most one timer tick), and
reports `Pumped::blocked` itself. `queue::pump` asks that instead of reading
every wait again. Two waits on one word in one head also cost one read now
instead of two.

Arithmetic, not a title measurement: at 4 blocked queues and ~1.5 µs per
read, the removed pass is ~6 µs a pump, ~5-6 ms over a frame's ~900 pumps;
the per-word cache removes the rest of the duplicate reads, whose count the
frame line's `pump` time already reports.

Verification: `cargo clippy -p victory-gpu --all-targets --locked -- -D
warnings` and `--all-features` both clean; `cargo test -p victory-gpu --lib
--locked --no-fail-fast` 231 passed, 2 failed — both the known Intel baseline
failures pristine main also fails (#1744/#1829). New test
`hold::tests::a_pump_reads_each_word_once_and_says_if_anything_is_blocked`
counts the reads. `rustfmt --edition 2024 --check` hunks against main:
hold.rs 11/11, queue.rs 10/10.

Synthetic tests only; no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:27:22 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 14:27 UTC · original · reviewed

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).

**@⁠Dukestar69** on GitHub · 2026-11-26 14:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3247#pullrequestreview-6075815417) · **reviewed** 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).
Reviewer found two edge cases in setting `done.blocked` when a segment's
wait was unmet: it stayed true if that queue drained in a later pass of the
same pump (timer started for nothing), and a lone `Item::FenceWait` never
set it (timer not started while work was held).

Both go away by taking the answer after `self.queues.retain(...)`, which is
exactly what the old `held.blocked(&read).is_empty()` asked: any queue with
anything left, fence wait included, and nothing read to know it.

The test now covers both cases: a queue drained within one pump reports
nothing held, and a remaining fence wait reports held.

Synthetic tests only; no game data.
Author
Owner

@⁠borosf on GitHub · 2026-11-26 14:33 UTC · original

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.

**@⁠borosf** on GitHub · 2026-11-26 14:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/3247#issuecomment-7194991383) 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.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 14:42 UTC · original

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.

**@⁠cloph-dsp** on GitHub · 2026-11-26 14:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/3247#issuecomment-7195209424) 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.
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/3247/head:github-bot/gh-3247'
git switch 'github-bot/gh-3247'

Merge

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