gpu: route unaligned loose root CBVs to scratch without allocating shadow::LOOSE windows #2063
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!2063
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2063"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@steven-seagull27 on GitHub · 2026-11-29 08:55 UTC · original
steven-seagull27:fix/2024-loose-root-cbv→main· +672 −26 · 2 files · 2 commits · merged 2026-11-30 14:12 UTCRelated: #2024
What it changes
draw::root_view_lenpreviously calledshadow::find(address, 1)for root CBVs (srv == false). Whenaddresswas outside any registered title buffer (shadow::BUFFERS),shadow::find(address, 1)fell through toshadow::loose(address, address + 1, true, false).For unaligned loose root CBVs (
address % 256 != 0outside registeredBUFFERS), everyshadow::LOOSEwindow starts on a>= 64 KiBtitle boundary with a 64 KiB-aligned host GPU virtual address, soshadow.gpu(address) % 256can never be0.root_view_lenimmediately discarded the returnedShadowand fell through toplace_constant/fill_scratch, leaving behind unusedLOOSED3D12 buffers for every unique loose window touched only by unaligned root CBVs (and repeatedly bumpingusedon 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:
shadow::lookup_bufferand addsshadow::find_root_cbv(address) -> Option<RootCbv>(withROOT_CBV_LEN = 1 << 16).BUFFERSwith length 1 first, preserving exact behavior for small (< 64 KiB) registered buffers, unaligned offsets inside registered buffers, and unaligned-start registered buffers whoseshadow.gpu(address)is still 256-byte aligned.BUFFERSmiss with!address.is_multiple_of(256), returnsRootCbv::Scratch(len)without touchingshadow::LOOSE.lenis computed viaunsized_window_left(address, reach(), grow()).min(ROOT_CBV_LEN), preserving the exact pre-patch scratch lengthshadow.left(address).min(64 KiB)near a window end (including whenVICTORY_WINDOW_REACH_KB=0).draw::root_view_lengoes straight toplace_constant/fill_scratch(whoseStep::Fillreads go throughhost::copy_mapped, safely handling uncommitted page boundaries).BUFFERSmiss withaddress.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).draw.rsto usefind_root_cbvforstage.root_cbvsas well.srv == true) and root UAVs unchanged.How it was tested
victory-gpu(isolated per-test 12 MiBMEM_RESERVEvirtual address ranges covering two exclusive 4 MiB cells soLOOSEmembership assertions cannot be affected by concurrent tests).shadow::LOOSEwindows before immediately falling through toplace_constant/fill_scratch.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, andu64::MAXsaturation.shadow::root_cbv_tests::find_root_cbv_unaligned_skips_loose_registered_hits_buffers_and_aligned_shares_backing: verifies noLOOSEwindow is created for unaligned loose root CBVs (including near cell boundaries), exactBUFFERShits and clamping for< 64 KiBaligned-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 sameArc<Shadow>(Arc::ptr_eq) asshadow::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 KiBregistered buffers, and an aligned loose CBV 256 bytes before a 4 MiB cell boundary.cargo testpassed for the crates it touches: yescargo test --locked -j 3 -p victory-gpu --lib -- shadow:: --test-threads=1: 73 passed, 0 failed, 5 ignoredcargo test --locked -j 3 -p victory-gpu --lib -- draw:: --test-threads=1: 26 passed, 0 failed, 2 ignoredcargo test --locked -j 3 -p victory-gpu --lib -- place_constant --test-threads=1: 1 passed, 0 failedcargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=1underVICTORY_WINDOW_REACH_KB=0,VICTORY_WINDOW_GROW=1,VICTORY_WINDOW_TAILS=1, andVICTORY_WINDOW_KB=64: 3 passed, 0 failed in each modecargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=4(parallel isolation check): 3 passed, 0 failedcargo check --locked -j 3 -p victory-gpu --lib --features diagnostics: passedcargo clippy --locked -j 3 -p victory-gpu --lib --tests: 0 warnings in touched codegit diff --check: cleanChecked for overlap
@ArturoWolff on GitHub · 2026-11-29 09:53 UTC · original · edited 2026-11-29 10:15 UTC
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/ base829188e9.With the current default 4 MiB grid and 2 MiB reach, I compiled and ran the unchanged
grid,reach_of,unsized_window,named_windowandwindow_offunctions 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: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
LOOSEcount/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
829188e9on 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).
@Ondra97 on GitHub · 2026-11-29 12:34 UTC · original
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
829188e9logs 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.
gpu: avoid 6 MiB loose shadow windows for unaligned and sized root CBVsto gpu: route unaligned loose root CBVs to scratch without allocating shadow::LOOSE windows5041496920to93824fbac9@Ondra97 on GitHub · 2026-11-29 12:57 UTC · original
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 on GitHub · 2026-11-29 12:59 UTC · original
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
93824fbaAligned loose root CBVs kept on the existing lookup path (@ArturoWolff):
shadow::find_root_cbvnow delegates 256-byte-aligned loose misses straight toloose(address, address + 1, true, false)(identical toshadow::find(address, 0)/find(address, 1)), so aligned loose CBVs share exactArc<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.Arc::ptr_eqbetweenfind_root_cbv(cell_end - 256)andfind(cell_end - 256, 0)in both call orders.Isolated per-address
LOOSEassertions (@ArturoWolff):LOOSEcount/byte snapshots withloose_covering(addr)scoped to exclusive 12 MiBMEM_RESERVEranges (yielding two complete 4 MiB cells owned solely by each test), so concurrent unrelated tests cannot interfere (also verified with--test-threads=4).Preserved exact scratch length near window ends, including
VICTORY_WINDOW_REACH_KB=0(@Ondra97):RootCbv::Scratch(len)computeslen = unsized_window_left(address, reach(), grow()).min(ROOT_CBV_LEN), matching the exact pre-patchshadow.left(address).min(64 KiB)without allocating a loose window (e.g., 4080 B atcell_end - 4096 + 0x10whenVICTORY_WINDOW_REACH_KB=0, 64 KiB under default 2 MiB reach).unsized_window_leftacrossreach = 0, default reach,grow, andu64::MAX, plus live D3D12 compute readback tests verified under default settings,VICTORY_WINDOW_REACH_KB=0,VICTORY_WINDOW_GROW=1,VICTORY_WINDOW_TAILS=1, andVICTORY_WINDOW_KB=64.Verification on
93824fbacargo test --locked -j 3 -p victory-gpu --lib -- shadow:: --test-threads=1— 73 passed, 0 failed, 5 ignoredcargo test --locked -j 3 -p victory-gpu --lib -- draw:: --test-threads=1— 26 passed, 0 failed, 2 ignoredcargo test --locked -j 3 -p victory-gpu --lib -- place_constant --test-threads=1— 1 passed, 0 failedcargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=1underVICTORY_WINDOW_REACH_KB=0,VICTORY_WINDOW_GROW=1,VICTORY_WINDOW_TAILS=1, andVICTORY_WINDOW_KB=64— 3 passed, 0 failed eachcargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=4— 3 passed, 0 failedcargo check --locked -j 3 -p victory-gpu --lib --features diagnostics— passedcargo clippy --locked -j 3 -p victory-gpu --lib --tests— 0 warnings in touched codegit diff --check— clean@Ondra97 on GitHub · 2026-11-29 13:06 UTC · original
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.
@steven-seagull27 on GitHub · 2026-11-29 14:26 UTC · original
Good catch @Ondra97 — both issues are fixed on the new head
d446adbc(d446adbcbe002099da6b84a835465d4992482ff2):Grown windows kept on the original lookup path (
shadow::find_root_cbv):RootCbv::Scratchshortcut now runs only when!address.is_multiple_of(256) && !grow(). UnderVICTORY_WINDOW_GROW=1,find_root_cbvstays on the existingloose(address, address + 1, true, false)path, so a pre-existing grown window (such as one seeded byfind(cell_end - 17, 512)extending 256 KiB pastcell_endunderVICTORY_WINDOW_GROW=1+VICTORY_WINDOW_REACH_KB=0) keeps its exactshadow.left(address).min(65536)length.shadow::root_cbv_testsseedingfind(cell1 - 17, 512)and assertingArc::ptr_eqagainstfind(cell1 - 17, 1)(and against the seeded backing whenreach() == 0), plusleft().min(ROOT_CBV_LEN) == 65536.Test shader GPU loads strictly bounded to available bytes (
draw::root_cbv_tests):RootConstants(num32BitConstants=1, b1)dword_countparameter to the synthetic compute shader and sized both the shader bounds check andDispatch(dword_count.div_ceil(64), 1, 1)to the exact available bytes for each case (e.g.64dwords /256B forcell1 - 256underVICTORY_WINDOW_REACH_KB=0,1020dwords /4080B forcell1 - 4096 + 0x10underVICTORY_WINDOW_REACH_KB=0, and1024/1016dwords for the 4 KiB registered buffer cases).Verification on
d446adbccargo test --locked -j 3 -p victory-gpu --lib -- shadow:: --test-threads=1— 73 passed, 0 failed, 5 ignoredcargo test --locked -j 3 -p victory-gpu --lib -- draw:: --test-threads=1— 26 passed, 0 failed, 2 ignoredcargo test --locked -j 3 -p victory-gpu --lib -- place_constant --test-threads=1— 1 passed, 0 failedcargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=1under:VICTORY_WINDOW_REACH_KB=0— 3 passed, 0 failedVICTORY_WINDOW_GROW=1— 3 passed, 0 failedVICTORY_WINDOW_GROW=1+VICTORY_WINDOW_REACH_KB=0— 3 passed, 0 failedVICTORY_WINDOW_TAILS=1— 3 passed, 0 failedVICTORY_WINDOW_KB=64— 3 passed, 0 failedcargo test --locked -j 3 -p victory-gpu --lib -- root_cbv_tests --test-threads=4— 3 passed, 0 failedcargo clippy --locked -j 3 -p victory-gpu --lib --tests— 0 warnings in touched codegit diff --check— clean