Sparse VRAM: async ring-buffered uploads, cached write-watch ranges, and coherent headroom #45
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!45
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/45/head"
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?
@raylitebull on GitHub · 2026-11-22 20:35 UTC · original
raylitebull:sparse-vram-perf-and-coherent-headroom→main· +1295 −317 · 9 files · 1 commits · merged 2026-11-22 20:53 UTCSummary
Follow-up to #40 (rebased onto
5dd2d56, keepingbb9f0b5'sCOHERENT_KEPThandling for committed console textures untouched) addressing the two follow-up items noted after merge:1. Sparse Window Upload & Write-Watch Overhead (
sparse.rs,title_textures.rs,uma.rs,kernelx.rs,real.rs)d3d12x::sparse): replaces the single staging buffer + synchronouswait_idle()(plus per-waitCreateEventW/CloseHandle) on every submit with a 64 MiB ring staging buffer, 16 upload command allocators/lists, a cached reusable Win32 event, and a dedicated 1 MiB pre-zeroed tile-clear buffer (zero_buf). Uploads submit asynchronously without stalling the CPU or holdingSTATEacross GPU completion; title queues continue to GPU-wait ons.fence. Readbacks use a dedicatedrb_alloc/rb_listand still wait before CPU copy-back.mapped,holes, andsentinto a per-tileTileEntry(pool tile +u16hole bitmask + lazy per-page sent hashes) in anFxHashMap(1 lookup per 64 KiB tile instead of 33 SipHash lookups), replaces the serial chunk hash with a 4-way parallel hash + compile-timeZERO_HASHES, skips allocating hash arrays on all-zero pages, scans directly into a reusablescratch_runsbuffer, and removes per-run COMAddRef/Releaseclones in upload loops.UpdateTileMappings: groups tile mappings by pool heap and merges contiguous resource/heap runs inmap_tilesandunmap_tiles.title_textures.rs,uma.rs,kernelx.rs): cacheswatch_rangeskeyed by atomic generation counters (sparse::mapped_gen,TEXTURES_GEN,kernelx::graphics_reservations_gen), reuses thread-localGetWriteWatchand dirty-page buffers, exposesUma::watch_regions()so contiguous sparse windows 0..2 are scanned as a single OS reservation, and skipstitle_textures::refreshon emptyExecuteCommandLists(0, null).2. Coherent Window 3 Headroom (
real.rs,bind.rs,console_list.rs)bb9f0b5'sCOHERENT_KEPT(128 MiB) guard onplace_console_texture.D3D12_HEAP_TYPE_CUSTOM+D3D12_CPU_PAGE_PROPERTY_WRITE_BACKheaps and non-COPY_DESTbuffers to coherent Window 3 (on Xbox UMA this is general CPU-cached graphics memory); only small explicitD3D12_HEAP_TYPE_READBACKheaps/buffers (<= 64 MiB) and small non-UAVCOPY_DESTCUSTOM + WRITE_BACKbuffers (<= 16 MiB) prefer Window 3 whileCOHERENT_KEPTremains free. Larger or excess readback allocations spill cleanly to sparse VRAM and are tracked inSPARSE_READBACKsoMap(0, NULL, ...)still reads back from VRAM automatically.AllocateUploadMemory(#148) calls into the command listArenaand routes large ones to sparse VRAM instead of burning 64 KiB coherent grains per call (updatingconsole_list::free_umato free sparse blocks viasparse::free).bind::countlogging to show bothcoherent used/total MBandsparse used MB.Testing
Verified on Windows 11 with an AMD Radeon RX 9070 XT:
sparse::tests::scan_page_lazy_alloc_and_coalescesparse::tests::ring_planner_handles_wrap_and_large_chunksreal::readback_routing_tests::custom_write_back_only_stays_coherent_for_small_copy_dest_buffersuma::tests::runtime_layout_places_sparse_in_0_to_2_and_committed_in_3(watch_regions()assertion)tests/testtitle/src/gpu.rs:coherent_window_headroom: verifies generalCUSTOM + WRITE_BACKbuffers/heaps and oversizedREADBACKbuffers (> 64 MiB) land in sparse VRAM whileCOPY_DESTbuffers read back automatically onMap(0, NULL, ...).sparse_async_ring_upload_stress: streams 80 MiB across 20 back-to-back pipelined submits (wrapping both the 64 MiB staging ring and 16 upload slots with zero CPU waits between submits) + reused-tilezero_bufclearing. Release run measured 228 MB uploaded across 32 submits in 83 ms upload / 13 ms chunk scan / 0 ms lock wait (~2.9 GB/s sustained across the 64 MiB steady-state slice)..\scripts\test.ps1: 329 lib passed, 0 failed; all 46xcl_testtitlee2e checks +disasm_e2e+rpf_e2epassed.cargo build --release --workspace&cargo test --release --test e2e: clean build, all checks passed.@ivall on GitHub · 2026-11-22 20:55 UTC · original
Thanks, merged! I tested it on top of current
main(which also has4de9016and the launcher menu). It merged cleanly and all tests pass, e2e and your new ones included.mainbeforemain(40.7 vs 37.0 fps; 9.1 vs 8.7 while loading)The picture was checked on screen in all four, and the logs have no errors or skipped draws. The write-watch scan still costs about the same CPU time in XDefiant (~31 s summed over ~47 s), but it no longer holds frames back.
Two things to keep in mind (neither showed up in these titles):
CUSTOM + WRITE_BACKbuffers in the sparse windows. Most of these buffers now live in the sparse windows. The CPU sees what the GPU wrote there only throughMap(a read range, orMap(0, NULL)for the smallCOPY_DESTones). A title that maps a buffer once and then reads GPU results from it every frame (UAV-written counters, readback buffers over 64 MiB) gets stale data. On the console that memory is coherent.wait_forwaits at most 5 s (WaitForSingleObject(self.event, 5000)) before a ring range is reused. After a longer GPU stall the staging memory would be overwritten while it is still being copied; an infinite wait, or skipping reuse when the fence hasn't passed, would be safer.