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

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

@⁠AscilCH on GitHub · 2026-11-25 08:19 UTC · original
AscilCH:fix/gpu-descriptor-sync-heaps-timing-and-straddle → main · +155 −7 · 2 files · 1 commits · open

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

**@⁠AscilCH** on GitHub · 2026-11-25 08:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/802) `AscilCH:fix/gpu-descriptor-sync-heaps-timing-and-straddle` → `main` · +155 −7 · 2 files · 1 commits · open ## 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.)*
Fix two bugs in `descriptor::sync_heaps()` (`crates/victory-gpu/src/descriptor.rs`,
`crates/victory-gpu/src/draw.rs`):

1. `sync_heaps()` previously ran only at `Host::submit()` (after recording).
   For raw-byte-copied buffer views and placed textures (`View::is_buffer()`),
   `HostHeap::mirror(index, handle, /*for_draw=*/ false)` defers materialization,
   writes a NULL descriptor into the host slot, and queues the slot into
   `changed`/`textures` for `State::heap_buffers()`/`State::early_textures()`.
   Because those passes already ran (and latched the per-frame `FRAME` guard)
   during recording, calling `sync_heaps()` only at `Host::submit()` nulled out
   raw-copied buffer/placed-texture slots right before GPU execution. Call
   `crate::descriptor::sync_heaps()` at the start of `State::heap_buffers()`
   (once per frame, before draining `buffer_changes()`) and `State::early_textures()`
   (before `heap_textures()`), while keeping the `Host::submit()` call for
   samplers and texture objects copied after recording.

2. In `sync_heaps()`, each dirty range is sliced into 64 KiB `PAGE` chunks.
   Any descriptor record straddling a 64 KiB page boundary in an unaligned
   placed heap failed `page_bytes.get(at..at + step)` on the first page and
   `checked_sub(from)` on the second page, permanently dropping the slot. 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`.

Add `descriptor::tests::straddling_record_across_page_boundary_is_mirrored_on_sync`
and `descriptor::tests::raw_copied_buffer_view_is_queued_by_sync_heaps_and_made_for_draw`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:28 +00:00
Author
Owner

@⁠yualk on GitHub · 2026-11-25 18:54 UTC · original

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.

**@⁠yualk** on GitHub · 2026-11-25 18:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/802#issuecomment-7171565978) 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 has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor.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/802/head:github-bot/gh-802'
git switch 'github-bot/gh-802'

Merge

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