GPU: waits on memory that cannot be read are counted apart (#2604) #2605

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

@⁠BastienRodz on GitHub · 2026-11-25 16:41 UTC · original
BastienRodz:gpu/unreadable-wait-holds-queue-pr → main · +50 −6 · 2 files · 1 commits · open

What's wrong

ValueWait::holds (9cc37c5) returns None both for a comparison we do not know and for memory that cannot be read. Its doc comment says the first is "taken as holding" and the second "taken as not holding". Held::pump can't tell the two apart: it counts every None as an unknown comparison and lets the work run. So a wait on memory that isn't readable yet runs at once and is reported as an unknown comparison. Nobody can see whether titles make such waits, or whether that memory becomes readable later.

What the fix does

This keeps main's behaviour, as the triage suggested: such work still runs at once. The change makes the case visible:

  • Held::pump counts waits on unreadable memory apart, as Pumped::unreadable. An ALWAYS wait never reads its memory and is not counted.
  • queue.rs's Account sums them per frame. The frame's warning reports unreadable next to forced, unknown and mappings, and a frame with only such waits is no longer skipped.
  • The doc comment on holds now says what the code does.

Holding the work back until the memory reads, the earlier version of this PR, can follow once a title run shows such waits happen and their memory becomes readable.

Tests

New hold::tests::unreadable_waits_are_counted_apart_and_do_not_hold_work:

  • a wait on unreadable memory runs and counts unreadable 1 and unknown 0;
  • an ALWAYS wait on the same memory runs and is not counted.

hold::tests (11), queue::tests (5) and fence::tests (2) pass under Wine 10 (they need no device), and cargo clippy --workspace --all-targets --locked -- -D warnings is clean.

Not tested

No title run. The counter is what such a run would report.

Fixes #2604

AI-assisted (Claude Code). No game data used.

🤖 Generated with Claude Code

**@⁠BastienRodz** on GitHub · 2026-11-25 16:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605) `BastienRodz:gpu/unreadable-wait-holds-queue-pr` → `main` · +50 −6 · 2 files · 1 commits · open ### What's wrong `ValueWait::holds` (9cc37c5) returns `None` both for a comparison we do not know and for memory that cannot be read. Its doc comment says the first is "taken as holding" and the second "taken as not holding". `Held::pump` can't tell the two apart: it counts every `None` as an unknown comparison and lets the work run. So a wait on memory that isn't readable yet runs at once and is reported as an unknown comparison. Nobody can see whether titles make such waits, or whether that memory becomes readable later. ### What the fix does This keeps `main`'s behaviour, as the triage suggested: such work still runs at once. The change makes the case visible: - `Held::pump` counts waits on unreadable memory apart, as `Pumped::unreadable`. An `ALWAYS` wait never reads its memory and is not counted. - `queue.rs`'s `Account` sums them per frame. The frame's warning reports `unreadable` next to `forced`, `unknown` and `mappings`, and a frame with only such waits is no longer skipped. - The doc comment on `holds` now says what the code does. Holding the work back until the memory reads, the earlier version of this PR, can follow once a title run shows such waits happen and their memory becomes readable. ### Tests New `hold::tests::unreadable_waits_are_counted_apart_and_do_not_hold_work`: - a wait on unreadable memory runs and counts `unreadable` 1 and `unknown` 0; - an `ALWAYS` wait on the same memory runs and is not counted. `hold::tests` (11), `queue::tests` (5) and `fence::tests` (2) pass under Wine 10 (they need no device), and `cargo clippy --workspace --all-targets --locked -- -D warnings` is clean. ### Not tested No title run. The counter is what such a run would report. Fixes #2604 AI-assisted (Claude Code). No game data used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`ValueWait::holds` returns `None` both for a comparison we do not know and
for memory that cannot be read, and `Held::pump` counted every `None` as
an unknown comparison, while the doc comment said unreadable memory was
"taken as not holding" (#2604). Whether titles make waits on memory not
yet readable, and whether it becomes readable later, could not be seen.

The pump now counts them apart (`Pumped::unreadable`, summed in the
frame's `Account` and named in its warning next to `forced`) and still
lets the work run, as `main` does; an `ALWAYS` wait never reads and is
not counted. The doc comment says so. Holding such work back can follow
once runs show the memory becomes readable.

Test: `unreadable_waits_are_counted_apart_and_do_not_hold_work`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:09 +00:00
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 16:44 UTC · original

One edge case in ValueWait::holds: if the address is unreadable, this patch returns Some(false) before reaching the ALWAYS comparison. The base returns None and the pump releases the segment. With the patch, an ALWAYS wait can hold the queue until the address becomes readable or the 10-second safety valve fires.

Should ALWAYS return Some(true) before the memory read? If that matches the intended behavior, adding w(ALWAYS, 5).holds(&|_, _| None) == Some(true) alongside the unreadable EQUAL case would cover both paths.

Static review only.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-25 16:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605#issuecomment-7168465628) One edge case in `ValueWait::holds`: if the address is unreadable, this patch returns `Some(false)` before reaching the `ALWAYS` comparison. The base returns `None` and the pump releases the segment. With the patch, an `ALWAYS` wait can hold the queue until the address becomes readable or the 10-second safety valve fires. Should `ALWAYS` return `Some(true)` before the memory read? If that matches the intended behavior, adding `w(ALWAYS, 5).holds(&|_, _| None) == Some(true)` alongside the unreadable `EQUAL` case would cover both paths. Static review only. *AI-assisted with Codex.*
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 16:47 UTC · original

Good catch @⁠DrDarkDK, thanks. ALWAYS doesn't read the memory, so it now holds whether or not the address is readable: holds returns Some(self.comparison == ALWAYS) when the read fails, and the unit test checks w(ALWAYS, 5) with unreadable memory next to the EQUAL case. hold::tests 11/11.

**@⁠BastienRodz** on GitHub · 2026-11-25 16:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605#issuecomment-7168529182) Good catch @⁠DrDarkDK, thanks. `ALWAYS` doesn't read the memory, so it now holds whether or not the address is readable: `holds` returns `Some(self.comparison == ALWAYS)` when the read fails, and the unit test checks `w(ALWAYS, 5)` with unreadable memory next to the `EQUAL` case. `hold::tests` 11/11.
Author
Owner

@⁠welisonzika14-jpg on GitHub · 2026-11-25 17:49 UTC · original

First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head 5de820a merged onto main 13f91ca, cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast -- --skip heap_direct_texture_reads_mark_their_heap_index. That one test is skipped because it kills the process on hardware on the current main (#2571, fixed by #2596/#2587).

The PR's new test(s) pass on this card: hold::tests::an_unreadable_wait_holds_its_queue_until_readable. The rest is the same as main on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in victory-gpu, 3 in victory-shader), nothing new.

One run, unit tests only, title not run.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

**@⁠welisonzika14-jpg** on GitHub · 2026-11-25 17:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605#issuecomment-7170051779) First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head `5de820a` merged onto `main` `13f91ca`, `cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast -- --skip heap_direct_texture_reads_mark_their_heap_index`. That one test is skipped because it kills the process on hardware on the current `main` (#2571, fixed by #2596/#2587). The PR's new test(s) pass on this card: `hold::tests::an_unreadable_wait_holds_its_queue_until_readable`. The rest is the same as `main` on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in `victory-gpu`, 3 in `victory-shader`), nothing new. One run, unit tests only, title not run. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Author
Owner

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

Reviewed: returning Some(comparison == ALWAYS) on unreadable memory is the right split — a queue wait must not pass on unverifiable data, while ALWAYS never reads. The companion test (held until readable, then proceeds) pins the behavior. Note this overlaps the same holds() as #2608/#2611 — all three are complementary pieces of the same wait-semantics fix; they merge cleanly on different hunks.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605#issuecomment-7170084131) Reviewed: returning `Some(comparison == ALWAYS)` on unreadable memory is the right split — a queue wait must not pass on unverifiable data, while `ALWAYS` never reads. The companion test (held until readable, then proceeds) pins the behavior. Note this overlaps the same `holds()` as #2608/#2611 — all three are complementary pieces of the same wait-semantics fix; they merge cleanly on different hunks.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 18:01 UTC · original

Tested 5de820a8 merged cleanly onto main (13f91ca) on Windows 11 with NVIDIA GeForce RTX 5090 (32.0.16.1656) and D3D12 WARP (--features diagnostics):

  • cargo test -p victory-gpu --lib hold::tests: 11 passed, 0 failed (default and RTX 5090 --features diagnostics)
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics -- --test-threads=1: 199 passed, 0 failed, 1 ignored
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics): clean (0 warnings)

Checked ValueWait::holds with unreadable memory (ALWAYS returns Some(true), all other predicates return Some(false) so Held::blocked keeps the queue held for the 2 ms timer / safety valve) — looks clean and ready.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605#issuecomment-7170337029) Tested `5de820a8` merged cleanly onto `main` (`13f91ca`) on Windows 11 with **NVIDIA GeForce RTX 5090** (`32.0.16.1656`) and **D3D12 WARP** (`--features diagnostics`): - `cargo test -p victory-gpu --lib hold::tests`: **11 passed, 0 failed** (default and RTX 5090 `--features diagnostics`) - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics -- --test-threads=1`: **199 passed, 0 failed, 1 ignored** - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`): clean (0 warnings) Checked `ValueWait::holds` with unreadable memory (`ALWAYS` returns `Some(true)`, all other predicates return `Some(false)` so `Held::blocked` keeps the queue held for the 2 ms timer / safety valve) — looks clean and ready.
Author
Owner

@⁠Kajanos on GitHub · 2026-11-25 19:05 UTC · original

One risk nobody has raised yet: read_value (queue.rs) reads the address directly as a CPU pointer. A wait on an address that never becomes readable (GPU-only memory, or an address we do not emulate) used to run at once and was counted as unknown. With this change, each such wait holds its queue for the full VALVE (10 s) until the safety valve forces it, logging "held work runs without its waits". If the title does this in the world, it turns slightly misordered work into multi-second stalls.

Before merging, it would help to check whether real runs show a non-zero "unknown" count in the frame summary. If they do, count unreadable addresses separately first (keep releasing, report them apart from unknown comparisons) to see whether they become readable later or never do.

AI-assisted (Claude Code). Reasoning only; tests not run (no Windows host).

**@⁠Kajanos** on GitHub · 2026-11-25 19:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605#issuecomment-7171811551) One risk nobody has raised yet: `read_value` (queue.rs) reads the address directly as a CPU pointer. A wait on an address that never becomes readable (GPU-only memory, or an address we do not emulate) used to run at once and was counted as unknown. With this change, each such wait holds its queue for the full `VALVE` (10 s) until the safety valve forces it, logging "held work runs without its waits". If the title does this in the world, it turns slightly misordered work into multi-second stalls. Before merging, it would help to check whether real runs show a non-zero "unknown" count in the frame summary. If they do, count unreadable addresses separately first (keep releasing, report them apart from unknown comparisons) to see whether they become readable later or never do. AI-assisted (Claude Code). Reasoning only; tests not run (no Windows host).
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 19:06 UTC · original

That's a fair risk to raise, and you're right that the PR has no in-game data. Its "Not tested" section says how often this happens isn't measured.

Two points that narrow it.

  • What "unreadable" means here. read_value goes through host::read_into, which is ReadProcessMemory on our own process. It fails only when the page isn't mapped readable at that moment. As far as I can see, every address a title passes as a wait's GPU address is title memory in this process: the console's memory is unified, and resources here live at title addresses. So "GPU-only memory" has no separate address space in this code path. An address that never becomes readable is one the title never commits. On the console, such a wait could not be satisfied either, and the title's own fence would hang.
  • What it costs if it does happen. The head is held until the valve (VALVE, 10 s) and then runs with the "held work runs without its waits" warning. On main it runs at once and is counted as unknown, a count that also includes unknown comparisons. So the two outcomes are a stall that is logged, or ordering that may be wrong and is lumped in with unknown comparisons. Which one is better depends on whether real runs hit this at all, and nobody has measured that yet.

I agree that counting unreadable waits on their own would settle it. It would be a separate counter in queue.rs's Account, next to unknown. I'd rather keep this PR to the hold.rs fix that matches the function's doc comment. If the maintainer wants that number before merging, I'll add it here or as a follow-up. Anyone running the title with this PR: a non-zero forced count in the frame summary, together with the "held work runs without its waits" warning, would be the signal.

**@⁠BastienRodz** on GitHub · 2026-11-25 19:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605#issuecomment-7171832202) That's a fair risk to raise, and you're right that the PR has no in-game data. Its "Not tested" section says how often this happens isn't measured. Two points that narrow it. - **What "unreadable" means here.** `read_value` goes through `host::read_into`, which is `ReadProcessMemory` on our own process. It fails only when the page isn't mapped readable at that moment. As far as I can see, every address a title passes as a wait's GPU address is title memory in this process: the console's memory is unified, and resources here live at title addresses. So "GPU-only memory" has no separate address space in this code path. An address that never becomes readable is one the title never commits. On the console, such a wait could not be satisfied either, and the title's own fence would hang. - **What it costs if it does happen.** The head is held until the valve (`VALVE`, 10 s) and then runs with the "held work runs without its waits" warning. On main it runs at once and is counted as `unknown`, a count that also includes unknown comparisons. So the two outcomes are a stall that is logged, or ordering that may be wrong and is lumped in with unknown comparisons. Which one is better depends on whether real runs hit this at all, and nobody has measured that yet. I agree that counting unreadable waits on their own would settle it. It would be a separate counter in `queue.rs`'s `Account`, next to `unknown`. I'd rather keep this PR to the `hold.rs` fix that matches the function's doc comment. If the maintainer wants that number before merging, I'll add it here or as a follow-up. Anyone running the title with this PR: a non-zero `forced` count in the frame summary, together with the "held work runs without its waits" warning, would be the signal.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:19 UTC · original · edited 2026-11-26 03:21 UTC

Automated triage for the maintainers.

Thanks for splitting it. 74ccd68 now does what the last triage asked for: behaviour stays as on main, and the case becomes visible.

  • Held::pump (crates/victory-gpu/src/hold.rs) still runs waits whose memory cannot be read. It now counts them as Pumped::unreadable instead of unknown.
  • ALWAYS waits are left uncounted. That arm can be reached, because holds reads memory before it checks the comparison.
  • queue.rs Account adds the count to the frame warning.
  • The doc comment on holds now matches what the code does.
  • The new test covers the count and the release.

Holding such work until the memory can be read is left for a follow-up, once a title run shows non-zero unreadable counts.

Verdict: merge candidate (a recommendation to look, not an approval). CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605#issuecomment-7177411395) · edited 2026-11-26 03:21 UTC <!-- victory-triage v1 head=74ccd687885227dc3ab76915306ab164df7f01e1 verdict=merge-candidate at=2026-11-26T03:21:05Z --> Automated triage for the maintainers. Thanks for splitting it. `74ccd68` now does what the last triage asked for: behaviour stays as on `main`, and the case becomes visible. - `Held::pump` (`crates/victory-gpu/src/hold.rs`) still runs waits whose memory cannot be read. It now counts them as `Pumped::unreadable` instead of `unknown`. - `ALWAYS` waits are left uncounted. That arm can be reached, because `holds` reads memory before it checks the comparison. - `queue.rs` `Account` adds the count to the frame warning. - The doc comment on `holds` now matches what the code does. - The new test covers the count and the release. Holding such work until the memory can be read is left for a follow-up, once a title run shows non-zero `unreadable` counts. **Verdict: merge candidate** (a recommendation to look, not an approval). CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

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

Rebased on main (842b0cb) and added the separate count the triage asks for, as c5d0230:

  • hold::Pumped gets unreadable: tests of waits whose memory could not be read. It is counted only when a wait holds, so the common path reads nothing more.
  • queue.rs's Account sums it per frame. The frame line's warning reports unreadable next to forced, unknown and mappings, and a frame with only unreadable waits is no longer skipped.
  • an_unreadable_wait_holds_its_queue_until_readable checks one count while the memory is unreadable and none once it reads.

How to read a title run: unreadable > 0 with forced at 0 means the memory became readable and the wait held only until then. forced growing with it means waits that never become readable, the stall @⁠Kajanos raised. I have no title to run; numbers from anyone who does would settle it.

hold::tests (11), queue::tests (5) and fence::tests (2) pass under Wine, and cargo clippy --workspace --all-targets --locked -- -D warnings is clean.

**@⁠BastienRodz** on GitHub · 2026-11-25 23:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605#issuecomment-7177509099) Rebased on `main` (`842b0cb`) and added the separate count the triage asks for, as `c5d0230`: - `hold::Pumped` gets `unreadable`: tests of waits whose memory could not be read. It is counted only when a wait holds, so the common path reads nothing more. - `queue.rs`'s `Account` sums it per frame. The frame line's warning reports `unreadable` next to `forced`, `unknown` and `mappings`, and a frame with only unreadable waits is no longer skipped. - `an_unreadable_wait_holds_its_queue_until_readable` checks one count while the memory is unreadable and none once it reads. How to read a title run: `unreadable > 0` with `forced` at 0 means the memory became readable and the wait held only until then. `forced` growing with it means waits that never become readable, the stall @⁠Kajanos raised. I have no title to run; numbers from anyone who does would settle it. `hold::tests` (11), `queue::tests` (5) and `fence::tests` (2) pass under Wine, and `cargo clippy --workspace --all-targets --locked -- -D warnings` is clean.
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-26 00:30 UTC · original

Split as suggested, as 74ccd68 (one commit on 63bcca4): the PR now keeps main's behaviour and only makes the case visible.

  • Waits on memory that cannot be read still run at once, as they do on main.
  • They are counted apart from unknown comparisons, as unreadable in Pumped and in the frame's Account, and reported in the frame warning next to forced.
  • The doc comment on holds now matches the code.

Holding such work until the memory reads can come as a follow-up once a run shows the count is non-zero and the memory becomes readable. The title and description are updated.

**@⁠BastienRodz** on GitHub · 2026-11-26 00:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2605#issuecomment-7178825305) Split as suggested, as `74ccd68` (one commit on `63bcca4`): the PR now keeps `main`'s behaviour and only makes the case visible. - Waits on memory that cannot be read still run at once, as they do on `main`. - They are counted apart from unknown comparisons, as `unreadable` in `Pumped` and in the frame's `Account`, and reported in the frame warning next to `forced`. - The doc comment on `holds` now matches the code. Holding such work until the memory reads can come as a follow-up once a run shows the count is non-zero and the memory becomes readable. The title and description are updated.
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/2605/head:github-bot/gh-2605'
git switch 'github-bot/gh-2605'

Merge

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