Repository navigation
D3D12.X: omit VRAM-only sparse tiles and GPU-written textures from write-watch ranges - #2754
Saksukella wants to merge 203 commits into
Conversation
pso_async means a graphics pipeline still being built to go on with its stand-in, which draws nothing, while a worker builds it; only compute pipelines are waited for (a skipped dispatch would leave its outputs unwritten). But graphics_bound and ExecuteIndirect called resolve_wait, which waits for the build - and builds it on the title's thread when no worker has started it. With lazy pipelines that is every graphics pipeline's first draw. On an NVIDIA GPU the retail title of xcl-dev#505 had its threads held 1 - 5 s per draw in the driver's compiler as its world loaded: 25 graphics binds, 33.2 s in all within 25 s (counted with xcl-dev#899's log), and its hang watchdog ended the run. A test report on xcl-dev#889 (RTX 4080) found a title thread held in bind::execute_indirect -> resolve_wait at the abort. Draws and ExecuteIndirect now take their pipeline with resolve_for_bind: a graphics one still being built goes to the workers and the draw uses its stand-in (ExecuteIndirect skips, as it already did for a pending one); a compute one is waited for as before. With this, the same world load logged no graphics wait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…addresses On the console a physical page mapped at several addresses is one page. XCL keeps a page at one address at a time and copies it when the title maps it elsewhere (`move_away`), so the other addresses go stale; a retail title maps its streamed pages into a pool, into the CPU view of a 24 GB reservation and into that reservation's GPU view (xcl-dev#1031). `kernelx::sections` is the base for real aliasing: a block of physical pages is one pagefile-backed SEC_RESERVE section, and a page is mapped as a view of its 64 KiB slice into a placeholder (MapViewOfFile3 with MEM_REPLACE_PLACEHOLDER). Every view of a slice is the same memory and a page takes commit once, when it is committed through any view. Unmapping leaves a placeholder for the next view. Ordinary reserved memory (write-watched if asked) can replace part of a placeholder and go back to one. Nothing calls it yet. Measured in a standalone program on Windows 11 26200 over 200 000 pages: map 2.2 us, unmap 2.75 us, commit 0.9 us a page. GetWriteWatch refuses a range that holds a view (error 87), and one call cannot span two neighbouring reservations either.
The upload of title memory to video memory (`d3d12x::sparse`) and the textures kept in step with title memory learn what the CPU wrote from the write watch, and a view of a section (`kernelx::sections`) cannot be write-watched: GetWriteWatch refuses any range that holds one. `kernelx::guards` keeps the views of a physical page read-only. The first write through any of them faults; a vectored handler makes that view writable, notes the page and lets the write go on. `take_dirty` hands over the pages of every view of each page written – a write through one view is a write to all of them – and guards those views again before their bytes are read, so a later write is caught again and an earlier one is in what is read. Kernel calls do not fault into the handler, they fail: `lazy::ensure`, which XCL already calls before a kernel call or its own code writes title memory, opens the guards there first and counts the write. A view committed by the lazy handler is writable and counts as written. Both take no lock until a view has been watched. Nothing watches a view yet.
… fault A guarded view of a physical page (`kernelx::guards`) is read-only until it is written. Code of XCL's own that writes there faults into the guard and goes on, but a kernel call does not fault: ReadFile into such a view fails. `lazy::ensure` opened the views first, yet the submit thread's `take_dirty` could guard them again before the write – between DirectStorage's check of its destination and the copy, or before the kernel wrote a ReadFile buffer. `guards::open` now returns `Opened`, which keeps its views writable until it is dropped; `take_dirty` uploads a pinned view but does not guard it again, and the end of the write counts as a write. `lazy::ensure` returns it and its callers hold it across their write: the routed ReadFile for a synchronous read, and the destination checks of DirectStorage and the CPU-side bottom-of-pipe writes. An overlapped ReadFile writes after the call returns: its views stay open until its OVERLAPPED is no longer STATUS_PENDING, which `take_dirty` reads without faulting (the title may free it once done). A retail title reads 271 MB that way into the CPU view of its 24 GB reservation 8.5 s after start. `guards::written` counts a page as written through all its views when XCL writes it by page number. Nothing watches a view yet, so nothing changes without views.
…s mapped at Without it XCL keeps a physical page at one address at a time and copies it when the title maps it elsewhere; the console shows the page at every address it is mapped at. A retail title maps its streamed pages into a pool, into the CPU view of a 24 GB reservation and into that reservation's GPU view (xcl-dev#1031). With `XCL_PAGE_ALIAS=1` (`kernelx::alias`): - a block of physical pages is a section (`kernelx::sections`) with a view of its own, through which XCL reads and writes pages by number (DirectStorage); the title never maps a page there; - the title's reservations of 64 KiB pages with no commit (its CPU view, GPU view and pool) are placeholders, and a page mapped there is a view of its slice, guarded (`kernelx::guards`) so that a write through one view is uploaded at all of them; `title_textures` adds those pages to what the write watch found; - a page mapped anywhere else (a placeholder region the title made in a sparse window) is moved there and back with its bytes, as before. Pages are committed on first use as before (`kernelx::lazy`); whether a page is committed is a bit per page: asking Windows walked the rest of a fresh block, and a title mapping 100 000 new pages one at a time took 20 s longer to its first frame. Measured in a traced run of a retail title: 3 blocks (11 360, 2 960 and 99 776 pages), 131 072 map calls in 150 s, nearly all single pages into its plain reservations, none at a page's home, no commit inside them.
…GPU-view page shows Queue method xcl-dev#31 (xcl-dev#29 of the older layout) maps pages of the title's memory into GPU views; it was a stub. Its batches are now decoded and checked against the batch count and the pool, and each 64 KiB page of a GPU view records the pool page it was given and the physical page the title had mapped there (kernelx::mirrors). A bad call records nothing; releasing a view drops its pages. XCL keeps a physical page's data where it was mapped last, and the title maps most streamed pages into the CPU view behind the GPU view too, so `mapped_source` answers where that page is now (`page_now`), else the pool page itself. Each title mapping is remembered per address (Away::title), written once the page is in place and forgotten when the reservation goes; a page freed while its allocation lives is no longer looked for (Away::freed). Nothing reads the record yet: textures are unchanged; the queue logs its counts. (xcl-dev#1031) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`mirrors::decode_batches` checks and decodes one call of the queue's CopyPageMappingsBatchX into (GPU-view page, pool page or unmapped) pairs; `apply_batches` records them as before. No change in behaviour: the next commit maps the decoded pages for real when physical pages alias.
The queue's CopyPageMappingsBatchX maps pool pages into GPU views; on the console a GPU-view page then shows the physical page mapped at its pool page at the time of the call. xcl-dev#1055 decodes the calls and keeps a record of them; with physical pages aliasing (`kernelx::alias`) the GPU view is a reservation of views, so the decoded mappings are made for real: each GPU-view page becomes a view of the physical page mapped at its pool page now, or is unmapped (kind 2, or nothing mapped at the pool page). Textures in the GPU view then read the page at their own address (`title_textures` prefers an address with a physical page mapped), and a write through any view of the page is uploaded at all of them. Without the switch nothing changes: the call is recorded as in xcl-dev#1055.
Each chained dispatch made a scratch buffer for all its groups and kept it until the allocator's reset. A retail title's 176 split programs need 187 KB a group (median), 3 GB for 960x540 pixels in groups of 8x4. At most XCL_SPLIT_SCRATCH_MB (256) of groups now run at once, each piece adding the slab's origin to the group ids, and the chains recorded on one list share the buffer.
In a pixel shader EXEC holds helper lanes (s_wqm), and on a primitive's edge the first lane of EXEC is often one. v_readfirstlane read that lane. An RDNA2 driver (RX 6700 XT, 32.0.21045) gives 0 for everything a helper lane holds once a WaveReadLaneAt ran inside a loop, quad reads included. A loop whose state the console's compiler carries in a vector register (v_mov v, s ... v_readfirstlane s, v) then read 0 back on each pass and ran to the loop budget: a retail title's volumetric light pass took seconds per draw at its world start and Windows reset the GPU (xcl-dev#675). v_readfirstlane now reads the first lane of EXEC that is live (ballot(true), per half in the wave32-in-64 form) when EXEC has one, and the first lane of EXEC as before when it has none. The value is the same: the console's compiler reads the first lane of a value equal in every lane, or of a lane it then removes from EXEC (a waterfall loop). The new GPU test draws that title's list-loop shape on two triangles sharing a diagonal. Without the change, on the RX 6700 XT, 69 of 1024 pixels run the loop 65 536 times (the budget) with wrong results; with it, none, and at most 16 passes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
placed_srv_resource and placed_uav_resource returned uncounted raw ID3D12Resource pointers after dropping TABLE.lock(), and on a concurrent cache-miss race entry(key).or_insert(res) dropped the losing resource inside TABLE.lock() (risking res_release -> format_alias::forget deadlock) while still returning the dropped loser pointer. Furthermore, concurrent eviction via evict_stale_internal_at -> defer_drop_resources -> late_release::hold could synchronously run drain_known(true) and release the PC COM object while dev_create_srv_x was mid-call before r.GetDesc() (crashing inside amdxc64.dll). Fix all three lifetime bugs: - Return owned Option<ID3D12Resource> cloned inside TABLE.lock() from placed_srv_resource and placed_uav_resource (via cache_insert_or_clone), dropping any race loser outside TABLE.lock(), and hold the owned reference across dev_create_srv_x / dev_create_uav_x. - Pin internal PlacedUav/PlacedSrv resources across sync_pair in on_uav_barrier and sync_title_writers. - Drop adopted evicted resources normally in defer_drop_resources (outside TABLE.lock()) so real::res_release cleans up title_textures/vram/format_alias maps on the final ref before deferring the PC Release via late_release::hold. - Reuse a single r.GetDesc() call across dev_create_srv_x. Verified with cargo check -p xcl --lib and cargo test -p xcl --lib -- hle::d3d12x::format_alias::tests --test-threads=1 (5 passed, 0 failed). Assisted-by: Antigravity (Gemini 4 Neon High)
…patch In live world runs ambient.rs tracked TemporalResolve / ReflectionHistory PSOs and captured the 128x128 sky dome, yet ambient_fill_cs and reflect_clamp_cs never dispatched because find_dispatch_views missed the output UAV: - SM 6.6 directly-indexed bindless heaps bind the view heap via SetDescriptorHeaps (s.heaps[0]) rather than Param::Table, leaving tables empty. - ExecuteIndirect compute dispatches (both chained split and direct) never called ambient::after_compute_dispatch, and matches_dispatch_target rejected indirect/1D dispatches. - matches_dispatch_target checked the resource format (often R16G16B16A16_TYPELESS) instead of the concrete UAV view format (R16G16B16A16_FLOAT / R11G11B10_FLOAT / R32G32B32A32_FLOAT). - VIEW_SLOTS was keyed only by slot.index, colliding across CPU-only view heaps before CopyDescriptors copied them to the >1.24M-slot shader-visible heap, while the 1<<20 index cap and 256-byte CBV scan truncated high slots and larger pass CBVs. Pass s.heaps[0] into find_dispatch_views, hook ExecuteIndirect compute dispatches, index ViewSlots by both unique slot.at and hosted GLOBAL index, raise the slot cap to 2_000_000 and CBV scan to 2048 B, match by concrete UAV view format with DepthOrArraySize == 1 guard, rank candidates by dispatch grid match, and log first-4 diagnostic misses. Verified with cargo check -p xcl --lib and hle::d3d12x::ambient::tests (5 passed, 0 failed). Assisted-by: Antigravity (Gemini 4 Neon High)
…adbacks Two defensive memory/resource-lifetime fixes: - kernelx.rs / uma.rs: clean up AWAY physical-page mappings, mirrors, and title mapping records on coherent UMA VirtualFree (MEM_DECOMMIT and MEM_RELEASE), matching sparse and plain VirtualFree so freed/reused coherent blocks never retain dangling AWAY entries. Add Uma::allocation_at and extend virtual_free_unmaps_away_pages_in_plain_and_sparse_reservations to cover coherent UMA MEM_DECOMMIT and MEM_RELEASE. - real.rs: call cpu_writes::unregister_water_readback in res_release so released or recycled placed textures never retain stale water-readback entries. Assisted-by: Antigravity (Gemini 4 Neon High)
…raphics once, and guard unbuilt ExecuteIndirect - Keep non-spared memory-writing producer compute pipelines (`!spared && !bvh_traversal`) exempt from the per-frame `XCL_PSO_FRAME_BUDGET_MS` skip cutoff so world-entry dispatches never leave title memory/tables uninitialized; prioritize wanted producer compute ahead of wanted graphics in `PsoQueue::pop`, and run non-deprioritized producer compute inline when no worker has started it yet. - Restrict `XCL_PSO_FRAME_BUDGET_MS` skipping to graphics pipelines and stamp `waited_frame` on `Pending` so an unready slow graphics PSO stalls at most one frame while workers finish compiling it in the background. - Skip `list_x::defer` for `spared`/`bvh_traversal` compute PSOs and make `FrameDeferCap` slot reservation atomic (`try_reserve`/`release`) so concurrent threads cannot overshoot the per-frame deferred segment cap (producer dispatches past the cap fall through to `resolve_wait` instead of being dropped). - Add `pso_async::bound_unbuilt(raw_pso, pso)` for `execute_indirect` and `dispatch_mesh` so a pipeline that finishes building right after `resolve_for_bind` returned the stand-in cannot slip into the raw PC call with a mismatched root signature. Assisted-by: Antigravity (Gemini 4 Neon High)
…8x4 grids in ambient Wave 16e diagnostics showed both TemporalResolve ([320, 360, 1]) and ReflectionHistory ([0, 0, 0]) reached ambient::after_compute_dispatch with tables=3, view_heap=0x4c610000, indices=16 (meaning zero root constants/CBVs and all bindings inside the two Param::Table descriptor tables). Fix all four remaining lookup gaps: - Decode CBV V# buffer descriptors (w3 >> 28 < 8, dst_sel 0xFAC) in slots 0..32 of every bound Param::Table and scan their readable constant-buffer bytes (up to 2048 B) for bindless view-heap indices. - Probe direct image T# descriptors across slots 0..64 of every bound Param::Table (previously capped at 0..16). - Resolve DXGI_FORMAT_UNKNOWN (0) in dev_create_uav_x and dev_create_srv_x to rd.Format.0 before calling ambient::note_descriptor so views that inherit the resource format are never dropped. - Score Wave32 [8, 4, 1] and [4, 2, 1] dispatch grids alongside [8, 8, 1] and lower min_w/min_h to (groups/2).max(64) so [320, 360, 1] matches 2560x1440, 1280x720, and half-res probe targets. Verified with cargo check -p xcl --lib and hle::d3d12x::ambient::tests (5 passed, 0 failed). Assisted-by: Antigravity (Gemini 4 Neon High)
luckyteagirl
left a comment
There was a problem hiding this comment.
On 60bc047f, mapped_ranges() now excludes an existing tile while entry.holes == 0xFFFF and caches that empty result in s.runs. The new invalidation in drain_lazy_commits() covers VEH commits, but the ordinary committed() → commit_range() path can also clear a hole bit on a tile that is already in s.mapped. In that case ensure_mapped() has no new entry to map, and commit_range() changes entry.holes without clearing s.runs or incrementing MAPPED_GEN. title_textures::cached_watch_ranges() can therefore keep omitting the newly CPU-backed tile on later submits, missing its CPU dirty pages until some unrelated mapping changes.
I reproduced the cache transition with a small CPU harness that compiles the exact commit_range, mapped_ranges, and new watchable_tile_runs functions from this head, with minimal state/ensure_mapped stubs for one already-mapped tile. After priming an all-holes tile and committing one 4 KiB page, the base b5c0275 still returned its watch range (exit 0); this head returned [] with holes=0xfffe and generation unchanged (assertion failure, exit 101). This isolates the cache behavior; it does not reproduce a D3D12 title failure.
Could the explicit commit path invalidate both the cached runs and generation when a tile becomes watchable? A regression test should prime mapped_ranges() before committing part of a VRAM-only tile, then assert the next range and generation include it. Codex (GPT-6.2 Sol and GPT-6.2 Astra) reviewed this exact head and CPU differential.
|
Independent test report: PR #2754 at head Hardware / toolchain
Tested (
Regression run
Not tested
AI use
|
|
Good catch @luckyteagirl — fixed in |
|
Independent Windows/NVIDIA check of PR #2754 head
I also attempted Not tested: paired clean-commit retail smoke, the time saved by AI use: Codex (GPT-6.2 Sol) ran the Windows checks, compared the focused failure with the base, and drafted this report. |
|
Tested - retail title on native Windows AMD RDNA2, PR head Tool: OpenCode with DeepSeek V4.1 Flash 1017
The target does not move on this title: the ~1.9M dirty pages are in tiles with CPU-committed Note: the PR is Not tested: world/FPS (not reached), NVIDIA/Intel GPUs, full workspace, debug build. AI use: OpenCode with DeepSeek V4.1 Flash 1017 ran the tests and the game runs, read the logs and wrote this comment; the counts, write-watch lines and merge check were verified against the logs and git. |
…nges Ports the sparse half of upstream PR #2754: 60bc047 ("omit VRAM-only sparse tiles and GPU-written textures from write-watch ranges") and its follow-up 891c97a ("invalidate sparse watch ranges when commit_range unmasks a VRAM-only tile"). A tile of a sparse window whose 16 pages are all holes (holes == 0xFFFF) has no page the CPU can write: the title has not committed one there. The upload before a submit already skips hole pages, so watching such a tile only had the looks for CPU writes walk memory nothing could have written. In this tree such tiles stay in `mapped` for a buffer placed over reserved memory (`buffer_tiles` maps its tiles with the holes Windows reports), and for a moment in each commit (`ensure_listed`, a tile over a CPU view committed at its own address). `State::runs` (what `mapped_ranges` returns for the window's own tiles) now holds only tiles with a page committed: `ensure_mapped` and `ensure_listed` leave an all-holes tile out, and `commit_range` clears holes through `unmask_committed_holes`, which puts a tile that had none committed into `runs` and bumps MAPPED_GEN, so the next submit makes its watched ranges again (`watch_key`). Write-watch bits outside the watched ranges are never reset, so what the CPU writes after the commit is found by the next look; `committed` also makes the blocks hot (`mark_hot`). A tile that becomes all holes on a decommit already left `mapped` and `runs` (`decommit_tiles`). Adapted, not cherry-picked: upstream rebuilds its runs from all of `mapped` when they are asked for and filters there; this tree keeps `runs` up to date incrementally (a retail title has ~150,000 tiles), so the filter sits where tiles are listed and committed. The two upstream commits are one here: with only the first, a commit on an all-holes tile would never be watched. Upstream's lazy VEH commit queue (`drain_lazy_commits`, `alloc_vram_only`) does not exist in this tree, so that part does not apply: holes are only cleared by `commit_range`. Ranges under WATCH_GAP (64 MiB) apart are still scanned as one, so this shrinks the looks only where the tiles left out open such a gap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ports the texture half of upstream PR #2754 (60bc047, "omit VRAM-only sparse tiles and GPU-written textures from write-watch ranges"). A texture the title's GPU work wrote (`gpu_written`) is never uploaded for a CPU write again, so watching its source only cost the looks for CPU writes. Upstream builds the textures' part of the watched ranges from every texture that is not GPU-written (`watchable_ranges`). Here that part is `Table::coarse`, 16 MiB blocks -> how many linked textures cover them, so the count now leaves GPU-written textures out: `link_src` and `unlink_src` are told whether the texture counts, `Table::mark_gpu_written` (from `note_gpu_write` and `submitted`) takes a linked one out, and one that `mapping_changed` gives back to the CPU counts again. A block whose count reaches 0 bumps COARSE_GEN, which is in `watch_key`, so the ranges are made again at the next submit; upstream's TEXTURES_GEN bump has no reader here. `src_pieces` is unchanged: a GPU-written texture is still found by its written pages and skipped there, as before. In this tree GPU-written textures were already skipped before the compare, so the saving is in the looks, not in the texture compare and upload. A block stays watched while a texture there that is not GPU-written, a sparse tile with a committed page, or a shown page lies in it, and ranges under WATCH_GAP apart are still one scan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port of xcl-dev#2754 by Saksukella (amd-dev commits 60bc047 and 891c97a) to main, re-implemented for main's sparse runs and coarse texture blocks; the idea and the rules are theirs. Sparse windows: a window's own tile with video memory and no CPU page (holes == 0xFFFF) takes no CPU write, yet main added it to State::runs at ensure_listed (XCL_SPARSE_LAZY), ensure_mapped (a placed buffer over uncommitted pages) and the CPU-view unlink, so write-watch scanned it. Such a tile now enters the runs at its first CPU page (commit_range_with_protection, with a MAPPED_GEN bump). Tiles over a CPU view (src != 0) are tracked by src_runs and unchanged. Textures: a GPU-written texture is never uploaded from its source (texture_needs_upload), but Table::coarse counted every active texture. It now counts only those that are not gpu_written, and a texture moves in or out where that flips: a published GPU write, a mapping change that undoes one (recheck_gpu_view_sources), and a download that makes the CPU's copy current. GPU-owned textures (gpu_written from the start) are no longer watched at all. Shadowed entries never count. Risk: a CPU commit XCL never sees leaves its tile unwatched, where main watched it from the GPU mapping. A block that comes back into the watched ranges may report pages written while it was out; that costs at most one extra upload of a texture there, as main's always-watched block would. Tests: a_tile_with_no_cpu_page_is_not_watched, a_tile_with_no_cpu_page_is_watched_from_its_first_commit (GPU), gpu_written_textures_leave_the_watched_blocks_until_they_are_current_again; the runs_of helper follows the new invariant. Co-authored-by: Saksukella <98151720+Saksukella@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Triage note: this no longer merges with current Worth knowing before you spend time on a rebase: #3242 is a port of this and #2891 to current Flagging it so the choice is yours; I have no stake in which route is used, only that one of them can be built and tested. AI use: an agent posted this triage note. |
|
This PR targets AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
What is in it
crates/xcl/src/hle/d3d12x/sparse.rs:watchable_tile_runs(mapped)and exclude VRAM-only tiles (holes == 0xFFFF, never CPU-committed) frommapped_ranges()soGetWriteWatchskips purely GPU-resident sparse tiles.drain_lazy_commits(), invalidateself.runsand bumpMAPPED_GENwhen a lazily CPU-committed tile transitions offholes == 0xFFFF.drain_lazy_commits_if_pending()(zero-lockAcquirefast path when no lazy commits are pending) sorefresh_once()reflects newly CPU-committed tiles on the very first submit without a 1-submit delay.watchable_tile_runs_omits_vram_only_holes_until_unmasked.crates/xcl/src/hle/d3d12x/title_textures.rs:Table::watchable_ranges(&self)excludinge.gpu_writtenrender targets / UAV textures fromcached_watch_ranges(), bumpTEXTURES_GENinnote_gpu_write()when a texture becomes GPU-written, and callsparse::drain_lazy_commits_if_pending()beforecached_watch_ranges(u)inrefresh_once().watchable_ranges_excludes_gpu_written_textures.amd-dev(wherealloc_vram_only/drain_lazy_commitslive).Tested
32.0.32029.2010), 24-thread x86_64 CPU, 32 GB RAM, Windows;rustc 1.100.0 (0ef1bc386 2026-11-09); debug (tests) and release (xcl.exe).cargo test -p xcl --lib watchable_tile_runs_omits_vram_only_holes_until_unmasked: 1 passed, 0 failed (0.00s).cargo test -p xcl --lib watchable_ranges_excludes_gpu_written_textures: 1 passed, 0 failed (0.00s).Regression run
Not tested
AI use
GetWriteWatchrange collection, catching the first-submitdrain_lazy_commitsordering hazard, writing the patch and unit tests, and running local tests and smoke verification. All diffs and measurements were verified locally on hardware.