Skip to content

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

Open
AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-readback-late-written-and-safe-write
Open

AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-readback-late-written-and-safe-write

Conversation

@AscilCH

@AscilCH AscilCH commented Nov 25, 2026

Copy link
Copy Markdown

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 GPU: keep clippy green without the diagnostics feature #491)

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

… write_mapped

- Compute title memory spans for deferred texture-to-buffer read-backs
  (`HostList::defer_read_back`) via `read_back_span` / `read_back_ranges` and
  include them in `Sent::read_backs`, `Flight::read_backs`, and `line.written`
  in `execute_late()`, `execute_own()`, and `relay_land()`. Previously, late
  and relay submissions reading a buffer populated by an in-flight texture
  read-back missed the dependency and read stale data.
- Replace raw `ptr::copy_nonoverlapping` in `read_backs()` with
  `watch::writing(...)` + `write_mapped(...)` so pages unmapped or write-guarded
  while a flight is in flight are handled safely without an unhandled AV.
- Add synthetic unit tests covering `read_back_span`, `read_back_ranges`,
  and `read_backs()` writing to both live memory and an unmapped (`VirtualFree`)
  address.
triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
Port of PalmVIDev 2ef001c8 (from fxceless#565, AscilCH).
Read-backs into title memory (HostList::defer_read_back) copied with a raw
copy_nonoverlapping after the list ran; a page unmapped or guarded while
the list flew faulted. They now tell the watch (watch::writing over the
rows' span) and copy each row through write_mapped, with checked row
addresses, and skip empty rows. Adapted to this tree's read_backs, which
keeps its walls trace after the copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBA8CxPD68KngjiMeJb
MKmajster pushed a commit to MKmajster/victory-fork-8gb that referenced this pull request Nov 27, 2026
…pth-position

Shaders: centroid position with conservative depth
YummerzdaG added a commit to YummerzdaG/Spectral-x-Victory that referenced this pull request Nov 28, 2026
…h the copy; heap buffers ready per heap (after proneonn/Vertex 1567b6ffbc + 1bb1d00dd3)

Written in by hand after proneonn/Vertex 1567b6ffbc ("GPU: title writes under ranges shaders write reach the copy in
the same submission") and the heap-pass and read-back parts of 1bb1d00dd3 ("GPU: the heap's buffers are ready for the
list that needs them; ..."), GPL-3.0-or-later. The adapter pick of 1bb1d00dd3 is left out.

1. Shadow::update left alone the ranges an earlier list of the same submission declared as written. A root UAV has no
   size, so that is the whole rest of its buffer: constants a later list copied into it were not there for that list's
   shaders, which read what the copy held before. The title's changed bytes now go into the copy and into what the
   shaders' writes are told from (update_busy, through merge_page, the page loop of merge_under_writes, our run joining
   kept), where merges_under_flights allows it. What the submission's one asking brought up to date is remembered per
   copy (fresh), so dispatches that bind one big buffer do not each go over its pages. VICTORY_BUSY_MERGE=0: as before.
   The bytes so put in are logged per frame on the frame-rate line.
2. The pass over the buffers shaders pick from a view heap by index ran once a frame for all heaps, its refreshes in
   the list recorded first: lists of other heaps and lists submitted before that one read stale copies. Now a HeapPass
   per heap and frame; every list that needs it carries Step::Heap, and the first submission with such a list brings
   the spans up to date (also in the one asking, stale_under_flights). VICTORY_HEAP_PASS_EACH=0: as before.
3. A texture read-back is written into title memory with the checked write (sent ahead, the memory may be unmapped or
   guarded by the time it lands; fxceless/victory-fork#565's second point).

Tests: Vertex's two busy-range copy tests (shadow/busy_tests.rs; its list-level tests need list helpers our tree lacks)
and a HeapPass take test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant