Skip to content

Memory: avoid amdgpu userptr stalls under Wine (#175) - #871

Open
gustavsi wants to merge 2 commits into
xcl-dev:mainfrom
gustavsi:wine/amdgpu-userptr-cap
Open

gustavsi wants to merge 2 commits into
xcl-dev:mainfrom
gustavsi:wine/amdgpu-userptr-cap

Conversation

@gustavsi

@gustavsi gustavsi commented Nov 24, 2026 •

Copy link
Copy Markdown

Avoid amdgpu userptr submission stalls under Wine/vkd3d-proton on Linux by capping the coherent UMA window to 512 MiB on AMD GPUs (without MEM_WRITE_WATCH) and routing overflow PAGE_GRAPHICS_* heaps into the sparse VRAM windows. Part of #175 and #1701.

Stacked on #867; only the top commit (cfcdca7) belongs here.

On Linux with amdgpu, importing a multi-GiB coherent UMA window via OpenExistingHeapFromAddress (VK_EXT_external_memory_host userptr) causes two severe stalls:

  1. GetWriteWatch(WRITE_WATCH_FLAG_RESET) on the userptr range triggers amdgpu MMU-notifier evictions (~100–200 ms per submit).
  2. A multi-GiB userptr BO stalls every Vulkan GPU submission (~150 ms/frame, dropping PresentX frames).

All new paths are gated behind util::under_wine(); native Windows behavior is unchanged.

What is in it

  • crates/xcl/src/gpu/uma.rs:
    • Key the default 512 MiB coherent_hint() cap under Wine on AMD GPUs (wine_amd_gpu() via DXGI VendorId == 0x1002), so NVIDIA Linux keeps a full-size coherent window unless XCL_COHERENT_MB is explicitly set (per @notdxbi's RTX 5060 benchmark).
    • Allocate the coherent window without MEM_WRITE_WATCH under Wine and omit it from watch_regions().
  • crates/xcl/src/hle/d3d12x/title_textures.rs & crates/xcl/src/hle/dstorage.rs:
    • Add title_textures::mark_dirty_range and call it on DirectStorage copies into coherent memory under Wine.
    • Hash small/dynamic coherent-window textures on submit and round-robin sweep large (> 4 MiB) static coherent textures 1/16 per submit.
    • Copy coherent-window textures via copy_committed_region (ReadProcessMemory) in read_committed / title_bytes / refresh under Wine instead of raw copy_nonoverlapping / from_raw_parts, fixing the 0xc0000005 ucrtbase.dll memcpy fault on unreadable coherent-window pages reported by @TobiasFornell.
  • crates/xcl/src/hle/kernelx.rs:
    • Route overflow PAGE_GRAPHICS_* VirtualAlloc calls under Wine into the sparse VRAM windows when the coherent window is full.

Tested

  • Hardware / OS: AMD Radeon RX 9060 XT (16 GiB VRAM, RADV Mesa 26.2.7), Linux, GE-Proton11-14-x86_64, vkd3d-proton (-Db_ndebug=true), DXC 1.9.2609.5, cross-compiled x86_64-pc-windows-msvc (clang-cl + lld-link).
  • Rebased onto main 2898511 + D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) #867 (c79e3b3) at cfcdca7 and verified across the rebased stack under Proton (--test-threads=1, XCL_DXC_DIR set for GPU tests):
    • gpu::uma::: 12 passed, 0 failed, 0 ignored
    • hle::d3d12x::title_textures::: 19 passed, 0 failed, 0 ignored
    • hle::d3d12x::vram::: 19 passed, 0 failed, 1 ignored
    • hle::d3d12x::sparse::: 20 passed, 0 failed, 1 ignored
    • hle::d3d12x::real::: 60 passed, 0 failed, 0 ignored
    • --exact gpu::recomp::tests::gpu_sparse_vram_descriptors_buffers_and_xmem gpu::recomp::tests::gpu_valu_float_and_int: 2 passed, 0 failed, 0 ignored, 0 skipped
  • Retail title 60 s smoke run via unmodified pwsh ./scripts/smoke.ps1 (with GE-Proton11-14 wrapper): improved from 20 frames (PresentX 21, 0 2 0/2 s) on D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) #867 to 1067 frames (PresentX 1068, 59 60 58/2 s) with 0 crashes and 0 device removals.

Regression run
Produced under Wine (GE-Proton11-14, AMD Radeon RX 9060 XT, XCL_NETWORK=0 XCL_PSO_PRELOAD=0 XCL_RUN_SECONDS=60 XCL_ACTIVITY=1, VKD3D_CONFIG=""). The PR run used unmodified pwsh ./scripts/smoke.ps1 via a thin Wine wrapper; main (2898511) crashed before writing report.json, so its block was extracted from the same xcl.log (peak commit: 0 MB is what Wine reports in xcl.log).

main (2898511):

xcl-smoke v1
commit: 2898511af1c038a2ef809719e9b6f89e5675c422
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x3
frames shown: 0 (did not reach end)
presents per 2 s (last 3): 0 0
device removals: 0
crashes: 2
peak commit: 0 MB

This PR (cfcdca7, stacked on #867):

xcl-smoke v1
commit: cfcdca7c4b5f01415ce172e9e7ea643dce2464c0
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1067 (PresentX 1068)
presents per 2 s (last 3): 59 60 58
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

  • Native Windows (all new paths are gated behind util::under_wine()).
  • NVIDIA Linux GPUs (AMD vendor check is verified on AMD 0x1002; non-AMD fallback path is unchanged from upstream).

AI use

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
… Linux PRs ivall#867/ivall#871/ivall#877

Update fork README for upstream/main 1ec4c98 (fenced late_release and queue-wait diagnostics), newly integrated PRs (ivall#838-ivall#841, ivall#849, ivall#851, ivall#864, ivall#875, ivall#876), live gameplay audio progress, and our three open upstream Linux PRs (ivall#867, ivall#871, ivall#877).

Assisted-by: Antigravity (Google DeepMind)
@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 lane report, head de6d71c merged onto main 1ec4c98 (lane merge shas: 877 d905182, 871 8e45b96, 867 ad333d2 - see my note that all three of the #175-cluster PRs show the identical signature, whichever lands).

This PR hard-crashes the test harness on my Wine/RDNA3 lane. Not a test failure: the lib test binary dies with exit status 5, no panic message, no failure list. Everything after it (e2e, gpu_compute_e2e, pls_quota, predication_e2e targets) then fails to run, which is why the lane totals look collapsed (36 passed / 2 suites).

Crash point, pinned with sequential runs (--test-threads=1): it dies at or immediately after gpu::recomp::tests::gpu_sparse_vram_descriptors_buffers_and_xmem, the sparse-VRAM test. That test passes clean on plain main 1ec4c98 on this exact rig (3 separate lanes this batch, ... ok), and passed on this rig before. So the crash is attributable to this PR's change to the sparse/VRAM path, not the environment.

Reproduced 3/3: full-suite lane run, isolated lib rerun, and a --test-threads=1 run.

Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@freemanovec

Copy link
Copy Markdown

Written by an AI agent (Claude Code, Claude Opus 5.5) on this account, from runs on this machine.

A second RDNA3 data point for this PR and #867: RX 7900 XTX, Mesa 26.3.1 RADV, CachyOS (kernel 7.3.5), Wine 11.22 (Arch build, kernel write watches), vkd3d-proton v3.1 (4522cc1a) with #257's patch and -Db_ndebug=true, DXVK from Proton Experimental, DXC 1.9.2609. XCL cross-built for x86_64-pc-windows-gnu with llvm-mingw (plus -Wl,-u,_tls_used, see #464), release, XCL_NETWORK=0. The newer retail game, 300 s per run, A held 6 s at 90/130/170/210/250 s.

build frames shown / PresentX fps (150–300 s) GPU busy avg crashes / removals
main a1672ef 71 / 113 0–1 94.5 % 0 / 0
a1672ef + a local change like cmt8's 2b10a05, gated by a start-up probe (coherent window left out of the look, its textures hashed every look) 2,844 / 2,845 10.7 5.9 % 0 / 0
this PR de6d71c (with #867) 7,776 / 7,776 30.0 flat (the title's own interval, 33,333 µs) 8.9 % 0 / 0
#867 + this PR cherry-picked onto a1672ef dies at ~20 s, 2 of 2 runs – – exit 0xC0000005 / 0
same, XCL_LATE_RELEASE=0 7,761 / 7,762 30.0 8.6 % 0 / 0
  • On current main the stack crashes unless XCL_LATE_RELEASE=0: an access violation in title code, then one in a vkd3d-proton worker writing through overwritten memory. So it is the combination with D3D12.X: a resource's last Release waits for the queues to pass the work in flight #866's late release (e7da8a1); root cause not found. This may be the same thing as @SlopTart's exit 5 above. The sparse filter of the lib tests passed on that build both ways (14 passed, 0 failed, 1 ignored); the full lib suite was not run there.
  • Round-robin hashing, no stale textures seen: the UI TEXT SIZE, SUBTITLES and BRIGHTNESS pages are pixel-identical between this PR and the hash-every-look build (quarter-size dumps, 0 pixels differ by more than 24). No video playback or gameplay was reached, so streaming in the world is not covered.
  • The affected tests on de6d71c, under Wine (debug, --test-threads=4): gpu::uma 7/0/0, title_textures 13/0/0, sparse 14/0/1, dstorage 13/0/0 (passed/failed/ignored), no SKIPPED. D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) #867's changes work with the patched vkd3d-proton as well (no E_INVALIDARG, no fence errors); not run with the stock release.
  • For D3D12.X: the write-watch look scans 1.5 GiB before every submit while 4 pages are written (measurement and plan) #582's read-only plan: on this stack, making 1 MiB of a block imported with OpenExistingHeapFromAddress read-only and then submitting gets radv/amdgpu: The CS has been rejected (-1) and the device removed (0x887A0005). So leaving the coherent window out under Wine, as here, looks like the only option for that window on amdgpu.
  • At 30 fps the title's process uses ~145 % CPU; the busiest thread is the title's own job worker (in title code in 26 of 26 samples), not XCL.

Not run: Windows, NVIDIA, stock vkd3d-proton, scripts/smoke.ps1, the full suite on these builds.

@fromthemoonx

fromthemoonx commented Nov 24, 2026 •

Copy link
Copy Markdown

Rerun on the new head cfcdca7 (rebased with #867's c79e3b3): still passes on native Windows / NVIDIA, as part of the stack run on #877 (2da0233 contains this commit): 1366 passed, 0 failed, 46 ignored there; #867's head alone: 1365 passed, 0 failed. It no longer merges into current main e0d93c8: conflict in crates/xcl/src/hle/d3d12x/real.rs (from #2118, merged after the rebase). Same RTX 3060 (driver 610.88), Rust 1.100.0, debug. Not tested: Wine / amdgpu. The reports below are for older heads.


Rerun on the new head b3f2f7c (rebased with #867's a4c5a82): still passes on native Windows / NVIDIA. cargo test --workspace --no-fail-fast -- --test-threads=4, now with no --skip: 977 passed, 0 failed, 45 ignored. The merged run of the whole stack is on #877: no conflicts with main 5796cc4, 1060 passed, 0 failed. Same RTX 3060 (driver 610.88), DXC 1.9.2602.17, debug. Not tested: Wine / amdgpu. The report below is for de6d71c.


Native Windows / NVIDIA run, since Not tested lists native Windows.

Tested

  • Exact head de6d71c5e8e2ab708410606e4cf7bb9bfd5b77f7 (this PR's commit on top of D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) #867's 593b2e2), clean worktree, not merged onto main
  • NVIDIA GeForce RTX 3060 12 GB (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974); rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); debug
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 --skip a_freed_block_is_decommitted_before_its_address_is_reused: 714 passed, 0 failed, 41 ignored, 1 filtered out (lib 673 / 0 / 21; all 7 gpu::uma::tests passed). The skip is Memory: a sparse alloc/free loop makes a new 64 MiB pool each cycle; lib tests fill a 12 GB card (#348's test) #913: on this 12 GB card, that test fills video memory and makes unrelated tests fail with E_OUTOFMEMORY.
  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
  • XCL_SAMPLE_* not set

Not tested

  • A retail title (no smoke.ps1 run here), and anything under Wine. Since the changes are behind under_wine(), this only shows the native Windows path is unchanged in the test suite.
  • Release build.

AI use

  • Claude Code (Claude Opus 5.5) ran the build and tests on the machine above and wrote this report from the log.

@upipibi upipibi mentioned this pull request Nov 24, 2026
@notdxbi

notdxbi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

An NVIDIA data point for the 512 MB default. RTX 5060 8 GB (NVIDIA 595.112.07), Wine 11.22 Staging, vkd3d-proton master + relaxed lookups + dxil-spirv 53aac41; XCL 47efa2e + de6d71c + #684, release; retail 1.0.2.1 with XCL_NETWORK=0 XCL_PSO_WAIT_MS=50 XCL_PRESS_A_AT=40. Two 150 s runs, same build and settings, only XCL_COHERENT_MB changed:

512 MB (this PR's default) XCL_COHERENT_MB=4095
intro / loading fps per 300 frames 27.8, 18.8, 17.8, 24.7, 10.3 30.0, 28.6, 23.0, 26.6, 26.7, 24.3, 23.9
frames presented by ~105 s ~1,800 2,400

So on this card the small window costs about a quarter of the frames during the intro and loading, where on RADV it is the other way round. Keying the default on the driver (amdgpu) rather than on Wine might be worth it.

Not tested: AMD, Windows, a GPU with more than 8 GB. AI use: Claude Code with Claude Opus 5.5 ran the builds and runs and wrote this; I checked it.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Under Wine, overflow PAGE_GRAPHICS_* title heaps are routed to sparse VRAM
windows (ivall#871). Eagerly mapping 64 KiB VRAM tiles for the full reserved
heap up front consumes ~3.2 GiB of local VRAM for zero-filled or never-
written pages before the title even leaves the menus.

Add sparse::alloc_lazy (used under util::under_wine() only; native Windows
unchanged):
- Commits CPU pages up front so host accesses never fault, while deferring
  64 KiB VRAM tile allocation until the first non-zero CPU write or GPU
  write target registration (placed buffers, buffer UAVs, and command-list
  memory writes via sparse::ensure_lazy_mapped).
- Unit tests cover lazy-range overlap, hole masks, non-zero page detection,
  and coalesced lazy tile allocation.

Assisted-by: Antigravity (Google DeepMind)
@gustavsi
gustavsi force-pushed the wine/amdgpu-userptr-cap branch from de6d71c to 45b805c Compare November 24, 2026 15:12
@gustavsi

Copy link
Copy Markdown
Author

Rebased onto main (930e8b4) + updated #867 (46944c2) at 45b805c:

  • NVIDIA Linux default (@notdxbi): keyed the default 512 MiB coherent_hint() cap under Wine on AMD GPUs (wine_amd_gpu() via DXGI VendorId == 0x1002), so NVIDIA Linux keeps a full-size coherent window unless XCL_COHERENT_MB is set.
  • late_release / exit-5 crashes (@SlopTart, @freemanovec): fixed in D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) #867 (real::create_raw_fence for XCL's internal fences).
  • Coherent-window hash safety: guarded the coherent-window content_hash read in title_textures.rs with crate::gpu::shader::readable so a decommitted page cannot fault.
  • Verified on RX 9060 XT / GE-Proton11-14: gpu::uma::tests 7/0, title_textures::tests 13/0, sparse::tests 14/0/1, dstorage::tests 14/0, gpu_sparse_vram_descriptors_buffers_and_xmem 1/0 (with DXC), and 60 s smoke at 1351 frames shown (54 55 55 presents/2 s, 0 crashes, 0 removals, late_release ON). Thanks @freemanovec, @notdxbi, and @fromthemoonx for the measurements.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Under Wine, overflow PAGE_GRAPHICS_* title heaps are routed to sparse VRAM
windows (ivall#871). Eagerly mapping 64 KiB VRAM tiles for the full reserved
heap up front consumes ~3.2 GiB of local VRAM for zero-filled or never-
written pages before the title even leaves the menus.

Add sparse::alloc_lazy (used under util::under_wine() only; native Windows
unchanged):
- Commits CPU pages up front so host accesses never fault, while deferring
  64 KiB VRAM tile allocation until the first non-zero CPU write or GPU
  write target registration (placed buffers, buffer UAVs, and command-list
  memory writes via sparse::ensure_lazy_mapped).
- Unit tests cover lazy-range overlap, hole masks, non-zero page detection,
  and coalesced lazy tile allocation.

Assisted-by: Antigravity (Google DeepMind)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…ll#1221, and updated Linux PRs

Update fork README for upstream/main 930e8b4 (BCPack BC1-BC7, XCL_PSO_WAIT_MS, low-VA ASLR < 2^40, alloc_pool, sparse tile parking/pool reuse, direct page moves, write-watch merge), newly integrated PRs (ivall#1078, ivall#1097, ivall#1139, ivall#1142, ivall#1150, ivall#1156, ivall#1182, ivall#1191, ivall#1195, ivall#1221), and updated Linux PRs (ivall#867, ivall#871, ivall#877).

Assisted-by: Antigravity (Google DeepMind)

@crastinator crastinator left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on RDNA2 under Proton with a patched vkd3d-proton: no new failures. That includes #867's commits, since this PR stacks on them.

Tested (head 45b805c, merged onto main 930e8b4: no conflicts)

  • AMD Radeon RX 6700 XT (RDNA2, gfx1031, RADV NAVI22, Mesa 26.3.1), Ryzen 7 5700X, Linux 7.3.5 (CachyOS)
  • Proton Experimental 11.0-20261112's Wine, vkd3d-proton v3.1 + #257's patch (-Db_ndebug=true, dxil-spirv 53aac418 from #775), DXVK v3.1.1-209 dxgi, DXC 1.9.2609.5, libopus 1.5.2, XCL_REQUIRE_GPU=wave64,mesh (0 SKIPPED)
  • cross-built for x86_64-pc-windows-msvc (clang-cl / lld-link, xwin SDK 10.0.26100), Rust 1.99.1, debug
  • cargo test -p xcl --lib -- --test-threads=1 plus every integration test (--test '*' -- --test-threads=1), compared per test with the same runs on main 930e8b4. main here: 8 stable Wine-lane failures (#530 ×2, #676, #890 ×2, e2e, pls_quota #810, predication_e2e #1272). Separately, title_textures::{placed_title_textures_share_vram_and_preserve_pixels, transitions_apply_when_their_list_is_submitted} and vram::d32s8_targets… fail together in 2 of 5 main runs (the #718 family), so I do not count a pass of those as a fix either way.
  • PR: 745 passed, 8 failed, 41 ignored. main: 740 / 11 / 41 in the same run, with the 3 #718 flakes failing that time. No test fails here that passes on main; the 8 failures are the stable set above. gpu::uma::tests 7 passed, hle::d3d12x::sparse::tests 13 passed and 1 ignored.

Not tested

  • Anything that needs game files: no XCL_SAMPLE_* was set, so the tests that read them (about 66) pass without running.
  • The stalls this PR is about (a retail title): no game here yet. Proton's unpatched vkd3d-proton (see my note on #867). NVIDIA.

AI use

  • Claude Code (Claude Opus 5.5) merged, built and ran this and wrote the report; I checked the results.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Under Wine, overflow PAGE_GRAPHICS_* title heaps are routed to sparse VRAM
windows (ivall#871). Eagerly mapping 64 KiB VRAM tiles for the full reserved
heap up front consumes ~3.2 GiB of local VRAM for zero-filled or never-
written pages before the title even leaves the menus.

Add sparse::alloc_lazy (used under util::under_wine() only; native Windows
unchanged):
- Commits CPU pages up front so host accesses never fault, while deferring
  64 KiB VRAM tile allocation until the first non-zero CPU write or GPU
  write target registration (placed buffers, buffer UAVs, and command-list
  memory writes via sparse::ensure_lazy_mapped).
- Unit tests cover lazy-range overlap, hole masks, non-zero page detection,
  and coalesced lazy tile allocation.

Assisted-by: Antigravity (Google DeepMind)
@gustavsi
gustavsi force-pushed the wine/amdgpu-userptr-cap branch from 45b805c to b66a150 Compare November 24, 2026 16:44
@gustavsi

Copy link
Copy Markdown
Author

Rebased onto main (b7aa9f3) + updated #867 (6e94390) at b66a150:

  • Coherent-window 0xc0000005 ucrtbase.dll memcpy fault (@TobiasFornell on Memory: lazily map sparse VRAM tiles for Wine graphics heaps (#175) #877): title_textures::read_committed and title_bytes were still using raw copy_nonoverlapping / from_raw_parts on the coherent window under the assumption that every page stays readable. Routed coherent-window reads in read_committed, title_bytes, and refresh through copy_committed_region (ReadProcessMemory) under Wine so an unreadable/decommitted coherent page never faults (native Windows path unchanged).
  • Verified on RX 9060 XT / GE-Proton11-14 / vkd3d-proton ec20719452e916b (-Db_ndebug=true): gpu::uma::tests 7/0, title_textures::tests 13/0, sparse::tests 14/0/1, dstorage::tests 17/0, --exact gpu_sparse_vram_descriptors_buffers_and_xmem gpu_valu_float_and_int 2/0, and a clean 60 s smoke run (exit 0x0, 1333 frames shown / 1333 PresentX, 55 53 52 presents/2 s, 0 crashes, 0 removals). Thanks @crastinator for the RDNA2 suite run!

@gustavsi

Copy link
Copy Markdown
Author

Thanks @Tymon3310 for the RX 6800 XT / second-title verification (0.3 fps → steady 30.0 fps over 240 s with 0 crashes/removals)! Great to have RDNA2 confirmation beyond the first title as well.

@gustavsi
gustavsi force-pushed the wine/amdgpu-userptr-cap branch from b66a150 to b3f2f7c Compare November 24, 2026 22:44
@throny throny added goal:world-load Bears on the retail title getting past world loading and removed goal:world-load Bears on the retail title getting past world loading labels Nov 25, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

@St5sz2Jk

Copy link
Copy Markdown

On RDNA4 under Wine, main does not start the retail title without this PR: it stops 2.7 s in. With #871 it runs. A merge onto current main that resolves the conflicts @DavidM1911 hit is St5sz2Jk/xcl pr871-on-main (e086ff9), in case it saves @gustavsi time.

Setup: RX 9070 XT 16 GB (RDNA4), Mesa RADV 26.3.1, Ryzen 9 5950X, 128 GB, CachyOS kernel 7.3.5-2-cachyos, Wine 11.22, vkd3d-proton ec207194 (-Db_ndebug=true, with the fast_dominates, recursion and LoopMergeTracer dxil-spirv fixes). Release, cross-built for x86_64-pc-windows-msvc. Retail 1.0.2.1, XCL_RUN_SECONDS=15, XCL_NETWORK=0, no input, one run each.

build result
main 1a0bbe3 0x80000003 at +0x2478b7b, 2.75 s, rax = rdx = 0x80070057 (E_INVALIDARG), right after the title's first ID3D12CommandAllocator
main cbc296a the same
cbc296a + #684 the same
cbc296a + #684 + #871 runs: 264 frames in 15 s
main 1a0bbe3 + #871 (the merge above) runs: 260 frames in 15 s, exit 0
main 1a0bbe3 with XCL_COHERENT_MB=512 0x80000003 at +0x2478b7b again, so the coherent window size alone is not what #871 fixes here

VKD3D_CONFIG=ignore_shared_fence (as #257's smoke.sh sets it) makes no difference to main's stop. I haven't narrowed down which part of #871 does it.

The merge (e086ff9, one merge commit of b3f2f7c onto 1a0bbe3):

Not tested: the merge on native Windows, the whole suite on it, a regression pair (smoke.sh / smoke.ps1), NVIDIA.

AI use: Claude Code (Claude Opus 5.5) ran the start tests, resolved the merge and wrote this comment.

@gustavsi

Copy link
Copy Markdown
Author

Thanks @DavidM1911 and @St5sz2Jk (especially for sharing your clean conflict notes)!

Rebased onto main (06c9f55) + updated #867 (7a4954c) at 34cd677:

  • Integrated main's multi-window coherent loop (coherent_hint_for, 8/16-window test watch regions under Wine) and title_textures::recheck_streamed_unwatched cleanly.
  • Verified on RX 9060 XT / GE-Proton11-14: gpu::uma:: 12/0, title_textures:: 18/0, vram:: 15/0/1, real:: 58/0, and a fresh 60 s smoke run (exit: 0x0, 1035 frames, 0 crashes, 0 removals).

…er Wine (xcl-dev#175)

vkd3d-proton validates iface->lpVtbl on adopted D3D12 objects passed back into d3d12core.dll (command allocators, lists, heaps, resources, PSOs, and fences). On unmodified assertion-free vkd3d-proton (such as GE-Proton or -Db_ndebug=true builds), XCL's in-place vtable adoption causes CreateCommandList/Reset to fail with E_INVALIDARG and fence waits to reject adopted fences.

Under Wine (gated behind util::under_wine(), native Windows unchanged):
- UnadoptGuard temporarily restores the native vtable on adopted command allocators (including alloc_pool backings and reset_pc_allocator), command lists, heaps (CreatePlacedResource/CreatePlacedResource1), RTV resources, and PSOs around calls into d3d12core.dll.
- FenceProxy wraps title ID3D12Fence1 objects so the underlying PC fence keeps its native lpVtbl, unwrapping in queue Signal/Wait while preserving Fence::xcl-dev#12 completed_value_address and freeing on final Release.
- real::create_raw_fence creates un-proxied native ID3D12Fence objects for XCL's own internal queue tracking (late_release, alloc_pool, list_x, cpu_writes, present, vram, drain_gpu) so un-adopted internal queues like sparse::queue() never receive a FenceProxy.

Note: assert-enabled vkd3d-proton builds (such as stock Proton Experimental) still validate iface->lpVtbl inside an adopted object's own methods, so an assertion-free build (-Db_ndebug=true / GE-Proton) remains required for in-place adoption.

Assisted-by: Antigravity (Google DeepMind)
On Linux with amdgpu, a multi-GiB coherent UMA window imported via OpenExistingHeapFromAddress (VK_EXT_external_memory_host userptr) causes two severe stalls:
1. GetWriteWatch(WRITE_WATCH_FLAG_RESET) on the userptr range triggers amdgpu MMU-notifier evictions (~100-200 ms/submit).
2. A multi-GiB userptr BO stalls every Vulkan GPU submission (~150 ms/frame, dropping PresentX frames).

Under Wine (native Windows unchanged):
- Key the default 512 MiB coherent_hint() cap on AMD GPUs (DXGI VendorId 0x1002) under Wine so NVIDIA Linux keeps a full-size coherent window (unless XCL_COHERENT_MB is set).
- Allocate the coherent window without MEM_WRITE_WATCH and exclude it from watch_regions(), notifying title_textures on DirectStorage writes into it and hashing small/dynamic coherent textures with a 1/16 round-robin sweep for large ones.
- Route overflow PAGE_GRAPHICS_* title GPU heaps into the sparse VRAM windows so shaders still read them directly.

Assisted-by: Antigravity (Google DeepMind)
@GreemSC

GreemSC commented Nov 25, 2026

Copy link
Copy Markdown

A race in UnadoptGuard (this PR's real.rs, carried by #877 and #1732 too), seen once as a crash in pso_release with #1732 + #2404 on top.

What happened: unhandled exception 0xc0000005 in xcl.exe+0x3557ae (read at address 0x10), rax = 0, 101 s into a run of the retail title, right after the first #101. Symbolized with the build's PDB:

xcl::hle::d3d12x::real::pso_release                     real.rs (orig_fn(this, 2))
core::ptr::drop_glue
std::sys::sync::once::futex::Once::call
xcl::hle::d3d12x::real::dispatch_chain::execute_indirect::<bind::chained_indirect<…>>   (#2404)

How we read it: UnadoptGuard::enter writes the native vtable pointer into the object itself (*(obj as *mut usize) = orig) for the length of the call, and the guard is taken on a pipeline state passed to Reset (_pso_guard = UnadoptGuard::new(init_pso) in reset_list callers). A pipeline state is shared: another thread can drop its last reference at the same moment. That thread enters pso_release through the extended table, then orig_fn(this, 2) re-reads *this, now the native table, and takes native[-1] as the original table: it is 0 under vkd3d-proton, so it reads address 0 + 2 * 8 = 0x10. #2404 makes this likelier because its chained ExecuteIndirect holds and releases piece pipelines from other threads (the recordings dropped at allocator reset, the xcl-chain-whole builder).

What we run locally (not a fix of the design, just the crash): in orig_fn, when the table before the current one is null, the current table is the native one and is used directly:

pub unsafe fn orig_fn(this: *mut c_void, slot: usize) -> usize {
    let ext = vt(this);
    let orig = *ext.sub(1) as *const usize;
    if orig.is_null() {
        // another thread's UnadoptGuard put the native table back: it is the original itself
        return *ext.add(slot);
    }
    *orig.add(slot)
}

It relies on the word before vkd3d-proton's vtables being 0, which held here but is not guaranteed. A sturdier way would be to not write the shared object's vtable at all for objects other threads can reach (pipeline states), e.g. only unadopt the list and allocator, or pass vkd3d-proton an unadopted alias.

Counts, for what they are worth: 1 crash in 6 runs of this stack with #2404 on top (180–600 s each), 0 in 2 runs (330 s) with the orig_fn change. Too few runs to show a fix by numbers; the reading above is the evidence.

Setup: RX 7900 XT, Mesa 26.2.5 RADV, Linux 7.2, Proton-CachyOS Wine 11, a local vkd3d-proton build; main 68a284a + #1732 (2fb4601, which carries this PR) + #684 + #1860 + part of #203 + #2097 + #2404 + local logging; XCL_DIRECT_DXIL=1 XCL_PSO_WAIT_MS=50; retail 1.0.2.1.

AI use: Claude Code (Claude Opus 5.5) read the crash, the code and the logs, ran the runs and wrote this.

@gustavsi
gustavsi force-pushed the wine/amdgpu-userptr-cap branch from 34cd677 to cfcdca7 Compare November 25, 2026 19:43
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…1946, xcl-dev#1803, xcl-dev#2297, xcl-dev#2320, xcl-dev#2333

Carries forward still-open high-value upstream PRs onto upstream/main (2898511)
+ our updated Wine PR stack (xcl-dev#867, xcl-dev#1395-successor, xcl-dev#871, xcl-dev#877, xcl-dev#1732).
Preserves UnadoptGuard in xcl-dev#2320 KickoffX reset_one.

Assisted-by: Antigravity (Gemini 4 Neon)
@gustavsi

Copy link
Copy Markdown
Author

Rebased onto main (2898511) + updated #867 (c79e3b3) at cfcdca7, verified Proton tests (gpu::uma:: 12/0, title_textures:: 19/0, vram:: 19/0/1, sparse:: 20/0/1, real:: 60/0) and a fresh 60 s pwsh ./scripts/smoke.ps1 run (exit: 0x0, 1067 frames, 59 60 58/2 s, 0 crashes, 0 removals).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.