GPU: serve unaligned root-CBV fill_scratch fills on the card in card_steps #875

Closed
github-bot wants to merge 0 commits from github-bot/gh-875 into main AGit
Owner

@⁠Starchaser1024 on GitHub · 2026-11-28 08:24 UTC · original
Starchaser1024:feat/card-steps-scratch-fills → main · +526 −65 · 2 files · 1 commits · closed without merging

Summary

Resolves the unaligned root-CBV fill_scratch refusal in card_steps that forces full in-flight GPU + copy-back settles during preparing (docs/findings.md:125-135, where a 0x20-byte upload fill inside the 174 MB world heap stalls behind in-flight UAV dispatches).

Cause

  1. Console shaders bind 16-byte-aligned root CBVs, whereas D3D12 requires 256-byte alignment (gpu % 256 == 0). Roughly 15 of 16 16-byte-aligned root CBVs in the 174 MB heap take the fallback in draw::root_view (list.fill_scratch(address, len)).
  2. HostList::fill_scratch sub-allocated from D3D12_HEAP_TYPE_UPLOAD (GENERIC_READ, which D3D12 forbids as a CopyBufferRegion destination) and recorded Step::Fill(to, src, len, None) (Does::Fill { to: false }).
  3. While descriptor-table CBVs (FillTo::Slot) and texture upload buffers (FillTo::Buffer) already run on the card behind in-flight shader writes, any single fill_scratch root CBV overlapping an in-flight UAV range (or reading a taken Step::Copy in the same submission) hit Err("a fill of memory the card cannot be given the bytes of") (card_steps.rs:367), refusing card_steps for the entire submission and blocking in relay_wait(WHY_READ) / settle.

Changes

  • card_steps::FillTo::Buffer & To::Buffer (crates/victory-gpu/src/host/card_steps.rs): add a u64 byte offset so card_steps::record copies unaligned root CBVs into 256-byte-aligned slices inside a shared chunk (deduplicating COPY_DEST -> COMMON barriers per chunk across single- and multi-level plans).
  • HostList::shared_scratch & SPARE_SHARED (crates/victory-gpu/src/host.rs): parameterize Scratch with shared: bool (256 KiB first chunk, 4 MiB subsequent chunks via Host::shared_buffer, CUSTOM + WRITE_BACK + L0, recycled in SPARE_SHARED and trimmed in allocator_trim and trim_spare_chunks).
  • VICTORY_SCRATCH_SHARED (default 1, A/B toggleable): when card_steps::stage() > 0 && scratch_shared(), HostList::fill_scratch sub-allocates 256-byte-aligned (4x 64-byte cache line) slots from shared_scratch and passes Some(FillTo::Buffer(buffer, at)), falling back to upload scratch otherwise.

Benchmark & Verification (RTX 5060 Ti 16 GB, Windows 11)

host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end (VICTORY_RELAY=2 VICTORY_CARD_STEPS=2, 8 rounds of in-flight GPU copies + shader writes into a Shadow UAV buffer followed immediately by a compute submission binding two unaligned UAV-overlapping root CBVs and one CPU-filled root CBV in the same chunk):

Mode Median submit Total submit (8 rounds) card_fills refused WHY_READ read_wait
VICTORY_SCRATCH_SHARED=0 (upload scratch) 7,793 us (7.79 ms) 61,850 us 0 8 60,762 us
VICTORY_SCRATCH_SHARED=1 (shared scratch) 205 us (0.21 ms) 3,504 us 16 0 0 us
  • host::card_steps::tests::shared_scratch_root_constants_plan_and_record_on_gpu: verifies 256B alignment, (src, len) deduplication, mixed CPU-filled + multi-level GPU-filled slots in one chunk with 0xa5 padding guard checks, live SetComputeRootConstantBufferView readback on GPU, SPARE_SHARED reuse across reset(), and oversized > 4 MiB fallback.
  • cargo test -p victory-gpu --locked: 455 passed, 0 failed.
  • cargo clippy --workspace --all-targets --all-features --locked: 0 warnings in changed files.
  • cargo xtask policy: 294 files ok.
**@⁠Starchaser1024** on GitHub · 2026-11-28 08:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/875) `Starchaser1024:feat/card-steps-scratch-fills` → `main` · +526 −65 · 2 files · 1 commits · closed without merging ## Summary Resolves the unaligned root-CBV `fill_scratch` refusal in `card_steps` that forces full in-flight GPU + copy-back settles during `preparing` (`docs/findings.md:125-135`, where a `0x20`-byte upload fill inside the 174 MB world heap stalls behind in-flight UAV dispatches). ### Cause 1. Console shaders bind 16-byte-aligned root CBVs, whereas D3D12 requires 256-byte alignment (`gpu % 256 == 0`). Roughly 15 of 16 16-byte-aligned root CBVs in the 174 MB heap take the fallback in `draw::root_view` (`list.fill_scratch(address, len)`). 2. `HostList::fill_scratch` sub-allocated from `D3D12_HEAP_TYPE_UPLOAD` (`GENERIC_READ`, which D3D12 forbids as a `CopyBufferRegion` destination) and recorded `Step::Fill(to, src, len, None)` (`Does::Fill { to: false }`). 3. While descriptor-table CBVs (`FillTo::Slot`) and texture upload buffers (`FillTo::Buffer`) already run on the card behind in-flight shader writes, any single `fill_scratch` root CBV overlapping an in-flight UAV range (or reading a taken `Step::Copy` in the same submission) hit `Err("a fill of memory the card cannot be given the bytes of")` (`card_steps.rs:367`), refusing `card_steps` for the entire submission and blocking in `relay_wait(WHY_READ)` / `settle`. ### Changes - **`card_steps::FillTo::Buffer` & `To::Buffer` (`crates/victory-gpu/src/host/card_steps.rs`)**: add a `u64` byte offset so `card_steps::record` copies unaligned root CBVs into 256-byte-aligned slices inside a shared chunk (deduplicating `COPY_DEST -> COMMON` barriers per chunk across single- and multi-level plans). - **`HostList::shared_scratch` & `SPARE_SHARED` (`crates/victory-gpu/src/host.rs`)**: parameterize `Scratch` with `shared: bool` (`256 KiB` first chunk, `4 MiB` subsequent chunks via `Host::shared_buffer`, `CUSTOM` + `WRITE_BACK` + `L0`, recycled in `SPARE_SHARED` and trimmed in `allocator_trim` and `trim_spare_chunks`). - **`VICTORY_SCRATCH_SHARED` (default `1`, A/B toggleable)**: when `card_steps::stage() > 0 && scratch_shared()`, `HostList::fill_scratch` sub-allocates 256-byte-aligned (`4x` 64-byte cache line) slots from `shared_scratch` and passes `Some(FillTo::Buffer(buffer, at))`, falling back to upload `scratch` otherwise. ## Benchmark & Verification (RTX 5060 Ti 16 GB, Windows 11) `host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end` (`VICTORY_RELAY=2 VICTORY_CARD_STEPS=2`, 8 rounds of in-flight GPU copies + shader writes into a `Shadow` UAV buffer followed immediately by a compute submission binding two unaligned UAV-overlapping root CBVs and one CPU-filled root CBV in the same chunk): | Mode | Median `submit` | Total `submit` (8 rounds) | `card_fills` | `refused` | `WHY_READ` `read_wait` | | :--- | ---: | ---: | ---: | ---: | ---: | | `VICTORY_SCRATCH_SHARED=0` (upload `scratch`) | **7,793 us** (`7.79 ms`) | `61,850 us` | `0` | `8` | `60,762 us` | | `VICTORY_SCRATCH_SHARED=1` (shared `scratch`) | **205 us** (`0.21 ms`) | `3,504 us` | `16` | `0` | **`0 us`** | - `host::card_steps::tests::shared_scratch_root_constants_plan_and_record_on_gpu`: verifies 256B alignment, `(src, len)` deduplication, mixed CPU-filled + multi-level GPU-filled slots in one chunk with `0xa5` padding guard checks, live `SetComputeRootConstantBufferView` readback on GPU, `SPARE_SHARED` reuse across `reset()`, and oversized `> 4 MiB` fallback. - `cargo test -p victory-gpu --locked`: 455 passed, 0 failed. - `cargo clippy --workspace --all-targets --all-features --locked`: 0 warnings in changed files. - `cargo xtask policy`: 294 files ok.
Extend `card_steps::FillTo::Buffer` and `To::Buffer` with a byte offset so
`card_steps` can copy unaligned root constant buffers into 256-byte-aligned
slices within a shared scratch chunk instead of only offset 0.

Parameterize `Scratch` with `shared: bool` alongside a dedicated
`SPARE_SHARED` pool (trimmed in `allocator_trim` and `trim_spare_chunks`), and
add `HostList::shared_scratch` plus `VICTORY_SCRATCH_SHARED` (on by default,
A/B toggleable). When `card_steps::stage() > 0`, `HostList::fill_scratch`
allocates from `shared_scratch` and records `Some(FillTo::Buffer(buffer, at))`
instead of upload-only scratch (`None`), eliminating `card_steps` refusals and
flight settles caused by 16-byte-aligned root CBVs in shader-written heaps.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 14:29:17 +00:00
github-bot changed title from GPU: serve unaligned root-CBV fill_scratch fills on the card in card_steps to [pr-performance][memory][NVIDIA] GPU: serve unaligned root-CBV fill_scratch fills on the card in card_steps 2026-11-29 01:55:14 +00:00
github-bot force-pushed github-bot/gh-875 from 4f178f0d16 to b484197300 2026-11-29 02:06:41 +00:00 Compare
github-bot changed title from [pr-performance][memory][NVIDIA] GPU: serve unaligned root-CBV fill_scratch fills on the card in card_steps to GPU: serve unaligned root-CBV fill_scratch fills on the card in card_steps 2026-11-29 02:28:35 +00:00
github-bot closed this pull request 2026-11-29 07:48:20 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!875
No description provided.