Repository navigation
D3D12.X: keep vkd3d-proton's vtables under Wine and wrap the title's fences (#175) - #3492
Royalflamejlh wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
3bd9a66 to
19e8fd5
Compare
|
Test report for #3492 at Tested
Not tested
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report. |
19e8fd5 to
c817f42
Compare
|
@ClosetPie107 thank you, that is the run this needed. One thing is still open and you may see it too: with 4 test threads, 1 of 4 runs of Your AI use: Claude Code (Claude Fable 5.2) made the runs and wrote this. |
…submit (xcl-dev#3492 c817f42) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
c817f42 to
0f347f6
Compare
… list at its PC submits (xcl-dev#3492 0f347f6) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Test report for #3492 at Tested
Not tested
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report. |
0f347f6 to
ebc21f2
Compare
|
Review (head ebc21f2, diff read, not a merge-check:
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. |
ebc21f2 to
313f55e
Compare
bmjask
left a comment
There was a problem hiding this comment.
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.
- High
crates/xcl/src/hle/d3d12x/bind.rs:2944: see below. - 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) - 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:
- High
crates/xcl/src/hle/d3d12x/bind.rs:2944:poll_two_pass_feedbackadds anUnadoptGuardonly in the adopted-queue branch. The else branch submits the same adopted copy list withq.ExecuteCommandListsand 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 thatis_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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
182896b to
cc2bf1f
Compare
|
On the point outside the diff, at head
The two earlier points still open are answered above: the in-place table and own-work objects in its thread, and |
|
Follow-up review of In short: This push makes the fence proxy's table as long as an adopted fence's (12 + High
Medium
Nit
Checked and fine
Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point. |
bmjask
left a comment
There was a problem hiding this comment.
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.
- High
crates/xcl/src/hle/d3d12x/list_x.rs:1268: see below. - High
crates/xcl/src/hle/d3d12x/bind.rs:2953: see below. - Medium
crates/xcl/src/hle/d3d12x/real.rs:1141:register_nativekeeps at most 64 native tables and only warns past that, and for a guarded object whose native table wasn't recorded,orig_fn'sis_known_nativecheck fails, so it reads*ext.sub(1)from the native table (not an XC.... (inline)
On lines outside the diff:
-
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 tolist_x::execute_bundle, which calls the native PC ExecuteBundle throughorig_fnwithout an UnadoptGuard. Onlycl_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 exercisescl_execute_bundle. Guarding inlist_x::execute_bundletoo would cover the title path. -
High
crates/xcl/src/hle/d3d12x/bind.rs:2953: The two-pass feedback fence is still made withdev.CreateFence(bind.rs:2770, not converted tocreate_raw_fence), so under Wine it's a FenceProxy, andpoll_two_pass_feedbackcallsq.Signalon it even when the queue isn't adopted, the case this PR handles for ExecuteCommandLists.IndirectFeedback::newruns during title recording on the adopted device, socopy_fenceis a proxy. When a DIRECT queue XCL didn't adopt submits a two-pass list, theelsebranch'sq.Signal(&fence)goes straight to vkd3d-proton with the proxy, which hits its fence-vtable assertion (process ends) or returns an error that setsfb.removedand turns feedback off. Creating that fence withcreate_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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
cc2bf1f to
287a691
Compare
|
@Foniass thanks. At
|
|
Follow-up review of In short: This push fixes the High finding from my last reviews. Medium
Checked and fine
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>
287a691 to
d9afcbf
Compare
|
At head
|
|
Follow-up review of In short: This push makes the two-pass feedback copy fence ( Medium
Checked and fine
Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point. |
|
@Foniass both points are as answered above. The whole suite and the smoke pair for |
bmjask
left a comment
There was a problem hiding this comment.
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.
- Medium
crates/xcl/src/hle/d3d12x/real.rs:5305: The Wine branch ofdev_create_fencewraps 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) - Medium
crates/xcl/src/hle/d3d12x/real.rs:5251: Under Wine,create_raw_fenceon a device that isn't adopted goes throughdev.CreateFenceand never callstrack_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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
On the items this review carries over, at
No code change for them. |
…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>
Edited 2026-12-02: head
d9afcbf1after 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 againstmainand 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).UnadoptGuardgives 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'sSignalandWait(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 sitesmainhas 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 orcreate_raw_fence.main(gpu_clear_uav_of_a_stencil_uav_clears_the_twin) signalled a device fence on a PC queue; it takes a raw fence.Tested
master71cae091(assertions on), RTX 4060 Ti 16 GB (driver 615.71.09), rustc 1.98.0, release build forx86_64-pc-windows-gnu. Base9335bc0d, head3bd9a664.d9afcbf1(2026-12-02), after bmjask's three reviews and Foniass's, rebased ontomain078358a0: bothExecuteBundleentries (the PC one and the console slot 27 inlist_x) give the bundle its native table (vkd3d-proton dropped an adopted bundle);create_raw_fenceputs its fences inFENCES, asmain'sCreateFencedoes, soend_titlesignals them (the separate call for thelist_xcell 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 bundleunder 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).d9afcbf1:cargo test --workspace -- --test-threads=4, 3,018 passed, 0 failed, 52 ignored, 1 run; 30SKIPPEDlines (wave64 tests: no wave64 on this card; no D3D12 debug layer; noGPU_UPLOADheaps; 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).0797336e(2026-12-01): under Wine the device'sCreateSharedHandleandSetEventOnMultipleFenceCompletionhand 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_refusingfailed once while a title was running on the same card (it passes alone, 3 of 3).76427620(2026-12-01), after a second review:UnadoptGuard::newand 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.313f55e8(2026-12-01), after a review: the fence proxy's GetCompletedValue, SetEventOnCompletion and Signal are nowmain's hooks, run on vkd3d-proton's own fence (they went straight to vkd3d-proton before, so a title's fence skipped the readback settlingmaingained on 2026-11-25); fences XCL makes inside its own work are not wrapped; the queue's Signal / Wait overrides are underunder_wine()again, so Windows takesmain'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.main7d86c5d2(headebc21f2e):main'sCreateFencenow 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.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_trimbesidecreate_list_reset_and_clear_state_track_initial_pso_on_d3d12ended that way 10 of 12 times; with a raw fence and the guard at its two submits, 0 of 20, andhle::d3d12x::bind::testsat 4 threads ran through 10 of 10 (4 of 16 ended early before).c817f425(2026-11-30):bind::tests::execute_indirect_reads_the_arguments_written_before_it, a test new onmainthat adopts its list and submits it on a PC queue, takes the guard at that submit. It ended in the read at0x2b28on19e8fd50(found on an RX 9070 by ClosetPie107, below; the same here) and passes now.mainf97120dc(head19e8fd50):main's rewritten late-release seal and itsInListResetincl_resetconflicted; 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_release8 passed,real::wine_vtable_tests4,real::in_place_tests2,real::depth_uav_twin_tests3,title_textures65,sparse::tests140,list_x::tests101 passed and 3 failed (the three that fail on the base). The counts and title runs below are on3bd9a664.hle::d3d12xunit 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):9335bc0d3bd9a664list_x::tests,tests)tests)The base's
list_x::testsends after 5 tests in vkd3d-proton's list check (a read at0x2b28); with this PR it runs through.hle::d3d12x::testsends the same way on both, a null read after aD3D12SerializeRootSignaturecall with an invalid version. Of this PR's 17 failures, 15 fail on the base too; the other two are inlist_x::tests, which the base does not get to in this pass, and both failed on the base in an earlier whole-suite run.game+0x2478b7bwithE_INVALIDARGinrax(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.master71cae091, debug build): the lib suite at 2 threads withoutgpu::and six tests that end the process or run out of memory there, 1,715 passed and 16 failed at0f347f68against 1,609 and 116 on the basef97120dc; 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:this PR's head:
Not tested
under_wine().gpu::tests and a title run.hle::d3d12x::sparse::testsin 20 did on the first head). It is between tests: the title's device is always adopted, and its queues with it.AI use
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.