Repository navigation
Sparse VRAM: async ring-buffered uploads, cached write-watch ranges, and coherent headroom - #45
Merged
ivall merged 1 commit intoNov 22, 2026
Conversation
…and coherent headroom Follow-up to PR xcl-dev#40 addressing the two remaining issues noted after merge: 1. Sparse window upload & write-watch overhead (XDefiant ~10 GB in 55 s): - Replace per-submit synchronous staging + wait_idle() in d3d12x::sparse with an asynchronous 64 MiB ring staging buffer, 16 upload command allocators/lists, a reusable Win32 fence event, and a dedicated 1 MiB pre-zeroed tile-clear buffer (zero CPU stall on uploads; title queues GPU-wait on the upload fence as before). - Unify mapped tile tracking into per-tile TileEntry (pool tile + u16 hole bitmask + lazy per-page sent hashes) backed by FxHashMap, replace the serial chunk hash with a 4-way parallel hash + compile-time ZERO_HASHES, and scan directly into a reusable dirty-run scratch buffer without per-page Vec/Box allocations on zero pages. - Batch UpdateTileMappings by pool heap with contiguous run merging in map_tiles/unmap_tiles, and eliminate per-run COM AddRef/Release clones in upload loops. - Cache watch_ranges in title_textures keyed by atomic generation counters (sparse mapped tiles, textures, graphics reservations), reuse thread-local GetWriteWatch/dirty buffers, merge contiguous sparse windows in Uma::watch_regions(), and skip refresh on empty ExecuteCommandLists(0, null). 2. Coherent Window 3 headroom (complementing bb9f0b5's COHERENT_KEPT for textures): - Stop blanket-routing D3D12_HEAP_TYPE_CUSTOM + D3D12_CPU_PAGE_PROPERTY_WRITE_BACK heaps and non-COPY_DEST buffers to coherent Window 3 (on Xbox UMA, CUSTOM+WRITE_BACK is general CPU-cached graphics memory); route them to sparse VRAM and spill oversized/excess readback allocations to sparse VRAM once coherent headroom reaches COHERENT_KEPT, while tracking SPARSE_READBACK so Map(0, NULL, ...) still syncs GPU writes back automatically. - Pack small AllocateUploadMemory (xcl-dev#148) calls into the command list Arena and route large ones to sparse VRAM instead of burning 64 KiB coherent grains per call.
Collaborator
|
Thanks, merged! I tested it on top of current
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):
|
grahamster2
added a commit
to grahamster2/xcl
that referenced
this pull request
Nov 26, 2026
…o memory first A tile listed with no video memory (XCL_SPARSE_LAZY=1) got some at the CPU's first bytes, a buffer placed on it, or a memory operation recorded on a list - and the last only when memory was not short (materialize without force). On tiled resources tier 2 a write to a tile with no memory is dropped: a shader's store, a copy, a fence value the title then waits for. The Series X profile on a 10 GB card hung (DEVICE_HUNG at 209 s, 38111 tiles listed with no memory). Now every route xcl sees a GPU write take asks for the tiles (sparse::gpu_write, taken by the next submit, before the list runs, forced like a placed buffer): - memory operations on a list (immediates, Write32/64, fills, CopyMemoryToMemory, timestamps), as before but forced; - buffer UAVs and their counters (CreateUnorderedAccessView, the view by address xcl-dev#71 with its counter at +0x30); - root UAVs (SetCompute/GraphicsRootUnorderedAccessView, the console lists' xcl-dev#45), from the address as far as the tiles are committed (4 MiB at most); - copies and query resolves into a console buffer (note_copy_into); - dispatches and draws whose console shaders may store to memory (gpu::effects::may_write_memory; unknown: may): their root views and the 64-bit addresses among their root constants (bind_abi, two-pass stages, console lists). A thread asks once for tiles it asked for lately, until tiles are listed again. Bytes the CPU owed a tile (starved) go up at the submit that gives it memory. The sparse windows' line counts "N tiles made resident for GPU writes (M found none)"; the first of each route that met a tile with no memory is logged, and a GPU write that found none is warned of. Tests (sparse::tests, real GPU): a UAV on a lazy range makes it resident (a root UAV too); a copy destination does; a read-only SRV does not, nor a root SRV of shaders that store nothing; effects::may_write_memory tells stores from loads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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(Report: a crash reported during a report write is kept; Config: title_memory in any case (#106) #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.