GPU: track expand_rects title reads and prioritize WHY_RUN in blocked_by (#168, #89) #207

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

@⁠AscilCH on GitHub · 2026-11-24 22:33 UTC · original
AscilCH:fix/relay-host-read-and-run-precedence → main · +93 −31 · 2 files · 1 commits · open

Problem

Related to #168 and #89; orthogonal to #191 (which covers aliased Step::Refresh, texture read_backs, and Late::Write).

Two remaining gaps in blocked_by under VICTORY_LATE_WAIT and VICTORY_RELAY=2:

  1. expand_rects CPU title-memory reads invisible to blocked_by (crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/host.rs):
    • expand_rects reads title vertex memory [from, from + n * 3 * stride) on the CPU at submission, but scheduled the closure with defer_host (Step::Host), which blocked_by ignores.
    • If an in-flight shader wrote that vertex buffer, VICTORY_LATE_WAIT / VICTORY_RELAY=2 could expand the stale title-memory bytes before copy-back landed.
  2. WHY_READ short-circuiting ahead of Step::Run (crates/victory-gpu/src/host.rs):
    • blocked_by returned Some(WHY_READ) on the first matching read step without scanning the remaining steps in runs for Step::Run(_).
    • Under VICTORY_RELAY=2, why == WHY_READ takes the selective relay_wait path (waiting only until line.written clears) instead of self.settle(..., WHY_RUN) (which settles all flights, including flights without shader writes, ahead of a Step::Run).

Fix

  • Add Step::HostRead(usize, usize, Box<dyn Fn() + Send>) and HostList::defer_host_read in crates/victory-gpu/src/host.rs.
  • Switch expand_rects in crates/victory-gpu/src/draw.rs from defer_host to defer_host_read(from as *const u8, n * 3 * stride, ...).
  • Update blocked_by / blocked_by_steps to check Step::HostRead against written and continue scanning for Step::Run(_) so WHY_RUN takes precedence over WHY_READ (without double-counting LATE_STATS).
  • Add host::relay_tests::blocked_by_steps_checks_host_read_and_prioritizes_run.

Verification

  • cargo test -p victory-gpu --locked -- --test-threads=1: 111 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean

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

**@⁠AscilCH** on GitHub · 2026-11-24 22:33 UTC · [original](https://github.com/fxceless/victory-fork/pull/207) `AscilCH:fix/relay-host-read-and-run-precedence` → `main` · +93 −31 · 2 files · 1 commits · open ## Problem Related to #168 and #89; orthogonal to #191 (which covers aliased `Step::Refresh`, texture `read_backs`, and `Late::Write`). Two remaining gaps in `blocked_by` under `VICTORY_LATE_WAIT` and `VICTORY_RELAY=2`: 1. **`expand_rects` CPU title-memory reads invisible to `blocked_by` (`crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/host.rs`)**: - `expand_rects` reads title vertex memory `[from, from + n * 3 * stride)` on the CPU at submission, but scheduled the closure with `defer_host` (`Step::Host`), which `blocked_by` ignores. - If an in-flight shader wrote that vertex buffer, `VICTORY_LATE_WAIT` / `VICTORY_RELAY=2` could expand the stale title-memory bytes before copy-back landed. 2. **`WHY_READ` short-circuiting ahead of `Step::Run` (`crates/victory-gpu/src/host.rs`)**: - `blocked_by` returned `Some(WHY_READ)` on the first matching read step without scanning the remaining steps in `runs` for `Step::Run(_)`. - Under `VICTORY_RELAY=2`, `why == WHY_READ` takes the selective `relay_wait` path (waiting only until `line.written` clears) instead of `self.settle(..., WHY_RUN)` (which settles all flights, including flights without shader writes, ahead of a `Step::Run`). ## Fix - Add `Step::HostRead(usize, usize, Box<dyn Fn() + Send>)` and `HostList::defer_host_read` in `crates/victory-gpu/src/host.rs`. - Switch `expand_rects` in `crates/victory-gpu/src/draw.rs` from `defer_host` to `defer_host_read(from as *const u8, n * 3 * stride, ...)`. - Update `blocked_by` / `blocked_by_steps` to check `Step::HostRead` against `written` and continue scanning for `Step::Run(_)` so `WHY_RUN` takes precedence over `WHY_READ` (without double-counting `LATE_STATS`). - Add `host::relay_tests::blocked_by_steps_checks_host_read_and_prioritizes_run`. ## Verification - `cargo test -p victory-gpu --locked -- --test-threads=1`: 111 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic unit test only, no game data.)*
Two synchronization gaps in `blocked_by` under `VICTORY_LATE_WAIT` and
`VICTORY_RELAY=2` (orthogonal to #191):

1. `expand_rects` (`crates/victory-gpu/src/draw.rs`) reads title vertex memory
   `[from, from + n * 3 * stride)` on the CPU at submission, but deferred the
   step with `HostList::defer_host` (`Step::Host`), which `blocked_by` ignores.
   Under `VICTORY_LATE_WAIT`/`VICTORY_RELAY`, a rect draw reading vertices
   produced by an in-flight shader could run before the copy-back landed.
2. `blocked_by` (`crates/victory-gpu/src/host.rs`) returned `Some(WHY_READ)` on
   the first matching copy/fill/texture step without scanning later steps for
   `Step::Run(_)`. Under `VICTORY_RELAY=2`, `WHY_READ` waits only until
   `blocked_by` clears rather than settling all flights, whereas `Step::Run(_)`
   requires a full `WHY_RUN` settle.

Add `Step::HostRead` / `HostList::defer_host_read`, switch `expand_rects` to
use it, and scan all steps in `blocked_by` so `WHY_RUN` takes precedence over
an earlier `WHY_READ`. Add
`host::relay_tests::blocked_by_steps_checks_host_read_and_prioritizes_run`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:38:19 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/207/head:github-bot/gh-207'
git switch 'github-bot/gh-207'

Merge

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