D3D12.X: shaders read buffers in a GPU view of the title's memory #2384
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!2384
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2384/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?
@ivall on GitHub · 2026-11-25 17:35 UTC · original
xcl-dev:gpu-view-buffers→main· +426 −8 · 5 files · 1 commits · closed without mergingA title reserves 64 KiB pages twice, once for the CPU and once with no CPU access, and gives the GPU addresses of the second. Those lie outside the memory windows, so a shader reads zeros there. With
XCL_GPU_VIEW_BUFFERS=1(off by default) the tiles a buffer view covers are mapped in free address space of a sparse window and kept in step with the title's pages, and the view's address is replaced by the window's.Off by default, so nothing changes without the switch. Not a fix for a device removal: see Not tested.
What is in it
hle/d3d12x/sparse/gpu_view.rs(new, half of it tests): the mirrors (base_for,sync),XCL_GPU_VIEW_MB(512) as their bound, views over 64 MiB left as they arehle/d3d12x/sparse.rs:upload_runstakes the reader of the bytes; the mirrors are brought up to date before a submithle/d3d12x/real.rs,bind.rs: constant buffer views, buffer SRVs and root descriptors ask for the window's address; UAVs keep theirs (a write through a mirror is lost)hle/d3d12x/title_textures.rs:mirror_sourcevisible to the new module426 lines added, about half are tests and comments. It is one change: the mirror has no use without the three places that ask for it.
Related, not stacked: #637 mirrors buffers outside unified memory into it (vertex and index buffers), #1102 and #1514 are about textures in GPU views.
Tested
main68a284a.cargo test --workspace --no-fail-fast -- --test-threads=4: 1289 passed, 3 failed, 46 ignored (7SKIPPEDnotices). The three fail the same way without this change:fuzz_validate_and_gpu_1/_3(#2115) anda_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, which is red onmainitself.XCL_GPU_VIEW_BUFFERS=1 cargo test -p xcl --lib -- gpu_view hle::d3d12x --test-threads=4: 232 passed, 0 failed, 2 ignored.XCL_GPU_VIEW_MB=1536: 0 views refused, 20 464 tiles mirrored (1 279 MB; 1 591 MB sent in 8 192 submits), the world's frames went on for about 24 s and the picture was flat grey with silhouettes of the geometry.Regression run
xcl-smokeblock names the GPU, and this account does not publish that; the maintainer can run it before a merge. This PR is a draft because of it. (claude is retarded)Not tested
0x887a0006) after the world's frames, also with the mirror at 1 536 MB, so this does not fix that and may not be related to it.AI use
@ClosetPie107 on GitHub · 2026-11-25 18:05 UTC · original
Independent AMD RDNA4 / Linux (RADV, native wave64) test report for head
d2306d7b80fc5d16e84e7fffd4890de0e038c20d(onmain68a284a).Hardware & environment
experimental-11.0-20261112),vkd3d-protonmasterec207194(3.2.0) +dxil-spirvb540c8a2+ relaxed-vtable patch (-Db_ndebug=true), DXVKv3.1.1-209, DXC1.9.2609.5, Rustx86_64-pc-windows-gnu(debug for tests, release for retail)Unit / GPU tests (
XCL_GPU_VIEW_BUFFERS=1,XCL_REQUIRE_GPU=wave64,VKD3D_CONFIG=ignore_shared_fence,--test-threads=1)gpu_view: 6 passed, 0 failed, 0 ignored (0 skipped)hle::d3d12x::sparse: 17 passed, 0 failed, 1 ignored (0 skipped)hle::d3d12x::real: 58 passed, 0 failed, 0 ignored (0 skipped)Retail title (1.0.2.1): AB-BA deadlock at ~20 s with
XCL_GPU_VIEW_BUFFERS=1Same flags (
XCL_DIRECT_DXIL=1,XCL_TEXTURE_LEVEL_PAGES=1,XCL_PSO_WAIT_MS=50,XCL_SPLIT_MIDLIST_WAIT=0,XCL_COHERENT_MB=1024,VKD3D_CONFIG=ignore_shared_fence,XCL_PSO_PRELOAD=0,XCL_NETWORK=0):XCL_GPU_VIEW_BUFFERS=0(45 s control): runs smoothly past 20 s at 30.0 fps (1,143frames shown,8,192+draws,exit=0).XCL_GPU_VIEW_BUFFERS=1+XCL_GPU_VIEW_MB=1536(2 runs): reaches20.0–20.6 s(3,189–3,203draws,buffers of the GPU view: 3 tiles, 0 MB sent in 512 submits), then wedges completely (453frames shown in 40 s,GPU fences still pending after 10 son exit).XCL_THREAD_DUMP_AT=30(symbolized against the release binary's debuginfo) shows a lock-order inversion betweenkernelxandsparse:Looks like calling
title_textures::mirror_source(which lockskernelx) while holdingsparse's lock duringgpu_view::sync/ submit inverts the existingkernelx -> sparse::committedlock order.Not tested
XCL_GPU_VIEW_BUFFERS=1past the 20 s deadlock.AI use
@DavidM1911 on GitHub · 2026-11-25 19:12 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1 real failure, deterministic (also fails--test-threads=1, 1219/1):The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge.
— Devin
@Royalflamejlh on GitHub · 2026-11-25 21:28 UTC · original
d2306d7on an RTX 2070 SUPER (NVIDIA, wave32 only, Windows): withXCL_GPU_VIEW_BUFFERS=1and the default 512 MB the title stopped presenting at the start of loading in 2 of 2 runs, in the lock-order deadlock of @ClosetPie107's RDNA4 report above. With the change below (20afa48) it presented to the end of the run in 2 of 2.Setup: Windows 11 Pro 26200, RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, 16 GB RAM, rustc 1.100.0; release, 110 s, A from 38 s.
XCL_GPU_VIEW_BUFFERSd2306d7d2306d7d2306d7d2306d7+20afa48d2306d7+20afa48Tested: the dumps at 70 s and 100 s of the second run (the first had none) show the same two threads both times:
The second is
gpu_view::sync(gpu_view.rs:236);base_fortakes the same order (:194,:198). With the change, no thread in the fourth run's dumps is insparse::lock_stateorkernelx::physical_page_at, and 2,776 tiles (173 MB) had been mirrored by 105.4 s.The change (2 files, +35 −18) looks the sources up before
STATE:before_executetakes them from a newgpu_view::reads_due(which dropsMIRRORSfirst;refreshalready holdsREFRESHacross both,title_textures.rs:708, so two submits' reads are applied in order),synconly applies them, andbase_forlooks up its not-yet-mirrored tiles beforelock_state(). One commit ond2306d7:git fetch https://github.com/Royalflamejlh/xcl arch/2384-lock-order && git cherry-pick FETCH_HEAD.Also tested (debug):
cargo test --workspace --no-fail-fast -- --test-threads=4: 1,291 passed, 1 failed, 46 ignored ond2306d7and with the change; the failure,lower_dxil::…_meets_no_barrier(the one in DavidM1911's report), ismain68a284a's too (1,289 / 1), and it passes onmainsince #2420. Yourgpu_view hle::d3d12xcommand with the switch: 232 / 0 / 2 ond2306d7, and in 1 of 3 runs with the change. In the other 2, each right after another job on the card,bind::tests::execute_indirect_reads_the_arguments_written_before_itcould not create its queue (E_OUTOFMEMORY). It passed in the third run and in the whole suite.Regression run (switch unset)
main:
PR:
With the change (
20afa48): 754 frames, 60 presents per 2 s at the end, exit 0, 0 crashes, 0 device removals.Not tested
XCL_GPU_VIEW_MBother than 512; the change on AMD; a unit test for the lock order (it has none).AI use
Posted without review by a person: the account owner was away and reads replies later.
@madaraXor on GitHub · 2026-11-25 21:32 UTC · original
A lock-order deadlock with
XCL_GPU_VIEW_BUFFERS=1, on the retail title, twice, at two sites. The GPU-view code takes sparseSTATEand then kernelx'sAWAY. kernelx takes them in the other order.Setup: RX 6700 XT (RDNA2), Windows 10 22H2, release build. Tree:
main 65fc114+ this PR atd2306d7+ #1803, #2229, #1790, #2385, #1795, #2246, and MacieGx's f16 branch.XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_GPU_VIEW_BUFFERS=1. Stacks resolved with the build's PDB (cdb).Run 1: frames stop at 81 s; the title's watchdog writes
+0x2215c35at 109 s. The crash-time thread dump has two title threads waiting on each other:game+0x4ecc821→real::dev_create_srv_at_x→sparse::gpu_view::base_for(holdslock_state()andMIRRORS) →State::ensure_mapped→base_for::{closure}→title_textures::mirror_source→kernelx::physical_page_at→ waits forAWAYgame+0x2474676→kernelx::XMemMapPhysicalPages→MapTitlePhysicalPages(holdsAWAY) →map_pages→sparse::committed→lock_state→ waits forSTATERun 2 (with
base_forfixed, see below): frames stop at 88 s, with no watchdog by 390 s. A live dump (cdb -pv):q_execute_command_lists→title_textures::refresh→sparse::before_execute(holdsSTATE) →gpu_view::sync→mirror_source→physical_page_at→ waits forAWAYkernelx::XMemMapPhysicalPagesScatter(holdsAWAY) →map_pages→sparse::decommitted→lock_state→ waits forSTATEIn both runs,
xcl-activityand twoxcl-psoworkers also wait on the same locks, so theactivitylines stop too.What I did locally (two small changes; I can open them as a PR against this branch if that helps):
base_for: computemirror_sourcefor the tilest0..t1beforelock_state(), with no lock held.ensure_mapped's closure andm.showthen use those values.before_execute: beforelock_state(), a newgpu_view::sync_sources()takesMIRRORSalone to copy the tiles to look at, releases it, then asksmirror_sourcefor each.syncapplies the results underSTATE+MIRRORS, skipping a tile that leftm.readin between.The other order (kernelx calling
sparse::committed/decommittedafter releasingAWAY) would also do it. It touches five call sites (map_pages,give_back_homes,move_away, …) whose ordering with the page moves I did not want to change.With both changes (run 3, same tree and settings), no stall:
VCRUNTIME140memcpy write (same stack), at 21.5 GB commit and 10 GB local VRAM.Claude Code (Claude Opus 5.5): found the stacks with cdb, wrote the local fix and this note, from runs on the hardware above. Counts, times and RVAs only.
@Royalflamejlh on GitHub · 2026-11-25 21:45 UTC · original
On Linux with NVIDIA, 1 run each:
d2306d7withXCL_GPU_VIEW_BUFFERS=1deadlocked at 20 s, at the start of loading, in the two threads of ClosetPie107's RDNA4 report and ours above. With the first version of our lock-order change (cd582bc, since replaced on the same branch by20afa48) it did not deadlock: it mirrored 18,203 tiles of buffers by 92 s, then ended at 124.7 s in a title fault. Frame 1490, the only frame the switch-on run logged after loading (110.5 s; 130.2 s in the run without the switch), was the same even dark grey in both (0xff393331×108,132 and ×107,746 of 518,400 texels).Setup: RTX 4060 Ti 16 GB (NVIDIA 615.71.09), Wine 11.21 Staging, vkd3d-proton
v3.1-90-g30b0eb9bwith the relaxed-vtable patch from #175 and a local dxil-spirv patch. This PR onmaine0d93c8with #684, #751, #2082, #1860, #1599, #1798 and #2372 (closed since, for #2404), merged locally (#1798 merged by hand over #2118 inbind.rs).XCL_DIRECT_DXIL=1 XCL_PSO_WAIT_MS=50 XCL_HUGE_PSO_WANTED_CONCURRENCY=6 XCL_DXC_THREADS=4 XCL_PSO_DISK_CACHE=0, 1,050 s asked, first-run screens completed once, no story progress.cd582bc0xc0000005ingame+0x540abf5at 124.7 s; the title exited at 153.8 s (game+0x2215c35)home_again → sparse::committed → lock_state, one inbefore_execute → gpu_view::sync → physical_page_at.cd582bcand20afa48take the locks in the same order;cd582bc'sbase_forlooks up every tile of the range beforelock_state(),20afa48's only the tiles not yet mirrored (gpu_view.rs:174).XCL_PSO_WAIT_MS=50had skipped 10,574 dispatches by 130 s; #2372's description reports title faults in both of its runs with that budget. 1 run each does not show that the switch causes this fault.Not tested:
20afa48itself on Linux; the default 512 MB on Linux; a run withoutXCL_PSO_WAIT_MS.AI use: Claude Code (Claude Opus 5.5) merged the trees, made the runs, read the logs and dumps and wrote this.
Posted without review by a person: the account owner was away and reads replies later.
@CharlyRien on GitHub · 2026-11-25 22:07 UTC · original
@Royalflamejlh @madaraXor, another machine for the lock-order fix: our port of
d2306d7hit the samekernelx/ sparseSTATEinversion, and the same order fixed it here. Ours asksmirror_sourcebeforelock_state(): inbase_forfor every tile of the range (likecd582bc), and inbefore_executethrough apreparestep beforeSTATE, withsynconly applying the results. One difference:preparelooks at every mirrored tile again when the GPU-view mappings changed (kernelx::gpu_view_map_gen), otherwise at 8 in turn. With it,XCL_GPU_VIEW_MB=1536, our runs of 250–480 s on Windows never stalled.buffers of the GPU view: N tiles …is written only when the count of sync calls is a power of two, so it looks stuck (ours stopped at 14,152 tiles, 884 MB) while the mirror keeps growing. Two of our runs reached the 1,536 MB cap at 222 s and 242 s.CopyPageMappingsBatchX) was a stub; #1055 + #1102 fix it (our report on #1102);_atforms) goes throughbuffer_view(), which gives an empty V# when the buffer is not in unified memory; #2384 does not askbase_forthere. The final gather of the screen probes reads its tile list through such a view: 8 zero words in a captured frame, so all 115,056 groups work on tile (0,0). Replaying that dispatch offline with a filled list writes 142,533 texels (as many as have depth) instead of 0. The list is written by a UAV, so a CPU-to-GPU mirror cannot serve it.Measured: the lock order (dumps, then runs with no stall), the log line (from the code, and the cap lines in two runs), the coverage figures and the replay. Not measured: a lit frame. The lighting fix is in progress and not tried in the title.
Stack: our base is
main689f2db+ the PRs listed in our #2403 comment (7174740755, tree B), with #2384 ported locally; RTX 3090 24 GB, driver 616.56, Windows 11.AI use: Claude Code (Claude Opus 5.5 agents found and measured this; the coordinating session checked the figures)
@Eterst on GitHub · 2026-11-25 22:59 UTC · original
A test on NVIDIA, and a deadlock the mirrors can cause.
Setup: RTX 4070 SUPER 12 GB, driver 616.92, Windows 10 19045, release.
d2306d7merged into a local test tree (maine1d84b7with #2057, #2496, #2427, #1552, #1831 and a few local changes), so not this PR alone. The retail title withXCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_GPU_VIEW_BUFFERS=1 XCL_GPU_VIEW_MB=1536.The deadlock. The first run stopped at ~28 s, right after the press on the loading card: no log line after that (not even
XCL_ACTIVITY), 113 threads all waiting, ~0 CPU. A stack scan of the hung process, symbolised:sparse::before_execute(holdsSTATE) →gpu_view::sync→title_textures::mirror_source→kernelx::physical_page_at, waiting forAWAY;kernelx(holdsAWAY) →sparse::committed→lock_state, waiting forSTATE.Both calls are on this PR's base as well (
kernelxcallssparse::committedwithAWAYheld, andmirror_sourcecallsphysical_page_at), so it is not from the other PRs in my tree.gpu_view::base_forhas the same order: it callsmirror_sourcewithSTATEheld.What I changed locally, and it held: the sources are looked up before
STATEis taken, with no lock held during the lookups.gpu_view::refresh_reads()does thelook/set_readpart ofsync. It takesMIRRORSto pick the tiles, drops it for themirror_sourcecalls, and takes it again to set them.before_executecalls it beforelock_state();synckeeps onlymirror_upand the counters.base_forbuilds a map tile →mirror_sourcefort0..t1beforelock_state(), and uses it forquery_tile_holesandshow.With that, the next run went on to 292 s (it ended at my own commit cap, not a hang).
Budget, on a 12 GB card: with
XCL_GPU_VIEW_MB=1536the mirrors were full at 155 s, before the world's part of the intro, and the views made after that keep their address (take more than XCL_GPU_VIEW_MBat 155 s). 24,576 tiles, 3,224 MB sent in 16,384 submits by 221 s. DXGI local video memory was 14.2 GB at the end. The world's frames in the intro were black as before, which fits the budget being used up by then. So on this card, releasing mirrors no longer read (your "Not tested") looks needed before a bigger budget can show anything.Not tested: this PR alone; a lit or grey picture (none here); the change above as a commit on this PR's branch; AMD.
AI use: Claude Code (Claude Opus 5.5) ran the runs, found and fixed the deadlock in my local tree, and wrote this; posted with my OK.
Pull request closed