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

Closed
Starchaser1024 wants to merge 0 commits from upstream-pr/875 into main
Starchaser1024 commented 2026-11-28 08:24:16 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Starchaser1024 on 2026-11-28T08:24:16Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5538286510 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/875). Originally posted by [Starchaser1024](https://github.com/Starchaser1024) on 2026-11-28T08:24:16Z. --- ## 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.

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!875
No description provided.