Skip to content

D3D12.X: coherent UMA windows in a driver heap on NVIDIA (port of #2844 to amd-dev) - #3061

Closed
vibryxcx wants to merge 286 commits into
xcl-dev:amd-devfrom
vibryxcx:amd-uma-driver
Closed

vibryxcx wants to merge 286 commits into
xcl-dev:amd-devfrom
vibryxcx:amd-uma-driver

Conversation

@vibryxcx

Copy link
Copy Markdown

Port of #2844 (coherent UMA windows in a driver CUSTOM heap at the title's address) to amd-dev, so the AMD branch has the same UMA backend as main and XCL_UMA_DRIVER works there. Part of #2688. #3003 is the same port for nvidia-dev.

The default stays as in #2844: on for NVIDIA outside Wine, opt-in elsewhere (XCL_UMA_DRIVER=custom). On an RX 6800 the driver heap does take effect, but it gives only a small gain and does not speed up the title's two heaviest compute programs (numbers below), so this PR does not turn it on for AMD.

What is in it

Tested

  • AMD Radeon RX 6800 16 GB (RDNA2), driver 32.0.21045.5002; Intel i5-10600KF, 32 GB; Windows 11 Pro 26200; Rust 1.100.0 MSVC; debug for the tests, release for the title.
  • cargo test -p xcl --lib -- --test-threads=1 (skipping 5 tests that hang or abort the whole run on this machine on amd-dev too: placed_title_textures_share_vram_and_preserve_pixels, d32s8_targets_take_their_own_size_of_video_memory, the_mirror_sync_copies_only_the_pages_the_title_wrote, xgameruntime::gamesave::tests, a_pipeline_an_earlier_run_used_is_built_ahead_of_its_first_use): 1666 passed, 11 failed, 28 ignored. The 11 failures are the ones amd-dev has on this card (listed in GPU test results: NVIDIA RTX 3080 (wave32) and AMD RDNA2 iGPU (no mesh shaders) #42). An earlier run of the same command aborted with 0xc0000409, as runs on amd-dev bases did for Recompiler: fix RDNA4 direct-DXIL f32 ordered compare (V_CMP_LG_F32) and V_DIV_*_F32 NaN/scaling semantics (#2952) #3023 / D3D12.X: gate vram_small block recycling on GPU fences, evict idle heaps under VRAM pressure, and pack small Texture1D #3025.
  • SKIPPED: 4 lines of f16_programs_on_the_gpu, pso_measurement_compiles_an_exact_synthetic_record.
  • uma_driver tests with XCL_UMA_DRIVER=custom: 3 passed.
  • Integration tests (cargo test --workspace --no-fail-fast --test '*' --bins -- --test-threads=4): all pass except d3d12_mesh_stream::console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly, e2e::test_title_runs_and_game_folder_is_untouched and 2 gpu_compute_e2e::offline_*_pipeline_is_reused_by_a_second_process, which fail the same way on amd-dev 7c795f5e (the e2e one at the test title's Write64BitValueTopOfPipeX: 0x0, 2 of 2 runs on each tree). So the new e2e check that the backend starts before DllMain is not reached on this card.
  • Retail title (warm caches, 360 s runs, A pressed every 10 s, same exe, XCL_GPU_PROFILE=1, interleaved custom / 0 / 0 / custom):
run XCL_UMA_DRIVER fps while presenting (avg / peak) a3c0b8a98beee431 GPU ms per call 344335e52c4be50e GPU ms per call end
1 custom 13.6 / 32.5 106 84 0x887a0020 at 255 s
2 0 11.5 / 33.5 108 95 0x887a0020 at 282 s
3 0 10.9 / 32.5 269 91 0x887a0020 at 324 s
4 custom 12.7 / 33 163 92 0x887a0006 at 309 s

Regression run

  • scripts/smoke.ps1 -Game <title> -Seconds 60, main side made on amd-dev 7c795f5e (this PR's base):
xcl-smoke v1
commit: 7c795f5eefa0661eaf3f9f696d0cba3a75ce9628
gpu: AMD Radeon RX 6800
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 678 (PresentX 678)
presents per 2 s (last 3): 60 65 60
device removals: 0
crashes: 0
peak commit: 13369 MB
xcl-smoke v1
commit: 29cb54537ca8c92d3533e8acdbc182b929db5abc
gpu: AMD Radeon RX 6800
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1344 (PresentX 1345)
presents per 2 s (last 3): 64 61 60
device removals: 0
crashes: 0
peak commit: 13350 MB

Not tested

AI use

  • Claude Code with Claude Opus 5.5: cherry-picked and resolved the conflicts, ran the tests and the title runs through a local runner, and wrote this description. I read the diff and the results.

🤖 Generated with Claude Code

ivall and others added 30 commits November 25, 2026 16:29
A retail game unmaps addresses while it streams its world with
XMemMapPhysicalPagesScatter(addresses, n, NULL); it checks the result
and runs into its own int3 when the call fails (+0xb18de7, then its
crash reporter). XCL refused a NULL page array with
ERROR_INVALID_PARAMETER. Page 0 already means "unmap this address" in a
scatter, so no array is taken as page 0 for every address.

Test scatter_without_pages_unmaps: two pages mapped and written, unmapped
with no array (the call succeeds, the addresses are no longer committed),
mapped again they read what was written. It fails without the change
("refused").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retail title keeps its destination page lists in slots of its own
table and writes a slot's pages after EnqueueRequest. At enqueue such a
slot can still name the pages of the slot's previous request, and the
snapshot taken then is what execute() wrote to (xcl-dev#289 rereads only the
entries that are 0). Over 16 000 requests a run were written into pages
the title had since reused: its objects got garbage pointers and it
crashed about 20 s into world loading; when the old pages were freed,
the request failed with E_ACCESS_VIOLATION.

The console reads the list when it runs the request. execute() now
reads it again (through read_own, as the snapshot) and takes it when it
differs and every page in it is allocated (kernelx::physical_pages_live).
A list that was on the enqueuing thread's stack keeps the snapshot: that
memory is reused once the call returns, and a page ID written there
since can belong to another live allocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir pages with their texels

A retail title places its streamed textures at full size and has memory behind
their levels only as it loads them, the small ones first. vram::place_pages
gives a sampled texture a 64 KiB page of video memory for every tile at once:
when that title's world is set up about 92 % of those pages have nothing behind
them (80 690 pages, 6 809 committed, on one card).

With the switch (off by default) a sampled 2D texture of one slice is placed
with no tile mapped. Its tiling is kept as groups of tiles, one for each level
with tiles of its own and one for the packed levels, and a group gets its pages
before the first upload that has texels for it - the same pages by address as
before, so textures placed at one address still share them. A texture the GPU
writes gets all its pages.

Part of xcl-dev#1773.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… done

When the GPU-wait watchdog releases a wait (xcl-dev#505), its lines say which
queues wait on which, but not what the GPU is running. With
XCL_GPU_CULPRIT=1 every dispatch XCL records (title lists,
console-recorded lists, ExecuteIndirect of a translated compute
pipeline) is wrapped in WriteBufferImmediate markers, in before and out
after, one pair of words per PC list in a readback buffer. At a release
the lists whose marker in is above their marker out are logged with the
dispatches between the two: console CS (fnv64 of the title's bytecode),
PC pipeline and groups.

On the retail title of xcl-dev#505 (RTX 5080) this named, at each stall, one
list with a run of 1-D dispatches of one CS whose first never finished;
not the same CS from run to run. DRED breadcrumbs were tried first: they
change the driver's pipeline cache keys, so every pipeline was built
again and the title never got past its start.

Off by default; without the variable nothing is recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring in 36 upstream PRs from origin/main (xcl-dev#2310..xcl-dev#587) onto amd-dev (c7a18d8) while preserving all local AMD RDNA4 work (xcl-dev#615 pipelined presenter SRVs, xcl-dev#495/xcl-dev#1405 XCL_PAGE_ALIAS=1 hooks, xcl-dev#2306 level tiling timers, xcl-dev#1989 vtable fix, mesh user SGPRs).

Resolved 4 conflicts:
- console_list.rs: kept both mesh_arguments_go_in_user_sgprs_from_s16 and xcl-dev#2323 dispatch-heap tests
- real.rs: kept both effective_st depth-UAV tracking and xcl-dev#2280 pc_clear_for_desc
- vram.rs: kept Step::Tiling timer around level_tiling
- kernelx.rs: kept XCL_PAGE_ALIAS=1 hooks in physical_pages_live and XMemMapPhysicalPagesScatter

Assisted-by: Antigravity (Gemini 4 Neon High)
Both internal indirect-argument rewrite passes in bind.rs (guard_dispatch_args and make_scaled_args_buffer) emitted the exact DRED breadcrumb pattern (barrier, barrier, marker, Dispatch, barrier, marker) with an unlabeled pipeline and had root-binding and alignment hazards on AMD RDNA4:

1. Neither guard_indirect_pipeline nor scale_indirect_pipeline called dred::label_text (or SetName), so DRED printed the fallback stand-in label.
2. Both reused abi_root_signature (6 root UAVs + directly-indexed heap flags) while leaving slots unbound; SCALE_ARGS_HLSL statically references cnt (u4) via a ternary even when no count buffer is bound.
3. src_va and count_va were passed directly to SetComputeRootUnorderedAccessView even when args_off or count_off was not 16-byte aligned (e.g. 12-byte Dispatch argument strides or 4-byte count offsets).

Fix all three: label both pipelines for DRED, give args_pipeline a minimal root signature with every parameter unconditionally bound (binding u4 to consts_va when count is None and guarding cnt.Load with an if), align root UAV bases down to 256 bytes and pass the byte offset via io, guard GUARD_ARGS_HLSL divisions, and validate bundle/stride/offset bounds.

Assisted-by: Antigravity (Gemini 4 Neon High)
Console D16_UNORM_S8_UINT (118..=120) depth+UAV twins used R16_UNORM SRVs and a float fullscreen pass. Because 2^24-1 is not a multiple of 65535, hardware R16_UNORM conversion can differ by 1 ULP from float(k) * asfloat(0x37800080) computed by tiled-lighting DepthFunc = EQUAL vertex shaders, rejecting lighting draws on AMD RDNA4.

Read the R16_TYPELESS twin as R16_UINT in a dedicated fullscreen PSO returning float(val) * asfloat(0x37800080) for console formats 118..=120, and update the twin-plan unit test.

Assisted-by: Antigravity (Gemini 4 Neon High)
…olves

Command list xcl-dev#146 (uav_barrier_x) synced depth+UAV enhanced barriers and PlacedUav format-alias pairs, but never checked D3D12_BARRIER_TYPE_TEXTURE transitions on TitlePlaced format-alias writers (such as R9G9B9E5 lighting targets), leaving aliased SRVs stale under enhanced barriers.

Add format_alias::filter_enhanced_barriers and call sync_title_writers in uav_barrier_x. Also translate console target formats in resolve_subresource_x and resolve_subresource_region_x via device_x::pc_target_format.

Assisted-by: Antigravity (Gemini 4 Neon High)
buffer_view (used by CreateShaderResourceView and CreateUnorderedAccessView on buffer resources) returned empty V# descriptors for placed GPU-view buffers, and dev_create_cbv_x / buffer_words_at only fell back to read-only sparse::gpu_view mirrors (requiring XCL_GPU_VIEW_BUFFERS=1 and skipping UAVs).

Add real::resolve_uma_va(va, len) consulting kernelx::mirrors::mapped_source and mirrors::source with per-64-KiB-page contiguity verification inside UMA, wire it ahead of sparse::gpu_view::base_for in buffer_view, dev_create_cbv_x, and buffer_words_at, and add read-only sparse fallback to buffer_view.

Assisted-by: Antigravity (Gemini 4 Neon High)
Keep amd-dev 0 commits behind origin/main (xcl-dev#573, xcl-dev#2083, xcl-dev#2345, xcl-dev#2342).
Resolved 1 conflict in bind.rs: kept pso_for_draw(raw_pso) and bounds-checked commands_at/count_at while taking xcl-dev#2342 failed shared compute stand-in check.

Assisted-by: Antigravity (Gemini 4 Neon High)
map_pages and move_away previously called sparse::committed(at, PHYS_PAGE)
inside the per-page loop. When a large physical-page allocation (~2+ GB) lands
in a sparse UMA window (such as Series S / lockhart TileHeap), this issued
~34,000 separate 64 KiB UpdateTileMappings + queue.Signal calls (>31 s at
~64 MB/s), tripping the title's 30 s init watchdog.

Coalesce contiguous 64 KiB sparse-window commits in SparseCommitBatch across
map_pages, move_away_batched, MapTitlePhysicalPages, and
XMemMapPhysicalPagesScatter, flushing early on any overlapping decommit/unmap.
Reduces ~34,000 UpdateTileMappings calls to one batched commit per contiguous
run (~34 pool-heap calls, <100 ms).

Assisted-by: Antigravity (Gemini 4 Neon High)
Titles can enqueue DirectStorage requests with heap-backed
DestinationPageArray pointers, populate/map the physical page lists, and then
call Submit(). Auto-submitting the queue at half capacity let worker threads
run mid-batch against unpopulated page entries, dropping streamed geometry.

When the pending queue contains any non-stack DestinationPageArray request,
suppress the half-capacity auto-submit and wait for explicit Submit() (or full
queue capacity), while keeping normal half-capacity auto-submit for memory,
file, and stack-backed page-list requests.

Assisted-by: Antigravity (Gemini 4 Neon High)
VOP3 v_interp_p1ll_f16, v_interp_p1lv_f16, and v_interp_p2_f16 encode
(high << 8) | (chan << 6) | attr in SRC0 (OPR_ATTR). For attr63.w (attr=63,
chan=3, high=0), SRC0 == 0xFF == 255, which rdna2::decode's VALU fallback
literal scan mistook for a 32-bit inline literal and consumed the following
instruction word.

Skip fields explicitly typed as non-source operands (!is_src_type) during the
VALU fallback literal scan while keeping v_nop's empty-operand hidden shader
hash literals intact.

Assisted-by: Antigravity (Gemini 4 Neon High)
ivall and others added 16 commits November 27, 2026 12:47
Keep the previous explicit HLSL override and reuse the cache identity of explicit direct compute.

Assisted-by: Codex (exact model identifier unavailable)
Reserve a D3D12 device slot for the parent process on AMD.

Assisted-by: Codex (exact model identifier unavailable)
Use the ambient stand-in when the raytracing gate forces misses.

Assisted-by: Codex (exact model identifier unavailable)
Most recordings need only a few argument records. Grow to the regular block size when a slot fills.

Assisted-by: Codex (exact model identifier unavailable)
Release recyclable scratch for the device when the system is short on commit.

Assisted-by: Codex (exact model identifier unavailable)
Use an explicit aliasing barrier for the overlapping placed resources. Keep native-driver execution available by adapter selection.

Assisted-by: Codex (exact model identifier unavailable)
Share identical shader bytes from different title addresses and check byte equality before reusing a hash match.

Assisted-by: Codex (exact model identifier unavailable)
Port the mapping and retirement changes from xcl-dev#2981. Seal only the unmaps covered by the queue signals and keep zero-buffer aliases alive through retirement.

Assisted-by: Codex (exact model identifier unavailable)
Adapt xcl-dev#2821 to bound fence waits and retry unsent writes when a slot is still busy. Use smaller upload and readback staging buffers with chunked transfers.

Assisted-by: Codex (exact model identifier unavailable)
Port xcl-dev#2912 so finished staging allocations are reaped even when the originating queue goes quiet.

Assisted-by: Codex (exact model identifier unavailable)
Port xcl-dev#2985 so supported fallback resources can share backing heaps and reuse the decoded layout.

Assisted-by: Codex (exact model identifier unavailable)
Sample process pages to distinguish unified, sparse, and other resident memory in the diagnostic report.

Assisted-by: Codex (exact model identifier unavailable)
Track the latest submitted work along with missing completion markers.

Assisted-by: Codex (exact model identifier unavailable)
Port the GPU timestamp profiler from nvidia-dev ea22791, including submission and pipeline identification hooks.

Assisted-by: Codex (exact model identifier unavailable)
XCL moves from GPL-2.0-only to GPL-3.0-or-later so that code can move
between XCL and GPL-3.0 projects (VIctory and its forks) in both
directions.

- LICENSE: the GPL-3.0 text from gnu.org; Cargo.toml: GPL-3.0-or-later.
- README, CONTRIBUTING, AGENTS, SECURITY: the new licence and the
  GPL-3.0 compatibility rule for dependencies.
- THIRD_PARTY.md: the GPL-3.0-compatible licence list; VIctory is used
  under its own GPL-3.0; AnyPS5 is listed as a reference only.
- AnyPS5 was read as a description of the hardware behaviour (MIMG A16
  address layout, 16-bit VALU halves), no code was taken from it: the
  two comments in recomp/emit.rs that said "ported" now say so.
- Headers of the VIctory and FFmpeg ports no longer name GPL-2.0-only.

No code change.

(cherry picked from commit 06f90c1)
…-dev#2844)

Port of xcl-dev#2844 (f2248f0) to amd-dev. Conflicts: real.rs keeps amd-dev's
outside_base release on a missing heap; host.rs keeps amd-dev's
flush_pipeline_library in the XCL_RUN_SECONDS thread, moved after
backend_before_guest as in xcl-dev#2844; title_textures.rs keeps amd-dev (the
Wine-only read change is left out). Behaviour on AMD is unchanged: the
driver window stays opt-in (XCL_UMA_DRIVER=custom) off NVIDIA.

The title's GPU code reads and writes the coherent window (4 GiB of host
memory) through a heap opened with OpenExistingHeapFromAddress. On an
RTX 5070 Ti, GPU loads from such imported pages ran 8-24x and atomics
13-22x slower than from a driver CUSTOM write-back L0 heap in host
memory, at the same CPU caching. A whole-frame replay of a captured
title frame took 172 ms of GPU time with the window in a CUSTOM L0
heap and 1,427 ms with it imported as XCL does, the hot compute
programs 18-39x slower each.

At open_uma the window's written pages are copied out, the window is
released, every other free stretch of 1 GiB or more is reserved for a
moment so that the driver's CPU mapping of a new CUSTOM L0 heap can only
land in the hole the window left, and the pages are copied back. The
title keeps its pointers. If the mapping lands anywhere else, or a step
fails, the window is made again at its address with its pages and
imported as before; if the snapshot of its written pages fails, the
window is not released at all (found in review by thehollowedone, with
the test failed_write_watch_does_not_release_the_original_window).
Buffers placed in it drop ALLOW_CROSS_ADAPTER. The heap is made with
D3D12_HEAP_FLAG_ALLOW_WRITE_WATCH, and GetWriteWatch reads the mapped
window on an RTX 5070 Ti (driver 610.74), so the window stays in the
write-watched regions and the title's CPU writes reach its textures as
with the import; a driver that refuses the flag, or whose mapping
GetWriteWatch cannot read, keeps the import.

The backend (and with it the window and any driver remap) is made once
before load_main, before a title DLL's TLS callbacks or DllMain can hold
a window pointer; a backend first made later only imports, so no remap
happens under guest threads. A write between the snapshot and the
release could otherwise be lost. If the window cannot be made again at
its address after it was released, XCL logs it and ends the process
rather than run the title on an unbacked window. Both found in review
by thehollowedone, with their tests (the e2e order check and
failed_restore_stops_before_importing_an_unbacked_window).

On by default for an NVIDIA adapter outside Wine; XCL_UMA_DRIVER=0
turns it off, XCL_UMA_DRIVER=1 (or custom) turns it on elsewhere.

Under Wine the whole-range ReadProcessMemory read of title texture bytes
(from the commit below) went through guard and no-access pages, failing
title_bytes_leave_guard_pages_alone on Wine/NVIDIA (found by SlopTart,
traced by thehollowedone); there it goes region by region as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andrewDoing

Copy link
Copy Markdown
Contributor

I checked the otherwise unreached startup-order assertion on NVIDIA GeForce RTX 5070 / driver 616.92, exact head 29cb54537ca8c92d3533e8acdbc182b929db5abc, using the stock bundled synthetic title and e2e test.

In both the default configuration and XCL_UMA_DRIVER=0, the host log placed D3D12 backend initialization before DllMain(testgame_mw.dll, PROCESS_ATTACH). Both stock tests failed before reaching the automated order assertion at Write64BitValueTopOfPipeX: 0x0, matching the failure described on AMD, so these are log observations rather than passing e2e tests.

In the default run, CUSTOM heap mapping returned an address different from the requested title address and XCL fell back to imported memory. Thus neither run verifies successful CUSTOM-heap startup. No retail title or performance was tested.

AI use: OpenAI Codex with GPT-6.2 Astra ran the checks; Codex reviewed and prepared this report.

@SlopTart

Copy link
Copy Markdown

Solo data from both Linux/Wine lanes on head 29cb5453.

Hardware

  • rig1: AMD Ryzen 9 9900X, 96 GB DDR5, RX 7900 XT (Navi 31), Arch, Mesa 26.2.5 RADV, wine 11.0 (proton build)
  • rig2: Intel i5-10600K, 16 GB DDR4, GTX 1070, nvidia 550.163.01, Debian 13, wine 10.0 under xvfb

uma_driver::tests::failed_restore_stops_before_importing_an_unbacked_window, run alone with --exact, x2 per mode:

  • rig1: default FAILED 1.41 s / 1.56 s; XCL_UMA_DRIVER=custom FAILED 1.50 s / 1.55 s
  • rig2: default FAILED 6.94 s / 6.54 s; XCL_UMA_DRIVER=custom FAILED 6.47 s / 6.52 s

The driver-heap backend changes nothing for this failure under Wine on either vendor: same assertion, same timing band in both modes. For reference these solos are the same two reds the main-branch threads track, and they stay red across linux/stack too.

uma_driver::tests::grooming_leaves_a_window_under_1_gib_only_its_hole does not exist on this base (0 tests matched), so no number for it here, and that is not a pass.

Tested: the two solo runs per lane per mode at 29cb5453.
Not tested: full suite on this head (amd-dev based suites die mid-run on both lanes, separate known issue), native Windows.
AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 29cb545

This PR ports #2844 to amd-dev. origin/amd-dev now contains #2844's own commit (f2248f0, through merge fa671a2) and later changes to uma_driver.rs (for example XCL_UMA_DRIVER=mixed:) and uma.rs is_driver_window. The PR's base 7c795f5 is no longer on amd-dev, so against the current branch its diff is about 52k lines, mostly old amd-dev commits that it shares with #3023, #3024, #3025 and #3079.
Recommendation: close (superseded by #2844, already on amd-dev through fa671a2).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 29cb545, description read; draft, base amd-dev, conflicts with it):

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded: this change is already on amd-dev (fa671a2). From Foniass's rechecked close list on #1607, checked again by script just now. If something here is still missing, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5).

@throny throny added the duplicate This issue or pull request already exists label Dec 1, 2026
@throny throny closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.