feat(gpu): opt-in D3D12 sparse VA page table for loose windows #260
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
needs-logs
old-names
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!260
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-260"
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?
@Vladimir-Human on GitHub · 2026-11-27 12:45 UTC · original
Vladimir-Human:feat/sparse-va-loose-windows→main· +62938 −5249 · 201 files · 638 commits · closed without mergingSummary
Adds an opt-in (
VICTORY_SPARSE_WINDOWS=1, off by default) D3D12 Hardware Virtual Page Table (crates/victory-gpu/src/sparse_va.rs) backing loose title-memory windows withID3D12Device::CreateReservedResource, pooled 64 KiBID3D12Heaptiles, andID3D12CommandQueue::UpdateTileMappings.Because D3D12 standard buffer tiles are 64 KiB — a 1:1 match with
watch::PAGE— overlapping loose-window views at different base addresses and sizes map to the exact same physical GPU tiles:D3D12_RESOURCE_BARRIER_TYPE_ALIASINGafter tile updates/uploads and UAV activity.D3D12_TILE_RANGE_FLAG_NULL) physical tiles, retired reserved buffers, upload chunks, and empty heaps.Key Implementation Details
crates/victory-gpu/src/sparse_va.rs(new):D3D12_FEATURE_DATA_D3D12_OPTIONS::TiledResourcesTier >= Tier 2); cleanly falls back to standard loose windows whenVICTORY_SPARSE_WINDOWS != 1or unsupported.ID3D12Heaptile allocator (64 KiBtiles,256tiles /16 MiBper heap) with coalescedUpdateTileMappingsruns and fence-tracked reclamation.PendingUpload) flushed into exact-size single-shot upload chunks (zero reads from write-combinedUPLOADmemory), pre-allocated prior to draining queues or committingMappedOnGputransitions, with signal-ordered fence advancement andGetDeviceRemovedReason()-safe waits.copied_attimestamps and cross-window active UAV range tracking (active_uav_ranges+uav_pages), single-read UAV snapshot capture with active-range subtraction, trimmedread_into/put3-way merge preserving title wins on repeated copy-backs, and lock-freehas_active_uav().crates/victory-gpu/src/shadow.rs:LooseBacking::Sparseintomake_loose_backing/build_loose_shadowoutside the globalLOOSEtable lock (preservingplaced>sparse>mapped>shared+cardpriority).Shadow::own_buffer_refs()(2for sparse,1for standard) solet_go_idleevicts unreferenced idle sparse windows and reclaims their tiles while descriptor-pinned windows (refs > 2) stay resident.writes_pending,writes_pending_in,stale_under_writes,merge_under_writes,update,nothing_new, exact range release incopy_back_done, reference-onlyplaced_copy, and 64 KiBPIECEsplitting infind_all.crates/victory-gpu/src/host.rs(+6/-4 lines):crate::sparse_va::has_active_uav()gate inHost::submitsettles rare active sparse UAV flights before submitting the next flight so asyncrelayreadbacks stay ordered onself.queue.crates/victory-gpu/src/lib.rs:#[cfg(windows)] mod sparse_va;.Verification (
VICTORY_D3D12_DEBUG=1,--test-threads=1,0D3D12 debug errors)NVIDIA GeForce RTX 4070 SUPER):TiledResourcesTier = 4, D3D12 debug layer ON.WARP):TiledResourcesTier = 3, D3D12 debug layer ON.rustc 1.98.1,--all-targets --locked -- -D warnings):--features diagnostics: 0 warnings.0D3D12 debug errors):cargo test -p victory-gpu --lib sparse_va:: -- --test-threads=1(default &--features diagnostics): 5/5 passed — covers overlapping alias coherence (CPU upload + GPU compute UAV write observed bit-exact across aliased windows with 0 duplicated tiles), untouched sparse gaps committing 0 tiles, explicit tile unmap/window drop & fence-safe reclamation/recycling, coalesced uploads & early drop, and 7-invariant shadow integration regressions (let_go_idleeviction,placed_copy0 uploads, single-readdeclare_uav_write, cross-window UAV visibility, trimmedread_intoacross a decommitted 4 KiB sub-page, repeated copy-back conflict preservation,find_all64 KiBPIECEsplit, and globalhas_active_uav()).cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 59/59 passed (4 ignored).cargo run -p xtask -- policy:314 files ok;cargo test -p xtask --locked: 11/11 passed.Benchmark vs Separate Loose Windows (
VICTORY_D3D12_DEBUG=1, 56 overlapping views, 144 MiB reserved VA)UpdateTileMappings144 MiB->4,096 KiB(36.0x less,16 MiBpool)24,576 KiB->8,192 KiB(3.00x less)34,738 us->1,379 us(25.2x faster)61,069 us->38,998 us(1.57x faster, 5 frames x 16 passes)2,935 us144 MiB->4,096 KiB(36.0x less,16 MiBpool)24,576 KiB->8,192 KiB(3.00x less)753,229 us->745 us(1,011x faster)926,310 us->601,273 us(1.54x faster, 5 frames x 2 passes)1,195 usDefault Impact
VICTORY_SPARSE_WINDOWS=1. With the flag unset, zero sparse resources are created and default loose-window behavior is unchanged (has_active_uav()is a single relaxed/acquire atomic read returningfalse).@TaynanGT on GitHub · 2026-11-27 12:53 UTC · original
@Vladimir-Human The sparse path needs the tile lifetime and the view lifetime checked together. I’ll look at overlapping windows that share a tile, an unmapped gap and a tile retired behind a fence. Keeping this opt-in gives us a clean baseline while the memory savings are measured in the same scene.
@Vladimir-Human on GitHub · 2026-11-27 12:58 UTC · original
@TaynanGT Here are the exact implementation and test entry points covering those three areas in
1ec48ce9:1. Overlapping windows sharing a canonical 64 KiB tile & cross-window UAV lifetime
crates/victory-gpu/src/sparse_va.rs—ensure_page(L517) allocates at most one 64 KiBID3D12Heaptile per canonicaltitle_pageand maps it into every overlapping window (create_windowL965maps already-committed canonical pages into newly opened overlapping views);flush(L1491, barrier atL1794) emitsD3D12_RESOURCE_BARRIER_TYPE_ALIASINGafter uploads and UAV activity.sparse_va.rs—declare_uav_write(L1211, single-read snapshot + subtraction of all already-active UAV ranges across overlapping windows),finish_uav_ranges(L1316),has_active_uav_in(L1347), paired withcrates/victory-gpu/src/shadow.rswrites_pending/writes_pending_in(L4621-L4639),stale_under_writes/merge_under_writes(L4652-L4715),update(L4961, skips cross-window active UAV spans),copy_back_done(L4530), and the lock-freehas_active_uav()settle gate incrates/victory-gpu/src/host.rs(L6350-L6357).VICTORY_D3D12_DEBUG=1):run_overlapping_views_suite(sparse_va.rs:L2722-L2902, CPU upload + GPU compute UAV write observed bit-exact across 3 aliased windows withcommitted_tilesdeduplicated) andsparse_shadow_integration_regressions_all_seven_invariants(sparse_va.rs:L3540-L3669, overlappingShadowB observing A's active UAV without clobbering GPU bytes).2. Unmapped sparse gaps (
NULLmappings & partial sub-page trim)0physical tiles committed; Tier 2+ guarantees zero-reads and dropped writes); unmapping/teardown emitsD3D12_TILE_RANGE_FLAG_NULL(sparse_va.rs:L1703,unmap_pagesL1896,release_windowL1936).copy_back_range(sparse_va.rs:L1397) trimsread_into/putstrictly tofirst_diff..=last_diff, so untouched unmapped/decommitted 4 KiB sub-pages inside a 64 KiB tile do not fail valid GPU merges.run_sparse_gaps_suite(sparse_va.rs:L2904-L3005, sparse reserved window committing only touched pages while untouched gaps stay at0tiles and read back0on HW + WARP) and Regression 5b (sparse_va.rs:L3633-L3662,VirtualFree(MEM_DECOMMIT)on an untouched 4 KiB sub-page during copy-back).3. Fence-gated tile retirement paired with
let_go_idleview evictionrelease_window(sparse_va.rs:L1936) queuesNULLtile unmaps and defers orphaned physical tiles (pending_retire_tiles) and the reservedID3D12Resource(pending_retire_resources) untilflush()(L1846-L1849) pairs them with theID3D12CommandQueue::Signalfence value (retired_tiles/retired_resources).reclaim(L1980) ->reclaim_completed(L762-L815) only returns tiles/heaps/resources onceID3D12Fence::GetCompletedValue() >= f(andwait_idleL1995checksGetDeviceRemovedReason()before waiting).let_go_idlecoupling:SparseShadowintentionally holds no duplicateID3D12Resourceref (Shadow::own_buffer_refs() == 2atshadow.rs:L4068), solet_go_idle(shadow.rs:L3867-L3938) keeps descriptor-pinned views (refs > 2) resident while evicting idle unpinned views (refs == 2), triggeringDrop for SparseShadow->release_window-> fence-gated reclamation;LooseBacking::Sparse(shadow.rs:L6656) also constructs outside the globalLOOSElock and drops losers outside the lock.run_reclamation_and_recycling_suite(sparse_va.rs:L3007-L3091, explicit tile unmap + fence completion + tile recycling + empty heap release),run_coalesced_upload_and_early_drop_suite(L3093), and Regression 1 (sparse_va.rs:L3510-L3527&L3671-L3705, realLOOSE+let_go_idle_now_testproving pinned view stays resident while unpinned views evict and reclaim tolive_windows == 0, committed_tiles == 0, heap_count == 0).@TaynanGT on GitHub · 2026-11-27 13:08 UTC · original
@Vladimir-Human The overlapping-window readback and active UAV check cover the sharing boundary. I’ll keep the NULL mapping and fence-retirement tests tied to this head. The next measurements should report committed tiles and host memory on the same route, with sparse windows as the only switch.
1ec48ce9eetob77ecacae4@Aniseto on GitHub · 2026-11-28 09:55 UTC · original
Ran the sparse virtual page-table tests at
b77ecacon an NVIDIA Blackwell desktop part:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build.All five tests pass, including the overlapping-alias coherence, untouched-gap and fence-safe reclamation cases. They are CPU-side tests of the opt-in
VICTORY_SPARSE_WINDOWS=1module; I did not enable the switch in a real session. The thread has reports on other NVIDIA cards but no RTX 5070 Ti.Not tested: a title with
VICTORY_SPARSE_WINDOWS=1, theshadow::suite, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
@TaynanGT on GitHub · 2026-11-29 11:23 UTC · original
Thanks for verifying the overlapping-alias, gap and fence reclamation cases on
b77ecac. Sparse windows should remain opt-in until real-session correctness, memory pressure and frame time are compared.@TaynanGT on GitHub · 2026-11-30 17:14 UTC · original
mainhas moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the currentmainand open a new PR; I'll review it there.Pull request closed