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

Open
AscilCH wants to merge 1 commit from upstream-pr/207 into main
AscilCH commented 2026-11-24 22:33:55 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-24T22:33:55Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6592757752 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/207). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-24T22:33:55Z. --- ## 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.)*
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/207:upstream-pr/207'
git switch 'upstream-pr/207'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/207'
git switch 'upstream-pr/207'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/207'
git switch 'upstream-pr/207'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/207'
git switch 'main'
git merge --squash 'upstream-pr/207'
git switch 'main'
git merge --ff-only 'upstream-pr/207'
git switch 'main'
git merge 'upstream-pr/207'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!207
No description provided.