Skip to content

D3D12.X: keep vkd3d-proton's vtables under Wine and wrap the title's fences (#175) - #3492

Open
Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:fix/wine-native-vtables
Open

Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:fix/wine-native-vtables

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Edited 2026-12-02: head d9afcbf1 after bmjask's reviews (see Tested).

Under Wine, vkd3d-proton takes an object only with its own vtable, and XCL replaces the vtable of every object it adopts. This carries #867 and #2477 by gustavsi (both closed unmerged on 2026-11-29: "anyone is welcome to rebase and reuse these commits") onto the current main, as one commit with gustavsi as co-author. Part of #175 and #3067.

#3099 does the fence and guard part against amd-dev; this one is against main and also has #2477's in-place tables.

What is in it

  • real.rs: under Wine, heaps, resources, descriptor and query heaps, root signatures, pipeline states and command signatures keep the runtime's table, with XCL's PC slots written into it (D3D12.X: patch assert-checked vtables in place under Wine (#175) #2477). UnadoptGuard gives a list, allocator, heap or pipeline its native table back for the host call that takes it as an argument, and the title's fences are proxies unwrapped at the queue's Signal and Wait (D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) #867).
  • real.rs, list_x.rs, sparse.rs, alloc_pool.rs, vram.rs, present.rs, title_textures.rs, late_release.rs, cpu_writes.rs, bind.rs: the submit, reset and fence sites main has gained since those PRs (native_queue_execute, the sparse queues, the two-pass feedback poll, the own-work submit, the retire and upload fences) get the same guard or create_raw_fence.
  • One test new on main (gpu_clear_uav_of_a_stencil_uav_clears_the_twin) signalled a device fence on a PC queue; it takes a raw fence.
  • It is one PR of about 890 lines because the two halves cannot be tested apart on an unpatched vkd3d-proton: without the in-place tables the first heap ends the process in an assertion.

Tested

  • Linux: Fedora 44, Wine 11.21 Staging, stock vkd3d-proton master 71cae091 (assertions on), RTX 4060 Ti 16 GB (driver 615.71.09), rustc 1.98.0, release build for x86_64-pc-windows-gnu. Base 9335bc0d, head 3bd9a664.
  • Head d9afcbf1 (2026-12-02), after bmjask's three reviews and Foniass's, rebased onto main 078358a0: both ExecuteBundle entries (the PC one and the console slot 27 in list_x) give the bundle its native table (vkd3d-proton dropped an adopted bundle); create_raw_fence puts its fences in FENCES, as main's CreateFence does, so end_title signals them (the separate call for the list_x cell fences is gone); the fence proxy's table is as long as an adopted fence's; the two-pass feedback submit is guarded on a queue XCL did not adopt too, and its fence is a raw one. cargo test --lib --release -- fence vtable wine unadopt two_pass bundle under Wine on the CPU only (lavapipe, no card): 100 passed, 0 failed. Three new tests, each failing without its change (none for the feedback guard, which needs a device).
  • RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, debug, head d9afcbf1: cargo test --workspace -- --test-threads=4, 3,018 passed, 0 failed, 52 ignored, 1 run; 30 SKIPPED lines (wave64 tests: no wave64 on this card; no D3D12 debug layer; no GPU_UPLOAD heaps; heap windows off; the driver cache cannot be turned off without Developer Mode; a_raw_fence_made_under_wine_is_signalled_at_the_title_end: not under Wine).
  • Head 0797336e (2026-12-01): under Wine the device's CreateSharedHandle and SetEventOnMultipleFenceCompletion hand vkd3d-proton its own fence too (one new test, with stand-in objects; not on a device or in a title). cargo test --lib -- fence vtable wine unadopt, RTX 4060 Ti: 57 passed, 0 failed in 5 of 6 runs; in the first, bind::tests::wait_oldest_fenced_reclaims_in_flight_buffer_before_refusing failed once while a title was running on the same card (it passes alone, 3 of 3).
  • Head 76427620 (2026-12-01), after a second review: UnadoptGuard::new and the tests now run the same body, so the Windows CI runs the shipped guard (the Wine-only guard test became a case of one that runs everywhere); the list of native tables warns once past its 64 entries, where it dropped a table silently. cargo test --lib -- fence vtable wine unadopt, RTX 4060 Ti: 56 passed, 0 failed. 997 added lines.
  • Head 313f55e8 (2026-12-01), after a review: the fence proxy's GetCompletedValue, SetEventOnCompletion and Signal are now main's hooks, run on vkd3d-proton's own fence (they went straight to vkd3d-proton before, so a title's fence skipped the readback settling main gained on 2026-11-25); fences XCL makes inside its own work are not wrapped; the queue's Signal / Wait overrides are under under_wine() again, so Windows takes main's path; three new tests. cargo test --lib -- fence vtable wine unadopt: 57 passed, 0 failed. --lib hle::d3d12x::real::: 178 passed, 3 failed (an_older_process_cannot_remove_a_replacement_blob, a_copy_of_a_destroyed_resources_view_is_the_null_view, dev_create_root_signature_strips_xbox_flags_and_keeps_parameters; all three fail the same way on the head before it). 1,042 added lines now. In a title, the change of this head on another tree that carries this pull request beside other unmerged ones (1 run each, 600 s asked, RTX 4060 Ti, XCL_GPU_PROFILE=1): with it 630 s, 1,880 frames, no crash, no device removal; without it 673 s, 1,520 frames, no crash. Not run in a title on this branch alone: the title numbers below are from the heads they name.
  • Rebased on 2026-12-01 onto main 7d86c5d2 (head ebc21f2e): main's CreateFence now drops console-only flag bits; the Wine path here passes the same cleaned flags. cargo test --lib -- fence vtable wine: 54 passed, 0 failed. The numbers below are from the heads they name.
  • Head 0f347f68 (2026-11-30): the cause of the rare trap with 4 test threads. Under vkd3d-proton every test gets the same device object, and some tests adopt it. A test that then makes a fence or a list from it gets XCL's proxy or an adopted list, and its own PC queue cannot take either. bind::tests::closed_list_replay_keeps_two_pass_buffer_across_fence_and_idle_trim beside create_list_reset_and_clear_state_track_initial_pso_on_d3d12 ended that way 10 of 12 times; with a raw fence and the guard at its two submits, 0 of 20, and hle::d3d12x::bind::tests at 4 threads ran through 10 of 10 (4 of 16 ended early before).
  • Head c817f425 (2026-11-30): bind::tests::execute_indirect_reads_the_arguments_written_before_it, a test new on main that adopts its list and submits it on a PC queue, takes the guard at that submit. It ended in the read at 0x2b28 on 19e8fd50 (found on an RX 9070 by ClosetPie107, below; the same here) and passes now.
  • Rebased on 2026-11-30 onto main f97120dc (head 19e8fd50): main's rewritten late-release seal and its InListReset in cl_reset conflicted; both keep the raw fence and the guards. On the new head the release build and these modules were rerun, with the same results as before: late_release 8 passed, real::wine_vtable_tests 4, real::in_place_tests 2, real::depth_uav_twin_tests 3, title_textures 65, sparse::tests 140, list_x::tests 101 passed and 3 failed (the three that fail on the base). The counts and title runs below are on 3bd9a664.
  • The hle::d3d12x unit tests, each test module in a process of its own with --test-threads=4 (96 modules, 1 pass of each tree; a whole-suite run ends early in a page fault on both trees):
base 9335bc0d this PR 3bd9a664
passed 1,013 1,172
failed 78 17
modules that ended in a page fault 2 (list_x::tests, tests) 1 (tests)

The base's list_x::tests ends after 5 tests in vkd3d-proton's list check (a read at 0x2b28); with this PR it runs through. hle::d3d12x::tests ends the same way on both, a null read after a D3D12SerializeRootSignature call with an invalid version. Of this PR's 17 failures, 15 fail on the base too; the other two are in list_x::tests, which the base does not get to in this pass, and both failed on the base in an earlier whole-suite run.

  • A retail title, same machine and vkd3d-proton, 1 run each (the base's launch pass translated from empty, this head's from the base's caches): on the base it ends at boot with 0 frames, a breakpoint at game+0x2478b7b with E_INVALIDARG in rax (the failure Wine: raw internal fences + native-vtable guards at host-runtime calls (rebased on amd-dev) #3099 describes); on this head it presented until the run's 300 s limit ended it (1,430 frames by then, lit, the last ones the loading pictures), with no crash and no device removal.
  • The same changes have been in our Linux branch (Linux (Wine + vkd3d-proton): status and tracking #3067), where a retail title reaches its world on this vkd3d-proton.
  • AMD under Wine, by ClosetPie107 (two reports below; RX 9070, RADV 26.3.1, stock vkd3d-proton master 71cae091, debug build): the lib suite at 2 threads without gpu:: and six tests that end the process or run out of memory there, 1,715 passed and 16 failed at 0f347f68 against 1,609 and 116 on the base f97120dc; no test fails with this PR that passes on the base.

Regression run
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by scripts/smoke.ps1, the same retail title for 60 s each.

main:

xcl-smoke v1
commit: 395405e4c0ed814afde0610a724dc96a3af329de
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1522 (PresentX 1522)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 16017 MB

this PR's head:

xcl-smoke v1
commit: d9afcbf1cdd02cfd3b48c8d9a4e55b5b65fd0745
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1516 (PresentX 1516)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15447 MB

Not tested

  • Windows: the smoke pair only (below, if pasted) and one whole-suite run. Each branch is behind under_wine().
  • AMD on Windows; on RADV the gpu:: tests and a title run.
  • The title past its loading pictures on this head: the run was 300 s. Under Wine the title's own window is not hidden without user: hide title console window when DWM cloaking is unavailable (#175) #794, which this PR does not include.
  • Other tests that make a fence or a list from the shared device and submit on a PC queue of their own can still meet the same thing at 4 threads when a device-adopting test runs beside them (one run of hle::d3d12x::sparse::tests in 20 did on the first head). It is between tests: the title's device is always adopted, and its queues with it.

AI use

  • Claude Code with Claude Fable 5.2: carried the two commits onto main, ran the tests above and wrote this description. The merge resolutions it starts from were made on our Linux branch with Claude Opus 5.5. Claude Opus 5.5 made the changes after bmjask's reviews of 2026-12-02 and their tests.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 30, 2026
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 30, 2026
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh marked this pull request as ready for review November 30, 2026 03:31
@github-actions github-actions Bot added the needs-rebase Has merge conflicts with its base branch label Nov 30, 2026
@Royalflamejlh
Royalflamejlh force-pushed the fix/wine-native-vtables branch from 3bd9a66 to 19e8fd5 Compare November 30, 2026 03:46
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-rebase Has merge conflicts with its base branch labels Nov 30, 2026
@ClosetPie107

Copy link
Copy Markdown

Test report for #3492 at 19e8fd50, against its base main f97120dc, under Wine. It wasn't run on Windows.

Tested

  • RX 9070 16 GB (RDNA4), Mesa 26.3.1 RADV, Ryzen 5 9600X, CachyOS. Proton Experimental experimental-11.0-20261112, stock vkd3d-proton master 71cae091. Debug build, x86_64-pc-windows-gnu.
  • Command: cargo test --locked -p xcl --lib --target x86_64-pc-windows-gnu -- <filter>, always with --skip gpu:: --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole (the last two run out of memory here).
f97120dc #3492 19e8fd50
hle::d3d12x:: at 2 threads 913 passed, 98 failed, then exit 5 at the crash below 471 passed, 10 failed, then the -14 CS rejection after list_x::…write_buffer_immediate_on_open_existing_heap_visible_to_cpu (the leak #1520 fixes; #3492 doesn't include it)
the lib suite at 2 threads, + #1520's test change (lab only) not run 886 passed, 12 failed, then -14 at real::readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state
the lib suite at 1 thread, + #1520's test change (lab only) not run 889 passed, 8 failed, no rejection, then exit 5 at the crash below
bind::…create_list_reset_and_clear_state_track_initial_pso_on_d3d12 alone fails (CreateCommandList refuses the list) passes
title_textures::…a_placed_texture_gets_the_pages_of_a_level_with_its_texels alone fails passes
bind::…execute_indirect_reads_the_arguments_written_before_it alone crashes crashes: access violation at d3d12core.dll+0x56215d, read of 0x2b28
  • Most of main's failures under Wine are gone with D3D12.X: keep vkd3d-proton's vtables under Wine and wrap the title's fences (#175) #3492 (98 → 10 in hle::d3d12x before the run ends). The cascade of refused list creations doesn't happen.
  • hle::d3d12x::sparse::tests at 4 threads, 20 runs: no trap in vkd3d-proton's list check. a_tile_of_a_gpu_view_shows_the_page_mapped_there failed 4 of 20 (!v.s.mapped.contains_key(&(w + TILE)), sparse.rs:12315). Alone it passed 20 of 20.
  • Crash that is not from this PR: hle::d3d12x::tests::serialize_root_signature_strips_console_flags_and_preserves_pc_flags crashes the process alone on f97120dc as well.
  • -14 at the coherent test: that test VirtualFrees memory while late_release still holds the resource. Under Wine that succeeds, and RADV rejects the next submission (Linux (Wine + vkd3d-proton): status and tracking #3067). That isn't from this PR either.

Not tested

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

@Royalflamejlh
Royalflamejlh force-pushed the fix/wine-native-vtables branch from 19e8fd5 to c817f42 Compare November 30, 2026 12:58
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 30, 2026
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@ClosetPie107 thank you, that is the run this needed. bind::tests::execute_indirect_reads_the_arguments_written_before_it crashes the same way here on NVIDIA at 19e8fd50. It is the test's own submit: it adopts its list (to record as XCL does) and then calls ExecuteCommandLists on a plain PC queue. c817f425 puts the guard around that submit, as #867 did for the older tests of that shape; it passes here now (RTX 4060 Ti, stock vkd3d-proton master 71cae091, 1 run alone).

One thing is still open and you may see it too: with 4 test threads, 1 of 4 runs of hle::d3d12x::bind::tests at c817f425 ended in the read at 0x2b28 (the other 3: 115 passed, 1 failed; main d52ff48c: 106 passed, 10 failed, 4 of 4). With one thread I have not seen it. The description says so under Not tested.

Your sparse::tests::a_tile_of_a_gpu_view_shows_the_page_mapped_there failure at 4 threads (4 of 20, never alone) I have not looked at yet.

AI use: Claude Code (Claude Fable 5.2) made the runs and wrote this.

Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 30, 2026
…submit (xcl-dev#3492 c817f42)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh force-pushed the fix/wine-native-vtables branch from c817f42 to 0f347f6 Compare November 30, 2026 13:30
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 30, 2026
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 30, 2026
… list at its PC submits (xcl-dev#3492 0f347f6)

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

Copy link
Copy Markdown

Test report for #3492 at 0f347f685f059f26749e8113f7ae8ff57af43bef, against its merge-base with main, f97120dc, under Wine on AMD.

Tested

Not tested

  • native Windows
  • NVIDIA
  • the gpu:: tests in the suite runs
  • the workspace's other crates and integration tests (only -p xcl --lib)
  • a game run (no regression block)

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

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Review (head ebc21f2, diff read, not a merge-check: PR description fails (no smoke blocks, no Windows suite run), so not built or run here):

  • Under Wine, title fences skip XCL's fence hooks. The fence proxy's slots 8 / 9 jump straight to vkd3d-proton and slot 10 only forwards and notes (real.rs ~5147-5157), so title fences skip main's fence_get_completed_value (settle_readbacks_try, title_textures::safe_fence_value), fence_set_event_on_completion (async sparse readbacks) and the send_pending step in fence_signal (~4358-4362, ~12359-12440). A title could see a fence complete before its texture downloads or sparse readbacks have landed and read stale memory.
  • Windows changes too: the queue now overrides Signal / Wait (~4342, ~12241) outside under_wine(), so XCL's own Signal / Wait on adopted queues take the CLASSES lock through slot_of on every call (same result, extra lock).
  • UnadoptGuard::new (~1461) calls readable() and takes the global UNADOPTED lock before skips_guard, on every bind_pipeline_exact, reset and execute; checking skips_guard first would avoid that.
  • Detection is under_wine() (any Wine), not vkd3d-proton specifically. Patching vkd3d-proton's vtables in place makes XCL's Release hooks run for every object of those classes, including XCL's own resources that main deliberately leaves unadopted; please say whether that's intended.
  • Nothing tests the queue Signal / Wait unwrapping or the fence-hook behaviour. At 969 lines, the create_raw_fence swaps across 9 files and the test-site guards could go first as a preparation PR.

Fine: in-place patching happens once per table under a lock and keeps the original entries, the guard pins a reference and does the final release through XCL's Release hook, and the proxy frees itself on the last release.

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

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

Review of 182896bc: 3 finding(s) (2 high, 1 medium), most severe first.

Re-review at 182896bc. From the 2791e80c review, the cross-thread UnadoptGuard vtable swap, the end_title raw fences, the unconverted fence sites and the null fences array weren't flagged again and look addressed. Still open: the in-place patch sends XCL's own-work and runtime-internal objects through the hooks, and EnqueueMakeResident still passes the fence proxy through. The three items below are new.

  1. High crates/xcl/src/hle/d3d12x/bind.rs:2944: see below.
  2. High crates/xcl/src/hle/d3d12x/real.rs:5159: The FenceProxy vtable has only 32 slots, while the adopted fence class it replaces had scanned + EXTRA_SLOTS (64) entries, with a logged stub on every console slot past the PC interface. (inline)
  3. Medium crates/xcl/src/hle/d3d12x/real.rs:1252: Kind::StateObject and Kind::PipelineLibrary are still adopted with extended vtable copies under Wine, but they're neither patched in place (in_place_kind) nor guarded where they're passed to the runtime as arguments. (inline)

On lines outside the diff:

  1. High crates/xcl/src/hle/d3d12x/bind.rs:2944: poll_two_pass_feedback adds an UnadoptGuard only in the adopted-queue branch. The else branch submits the same adopted copy list with q.ExecuteCommandLists and no guard. Under Wine, the feedback copy list (made through the adopted device, so it carries XCL's extended vtable) is submitted on a queue that is_adopted() says isn't adopted, and vkd3d-proton's list check sees the wrong lpVtbl and rejects or asserts: the crash the guard was added to prevent on the other branch. Guarding both branches would fix it.

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

}
creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]);

/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying

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.

High: The FenceProxy vtable has only 32 slots, while the adopted fence class it replaces had scanned + EXTRA_SLOTS (64) entries, with a logged stub on every console slot past the PC interface. Under Wine, a title calling a console ID3D12Fence method at slot 32 or above through the proxy reads past the end of the 32-entry leaked Vec and jumps to whatever pointer follows on the heap, so it crashes where before it hit a logged S_OK stub. Sizing the proxy table like the adopted class, with the same stubs, would keep the old behaviour.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right. The proxy's table now has the adopted fence's length, 12 PC slots and EXTRA_SLOTS (real.rs:5172). Every slot past 12 is a logged stub, as before. New test a_fence_proxy_answers_every_slot_an_adopted_fence_has calls the last slot. It fails without the change, because the process faults. Head cc2bf1fa.

/// sit inside the PC interface: patched in place under Wine. (Not fences: console #12 is past the
/// PC table's end. Not command allocators and lists: vkd3d-proton checks those at run time, and a
/// title calls an allocator past its 9 PC methods.)
fn in_place_kind(kind: Kind) -> bool {

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.

Medium: Kind::StateObject and Kind::PipelineLibrary are still adopted with extended vtable copies under Wine, but they're neither patched in place (in_place_kind) nor guarded where they're passed to the runtime as arguments. If a title under Wine creates a raytracing state object (adopted) and calls SetPipelineState1(so) or AddToStateObject(desc, so), vkd3d-proton gets an object with XCL's extended vtable. By the PR's own premise it only accepts its own vtable, so this can trip the same lpVtbl assertion the PR fixes for PSOs and heaps. Adding them to in_place_kind (or guarding those calls) would cover them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not so, as in the earlier thread on this line. vkd3d-proton does not compare a state object's table. SetPipelineState1 and AddToStateObject both take it with rt_impl_from_ID3D12StateObject, a plain CONTAINING_RECORD (libs/vkd3d/vkd3d_private.h:6533, device.c:8113 at 71cae091). A pipeline library is never passed to the runtime as an argument. Its own methods reach vkd3d-proton through XCL's table, with vkd3d-proton's own object. Left as is.

@Royalflamejlh
Royalflamejlh force-pushed the fix/wine-native-vtables branch from 182896b to cc2bf1f Compare December 2, 2026 22:13
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

On the point outside the diff, at head cc2bf1fa:

  • poll_two_pass_feedback, the queue that is not adopted: right. The guard now covers both branches (bind.rs:2944). That branch runs only on a queue XCL did not adopt; in the title every queue is adopted, so it is reached by tests that share the device. No new test: it would need the two-pass feedback running on such a queue.

The two earlier points still open are answered above: the in-place table and own-work objects in its thread, and EnqueueMakeResident, where vkd3d-proton signals through the fence's table (device.c:7116).

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of cc2bf1fa, since 182896bc (code reading only, not a merge-check; PR description red) · 1 high, 2 medium, 1 nit

In short: This push makes the fence proxy's table as long as an adopted fence's (12 + EXTRA_SLOTS, with logged stubs for the console slots), so a title calling a console fence method on a proxy reaches a stub instead of running off the table. A test covers it. The test helper in alloc_pool.rs now takes the list guard on both of its submit paths. The earlier High finding is unchanged: the title's ExecuteBundle still hands vkd3d-proton the adopted bundle. The smoke pair names an earlier head.

High

  1. The title's ExecuteBundle misses the bundle guard (still open). Console slot 27 sends calls from the game image to list_x::execute_bundle (list_x.rs ~1266), which calls the runtime through pc(this, 27) with no UnadoptGuard. Only callers outside the title reach the guarded cl_execute_bundle. Fix: add let _bundle_guard = real::UnadoptGuard::new(bundle); before the PC call in list_x::execute_bundle, and run the test through that function.

Medium

  1. No Windows suite counts (still open). Tested has filtered runs only. CONTRIBUTING.md item 2 asks for the whole suite on a GPU.
  2. Size (still open). +1,181 lines in one commit. The stack suggested earlier still applies: create_raw_fence at the call sites, the in-place tables, UnadoptGuard, the fence proxy.

Nit

  1. The raw-fence test does nothing off Wine (still open). a_raw_fence_made_under_wine_is_signalled_at_the_title_end returns early when not under Wine, without skip_test.
Checked and fine
  • fence_proxy_vtable (real.rs ~5170) now has 76 slots. Slots 0-11 forward to the runtime's fence or XCL's hooks, slot 12 is completed_value_address, and 13 onward are logged stubs, as on an adopted fence's table. a_fence_proxy_answers_every_slot_an_adopted_fence_has calls the last slot.
  • In the alloc_pool.rs test helper, UnadoptGuard::new(cl) now covers the ExecuteCommandLists path as well as the native one. Test-only.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026

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

Review of cc2bf1fa: 3 finding(s) (2 high, 1 medium), most severe first.

Re-review at cc2bf1fa. From the 182896bc review, the 32-slot FenceProxy table and the StateObject/PipelineLibrary vtables weren't flagged again. The poll_two_pass_feedback submit now has its guard, but the Signal on the same path still passes a proxy (second item). Still open from earlier: EnqueueMakeResident doesn't unwrap the fence, and the in-place patch routes XCL's own-work and runtime-internal objects through the hooks.

  1. High crates/xcl/src/hle/d3d12x/list_x.rs:1268: see below.
  2. High crates/xcl/src/hle/d3d12x/bind.rs:2953: see below.
  3. Medium crates/xcl/src/hle/d3d12x/real.rs:1141: register_native keeps at most 64 native tables and only warns past that, and for a guarded object whose native table wasn't recorded, orig_fn's is_known_native check fails, so it reads *ext.sub(1) from the native table (not an XC.... (inline)

On lines outside the diff:

  1. High crates/xcl/src/hle/d3d12x/list_x.rs:1268: The title's ExecuteBundle never reaches the new bundle guard: console slot 27 sends title calls to list_x::execute_bundle, which calls the native PC ExecuteBundle through orig_fn without an UnadoptGuard. Only cl_execute_bundle (non-title callers, real.rs:11945) got the guard. Under Wine, a title that records a bundle and calls ExecuteBundle from its own code hands vkd3d-proton the bundle with XCL's extended vtable, the case that drops or asserts. The new test only exercises cl_execute_bundle. Guarding in list_x::execute_bundle too would cover the title path.

  2. High crates/xcl/src/hle/d3d12x/bind.rs:2953: The two-pass feedback fence is still made with dev.CreateFence (bind.rs:2770, not converted to create_raw_fence), so under Wine it's a FenceProxy, and poll_two_pass_feedback calls q.Signal on it even when the queue isn't adopted, the case this PR handles for ExecuteCommandLists. IndirectFeedback::new runs during title recording on the adopted device, so copy_fence is a proxy. When a DIRECT queue XCL didn't adopt submits a two-pass list, the else branch's q.Signal(&fence) goes straight to vkd3d-proton with the proxy, which hits its fence-vtable assertion (process ends) or returns an error that sets fb.removed and turns feedback off. Creating that fence with create_raw_fence (or unwrapping before Signal) would fix it.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

!is_ext_fast(cur) || in_place_original(cur, 0).is_some()
}

fn register_native(orig: usize) {

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.

Medium: register_native keeps at most 64 native tables and only warns past that, and for a guarded object whose native table wasn't recorded, orig_fn's is_known_native check fails, so it reads *ext.sub(1) from the native table (not an XCL pointer) and calls through it. Once the list is full, if one thread guards object X and another enters a hook on X and calls orig_fn(X, slot), it reads the 8 bytes before vkd3d's vtable as a table pointer and jumps through garbage. Growing the set (or refusing the guard when it can't be recorded) would prevent the crash the warning predicts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the point answered earlier on this line. The 64 count distinct native tables. vkd3d-proton has a handful, and the warning never came up in 250 of our runs. Refusing the guard past the cap would not avoid a crash: vkd3d-proton would then get the adopted list and fail its own check (the read at 0x2b28). Left as is.

@Royalflamejlh
Royalflamejlh force-pushed the fix/wine-native-vtables branch from cc2bf1f to 287a691 Compare December 2, 2026 22:38
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@Foniass thanks. At 287a6918, rebased onto main 078358a0:

  • The title's ExecuteBundle: right. Console slot 27 goes to list_x::execute_bundle, which called the runtime without the guard. It takes the guard now (list_x.rs:1268). a_bundle_reaches_execute_bundle_with_its_native_table_only_under_wine calls both entries, and fails on this one without the guard.
  • Windows suite counts: the whole suite and the smoke pair for this head are queued on a Windows machine. They go into the description when they are done.
  • Size: it stays one commit. The halves cannot be run apart on an unpatched vkd3d-proton: without the in-place tables, the first heap ends the process in an assertion. A stack would have every PR but the last fail the same way.
  • The raw-fence test off Wine: it now reports itself skipped (skip_test("not under Wine")).

@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of 287a6918, since cc2bf1fa (code reading only, not a merge-check; PR description red) · 2 medium

In short: This push fixes the High finding from my last reviews. list_x::execute_bundle, the path a title's ExecuteBundle takes, now holds an UnadoptGuard on the bundle, and the bundle test runs through it as well as through cl_execute_bundle. The raw-fence test now skips visibly off Wine. The suite-count and size points are unchanged. The smoke pair names an earlier head.

Medium

  1. No Windows suite counts (still open). Tested has filtered runs only. CONTRIBUTING.md item 2 asks for the whole suite on a GPU.
  2. Size (still open). +1,185 lines in one commit. The stack suggested earlier still applies: create_raw_fence at the call sites, the in-place tables, UnadoptGuard, the fence proxy.
Checked and fine
  • Earlier finding fixed: the title's ExecuteBundle missed the bundle guard. execute_bundle (list_x.rs ~1266) takes real::UnadoptGuard::new(bundle) before the PC call through slot 27. The test checks the native table is seen through both cl_execute_bundle and list_x::execute_bundle, and that the bundle's own table is back afterwards.
  • Earlier finding fixed: a_raw_fence_made_under_wine_is_signalled_at_the_title_end calls skip_test("not under Wine") instead of returning silently.
  • The fence proxy's 76-slot table from the last push is unchanged.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

…fences (xcl-dev#175)

vkd3d-proton takes an object only with its own vtable. For command lists and
allocators it checks at run time and returns NULL, which its submit path then
reads (`NULL+0x2b28`); for heaps, resources, descriptor and query heaps, root
signatures, pipeline states and command signatures an assertion ends the
process; a fence is cast without a check on its queue thread.

Under Wine only:
- the assert-checked classes keep the runtime's table and XCL's PC slots are
  written into it, with the entries it had kept for `orig_fn`;
- `UnadoptGuard` gives a list, bundle, allocator, heap or pipeline its
  native table back for the length of the host call that takes it as an
  argument (ExecuteBundle drops a bundle whose table is not its own);
- the title's fences are thin proxies over the runtime's fence, unwrapped at
  the queue's Signal and Wait and the device's CreateSharedHandle and
  SetEventOnMultipleFenceCompletion; their GetCompletedValue,
  SetEventOnCompletion and Signal run XCL's fence hooks on the runtime's
  fence, as an adopted fence's do on Windows; the proxy's table is as long
  as an adopted fence's, its console slots logged stubs. XCL's own fences
  (`create_raw_fence`, and those made in its own work) stay the runtime's, as
  `main` leaves them unadopted; `create_raw_fence` still puts its fences in
  `FENCES`, as `main`'s `CreateFence` does, so `end_title` signals them.

This is xcl-dev#867 and xcl-dev#2477 by gustavsi, which were closed unmerged, carried onto
the current `main`: the submit, fence and reset sites `main` has gained since
(`native_queue_execute`, the sparse queues, the two-pass feedback poll, the
own-work submit, the retire and upload fences) get the same guard or raw
fence. One test new on `main` signalled a device fence on a PC queue and takes
a raw fence now.

On Windows nothing changes: `under_wine()` gates each branch.

Co-authored-by: gustavsi <86445165+gustavsi@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh force-pushed the fix/wine-native-vtables branch from 287a691 to d9afcbf Compare December 2, 2026 22:42
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

At head d9afcbf1, on the two points outside the diff:

  • The title's ExecuteBundle (list_x::execute_bundle): fixed in 287a6918, after Foniass's review. It takes the guard, and the bundle test calls both entries.
  • The two-pass feedback fence: right. Under Wine it was a proxy, and a queue XCL did not adopt passed it to vkd3d-proton at the Signal. It is made with create_raw_fence now (bind.rs:2770). No new test: it needs the two-pass feedback running on such a queue.

EnqueueMakeResident and the in-place tables are answered above (vkd3d-proton signals through the fence's table, device.c:7116).

@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of d9afcbf1, since 287a6918 (code reading only, not a merge-check; PR description red) · 2 medium

In short: This push makes the two-pass feedback copy fence (bind.rs, IndirectFeedback) a raw fence from create_raw_fence, like XCL's other internal fences under Wine. Nothing else changed in the code. The suite-count and size points are unchanged. Tested now has a Wine CPU-only run at this head (100 passed), but no GPU run.

Medium

  1. No whole-suite GPU run (still open). Tested has filtered runs only: the new one under Wine on lavapipe, the earlier ones filtered on an RTX 4060 Ti. CONTRIBUTING.md item 2 asks for the whole suite on a GPU.
  2. Size (still open). +1,187 lines in one commit. The stack suggested earlier still applies: create_raw_fence at the call sites, the in-place tables, UnadoptGuard, the fence proxy.
Checked and fine
  • create_raw_fence off Wine goes through dev.CreateFence, as before. Under Wine it makes the runtime's fence and tracks it in FENCES, so end_title still signals the feedback fence.
  • The ExecuteBundle guard on both paths, the fence proxy's full table, and the visible skip off Wine from the last push are unchanged.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@Foniass both points are as answered above. The whole suite and the smoke pair for d9afcbf1 are queued on a Windows machine, and their counts go into Tested when done. The size stays one commit, for the reason given: the halves cannot be run apart on an unpatched vkd3d-proton.

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

Review of d9afcbf1: 2 finding(s) (2 medium), most severe first.

Re-review at d9afcbf1. Correcting my 182896bc note: StateObject/PipelineLibrary still aren't patched in place or guarded, and UnadoptGuard still exposes the native vtable to other threads while it's held (now via the bundle guard). Both are still open, along with EnqueueMakeResident not unwrapping the fence proxy and the in-place patch hooking XCL's own-work and runtime-internal objects. Two new items below.

  1. Medium crates/xcl/src/hle/d3d12x/real.rs:5305: The Wine branch of dev_create_fence wraps the fence of every caller outside own-work in a FenceProxy and drops creator!'s IN_CREATOR re-entrancy bypass, so callers that used to get the raw fence now get a proxy. (inline)
  2. Medium crates/xcl/src/hle/d3d12x/real.rs:5251: Under Wine, create_raw_fence on a device that isn't adopted goes through dev.CreateFence and never calls track_end_title_fence, although its doc says its fences go into FENCES. (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

}
}
let hr = dev_create_fence_pc(this, value, pc_flags, riid, ppv);
let hr = if crate::util::under_wine() {

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.

Medium: The Wine branch of dev_create_fence wraps the fence of every caller outside own-work in a FenceProxy and drops creator!'s IN_CREATOR re-entrancy bypass, so callers that used to get the raw fence now get a proxy. That covers several XCL sites that still call dev.CreateFence (console_heap.rs:244, list_x.rs:2341, real.rs:593, uma_driver.rs:529/627, gpu_awake.rs:297), any non-title caller through the adopted device vtable (vkd3d-proton's own swapchain, interop layers), and a runtime-internal CreateFence made while another creator is running. Any of them that reads the fence's internals or checks its vtable gets the 16-byte proxy, which means a vkd3d-proton assertion or a garbage read. Keeping the IN_CREATOR bypass and converting the remaining internal sites to create_raw_fence would limit proxies to title fences.

@Royalflamejlh Royalflamejlh Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed. A proxy for every fence made through the adopted device, outside XCL's own work, is the Wine form of what main does: there dev_create_fence adopts every such fence. The IN_CREATOR case is D3D12Core calling the device's public methods from inside another one. vkd3d-proton never does that for fences: it has no ID3D12Device_CreateFence call of its own (at 71cae091 the only one in libs/vkd3d is the definition, device.c:7178). Its swap chain makes its fences internally. The XCL sites listed each reach vkd3d-proton with its own fence, as answered above: native_queue_signal unwraps, gpu_awake is own work, and uma_driver runs before the device is adopted.

/// (`late_release`, `alloc_pool`, `list_x`, `cpu_writes`, `present`, `vram`, `drain_gpu`)
/// so under Wine/vkd3d-proton it can be signalled on raw internal queues (`sparse::queue()`)
/// and passed to native APIs without hitting `FenceProxy` vtable mismatches.
pub(super) unsafe fn create_raw_fence(dev: &ID3D12Device) -> windows::core::Result<ID3D12Fence> {

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.

Medium: Under Wine, create_raw_fence on a device that isn't adopted goes through dev.CreateFence and never calls track_end_title_fence, although its doc says its fences go into FENCES. If XCL code on a non-adopted device (e.g. a second device) makes an internal fence and has a queue Wait on it, end_title doesn't signal it to u64::MAX, so drain_gpu waits until the 15 s watchdog ends the process. Tracking the fence on both branches would fix it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed: that matches main. On a device XCL did not adopt, CreateFence goes straight to the runtime on main as well, and its fence never enters FENCES there either. FENCES holds the fences made through the adopted device, and create_raw_fence keeps that. The doc line says "one create_raw_fence makes under Wine", meaning the branch that skips dev_create_fence.

@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

On the items this review carries over, at d9afcbf1. Each is answered in its thread with the vkd3d-proton line it rests on:

  • State objects: SetPipelineState1 and AddToStateObject take them with a plain CONTAINING_RECORD and no table check (vkd3d_private.h:6533, device.c:8113 at 71cae091). A pipeline library is never passed as an argument.
  • UnadoptGuard on other threads: it covers lists, bundles and allocators, which D3D12 does not let two threads use at once. The in-place classes are skipped.
  • EnqueueMakeResident: vkd3d-proton signals the fence through its table (device.c:7116).
  • The in-place tables and objects XCL did not adopt: the cost of D3D12.X: patch assert-checked vtables in place under Wine (#175) #2477's approach, with what each case does.

No code change for them.

Royalflamejlh added a commit to Royalflamejlh/xcl-linux that referenced this pull request Dec 3, 2026
…ton's fence

The change of xcl-dev/xcl#3492 at 313f55e8: a title's fence went straight
to vkd3d-proton and skipped the readback settling the hooks do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants