Skip to content

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

Open
BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/unreadable-wait-holds-queue-pr
Open

BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/unreadable-wait-holds-queue-pr

Conversation

@BastienRodz

@BastienRodz BastienRodz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

@DrDarkDK

Copy link
Copy Markdown

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.

@BastienRodz
BastienRodz force-pushed the gpu/unreadable-wait-holds-queue-pr branch from 8807bd1 to 5de820a Compare November 25, 2026 16:46
@BastienRodz

Copy link
Copy Markdown
Contributor Author

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.

@welisonzika14-jpg

Copy link
Copy Markdown

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.

@kotekompotek

Copy link
Copy Markdown

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.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

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.

@Kajanos

Kajanos commented Nov 25, 2026

Copy link
Copy Markdown

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

@BastienRodz

Copy link
Copy Markdown
Contributor Author

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.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@BastienRodz
BastienRodz force-pushed the gpu/unreadable-wait-holds-queue-pr branch from 5de820a to c5d0230 Compare November 25, 2026 23:23
@BastienRodz

Copy link
Copy Markdown
Contributor Author

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.

`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" (Marvisak#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 <noreply@anthropic.com>
@BastienRodz
BastienRodz force-pushed the gpu/unreadable-wait-holds-queue-pr branch from c5d0230 to 74ccd68 Compare November 26, 2026 00:30
@BastienRodz BastienRodz changed the title GPU: a wait on memory that cannot be read holds its queue GPU: waits on memory that cannot be read are counted apart (#2604) Nov 26, 2026
@BastienRodz

Copy link
Copy Markdown
Contributor Author

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.

@cloph-dsp

Copy link
Copy Markdown

Independent local verification (Windows 11, Rust 1.100.0/MSVC, head 74ccd68, no game data):

  • cargo test --locked -p victory-gpu --lib -- unreadable_waits_are_counted_apart_and_do_not_hold_work → 1 passed, 0 failed, 232 filtered, exit 0. The new test uses Held::default plus a RefCell fake fallback, no host/GPU device.
  • Negative control: the test name is absent from origin/main (git grep → 0 hits), so it is genuinely added by this PR.
  • git diff --check <merge-base 63bcca4> HEAD → clean.
  • Worktree-local CARGO_TARGET_DIR used throughout.

Only the synthetic unreadable-wait scenario was exercised; no real D3D12 device, WARP adapter or game data was involved. AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only hold/queue bookkeeping). No game data used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPU: a list waiting on memory that cannot be read yet runs at once and is counted as an unknown comparison

8 participants