GPU/host: fix late_met overwrite/unsure handling and relay_land in_hand race #785

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

@⁠AscilCH on GitHub · 2026-11-25 07:35 UTC · original
AscilCH:fix/gpu-host-late-met-overwrite-unsure-and-in-hand → main · +139 −23 · 1 files · 1 commits · open

Summary

Fix two ordering and freshness bugs in crates/victory-gpu/src/host.rs:

  1. late_met() scanned overlapping writes in forward order and returned on the first exact match, ignoring later overwrites and unsure flags.

    • Extract eval_late_met() to scan all overlapping writes in submission order:
      • Track unsure whenever line.written is already unsure, a write only partially overlaps the queried (at, size), or a write is Written::GpuTimestamp (value only known after GPU execution).
      • Keep the final exact-match write's value rather than returning on the first match, so a later overwrite or partial/timestamp clobber overrides an earlier match.
      • Return false if unsure is set.
    • Check !line.settling in late_met() alongside line.pending so queued late writes aren't treated as satisfied while settle() is draining them.
  2. relay_land() kept completed Late::Write entries in line.in_hand until after executing all writes.

    • Remove each Late::Write entry from line.in_hand immediately before executing what.write(...) so concurrent readers/overlap checks cannot observe a stale pending entry once the write begins landing.

Verification

  • cargo test -p victory-gpu --locked -- host::batch: 5 passed; 0 failed; 1 ignored (benchmark), including new unit test eval_late_met_uses_final_write_and_honors_unsure.
  • cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 warnings in crates/victory-gpu/src/host.rs (only pre-existing 8dd30ab warnings in draw.rs and indirect.rs).
  • cargo xtask policy: 171 files ok.

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 07:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/785) `AscilCH:fix/gpu-host-late-met-overwrite-unsure-and-in-hand` → `main` · +139 −23 · 1 files · 1 commits · open ## Summary Fix two ordering and freshness bugs in `crates/victory-gpu/src/host.rs`: 1. **`late_met()` scanned overlapping writes in forward order and returned on the first exact match, ignoring later overwrites and `unsure` flags.** - Extract `eval_late_met()` to scan all overlapping writes in submission order: - Track `unsure` whenever `line.written` is already `unsure`, a write only partially overlaps the queried `(at, size)`, or a write is `Written::GpuTimestamp` (value only known after GPU execution). - Keep the **final** exact-match write's value rather than returning on the first match, so a later overwrite or partial/timestamp clobber overrides an earlier match. - Return `false` if `unsure` is set. - Check `!line.settling` in `late_met()` alongside `line.pending` so queued late writes aren't treated as satisfied while `settle()` is draining them. 2. **`relay_land()` kept completed `Late::Write` entries in `line.in_hand` until after executing all writes.** - Remove each `Late::Write` entry from `line.in_hand` immediately before executing `what.write(...)` so concurrent readers/overlap checks cannot observe a stale pending entry once the write begins landing. ## Verification - `cargo test -p victory-gpu --locked -- host::batch`: `5 passed; 0 failed; 1 ignored` (benchmark), including new unit test `eval_late_met_uses_final_write_and_honors_unsure`. - `cargo clippy -p victory-gpu --all-targets --all-features --locked`: 0 warnings in `crates/victory-gpu/src/host.rs` (only pre-existing `8dd30ab` warnings in `draw.rs` and `indirect.rs`). - `cargo xtask policy`: `171 files ok`. *(AI-assisted; synthetic unit tests only, no game data.)*
Three synchronization bugs in `late_met()` and `relay_land()`
(`crates/victory-gpu/src/host.rs`):

1. `late_met()` returned `true` on the first `Late::Write` matching
   `wait.holds_for(*v)`, ignoring later queued writes that overwrite the same
   address with a non-matching value (e.g. `1` followed by `0` while waiting
   for `1`).
2. `late_met()` ignored `unsure == true` (set when `line.written` indicates
   an in-flight shader write overlaps `address`, or an overlapping timestamp /
   partial write occurs) and returned `true` immediately without settling.
3. In `relay_land()`, `Late::Write` wrote to title memory and `Late::Signal`
   woke the title before `line.in_hand.clear()` ran at the end of `relay_land`.
   If the title observed the write/signal, reset `*address = 0`, and queued a
   new wait before `in_hand.clear()`, `late_met()` saw the already-completed
   entry in `in_hand` and falsely returned `true`. Also, `late_met()` returned
   early when `line.line` and `line.in_hand` were empty even while
   `line.settling` was true with shader writes still in `line.written`.

Extract `eval_late_met()` to scan all overlapping writes in order, keep the
last exact-match result, and require `!unsure` before returning `Some(true)`.
Remove each `Late::Write` from `line.in_hand` immediately before executing it
in `relay_land()`, and check `line.written` while `line.settling` is true.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:06 +00:00
Author
Owner

@⁠Pin0d1 on GitHub · 2026-11-25 09:03 UTC · original · edited 2026-11-25 09:06 UTC

@⁠AscilCH, I reran the overwrite through the queue predicate on 67c6c89. With an equality wait for 1 and pending stores of 1 then 0, late_met returns false as expected. If the CPU word currently holds 0, queue::value_met also returns false. If the CPU word still holds 1, queue::value_met returns true through wait.met() before it consults the ordered writes.

The helper test passes. The queue-level case reproduced in two fresh Windows processes. Could the queue distinguish a pending write with a known final value from an address with no pending writer before using the current CPU word? Test patch and both controls.

Prepared with the help of Codex 6.2 Astra Max.

**@⁠Pin0d1** on GitHub · 2026-11-25 09:03 UTC · [original](https://github.com/fxceless/victory-fork/pull/785#issuecomment-7157819532) · edited 2026-11-25 09:06 UTC @⁠AscilCH, I reran the overwrite through the queue predicate on 67c6c89. With an equality wait for 1 and pending stores of 1 then 0, late_met returns false as expected. If the CPU word currently holds 0, queue::value_met also returns false. If the CPU word still holds 1, queue::value_met returns true through wait.met() before it consults the ordered writes. The helper test passes. The queue-level case reproduced in two fresh Windows processes. Could the queue distinguish a pending write with a known final value from an address with no pending writer before using the current CPU word? [Test patch and both controls](https://github.com/Pin0d1/victory-fork/tree/b34a4cd06c4ef9cb5e79c51d1e4f79b8400610da/review-evidence/relay-followup). Prepared with the help of Codex 6.2 Astra Max.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/785/head:github-bot/gh-785'
git switch 'github-bot/gh-785'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-785'
git switch 'github-bot/gh-785'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-785'
git switch 'github-bot/gh-785'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-785'
git switch 'main'
git merge --squash 'github-bot/gh-785'
git switch 'main'
git merge --ff-only 'github-bot/gh-785'
git switch 'main'
git merge 'github-bot/gh-785'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.