D3D12.X: mirror buffer views outside unified memory into UMA #632
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/637"
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?
Imported from ivall/xcl. Originally posted by WTactic on 2026-11-24T02:45:48Z.
When a title allocates resources outside XCL's mapped unified memory (UMA) windows and attempts to bind them into vertex or index buffers, native D3D12 device calls previously failed or produced invalid GPU virtual addresses.
This change transparently mirrors buffer views that fall outside the UMA memory windows into the coherent UMA pool (via
safe_copy_from_title), allowing games with custom out-of-pool heap layouts to bind buffers cleanly.What is in it
crates/xcl/src/hle/d3d12x/device_x.rs,crates/xcl/src/hle/d3d12x/list_x.rs,crates/xcl/src/hle/d3d12x/real.rs: mirror buffer views residing outside the 3 sparse UMA windows into the coherent memory region.Tested
rustc 1.97.1, release/debugcargo test -p xcl --lib list_x::tests: 27 passed, 0 failedRegression run
main(1d027e5):PR (
3217101):Not tested
AI use
Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T04:18:57Z.
Review: COMMENTED
Review of
0f418b0against its merge base508a0c7, by reading the code; nothing was built or run here. The idea (give buffer views outside unified memory a mirror instead of an empty V#) fits the existing vertex/index mirrors, butmirror_ofwas written for a caller that had already checked the range, and the new callers do not.CONFIRMED:
mirror_ofcopies from a source nobody checked (crates/xcl/src/hle/d3d12x/list_x.rs:1872-1877, copy at:1890). Whenreadable(src_start, len)fails, the fallback takes(va, bytes, src_va)and copies without a second check. Onmainthat was safe because the only caller,gpu_va, returns early unlessreadable(va, bytes)(list_x.rs:1810). The three new callers check nothing:buffer_view(real.rs:1195, whole resourceWidthat the placed address),dev_create_cbv_x(real.rs:1808) andbuffer_words_at(real.rs:2205). Scenario: a 64 KiB-aligned buffer whose memory is reserved but not committed, or larger than 256 MiB (readablereturns false above that,crates/xcl/src/gpu/shader.rs:208): the first check fails, the fallback is the same range, and the copy faults on its first byte. That matches the trace Dukiverse posted (0x3200000bytes, fault at the first source byte, insidemirror_of); I did not reproduce it. Fix: in the fallback, returnNoneunlessreadable(src_va, bytes), so the caller writes the empty V# as before.CONFIRMED: nothing refreshes these mirrors when the title writes; the description says it does.
sync_title_buffers(list_x.rs:1901-1916) only looks at the list's bound vertex and index buffers;MIRRORShas no other reader. A CBV/SRV/UAV mirror is filled when a view is created and again only when another view of the same range is created. Scenario: a title creates one CBV for a constant buffer outside unified memory and rewrites the constants every frame: the shader keeps reading the bytes from creation time.cbv_outside_uma_is_mirrored_and_refreshed(real.rs:5568-5593) passes because it callsmirror_oftwice itself; it never goes throughdev_create_cbv_xand does not show a refresh on a write. Fix: either sync the mirrored ranges the bound descriptors point at before a draw/dispatch, or say plainly in the description that views are a snapshot from creation time and rename the test.CONFIRMED: every
mirror_ofhit now recopies the whole view (list_x.rs:1850-1866). This also changes the existing vertex/index path: eachIASetVertexBuffers/IASetIndexBufferof a mirrored buffer (list_x.rs:2032,:2079) now copiesSizeInBytesat the bind, on top of the per-draw partial copy that the design note abovegpu_vasays replaced whole-buffer copies. Forbuffer_viewit is the whole resource per created view (50 MB perCreateShaderResourceViewin the trace above). Fix: keepmirror_offill-once as onmainand put the refresh where it is needed (see 2), not in the lookup.CONFIRMED (minor):
TITLE_BUFFER_BYTESis never cleaned up.res_releaseremoves the resource fromTITLE_ADDRESS(real.rs:1600-1602) but not from the new map (real.rs:1566-1574), so it grows by one entry per placed buffer and can hand a stale size to a later resource at the same pointer. Fix: remove it next toTITLE_ADDRESSinres_release.Also missing against CONTRIBUTING: the description has no Regression run for a runtime change, and no test covers an unreadable source (finding 1).
Verdict: not ready to merge; finding 1 can crash a title that ran before, and the "refreshed on CPU writes" claim does not hold.
Review by Claude Code (Claude Fable 5.2); each point checked by a person before posting.
Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T03:33:16Z.
Test run of
0f418b034490020422a44a7662cedb58b5bca2cbon AMD RDNA4. I merged it onto currentmain91f9a5elocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 694 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 654 passed, 0 failed, 21 ignoredSKIPPED;buffer_views_outside_uma_are_mirroredandcbv_outside_uma_is_mirrored_and_refreshedpass.Review: A view of a buffer outside unified memory now gets a mirror in UMA, and every path that fills the mirror copies from
mirrors::source(va)(the title's current source for a moved page) after areadablecheck, so the copy cannot fault. The mirror is filled when a view is created and by the existing refresh path; I did not trace every CPU write path, so whether a title write between view creation and submit always reaches the mirror is not something this run shows.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Imported from ivall/xcl. Originally posted by relativespace2K on 2026-11-24T03:48:27Z.
Tested -
3217101onmain3da2abb, retail GTA6 1.0.2.1Tool: OpenCode with DeepSeek V4.1 Flash 1017
0xc0000409; stdoutmemory allocation of 2073600 bytes failed(host OOM), peaks31,964 MB and 35,116 MB.
peak 40,020 MB, mirrors active, 0 failed pipelines, 0 DXIL failures, 40 refusals as
main.main240 s exit 0 at 33,429 MB; #684 240 s exit 0 at 35,380 MB.feature raises peak memory to ~40 GB; with enough headroom the run is clean.
Tested - re-tested at the new head, independent AMD RDNA2 validation
cfc848f934f1ba13dff0f31121718a226702e493, based on47efa2e(the branch wasrebased; the previous report was for
0f418b0). Applied as a cherry-pick withoutcommitting onto current
mainb8b1f49(clean;real.rsauto-merged).Windows 11 IoT Enterprise LTSC 26100; Rust 1.100.0
stable-x86_64-pc-windows-msvc;DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); debug; no
XCL_SAMPLE_*.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4.mainb8b1f49main+ this PRbuffer_views_outside_uma_are_mirrored,cbv_outside_uma_is_mirrored_and_refreshedanduncommitted_buffer_view_does_not_crash(lib tests go 702 -> 705; the integration binaries are unchanged).
3D 64x64x64 4 mips: subresource 2 mismatch(#470) and the twoPoisonErrorfollow-ons (#673).
cargo test -p xcl --lib outside_uma: 2 passed, 0 failed, 0 ignored, and thelog shows both paths active - the CBV and the buffer view outside unified memory are
mirrored at
0x420010000/0x420020000, "each draw copies what it reads".SKIPPEDGPU tests on this adapter.Not tested: retail title /
smoke.ps1, release build, NVIDIA / Intel.AI use: OpenCode with DeepSeek V4.1 Flash 1017 ran the tests and drafted this report.
Imported from ivall/xcl. Originally posted by iggyvilla on 2026-11-24T04:00:56Z.
Tested (PR head
0f418b0, not merged onto currentmain; RDNA2/wave64, which the PR lists under Not tested)Windows 11 build 26300,
rustc 1.100.0 (0ef1bc386 2026-11-09) stable-x86_64-pc-windows-msvc.cargo build --release -p xcl— ok.cargo build --workspace— ok (debug test title built).cargo test --workspace --no-fail-fast -- --test-threads=4on the PR head, debug:679 passed, 3 failed, 41 ignored, 0 skipped.
xcllib: 639 passed, 3 failed, 21 ignoredconsole_dlls_e2e13;console_shaders3 passed, 4 ignored;disasm_e2e1;e2e3;gpu_compute_e2e2;gpu_pso_e2e7;heap_probe4 ignored;pls_quota1;predication_e2e1;rpf_e2e2;texture_states1;xg_oracle6 passed, 12 ignored.SKIPPEDlines.mainon this card, not new ones:placed_title_textures_share_vram_and_preserve_pixels— also fails alone:assertion left == right failed: 3D 64x64x64 4 mips: subresource 2 mismatch(#470).transitions_apply_when_their_list_is_submittedandd32s8_targets_take_their_own_size_of_video_memory—PoisonErrorin the suite (the lock-poisoncascade #673 fixes); both pass when run alone. Not caused by this PR.
buffer_views_outside_uma_are_mirroredandcbv_outside_uma_is_mirrored_and_refreshed.XCL_NETWORK=0,scripts/smoke.ps1 -Game D:\GTA6.Xbox.v1.0.2.1-CYBERLEEK,as printed:
For reference, a
mainrun on this machine the same way (commitdd2ae9a, not this PR's base508a0c7) is 569 frames, 23 24 23 presents per 2 s, peak commit 15856 MB, exit0x0, 0 crashes. Thedifference is reported as measured; this run does not attribute it to the PR.
Not tested
mainhere; only the head as fetched was built and run.XCL_SAMPLE_*tests (none set).AI use
opencode with DeepSeek V4.1 Flash (opencode-go/deepseek-v4.1-flash) ran the build, the tests and the smoke
run and wrote this report.
Imported from ivall/xcl. Originally posted by Dukiverse on 2026-11-24T04:03:36Z.
Retail regression run of this PR: the retail title 1.0.2.1 (the same title as #675 and #616) crashes about 18–23 s in, inside
mirror_of, with no input.mainruns the full 60 s.Tested
XCL_NETWORK=0, nothing touched during the runs.scripts/smoke.ps1 -Seconds 60, run on four builds:mainf4ce27c: full 60 s, 1465 frames, no crash, 14632 MB peak.f4ce27c(local merge723b057, clean):0xc0000005at 17.8 s.0f418b0on its own base, two runs:0xc0000005at 22.9 s and 23.5 s.maindd2ae9a, for the head-only runs: full 60 s, 1464 frames, no crash.0x3200000) copy into a new mirror at0x469a00000, and it faults on the first byte of its source. The source is the title's memory outside unified memory. Just before it, two mirrors are made for small views (118060 and 44048 bytes, at0x463a70000/0x463a90000). The third view, the one being mirrored here, is never logged, because the copy runs before the log line.copy_nonoverlapping(src, p, len)at the end ofmirror_of).readable(src_start, len)fails, the fallback usesmirrors::source(va)without its ownreadablecheck. The caller checkedva, not that source. I have not confirmed this is the path taken.cargo test --workspace -- --test-threads=4(debug build present) on0f418b0: 663 passed, 0 failed, 25 ignored. SKIPPED: 2 wave64 tests (32-lane GPU).Regression run
main
f4ce27c:this PR merged onto it:
Not tested
mirror_ofthe crashing copy took.title:lines in the smoke blocks are redacted; nothing else in them is edited.Runs and report by Claude Code (Claude Opus 5.5) on my machine.
Generated by Claude Code
Imported from ivall/xcl. Originally posted by WTactic on 2026-11-24T12:07:42Z.
Thanks for finding and reporting this @Dukiverse!
Root Cause
The 50 MB buffer view was placed in
MEM_RESERVEmemory (e.g. an unwritten GPU UAV output buffer) that had not been committed yet on the CPU. The previous fallback attemptedcopy_nonoverlappingdirectly from reserved memory without ensuring lazy page commit or verifying per-page commit status, triggering the0xc0000005fault.Fix
safe_copy_from_title:kernelx::lazy::ensure(src, len)to commit any pending lazy pages.MEM_RESERVE), queries page states viaVirtualQuery: committed readable pages are copied, while uncommitted pages are safely zeroed in the mirror rather than faulting.uncommitted_buffer_view_does_not_crashinreal.rsverifying that views over uncommittedMEM_RESERVEmemory mirror cleanly without faulting.Squashed and force-pushed head
8d051f3. All workspace tests pass (cargo test --workspace -- --test-threads=4: 664 passed inxcllib).Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T13:49:35Z.
Re-read at
cfc848f(nothing built or run here). Point 1 of my review is fixed another way: the copies now go throughsafe_copy_from_title, which zeroes uncommitted pages instead of faulting. Points 2-4 still apply at this head:sync_title_buffers,list_x.rs:3208-3220); a CBV/SRV/UAV mirror is copied again only when a view of the same range is created (mirror_offromreal.rs:1195,:1827,:2224). The description still says the views are "refreshed on CPU writes".mirror_ofhit copies the whole requested range again (list_x.rs:3159-3161, and the second lookup under the lock).TITLE_BUFFER_BYTES(real.rs:1566-1573) still has no removal inres_release(:1587).Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.
Imported from ivall/xcl. Originally posted by crosettiremi on 2026-11-24T16:28:57Z.
RX 7900 XT downstream test of
cb4a9aeon a build based on930e8b4. The three focused tests for non-UMA buffers, constant-buffer refresh, and uncommitted views passed. The comparison build logged an empty buffer descriptor during startup. With this PR the title reached the new mirror path: one logged view was 118,060 bytes, and the last power-of-two sample showed 8,192 mirrors totaling 1,408 MB.Both runs had matching initial caches, scripted Player1 input at 33 seconds, two DXC workers and a 28 GiB whole-job limit. The comparison build later had a GPU page fault during world loading. The mirrored build exited at about 190 s with Rust allocation-error handling on a DirectStorage queue worker; peak sampled process commit was 27,560 MB and no device removal was logged. The title exercised the implementation. These two runs do not establish that mirroring fixed the GPU fault, or that mirrors alone caused the allocation failure.
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T06:36:55Z.
Empirical test report (
32171011)Hardware / environment
32171011d20dacd2f87de84865be3ef1fcb96e86, verified on a clean detached HEAD.Commands and results
cargo test --workspace --no-runexited 0 and built the workspace test executables. This command compiled tests only.XCL_ADAPTER=NONE_CPU_ONLYandRUST_TEST_NOCAPTURE=1.$unitTestExerefers to the prebuilt library harness,xcl-77aca8ccb20e299f.exe.All three commands exited 0. Each reported 1 passed, 0 failed and 0 ignored. The focused log totals were 3 passed, 0 failed, 0 ignored and 0 skipped (case-sensitive
^SKIPPEDlines).Observed behavior
Not tested
The full GPU workspace suite, shader execution against these descriptors and game smoke runs were omitted.
AI use
Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr637-focused.log and published.
Imported from ivall/xcl. Originally posted by CharlyRien on 2026-11-25T08:59:59Z.
A test of this PR's idea on the retail title, done with an equivalent local change rather than this branch: copies of out-of-window buffer views are enough to get world geometry rasterised, with three conditions this PR may want to know about. Numbers: https://github.com/xcl-dev/xcl/issues/697#issuecomment-7155524209
Setup in short (the full block is in the linked comment):
main689f2db+ #1329 (+ #1326, #1327), #1448, #1323, #889, #684, #929, #640, #1850, #765, #1982, #1405, #1464, three allocator-lifetime commits fromwondercrash/xcl, then #541, #2092's3442b58state, #1887, #1803, plus local changes;XCL_UMA_SHADOW=1 XCL_HEAP_WINDOWS=1; RTX 3090 24 GB (driver 616.56), Windows 11 22631; one clean run and one partial run.buffer_words_atpath this PR also changes): 94 412 distinct ranges in the first 25 s of the world, 1 156 MB, every one an SRV, 71 % of them 4 KiB or less. The title's GPU-driven culling and its mesh programs read through them.Not tested: this branch itself; writes through UAV copies going back to the title (none of the by-address views in the GPU view was a UAV here).
AI use: Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 for the ports and the runs) did this and drafted the comment.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T12:43:42Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by throny on 2026-11-25T20:14:29Z.
Two contributors checked independently and found that #2384 solves the same problem in a different way: #1607, group D110. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.
This is a hint from the community triage in #1607, not a maintainer decision.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Imported from ivall/xcl. Originally posted by CalvyPZ on 2026-11-25T22:45:09Z.
This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T16:54:22Z.
Code review location:
crates/xcl/src/hle/d3d12x/list_x.rs; line 3348Could the new copy test cover a range that spans both committed and reserved pages? The current tests exercise a fully committed allocation and a wholly
MEM_RESERVEallocation, whilesafe_copy_from_titlehandles eachVirtualQueryregion separately. A focused mixed-region case would verify that the committed prefix is copied and only the uncommitted suffix is zeroed. AI-assisted review: I inspected the diff and existing tests; I did not run tests.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:50:29Z.
Triage (#1607) – head
3217101#2384 (closed) went at buffers outside unified memory a different way: it mapped GPU-view tiles into a sparse window behind
XCL_GPU_VIEW_BUFFERS, read-only. This PR copies the buffer into a UMA mirror when the view is made. Main still gives such views an empty V#.Problems in the diff:
mirror_ofruns again for the range). Later CPU writes, for example to a constant buffer filled each frame, never reach them, becausesync_title_buffersonly updates vertex and index ranges.mirror_ofover the same range writes the CPU copy over them.mirror_ofnow copies on every hit, andsafe_copy_from_titlecallslazy::ensure, which commits the title's lazy reservations just because a view was made.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.