gpu: route unaligned loose root CBVs to scratch without allocating shadow::LOOSE windows #2063

Merged
steven-seagull27 merged 2 commits from upstream-pr/2063 into main 2026-11-30 14:12:04 +00:00
steven-seagull27 commented 2026-11-29 08:55:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by steven-seagull27 on 2026-11-29T08:55:18Z.


Related: #2024

What it changes

draw::root_view_len previously called shadow::find(address, 1) for root CBVs (srv == false). When address was outside any registered title buffer (shadow::BUFFERS), shadow::find(address, 1) fell through to shadow::loose(address, address + 1, true, false).

For unaligned loose root CBVs (address % 256 != 0 outside registered BUFFERS), every shadow::LOOSE window starts on a >= 64 KiB title boundary with a 64 KiB-aligned host GPU virtual address, so shadow.gpu(address) % 256 can never be 0. root_view_len immediately discarded the returned Shadow and fell through to place_constant / fill_scratch, leaving behind unused LOOSE D3D12 buffers for every unique loose window touched only by unaligned root CBVs (and repeatedly bumping used on them). Note that memory savings are per unique avoided loose window, not 6 MiB per CBV call (windows may already be shared with other accesses).

This PR narrows the change strictly to the unaligned loose root CBV path, deferring aligned loose CBV sizing to a separate follow-up with full GPU-write-to-CBV coherence and default-grid boundary testing:

  • Factors registered title buffer lookup into shadow::lookup_buffer and adds shadow::find_root_cbv(address) -> Option<RootCbv> (with ROOT_CBV_LEN = 1 << 16).
  • Checks registered BUFFERS with length 1 first, preserving exact behavior for small (< 64 KiB) registered buffers, unaligned offsets inside registered buffers, and unaligned-start registered buffers whose shadow.gpu(address) is still 256-byte aligned.
  • On a BUFFERS miss with !address.is_multiple_of(256), returns RootCbv::Scratch(len) without touching shadow::LOOSE. len is computed via unsized_window_left(address, reach(), grow()).min(ROOT_CBV_LEN), preserving the exact pre-patch scratch length shadow.left(address).min(64 KiB) near a window end (including when VICTORY_WINDOW_REACH_KB=0). draw::root_view_len goes straight to place_constant / fill_scratch (whose Step::Fill reads go through host::copy_mapped, safely handling uncommitted page boundaries).
  • On a BUFFERS miss with address.is_multiple_of(256), delegates to the existing unsized loose lookup (loose(address, address + 1, true, false)) so aligned loose root CBVs keep identical window backing identity (Arc::ptr_eq) and GPU-write coherence with root UAVs and root SRVs (avoiding duplicate 8 MiB boundary windows on the default 4 MiB grid + 2 MiB reach).
  • Updates the diagnostics draw listing loop in draw.rs to use find_root_cbv for stage.root_cbvs as well.
  • Leaves root SRVs (srv == true) and root UAVs unchanged.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): synthetic unit tests and live D3D12 compute shader readback tests in victory-gpu (isolated per-test 12 MiB MEM_RESERVE virtual address ranges covering two exclusive 4 MiB cells so LOOSE membership assertions cannot be affected by concurrent tests).
  • Before: unaligned loose root CBVs allocated and pinned unused shadow::LOOSE windows before immediately falling through to place_constant / fill_scratch.
  • After:
    • shadow::root_cbv_tests::unsized_window_left_matches_unsized_window_across_reach_and_grow_modes: verifies exact pre-patch scratch length near 4 MiB cell boundaries under default 2 MiB reach, VICTORY_WINDOW_REACH_KB=0, grow, and u64::MAX saturation.
    • shadow::root_cbv_tests::find_root_cbv_unaligned_skips_loose_registered_hits_buffers_and_aligned_shares_backing: verifies no LOOSE window is created for unaligned loose root CBVs (including near cell boundaries), exact BUFFERS hits and clamping for < 64 KiB aligned-start and unaligned-start registered buffers, and that an aligned loose root CBV starting 256 bytes before a 4 MiB cell boundary returns the exact same Arc<Shadow> (Arc::ptr_eq) as shadow::find(addr, 0) in both call orders.
    • draw::root_cbv_tests::root_cbv_scratch_small_registered_and_aligned_loose_read_exact_bytes: end-to-end D3D12 compute shader (SetComputeRootConstantBufferView) readback covering an unaligned loose CBV abutting an uncommitted 4 KiB page, an unaligned loose CBV near a 4 MiB cell boundary, < 64 KiB registered buffers, and an aligned loose CBV 256 bytes before a 4 MiB cell boundary.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader translator changes).
  • cargo test passed for the crates it touches: yes
    • cargo test --locked -j 3 -p victory-gpu --lib -- shadow:: --test-threads=1: 73 passed, 0 failed, 5 ignored
    • cargo test --locked -j 3 -p victory-gpu --lib -- draw:: --test-threads=1: 26 passed, 0 failed, 2 ignored
    • cargo test --locked -j 3 -p victory-gpu --lib -- place_constant --test-threads=1: 1 passed, 0 failed
    • cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=1 under VICTORY_WINDOW_REACH_KB=0, VICTORY_WINDOW_GROW=1, VICTORY_WINDOW_TAILS=1, and VICTORY_WINDOW_KB=64: 3 passed, 0 failed in each mode
    • cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=4 (parallel isolation check): 3 passed, 0 failed
    • cargo check --locked -j 3 -p victory-gpu --lib --features diagnostics: passed
    • cargo clippy --locked -j 3 -p victory-gpu --lib --tests: 0 warnings in touched code
    • git diff --check: clean

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #2024
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5549189677 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2063). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-29T08:55:18Z. --- Related: #2024 ## What it changes `draw::root_view_len` previously called `shadow::find(address, 1)` for root CBVs (`srv == false`). When `address` was outside any registered title buffer (`shadow::BUFFERS`), `shadow::find(address, 1)` fell through to `shadow::loose(address, address + 1, true, false)`. For **unaligned loose root CBVs** (`address % 256 != 0` outside registered `BUFFERS`), every `shadow::LOOSE` window starts on a `>= 64 KiB` title boundary with a 64 KiB-aligned host GPU virtual address, so `shadow.gpu(address) % 256` can never be `0`. `root_view_len` immediately discarded the returned `Shadow` and fell through to `place_constant` / `fill_scratch`, leaving behind unused `LOOSE` D3D12 buffers for every unique loose window touched only by unaligned root CBVs (and repeatedly bumping `used` on them). Note that memory savings are per unique avoided loose window, not 6 MiB per CBV call (windows may already be shared with other accesses). This PR narrows the change strictly to the **unaligned loose root CBV path**, deferring aligned loose CBV sizing to a separate follow-up with full GPU-write-to-CBV coherence and default-grid boundary testing: - Factors registered title buffer lookup into `shadow::lookup_buffer` and adds `shadow::find_root_cbv(address) -> Option<RootCbv>` (with `ROOT_CBV_LEN = 1 << 16`). - Checks registered `BUFFERS` with length 1 first, preserving exact behavior for small (`< 64 KiB`) registered buffers, unaligned offsets inside registered buffers, and unaligned-start registered buffers whose `shadow.gpu(address)` is still 256-byte aligned. - On a `BUFFERS` miss with `!address.is_multiple_of(256)`, returns `RootCbv::Scratch(len)` without touching `shadow::LOOSE`. `len` is computed via `unsized_window_left(address, reach(), grow()).min(ROOT_CBV_LEN)`, preserving the exact pre-patch scratch length `shadow.left(address).min(64 KiB)` near a window end (including when `VICTORY_WINDOW_REACH_KB=0`). `draw::root_view_len` goes straight to `place_constant` / `fill_scratch` (whose `Step::Fill` reads go through `host::copy_mapped`, safely handling uncommitted page boundaries). - On a `BUFFERS` miss with `address.is_multiple_of(256)`, delegates to the existing unsized loose lookup (`loose(address, address + 1, true, false)`) so aligned loose root CBVs keep identical window backing identity (`Arc::ptr_eq`) and GPU-write coherence with root UAVs and root SRVs (avoiding duplicate 8 MiB boundary windows on the default 4 MiB grid + 2 MiB reach). - Updates the diagnostics draw listing loop in `draw.rs` to use `find_root_cbv` for `stage.root_cbvs` as well. - Leaves root SRVs (`srv == true`) and root UAVs unchanged. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): synthetic unit tests and live D3D12 compute shader readback tests in `victory-gpu` (isolated per-test 12 MiB `MEM_RESERVE` virtual address ranges covering two exclusive 4 MiB cells so `LOOSE` membership assertions cannot be affected by concurrent tests). - Before: unaligned loose root CBVs allocated and pinned unused `shadow::LOOSE` windows before immediately falling through to `place_constant` / `fill_scratch`. - After: - `shadow::root_cbv_tests::unsized_window_left_matches_unsized_window_across_reach_and_grow_modes`: verifies exact pre-patch scratch length near 4 MiB cell boundaries under default 2 MiB reach, `VICTORY_WINDOW_REACH_KB=0`, `grow`, and `u64::MAX` saturation. - `shadow::root_cbv_tests::find_root_cbv_unaligned_skips_loose_registered_hits_buffers_and_aligned_shares_backing`: verifies no `LOOSE` window is created for unaligned loose root CBVs (including near cell boundaries), exact `BUFFERS` hits and clamping for `< 64 KiB` aligned-start and unaligned-start registered buffers, and that an aligned loose root CBV starting 256 bytes before a 4 MiB cell boundary returns the exact same `Arc<Shadow>` (`Arc::ptr_eq`) as `shadow::find(addr, 0)` in both call orders. - `draw::root_cbv_tests::root_cbv_scratch_small_registered_and_aligned_loose_read_exact_bytes`: end-to-end D3D12 compute shader (`SetComputeRootConstantBufferView`) readback covering an unaligned loose CBV abutting an uncommitted 4 KiB page, an unaligned loose CBV near a 4 MiB cell boundary, `< 64 KiB` registered buffers, and an aligned loose CBV 256 bytes before a 4 MiB cell boundary. - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader translator changes). - `cargo test` passed for the crates it touches: yes - `cargo test --locked -j 3 -p victory-gpu --lib -- shadow:: --test-threads=1`: 73 passed, 0 failed, 5 ignored - `cargo test --locked -j 3 -p victory-gpu --lib -- draw:: --test-threads=1`: 26 passed, 0 failed, 2 ignored - `cargo test --locked -j 3 -p victory-gpu --lib -- place_constant --test-threads=1`: 1 passed, 0 failed - `cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=1` under `VICTORY_WINDOW_REACH_KB=0`, `VICTORY_WINDOW_GROW=1`, `VICTORY_WINDOW_TAILS=1`, and `VICTORY_WINDOW_KB=64`: 3 passed, 0 failed in each mode - `cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=4` (parallel isolation check): 3 passed, 0 failed - `cargo check --locked -j 3 -p victory-gpu --lib --features diagnostics`: passed - `cargo clippy --locked -j 3 -p victory-gpu --lib --tests`: 0 warnings in touched code - `git diff --check`: clean ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2024
ArturoWolff commented 2026-11-29 09:53:17 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ArturoWolff on 2026-11-29T09:53:17Z.


The unaligned-only path looks particularly useful; thanks for following up the measurements in #2024. I would separate that optimization from the aligned sizing change, though. Independent source review found a concrete default-grid counterexample on exact head 50414969 / base 829188e9.

With the current default 4 MiB grid and 2 MiB reach, I compiled and ran the unchanged grid, reach_of, unsized_window, named_window and window_of functions from shadow.rs in a small native Rust harness (authored synthetic addresses, no D3D12 or game). For an aligned 64 KiB CBV near the end of a cell:

Request Named window size
Existing unsized request 6 MiB
Sized request wholly inside the cell 6 MiB
Sized request starting 256 bytes before the cell boundary 8 MiB

The original 6 MiB window already covers the third request. loose(..., false, false) nevertheless names a distinct 8 MiB entry; the exact-key lookup and insertion can retain both (14 MiB total logical window span). This is a measured sizing result, not a measured resident-memory delta. More importantly, root UAVs still use the unsized request and schedule writes on its own shadow; another backing for the overlapping CBV needs a same-list GPU-write-to-CBV coherence test before adoption. I have not reproduced stale pixels, so that is a correctness risk, not a proven rendering regression.

Could you keep aligned loose views on the existing lookup path for the first, conservative patch? For the aligned follow-up I'd test the default-grid boundary, pre-existing shared backing, full known-byte readback after GPU writes, and the fine/grow configurations in separate processes. Also, global LOOSE count/byte assertions need test isolation so concurrent unrelated fixtures cannot affect the result. The unaligned optimization's savings should count unique avoided windows, not 6 MiB per CBV call (windows may be reused).

Why this matters on 8 GB/16 GB Linux: our actual cold launch of unmodified 829188e9 on RTX 4060 / GE-Proton11-14 reached a defective opening cinematic, unlike our earlier loading exits. It presented at 2560x1440 from the 1080 scene mode, requested the RT builder and full write-back, and did not omit passes intentionally. Clarification from the subsequent full log review: RT was requested, but the builder actually stayed off with 34/53 stages missing; the same-build warm run reproduced this with 40/53. See the matched-configuration baseline report on #2148. We have not verified functioning RT. At the late sampled point the compile memory log recorded 378 started / 377 finished, 98 put off after waiting, and about 30,152 MiB commit left. Deferrals were attributed to the soft physical floor, not the commit floor. Buffer-mirror span rose from roughly 192 MiB before the cinematic to around 1,490 MiB later. Host MemAvailable minimum 347,248 KiB with the independent 128 MiB external guard unchanged; exit 3, no recorded kernel OOM/GPU fault. Neither those counters nor #2024's different Windows scene establish that loose CBVs account for the pressure. No proposed guard relaxation and no claim of a gameplay benefit yet.

I'll keep this candidate out of our gameplay build until the backing identity and correctness question is resolved. The unaligned-only change is a worthwhile narrower discriminator.

AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7254064642 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2063#issuecomment-7254064642). Originally posted by [ArturoWolff](https://github.com/ArturoWolff) on 2026-11-29T09:53:17Z. --- The unaligned-only path looks particularly useful; thanks for following up the measurements in #2024. I would separate that optimization from the aligned sizing change, though. Independent source review found a concrete default-grid counterexample on exact head `50414969` / base `829188e9`. With the current default 4 MiB grid and 2 MiB reach, I compiled and ran the **unchanged** `grid`, `reach_of`, `unsized_window`, `named_window` and `window_of` functions from [shadow.rs](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/829188e969ffd2907e5867c5d9aca29bd91cb1b6/crates/victory-gpu/src/shadow.rs#L7890-L7973) in a small native Rust harness (authored synthetic addresses, no D3D12 or game). For an aligned 64 KiB CBV near the end of a cell: | Request | Named window size | | --- | ---: | | Existing unsized request | 6 MiB | | Sized request wholly inside the cell | 6 MiB | | Sized request starting 256 bytes before the cell boundary | 8 MiB | The original 6 MiB window already covers the third request. `loose(..., false, false)` nevertheless names a distinct 8 MiB entry; the [exact-key lookup and insertion](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/829188e969ffd2907e5867c5d9aca29bd91cb1b6/crates/victory-gpu/src/shadow.rs#L8255-L8322) can retain both (14 MiB total logical window span). This is a measured sizing result, not a measured resident-memory delta. More importantly, root UAVs still use the unsized request and schedule writes on its own shadow; another backing for the overlapping CBV needs a same-list GPU-write-to-CBV coherence test before adoption. I have not reproduced stale pixels, so that is a correctness risk, not a proven rendering regression. Could you keep aligned loose views on the existing lookup path for the first, conservative patch? For the aligned follow-up I'd test the default-grid boundary, pre-existing shared backing, full known-byte readback after GPU writes, and the fine/grow configurations in separate processes. Also, global `LOOSE` count/byte assertions need test isolation so concurrent unrelated fixtures cannot affect the result. The unaligned optimization's savings should count unique avoided windows, not 6 MiB per CBV call (windows may be reused). **Why this matters on 8 GB/16 GB Linux:** our actual cold launch of unmodified `829188e9` on RTX 4060 / GE-Proton11-14 reached a defective opening cinematic, unlike our earlier loading exits. It presented at 2560x1440 from the 1080 scene mode, requested the RT builder and full write-back, and did not omit passes intentionally. **Clarification from the subsequent full log review:** RT was requested, but the builder actually stayed off with 34/53 stages missing; the same-build warm run reproduced this with 40/53. See [the matched-configuration baseline report on #2148](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2148#issuecomment-7254308246). We have not verified functioning RT. At the late sampled point the compile memory log recorded 378 started / 377 finished, 98 put off after waiting, and about 30,152 MiB commit left. Deferrals were attributed to the soft physical floor, not the commit floor. Buffer-mirror span rose from roughly 192 MiB before the cinematic to around 1,490 MiB later. Host MemAvailable minimum 347,248 KiB with the independent 128 MiB external guard unchanged; exit 3, no recorded kernel OOM/GPU fault. Neither those counters nor #2024's different Windows scene establish that loose CBVs account for the pressure. No proposed guard relaxation and no claim of a gameplay benefit yet. I'll keep this candidate out of our gameplay build until the backing identity and correctness question is resolved. The unaligned-only change is a worthwhile narrower discriminator. AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).
Ondra97 commented 2026-11-29 12:34:48 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Ondra97 on 2026-11-29T12:34:48Z.


I can run a separate empty-cache Windows check of the unaligned-only change on an RTX 4070 Ti SUPER / 32 GB machine. Our cold 829188e9 logs show several GiB of tracked shadow copies during compile admission pressure, but the current counters cannot attribute that memory to unused root CBV windows. The TileHeap startup blocker is now independently exercised by #2263.

If you split the unaligned path from the aligned sizing change, please flag the new head here. I would compare unique avoided window allocations, free physical memory and pending PSOs with the same input and FG off. Please preserve the existing scratch length near a window end, including when VICTORY_WINDOW_REACH_KB=0, so the run can also check for rendering regressions.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7255914162 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2063#issuecomment-7255914162). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-11-29T12:34:48Z. --- I can run a separate empty-cache Windows check of the unaligned-only change on an RTX 4070 Ti SUPER / 32 GB machine. Our cold 829188e9 logs show several GiB of tracked shadow copies during compile admission pressure, but the current counters cannot attribute that memory to unused root CBV windows. The TileHeap startup blocker is now independently exercised by #2263. If you split the unaligned path from the aligned sizing change, please flag the new head here. I would compare unique avoided window allocations, free physical memory and pending PSOs with the same input and FG off. Please preserve the existing scratch length near a window end, including when VICTORY_WINDOW_REACH_KB=0, so the run can also check for rendering regressions.
Ondra97 commented 2026-11-29 12:57:33 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Ondra97 on 2026-11-29T12:57:33Z.


I ran a private diagnostic variant on Windows with only the unaligned root CBV no-window shortcut. It applied only on a registered-buffer miss and a miss for the exact existing loose-window key, preserved the original clipped scratch length, and used the original path with grow/tails on. The build and two targeted tests passed, including a window-end case at REACH=0. This was a separate local variant of the narrower idea, independent of the aligned change in this PR.

Same binary with that one switch on/off, same input seed, Series X 2560×1440, DLSS Performance, RT requested, FG off, fresh emulator image/shader/PSO caches. Both 240-second runs passed TileHeap via #2263, then remained in heavy cold compilation with one admitted compile in the median and roughly a thousand host PSOs still pending. In the overlapping 2,098–4,998 draw-count band, tracked shadow-copy span had medians of 5,881/5,922 MiB (5/2 snapshots), and free physical RAM had medians of 705/852 MiB. That is too little matching telemetry for an FPS claim, and it did not establish meaningful cold-start recovery. The existing driver cache was unchanged by the setup and could evolve between sequential runs.

This does not measure individual avoided allocations or rule out this optimization in other scenes. I will keep the local variant as diagnostic evidence while you own the PR.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7256185239 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2063#issuecomment-7256185239). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-11-29T12:57:33Z. --- I ran a private diagnostic variant on Windows with only the unaligned root CBV no-window shortcut. It applied only on a registered-buffer miss and a miss for the exact existing loose-window key, preserved the original clipped scratch length, and used the original path with grow/tails on. The build and two targeted tests passed, including a window-end case at REACH=0. This was a separate local variant of the narrower idea, independent of the aligned change in this PR. Same binary with that one switch on/off, same input seed, Series X 2560×1440, DLSS Performance, RT requested, FG off, fresh emulator image/shader/PSO caches. Both 240-second runs passed TileHeap via #2263, then remained in heavy cold compilation with one admitted compile in the median and roughly a thousand host PSOs still pending. In the overlapping 2,098–4,998 draw-count band, tracked shadow-copy span had medians of 5,881/5,922 MiB (5/2 snapshots), and free physical RAM had medians of 705/852 MiB. That is too little matching telemetry for an FPS claim, and it did not establish meaningful cold-start recovery. The existing driver cache was unchanged by the setup and could evolve between sequential runs. This does not measure individual avoided allocations or rule out this optimization in other scenes. I will keep the local variant as diagnostic evidence while you own the PR.
steven-seagull27 commented 2026-11-29 12:59:23 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by steven-seagull27 on 2026-11-29T12:59:23Z.


Thanks @ArturoWolff and @Ondra97 for the thorough reviews — both catches were spot-on. I've narrowed this PR to the conservative unaligned-only loose root CBV path and pushed the updated head: 93824fba (93824fbac9f05435f4ff5ba7637de844e1177d66).

Changes in 93824fba

  1. Aligned loose root CBVs kept on the existing lookup path (@ArturoWolff):

    • shadow::find_root_cbv now delegates 256-byte-aligned loose misses straight to loose(address, address + 1, true, false) (identical to shadow::find(address, 0) / find(address, 1)), so aligned loose CBVs share exact Arc<Shadow> backing identity and GPU-write coherence with root UAVs/SRVs and never create a duplicate 8 MiB boundary window on the default 4 MiB grid + 2 MiB reach.
    • Replaced the aligned-sizing test with a boundary identity test verifying Arc::ptr_eq between find_root_cbv(cell_end - 256) and find(cell_end - 256, 0) in both call orders.
    • Deferred aligned loose CBV sizing to a separate follow-up with full GPU-write-to-CBV coherence and default-grid boundary testing, and updated the PR title/description to clarify that savings are per unique avoided loose window (not 6 MiB per call).
  2. Isolated per-address LOOSE assertions (@ArturoWolff):

    • Replaced global LOOSE count/byte snapshots with loose_covering(addr) scoped to exclusive 12 MiB MEM_RESERVE ranges (yielding two complete 4 MiB cells owned solely by each test), so concurrent unrelated tests cannot interfere (also verified with --test-threads=4).
  3. Preserved exact scratch length near window ends, including VICTORY_WINDOW_REACH_KB=0 (@Ondra97):

    • RootCbv::Scratch(len) computes len = unsized_window_left(address, reach(), grow()).min(ROOT_CBV_LEN), matching the exact pre-patch shadow.left(address).min(64 KiB) without allocating a loose window (e.g., 4080 B at cell_end - 4096 + 0x10 when VICTORY_WINDOW_REACH_KB=0, 64 KiB under default 2 MiB reach).
    • Added unit coverage for unsized_window_left across reach = 0, default reach, grow, and u64::MAX, plus live D3D12 compute readback tests verified under default settings, VICTORY_WINDOW_REACH_KB=0, VICTORY_WINDOW_GROW=1, VICTORY_WINDOW_TAILS=1, and VICTORY_WINDOW_KB=64.

Verification on 93824fba

  • cargo test --locked -j 3 -p victory-gpu --lib -- shadow:: --test-threads=1 — 73 passed, 0 failed, 5 ignored
  • cargo test --locked -j 3 -p victory-gpu --lib -- draw:: --test-threads=1 — 26 passed, 0 failed, 2 ignored
  • cargo test --locked -j 3 -p victory-gpu --lib -- place_constant --test-threads=1 — 1 passed, 0 failed
  • cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=1 under VICTORY_WINDOW_REACH_KB=0, VICTORY_WINDOW_GROW=1, VICTORY_WINDOW_TAILS=1, and VICTORY_WINDOW_KB=64 — 3 passed, 0 failed each
  • cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=4 — 3 passed, 0 failed
  • cargo check --locked -j 3 -p victory-gpu --lib --features diagnostics — passed
  • cargo clippy --locked -j 3 -p victory-gpu --lib --tests — 0 warnings in touched code
  • git diff --check — clean
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7256206496 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2063#issuecomment-7256206496). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-29T12:59:23Z. --- Thanks @ArturoWolff and @Ondra97 for the thorough reviews — both catches were spot-on. I've narrowed this PR to the conservative **unaligned-only** loose root CBV path and pushed the updated head: **`93824fba`** (`93824fbac9f05435f4ff5ba7637de844e1177d66`). ### Changes in `93824fba` 1. **Aligned loose root CBVs kept on the existing lookup path (@ArturoWolff):** - `shadow::find_root_cbv` now delegates 256-byte-aligned loose misses straight to `loose(address, address + 1, true, false)` (identical to `shadow::find(address, 0)` / `find(address, 1)`), so aligned loose CBVs share exact `Arc<Shadow>` backing identity and GPU-write coherence with root UAVs/SRVs and never create a duplicate 8 MiB boundary window on the default 4 MiB grid + 2 MiB reach. - Replaced the aligned-sizing test with a boundary identity test verifying `Arc::ptr_eq` between `find_root_cbv(cell_end - 256)` and `find(cell_end - 256, 0)` in both call orders. - Deferred aligned loose CBV sizing to a separate follow-up with full GPU-write-to-CBV coherence and default-grid boundary testing, and updated the PR title/description to clarify that savings are per unique avoided loose window (not 6 MiB per call). 2. **Isolated per-address `LOOSE` assertions (@ArturoWolff):** - Replaced global `LOOSE` count/byte snapshots with `loose_covering(addr)` scoped to exclusive 12 MiB `MEM_RESERVE` ranges (yielding two complete 4 MiB cells owned solely by each test), so concurrent unrelated tests cannot interfere (also verified with `--test-threads=4`). 3. **Preserved exact scratch length near window ends, including `VICTORY_WINDOW_REACH_KB=0` (@Ondra97):** - `RootCbv::Scratch(len)` computes `len = unsized_window_left(address, reach(), grow()).min(ROOT_CBV_LEN)`, matching the exact pre-patch `shadow.left(address).min(64 KiB)` without allocating a loose window (e.g., 4080 B at `cell_end - 4096 + 0x10` when `VICTORY_WINDOW_REACH_KB=0`, 64 KiB under default 2 MiB reach). - Added unit coverage for `unsized_window_left` across `reach = 0`, default reach, `grow`, and `u64::MAX`, plus live D3D12 compute readback tests verified under default settings, `VICTORY_WINDOW_REACH_KB=0`, `VICTORY_WINDOW_GROW=1`, `VICTORY_WINDOW_TAILS=1`, and `VICTORY_WINDOW_KB=64`. ### Verification on `93824fba` - `cargo test --locked -j 3 -p victory-gpu --lib -- shadow:: --test-threads=1` — 73 passed, 0 failed, 5 ignored - `cargo test --locked -j 3 -p victory-gpu --lib -- draw:: --test-threads=1` — 26 passed, 0 failed, 2 ignored - `cargo test --locked -j 3 -p victory-gpu --lib -- place_constant --test-threads=1` — 1 passed, 0 failed - `cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=1` under `VICTORY_WINDOW_REACH_KB=0`, `VICTORY_WINDOW_GROW=1`, `VICTORY_WINDOW_TAILS=1`, and `VICTORY_WINDOW_KB=64` — 3 passed, 0 failed each - `cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=4` — 3 passed, 0 failed - `cargo check --locked -j 3 -p victory-gpu --lib --features diagnostics` — passed - `cargo clippy --locked -j 3 -p victory-gpu --lib --tests` — 0 warnings in touched code - `git diff --check` — clean
Ondra97 commented 2026-11-29 13:06:01 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Ondra97 on 2026-11-29T13:06:01Z.


Thanks for narrowing the patch and adding the boundary coverage. I found one remaining scratch-length case on exact head 93824fba.

With VICTORY_WINDOW_GROW=1 and VICTORY_WINDOW_REACH_KB=0, let an unaligned address be 17 bytes before the end of a 4 MiB cell. A preceding sized find(address, 512) can create a grown window that ends 256 KiB beyond the cell. The original find(address, 1) then returns that same backing through holding_in, and shadow.left(address).min(65536) is 65,536 bytes. The new unaligned branch derives the extent of a fresh unsized cell and returns Scratch(17). I checked the arithmetic in a small synthetic Rust fixture. I have not tested those reads in the title. The current fresh-window tests do not cover a previously grown window.

The smallest way to preserve existing behavior seems to be leaving grown windows on the original lookup path for this PR. A regression test could seed the sized lookup, then compare the scratch length with the selected backing's left().

One test issue also remains under REACH_KB=0. The aligned loose case binds a root CBV with 256 bytes left in its resource, while the shader still executes loads for 4,160 bytes. Limiting the CPU assertion to the first 256 bytes still leaves those GPU reads. Could the dispatch or shader bound its loads to the bytes available for each case?

The relevant code is in find_root_cbv and its length calculation, the existing grown lookup, and the aligned readback test.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7256288393 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2063#issuecomment-7256288393). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-11-29T13:06:01Z. --- Thanks for narrowing the patch and adding the boundary coverage. I found one remaining scratch-length case on exact head 93824fba. With VICTORY_WINDOW_GROW=1 and VICTORY_WINDOW_REACH_KB=0, let an unaligned address be 17 bytes before the end of a 4 MiB cell. A preceding sized find(address, 512) can create a grown window that ends 256 KiB beyond the cell. The original find(address, 1) then returns that same backing through holding_in, and shadow.left(address).min(65536) is 65,536 bytes. The new unaligned branch derives the extent of a fresh unsized cell and returns Scratch(17). I checked the arithmetic in a small synthetic Rust fixture. I have not tested those reads in the title. The current fresh-window tests do not cover a previously grown window. The smallest way to preserve existing behavior seems to be leaving grown windows on the original lookup path for this PR. A regression test could seed the sized lookup, then compare the scratch length with the selected backing's left(). One test issue also remains under REACH_KB=0. The aligned loose case binds a root CBV with 256 bytes left in its resource, while the shader still executes loads for 4,160 bytes. Limiting the CPU assertion to the first 256 bytes still leaves those GPU reads. Could the dispatch or shader bound its loads to the bytes available for each case? The relevant code is in [find_root_cbv and its length calculation](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/93824fbac9f05435f4ff5ba7637de844e1177d66/crates/victory-gpu/src/shadow.rs#L7767-L7805), [the existing grown lookup](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/93824fbac9f05435f4ff5ba7637de844e1177d66/crates/victory-gpu/src/shadow.rs#L8529-L8548), and [the aligned readback test](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/93824fbac9f05435f4ff5ba7637de844e1177d66/crates/victory-gpu/src/draw.rs#L9051-L9062).
steven-seagull27 commented 2026-11-29 14:26:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by steven-seagull27 on 2026-11-29T14:26:19Z.


Good catch @Ondra97 — both issues are fixed on the new head d446adbc (d446adbcbe002099da6b84a835465d4992482ff2):

  1. Grown windows kept on the original lookup path (shadow::find_root_cbv):

    • The unaligned RootCbv::Scratch shortcut now runs only when !address.is_multiple_of(256) && !grow(). Under VICTORY_WINDOW_GROW=1, find_root_cbv stays on the existing loose(address, address + 1, true, false) path, so a pre-existing grown window (such as one seeded by find(cell_end - 17, 512) extending 256 KiB past cell_end under VICTORY_WINDOW_GROW=1 + VICTORY_WINDOW_REACH_KB=0) keeps its exact shadow.left(address).min(65536) length.
    • Added regression coverage in shadow::root_cbv_tests seeding find(cell1 - 17, 512) and asserting Arc::ptr_eq against find(cell1 - 17, 1) (and against the seeded backing when reach() == 0), plus left().min(ROOT_CBV_LEN) == 65536.
  2. Test shader GPU loads strictly bounded to available bytes (draw::root_cbv_tests):

    • Added a RootConstants(num32BitConstants=1, b1) dword_count parameter to the synthetic compute shader and sized both the shader bounds check and Dispatch(dword_count.div_ceil(64), 1, 1) to the exact available bytes for each case (e.g. 64 dwords / 256 B for cell1 - 256 under VICTORY_WINDOW_REACH_KB=0, 1020 dwords / 4080 B for cell1 - 4096 + 0x10 under VICTORY_WINDOW_REACH_KB=0, and 1024/1016 dwords for the 4 KiB registered buffer cases).

Verification on d446adbc

  • cargo test --locked -j 3 -p victory-gpu --lib -- shadow:: --test-threads=1 — 73 passed, 0 failed, 5 ignored
  • cargo test --locked -j 3 -p victory-gpu --lib -- draw:: --test-threads=1 — 26 passed, 0 failed, 2 ignored
  • cargo test --locked -j 3 -p victory-gpu --lib -- place_constant --test-threads=1 — 1 passed, 0 failed
  • cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=1 under:
    • VICTORY_WINDOW_REACH_KB=0 — 3 passed, 0 failed
    • VICTORY_WINDOW_GROW=1 — 3 passed, 0 failed
    • VICTORY_WINDOW_GROW=1 + VICTORY_WINDOW_REACH_KB=0 — 3 passed, 0 failed
    • VICTORY_WINDOW_TAILS=1 — 3 passed, 0 failed
    • VICTORY_WINDOW_KB=64 — 3 passed, 0 failed
  • cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=4 — 3 passed, 0 failed
  • cargo clippy --locked -j 3 -p victory-gpu --lib --tests — 0 warnings in touched code
  • git diff --check — clean
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7257302883 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2063#issuecomment-7257302883). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-29T14:26:19Z. --- Good catch @Ondra97 — both issues are fixed on the new head **`d446adbc`** (`d446adbcbe002099da6b84a835465d4992482ff2`): 1. **Grown windows kept on the original lookup path (`shadow::find_root_cbv`):** - The unaligned `RootCbv::Scratch` shortcut now runs only when `!address.is_multiple_of(256) && !grow()`. Under `VICTORY_WINDOW_GROW=1`, `find_root_cbv` stays on the existing `loose(address, address + 1, true, false)` path, so a pre-existing grown window (such as one seeded by `find(cell_end - 17, 512)` extending 256 KiB past `cell_end` under `VICTORY_WINDOW_GROW=1` + `VICTORY_WINDOW_REACH_KB=0`) keeps its exact `shadow.left(address).min(65536)` length. - Added regression coverage in `shadow::root_cbv_tests` seeding `find(cell1 - 17, 512)` and asserting `Arc::ptr_eq` against `find(cell1 - 17, 1)` (and against the seeded backing when `reach() == 0`), plus `left().min(ROOT_CBV_LEN) == 65536`. 2. **Test shader GPU loads strictly bounded to available bytes (`draw::root_cbv_tests`):** - Added a `RootConstants(num32BitConstants=1, b1)` `dword_count` parameter to the synthetic compute shader and sized both the shader bounds check and `Dispatch(dword_count.div_ceil(64), 1, 1)` to the exact available bytes for each case (e.g. `64` dwords / `256` B for `cell1 - 256` under `VICTORY_WINDOW_REACH_KB=0`, `1020` dwords / `4080` B for `cell1 - 4096 + 0x10` under `VICTORY_WINDOW_REACH_KB=0`, and `1024`/`1016` dwords for the 4 KiB registered buffer cases). ### Verification on `d446adbc` - `cargo test --locked -j 3 -p victory-gpu --lib -- shadow:: --test-threads=1` — 73 passed, 0 failed, 5 ignored - `cargo test --locked -j 3 -p victory-gpu --lib -- draw:: --test-threads=1` — 26 passed, 0 failed, 2 ignored - `cargo test --locked -j 3 -p victory-gpu --lib -- place_constant --test-threads=1` — 1 passed, 0 failed - `cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=1` under: - `VICTORY_WINDOW_REACH_KB=0` — 3 passed, 0 failed - `VICTORY_WINDOW_GROW=1` — 3 passed, 0 failed - `VICTORY_WINDOW_GROW=1` + `VICTORY_WINDOW_REACH_KB=0` — 3 passed, 0 failed - `VICTORY_WINDOW_TAILS=1` — 3 passed, 0 failed - `VICTORY_WINDOW_KB=64` — 3 passed, 0 failed - `cargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=4` — 3 passed, 0 failed - `cargo clippy --locked -j 3 -p victory-gpu --lib --tests` — 0 warnings in touched code - `git diff --check` — clean
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!2063
No description provided.