GPU/host: track deferred read-backs in late line.written and copy via write_mapped #565

Open
AscilCH wants to merge 1 commit from upstream-pr/565 into main
AscilCH commented 2026-11-25 02:17:20 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T02:17:20Z.


Problem

Two bugs in texture-to-buffer read-back handling (HostList::defer_read_back / read_backs()) in crates/victory-gpu/src/host.rs:

  1. Missing line.written dependency tracking in late/relay mode:
    • execute_late(), execute_own(), and relay_land() populated line.written solely from sent.back / flight.back (Step::GpuWrite), omitting ranges written by list.deferred().backs (CopyTextureRegion texture-to-buffer read-backs). A subsequent submission or wait reading the destination title buffer before the read-back landed missed late_blocked() / late_met() and read stale bytes.
  2. Unchecked raw pointer write in read_backs():
    • Unlike Shadow::copy_back() (which opens write-watch guards with watch::writing and copies via write_mapped), read_backs() wrote directly into title memory using std::ptr::copy_nonoverlapping. If the title unmapped/freed the destination buffer while the flight was in flight (or if pages were write-guarded), read_backs() triggered an unhandled access violation.

Fix

  • Add read_back_span() and read_back_ranges() helpers and store read_backs: Vec<(usize, usize)> on Sent and Flight, merging them into line.written in execute_late(), execute_own(), and relay_land().
  • Update read_backs() to call crate::watch::writing(...) and copy each row through write_mapped(...) with checked row offsets.
  • Add synthetic D3D12 unit test read_backs_tracks_spans_copies_mapped_rows_and_skips_unmapped_memory.

Verification

  • cargo test -p victory-gpu --locked host::batch -- --test-threads=1: 5 passed, 0 failed (1 pre-existing ignored benchmark)
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean (default-features build on c96b4f2 has only the pre-existing dead_code warning on placed_filler_twins, tracked in #491)

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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6595633191 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/565). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T02:17:20Z. --- ## Problem Two bugs in texture-to-buffer read-back handling (`HostList::defer_read_back` / `read_backs()`) in `crates/victory-gpu/src/host.rs`: 1. **Missing `line.written` dependency tracking in late/relay mode**: - `execute_late()`, `execute_own()`, and `relay_land()` populated `line.written` solely from `sent.back` / `flight.back` (`Step::GpuWrite`), omitting ranges written by `list.deferred().backs` (`CopyTextureRegion` texture-to-buffer read-backs). A subsequent submission or wait reading the destination title buffer before the read-back landed missed `late_blocked()` / `late_met()` and read stale bytes. 2. **Unchecked raw pointer write in `read_backs()`**: - Unlike `Shadow::copy_back()` (which opens write-watch guards with `watch::writing` and copies via `write_mapped`), `read_backs()` wrote directly into title memory using `std::ptr::copy_nonoverlapping`. If the title unmapped/freed the destination buffer while the flight was in flight (or if pages were write-guarded), `read_backs()` triggered an unhandled access violation. ## Fix - Add `read_back_span()` and `read_back_ranges()` helpers and store `read_backs: Vec<(usize, usize)>` on `Sent` and `Flight`, merging them into `line.written` in `execute_late()`, `execute_own()`, and `relay_land()`. - Update `read_backs()` to call `crate::watch::writing(...)` and copy each row through `write_mapped(...)` with checked row offsets. - Add synthetic D3D12 unit test `read_backs_tracks_spans_copies_mapped_rows_and_skips_unmapped_memory`. ## Verification - `cargo test -p victory-gpu --locked host::batch -- --test-threads=1`: 5 passed, 0 failed (1 pre-existing ignored benchmark) - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings`: clean (default-features build on `c96b4f2` has only the pre-existing `dead_code` warning on `placed_filler_twins`, tracked in #491) *(AI-assisted; synthetic unit tests 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/565:upstream-pr/565'
git switch 'upstream-pr/565'

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/565'
git switch 'upstream-pr/565'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/565'
git switch 'upstream-pr/565'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/565'
git switch 'main'
git merge --squash 'upstream-pr/565'
git switch 'main'
git merge --ff-only 'upstream-pr/565'
git switch 'main'
git merge 'upstream-pr/565'
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!565
No description provided.