Skip to content

D3D12.X: patch assert-checked vtables in place under Wine (#175) - #2477

Open
gustavsi wants to merge 2 commits into
xcl-dev:mainfrom
gustavsi:wine/vkd3d-inplace-vtables
Open

gustavsi wants to merge 2 commits into
xcl-dev:mainfrom
gustavsi:wine/vkd3d-inplace-vtables

Conversation

@gustavsi

@gustavsi gustavsi commented Nov 25, 2026 •

Copy link
Copy Markdown

Patch vkd3d-proton's assert-checked COM vtables in place under Wine so stock assertion-enabled vkd3d-proton builds (such as Proton Experimental) no longer abort on adopted heaps, resources, descriptor/query heaps, root signatures, pipeline states, and command signatures. Part of #175 and #1701.

Stacked on #867; only the top commit (a970ef38) belongs here. Carries forward the permitted implementation from closed #1395 (originally authored by @cmt8), composed cleanly with #867's UnadoptGuard.

Under Wine, vkd3d-proton keeps assert(iface->lpVtbl == &d3d12_*_vtbl) active even in release builds for these seven classes. Because their console slots sit inside the PC interface, patching their PC slots in place (saving the runtime's original function pointers in IN_PLACE for orig_fn) preserves the runtime's own vtable pointer and eliminates those aborts. All new paths are gated behind util::under_wine(); native Windows behavior is unchanged.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs:
    • Add lock-free IN_PLACE / in_place_original / in_place_kind / patch_in_place (from closed D3D12.X: under Wine, vkd3d-proton's assert-checked classes keep their vtable #1395) for Heap, Resource, DescriptorHeap, RootSignature, PipelineState, QueryHeap, and CommandSignature under Wine. IN_PLACE_N is published with Ordering::Release and register() runs before each changed slot is written via an aligned AtomicUsize::store(..., Ordering::Release).
    • Have UnadoptGuard::new skip vtables patched in place (skips_guard: !is_ext_fast(cur) || in_place_original(cur, 0).is_some()) so ext[-1] is never dereferenced on runtime-owned vtables.
    • Unit tests in in_place_tests:
      • a_vtable_patched_in_place_keeps_its_originals_and_its_neighbour
      • concurrent_calls_and_patches_on_readonly_vtable_never_tear_or_miss_orig_fn (4 caller threads continuously invoking slot Implement XSystemGetDeviceType/PLS thunks and Opus audio carrier parsing #1 through a PAGE_READONLY vtable while 2 patcher threads race to call patch_in_place, with a 10 s deadline instead of a fixed iteration cap so callers do not exit before the patch lands under --test-threads=4; verifies exact-once patching, zero torn entries or orig_fn misses, and that skips_guard skips the patched table; the latter is asserted directly because UnadoptGuard::new returns early off Wine, and fails with the in-place check removed).

Tested

  • Hardware / OS: AMD Radeon RX 9060 XT (16 GiB VRAM, RADV Mesa 26.2.7), Linux, DXC 1.9.2609.5, cross-compiled x86_64-pc-windows-msvc (clang-cl + lld-link).
  • Direct reproduction on stock assertion-enabled Proton Experimental (Proton - Experimental vkd3d-proton d3d12core.dll containing iface->lpVtbl == &d3d12_heap_vtbl assertions; also independently reproduced by @ClosetPie107 on RX 9070 / stock Proton Experimental and by @Royalflamejlh on RTX 4070 / assertion-enabled vkd3d-proton):
    • Parent #867 (without this PR): --exact gpu::recomp::tests::gpu_sparse_vram_descriptors_buffers_and_xmem aborts immediately with Assertion failed: iface->lpVtbl == &d3d12_heap_vtbl, file ../src-vkd3d-proton/libs/vkd3d/vkd3d_private.h, line 1077 (exit 3).
    • With this PR stacked on #867: real:: passed with 0 assertions, gpu_sparse_vram_descriptors_buffers_and_xmem + gpu_valu_float_and_int passed 2/0 with 0 assertions, and a 20 s retail title run exited 0 with 337 frames shown and all 7 assert-checked classes patched in place.
  • Restacked onto updated D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) #867 (d9e6ad51, on main 08db8020) at a970ef38 (no conflicts, commit diff unchanged) under GE-Proton11-14:
    • real::in_place_tests real::wine_vtable_tests --test-threads=4 (× 5 runs): 5/5 passed (6 passed, 0 failed, 0 ignored each)
    • hle::d3d12x::real:: --test-threads=1: 65 passed, 0 failed, 0 ignored
    • hle::d3d12x::alloc_pool:: --test-threads=4: 4 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: 45 frames shown (PresentX 45, 3 1 2/2 s), exit: 0x0, 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 (a970ef38, stacked on #867):

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

Not tested

  • Native Windows locally (independently verified by @DavidM1911 on Windows 11 / RTX 3060 Ti; all new paths are gated behind util::under_wine()).
  • NVIDIA Linux GPUs locally (independently verified on RTX 4070 / RTX 3080 / RTX 4060 Laptop with assertion-enabled vkd3d-proton by @Royalflamejlh, @wayback94, and @pickles976).

AI use

@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.

No confirmed code-level defect found, but this is high-risk and not merge-ready. The target validation gap is material: the intended assertion-enabled stock Proton/vkd3d-proton scenario was not reproduced directly; the author run used GE-Proton with assertions disabled. Please reproduce it before merge. Also, the shared runtime vtable is patched while other threads may call it; aligned entry stores are relied upon, but there is no concurrent call/patch stress test despite the process-wide blast radius. Finally, the branch is dirty/non-mergeable and stacked on #867, so it needs a rebase and refreshed CI/test evidence.

@gustavsi
gustavsi force-pushed the wine/vkd3d-inplace-vtables branch from 86a10c6 to 0c249f0 Compare November 25, 2026 20:32
@gustavsi

Copy link
Copy Markdown
Author

Thanks @bmjask for the review! Addressed all three points at 0c249f08 (rebased onto main e0d93c84 + updated #867 f98da36d):

  1. Direct reproduction on stock assertion-enabled Proton Experimental (Proton - Experimental vkd3d-proton d3d12core.dll verified to contain iface->lpVtbl == &d3d12_heap_vtbl):
    • Parent D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) #867 (f98da36d, without this PR): gpu_sparse_vram_descriptors_buffers_and_xmem aborts with Assertion failed: iface->lpVtbl == &d3d12_heap_vtbl, file ../src-vkd3d-proton/libs/vkd3d/vkd3d_private.h, line 1077 (exit 3).
    • This PR (0c249f08): hle::d3d12x::real:: 63/0, gpu_sparse_vram_descriptors_buffers_and_xmem + gpu_valu_float_and_int 2/0, and a 20 s retail title run exited 0 with 337 frames shown (337 PresentX), all 7 assert-checked classes (ID3D12Heap1, ID3D12Resource2, ID3D12DescriptorHeap, ID3D12RootSignature, ID3D12PipelineState, ID3D12QueryHeap, ID3D12CommandSignature) patched in place and 0 assertions.
  2. Concurrent call/patch stress test: added in_place_tests::concurrent_calls_and_patches_on_readonly_vtable_never_tear_or_miss_orig_fn — 4 caller threads continuously invoking slot Implement XSystemGetDeviceType/PLS thunks and Opus audio carrier parsing #1 through a PAGE_READONLY vtable while 2 patcher threads race in patch_in_place (verifies exact-once patching, zero torn entries or orig_fn misses, and UnadoptGuard::new skipping the patched table).
  3. Clean rebase & refreshed smoke: rebased onto e0d93c84 + updated D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) #867, verified with a fresh 60 s pwsh ./scripts/smoke.ps1 run (exit: 0x0, 22 frames, 0 crashes, 0 removals).

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@ClosetPie107

ClosetPie107 commented Nov 25, 2026 •

Copy link
Copy Markdown

Update for head a970ef38 (earlier reports for 9b9012c8 and 0c249f08 below)

git range-diff shows this PR's own commit unchanged from 9b9012c8; only the #867 commit under it moved (now d9e6ad51). Same machine and Proton as below.

Stock assertion-enabled Proton (d3d12core.dll sha256 93565013…)

Patched vkd3d-proton (master ec207194 without the allocator / command-list lpVtbl checks), test commit 272ab8cd:

Not tested

AI use

  • Claude Code (Claude Opus 5.5) wrote the test scripts, ran the tests and runs on this machine and wrote this update.

Update for head 9b9012c8 (earlier report for 0c249f08 below)

Independent test report under Wine/Proton (not native Windows), on stock Proton Experimental vkd3d-proton with assertions enabled (d3d12core.dll sha256 93565013…4b2576, same as before).

Tested

  • AMD Radeon RX 9070 (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, CachyOS Linux 7.3.5

  • Proton Experimental experimental-11.0-20261112, DXVK v3.1.1-209, DXC 1.9.2609.5, Rust 1.96.0, target x86_64-pc-windows-gnu, debug build for tests

  • Head merged onto main 8b957bec (test commit 1b59ec6e): cargo test -p xcl --lib in_place_tests -- --test-threads=1 2 passed, 0 failed. cargo test -p xcl --lib hle::d3d12x::alloc_pool:: -- --test-threads=1 4 passed, 0 failed.

  • Retail title, 60 s, release build, XCL_DIRECT_DXIL=1, XCL_PREPARE=0, XCL_PSO_PRELOAD=0, built from exact commits:

    • Parent e57cb659: aborts after 5 s with Assertion failed: iface->lpVtbl == &d3d12_heap_vtbl, file …/libs/vkd3d/vkd3d_private.h, line 1077, exit 3.
    • Head 9b9012c8: ran the full 60 s, 1,589 presents, exit 0, no assertion or crash.
  • I did not get a boot comparison on current main: main 8b957bec and main+PR 1b59ec6e both stayed in the startup shader-preparation window until the 150 s wall-clock cap (exit 124), so neither reached the title.

Not tested

  • Native Windows, NVIDIA/Intel, the full workspace suite on this head, the retail run on main+PR

AI use

  • Codex in T3 Code (gpt-6.2-sol) wrote the test scripts and ran the tests on this machine. Claude Code (Claude Opus 5.5) wrote this report from the logs.

Independent AMD RDNA4 / Linux (RADV, native wave64) test report for head 0c249f08137161fc48e018cfffc179c65339f304 (merged cleanly onto main 6d12f58) on stock, unmodified, assertion-enabled Proton Experimental vkd3d-proton.

Hardware & environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1, native wave64), Ryzen 5 9600X, 30 GiB RAM, CachyOS Linux
  • Proton Experimental (experimental-11.0-20261112), stock assertion-enabled d3d12core.dll (sha256: 9356501320114773be279506644aabd9a1717ff451d480ac802a4fd4e94b2576, verified iface->lpVtbl == &d3d12_heap_vtbl assertions present), DXVK v3.1.1-209, DXC 1.9.2609.5, Rust x86_64-pc-windows-gnu (debug for tests, release for retail)

Unit / GPU tests (XCL_REQUIRE_GPU=wave64, XCL_DXC_DIR, VKD3D_CONFIG=ignore_shared_fence)

  • hle::d3d12x::real:: --test-threads=1 --nocapture: 63 passed, 0 failed, 0 ignored (0 skipped, 0 assertions; includes both in_place_tests)
  • hle::d3d12x::alloc_pool:: --test-threads=4 --nocapture: 4 passed, 0 failed, 0 ignored (0 skipped, 0 assertions)
  • --exact gpu::recomp::tests::gpu_sparse_vram_descriptors_buffers_and_xmem gpu::recomp::tests::gpu_valu_float_and_int --test-threads=1 --nocapture: 2 passed, 0 failed, 0 ignored (0 skipped, 0 assertions)
  • Full hle::d3d12x (--test-threads=4 and --test-threads=1): 0 assertions and 0 aborts — all 7 assert-checked classes (ID3D12Heap1, ID3D12Resource2, ID3D12DescriptorHeap, ID3D12RootSignature, ID3D12PipelineState, ID3D12QueryHeap, ID3D12CommandSignature) patched in place cleanly. (12–13 subsequent GPU tests in the full module run failed after an unrelated radv/amdgpu: The CS has been rejected poisoned the singleton device on stock Proton's vkd3d-proton.)

Retail title (60 s, stock assertion-enabled Proton Experimental d3d12core.dll)

  • Flags: XCL_DIRECT_DXIL=1, XCL_TEXTURE_LEVEL_PAGES=1, XCL_PSO_WAIT_MS=50, XCL_SPLIT_MIDLIST_WAIT=0, XCL_COHERENT_MB=1024, VKD3D_CONFIG=ignore_shared_fence, XCL_PSO_PRELOAD=0, XCL_NETWORK=0
  • Completed the full 60 s (exit=0) with 0 assertions, 0 crashes, and 0 device removals:
    • 1,200+ frames presented at 30.0 fps, 11,962 translated draws, 2,048 dispatches, 1,031 Opus packets (0 errors), 10.25 GiB peak VRAM, 8.1 GiB peak RSS.
    • All 7 assert-checked vkd3d-proton classes logged written into the runtime's own vtable.

Not tested

  • Full workspace test suite, native Windows, NVIDIA/Intel GPUs, or longer world-load runs on stock Proton's vkd3d-proton.

AI use

  • T3 Code / Antigravity (Gemini 4 Neon) merged the PR onto main, swapped in stock Proton Experimental d3d12core.dll, ran the tests and 60 s retail run on this machine, and drafted this report.

@gustavsi

Copy link
Copy Markdown
Author

Thanks @ClosetPie107 for the independent AMD RDNA4 verification on stock assertion-enabled Proton Experimental (60 s at 30.0 fps, 0 assertions, 0 crashes) and @DavidM1911 for verifying on Windows 11!

Rebased onto main (08db8020) + updated #867 (e57cb659, picking up the UnadoptGuard COM reference pin and alignment guard) at 96b91da5:

  • Verified under GE-Proton11-14 (RX 9060 XT): real:: 64/0, alloc_pool:: --test-threads=4 4/0, 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, 11 frames shown, 0 crashes, 0 removals; block updated in PR description).

AI use: Antigravity (Gemini 4 Neon) rebased onto main + updated #867, ran the Proton tests and smoke run, and 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

@Royalflamejlh Royalflamejlh 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.

The new test concurrent_calls_and_patches_on_readonly_vtable_never_tear_or_miss_orig_fn failed on 0c249f0 under Wine in 3 of 21 runs of real::in_place_tests real::wine_vtable_tests (4 tests) at --test-threads=4, the count scripts/test.ps1 uses, at real.rs:8070 ("callers must observe the patched hook"); alone and at one thread it passed 10 of 10 each. The test is unchanged at the rebased head 96b91da (the loop and the assert are now at :8058 and :8097); we have not rerun it there. The change itself works on Linux + NVIDIA: on a vkd3d-proton built with assertions on and without XCL's relaxed-vtable patch, #867 alone aborts before the first frame and #2477 on top runs.

The callers stop after 20,000 calls each (:8058 at 96b91da), so if the patch lands after they finish, hook_hits stays 0 (a reading of the test). With the loop bounded by time instead, the same 4 tests passed 25 of 25 runs at --test-threads=4 here, each in 0.02–0.04 s: the callers still stop once the hook has been seen, so the 10 s only bounds a failing run:

// real.rs:8058 at 96b91da, in place of `for _ in 0..20_000 {`
let until = std::time::Instant::now() + std::time::Duration::from_secs(10);
while std::time::Instant::now() < until {

Setup: main e0d93c84 (the commit this head is rebased on) + #684 e56dbc3, then + #867 f98da36, then + #2477 0c249f0. RTX 4070 12 GB (615.71.09), Fedora 44, Wine 11.21 Staging, release, Series X profile, 100 s, XCL_PSO_PRELOAD=0. vkd3d-proton v3.1-90-g30b0eb9b without the relaxed-vtable patch, assertions on (d3d12core.dll 5b59f1b8…) and off.

tree assertions runs result
base + #684 on 1 Assertion failed: iface->lpVtbl == &d3d12_heap_vtbl (vkd3d_private.h:1078), 0 frames
+ #867 on 1 the same, 0 frames
+ #867 + #2477 on 2 ran, presented until about 76 and 70 s
+ #867 + #2477 off 1 ran, presented until about 88 s
  • The heads before the rebase (86a10c6, c79e3b3) gave the same pattern on the assertion build: the base and #867 aborted in 2 of 2 runs each, and #2477 ran in 3 of 3.

Not tested: Proton's own build; the suite; Windows.

AI use: Claude Code (Claude Opus 5.5) ran the title and the tests, tried the fix and wrote this comment.

@gustavsi
gustavsi force-pushed the wine/vkd3d-inplace-vtables branch from 96b91da to 94a05e5 Compare November 26, 2026 02:16
@gustavsi

Copy link
Copy Markdown
Author

Thanks @Royalflamejlh for the assertion-enabled vkd3d-proton RTX 4070 verification and for tracking down the --test-threads=4 flake, and @DavidM1911 for the Windows 11 re-verification!

Applied the suggested 10 s deadline loop in concurrent_calls_and_patches_on_readonly_vtable_never_tear_or_miss_orig_fn at 94a05e53:

  • real::in_place_tests real::wine_vtable_tests --test-threads=4 (× 25 runs under GE-Proton11-14, RX 9060 XT): 25/25 passed (5 passed, 0 failed, 0 ignored each, ~0.10 s/run).
  • hle::d3d12x::real:: --test-threads=1: 64 passed, 0 failed, 0 ignored.
  • Fresh 60 s pwsh ./scripts/smoke.ps1 run: exit: 0x0, 13 frames shown (1 1 1/2 s), 0 crashes, 0 device removals (block updated in PR description).

AI use: Antigravity (Gemini 4 Neon) applied the time-bounded loop fix, ran the 25× stress test and smoke run, and drafted this comment.

@Alm0stSurely

Alm0stSurely commented Nov 26, 2026 •

Copy link
Copy Markdown

Tested on an RTX 5080 16 GB, NVIDIA 620.73.04, Linux, stock Proton Experimental (vkd3d-proton cae8353, assertions enabled). One direct title run per revision, fresh prefixes and cold caches, same synthetic profile. Built with cargo build --locked --offline --release --target x86_64-pc-windows-gnu -p xcl --bin xcl. Ran xcl.exe run <title-directory> with VKD3D_CONFIG=single_queue, XCL_PSO_PRELOAD=0, XCL_ACTIVITY=1, XCL_NETWORK=0, a 60 s time limit and the same host memory guards.

The parent started with 14,308 MiB free VRAM; this run started with 10,883 MiB. The local guard ended the latter at 5,045 MiB free (cutoff 5,120), about 14 s after preflight. This verifies the heap fix on this Proton build. World rendering, stability beyond that point and gameplay FPS remain unmeasured.

Follow-up on nvidia-dev (af2cecc4), same RTX 5080 and stock Proton. The unmodified branch exits 3 on the heap identity assertion in gpu_placed_console_depth_target_with_clear_value. With the Wine heap/resource changes ported locally onto that head, the same GPU test passes in 0.79 s, with no skip (dedicated allocation fallback for the depth target). With XCL_PREPARE=0 for a direct cold title run, the next stop is the shared-fence identity assertion before PresentX. This local port covers the object classes changed here and does not carry the fence changes from #867.

AI use: OpenAI Codex (gpt-6.2-astra) ran the comparison, checked the logs and capture, and wrote this report.

RTX 5080 / Proton Experimental follow-up on the same NVIDIA base, af2cecc. With the heap-only port of #2477, full preparation processed 26,503/26,503 entries in 27,081.6 s and created 2,671 GPU pipelines, zero refused. The title then exited 3 at the shared-fence vtable check in vkd3d_private.h:757 before its first present. The on-demand run had reached the same assertion.

A separate GPU test on that base creates a shared fence through the title device and calls queue Signal(1), Wait(1), Signal(2). The heap-only build hit the same assertion. Adding the Wine fence adapter from #867 made the same test reach completed value 2 in a 0.66 s test run. Both GPU probes used the same driver, single_queue and VK_NV_optical_flow disabled. The candidate is a local port, not a test of the latest #2477 head.

AI use: OpenAI Codex (gpt-6.2-astra) adapted the existing fence changes, prepared and ran the probes, and wrote this follow-up.

@safesearch77

Copy link
Copy Markdown

Reviewed 94a05e53 against main (b49be183) with #867 (e57cb659) as its first commit. The
order in patch_in_place (publish the IN_PLACE entry and register() before the first store,
then one atomic store per entry) is right, and orig_fn reads the saved entries lock-free
against that. One test gap:

The last assertion of concurrent_calls_and_patches_on_readonly_vtable_never_tear_or_miss_orig_fn
cannot fail in the CI job.
assert!(UnadoptGuard::new(obj_addr as *mut c_void).is_none(), "UnadoptGuard must skip in-place patched vtables") is meant to cover the new
|| in_place_original(cur, 0).is_some() check in UnadoptGuard::new. But new starts with
if !crate::util::under_wine() || ... { return None; }, and under_wine() is a
wine_get_version lookup in ntdll (util.rs:126), false on the Windows runner. So on CI
new returns None on its first line and the assertion passes whether or not the skip exists;
it only means something when someone runs the test under Wine. The #867 test avoids this by
calling the #[cfg(test)] enter, which has no skip.

Moving the condition into a small helper (fn skips_guard(cur: usize) -> bool { !is_ext_fast(cur) || in_place_original(cur, 0).is_some() }, used by new) and asserting on that in the test would
make the skip checked on Windows too.

Read only (git apply --check, source); no GPU, Wine or Windows run.

AI use: Antigravity (Claude Sonnet 5.5) read the diff and the call sites; I re-checked the point
against the source before posting.

@gustavsi
gustavsi force-pushed the wine/vkd3d-inplace-vtables branch from 94a05e5 to 9b9012c Compare November 26, 2026 15:14
@gustavsi

Copy link
Copy Markdown
Author

Thanks @safesearch77, good catch: off Wine, UnadoptGuard::new returns on its first line, so that assertion could not fail on the CI runner.

Updated at 9b9012c8 (still one commit on #867 e57cb659):

  • The skip condition is now skips_guard(cur) (!is_ext_fast(cur) || in_place_original(cur, 0).is_some()), used by UnadoptGuard::new.
  • concurrent_calls_and_patches_on_readonly_vtable_never_tear_or_miss_orig_fn asserts skips_guard(table_addr) directly, which does not depend on under_wine(). The test registers the table as extended before patching, so only the in-place check can make it true: with that check removed from skips_guard, the test fails at the new assertion (UnadoptGuard must skip in-place patched vtables), and passes with it.
  • Under GE-Proton11-14 (RX 9060 XT): real::in_place_tests real::wine_vtable_tests --test-threads=4 25/25 runs passed, hle::d3d12x::real:: 64 passed / 0 failed, alloc_pool:: --test-threads=4 4/0, --exact gpu_sparse_vram_descriptors_buffers_and_xmem gpu_valu_float_and_int 2/0. New smoke block in the description.

@Royalflamejlh, your time-bounded loop is in since 94a05e53; could you take another look when you have time?

AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and the smoke run, and drafted this reply; I checked it.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Under Wine 11.21 Staging, at head 9b9012c8 (with #867 e57cb659 as its first commit) merged on main 8b957bec, real::in_place_tests real::wine_vtable_tests passed in 21 of 21 runs at --test-threads=4, concurrent_calls_and_patches_on_readonly_vtable_never_tear_or_miss_orig_fn included.

The callers' loop is now bounded by 10 s instead of 20,000 calls (real.rs:8064 at 9b9012c8), the change we asked for. Each run took 0.02–0.04 s, so none came near the deadline. It had failed in 3 of 21 runs of the same filter (then 4 tests) on 0c249f0, so we withdraw our request for changes.

Setup: release, cargo test --release -p xcl --lib --target x86_64-pc-windows-gnu -- real::in_place_tests real::wine_vtable_tests --test-threads=4, Fedora 44, Wine 11.21 Staging; 5 tests in each run. By reading, none of the five creates a D3D12 device, so the card and vkd3d-proton play no part.

Not tested: the title at this head; the whole test suite; Windows.

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

Posted without review by a person: the account owner was away and reads replies later.

@Royalflamejlh Royalflamejlh 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.

At 9b9012c8 the callers' loop is bounded by 10 s, the change we asked for, and the five real::in_place_tests real::wine_vtable_tests tests passed in 21 of 21 runs under Wine at --test-threads=4 (details: #2477 (comment)). This replaces our request for changes.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this review.

…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)
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
gustavsi force-pushed the wine/vkd3d-inplace-vtables branch from 9b9012c to a970ef3 Compare November 26, 2026 20:15
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
…add XCL_PREPARE=0 opt-out

Bring fork main in sync with the latest upstream PR review fixes:
- xcl-dev#867: UnadoptGuard COM +1 refcount pin, under_wine() gate on
  create_raw_fence, and track_end_title_fence for list_x cell fences.
- xcl-dev#2477: skips_guard helper and 10 s deadline loop in concurrent
  in-place vtable test.
- xcl-dev#1732: RbStatus + retained FIFO deferred retry and per-64-byte-segment
  RbSnapshot/last_rb CPU-write protection for async/deferred readbacks.
- present/preparation: allow XCL_PREPARE=0 (matching upstream nvidia-dev)
  to skip startup shader preparation during smoke runs and quick iterations.

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

Copy link
Copy Markdown
Contributor

Independent native Windows 11 desktop NVIDIA regression verification of PR #2477 at head a970ef38a57d72a642e5f7994b35fea968c17a15 (2 commits d9e6ad51 -> a970ef38 on merge-base 08db8020d323bf478964fcc586152cce54959cfc, pre-#2555 ancestor of main; parent d9e6ad51baaad5421a794ca39c0560d1edd28421).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (native Windows, non-Wine, Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (a970ef38)

Command Result
cargo test --release -p xcl --lib a_vtable_patched_in_place_keeps_its_originals_and_its_neighbour -- --nocapture 1 passed; 0 failed; 0 ignored; 1336 filtered out (0.00s)
cargo test --release -p xcl --lib concurrent_calls_and_patches_on_readonly_vtable_never_tear_or_miss_orig_fn -- --nocapture 1 passed; 0 failed; 0 ignored; 1336 filtered out (0.00s)
cargo test --release -p xcl --lib unadopt_guard_restores_native_vtable_and_reapplies_extended_on_drop -- --nocapture 1 passed; 0 failed; 0 ignored; 1336 filtered out (0.00s)
cargo test --release -p xcl --lib concurrent_release_during_unadopt_guard_still_runs_hooked_cleanup -- --nocapture 1 passed; 0 failed; 0 ignored; 1336 filtered out (0.00s)
cargo test --release -p xcl --lib fence_proxy_forwards_signal_unwraps_and_frees_on_final_release -- --nocapture 1 passed; 0 failed; 0 ignored; 1336 filtered out (0.02s)
cargo test --release -p xcl --lib track_end_title_fence_registers_once_and_addrefs -- --nocapture 1 passed; 0 failed; 0 ignored; 1336 filtered out (0.00s)
cargo test --release -p xcl --lib hle::d3d12x::real:: -- --test-threads=4 (3 consecutive runs) 65 passed; 0 failed; 0 ignored; 1272 filtered out × 3 (0.66s, 0.67s, 0.70s)
cargo test --release -p xcl --lib hle::d3d12x::list_x:: 40 passed; 0 failed; 0 ignored; 1297 filtered out (0.68s)
cargo test --release -p xcl --lib hle::d3d12x::sparse:: 17 passed; 0 failed; 1 ignored; 1319 filtered out (0.30s; early_commit_timing is #[ignore])
cargo build --release -p xcl --bin xcl Clean build (1m 10s, exit 0)

Paired quiet 60 s retail smoke (title: 29640639)

Merge-base (08db8020d323bf478964fcc586152cce54959cfc, cached baseline on the same machine):

xcl-smoke v1
commit: 08db8020d323bf478964fcc586152cce54959cfc
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1588 (PresentX 1588)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14000 MB

PR #2477 (a970ef38a57d72a642e5f7994b35fea968c17a15):

xcl-smoke v1
commit: a970ef38a57d72a642e5f7994b35fea968c17a15
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1594 (PresentX 1594)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14011 MB

Runtime log observations (xcl.log)

  • 9222 log lines, 0 [ERROR] / device-removal / panic lines.
  • Standard native Windows vtable adoption active (ID3D12Device14, ID3D12Heap1, ID3D12CommandQueue, ID3D12Fence1).
  • Final draw/memory telemetry in log: 19483 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample 14011 MB committed by the process; video memory 6116 MB local, 4683 MB non-local.

Limits of coverage

  • This is a native Windows 11 (non-Wine) regression check on RTX 4060; Linux / Wine + vkd3d-proton runtime execution was NOT tested here.
  • In-place vtable patching, UnadoptGuard, and fence-proxy mechanics were verified via the 6 new unit tests (in_place_tests and wine_vtable_tests), while 3× parallel hle::d3d12x::real:: -- --test-threads=4, list_x::, sparse:: (early_commit_timing remained #[ignore]), and the paired 60 s retail smoke confirm zero regression on native Windows D3D12.

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

@pickles976

Copy link
Copy Markdown

Offscreen Wine/NVIDIA verification of #2477 a970ef38a57d72a642e5f7994b35fea968c17a15, directly on #867 d9e6ad51baaad5421a794ca39c0560d1edd28421: 12 selected fixtures passed (6 concurrency/proxy, 4 allocator, 2 GPU sequence). Production unchanged; local test-only strengthening in real.rs requires every concurrent caller to observe the patched hook and verifies the vtable page returns to PAGE_READONLY.

Crucially, the hardware legs used stock assertion-enabled vkd3d-proton 2576c0b4adfae4a, not our installed relaxed diagnostic DLLs. We copied only the test executable and stock D3D12 DLLs into a disposable application directory; WINEDEBUG=-all,+loaddll proves both native DLLs loaded from that directory. The shared prefix's installed diagnostic pair was mounted read-only and its before/after hashes stayed unchanged.

Stock SHA-256:

d3d12.dll     fc2bbef02509fb11c334cc96dd211f64def94bb7b4eb82082a4808e6e0549543
d3d12core.dll 9356501320114773be279506644aabd9a1717ff451d480ac802a4fd4e94b2576

Test executable SHA-256: dce8970b6a14edb5beec9df8639966229e3f1113dc728aea0cb95370559d2b0b. Fresh intended-worktree Compiling xcl line recorded; release test build took 146 s.

Machine/config: Linux 6.17, Wine 11.0, Intel i7-13620H, 16 GiB RAM, physical RTX 4060 Laptop 8 GiB / NVIDIA 590.48.01, Rust 1.98.1 / Windows MSVC target. DXVK_CONFIG='dxgi.hideNvidiaGpu = False', XCL_ADAPTER=nvidia; isolated offline fixtures, unchanged 9 GiB/512 MiB scope and global 2048 MiB available-RAM / 6000 MiB GPU / 10 GiB disk guards. No guard stop. Hardware legs sampled at most 413 MiB global GPU use and at least 11129 MiB available RAM; these short samples are not title-memory measurements.

Results / reproducible selection

# Build only, using local SDK wrapper:
cargo test --locked --offline --release --target x86_64-pc-windows-msvc -p xcl --lib --no-run

# Run the built executable beside stock DLLs with native d3d12,d3d12core overrides:
xcl-tests.exe real::in_place_tests real::wine_vtable_tests --test-threads=4 --nocapture
# 6 passed / 0 failed / 0 ignored; 0.04 s

xcl-tests.exe hle::d3d12x::alloc_pool:: --test-threads=4 --nocapture
# 4 passed / 0 failed / 0 ignored; 1.41 s

xcl-tests.exe gpu::recomp::tests::gpu_sparse_vram_descriptors_buffers_and_xmem gpu::recomp::tests::gpu_valu_float_and_int --exact --test-threads=1 --nocapture
# 2 passed / 0 failed / 0 ignored; 1.62 s

Hardware groups used XCL_REQUIRE_GPU=wave64, and the wrapper rejects any SKIPPED output. The GPU pair ran in that order in one process, so it exercises the adopted singleton followed by the next runner submission. Logs show the real NVIDIA backend, sparse XMem/descriptor execution, and in-place Heap/RootSignature/PipelineState/DescriptorHeap/Resource vtables. No stock-vkd3d assertion fired in these tests.

The six CPU fixtures cover original-method/neighbor preservation, two patchers racing four callers, skip-guard behavior, concurrent final-release cleanup, fence proxy forwarding/unwrapping, and end-title fence registration. They use fake vtables, not GPU stress. The allocator group contains two bookkeeping fixtures and two hardware paths; it is not four shader tests.

Evidence caveats: the CPU test binary returned 6/6, but my first postprocessor returned exit 1 because it compared single-backslash paths with Wine's escaped \\ loader log. The recorded log actually shows the correct app-local native d3d12.dll; corrected path matching was checked against that existing log, without rerunning the tests. Both hardware groups then passed the corrected loader/hash validation. The GPU log also has a non-fatal Failed to open stream archive write file exclusively cache message; this is not cache-persistence certification or an error-free retail run.

Local evidence:

  • .compat-runtime/logs/verify-xcl2477-build-20261126T235345Z/
  • .compat-runtime/logs/verify-xcl2477-stock-cpu-20261126T235624Z/
  • .compat-runtime/logs/verify-xcl2477-stock-alloc-20261126T235755Z/
  • .compat-runtime/logs/verify-xcl2477-stock-gpu-20261126T235821Z/
  • .compat-xcl/stock-pr2477/run-{cpu,alloc,gpu}-* contains DLL/executable provenance and loader traces; runner source archived with the verification logs.

Not tested: a matched parent-only run, full suite, all interleavings, other drivers/adapters, title loading/RAM/FPS, or our separate Game-Init stalled-fence watchdog. This supports the selected stock-vkd3d compatibility and concurrency paths; it does not certify the whole nvidia-dev merge or justify repeating an unchanged crashing title launch. Suggested owner follow-through: retain the per-caller completion/page-protection assertions and run the same adopted-device→subsequent-submit sequence in full-suite/native-Windows coverage.

AI-assisted verification/report: omp, OpenAI GPT-6 Astra; all pass counts above come from executed commands.

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.

9 participants