Skip to content

D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) - #867

Open
gustavsi wants to merge 1 commit into
xcl-dev:mainfrom
gustavsi:wine/vkd3d-vtables
Open

gustavsi wants to merge 1 commit into
xcl-dev:mainfrom
gustavsi:wine/vkd3d-vtables

Conversation

@gustavsi

@gustavsi gustavsi commented Nov 24, 2026 •

Copy link
Copy Markdown

Preserve native COM vtables around d3d12core.dll calls and wrap ID3D12Fence1 in a thin proxy under Wine so XCL runs on unmodified assertion-free vkd3d-proton (no vkd3d-proton vtable-check patch required). Part of #175 and #1701.

vkd3d-proton validates iface->lpVtbl on adopted D3D12 objects passed back into d3d12core.dll (ID3D12CommandAllocator, ID3D12GraphicsCommandList, ID3D12Heap, ID3D12Resource, ID3D12PipelineState, and ID3D12Fence, including on its async queue thread). With XCL's in-place vtable adoption, unmodified assertion-free vkd3d-proton (GE-Proton or -Db_ndebug=true builds) rejects adopted allocators/lists with E_INVALIDARG and fails fence calls. Native Windows behavior is unchanged (all new paths are gated behind util::under_wine()).

Note: assert-enabled vkd3d-proton builds (such as stock Proton Experimental) also validate iface->lpVtbl inside an adopted object's own methods (for example d3d12_heap_GetDesc), so either an assertion-free build (GE-Proton / -Db_ndebug=true) or complementary in-place vtable patching for the assert-only classes (#2477, stacked on this PR) is needed there.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs:
    • Add refcounted UnadoptGuard (UNADOPTED per-object active count with atomic vtable stores and 8-byte pointer alignment check) to temporarily restore native vtables 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 without restoring early under concurrent guards.
    • Pin +1 COM reference via native AddRef before exposing the native vtable on the first active guard, and release it via XCL's hooked Release slot after restoring the extended vtable (outside UNADOPTED) on the last guard drop: even if another thread concurrently loads the native vtable and calls Release, refcount stays >= 1 during the guard window and the final 1 -> 0 transition always executes XCL's hooked cleanup (pso_release, heap_release, res_release, cl_release, alloc_release).
    • Track unadopted native vtables lock-free (register_native / is_known_native) so orig_fn reads *ext.add(slot) directly if another thread enters a hook while an UnadoptGuard temporarily restored the native vtable on a shared object (fixes the 0xc0000005 orig_fn(this, 2) race reported by @GreemSC).
    • Add FenceProxy (wrap_fence_proxy, unwrap_fence, fence_proxy_release, fence_proxy_signal, fence_proxy_qi) so title PC fences keep their native lpVtbl while preserving console slot #12 (completed_value_address), unwrapping in CommandQueue::Signal / Wait, and freeing on final Release.
    • Add create_raw_fence so XCL's own internal queue tracking (late_release, alloc_pool, list_x, cpu_writes, present, vram, sparse, drain_gpu) creates raw un-proxied ID3D12Fence objects and never passes a FenceProxy to un-adopted internal queues like sparse::queue().
    • Add unit tests in wine_vtable_tests: unadopt_guard_restores_native_vtable_and_reapplies_extended_on_drop, concurrent_release_during_unadopt_guard_still_runs_hooked_cleanup (verifies a concurrent thread calling native Release during an active guard cannot finalize the object and the guard exit runs hooked pso_release cleanup), and fence_proxy_forwards_signal_unwraps_and_frees_on_final_release.
  • crates/xcl/src/hle/d3d12x/alloc_pool.rs, cpu_writes.rs, late_release.rs, list_x.rs, present.rs, sparse.rs, vram.rs:
    • Use real::create_raw_fence for XCL's internal fences and guard alloc_pool::reset_list / KickoffX / #2118 deferred-dispatch Reset / mid-list split calls with UnadoptGuard.
  • crates/xcl/src/gpu/recomp/runner.rs:
    • Add submit_list using real::UnadoptGuard so tests running after real::init() adopts the process-wide singleton ID3D12Device do not submit an adopted command list to the runner's pre-existing un-adopted ID3D12CommandQueue.

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, unmodified vtable checks), DXC 1.9.2609.5, cross-compiled x86_64-pc-windows-msvc (clang-cl + lld-link).
  • Rebased onto main 08db8020 at e57cb659 and verified under Proton (XCL_DXC_DIR set for GPU tests):
    • hle::d3d12x::real:: --test-threads=1: 62 passed, 0 failed, 0 ignored (including all three wine_vtable_tests, with the new concurrent-Release-during-UnadoptGuard regression)
    • hle::d3d12x::list_x:: --test-threads=1: 40 passed, 0 failed, 0 ignored
    • hle::d3d12x::alloc_pool:: --test-threads=4 (× 3): 4 passed, 0 failed, 0 ignored each
    • --exact gpu::recomp::tests::gpu_sparse_vram_descriptors_buffers_and_xmem gpu::recomp::tests::gpu_valu_float_and_int --test-threads=1: 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): main (e0d93c84) exits 0x3 (2 crashes, 0 frames); this PR (e57cb659) runs the full 60 s cleanly (exit: 0x0, 18 frames shown / PresentX 19, 0 crashes, 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 (e0d93c84) 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 (e0d93c84):

xcl-smoke v1
commit: e0d93c84ad8253f6e17738d14741c1bab7061127
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 (e57cb659):

xcl-smoke v1
commit: e57cb659b8f99801089846cbf680dc9964e6800c
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 18 (PresentX 19)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

AI use

  • Antigravity (Gemini 4 Neon) assisted with adding the UnadoptGuard COM reference pin and concurrent-Release regression test for @bmjask's P1 review, rebasing onto main (08db8020), running the Proton test/smoke verification, and drafting this update.

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 593b2e2 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.

@fromthemoonx

fromthemoonx commented Nov 24, 2026 •

Copy link
Copy Markdown

Rerun on the new head e57cb65 (the UnadoptGuard reference pin, rebased onto main 08db802): still passes on native Windows / NVIDIA. Merged onto main b49be18 (clean): cargo test --workspace --no-fail-fast -- --test-threads=4 1438 passed, 0 failed, 47 ignored, 25 SKIPPED lines. wine_vtable_tests (3 tests) 40 of 40; hle::d3d12x::real:: (63 tests) at --test-threads=8 30 of 30. The e2e debug-layer messages are the same as main b49be18's (3× error id 93, 1× error id 1046, 1× warning id 820, 8× id 0 at exit). #871 and #877 are not rebased onto this head yet. Same RTX 3060 (driver 610.88), Rust 1.100.0, debug. Not tested: Wine / vkd3d-proton. The reports below are for older heads.


Rerun on the new head 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. Merged onto main 80f4819 (no conflicts; auto-merged cpu_writes.rs, list_x.rs, real.rs): 995 passed, 0 failed, 45 ignored. The e2e debug-layer messages on the merged tree are the same as main 80f4819's (3× error id 93, 1× error id 1046, 1× warning id 820, plus the exit-time live-object report). Same RTX 3060 (driver 610.88), DXC 1.9.2602.17, debug. Not tested: Wine / vkd3d-proton (none here). The report below is for 593b2e2.


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

Tested

  • Exact head 593b2e21fc0d4659861587ca426a0e30c57c590c, 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). 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.
  • Both new tests passed: wine_vtable_tests::fence_proxy_forwards_signal_unwraps_and_frees_on_final_release, wine_vtable_tests::unadopt_guard_restores_native_vtable_and_reapplies_extended_on_drop
  • 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: 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.

@sander110419

Copy link
Copy Markdown

Test report for 593b2e2 (this PR's head, on its own base), Linux:

  • NVIDIA GeForce RTX 5070 Laptop GPU (8 GB, 32-lane waves), driver 595.104.02; AMD Ryzen 9 9955HX; kernel 7.2.15
  • GE-Proton11-11 (its wine, vkd3d-proton and DXVK), xcl.exe started with that wine directly; release build for x86_64-pc-windows-gnu, rustc 1.99.1
  • The newer retail game in the README table, no VKD3D_CONFIG set, 150 s run: steady 28–30 fps presents (1,800 frames at 94 s), no crash; the run ended at my timeout.

For comparison, same machine:

Not tested: Windows, AMD, cargo test on this commit.

Merging this into 09940bb conflicts in list_x.rs / real.rs with alloc_pool (#897, #907). My resolution (the guards on the alloc_pool allocator that is passed instead of the title's) crashed 12 s in with an access violation in vkd3d-proton's queue thread. That may well be my resolution and not this PR; a rebase by you would settle it.

AI use: Hermes agent with Claude Opus 5.5 (claude-opus-5-5) ran the builds and the game, and wrote this report; I checked it.

@TobiasFornell

Copy link
Copy Markdown

Test report for 593b2e2 (stack head 2f81d51, on its own base) with Proton Experimental's own vkd3d-proton, which nobody seems to have covered yet.

Tested: AMD Radeon RX 9070 XT (RDNA4, 16 GiB), Mesa RADV 26.3.1, CachyOS (kernel 7.3), Proton Experimental 11.0-20261112 (its Wine and its vkd3d-proton 3.2.0, unmodified), DXC 1.9.2609, x86_64-pc-windows-msvc cross-build, retail title 1.0.2.1, XCL_NETWORK=0.

  • Stock vkd3d-proton from Proton Experimental: the title aborts a few seconds in with Assertion failed: iface->lpVtbl == &d3d12_heap_vtbl (vkd3d_private.h:1077), right after the first ID3D12Heap1 is adopted. Valve's build keeps the assertions, and the adopted heap reaches CreatePlacedResource with the extended vtable – this PR's guards cover lists, allocators and fences, not heaps. The start-up check from Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257 reports it correctly.
  • vkd3d-proton v3.1 from scripts/linux/build-vkd3d-proton.sh (-Db_ndebug=true, dxil-spirv 53aac418): boots, reaches the first screen, steady 30 fps for 8 min, no crash, no device removal.

So on Proton Experimental an ndebug build is still required even with this PR (GE-Proton evidently ships one, given @sander110419's run on GE-Proton11-11). A guard for heaps – and any other adopted object passed back as a parameter – would make stock Proton Experimental work.

Testing and write-up assisted by Claude Code (Claude Opus 5.5); runs on my own hardware, checked by me. No game data attached.

@TobiasFornell

Copy link
Copy Markdown

Follow-up to my report above, in case someone wants to make stock Proton Experimental's vkd3d-proton (assertions on) work by extending this PR's UnadoptGuard approach. I tried it locally and it is not enough; notes so nobody repeats it:

  • A local branch on top of this stack added guards for adopted heaps and resources passed as parameters (CreatePlacedResource/1/2, view creation, UpdateTileMappings/CopyTileMappings, MakeResident/Evict/EnqueueMakeResident, CreateSharedHandle …). The title still aborts at the same place: Assertion failed: iface->lpVtbl == &d3d12_heap_vtbl right after the first ID3D12Heap1 is adopted.
  • Reason (vkd3d-proton 3.2.0 source, vkd3d_private.h): the vtable-identity asserts sit in the impl_from_* helpers that the objects' own methods use (heap.c: QueryInterface/AddRef/Release/GetDesc/… all call impl_from_ID3D12Heap1(iface)), not only where an object is passed as a parameter. So every PC method reached through the extended vtable trips it.
  • The same assert exists for 10 interfaces: fence, shared fence, heap, resource, descriptor heap, query heap, root signature, pipeline state, command signature (vkd3d_private.h lines ~710–4068 in 3.2.0).
  • Guarding all of that would mean a vtable swap around every PC method call on every adopted object, which is also racy when two threads use the same object (one sees the native vtable while the other's guard is active).

So for stock Proton the realistic options seem to be proxy objects instead of in-place vtable replacement, or an assertion-free vkd3d-proton build (as scripts/linux does; GE-Proton evidently ships one). Not a criticism of this PR – it fixes what it targets; just the boundary for stock Proton.

Testing and write-up assisted by Claude Code (Claude Opus 5.5); runs on my own hardware, checked by me.

@gustavsi

Copy link
Copy Markdown
Author

Rebased onto main (930e8b4) at 46944c2 and fixed the rebase crashes reported by @SlopTart, @freemanovec, @sander110419, and @TobiasFornell:

  • Root cause of the late_release / alloc_pool / vkd3d_realloc: Out of memory / exit-5 crashes: dev_create_fence was returning a 16-byte FenceProxy to XCL's own internal CreateFence calls (late_release, alloc_pool, etc.), which then signalled un-adopted internal queues like sparse::queue() with a FenceProxy so vkd3d-proton cast the proxy struct as struct d3d12_fence. Fixed by adding real::create_raw_fence for XCL's internal fences and placing UnadoptGuard inside alloc_pool::reset_list closures, reset_pc_allocator, CreatePlacedResource/1, CreateRenderTargetView, and PSO parameters.
  • Stock Proton Experimental (assert-enabled vkd3d-proton): thanks @TobiasFornell for verifying that impl_from_ID3D12Heap1 also fires inside adopted objects' own methods; updated the PR description to state clearly that assertion-free vkd3d-proton (GE-Proton or -Db_ndebug=true) remains required for in-place adoption.
  • Verified on RX 9060 XT / GE-Proton11-14 (--test-threads=1): real:: 24/0, list_x:: 26/0, late_release:: 2/0, alloc_pool:: 3/0, gpu_sparse_vram_descriptors_buffers_and_xmem 1/0 (with DXC 1.9.2609.5, 0 skipped), plus a clean 60 s smoke run with late_release and alloc_pool enabled and VKD3D_CONFIG="". Thanks @fromthemoonx for the native Windows run as well.

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 (RADV) against three vkd3d-proton builds. It works with an unpatched vkd3d-proton built with -Db_ndebug=true, and two gaps are left. Proton's own vkd3d-proton still aborts at two other vtable assertions. And on the unpatched build, one sparse test leaves later GPU tests reading zeros.

Tested (head 46944c2, which already contains main 930e8b4)

  • 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, DXVK v3.1.1-209 dxgi, DXC 1.9.2609.5, XCL_REQUIRE_GPU=wave64,mesh (0 SKIPPED). Cross-built for x86_64-pc-windows-msvc, Rust 1.99.1, debug.
  • cargo test -p xcl --lib -- --test-threads=1 plus every integration test (--test-threads=1), compared per test with main 930e8b4 on the same build:
vkd3d-proton main this PR
Proton Experimental's own (asserts on) the lib binary aborts at iface->lpVtbl == &d3d12_heap_vtbl (vkd3d_private.h:1077). The e2e title hits the same assertion, so that test fails. gpu_compute_e2e aborts at &d3d12_root_signature_vtbl (:2111), and predication_e2e and sparse_reinit abort too the same aborts, at the same assertions
v3.1, no XCL patch, -Db_ndebug=true, dxil-spirv 53aac418 699 passed, 52 failed, 41 ignored 731 passed, 22 failed, 41 ignored. 30 fixed, 0 new; 3 of the 30 are the #718 flaky group
v3.1 + #257's patch, -Db_ndebug=true, same dxil-spirv 740 / 11 / 41 742 / 11 / 41, no new failure
  • So "unmodified vkd3d-proton" holds when the build compiles its assertions out. The vkd3d-proton that Proton (Experimental, and I expect other Proton builds) ships still trips d3d12_heap_vtbl and d3d12_root_signature_vtbl on XCL's adopted heaps and root signatures.
  • On the unpatched -Db_ndebug build, 14 of the 22 remaining failures are a chain: every gpu::recomp test after gpu_sparse_vram_descriptors_buffers_and_xmem in list order reads zeros back. For example, gpu_valu_float_and_int gets lane 0 v_add_f32 left: 0.0, and gpu_unified_memory_arena gets s_load from process memory left: (0, 0). The --exact pair gpu_sparse_vram_descriptors_buffers_and_xmem gpu_valu_float_and_int reproduces it 2/2, and gpu_valu_float_and_int alone passes 2/2. With #257's patch the same pair passes. It looks like something the sparse test does goes through a vkd3d-proton path that is still not covered without the patch. The other 8 are the Wine-lane failures main has with the patch too (#530 ×2, #676, #890 ×2, e2e, pls_quota #810, predication_e2e #1272).

Not tested

  • A retail title. NVIDIA. GE-Proton's vkd3d-proton.
  • Anything that needs game files: no XCL_SAMPLE_* was set, so the tests that read them (about 66) pass without running.

AI use

  • Claude Code (Claude Opus 5.5) built the vkd3d-proton variants, ran the tests and wrote this report; I checked the results.

Update: retested at 6e94390 (rebased on main b7aa9f3, same RX 6700 XT / RADV 26.3.1 / Proton Experimental Wine; --test-threads=1, compared per test with main b7aa9f3 on the same build)

vkd3d-proton main b7aa9f3 6e94390
v3.1, no XCL patch, -Db_ndebug=true, dxil-spirv 53aac418 717 passed, 53 failed 760 passed, 12 failed: 41 fixed, 0 new
v3.1 + #257's patch (same build otherwise) 761 / 9 763 / 9, no new failure
Proton Experimental's own (asserts on) aborts (d3d12_heap_vtbl, d3d12_root_signature_vtbl) the same; #1395's part
  • The chain is gone. --exact gpu_sparse_vram_descriptors_buffers_and_xmem gpu_valu_float_and_int passes 3/3, and all 14 gpu::recomp tests after it pass in the full run.
  • On the unpatched build, the 12 failures left are the same 9 main has with #257's patch, plus the #718 trio (title_textures ×2, vram::d32s8). That trio fails in about 2/5 runs here on main too. So with this PR, the unpatched -Db_ndebug build reaches parity with the patched one in the test suite.
  • Not tested: #867 + #1395 together (once #1395's UnadoptGuard condition is in). A retail title.

@cmt8

cmt8 commented Nov 24, 2026

Copy link
Copy Markdown

For the assert-only classes on stock release builds (heap, resource, descriptor heap, query heap, root signature, pipeline state, command signature), #1395 writes XCL's PC slots into vkd3d-proton's own tables, so those objects keep their vtable pointer. It complements this PR rather than replacing it. One thing for composing the two: UnadoptGuard::new needs to skip tables patched in place (for those, ext[-1] is not the native table), e.g. || in_place_original(*(obj as *const usize), 0).is_some(). Test table for this PR alone and both together on the official v3.1 DLLs is in #1395.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…#1395 in-place vtables

Integrates 16 upstream PRs (xcl-dev#1380, xcl-dev#1383, xcl-dev#1384, xcl-dev#1395, xcl-dev#1398, xcl-dev#1400,
xcl-dev#1404, xcl-dev#1405, xcl-dev#1419, xcl-dev#1420, xcl-dev#1421, xcl-dev#1423, xcl-dev#1424, xcl-dev#1427, xcl-dev#1428, xcl-dev#1429)
on top of the Linux/Proton fork, plus three Proton/vkd3d-proton fixes
caught during verification:
- Recompiler (xcl-dev#1428): flatten IO_GROUP_LIMIT early-return in compute
  shaders so vkd3d-proton v3.1 dxil-spirv accepts the emitted CFG.
- D3D12.X (xcl-dev#1395 + xcl-dev#867): skip UnadoptGuard on in-place-patched vtables
  and restore native vtables in runner::submit_list when a prior test
  adopted the singleton ID3D12Device.
- Tests: match Wine centered default in window_position_modes.

Verified under GE-Proton11-14 (RX 9060 XT / RADV):
- gpu_sparse_vram_descriptors_buffers_and_xmem + gpu_valu_float_and_int
  + window_position_modes: 3 passed, 0 failed
- Broad sweep (present, real, sparse, clamp, dstorage, gpu_valu,
  gpu_typed_buffer): 82 passed, 0 failed, 1 ignored, 0 skipped
- 2.5 min retail title run (XCL_MEM_LIMIT=12G): 3,000+ frames at 30.0
  fps, 6.0-6.1 GB flat committed RAM, 6.4 GB local VRAM, 0 DS failures.
@gustavsi

Copy link
Copy Markdown
Author

Rebased onto main (b7aa9f3) at 6e94390 and addressed the remaining review gap:

  • 14-test zero-read chain after gpu_sparse_vram_descriptors_buffers_and_xmem (@crastinator): root-caused and fixed. real::init() adopts the process-wide singleton ID3D12Device after runner::gpu() already created its un-adopted gpu.queue, so subsequent runner::gpu() tests created adopted command lists via the adopted device and submitted them directly to the un-adopted gpu.queue (bypassing q_execute_command_lists and UnadoptGuard). Added runner::submit_list using real::UnadoptGuard::new; --exact gpu::recomp::tests::gpu_sparse_vram_descriptors_buffers_and_xmem gpu::recomp::tests::gpu_valu_float_and_int now passes 2/2 back-to-back on unmodified -Db_ndebug=true vkd3d-proton.
  • Composing with D3D12.X: under Wine, vkd3d-proton's assert-checked classes keep their vtable #1395 (@cmt8): thanks for the complementary in-place patching PR and the UnadoptGuard::new composition note (in_place_original(vt(obj) as usize, 0).is_some()). Noted D3D12.X: under Wine, vkd3d-proton's assert-checked classes keep their vtable #1395 in the PR description and happy to add that guard once D3D12.X: under Wine, vkd3d-proton's assert-checked classes keep their vtable #1395 lands (or compose cleanly in whichever order merges first).
  • Verified on RX 9060 XT / GE-Proton11-14 / vkd3d-proton ec20719452e916b (-Db_ndebug=true): real:: 29/0, list_x:: 26/0, late_release:: 2/0, alloc_pool:: 3/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, 10 frames shown / 18 PresentX, 0 crashes, 0 removals).

@gustavsi

Copy link
Copy Markdown
Author

Thanks @SzczepanGrela for pinning the exact parallel alloc_pool crash and @DavidM1911 for the Windows verification!

Rebased onto main (06c9f55) at 7a4954c:

  • Wrapped the three raw queue.ExecuteCommandLists calls in alloc_pool::tests::a_recording_outlives_the_reset_of_the_titles_allocator (and the new list_x::tests::reset_while_the_last_submit_runs test) with UnadoptGuard::new, and switched their test fences plus vram::Pages::retire_fence and sparse::State fences to real::create_raw_fence.
  • Verified on RX 9060 XT / GE-Proton11-14: alloc_pool:: --test-threads=4 passes 3/3 (4/0 each), list_x:: 34/0, real:: 58/0, gpu_sparse_vram_descriptors_buffers_and_xmem + gpu_valu_float_and_int 2/0, plus a fresh 60 s smoke run (exit: 0x0, 20 frames, 0 crashes, 0 removals).

@omrih4

omrih4 commented Nov 25, 2026

Copy link
Copy Markdown

can confirm proton-cachyos on main crashes, successfully starts up with this pr rebased on top of it

@pickles976

Copy link
Copy Markdown

#1395 is now closed unmerged (the author explicitly permitted reuse), so this PR is again the active upstream path for Wine/vkd3d object compatibility. One current consequence: exact #877 head aec41e2 + this head 7a4954c still aborts at its first sparse heap on stock assertion-enabled vkd3d-proton 3.2:

Assertion failed: iface->lpVtbl == &d3d12_heap_vtbl, .../vkd3d_private.h, line 1077

Verified on RTX 4060 Laptop / NVIDIA 590.48.1; #877 sparse tests pass 16/0/1, but the retail title exits 3 after 4.13 s. The in-place native-vtable implementation from closed #1395 gets this same machine past that heap when stacked with this PR. Since #1395 will not land independently, folding or succeeding its permitted implementation is now necessary for this PR's heap/resource half to work with release assertions enabled.

Full exact-head report: #877 (comment)

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
Carries forward the permitted in-place vtable patching from closed xcl-dev#1395
(originally by @cmt8) on top of xcl-dev#867, skipping in-place patched tables in
UnadoptGuard::new so ext[-1] is never read on runtime-owned vtables.

Under Wine, vkd3d-proton asserts iface->lpVtbl == &d3d12_*_vtbl on heaps,
resources, descriptor/query heaps, root signatures, pipeline states and
command signatures even in release builds. Patching their PC slots in place
preserves the runtime's vtable pointer and avoids those aborts on stock
Proton Experimental / vkd3d-proton 3.2.

Assisted-by: Antigravity (Gemini 4 Neon)
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

Thanks @omrih4 for confirming startup on proton-cachyos and @pickles976 for testing against stock assertion-enabled vkd3d-proton 3.2!

Rebased onto main (2898511) at c79e3b3:

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
Carries forward the permitted in-place vtable patching from closed xcl-dev#1395
(originally by @cmt8) on top of xcl-dev#867, skipping in-place patched tables in
UnadoptGuard::new so ext[-1] is never read on runtime-owned vtables.

Under Wine, vkd3d-proton asserts iface->lpVtbl == &d3d12_*_vtbl on heaps,
resources, descriptor/query heaps, root signatures, pipeline states and
command signatures even in release builds. Patching their PC slots in place
preserves the runtime's vtable pointer and avoids those aborts on stock
Proton Experimental / vkd3d-proton 3.2.

Assisted-by: Antigravity (Gemini 4 Neon)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
Carries forward the permitted in-place vtable patching from closed xcl-dev#1395
(originally by @cmt8) on top of xcl-dev#867, skipping in-place patched tables in
UnadoptGuard::new so ext[-1] is never read on runtime-owned vtables.

Under Wine, vkd3d-proton asserts iface->lpVtbl == &d3d12_*_vtbl on heaps,
resources, descriptor/query heaps, root signatures, pipeline states and
command signatures even in release builds. Patching their PC slots in place
preserves the runtime's vtable pointer and avoids those aborts on stock
Proton Experimental / vkd3d-proton 3.2.

Assisted-by: Antigravity (Gemini 4 Neon)
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 (e0d93c84) at f98da36d:

  • Fixed the multithreaded UnadoptGuard / orig_fn race reported by @GreemSC on Memory: avoid amdgpu userptr stalls under Wine (#175) #871 (0xc0000005 reading 0x10 in pso_release -> orig_fn(this, 2)): UnadoptGuard is now refcounted per object pointer (UNADOPTED with atomic vtable stores so overlapping guards on shared objects don't restore early), and unadopted native vtables are registered lock-free (register_native / is_known_native) so orig_fn reads *ext.add(slot) directly without touching native[-1]. Extended wine_vtable_tests to cover overlapping guards and orig_fn while guarded with a zero-prefixed native table.
  • Added UnadoptGuard::new around the two new deferred-dispatch PC_RESET sites and raw test submit from D3D12.X: a dispatch waits for its pipeline at the submit, not in the bind #2118.
  • Verified under Proton (real:: 61/0, list_x:: 40/0, alloc_pool:: --test-threads=4 4/0 × 3) and a fresh 60 s pwsh ./scripts/smoke.ps1 run (exit: 0x0, 21 frames, 0 crashes, 0 removals).

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 concurrency hole: UnadoptGuard temporarily publishes a native vtable on a shared adopted object. A new concurrent COM call starting during that window dispatches directly to d3d12core and bypasses XCL hooks; e.g. cl_set_pipeline_state unadopts a PSO while concurrent Release can bypass pso_release async/DRED/lifetime bookkeeping. orig_fn only protects a hook already entered before the swap, not calls loading native table afterward. Add synchronization/proxying or prove a no-concurrent-use invariant, with a guard-vs-new-hook-call regression. Current head also lacks visible Windows CI.

@Mantarochen23

Copy link
Copy Markdown

As a Linux-only user, I would highly appreciate this to be merged. Building and testing on Linux seems to be very doable with this.

@Alm0stSurely

Alm0stSurely commented Nov 26, 2026 •

Copy link
Copy Markdown

Tested on an RTX 5080, NVIDIA 620.73.04, Proton Experimental (vkd3d-proton cae8353ed7959c4). Local builds from nvidia-dev at c044dc6d48d2b46a8ae77852df275c534681f3df, with the heap change from #1395 and the Wine fence adapter from this PR (a4c5a8228688d6642a21aaee80eaed5653905164).

I could reproduce the allocator identity check outside the game. With a fresh DIRECT allocator, node mask 1 and no initial PSO, the native allocator vtable gave S_OK for both PC graphics-list IIDs (base and v6). The title's console v6 IID gave E_NOINTERFACE, which lets XCL retry with the PC IID. Copying the same nine entries to a different address gave E_INVALIDARG for all three IIDs. On a closed native list, Reset also gave E_INVALIDARG with the copied table, then S_OK on the same list after restoring the native table.

In the retail run, the heap + fence baseline stopped at its first CreateCommandListX. Exposing the native allocator during that call let all eight sampled direct/compute list creations return S_OK. With default heap placement, the title then reached the newer layout's slot 139 (Reset) and stopped with E_INVALIDARG.

In a follow-up build, the allocator selected by the pool was also exposed natively around the driver's list Reset. On the same cold, default-placement recipe, the native slot 10 returned S_OK and the title's slot 139 returned S_OK on the primary list. XCL then logged ExecuteCommandListsX with one list, followed by an access violation in the stock D3D12 runtime before the first present. I have not isolated the cause of that subsequent fault.

A further selective port of this PR's submission change passed the native list tables to the stock driver for each chunk after XCL expanded the console lists. All 16 instrumented chunks returned from the CPU call in each of two cold runs, including chunks with two lists. The title reached PresentX and created a 3840×2160 swap chain. The video showed a blank white window before shutdown. A local VRAM guard stopped the runs at 3313 and 3529 MiB free. The second run added only no_upload_hvv. No in-world frames were verified. Seven focused CPU tests passed, including a mixed-list batch with a duplicate. This is a diagnostic port; return from the submission call does not establish GPU completion.

The paired runs used xcl run <retail executable>, empty caches, VKD3D_CONFIG=ignore_shared_fence,single_queue and XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_UMA_SHADOW=1 XCL_LOOK_SKIP=1.

Tested the rebased PR head separately. I built e57cb659b8f99801089846cbf680dc9964e6800c without local changes and ran scripts/smoke.ps1 -Seconds 60 on the RTX 5080 with GE-Proton11-14, cold caches, XCL_PSO_PRELOAD=0, XCL_NETWORK=0 and no VKD3D_CONFIG flags. Proton ran directly in an offline sandbox. The title exited before its first present. vkd3d logged Failed to create Vulkan device, vr -3. Adding only single_queue gave vr -1 at the same step. Proton Experimental with single_queue also gave vr -1. All three XCL runtime reports recorded zero presents. The smoke script's subsequent Get-CimInstance fallback failed under Wine, so there is no official manifest for these runs. A separate D3D12 readback control passed on the same GPU under Proton Experimental. The author used an AMD GPU and did not identify the retail title. These runs stop before they can evaluate the rebased submission change.

Follow-up on the clean rebased head under Proton Experimental. Two direct xcl run launches with the same executable, synthetic save, empty caches and single_queue diverged. With 10,835 MiB of free VRAM at startup, both the launcher preflight and the title host failed to create a D3D12 device. With 14,308 MiB free, both initialized the RTX 5080. The second run then exited at the stock driver's heap identity assertion (iface->lpVtbl == &d3d12_heap_vtbl), with zero presents and a black window. Available VRAM was observed, not controlled. This places the second run at the heap-compatibility issue covered by #1395.

Not tested on AMD or native Windows. The local change covers selected call sites on this base. Concurrent title access to the allocator's extra slot while exposing the native vtable remains unverified. No gameplay FPS measured.

OpenAI Codex (GPT-6.2 Astra) assisted with the probes, runs and this report.

…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)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
Carries forward the permitted in-place vtable patching from closed xcl-dev#1395
(originally by @cmt8) on top of xcl-dev#867, skipping in-place patched tables in
UnadoptGuard::new so ext[-1] is never read on runtime-owned vtables.

Under Wine, vkd3d-proton asserts iface->lpVtbl == &d3d12_*_vtbl on heaps,
resources, descriptor/query heaps, root signatures, pipeline states and
command signatures even in release builds. Patching their PC slots in place
preserves the runtime's vtable pointer and avoids those aborts on stock
Proton Experimental / vkd3d-proton 3.2.

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

Copy link
Copy Markdown
Author

Thanks @bmjask for the review! Addressed the UnadoptGuard concurrent-Release P1 and rebased onto main (08db8020) at e57cb659:

  • COM reference pin across UnadoptGuard: on the first active guard for an object, UnadoptGuard::new calls native AddRef before exposing orig (raising refcount >= 2), and on the last guard drop restores ext (Ordering::Release), releases UNADOPTED, and then calls XCL's hooked Release slot (*ext.add(2)). Even if another thread concurrently loads the native vtable during the guard window and invokes Release, refcount stays >= 1 so the object cannot finalize early, and the guard exit runs XCL's hooked 1 -> 0 cleanup (pso_release, heap_release, res_release, cl_release, alloc_release). (Note: with D3D12.X: patch assert-checked vtables in place under Wine (#175) #2477 stacked on this PR, the 7 shared assert-checked classes are patched in place and bypass UnadoptGuard altogether.)
  • Alignment guard: UnadoptGuard::new now checks (obj as usize) & 7 == 0 before its atomic vtable load so synthetic unaligned pointers cannot panic in debug builds.
  • Regression test: added wine_vtable_tests::concurrent_release_during_unadopt_guard_still_runs_hooked_cleanup spawning a concurrent thread that observes orig_vt and invokes native Release during an active guard, verifying rc == 1 while guarded and hooked pso_release cleanup on 1 -> 0 when the guard drops.
  • Verification (GE-Proton11-14, RX 9060 XT): real:: 62/0, list_x:: 40/0, alloc_pool:: --test-threads=4 4/0 (× 3), gpu_sparse_vram_descriptors_buffers_and_xmem + gpu_valu_float_and_int 2/0, plus a fresh 60 s pwsh ./scripts/smoke.ps1 run (exit: 0x0, 18 frames shown, 0 crashes, 0 removals).

AI use: Antigravity (Gemini 4 Neon) implemented the UnadoptGuard reference pin and regression test, ran the Proton tests and smoke run, and drafted this comment.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
Carries forward the permitted in-place vtable patching from closed xcl-dev#1395
(originally by @cmt8) on top of xcl-dev#867, skipping in-place patched tables in
UnadoptGuard::new so ext[-1] is never read on runtime-owned vtables.

Under Wine, vkd3d-proton asserts iface->lpVtbl == &d3d12_*_vtbl on heaps,
resources, descriptor/query heaps, root signatures, pipeline states and
command signatures even in release builds. Patching their PC slots in place
preserves the runtime's vtable pointer and avoids those aborts on stock
Proton Experimental / vkd3d-proton 3.2.

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

Copy link
Copy Markdown
Author

Thanks @Alm0stSurely for the detailed RTX 5080 / Proton Experimental verification! The iface->lpVtbl == &d3d12_heap_vtbl assertion you hit on stock Proton Experimental is indeed the heap/resource/PSO in-place vtable patching carried forward from #1395 in #2477 (stacked on this PR, now updated at 94a05e53).

AI use: Antigravity (Gemini 4 Neon) drafted this comment.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

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.