GPU/descriptor: sync raw-copied heap slots before draw passes and handle page-straddling records #801

Open
AscilCH wants to merge 1 commit from upstream-pr/802 into main
AscilCH commented 2026-11-25 08:19:12 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T08:19:12Z.


Summary

Fix two descriptor::sync_heaps() bugs introduced in a26859f..9376fd6 (crates/victory-gpu/src/descriptor.rs, crates/victory-gpu/src/draw.rs):

  1. Sync raw-byte-copied slots before State::heap_buffers and State::early_textures run.

    • sync_heaps() previously ran only at Host::submit() (after command-list recording). For raw-byte-copied buffer views and placed textures (View::is_buffer()), HostHeap::mirror(..., /*for_draw=*/ false) defers materialization, writes a NULL descriptor into the host slot, and queues the slot into changed/textures for heap_buffers()/heap_textures().
    • Because State::heap_buffers() already ran and latched its per-frame FRAME guard during recording, running sync_heaps() only at Host::submit() nulled out raw-copied buffer and placed-texture slots immediately before GPU execution.
    • Call crate::descriptor::sync_heaps() before draining buffer_changes() in State::heap_buffers() and before heap_textures() in State::early_textures() (keeping the Host::submit() call for samplers and texture objects copied after recording).
  2. Handle descriptor records straddling 64 KiB PAGE boundaries in sync_heaps().

    • sync_heaps() sliced each dirty range into 64 KiB PAGE chunks and skipped any slot where (handle - from) underflowed or at + step > page_bytes.len(). In an unaligned placed heap, any record straddling a 64 KiB boundary was dropped by both adjacent pages.
    • Fall back to a kernel read_into() of the step-byte record into a stack buffer whenever a slot in [start, end) straddles from or to.

Verification

  • cargo test -p victory-gpu --locked -- descriptor::: 30 passed; 0 failed; 0 ignored, including new straddling_record_across_page_boundary_is_mirrored_on_sync and raw_copied_buffer_view_is_queued_by_sync_heaps_and_made_for_draw.
  • cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 warnings in crates/victory-gpu/src/descriptor.rs and crates/victory-gpu/src/draw.rs (only pre-existing 9376fd6 warnings in draw.rs:2399 and indirect.rs:1436).
  • cargo xtask policy: 171 files ok.

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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6600220463 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/802). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T08:19:12Z. --- ## Summary Fix two `descriptor::sync_heaps()` bugs introduced in `a26859f..9376fd6` (`crates/victory-gpu/src/descriptor.rs`, `crates/victory-gpu/src/draw.rs`): 1. **Sync raw-byte-copied slots before `State::heap_buffers` and `State::early_textures` run.** - `sync_heaps()` previously ran only at `Host::submit()` (after command-list recording). For raw-byte-copied buffer views and placed textures (`View::is_buffer()`), `HostHeap::mirror(..., /*for_draw=*/ false)` defers materialization, writes a NULL descriptor into the host slot, and queues the slot into `changed`/`textures` for `heap_buffers()`/`heap_textures()`. - Because `State::heap_buffers()` already ran and latched its per-frame `FRAME` guard during recording, running `sync_heaps()` only at `Host::submit()` nulled out raw-copied buffer and placed-texture slots immediately before GPU execution. - Call `crate::descriptor::sync_heaps()` before draining `buffer_changes()` in `State::heap_buffers()` and before `heap_textures()` in `State::early_textures()` (keeping the `Host::submit()` call for samplers and texture objects copied after recording). 2. **Handle descriptor records straddling 64 KiB `PAGE` boundaries in `sync_heaps()`.** - `sync_heaps()` sliced each dirty range into 64 KiB `PAGE` chunks and skipped any slot where `(handle - from)` underflowed or `at + step > page_bytes.len()`. In an unaligned placed heap, any record straddling a 64 KiB boundary was dropped by both adjacent pages. - Fall back to a kernel `read_into()` of the `step`-byte record into a stack buffer whenever a slot in `[start, end)` straddles `from` or `to`. ## Verification - `cargo test -p victory-gpu --locked -- descriptor::`: `30 passed; 0 failed; 0 ignored`, including new `straddling_record_across_page_boundary_is_mirrored_on_sync` and `raw_copied_buffer_view_is_queued_by_sync_heaps_and_made_for_draw`. - `cargo clippy -p victory-gpu --all-targets --all-features --locked`: 0 warnings in `crates/victory-gpu/src/descriptor.rs` and `crates/victory-gpu/src/draw.rs` (only pre-existing `9376fd6` warnings in `draw.rs:2399` and `indirect.rs:1436`). - `cargo xtask policy`: `171 files ok`. *(AI-assisted; synthetic unit tests only, no game data.)*
yualk commented 2026-11-25 19:09:47 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by yualk on 2026-11-25T18:54:32Z.


Independent off-title WARP check of exact 55502c19 on top of #792's coherent record decoder (635b77c production change):

  • Authored SM 6.6 pixel shader used ResourceDescriptorHeap[NonUniformResourceIndex(slot)] (createHandleFromHeap) and Texture2D.Load(0,0,0) on raw-copied placed-Texture2D slot 2047.
  • #792 baseline: aligned and 64 KiB-straddling 32-byte records both left the target typed-null (0). API-published control 0xff21d452, same-shaped decoy 0xff7924b6, and covered guard 0xffffffff passed after the production submission fence.
  • #792 + #802: aligned and straddling target returned exact 0xc35a29e7; controls/guard unchanged. Scan receipts were [pages, looked, mirrored] = [1,2048,3] aligned and [2,2049,3] straddling.
  • Pre-scan-only attribution (without the whole-record fallback) recovered aligned, while the straddling target stayed null. Thus the early scan and boundary fallback each affect a distinct tested case.
  • Equal-output API-published control, 24 fresh processes/arm over 2,048 records: preparation median/p95 336/460 us baseline vs 374/557 us combined. This is synthetic first-draw cost, not title FPS.

No game data, title launch, or lighting claim. This qualifies the combined changes for a first live copied-Texture2D comparison; it does not prove a title slot or the exposure LUT uses this path. AI-assisted fixture; I reviewed the fenced outputs and split attribution.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7171565978 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/802#issuecomment-7171565978). Originally posted by [yualk](https://github.com/yualk) on 2026-11-25T18:54:32Z. --- Independent off-title WARP check of exact `55502c19` on top of #792's coherent record decoder (`635b77c` production change): - Authored SM 6.6 pixel shader used `ResourceDescriptorHeap[NonUniformResourceIndex(slot)]` (`createHandleFromHeap`) and `Texture2D.Load(0,0,0)` on raw-copied placed-Texture2D slot 2047. - #792 baseline: aligned and 64 KiB-straddling 32-byte records both left the target typed-null (`0`). API-published control `0xff21d452`, same-shaped decoy `0xff7924b6`, and covered guard `0xffffffff` passed after the production submission fence. - #792 + #802: aligned and straddling target returned exact `0xc35a29e7`; controls/guard unchanged. Scan receipts were `[pages, looked, mirrored] = [1,2048,3]` aligned and `[2,2049,3]` straddling. - Pre-scan-only attribution (without the whole-record fallback) recovered aligned, while the straddling target stayed null. Thus the early scan and boundary fallback each affect a distinct tested case. - Equal-output API-published control, 24 fresh processes/arm over 2,048 records: preparation median/p95 `336/460 us` baseline vs `374/557 us` combined. This is synthetic first-draw cost, not title FPS. No game data, title launch, or lighting claim. This qualifies the combined changes for a first live copied-Texture2D comparison; it does not prove a title slot or the exposure LUT uses this path. AI-assisted fixture; I reviewed the fenced outputs and split attribution.
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/802:upstream-pr/802'
git switch 'upstream-pr/802'

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