Repository navigation
DXIL: fix compact SGPR liveness for RMW/CMOV SALU and Wave32 masks - #2604
real-alponzo wants to merge 195 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 #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 #899's log), and its hang watchdog ended the run. A test report on #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 (#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 (#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 #31 (#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. (#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. #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 #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 (#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>
sparse::State::queue is a D3D12_COMMAND_LIST_TYPE_DIRECT queue, but take_readback_job created its pooled allocator and command list as D3D12_COMMAND_LIST_TYPE_COPY. Submitting a COPY command list to a DIRECT queue immediately triggers DXGI_ERROR_INVALID_CALL (0x887a0001). Create ReadbackJob allocators/lists as D3D12_COMMAND_LIST_TYPE_DIRECT matching State::queue, and skip returning/resetting a ReadbackJob if its fence wait times out so an in-flight allocator is never reused early. Assisted-by: Antigravity (Gemini 4 Neon High)
…sync
Implement indirect Draw/DrawIndexed safety caps (#408) and eliminate
per-draw CPU lock contention and heap allocations across command-list
recording and descriptor lookups (#395):
- Indirect draw caps (device_x.rs, bind.rs): track Draw/DrawIndexed
command signatures in DRAW_SIGS (RwLock) and guard indirect draw
argument buffers via hoisted PRELUDE_DRAW_GUARD_* (or inline
GUARD_DRAW_ARGS_* when prelude hoisting is blocked), zeroing any
record with verts == 0, instances == 0, verts >= 2^23 (8,388,608),
or verts * instances > 2^26 (67,108,864) using overflow-safe u32
arithmetic. Opt-out via XCL_INDIRECT_DRAW_GUARD=0 or
XCL_INDIRECT_GUARD=0. Indirect dispatch guards already enforce
<= 2^22 total groups with X > 65,535 folding into Y.
- Lock contention & per-stage bind cache (bind.rs, list_x.rs):
- Shard bind::STATES across 64 Mutex shards and switch command
signature tables (ROOT_SIGNATURES, DISPATCH_SIGNATURES,
DISPATCH_ONLY, DISPATCH_MESH_SIGS, DRAW_SIGS) and list_x::MIRRORS
to RwLock so parallel recording threads do not serialize.
- Zero-allocation stack [u32; KERNEL_SGPRS] io builders (fill_io_gfx,
fill_io_compute, fill_io_two_pass), zero-allocation little-endian
Set*Root32BitConstants, reusable dummy_table_p when all root args
fit inline, and idempotent Set*RootSignature preserving io_cache
and Vec capacity.
- Cache per-list heaps_ensured, lazily cached vram_io_dev, and
pso_abi_cache (skipping repeated pso_async/real/list_x/GLOBAL
lookups on consecutive draws with the same PSO).
- Fix list_x::skip_redundant_pso_bind so bind_abi re-binding an
already-active resolved PC PSO hits the cache instead of
re-emitting SetPipelineState + DRED markers on every async PSO.
- Reusable dirty-page bitset & descriptor lookup (list_x.rs,
console_heap.rs, real.rs):
- Replace per-draw Vec<bool> in list_x::copy_written with a reusable
thread-local Vec<u64> bitset and word-wise run scanning.
- Keep console_heap::HEAPS sorted for O(log N) partition_point
lookups, add single-lock slot_pair for copy_console_slots,
zero-refcount global_*_heap_raw accessors, and smallest_failed
allocation short-circuiting on full shared heaps.
Assisted-by: Antigravity (Gemini 4 Neon High)
Break any active 256-slot InlineGuardBatch on graphics draws (DrawInstanced, DrawIndexedInstanced, DispatchMesh, graphics ExecuteIndirect) and mark prelude_blocked + close inline_guard on Enhanced/UAV barriers (uav_barrier_x and UAV resource_barrier_x) so memory-writing graphics shaders never race with a pre-draw indirect guard batch or hoisted prelude (#424). Also gate test-only indirect draw limit constants with #[cfg(test)] for zero warnings. Assisted-by: Antigravity (Gemini 4 Neon High)
Complete Win11 scheduling hardening in kernelx/host/real: - Export guest SetThreadPriority in kernelx.rs and floor guest priorities below THREAD_PRIORITY_BELOW_NORMAL (IDLE / LOWEST) to BELOW_NORMAL unless XCL_PRIORITY=0, preventing Windows 11 hybrid E-core starvation of title streaming/background threads while leaving internal XCL pso_async workers (calling win32 directly) untouched. - Add winmm timeBeginPeriod(1) alongside NtSetTimerResolution(finest, 1) in kernelx::fine_timer(), and add idempotent restore_fine_timer() called on normal exit (host.rs) and forced/timed exit (real::end_title) so both timer-resolution requests are cleanly released on shutdown. - Add unit tests covering priority flooring (pure + live guest hook) and idempotent timer-resolution restoration. Assisted-by: Antigravity (Gemini 4 Neon High)
…ze deferred submits Give graphics and compute pipelines independent 12 s per-frame wait windows (XCL_PSO_FRAME_BUDGET_MS, default 12000 ms; 0 = skip immediately, off = disabled). Builds run on prioritized wanted xcl-pso-* workers so title threads always wake when a frame's window expires; once spent, remaining unready draws or dispatches for that kind return the stand-in for the current frame and retry with a fresh window on the next frame instead of stalling PresentX into title render watchdogs or dropping fast cold graphics draws permanently. Also mark deferred submits wanted immediately in need_by_submit so DXC/big-compile gates and preload workers prioritize them right away. Assisted-by: Antigravity (Gemini 4 Neon High)
…ure caches (#2578) Adapt two cache-safe stability fixes cleanly onto origin/amd-dev (bf02341): - #2577 (real.rs, shaders.rs): record the chosen adapter's PCI vendor ID in driver_cache::note_vendor() and disable on-disk .pso driver blobs on AMD (0x1002) unless XCL_PSO_DISK_CACHE=1, avoiding device removals from stale 954-byte driver cache stubs written before a crash/kill (#2512). Adds driver_cache::tests::blobs_are_kept_on_disk_unless_they_are_references. - #2578 (title_textures.rs): return all retired resource pointers from Table::retire_range() so retire_overlapping() evicts LAST_CONTENT and STREAM_RECHECK for every retired texture (not only placed unmap targets). Assisted-by: Antigravity (Gemini 4 Neon High)
…access (#2582) Fix #2582 (0xc0000005 CPU write AV inside sparse UMA windows on buffers backed by OutsideBufferTable / sparse::alloc_vram_only): - place_at_title_address stored alloc_vram_only's uncommitted sparse VA (holes = 0xFFFF, MEM_RESERVE only) in UMA_BUFFERS, so GetGPUVirtualAddress and Map handed that uncommitted VA back to the title. When the title later CPU-wrote through it (e.g. clearing a 128x0x5c0 table), Windows raised 0xc0000005. - Mark alloc_vram_only 64 KiB pages with kernelx::lazy::mark (0 upfront CPU commit, GPU-only buffers keep holes = 0xFFFF and never clobber UAV writes) and unmark + MEM_DECOMMIT them cleanly in free_vram_only. - When the title first CPU-touches a page, kernelx::lazy::commit commits it and queues it via sparse::note_lazy_commit (without locking sparse::STATE inside the VEH); before_execute, readback_now, readback_after_execute, and decommit_range drain LAZY_COMMITS to clear entry.holes without touching to_zero so only CPU-written 4 KiB pages upload to VRAM. - In real::res_map, call kernelx::lazy::ensure(p, bytes) before readback_now so Map() on a lazy sparse buffer commits pages before VRAM->CPU copy. - Add regression test lazy_commit_clears_vram_only_holes_without_clobbering_to_zero. Assisted-by: Antigravity (Gemini 4 Neon High)
…ts, and keep split whole builds async Eliminate the remaining multi-second stalls observed past the 12 s per-frame pipeline wait window on cold/warm world frames: - Track in-flight wall-clock waits (`active_waiters` / `active_since`) in `pso_async::FrameWaitBudget` so staggered concurrent title threads share one hard wall-clock ceiling per kind per frame instead of each getting a fresh 12 s window (applied to both `FRAME_BUDGET_GFX`/`FRAME_BUDGET_CS` and `FRAME_WAIT`). - Skip deferring pending compute dispatches to submit in `list_x::defer` when `XCL_PSO_WAIT_MS` is set (#2581), when the current frame's compute wait window is already spent, or once 16 deferred segments have already been allocated on the current frame (prevents 512+ deferred segments and command-allocator/RAM churn). - Never compile `Chain::whole()` synchronously on a title/submit thread inside `dispatch_chain::dispatch` when scratch allocation fails under memory pressure or missing backing allocator: kick off `start_whole_async()` and return an error so the dispatch is skipped cleanly until the background whole build finishes, matching `whole_nonblocking`. Assisted-by: Antigravity (Gemini 4 Neon High)
inst_sreg_scc_use_def now treats all S_CMOV* as conditional writes and S_ADDK_I32/S_MULK_I32/S_BITSET* as read-modify-write on SDST, and clamps Wave32 VALU 64-bit mask defs to 1 SGPR so live s[v+1] slots are not killed. Assisted-by: Antigravity (Gemini 4 Neon)
|
Verification on RTX 3060 Ti (Windows 11), head merged with current
Note the branch carries ~19 commits on top of — Devin |
|
NVIDIA wave32-only run (listed as untested), plus an RX 9070 XT: the new test passes on both, and nothing else changes against Head
On both cards, the only result change is the new
Not tested: Intel, Linux / Wine, a title. |
|
merge-check |
|
Releasing my merge-check claim: current This PR can be closed as already applied on |
|
merge-check claim |
|
merge-check |
… stores The compact form lowers each class of identical blocks once, but a block only joins a class when everything in it matches, and every class stores all SGPRs and SCC it wrote back to their slots. In large console programs the same buffer / SMEM / image access sits in many blocks with different ALU around it, so its long lowering was emitted once per block. On large programs (64 blocks or more): - a memory instruction that occurs more than once becomes a micro-block of its own, lowered once for all its occurrences; pure no-ops (s_nop, s_waitcnt*, s_clause, ...) are left out, and the empty jump blocks that leaves are bypassed; - blocks that differ only in one 32-bit literal, or only in where an s_getpc_b64 sits, share a class and read the literal / block PC from a packed table, when that saves at least 64 classes; - the successor field can index a pool of distinct taken targets (fallthrough = 0) when that is smaller than inline block numbers or offset pairs; the table limit rises from 12288 to 32768 words; - a backward liveness over s0..s105 and SCC gives each class the union of its blocks' live-out sets, and a class stores only what is live; the same liveness strips far-jump veneers (s_getpc_b64 + s_add_u32 + s_addc_u32 feeding a resolved s_setpc_b64) whose registers and SCC are dead at the target. Kernel-mode programs (the tests' ABI) keep every register live at the end. The use / def sets are conservative: s_movrel* reads every SGPR, conditional and read-modify-write SALU (s_cmov*, s_addk, s_mulk, s_bitset*) read their destination and s_cmov* does not kill it, and a wave32 VALU mask write defines only its low SGPR (from 33d1222, open as #2604). New here: SDWA sources with their S0 / S1 bit set are SGPR uses, as Lw::sources reads them; the ported code missed S1, so a v_add_nc_u32 sdwa reading s20 through VSRC1 left s20 dead and its store out. The micro-blocks and the liveness are one commit: on an RTX 5070 Ti the micro-blocks alone make the retail title's largest compute program (95cc13288a27a96e) one the driver refuses (E_OUTOFMEMORY); with the liveness it builds, and goes from 804 KB to 258 KB of DXIL. Ported from the compact-form and liveness parts of amd-dev's f089a9d (raylitebull, cherry-picked there from 46aecbf, Assisted-by: Antigravity (Gemini 4 Neon High)) and 33d1222 (Alp Pesen, Assisted-by: Antigravity (Gemini 4 Neon)). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Only the top commit (281d8f0) belongs to this PR. The other 211 commits (+34k lines) come from a fork branch that is also the base of #2605 and several other open PRs. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Fixes two SGPR liveness bugs in
amd-dev's compact DXIL micro-block emitter (crates/xcl/src/gpu/dxil/compact.rs):use/ killed indef:inst_sreg_scc_use_defonly treatedS_CMOVK_I32as a conditional write. Inrdna2_spec.rs,S_CMOV_B32,S_CMOV_B64,S_ADDK_I32,S_MULK_I32,S_BITSET0_B32/B64, andS_BITSET1_B32/B64declareSDSTwithinput: false, output: true, so predecessor micro-blocks could elide storingSDSTto its alloca slot and feed stale/zero data into the successor.s[v + 1]: VALU mask writers (V_CMP_*,V_ADD_CO_*, etc.) declaresize: 64inrdna2_spec.rs, but in Wave32 (!wave64) they only write the low SGPR and leaves[v + 1]intact.What is in it
lw.wave64intocompute_live_outandinst_sreg_scc_use_defincrates/xcl/src/gpu/dxil/compact.rs.S_CMOV*as conditional writes (addSDSTtou, omit fromdef) andS_ADDK_I32/S_MULK_I32/S_BITSET{0,1}_B{32,64}as read-modify-write (addSDSTto bothuanddef).defwidth to 1 SGPR for non-S_*64-bit mask outputs when!wave64.cmov_and_rmw_salu_read_sdst_and_wave32_valu_keeps_hi_sgprincompact::liveness_tests.Tested
rustc 1.100.0, DXC1.9.2602.17.cargo test -p xcl --lib gpu::dxil::compact: 12 passed, 0 failed, 0 ignored, 0 skipped.Not tested
Regression run
AI use
amd-devcompact.rsliveness, implemented the fix and unit test, ran the tests and pairedscripts/smoke.ps1runs, and drafted this PR description.