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

Open
Royalflamejlh wants to merge 1 commit from upstream-pr/3492 into main
Royalflamejlh commented 2026-11-30 02:45:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-11-30T02:45:57Z.


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 (#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 (#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 #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 (#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 #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.
<!-- greyfinch-sync:ivall/xcl:issue:5558048001 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-11-30T02:45:57Z. --- _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 (#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` (#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 #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 (#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 #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.
ClosetPie107 commented 2026-11-30 12:53:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-30T12:53:06Z.


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 #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 (#3067). That isn't from this PR either.

Not tested

  • native Windows
  • NVIDIA
  • the gpu:: tests
  • the full suite without #1520
  • a game run (no regression block)

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

<!-- greyfinch-sync:ivall/xcl:comment:7279055219 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7279055219). Originally posted by [ClosetPie107](https://github.com/ClosetPie107) on 2026-11-30T12:53:06Z. --- 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 #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 `VirtualFree`s memory while `late_release` still holds the resource. Under Wine that succeeds, and RADV rejects the next submission (#3067). That isn't from this PR either. **Not tested** - native Windows - NVIDIA - the `gpu::` tests - the full suite without #1520 - a game run (no regression block) AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Royalflamejlh commented 2026-11-30 12:59:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-11-30T12:59:27Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7279201180 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7279201180). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-11-30T12:59:27Z. --- @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.
ClosetPie107 commented 2026-11-30 16:03:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-30T16:03:04Z.


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

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, under Wine. It wasn't run on Windows.
  • Command: cargo test --locked -p xcl --lib --target x86_64-pc-windows-gnu -- <filter>.
  • The PR's new tests, each alone (--test-threads=1 <name>): all 6 pass: a_vtable_patched_in_place_keeps_its_originals_and_its_neighbour, concurrent_calls_and_patches_on_readonly_vtable_never_tear_or_miss_orig_fn, concurrent_release_during_unadopt_guard_still_runs_hooked_cleanup, fence_proxy_forwards_signal_unwraps_and_frees_on_final_release, track_end_title_fence_registers_once_and_addrefs, unadopt_guard_restores_native_vtable_and_reapplies_extended_on_drop. 6 passed, 0 failed.
  • The lib suite at --test-threads=2, with --skip gpu:: and these six: failed_restore_stops_before_importing_an_unbacked_window, grooming_leaves_a_window_under_1_gib_only_its_hole (both run out of memory here), write_buffer_immediate_on_open_existing_heap_visible_to_cpu, coherent_buffer_sanitizes_console_flags_and_state, serialize_root_signature_strips_console_flags_and_preserves_pc_flags and execute_indirect_reads_the_arguments_written_before_it. Under Wine each of the last four ends the process or makes RADV reject later submissions (#3067), so without them the suite reaches its summary:
    • #3492 0f347f68: 1715 passed, 16 failed, 5 ignored
    • base f97120dc: 1609 passed, 116 failed, 5 ignored
  • No test fails on #3492 that passes on the base, and 100 of the base's failures pass with it (the list-creation cascade is gone). Most of the base's failures under Wine are main's known ones on stock vkd3d-proton: list creation refused (E_INVALIDARG, #175 / #1701) and the tests after it (#3067).
  • Since my report on 19e8fd50, bind::tests::execute_indirect_reads_the_arguments_written_before_it passes alone (3 of 3). At 19e8fd50 it crashed (access violation at d3d12core.dll+0x56215d). title_textures::…a_placed_texture_gets_the_pages_of_a_level_with_its_texels and bind::…create_list_reset_and_clear_state_track_initial_pso_on_d3d12 pass alone too.
  • hle::d3d12x::sparse::tests at 4 threads, 10 runs: no trap in vkd3d-proton's list check. a_tile_of_a_gpu_view_shows_the_page_mapped_there failed 1 of 10 (!v.s.mapped.contains_key(&(w + TILE)), sparse.rs:12315), as at the old head (4 of 20); it passed 20 of 20 alone there.

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.

<!-- greyfinch-sync:ivall/xcl:comment:7284034091 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7284034091). Originally posted by [ClosetPie107](https://github.com/ClosetPie107) on 2026-11-30T16:03:04Z. --- Test report for #3492 at `0f347f685f059f26749e8113f7ae8ff57af43bef`, against its merge-base with `main`, `f97120dc`, under Wine on AMD. **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`, under Wine. It wasn't run on Windows. - Command: `cargo test --locked -p xcl --lib --target x86_64-pc-windows-gnu -- <filter>`. - The PR's new tests, each alone (`--test-threads=1 <name>`): all 6 pass: `a_vtable_patched_in_place_keeps_its_originals_and_its_neighbour`, `concurrent_calls_and_patches_on_readonly_vtable_never_tear_or_miss_orig_fn`, `concurrent_release_during_unadopt_guard_still_runs_hooked_cleanup`, `fence_proxy_forwards_signal_unwraps_and_frees_on_final_release`, `track_end_title_fence_registers_once_and_addrefs`, `unadopt_guard_restores_native_vtable_and_reapplies_extended_on_drop`. **6 passed, 0 failed.** - The lib suite at `--test-threads=2`, with `--skip gpu::` and these six: `failed_restore_stops_before_importing_an_unbacked_window`, `grooming_leaves_a_window_under_1_gib_only_its_hole` (both run out of memory here), `write_buffer_immediate_on_open_existing_heap_visible_to_cpu`, `coherent_buffer_sanitizes_console_flags_and_state`, `serialize_root_signature_strips_console_flags_and_preserves_pc_flags` and `execute_indirect_reads_the_arguments_written_before_it`. Under Wine each of the last four ends the process or makes RADV reject later submissions (#3067), so without them the suite reaches its summary: - #3492 `0f347f68`: 1715 passed, 16 failed, 5 ignored - base `f97120dc`: 1609 passed, 116 failed, 5 ignored - No test fails on #3492 that passes on the base, and 100 of the base's failures pass with it (the list-creation cascade is gone). Most of the base's failures under Wine are `main`'s known ones on stock vkd3d-proton: list creation refused (`E_INVALIDARG`, #175 / #1701) and the tests after it (#3067). - **Since my report on `19e8fd50`**, `bind::tests::execute_indirect_reads_the_arguments_written_before_it` passes alone (3 of 3). At `19e8fd50` it crashed (access violation at `d3d12core.dll+0x56215d`). `title_textures::…a_placed_texture_gets_the_pages_of_a_level_with_its_texels` and `bind::…create_list_reset_and_clear_state_track_initial_pso_on_d3d12` pass alone too. - `hle::d3d12x::sparse::tests` at 4 threads, 10 runs: no trap in vkd3d-proton's list check. `a_tile_of_a_gpu_view_shows_the_page_mapped_there` failed 1 of 10 (`!v.s.mapped.contains_key(&(w + TILE))`, `sparse.rs:12315`), as at the old head (4 of 20); it passed 20 of 20 alone there. **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 commented 2026-12-01 08:12:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:12:32Z.


Review (head ebc21f2e, 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.

<!-- greyfinch-sync:ivall/xcl:comment:7305015408 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7305015408). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:12:32Z. --- Review (head ebc21f2e, 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.
Royalflamejlh commented 2026-12-01 08:49:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T08:49:14Z.


Thanks. Point by point, at head 313f55e8:

  • Title fences skipping the fence hooks: right. The proxy was written before main's hooks gained the readback settling. Its GetCompletedValue, SetEventOnCompletion and Signal are now main's hooks, run on vkd3d-proton's own fence; XCL's own fence queries unwrap the proxy first and skip the hook, as on main. Fences made inside XCL's own work are no longer wrapped.
  • Windows changes too: right. The queue's Signal / Wait overrides are under under_wine() again, so Windows takes main's path; under Wine they no longer take the class lock.
  • UnadoptGuard::new: not as proposed: checking skips_guard first would skip an object whose native table another thread's guard has put in, and that guard's drop would then restore XCL's table in the middle of this call. A lock-free pre-check that is equivalent was added instead.
  • Any Wine, and the Release hooks: intended. Without vkd3d-proton, Wine's d3d12 is upstream vkd3d, which checks the same vtables but only logs where vkd3d-proton asserts; the path is the same there (not run on it). For an object XCL never recorded each Release hook finds nothing and forwards; the one difference is that XCL's own resources are kept until the queues finish their work.
  • Tests: three added, for the proxy's hooks and the queue unwrapping; two fail without the change.
  • Size: a clean split exists (the guard and create_raw_fence with their call sites first, about 500 lines; then the tables, the proxy and the queue unwrap), but the first part alone still stops at vkd3d-proton's assertion. I can split it if that is wanted.

cargo test --lib -- fence vtable wine unadopt, RTX 4060 Ti under Wine: 57 passed, 0 failed. Not run in a title on this head yet; the Windows suite and the smoke pair are still owed.

AI use: Claude Code. Claude Opus 5.5 checked the points and wrote the changes; Claude Fable 5.2 ran the tests on the card and wrote this reply.

<!-- greyfinch-sync:ivall/xcl:comment:7305827857 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7305827857). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-01T08:49:14Z. --- Thanks. Point by point, at head `313f55e8`: - **Title fences skipping the fence hooks:** right. The proxy was written before `main`'s hooks gained the readback settling. Its GetCompletedValue, SetEventOnCompletion and Signal are now `main`'s hooks, run on vkd3d-proton's own fence; XCL's own fence queries unwrap the proxy first and skip the hook, as on `main`. Fences made inside XCL's own work are no longer wrapped. - **Windows changes too:** right. The queue's Signal / Wait overrides are under `under_wine()` again, so Windows takes `main`'s path; under Wine they no longer take the class lock. - **`UnadoptGuard::new`:** not as proposed: checking `skips_guard` first would skip an object whose native table another thread's guard has put in, and that guard's drop would then restore XCL's table in the middle of this call. A lock-free pre-check that is equivalent was added instead. - **Any Wine, and the Release hooks:** intended. Without vkd3d-proton, Wine's d3d12 is upstream vkd3d, which checks the same vtables but only logs where vkd3d-proton asserts; the path is the same there (not run on it). For an object XCL never recorded each Release hook finds nothing and forwards; the one difference is that XCL's own resources are kept until the queues finish their work. - **Tests:** three added, for the proxy's hooks and the queue unwrapping; two fail without the change. - **Size:** a clean split exists (the guard and `create_raw_fence` with their call sites first, about 500 lines; then the tables, the proxy and the queue unwrap), but the first part alone still stops at vkd3d-proton's assertion. I can split it if that is wanted. `cargo test --lib -- fence vtable wine unadopt`, RTX 4060 Ti under Wine: 57 passed, 0 failed. Not run in a title on this head yet; the Windows suite and the smoke pair are still owed. **AI use:** Claude Code. Claude Opus 5.5 checked the points and wrote the changes; Claude Fable 5.2 ran the tests on the card and wrote this reply.
Foniass commented 2026-12-01 09:01:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:01:50Z.


Review (head 313f55e8, diff read, not a merge-check; PR description red, no Windows run):

  • Native Windows: I found no behaviour change (from reading). Every new path is behind under_wine(), which looks for ntdll!wine_get_version and caches the answer. Title fences aren't wrapped on Windows. The queue's Signal / Wait overrides are Wine-only. With in-place tables off, the table sizes in make_class match main. What Windows still pays is one OnceLock load per orig_fn call, per UnadoptGuard::new and per unwrap_fence. That includes every pipeline bind (bind_pipeline_exact) and every ExecuteCommandLists. It's small, but the suite and the smoke pair on Windows are what would show it, and neither has run (the description says so).
  • Size. It is +1042/-78. The stated reason, that the halves can't be tested apart on an unpatched vkd3d-proton, is about testing on Wine, not about review. It splits cleanly into a stack:
    1. create_raw_fence at the ~15 call sites (same behaviour on Windows);
    2. the in-place tables (class_for / patch_in_place);
    3. UnadoptGuard;
    4. the fence proxy.
  • Tests on Windows CI barely reach the shipped code. The guard tests use a test-only UnadoptGuard::enter (real.rs ~1492) that copies new's body. a_guard_on_an_object_... (~15668) returns early off Wine. The Wine branches of class_for (~1604) and dev_create_fence (~5282) aren't covered.
  • Wine-only, unverified:
    • Patching vkd3d-proton's shared tables hooks every object of those classes, XCL's own-work resources included, so is_adopted becomes true for them.
    • While a guard is active, other threads' calls on that object skip XCL's hooks.
    • uma_driver.rs (~529, ~627) still calls dev.CreateFence and may hand a proxy to vkd3d-proton.
    • The fixed caps (IN_PLACE_MAX 32, the 64-entry fast tables) fail silently when exceeded.
  • Overlap: #3099 does the same raw-fence and guard part against amd-dev. One should be picked. This carries over #867 and #2477, which were closed unmerged.

Fine: track_end_title_fence (real.rs ~5248) is a no-op on Windows, because dev_create_fence already tracked the fence. The proxy shares the real fence's reference count and is freed with it. patch_in_place saves the entries under a lock before writing.

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

<!-- greyfinch-sync:ivall/xcl:comment:7306113727 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7306113727). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:01:50Z. --- Review (head 313f55e8, diff read, not a merge-check; `PR description` red, no Windows run): - **Native Windows: I found no behaviour change** (from reading). Every new path is behind `under_wine()`, which looks for `ntdll!wine_get_version` and caches the answer. Title fences aren't wrapped on Windows. The queue's Signal / Wait overrides are Wine-only. With in-place tables off, the table sizes in `make_class` match main. What Windows still pays is one `OnceLock` load per `orig_fn` call, per `UnadoptGuard::new` and per `unwrap_fence`. That includes every pipeline bind (`bind_pipeline_exact`) and every `ExecuteCommandLists`. It's small, but the suite and the smoke pair on Windows are what would show it, and neither has run (the description says so). - **Size.** It is +1042/-78. The stated reason, that the halves can't be tested apart on an unpatched vkd3d-proton, is about testing on Wine, not about review. It splits cleanly into a stack: 1. `create_raw_fence` at the ~15 call sites (same behaviour on Windows); 2. the in-place tables (`class_for` / `patch_in_place`); 3. `UnadoptGuard`; 4. the fence proxy. - **Tests on Windows CI barely reach the shipped code.** The guard tests use a test-only `UnadoptGuard::enter` (`real.rs` ~1492) that copies `new`'s body. `a_guard_on_an_object_...` (~15668) returns early off Wine. The Wine branches of `class_for` (~1604) and `dev_create_fence` (~5282) aren't covered. - **Wine-only, unverified:** - Patching vkd3d-proton's shared tables hooks every object of those classes, XCL's own-work resources included, so `is_adopted` becomes true for them. - While a guard is active, other threads' calls on that object skip XCL's hooks. - `uma_driver.rs` (~529, ~627) still calls `dev.CreateFence` and may hand a proxy to vkd3d-proton. - The fixed caps (`IN_PLACE_MAX` 32, the 64-entry fast tables) fail silently when exceeded. - **Overlap:** #3099 does the same raw-fence and guard part against `amd-dev`. One should be picked. This carries over #867 and #2477, which were closed unmerged. Fine: `track_end_title_fence` (`real.rs` ~5248) is a no-op on Windows, because `dev_create_fence` already tracked the fence. The proxy shares the real fence's reference count and is freed with it. `patch_in_place` saves the entries under a lock before writing. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Royalflamejlh commented 2026-12-01 09:48:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T09:48:36Z.


Thanks. On the Wine-only list and the tests, at head 76427620:

  • uma_driver.rs fences: not so. Those calls run in open_uma, before the device is adopted, so the fence is vkd3d-proton's own. Every other remaining CreateFence reaches the runtime only through a Signal / Wait that unwraps the proxy.
  • Fixed caps: right for one of three. The list of native tables dropped a table silently past 64 entries; it now warns once. Of the other two, one falls back to the locked set and the other already warned. vkd3d-proton has 4 and 7 such tables.
  • Other threads during a guard, and is_adopted: both true, and neither gives a wrong result: under Wine only lists and allocators get guards, the title may not call one while it is an argument, and Release is pinned; is_adopted only picks orig_fn, which for an in-place table is the runtime's own entry.
  • Tests: right. UnadoptGuard::new and the tests now run the same body, so the Windows CI runs the shipped guard, and the Wine-only test became a case of one that runs everywhere. The Wine branches of class_for and dev_create_fence stay uncovered off Wine.
  • Windows cost: confirmed as a few atomic or OnceLock loads a call, no allocation, and one lock write per new sync-graph cell fence. The suite and the smoke pair on Windows are still owed.
  • Found while checking: SetEventOnMultipleFenceCompletion with two or more fences, or CreateSharedHandle on a fence, would still hand vkd3d-proton the proxy. Not hooked yet; now in the description.

On the split and #3099: the four parts build in the order you give, and under Wine nothing improves before the last. #3099 is the same guard and proxy in an older form against amd-dev, without the in-place tables. I will leave which of the two goes forward, and whether to stack this one, to the maintainers and the author of #3099.

cargo test --lib -- fence vtable wine unadopt, RTX 4060 Ti under Wine: 56 passed, 0 failed.

AI use: Claude Code. Claude Opus 5.5 checked the points and wrote the changes; Claude Fable 5.2 ran the tests on the card and wrote this reply.

<!-- greyfinch-sync:ivall/xcl:comment:7307238359 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7307238359). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-01T09:48:36Z. --- Thanks. On the Wine-only list and the tests, at head `76427620`: - **`uma_driver.rs` fences:** not so. Those calls run in `open_uma`, before the device is adopted, so the fence is vkd3d-proton's own. Every other remaining `CreateFence` reaches the runtime only through a Signal / Wait that unwraps the proxy. - **Fixed caps:** right for one of three. The list of native tables dropped a table silently past 64 entries; it now warns once. Of the other two, one falls back to the locked set and the other already warned. vkd3d-proton has 4 and 7 such tables. - **Other threads during a guard, and `is_adopted`:** both true, and neither gives a wrong result: under Wine only lists and allocators get guards, the title may not call one while it is an argument, and Release is pinned; `is_adopted` only picks `orig_fn`, which for an in-place table is the runtime's own entry. - **Tests:** right. `UnadoptGuard::new` and the tests now run the same body, so the Windows CI runs the shipped guard, and the Wine-only test became a case of one that runs everywhere. The Wine branches of `class_for` and `dev_create_fence` stay uncovered off Wine. - **Windows cost:** confirmed as a few atomic or `OnceLock` loads a call, no allocation, and one lock write per new sync-graph cell fence. The suite and the smoke pair on Windows are still owed. - **Found while checking:** `SetEventOnMultipleFenceCompletion` with two or more fences, or `CreateSharedHandle` on a fence, would still hand vkd3d-proton the proxy. Not hooked yet; now in the description. On the split and #3099: the four parts build in the order you give, and under Wine nothing improves before the last. #3099 is the same guard and proxy in an older form against `amd-dev`, without the in-place tables. I will leave which of the two goes forward, and whether to stack this one, to the maintainers and the author of #3099. `cargo test --lib -- fence vtable wine unadopt`, RTX 4060 Ti under Wine: 56 passed, 0 failed. **AI use:** Claude Code. Claude Opus 5.5 checked the points and wrote the changes; Claude Fable 5.2 ran the tests on the card and wrote this reply.
Foniass commented 2026-12-01 09:55:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:55:39Z.


Re-review (head 76427620; the diff from 313f55e8, which I reviewed, read: real.rs +18 / -63). Not a merge-check: PR description is still red.

  • The guard tests now reach the shipped code: fixed. UnadoptGuard::new and the tests share one body, so Windows CI runs the guard that ships. The Wine-only guard test became a case of a test that runs everywhere.
  • The silent cap: fixed. The native-table list warns once past its 64 entries instead of dropping a table without a word.
  • Still open from my first review:
    • no Windows suite run and no smoke pair (the description says "Windows: nothing");
    • the size (997 added lines), and how it could be stacked (create_raw_fence sites / in-place tables / UnadoptGuard / the fence proxy);
    • the overlap with #3099, against amd-dev.
  • The new known gap the description names is worth a test or a hook before merge. SetEventOnMultipleFenceCompletion with two or more fences, or CreateSharedHandle on a fence, would hand vkd3d-proton the proxy.

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

<!-- greyfinch-sync:ivall/xcl:comment:7307411217 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7307411217). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:55:39Z. --- Re-review (head 76427620; the diff from 313f55e8, which I reviewed, read: `real.rs` +18 / -63). Not a merge-check: `PR description` is still red. - **The guard tests now reach the shipped code: fixed.** `UnadoptGuard::new` and the tests share one body, so Windows CI runs the guard that ships. The Wine-only guard test became a case of a test that runs everywhere. - **The silent cap: fixed.** The native-table list warns once past its 64 entries instead of dropping a table without a word. - **Still open from my first review:** - no Windows suite run and no smoke pair (the description says "Windows: nothing"); - the size (997 added lines), and how it could be stacked (`create_raw_fence` sites / in-place tables / `UnadoptGuard` / the fence proxy); - the overlap with #3099, against `amd-dev`. - The new known gap the description names is worth a test or a hook before merge. `SetEventOnMultipleFenceCompletion` with two or more fences, or `CreateSharedHandle` on a fence, would hand vkd3d-proton the proxy. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Royalflamejlh commented 2026-12-01 10:10:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T10:10:39Z.


The gap is closed at head 0797336e: under Wine the device's CreateSharedHandle and SetEventOnMultipleFenceCompletion now unwrap the proxy and hand vkd3d-proton its own fence (one new test, red without either unwrap; tested with stand-in objects, not on a device or in a title). The other paths were checked against vkd3d-proton's source and left: residency calls only ask whether an object is a heap or a resource, EnqueueMakeResident only calls the fence's Signal through its vtable, and OpenSharedHandle returns the runtime's own fence.

cargo test --lib -- fence vtable wine unadopt, RTX 4060 Ti under Wine: 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). The Windows suite and smoke pair are still owed.

AI use: Claude Code. Claude Opus 5.5 wrote the change; Claude Fable 5.2 ran the tests on the card and wrote this reply.

Edited: the first run of that command had one failure, which I had not read when I posted "0 failed"; the counts above are the corrected ones.

<!-- greyfinch-sync:ivall/xcl:comment:7307788080 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7307788080). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-01T10:10:39Z. --- The gap is closed at head `0797336e`: under Wine the device's `CreateSharedHandle` and `SetEventOnMultipleFenceCompletion` now unwrap the proxy and hand vkd3d-proton its own fence (one new test, red without either unwrap; tested with stand-in objects, not on a device or in a title). The other paths were checked against vkd3d-proton's source and left: residency calls only ask whether an object is a heap or a resource, `EnqueueMakeResident` only calls the fence's `Signal` through its vtable, and `OpenSharedHandle` returns the runtime's own fence. `cargo test --lib -- fence vtable wine unadopt`, RTX 4060 Ti under Wine: 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). The Windows suite and smoke pair are still owed. **AI use:** Claude Code. Claude Opus 5.5 wrote the change; Claude Fable 5.2 ran the tests on the card and wrote this reply. Edited: the first run of that command had one failure, which I had not read when I posted "0 failed"; the counts above are the corrected ones.
Foniass commented 2026-12-01 10:13:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:13:16Z.


Follow-up (head 0797336e; the 57-line diff from 76427620 read). The gap is covered: under Wine, device #31 CreateSharedHandle and #45 SetEventOnMultipleFenceCompletion now unwrap a fence proxy before the runtime sees it, and the overrides are added only under under_wine(). The test checks both, with a proxy and a plain object mixed in one array, and that off Wine the proxy passes through unchanged. The other open points from my last comment (a Windows suite run and smoke pair, the size / stack, #3099) stand.

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

<!-- greyfinch-sync:ivall/xcl:comment:7307853533 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7307853533). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T10:13:16Z. --- Follow-up (head 0797336e; the 57-line diff from 76427620 read). The gap is covered: under Wine, device #31 `CreateSharedHandle` and #45 `SetEventOnMultipleFenceCompletion` now unwrap a fence proxy before the runtime sees it, and the overrides are added only under `under_wine()`. The test checks both, with a proxy and a plain object mixed in one array, and that off Wine the proxy passes through unchanged. The other open points from my last comment (a Windows suite run and smoke pair, the size / stack, #3099) stand. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 10:40:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:40:37Z.


Triage (#1607) – head 0797336

Overlaps #3099 (D260): both carry UnadoptGuard, FenceProxy and create_raw_fence for vkd3d-proton's vtable checks under Wine. #3099 targets amd-dev, is a 151-file / 82k-line branch diff and conflicts. This PR targets main, adds #2477's in-place vtables (patch_in_place, in_place_kind), and covers main's newer fence and submit sites (sparse, vram, late_release, cpu_writes, present, title_textures, bind::poll_two_pass_feedback, sparse::pc_execute). For main, this is the one to review.
No problems found in the parts read. The failing check is the PR description check: the smoke pair is still owed. The new top commit 0797336 closes the gap the description listed: under Wine, CreateSharedHandle (#31) and SetEventOnMultipleFenceCompletion (#45) now unwrap fence proxies before calling the runtime, with a test.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7308542782 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7308542782). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T10:40:37Z. --- **Triage (#1607)** – head 0797336 Overlaps #3099 (D260): both carry UnadoptGuard, FenceProxy and create_raw_fence for vkd3d-proton's vtable checks under Wine. #3099 targets `amd-dev`, is a 151-file / 82k-line branch diff and conflicts. This PR targets `main`, adds #2477's in-place vtables (`patch_in_place`, `in_place_kind`), and covers main's newer fence and submit sites (sparse, vram, late_release, cpu_writes, present, title_textures, `bind::poll_two_pass_feedback`, `sparse::pc_execute`). For main, this is the one to review. No problems found in the parts read. The failing check is the PR description check: the smoke pair is still owed. The new top commit 0797336 closes the gap the description listed: under Wine, `CreateSharedHandle` (#31) and `SetEventOnMultipleFenceCompletion` (#45) now unwrap fence proxies before calling the runtime, with a test. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-02 05:26:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-02T05:26:27Z.


merge-check claim
head: 0797336ee0

<!-- greyfinch-sync:ivall/xcl:comment:7335936175 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7335936175). Originally posted by [throny](https://github.com/throny) on 2026-12-02T05:26:27Z. --- merge-check claim head: 0797336ee0c4ef4d24b79f9c65aa5bf1c51fa92d
throny commented 2026-12-02 05:39:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-02T05:39:20Z.


merge-check
base: main 1c8b55147
head: 0797336ee0
merge: trial merge into base is clean (MERGEABLE)
build: cargo build --workspace on the merged tree: OK
tests: cargo test --workspace --no-fail-fast -- --test-threads=4: 2918 passed, 0 failed, 51 ignored; 25 SKIPPED lines (GPU tests that skip); 0 binaries ended abnormally (base 2909 by the other two trees, so +9 tests all pass)
review: Diff read (+1054 -78, 10 files, scan flags only expected unsafe vtable transmutes and VirtualProtect). Earlier review points checked against the head: fence proxy now runs main's fence hooks, queue Signal/Wait overrides and shared-handle / multiple-fence unwrap are under_wine() only, UnadoptGuard shares one body with its test, 9 new tests pass on Windows. Reading shows no Windows behaviour change beyond OnceLock loads per call. Still open from reviews: size (about 1050 lines, reviewers asked for a stack: raw-fence call sites, in-place tables, guard, proxy; the author offered to split), overlap with #3099 (targets amd-dev, one must be chosen), fixed caps (IN_PLACE_MAX 32, 64-entry tables), Wine branches of class_for and dev_create_fence untested off Wine, and the reports under Wine/AMD show the remaining failures (execute_indirect crash, intermittent sparse test at 4 threads) are partly not from this PR. None of the Wine paths were exercised on this Windows machine.
performance: not measured; no xcl-smoke pair on the PR, no retail run here
verdict: not yet: no xcl-smoke pair and no Windows suite run by the author (mine above is green), over the ~800-line limit without a split; the split / #3099 overlap needs the maintainer's decision.
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report

<!-- greyfinch-sync:ivall/xcl:comment:7336156213 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7336156213). Originally posted by [throny](https://github.com/throny) on 2026-12-02T05:39:20Z. --- merge-check base: main 1c8b55147 head: 0797336ee0c4ef4d24b79f9c65aa5bf1c51fa92d merge: trial merge into base is clean (MERGEABLE) build: cargo build --workspace on the merged tree: OK tests: cargo test --workspace --no-fail-fast -- --test-threads=4: 2918 passed, 0 failed, 51 ignored; 25 SKIPPED lines (GPU tests that skip); 0 binaries ended abnormally (base 2909 by the other two trees, so +9 tests all pass) review: Diff read (+1054 -78, 10 files, scan flags only expected unsafe vtable transmutes and VirtualProtect). Earlier review points checked against the head: fence proxy now runs main's fence hooks, queue Signal/Wait overrides and shared-handle / multiple-fence unwrap are under_wine() only, UnadoptGuard shares one body with its test, 9 new tests pass on Windows. Reading shows no Windows behaviour change beyond OnceLock loads per call. Still open from reviews: size (about 1050 lines, reviewers asked for a stack: raw-fence call sites, in-place tables, guard, proxy; the author offered to split), overlap with #3099 (targets amd-dev, one must be chosen), fixed caps (IN_PLACE_MAX 32, 64-entry tables), Wine branches of class_for and dev_create_fence untested off Wine, and the reports under Wine/AMD show the remaining failures (execute_indirect crash, intermittent sparse test at 4 threads) are partly not from this PR. None of the Wine paths were exercised on this Windows machine. performance: not measured; no xcl-smoke pair on the PR, no retail run here verdict: not yet: no xcl-smoke pair and no Windows suite run by the author (mine above is green), over the ~800-line limit without a split; the split / #3099 overlap needs the maintainer's decision. hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report
Royalflamejlh commented 2026-12-02 05:39:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T05:39:54Z.


Thanks for the merge-check. Two of the gaps are closed now: both xcl-smoke blocks for head 0797336e are in Regression run (RTX 5070 Ti, 60 s: main 1,620 frames / 15,476 MB, this head 1,616 / 15,524 MB, no removal), and a whole-suite run on that card at this head is under Tested (2,905 passed, 0 failed, 51 ignored). The size is explained near the top: the fence/guard half and the in-place tables cannot be tested apart on an unpatched vkd3d-proton, because without the tables the first heap ends the process in an assertion. The #3099 overlap is for the maintainer to decide, as you say.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

<!-- greyfinch-sync:ivall/xcl:comment:7336165831 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7336165831). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T05:39:54Z. --- Thanks for the merge-check. Two of the gaps are closed now: both `xcl-smoke` blocks for head `0797336e` are in **Regression run** (RTX 5070 Ti, 60 s: `main` 1,620 frames / 15,476 MB, this head 1,616 / 15,524 MB, no removal), and a whole-suite run on that card at this head is under **Tested** (2,905 passed, 0 failed, 51 ignored). The size is explained near the top: the fence/guard half and the in-place tables cannot be tested apart on an unpatched vkd3d-proton, because without the tables the first heap ends the process in an assertion. The #3099 overlap is for the maintainer to decide, as you say. AI use: Claude Code (Claude Opus 5.5) wrote this reply.
bmjask commented 2026-12-02 08:48:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T08:48:17Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1730

@@ -1472,9 +1727,31 @@ unsafe fn class_for(obj: *mut c_void, orig: usize, kind: Kind) -> usize {
             *e = super::guard::make_before(*e, (i - 1) as u64, super::bind::before_list_call);
         }
     }
+    if in_place {

Patching in place rewrites the runtime's shared vtable, so every object of that class gets XCL's hooks and is_adopted() returns true for it. That includes resources is_own_object deliberately leaves unadopted, objects the runtime creates internally, and objects XCL never adopted. Under Wine, after the first title resource is adopted, an XCL own-work upload buffer or a runtime-internal resource (e.g. a swapchain image) calls Release through res_release. With late_release on, its last reference is held until the queues pass, which leaks memory or makes ResizeBuffers see outstanding references, and its Map goes through res_map too. adopt() now also returns early on is_ext(v), so XCL_DRED's name_for_report never names any later resource or heap. The hooks need to check per object (e.g. a side-table lookup) whether XCL actually adopted it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4766881711 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4766881711). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T08:48:17Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1730 ~~~~diff @@ -1472,9 +1727,31 @@ unsafe fn class_for(obj: *mut c_void, orig: usize, kind: Kind) -> usize { *e = super::guard::make_before(*e, (i - 1) as u64, super::bind::before_list_call); } } + if in_place { ~~~~ --- Patching in place rewrites the runtime's shared vtable, so every object of that class gets XCL's hooks and `is_adopted()` returns true for it. That includes resources `is_own_object` deliberately leaves unadopted, objects the runtime creates internally, and objects XCL never adopted. Under Wine, after the first title resource is adopted, an XCL own-work upload buffer or a runtime-internal resource (e.g. a swapchain image) calls Release through `res_release`. With late_release on, its last reference is held until the queues pass, which leaks memory or makes ResizeBuffers see outstanding references, and its Map goes through `res_map` too. `adopt()` now also returns early on `is_ext(v)`, so XCL_DRED's `name_for_report` never names any later resource or heap. The hooks need to check per object (e.g. a side-table lookup) whether XCL actually adopted it.
bmjask commented 2026-12-02 08:48:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T08:48:17Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1252

@@ -1134,16 +1197,99 @@ pub(super) fn test_command_list_class(orig: usize, ext: usize) -> TestCommandLis
 }
 
 unsafe fn vt(obj: *mut c_void) -> *const usize {
-    *(obj as *const *const usize)
+    (*(obj as *const AtomicUsize)).load(Ordering::Acquire) as *const usize
 }
 
 /// Original function of `slot` for an adopted object.
 pub unsafe fn orig_fn(this: *mut c_void, slot: usize) -> usize {
     let ext = vt(this);
+    if let Some(f) = in_place_original(ext as usize, slot) {
+        return f;
+    }
+    if crate::util::under_wine() && is_known_native(ext as usize) {
+        // Another thread's UnadoptGuard temporarily restored the native vtable on this
+        // shared object (e.g. a pipeline state); `ext` is already the original table.
+        return *ext.add(slot);
+    }
     let orig = *ext.sub(1) as *const usize;
     *orig.add(slot)
 }
 
+// vkd3d-proton takes an object (as `this` of its own methods, or as an argument) only with its own
+// vtable: for heaps, resources, descriptor / query heaps, root signatures, pipeline states and
+// command signatures an assertion, which its release builds keep (the process ends). So under
+// Wine those classes keep their table and XCL's PC slots are written into it (`in_place_kind`), as
+// XAudio2's `patch` does; the entries it had before are kept here for `orig_fn`. Only
+// `class_for`'s Wine branch adds a table, so on Windows the list stays empty and `orig_fn` reads
+// ext[-1] as before.
+
+struct InPlace {
+    table: AtomicUsize,
+    /// the table's first `len` entries before XCL wrote its own
+    saved: AtomicUsize,
+    len: AtomicUsize,
+}
+
+const IN_PLACE_MAX: usize = 32;
+static IN_PLACE: [InPlace; IN_PLACE_MAX] = [const { InPlace { table: AtomicUsize::new(0), saved: AtomicUsize::new(0), len: AtomicUsize::new(0) } }; IN_PLACE_MAX];
+/// entries of `IN_PLACE` in use (published with Release after the entry is written)
+static IN_PLACE_N: AtomicUsize = AtomicUsize::new(0);
+static IN_PLACE_LOCK: Mutex<()> = Mutex::new(());
+
+/// For a vtable patched in place: the runtime's function of `slot` (lock-free: `orig_fn`).
+fn in_place_original(table: usize, slot: usize) -> Option<usize> {
+    let n = IN_PLACE_N.load(Ordering::Acquire);
+    let e = IN_PLACE[..n].iter().find(|e| e.table.load(Ordering::Relaxed) == table)?;
+    let len = e.len.load(Ordering::Relaxed);
+    // SAFETY: `saved` holds `len` entries (leaked); past them the table is the runtime's own
+    Some(unsafe { if slot < len { *(e.saved.load(Ordering::Relaxed) as *const usize).add(slot) } else { *(table as *const usize).add(slot) } })
+}
+
+/// The classes vkd3d-proton checks only by an assertion on their vtable, whose console slots all
+/// 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 {

State objects (Kind::StateObject, adopted through dev_create_state_object) aren't in in_place_kind and never get a guard, so the runtime still receives them with XCL's copied vtable. Under Wine, a DXR title calling SetPipelineState1(stateObject) or GetProperties fails vkd3d-proton's state-object vtable check, the same assertion this PR fixes for pipeline states and root signatures.

<!-- greyfinch-sync:ivall/xcl:review-comment:4766881721 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4766881721). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T08:48:17Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1252 ~~~~diff @@ -1134,16 +1197,99 @@ pub(super) fn test_command_list_class(orig: usize, ext: usize) -> TestCommandLis } unsafe fn vt(obj: *mut c_void) -> *const usize { - *(obj as *const *const usize) + (*(obj as *const AtomicUsize)).load(Ordering::Acquire) as *const usize } /// Original function of `slot` for an adopted object. pub unsafe fn orig_fn(this: *mut c_void, slot: usize) -> usize { let ext = vt(this); + if let Some(f) = in_place_original(ext as usize, slot) { + return f; + } + if crate::util::under_wine() && is_known_native(ext as usize) { + // Another thread's UnadoptGuard temporarily restored the native vtable on this + // shared object (e.g. a pipeline state); `ext` is already the original table. + return *ext.add(slot); + } let orig = *ext.sub(1) as *const usize; *orig.add(slot) } +// vkd3d-proton takes an object (as `this` of its own methods, or as an argument) only with its own +// vtable: for heaps, resources, descriptor / query heaps, root signatures, pipeline states and +// command signatures an assertion, which its release builds keep (the process ends). So under +// Wine those classes keep their table and XCL's PC slots are written into it (`in_place_kind`), as +// XAudio2's `patch` does; the entries it had before are kept here for `orig_fn`. Only +// `class_for`'s Wine branch adds a table, so on Windows the list stays empty and `orig_fn` reads +// ext[-1] as before. + +struct InPlace { + table: AtomicUsize, + /// the table's first `len` entries before XCL wrote its own + saved: AtomicUsize, + len: AtomicUsize, +} + +const IN_PLACE_MAX: usize = 32; +static IN_PLACE: [InPlace; IN_PLACE_MAX] = [const { InPlace { table: AtomicUsize::new(0), saved: AtomicUsize::new(0), len: AtomicUsize::new(0) } }; IN_PLACE_MAX]; +/// entries of `IN_PLACE` in use (published with Release after the entry is written) +static IN_PLACE_N: AtomicUsize = AtomicUsize::new(0); +static IN_PLACE_LOCK: Mutex<()> = Mutex::new(()); + +/// For a vtable patched in place: the runtime's function of `slot` (lock-free: `orig_fn`). +fn in_place_original(table: usize, slot: usize) -> Option<usize> { + let n = IN_PLACE_N.load(Ordering::Acquire); + let e = IN_PLACE[..n].iter().find(|e| e.table.load(Ordering::Relaxed) == table)?; + let len = e.len.load(Ordering::Relaxed); + // SAFETY: `saved` holds `len` entries (leaked); past them the table is the runtime's own + Some(unsafe { if slot < len { *(e.saved.load(Ordering::Relaxed) as *const usize).add(slot) } else { *(table as *const usize).add(slot) } }) +} + +/// The classes vkd3d-proton checks only by an assertion on their vtable, whose console slots all +/// 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 { ~~~~ --- State objects (`Kind::StateObject`, adopted through `dev_create_state_object`) aren't in `in_place_kind` and never get a guard, so the runtime still receives them with XCL's copied vtable. Under Wine, a DXR title calling `SetPipelineState1(stateObject)` or GetProperties fails vkd3d-proton's state-object vtable check, the same assertion this PR fixes for pipeline states and root signatures.
bmjask commented 2026-12-02 08:48:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T08:48:17Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1472

@@ -1299,6 +1446,93 @@ pub(super) unsafe fn readopt(obj: *mut c_void, kind: Kind) {
     *(obj as *mut usize) = class_for(obj, orig, kind);
 }
 
+/// Active `UnadoptGuard` counts per object pointer so concurrent guards on a shared object
+/// (such as a pipeline state, heap, or resource) keep the native vtable installed until the
+/// last guard drops, while pinning a COM reference (`AddRef` before unadopt, hooked `Release`
+/// after restoring the extended vtable) so a concurrent `Release` through the native vtable
+/// cannot drop the refcount to zero and bypass XCL's final-release cleanup (`pso_release`,
+/// `heap_release`, `res_release`, `cl_release`, `alloc_release`).
+static UNADOPTED: Mutex<Option<HashMap<usize, (usize, u32)>>> = Mutex::new(None);
+
+/// Temporarily restores an adopted object's native vtable for a call into `d3d12core.dll`
+/// (vkd3d-proton validates `iface->lpVtbl` on command allocators and command lists).
+pub(crate) struct UnadoptGuard {
+    obj: *mut c_void,
+}
+
+impl UnadoptGuard {
+    pub(crate) unsafe fn new(obj: *mut c_void) -> Option<Self> {
+        if !crate::util::under_wine() || obj.is_null() || (obj as usize) & 7 != 0 || !crate::gpu::shader::readable(obj as usize, 8) {
+            return None;
+        }
+        Self::enter(obj)
+    }
+
+    /// `new` past its Wine and pointer checks.
+    unsafe fn enter(obj: *mut c_void) -> Option<Self> {

UnadoptGuard::enter swaps the object's vtable pointer for every thread, not just the host call it wraps, so while a guard is live other threads see the object as unadopted and skip XCL's hooks and console slots. A pipeline state on the copy-table fallback is guarded in bind_pipeline_exact on thread A. On thread B, bind::held_pso checks is_adopted(p), gets false and returns None, so a deferred draw keeps no reference and the PSO can be freed under it. A title call on B to a console-only slot reads past the native table and crashes.

<!-- greyfinch-sync:ivall/xcl:review-comment:4766881727 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4766881727). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T08:48:17Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1472 ~~~~diff @@ -1299,6 +1446,93 @@ pub(super) unsafe fn readopt(obj: *mut c_void, kind: Kind) { *(obj as *mut usize) = class_for(obj, orig, kind); } +/// Active `UnadoptGuard` counts per object pointer so concurrent guards on a shared object +/// (such as a pipeline state, heap, or resource) keep the native vtable installed until the +/// last guard drops, while pinning a COM reference (`AddRef` before unadopt, hooked `Release` +/// after restoring the extended vtable) so a concurrent `Release` through the native vtable +/// cannot drop the refcount to zero and bypass XCL's final-release cleanup (`pso_release`, +/// `heap_release`, `res_release`, `cl_release`, `alloc_release`). +static UNADOPTED: Mutex<Option<HashMap<usize, (usize, u32)>>> = Mutex::new(None); + +/// Temporarily restores an adopted object's native vtable for a call into `d3d12core.dll` +/// (vkd3d-proton validates `iface->lpVtbl` on command allocators and command lists). +pub(crate) struct UnadoptGuard { + obj: *mut c_void, +} + +impl UnadoptGuard { + pub(crate) unsafe fn new(obj: *mut c_void) -> Option<Self> { + if !crate::util::under_wine() || obj.is_null() || (obj as usize) & 7 != 0 || !crate::gpu::shader::readable(obj as usize, 8) { + return None; + } + Self::enter(obj) + } + + /// `new` past its Wine and pointer checks. + unsafe fn enter(obj: *mut c_void) -> Option<Self> { ~~~~ --- `UnadoptGuard::enter` swaps the object's vtable pointer for every thread, not just the host call it wraps, so while a guard is live other threads see the object as unadopted and skip XCL's hooks and console slots. A pipeline state on the copy-table fallback is guarded in `bind_pipeline_exact` on thread A. On thread B, `bind::held_pso` checks `is_adopted(p)`, gets false and returns None, so a deferred draw keeps no reference and the PSO can be freed under it. A title call on B to a console-only slot reads past the native table and crashes.
bmjask commented 2026-12-02 08:48:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T08:48:17Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1141

@@ -1104,6 +1104,69 @@ struct Class {
 
 static CLASSES: Mutex<Vec<Class>> = Mutex::new(Vec::new());
 static EXTS: Mutex<Option<HashSet<usize>>> = Mutex::new(None);
+const EXT_FAST_CAP: usize = 64;
+static EXT_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP];
+static EXT_FAST_N: AtomicUsize = AtomicUsize::new(0);
+static NATIVE_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP];
+static NATIVE_FAST_N: AtomicUsize = AtomicUsize::new(0);
+static NATIVE_FAST_LOCK: Mutex<()> = Mutex::new(());
+
+fn register_ext(ext: usize) {
+    let mut g = EXTS.lock().unwrap();
+    if g.get_or_insert_with(HashSet::new).insert(ext) {
+        let n = EXT_FAST_N.load(Ordering::Relaxed);
+        if n < EXT_FAST_CAP {
+            EXT_FAST[n].store(ext, Ordering::Relaxed);
+            EXT_FAST_N.store(n + 1, Ordering::Release);
+        }
+    }
+}
+
+fn is_ext_fast(v: usize) -> bool {
+    let n = EXT_FAST_N.load(Ordering::Acquire);
+    for slot in &EXT_FAST[..n.min(EXT_FAST_CAP)] {
+        if slot.load(Ordering::Relaxed) == v {
+            return true;
+        }
+    }
+    n >= EXT_FAST_CAP && is_ext(v)
+}
+
+/// Whether `UnadoptGuard::new` leaves an object whose vtable is `cur` alone: not an extended
+/// vtable, or a runtime table XCL patched in place (its `ext[-1]` is not the native table).
+fn skips_guard(cur: usize) -> bool {
+    !is_ext_fast(cur) || in_place_original(cur, 0).is_some()
+}
+
+fn register_native(orig: usize) {

Not certain about this one: once 64 distinct native vtables have been guarded, register_native only logs a warning. orig_fn on a guarded object whose table wasn't recorded then falls through to *ext.sub(1) on the native table. Under Wine, after the cap (lists, allocators, and the copy-table fallback for pipeline states across interface versions), a thread calling orig_fn while another thread's guard has the native table installed reads the word before vkd3d-proton's vtable and calls through it, which is a crash or a wrong function.

<!-- greyfinch-sync:ivall/xcl:review-comment:4766881734 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4766881734). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T08:48:17Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1141 ~~~~diff @@ -1104,6 +1104,69 @@ struct Class { static CLASSES: Mutex<Vec<Class>> = Mutex::new(Vec::new()); static EXTS: Mutex<Option<HashSet<usize>>> = Mutex::new(None); +const EXT_FAST_CAP: usize = 64; +static EXT_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP]; +static EXT_FAST_N: AtomicUsize = AtomicUsize::new(0); +static NATIVE_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP]; +static NATIVE_FAST_N: AtomicUsize = AtomicUsize::new(0); +static NATIVE_FAST_LOCK: Mutex<()> = Mutex::new(()); + +fn register_ext(ext: usize) { + let mut g = EXTS.lock().unwrap(); + if g.get_or_insert_with(HashSet::new).insert(ext) { + let n = EXT_FAST_N.load(Ordering::Relaxed); + if n < EXT_FAST_CAP { + EXT_FAST[n].store(ext, Ordering::Relaxed); + EXT_FAST_N.store(n + 1, Ordering::Release); + } + } +} + +fn is_ext_fast(v: usize) -> bool { + let n = EXT_FAST_N.load(Ordering::Acquire); + for slot in &EXT_FAST[..n.min(EXT_FAST_CAP)] { + if slot.load(Ordering::Relaxed) == v { + return true; + } + } + n >= EXT_FAST_CAP && is_ext(v) +} + +/// Whether `UnadoptGuard::new` leaves an object whose vtable is `cur` alone: not an extended +/// vtable, or a runtime table XCL patched in place (its `ext[-1]` is not the native table). +fn skips_guard(cur: usize) -> bool { + !is_ext_fast(cur) || in_place_original(cur, 0).is_some() +} + +fn register_native(orig: usize) { ~~~~ --- Not certain about this one: once 64 distinct native vtables have been guarded, `register_native` only logs a warning. `orig_fn` on a guarded object whose table wasn't recorded then falls through to `*ext.sub(1)` on the native table. Under Wine, after the cap (lists, allocators, and the copy-table fallback for pipeline states across interface versions), a thread calling `orig_fn` while another thread's guard has the native table installed reads the word before vkd3d-proton's vtable and calls through it, which is a crash or a wrong function.
bmjask commented 2026-12-02 08:48:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T08:48:17Z.

Review: COMMENTED


Review of 0797336e: 6 finding(s). 4 are inline. These are on lines outside the diff:

crates/xcl/src/hle/d3d12x/real.rs:11908: cl_execute_bundle passes an adopted bundle list (extended vtable) to the runtime's ExecuteBundle without an UnadoptGuard, but ExecuteBundle is one of the native calls that checks a list's lpVtbl. Under Wine, a title bundle created through the adopted device fails vkd3d-proton's bundle-from-iface check (XCL's table instead of d3d12_bundle_vtbl), so its draws are silently dropped or an assertion ends the process. Reset, CreateCommandList and ExecuteCommandLists got the guard.

crates/xcl/src/hle/d3d12x/real.rs:4265: dev_enqueue_make_resident passes the title's fence straight to the runtime without unwrap_fence, unlike CreateSharedHandle and SetEventOnMultipleFenceCompletion. Under Wine, ID3D12Device3::EnqueueMakeResident(..., fence, value) with a fence from CreateFence (now a FenceProxy) hands vkd3d-proton the proxy where it expects its own fence, so its type check asserts or it signals the wrong object and the title waits forever.


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.

<!-- greyfinch-sync:ivall/xcl:review:6147399846 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#pullrequestreview-6147399846). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T08:48:17Z. **Review:** COMMENTED --- Review of `0797336e`: 6 finding(s). 4 are inline. These are on lines outside the diff: **`crates/xcl/src/hle/d3d12x/real.rs:11908`**: `cl_execute_bundle` passes an adopted bundle list (extended vtable) to the runtime's ExecuteBundle without an `UnadoptGuard`, but ExecuteBundle is one of the native calls that checks a list's lpVtbl. Under Wine, a title bundle created through the adopted device fails vkd3d-proton's bundle-from-iface check (XCL's table instead of `d3d12_bundle_vtbl`), so its draws are silently dropped or an assertion ends the process. Reset, CreateCommandList and ExecuteCommandLists got the guard. **`crates/xcl/src/hle/d3d12x/real.rs:4265`**: `dev_enqueue_make_resident` passes the title's fence straight to the runtime without `unwrap_fence`, unlike CreateSharedHandle and SetEventOnMultipleFenceCompletion. Under Wine, `ID3D12Device3::EnqueueMakeResident(..., fence, value)` with a fence from CreateFence (now a FenceProxy) hands vkd3d-proton the proxy where it expects its own fence, so its type check asserts or it signals the wrong object and the title waits forever. --- _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._
bmjask commented 2026-12-02 14:12:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:12:45Z.


@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

<!-- greyfinch-sync:ivall/xcl:comment:7348171313 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7348171313). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T14:12:45Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Royalflamejlh commented 2026-12-02 20:39:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:39:32Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1730

@@ -1472,9 +1727,31 @@ unsafe fn class_for(obj: *mut c_void, orig: usize, kind: Kind) -> usize {
             *e = super::guard::make_before(*e, (i - 1) as u64, super::bind::before_list_call);
         }
     }
+    if in_place {

Right that the patched table belongs to the whole class. Under Wine every object of that class runs XCL's PC slots, adopted or not, and is_adopted is true for all of them. That is #2477's design, and the price of getting past vkd3d-proton's assertion. Here is what it does in the cases named:

  • res_release on a resource XCL never adopted keeps its last reference until the queues pass the work in flight, then releases it (late_release). That is a delay, not a leak. The maps it clears are keyed by address and have no entry for such a resource.
  • A swap-chain buffer: the presenter takes one with GetBuffer each present (present.rs:1500), so its last public reference can be held for a moment. A ResizeBuffers in that moment would fail, and ensure_swapchain runs again at the next present (present.rs:1496). I have not seen this in a run.
  • res_map: console_buffer has no entry for such a resource, and the PC's Map runs as before (real.rs:2623).
  • XCL_DRED names: right. Under Wine, adopt names only the objects made before their class's table is patched (real.rs:1537). It is a debugging aid. I'd leave it to a follow-up rather than grow this PR, which is already over the size limit.

A check per object in every hook is a larger change, and not for this PR.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775711143 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4775711143). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:39:32Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1730 ~~~~diff @@ -1472,9 +1727,31 @@ unsafe fn class_for(obj: *mut c_void, orig: usize, kind: Kind) -> usize { *e = super::guard::make_before(*e, (i - 1) as u64, super::bind::before_list_call); } } + if in_place { ~~~~ --- Right that the patched table belongs to the whole class. Under Wine every object of that class runs XCL's PC slots, adopted or not, and `is_adopted` is true for all of them. That is #2477's design, and the price of getting past vkd3d-proton's assertion. Here is what it does in the cases named: - `res_release` on a resource XCL never adopted keeps its last reference until the queues pass the work in flight, then releases it (`late_release`). That is a delay, not a leak. The maps it clears are keyed by address and have no entry for such a resource. - A swap-chain buffer: the presenter takes one with `GetBuffer` each present (`present.rs:1500`), so its last public reference can be held for a moment. A `ResizeBuffers` in that moment would fail, and `ensure_swapchain` runs again at the next present (`present.rs:1496`). I have not seen this in a run. - `res_map`: `console_buffer` has no entry for such a resource, and the PC's `Map` runs as before (`real.rs:2623`). - `XCL_DRED` names: right. Under Wine, `adopt` names only the objects made before their class's table is patched (`real.rs:1537`). It is a debugging aid. I'd leave it to a follow-up rather than grow this PR, which is already over the size limit. A check per object in every hook is a larger change, and not for this PR.
Royalflamejlh commented 2026-12-02 20:39:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:39:35Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1252

@@ -1134,16 +1197,99 @@ pub(super) fn test_command_list_class(orig: usize, ext: usize) -> TestCommandLis
 }
 
 unsafe fn vt(obj: *mut c_void) -> *const usize {
-    *(obj as *const *const usize)
+    (*(obj as *const AtomicUsize)).load(Ordering::Acquire) as *const usize
 }
 
 /// Original function of `slot` for an adopted object.
 pub unsafe fn orig_fn(this: *mut c_void, slot: usize) -> usize {
     let ext = vt(this);
+    if let Some(f) = in_place_original(ext as usize, slot) {
+        return f;
+    }
+    if crate::util::under_wine() && is_known_native(ext as usize) {
+        // Another thread's UnadoptGuard temporarily restored the native vtable on this
+        // shared object (e.g. a pipeline state); `ext` is already the original table.
+        return *ext.add(slot);
+    }
     let orig = *ext.sub(1) as *const usize;
     *orig.add(slot)
 }
 
+// vkd3d-proton takes an object (as `this` of its own methods, or as an argument) only with its own
+// vtable: for heaps, resources, descriptor / query heaps, root signatures, pipeline states and
+// command signatures an assertion, which its release builds keep (the process ends). So under
+// Wine those classes keep their table and XCL's PC slots are written into it (`in_place_kind`), as
+// XAudio2's `patch` does; the entries it had before are kept here for `orig_fn`. Only
+// `class_for`'s Wine branch adds a table, so on Windows the list stays empty and `orig_fn` reads
+// ext[-1] as before.
+
+struct InPlace {
+    table: AtomicUsize,
+    /// the table's first `len` entries before XCL wrote its own
+    saved: AtomicUsize,
+    len: AtomicUsize,
+}
+
+const IN_PLACE_MAX: usize = 32;
+static IN_PLACE: [InPlace; IN_PLACE_MAX] = [const { InPlace { table: AtomicUsize::new(0), saved: AtomicUsize::new(0), len: AtomicUsize::new(0) } }; IN_PLACE_MAX];
+/// entries of `IN_PLACE` in use (published with Release after the entry is written)
+static IN_PLACE_N: AtomicUsize = AtomicUsize::new(0);
+static IN_PLACE_LOCK: Mutex<()> = Mutex::new(());
+
+/// For a vtable patched in place: the runtime's function of `slot` (lock-free: `orig_fn`).
+fn in_place_original(table: usize, slot: usize) -> Option<usize> {
+    let n = IN_PLACE_N.load(Ordering::Acquire);
+    let e = IN_PLACE[..n].iter().find(|e| e.table.load(Ordering::Relaxed) == table)?;
+    let len = e.len.load(Ordering::Relaxed);
+    // SAFETY: `saved` holds `len` entries (leaked); past them the table is the runtime's own
+    Some(unsafe { if slot < len { *(e.saved.load(Ordering::Relaxed) as *const usize).add(slot) } else { *(table as *const usize).add(slot) } })
+}
+
+/// The classes vkd3d-proton checks only by an assertion on their vtable, whose console slots all
+/// 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 {

Not so on vkd3d-proton: it does not check a state object's table. SetPipelineState1 takes the object with rt_impl_from_ID3D12StateObject, a plain CONTAINING_RECORD (libs/vkd3d/vkd3d_private.h:6533 at 71cae091). GetProperties and QueryInterface go through the title's table to the runtime's. The tables vkd3d-proton compares are those of lists and allocators, bundles and bundle allocators (bundle.c:241, :1925), and the assert-checked classes in in_place_kind. Left as is.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775711868 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4775711868). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:39:35Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1252 ~~~~diff @@ -1134,16 +1197,99 @@ pub(super) fn test_command_list_class(orig: usize, ext: usize) -> TestCommandLis } unsafe fn vt(obj: *mut c_void) -> *const usize { - *(obj as *const *const usize) + (*(obj as *const AtomicUsize)).load(Ordering::Acquire) as *const usize } /// Original function of `slot` for an adopted object. pub unsafe fn orig_fn(this: *mut c_void, slot: usize) -> usize { let ext = vt(this); + if let Some(f) = in_place_original(ext as usize, slot) { + return f; + } + if crate::util::under_wine() && is_known_native(ext as usize) { + // Another thread's UnadoptGuard temporarily restored the native vtable on this + // shared object (e.g. a pipeline state); `ext` is already the original table. + return *ext.add(slot); + } let orig = *ext.sub(1) as *const usize; *orig.add(slot) } +// vkd3d-proton takes an object (as `this` of its own methods, or as an argument) only with its own +// vtable: for heaps, resources, descriptor / query heaps, root signatures, pipeline states and +// command signatures an assertion, which its release builds keep (the process ends). So under +// Wine those classes keep their table and XCL's PC slots are written into it (`in_place_kind`), as +// XAudio2's `patch` does; the entries it had before are kept here for `orig_fn`. Only +// `class_for`'s Wine branch adds a table, so on Windows the list stays empty and `orig_fn` reads +// ext[-1] as before. + +struct InPlace { + table: AtomicUsize, + /// the table's first `len` entries before XCL wrote its own + saved: AtomicUsize, + len: AtomicUsize, +} + +const IN_PLACE_MAX: usize = 32; +static IN_PLACE: [InPlace; IN_PLACE_MAX] = [const { InPlace { table: AtomicUsize::new(0), saved: AtomicUsize::new(0), len: AtomicUsize::new(0) } }; IN_PLACE_MAX]; +/// entries of `IN_PLACE` in use (published with Release after the entry is written) +static IN_PLACE_N: AtomicUsize = AtomicUsize::new(0); +static IN_PLACE_LOCK: Mutex<()> = Mutex::new(()); + +/// For a vtable patched in place: the runtime's function of `slot` (lock-free: `orig_fn`). +fn in_place_original(table: usize, slot: usize) -> Option<usize> { + let n = IN_PLACE_N.load(Ordering::Acquire); + let e = IN_PLACE[..n].iter().find(|e| e.table.load(Ordering::Relaxed) == table)?; + let len = e.len.load(Ordering::Relaxed); + // SAFETY: `saved` holds `len` entries (leaked); past them the table is the runtime's own + Some(unsafe { if slot < len { *(e.saved.load(Ordering::Relaxed) as *const usize).add(slot) } else { *(table as *const usize).add(slot) } }) +} + +/// The classes vkd3d-proton checks only by an assertion on their vtable, whose console slots all +/// 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 { ~~~~ --- Not so on vkd3d-proton: it does not check a state object's table. `SetPipelineState1` takes the object with `rt_impl_from_ID3D12StateObject`, a plain `CONTAINING_RECORD` (`libs/vkd3d/vkd3d_private.h:6533` at `71cae091`). `GetProperties` and `QueryInterface` go through the title's table to the runtime's. The tables vkd3d-proton compares are those of lists and allocators, bundles and bundle allocators (`bundle.c:241`, `:1925`), and the assert-checked classes in `in_place_kind`. Left as is.
Royalflamejlh commented 2026-12-02 20:39:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:39:38Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1472

@@ -1299,6 +1446,93 @@ pub(super) unsafe fn readopt(obj: *mut c_void, kind: Kind) {
     *(obj as *mut usize) = class_for(obj, orig, kind);
 }
 
+/// Active `UnadoptGuard` counts per object pointer so concurrent guards on a shared object
+/// (such as a pipeline state, heap, or resource) keep the native vtable installed until the
+/// last guard drops, while pinning a COM reference (`AddRef` before unadopt, hooked `Release`
+/// after restoring the extended vtable) so a concurrent `Release` through the native vtable
+/// cannot drop the refcount to zero and bypass XCL's final-release cleanup (`pso_release`,
+/// `heap_release`, `res_release`, `cl_release`, `alloc_release`).
+static UNADOPTED: Mutex<Option<HashMap<usize, (usize, u32)>>> = Mutex::new(None);
+
+/// Temporarily restores an adopted object's native vtable for a call into `d3d12core.dll`
+/// (vkd3d-proton validates `iface->lpVtbl` on command allocators and command lists).
+pub(crate) struct UnadoptGuard {
+    obj: *mut c_void,
+}
+
+impl UnadoptGuard {
+    pub(crate) unsafe fn new(obj: *mut c_void) -> Option<Self> {
+        if !crate::util::under_wine() || obj.is_null() || (obj as usize) & 7 != 0 || !crate::gpu::shader::readable(obj as usize, 8) {
+            return None;
+        }
+        Self::enter(obj)
+    }
+
+    /// `new` past its Wine and pointer checks.
+    unsafe fn enter(obj: *mut c_void) -> Option<Self> {

Yes, every thread sees the swap. That only matters for an object two threads use at once. The guard is for lists and allocators, and D3D12 does not let two threads use one of those at once: a second thread on one during its submit or reset is the title's own race. Pipeline states and the other in_place_kind classes are skipped by the guard (skips_guard, real.rs:1137; asserted at real.rs:13341). So the case described needs the copy-table fallback, which is taken only when VirtualProtect fails or past 32 tables. In 250 of our runs under Wine that logged the in-place write, none logged the fallback ("its vtable cannot be written"). Left as is.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775712496 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4775712496). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:39:38Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1472 ~~~~diff @@ -1299,6 +1446,93 @@ pub(super) unsafe fn readopt(obj: *mut c_void, kind: Kind) { *(obj as *mut usize) = class_for(obj, orig, kind); } +/// Active `UnadoptGuard` counts per object pointer so concurrent guards on a shared object +/// (such as a pipeline state, heap, or resource) keep the native vtable installed until the +/// last guard drops, while pinning a COM reference (`AddRef` before unadopt, hooked `Release` +/// after restoring the extended vtable) so a concurrent `Release` through the native vtable +/// cannot drop the refcount to zero and bypass XCL's final-release cleanup (`pso_release`, +/// `heap_release`, `res_release`, `cl_release`, `alloc_release`). +static UNADOPTED: Mutex<Option<HashMap<usize, (usize, u32)>>> = Mutex::new(None); + +/// Temporarily restores an adopted object's native vtable for a call into `d3d12core.dll` +/// (vkd3d-proton validates `iface->lpVtbl` on command allocators and command lists). +pub(crate) struct UnadoptGuard { + obj: *mut c_void, +} + +impl UnadoptGuard { + pub(crate) unsafe fn new(obj: *mut c_void) -> Option<Self> { + if !crate::util::under_wine() || obj.is_null() || (obj as usize) & 7 != 0 || !crate::gpu::shader::readable(obj as usize, 8) { + return None; + } + Self::enter(obj) + } + + /// `new` past its Wine and pointer checks. + unsafe fn enter(obj: *mut c_void) -> Option<Self> { ~~~~ --- Yes, every thread sees the swap. That only matters for an object two threads use at once. The guard is for lists and allocators, and D3D12 does not let two threads use one of those at once: a second thread on one during its submit or reset is the title's own race. Pipeline states and the other `in_place_kind` classes are skipped by the guard (`skips_guard`, `real.rs:1137`; asserted at `real.rs:13341`). So the case described needs the copy-table fallback, which is taken only when `VirtualProtect` fails or past 32 tables. In 250 of our runs under Wine that logged the in-place write, none logged the fallback ("its vtable cannot be written"). Left as is.
Royalflamejlh commented 2026-12-02 20:39:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:39:40Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1141

@@ -1104,6 +1104,69 @@ struct Class {
 
 static CLASSES: Mutex<Vec<Class>> = Mutex::new(Vec::new());
 static EXTS: Mutex<Option<HashSet<usize>>> = Mutex::new(None);
+const EXT_FAST_CAP: usize = 64;
+static EXT_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP];
+static EXT_FAST_N: AtomicUsize = AtomicUsize::new(0);
+static NATIVE_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP];
+static NATIVE_FAST_N: AtomicUsize = AtomicUsize::new(0);
+static NATIVE_FAST_LOCK: Mutex<()> = Mutex::new(());
+
+fn register_ext(ext: usize) {
+    let mut g = EXTS.lock().unwrap();
+    if g.get_or_insert_with(HashSet::new).insert(ext) {
+        let n = EXT_FAST_N.load(Ordering::Relaxed);
+        if n < EXT_FAST_CAP {
+            EXT_FAST[n].store(ext, Ordering::Relaxed);
+            EXT_FAST_N.store(n + 1, Ordering::Release);
+        }
+    }
+}
+
+fn is_ext_fast(v: usize) -> bool {
+    let n = EXT_FAST_N.load(Ordering::Acquire);
+    for slot in &EXT_FAST[..n.min(EXT_FAST_CAP)] {
+        if slot.load(Ordering::Relaxed) == v {
+            return true;
+        }
+    }
+    n >= EXT_FAST_CAP && is_ext(v)
+}
+
+/// Whether `UnadoptGuard::new` leaves an object whose vtable is `cur` alone: not an extended
+/// vtable, or a runtime table XCL patched in place (its `ext[-1]` is not the native table).
+fn skips_guard(cur: usize) -> bool {
+    !is_ext_fast(cur) || in_place_original(cur, 0).is_some()
+}
+
+fn register_native(orig: usize) {

The 64 count distinct native tables, not objects. vkd3d-proton has one table per class: lists, bundles, allocators, bundle allocators, and a fallback class when one happens. A run registers a handful. In those 250 runs the warning ("more than 64 native vtables") was never logged. Left as is: the warning says when it happens.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775712944 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4775712944). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:39:40Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1141 ~~~~diff @@ -1104,6 +1104,69 @@ struct Class { static CLASSES: Mutex<Vec<Class>> = Mutex::new(Vec::new()); static EXTS: Mutex<Option<HashSet<usize>>> = Mutex::new(None); +const EXT_FAST_CAP: usize = 64; +static EXT_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP]; +static EXT_FAST_N: AtomicUsize = AtomicUsize::new(0); +static NATIVE_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP]; +static NATIVE_FAST_N: AtomicUsize = AtomicUsize::new(0); +static NATIVE_FAST_LOCK: Mutex<()> = Mutex::new(()); + +fn register_ext(ext: usize) { + let mut g = EXTS.lock().unwrap(); + if g.get_or_insert_with(HashSet::new).insert(ext) { + let n = EXT_FAST_N.load(Ordering::Relaxed); + if n < EXT_FAST_CAP { + EXT_FAST[n].store(ext, Ordering::Relaxed); + EXT_FAST_N.store(n + 1, Ordering::Release); + } + } +} + +fn is_ext_fast(v: usize) -> bool { + let n = EXT_FAST_N.load(Ordering::Acquire); + for slot in &EXT_FAST[..n.min(EXT_FAST_CAP)] { + if slot.load(Ordering::Relaxed) == v { + return true; + } + } + n >= EXT_FAST_CAP && is_ext(v) +} + +/// Whether `UnadoptGuard::new` leaves an object whose vtable is `cur` alone: not an extended +/// vtable, or a runtime table XCL patched in place (its `ext[-1]` is not the native table). +fn skips_guard(cur: usize) -> bool { + !is_ext_fast(cur) || in_place_original(cur, 0).is_some() +} + +fn register_native(orig: usize) { ~~~~ --- The 64 count distinct native tables, not objects. vkd3d-proton has one table per class: lists, bundles, allocators, bundle allocators, and a fallback class when one happens. A run registers a handful. In those 250 runs the warning ("more than 64 native vtables") was never logged. Left as is: the warning says when it happens.
Royalflamejlh commented 2026-12-02 20:39:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:39:43Z.


On the two points outside the diff, at head 2791e80c:

  • cl_execute_bundle without a guard: right. vkd3d-proton's d3d12_bundle_from_iface compares the table (bundle.c:1925 at 71cae091), returns NULL for XCL's, and ExecuteBundle drops the bundle with a warning. The bundle now gets its native table back for that call (real.rs:11939). New test a_bundle_reaches_execute_bundle_with_its_native_table_only_under_wine, red without it.
  • dev_enqueue_make_resident and the fence proxy: not so. vkd3d-proton's EnqueueMakeResident signals the fence through its own table, ID3D12Fence_Signal(fence_to_signal, value) (libs/vkd3d/device.c:7116 at 71cae091), with no type check. On a proxy, that call is the proxy's Signal, which runs XCL's hook on the runtime's fence. Left as is.

The four inline points are answered in their threads.

<!-- greyfinch-sync:ivall/xcl:comment:7358105295 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7358105295). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:39:43Z. --- On the two points outside the diff, at head `2791e80c`: - **`cl_execute_bundle` without a guard:** right. vkd3d-proton's `d3d12_bundle_from_iface` compares the table (`bundle.c:1925` at `71cae091`), returns NULL for XCL's, and `ExecuteBundle` drops the bundle with a warning. The bundle now gets its native table back for that call (`real.rs:11939`). New test `a_bundle_reaches_execute_bundle_with_its_native_table_only_under_wine`, red without it. - **`dev_enqueue_make_resident` and the fence proxy:** not so. vkd3d-proton's `EnqueueMakeResident` signals the fence through its own table, `ID3D12Fence_Signal(fence_to_signal, value)` (`libs/vkd3d/device.c:7116` at `71cae091`), with no type check. On a proxy, that call is the proxy's Signal, which runs XCL's hook on the runtime's fence. Left as is. The four inline points are answered in their threads.
bmjask commented 2026-12-02 20:54:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:54:37Z.

Review: COMMENTED


Review of 2791e80c: 6 finding(s) (2 high, 4 medium), most severe first.

  1. High crates/xcl/src/hle/d3d12x/real.rs:1732: Under Wine, the in-place patch writes XCL's Resource/Heap/PSO/DescriptorHeap hooks into the runtime's shared vtable and registers it as an ext (register_ext(orig)), so every object of those classes, including XCL's own-work buffers and.... (inline)
  2. High crates/xcl/src/hle/d3d12x/real.rs:11915: UnadoptGuard replaces the shared object's vtable pointer for every thread, not just the caller, so while a guard is held other threads see is_adopted(obj) == false, bypass XCL hooks, and slot_of(obj, ..) panics with 'adopted class'.... (inline)
  3. Medium crates/xcl/src/hle/d3d12x/real.rs:5251: Under Wine, create_raw_fence skips the hooked dev_create_fence, so XCL's internal fences (sparse, vram, title_textures, cpu_writes, late_release, alloc_pool, present, copy_scratch) are no longer in FENCES and end_title no longer si.... (inline)
  4. Medium crates/xcl/src/hle/d3d12x/list_x.rs:2340: see below.
  5. Medium crates/xcl/src/hle/d3d12x/real.rs:4265: see below.
  6. Medium crates/xcl/src/hle/d3d12x/real.rs:4290: dev_set_event_on_multiple_fence_completion reads *fences.add(i) for n > 0 without checking fences for null, so under Wine a call with n=1 and fences=NULL (which the runtime rejects with E_INVALIDARG) now takes an access violation.... (inline)

On lines outside the diff:

  1. Medium crates/xcl/src/hle/d3d12x/list_x.rs:2340: Several internal fence sites weren't converted to create_raw_fence (list_x::note_submitted, console_heap.rs:244, gpu_awake.rs:297, uma_driver.rs:529/627, real.rs:593), so under Wine they get a FenceProxy that's added to FENCES with an extra reference. note_submitted creates one proxied progress fence per queue and gpu_awake one per state, each leaking a proxy plus a pinned reference. Any of them signalled through q.Signal on a non-adopted queue (e.g. from a non-adopted device, as in the shared-device tests) reaches vkd3d-proton as a proxy and hits its fence vtable assertion, the failure this PR fixes elsewhere.

  2. Medium crates/xcl/src/hle/d3d12x/real.rs:4265: Not certain about this one, because it depends on how vkd3d-proton resolves the fence argument: dev_enqueue_make_resident still passes the title's fence pointer straight through, and under Wine that's now a FenceProxy, unlike CreateSharedHandle and SetEventOnMultipleFenceCompletion, which unwrap it. If vkd3d-proton resolves fence_to_signal with impl_from/unsafe_impl_from rather than a COM call, its vtable assertion fires or it reads the 16-byte proxy as a d3d12_fence. unwrap_fence(fence), as in the sibling hooks, 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.

<!-- greyfinch-sync:ivall/xcl:review:6158842382 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#pullrequestreview-6158842382). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T20:54:37Z. **Review:** COMMENTED --- Review of `2791e80c`: 6 finding(s) (2 high, 4 medium), most severe first. 1. **High** `crates/xcl/src/hle/d3d12x/real.rs:1732`: Under Wine, the in-place patch writes XCL's Resource/Heap/PSO/DescriptorHeap hooks into the runtime's shared vtable and registers it as an ext (`register_ext(orig)`), so every object of those classes, including XCL's own-work buffers and.... (inline) 2. **High** `crates/xcl/src/hle/d3d12x/real.rs:11915`: `UnadoptGuard` replaces the shared object's vtable pointer for every thread, not just the caller, so while a guard is held other threads see `is_adopted(obj) == false`, bypass XCL hooks, and `slot_of(obj, ..)` panics with 'adopted class'.... (inline) 3. **Medium** `crates/xcl/src/hle/d3d12x/real.rs:5251`: Under Wine, `create_raw_fence` skips the hooked `dev_create_fence`, so XCL's internal fences (sparse, vram, title_textures, cpu_writes, late_release, alloc_pool, present, copy_scratch) are no longer in FENCES and `end_title` no longer si.... (inline) 4. **Medium** `crates/xcl/src/hle/d3d12x/list_x.rs:2340`: see below. 5. **Medium** `crates/xcl/src/hle/d3d12x/real.rs:4265`: see below. 6. **Medium** `crates/xcl/src/hle/d3d12x/real.rs:4290`: `dev_set_event_on_multiple_fence_completion` reads `*fences.add(i)` for `n > 0` without checking `fences` for null, so under Wine a call with n=1 and fences=NULL (which the runtime rejects with E_INVALIDARG) now takes an access violation.... (inline) **On lines outside the diff:** 4. **Medium** `crates/xcl/src/hle/d3d12x/list_x.rs:2340`: Several internal fence sites weren't converted to `create_raw_fence` (`list_x::note_submitted`, console_heap.rs:244, gpu_awake.rs:297, uma_driver.rs:529/627, real.rs:593), so under Wine they get a FenceProxy that's added to FENCES with an extra reference. `note_submitted` creates one proxied progress fence per queue and gpu_awake one per state, each leaking a proxy plus a pinned reference. Any of them signalled through `q.Signal` on a non-adopted queue (e.g. from a non-adopted device, as in the shared-device tests) reaches vkd3d-proton as a proxy and hits its fence vtable assertion, the failure this PR fixes elsewhere. 5. **Medium** `crates/xcl/src/hle/d3d12x/real.rs:4265`: Not certain about this one, because it depends on how vkd3d-proton resolves the fence argument: `dev_enqueue_make_resident` still passes the title's fence pointer straight through, and under Wine that's now a FenceProxy, unlike CreateSharedHandle and SetEventOnMultipleFenceCompletion, which unwrap it. If vkd3d-proton resolves `fence_to_signal` with `impl_from`/`unsafe_impl_from` rather than a COM call, its vtable assertion fires or it reads the 16-byte proxy as a `d3d12_fence`. `unwrap_fence(fence)`, as in the sibling hooks, 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._
bmjask commented 2026-12-02 20:54:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:54:37Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1732

@@ -1472,9 +1727,31 @@ unsafe fn class_for(obj: *mut c_void, orig: usize, kind: Kind) -> usize {
             *e = super::guard::make_before(*e, (i - 1) as u64, super::bind::before_list_call);
         }
     }
+    if in_place {
+        let register = || {
+            register_ext(orig);

High: Under Wine, the in-place patch writes XCL's Resource/Heap/PSO/DescriptorHeap hooks into the runtime's shared vtable and registers it as an ext (register_ext(orig)), so every object of those classes, including XCL's own-work buffers and DXGI/vkd3d-internal resources, runs res_release, res_map and the other hooks and reports is_adopted() == true, which defeats is_own_object. An own-work upload buffer, or a swapchain back buffer released by the DXGI layer through the COM vtable, now goes through res_release: it takes vram::lock_tracked_srv_lifetime(), AddRefs/Releases on every call, and on the last reference may be held by late_release. Frees are delayed, ResizeBuffers can fail with outstanding back-buffer references, and Release calls from inside the runtime now take XCL's locks (a deadlock risk). Checking the object against XCL's own/runtime-internal objects inside the patched hooks (or keeping those classes out of the in-place patch) would restore the split.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775912233 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4775912233). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T20:54:37Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1732 ~~~~diff @@ -1472,9 +1727,31 @@ unsafe fn class_for(obj: *mut c_void, orig: usize, kind: Kind) -> usize { *e = super::guard::make_before(*e, (i - 1) as u64, super::bind::before_list_call); } } + if in_place { + let register = || { + register_ext(orig); ~~~~ --- **High**: Under Wine, the in-place patch writes XCL's Resource/Heap/PSO/DescriptorHeap hooks into the runtime's shared vtable and registers it as an ext (`register_ext(orig)`), so every object of those classes, including XCL's own-work buffers and DXGI/vkd3d-internal resources, runs `res_release`, `res_map` and the other hooks and reports `is_adopted() == true`, which defeats `is_own_object`. An own-work upload buffer, or a swapchain back buffer released by the DXGI layer through the COM vtable, now goes through `res_release`: it takes `vram::lock_tracked_srv_lifetime()`, AddRefs/Releases on every call, and on the last reference may be held by `late_release`. Frees are delayed, ResizeBuffers can fail with outstanding back-buffer references, and Release calls from inside the runtime now take XCL's locks (a deadlock risk). Checking the object against XCL's own/runtime-internal objects inside the patched hooks (or keeping those classes out of the in-place patch) would restore the split.
bmjask commented 2026-12-02 20:54:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:54:37Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 11915

@@ -11457,7 +11911,10 @@ unsafe extern "system" fn cl_om_set_render_targets(this: *mut c_void, n: u32, rt
 pub(super) unsafe fn bind_pipeline_exact(this: *mut c_void, original: usize, raw: usize) {
     type F = unsafe extern "system" fn(*mut c_void, *mut c_void);
     let f: F = std::mem::transmute(orig_fn(this, slot!(this, "SetPipelineState")));
-    f(this, raw as *mut c_void);
+    {
+        let _pso_guard = UnadoptGuard::new(raw as *mut c_void);

High: UnadoptGuard replaces the shared object's vtable pointer for every thread, not just the caller, so while a guard is held other threads see is_adopted(obj) == false, bypass XCL hooks, and slot_of(obj, ..) panics with 'adopted class' because the native table isn't in CLASSES. If thread A holds _alloc_guard (cl_reset / reset_list) or _pso_guard (fallback PSO) while thread B uses the same object, bind::held_pso returns None so a deferred draw holds no PSO reference, pc_heap_desc/pc_fn take the non-adopted branch, and a first-time slot!/slot_of on that object hits .expect("adopted class") and aborts. Only orig_fn knows about native tables. Calling the native function through the original table instead of swapping the object's vtable would avoid the cross-thread window.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775912254 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4775912254). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T20:54:37Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 11915 ~~~~diff @@ -11457,7 +11911,10 @@ unsafe extern "system" fn cl_om_set_render_targets(this: *mut c_void, n: u32, rt pub(super) unsafe fn bind_pipeline_exact(this: *mut c_void, original: usize, raw: usize) { type F = unsafe extern "system" fn(*mut c_void, *mut c_void); let f: F = std::mem::transmute(orig_fn(this, slot!(this, "SetPipelineState"))); - f(this, raw as *mut c_void); + { + let _pso_guard = UnadoptGuard::new(raw as *mut c_void); ~~~~ --- **High**: `UnadoptGuard` replaces the shared object's vtable pointer for every thread, not just the caller, so while a guard is held other threads see `is_adopted(obj) == false`, bypass XCL hooks, and `slot_of(obj, ..)` panics with 'adopted class' because the native table isn't in CLASSES. If thread A holds `_alloc_guard` (cl_reset / reset_list) or `_pso_guard` (fallback PSO) while thread B uses the same object, `bind::held_pso` returns None so a deferred draw holds no PSO reference, `pc_heap_desc`/`pc_fn` take the non-adopted branch, and a first-time `slot!`/`slot_of` on that object hits `.expect("adopted class")` and aborts. Only `orig_fn` knows about native tables. Calling the native function through the original table instead of swapping the object's vtable would avoid the cross-thread window.
bmjask commented 2026-12-02 20:54:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:54:37Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 5251

@@ -4839,6 +5156,126 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 {
 }
 creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]);
 
+/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying
+/// fence's native `lpVtbl` stays intact (`vkd3d-proton` compares `fence->lpVtbl` against
+/// `&d3d12_fence_vtbl` in `CommandQueue::Signal` / `Wait` and on its queue thread).
+#[repr(C)]
+struct FenceProxy {
+    vt: usize,
+    pc: *mut c_void,
+}
+
+static FENCE_PROXY_VT: std::sync::OnceLock<usize> = std::sync::OnceLock::new();
+
+fn fence_proxy_vtable() -> usize {
+    *FENCE_PROXY_VT.get_or_init(|| {
+        const SLOTS: usize = 32;
+        let mut v = vec![0usize; SLOTS];
+        for slot in 0..12 {
+            // mov rcx, [rcx + 8]; mov rax, [rcx]; jmp [rax + slot * 8]
+            let mut c = vec![0x48u8, 0x8B, 0x49, 0x08, 0x48, 0x8B, 0x01, 0xFF, 0xA0];
+            c.extend_from_slice(&((slot * 8) as u32).to_le_bytes());
+            let p = crate::stubs::alloc_code(c.len());
+            unsafe { std::ptr::copy_nonoverlapping(c.as_ptr(), p, c.len()) };
+            v[slot] = p as usize;
+        }
+        v[0] = fence_proxy_qi as usize;
+        v[2] = fence_proxy_release as usize;
+        v[8] = fence_get_completed_value as usize;
+        v[9] = fence_set_event_on_completion as usize;
+        v[10] = fence_signal as usize;
+        v[12] = super::fence_x::completed_value_address as usize;
+        for slot in 13..SLOTS {
+            let (addr, _) = stubs::make_stub_info(DLL, &format!("ID3D12Fence1::#{slot} (not on PC)"), 0);
+            v[slot] = addr;
+        }
+        Box::leak(v.into_boxed_slice()).as_ptr() as usize
+    })
+}
+
+unsafe extern "system" fn fence_proxy_qi(this: *mut c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT {
+    let pc = (*(this as *const FenceProxy)).pc;
+    let f: QiFn = std::mem::transmute(*vt(pc));
+    let hr = f(pc, riid, ppv);
+    if hr >= 0 && !ppv.is_null() && *ppv == pc {
+        *ppv = this;
+    } else if hr == E_NOINTERFACE && !riid.is_null() {
+        let s = layout::guid_string(&*riid);
+        if UNKNOWN_IIDS.lock().unwrap().insert(s.clone()) {
+            crate::xlog_warn!("D3D12.X: QueryInterface({s}) – interface unknown on the PC (console-only?)");
+        }
+    }
+    hr
+}
+
+unsafe extern "system" fn fence_proxy_release(this: *mut c_void) -> u32 {
+    let pc = (*(this as *const FenceProxy)).pc;
+    let f: RefFn = std::mem::transmute(*vt(pc).add(2));
+    let n = f(pc);
+    if n == 0 {
+        drop(Box::from_raw(this as *mut FenceProxy));
+    }
+    n
+}
+
+/// The fence a fence hook calls and its PC method `slot`: the runtime's fence behind a proxy, or
+/// the adopted fence's original.
+unsafe fn fence_pc_fn(this: *mut c_void, slot: usize) -> (*mut c_void, usize) {
+    if FENCE_PROXY_VT.get() == Some(&(vt(this) as usize)) {
+        let pc = (*(this as *const FenceProxy)).pc;
+        return (pc, *vt(pc).add(slot));
+    }
+    (this, orig_fn(this, slot))
+}
+
+unsafe fn wrap_fence_proxy(pc: *mut c_void) -> *mut c_void {
+    Box::into_raw(Box::new(FenceProxy { vt: fence_proxy_vtable(), pc })) as *mut c_void
+}
+
+unsafe fn unwrap_fence(p: *mut c_void) -> *mut c_void {
+    if crate::util::under_wine() { unwrap_fence_proxy(p) } else { p }
+}
+
+unsafe fn unwrap_fence_proxy(p: *mut c_void) -> *mut c_void {
+    if !p.is_null() && crate::gpu::shader::readable(p as usize, 16) && *(p as *const usize) == fence_proxy_vtable() {
+        (*(p as *const FenceProxy)).pc
+    } else {
+        p
+    }
+}
+
+/// Create an un-adopted, un-proxied `ID3D12Fence` for XCL's own internal queue tracking
+/// (`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> {

Medium: Under Wine, create_raw_fence skips the hooked dev_create_fence, so XCL's internal fences (sparse, vram, title_textures, cpu_writes, late_release, alloc_pool, present, copy_scratch) are no longer in FENCES and end_title no longer signals them to u64::MAX. Only the list_x cell fences are re-added through track_end_title_fence. If a title or internal queue is blocked in a GPU Wait on one of these and the thread that would signal it is suspended or stuck, drain_gpu waits until the 15 s watchdog kills the process, the case the cell-fence special case was added for. Tracking every raw fence for end_title would cover them all.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775912280 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4775912280). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T20:54:37Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 5251 ~~~~diff @@ -4839,6 +5156,126 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 { } creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]); +/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying +/// fence's native `lpVtbl` stays intact (`vkd3d-proton` compares `fence->lpVtbl` against +/// `&d3d12_fence_vtbl` in `CommandQueue::Signal` / `Wait` and on its queue thread). +#[repr(C)] +struct FenceProxy { + vt: usize, + pc: *mut c_void, +} + +static FENCE_PROXY_VT: std::sync::OnceLock<usize> = std::sync::OnceLock::new(); + +fn fence_proxy_vtable() -> usize { + *FENCE_PROXY_VT.get_or_init(|| { + const SLOTS: usize = 32; + let mut v = vec![0usize; SLOTS]; + for slot in 0..12 { + // mov rcx, [rcx + 8]; mov rax, [rcx]; jmp [rax + slot * 8] + let mut c = vec![0x48u8, 0x8B, 0x49, 0x08, 0x48, 0x8B, 0x01, 0xFF, 0xA0]; + c.extend_from_slice(&((slot * 8) as u32).to_le_bytes()); + let p = crate::stubs::alloc_code(c.len()); + unsafe { std::ptr::copy_nonoverlapping(c.as_ptr(), p, c.len()) }; + v[slot] = p as usize; + } + v[0] = fence_proxy_qi as usize; + v[2] = fence_proxy_release as usize; + v[8] = fence_get_completed_value as usize; + v[9] = fence_set_event_on_completion as usize; + v[10] = fence_signal as usize; + v[12] = super::fence_x::completed_value_address as usize; + for slot in 13..SLOTS { + let (addr, _) = stubs::make_stub_info(DLL, &format!("ID3D12Fence1::#{slot} (not on PC)"), 0); + v[slot] = addr; + } + Box::leak(v.into_boxed_slice()).as_ptr() as usize + }) +} + +unsafe extern "system" fn fence_proxy_qi(this: *mut c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + let pc = (*(this as *const FenceProxy)).pc; + let f: QiFn = std::mem::transmute(*vt(pc)); + let hr = f(pc, riid, ppv); + if hr >= 0 && !ppv.is_null() && *ppv == pc { + *ppv = this; + } else if hr == E_NOINTERFACE && !riid.is_null() { + let s = layout::guid_string(&*riid); + if UNKNOWN_IIDS.lock().unwrap().insert(s.clone()) { + crate::xlog_warn!("D3D12.X: QueryInterface({s}) – interface unknown on the PC (console-only?)"); + } + } + hr +} + +unsafe extern "system" fn fence_proxy_release(this: *mut c_void) -> u32 { + let pc = (*(this as *const FenceProxy)).pc; + let f: RefFn = std::mem::transmute(*vt(pc).add(2)); + let n = f(pc); + if n == 0 { + drop(Box::from_raw(this as *mut FenceProxy)); + } + n +} + +/// The fence a fence hook calls and its PC method `slot`: the runtime's fence behind a proxy, or +/// the adopted fence's original. +unsafe fn fence_pc_fn(this: *mut c_void, slot: usize) -> (*mut c_void, usize) { + if FENCE_PROXY_VT.get() == Some(&(vt(this) as usize)) { + let pc = (*(this as *const FenceProxy)).pc; + return (pc, *vt(pc).add(slot)); + } + (this, orig_fn(this, slot)) +} + +unsafe fn wrap_fence_proxy(pc: *mut c_void) -> *mut c_void { + Box::into_raw(Box::new(FenceProxy { vt: fence_proxy_vtable(), pc })) as *mut c_void +} + +unsafe fn unwrap_fence(p: *mut c_void) -> *mut c_void { + if crate::util::under_wine() { unwrap_fence_proxy(p) } else { p } +} + +unsafe fn unwrap_fence_proxy(p: *mut c_void) -> *mut c_void { + if !p.is_null() && crate::gpu::shader::readable(p as usize, 16) && *(p as *const usize) == fence_proxy_vtable() { + (*(p as *const FenceProxy)).pc + } else { + p + } +} + +/// Create an un-adopted, un-proxied `ID3D12Fence` for XCL's own internal queue tracking +/// (`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> { ~~~~ --- **Medium**: Under Wine, `create_raw_fence` skips the hooked `dev_create_fence`, so XCL's internal fences (sparse, vram, title_textures, cpu_writes, late_release, alloc_pool, present, copy_scratch) are no longer in FENCES and `end_title` no longer signals them to `u64::MAX`. Only the list_x cell fences are re-added through `track_end_title_fence`. If a title or internal queue is blocked in a GPU Wait on one of these and the thread that would signal it is suspended or stuck, `drain_gpu` waits until the 15 s watchdog kills the process, the case the cell-fence special case was added for. Tracking every raw fence for `end_title` would cover them all.
bmjask commented 2026-12-02 20:54:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:54:37Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 4290

@@ -3999,6 +4276,21 @@ unsafe extern "system" fn dev_enqueue_make_resident(
     f(this, flags, n, objects, fence, value)
 }
 
+/// device #31 CreateSharedHandle (Wine): the runtime gets its own fence, not the title's proxy
+unsafe extern "system" fn dev_create_shared_handle(this: *mut c_void, object: *mut c_void, attributes: *const c_void, access: u32, name: *const u16, handle: *mut *mut c_void) -> HRESULT {
+    let f: unsafe extern "system" fn(*mut c_void, *mut c_void, *const c_void, u32, *const u16, *mut *mut c_void) -> HRESULT =
+        std::mem::transmute(orig_fn(this, pc_slot!("ID3D12Device", "CreateSharedHandle")));
+    f(this, unwrap_fence(object), attributes, access, name, handle)
+}
+
+/// device #45 SetEventOnMultipleFenceCompletion (Wine): the runtime gets its own fences, not the title's proxies
+unsafe extern "system" fn dev_set_event_on_multiple_fence_completion(this: *mut c_void, fences: *const *mut c_void, values: *const u64, n: u32, flags: u32, event: *mut c_void) -> HRESULT {
+    let f: unsafe extern "system" fn(*mut c_void, *const *mut c_void, *const u64, u32, u32, *mut c_void) -> HRESULT =
+        std::mem::transmute(orig_fn(this, pc_slot!("ID3D12Device1", "SetEventOnMultipleFenceCompletion")));
+    let pc: Vec<*mut c_void> = (0..n as usize).map(|i| unwrap_fence(*fences.add(i))).collect();

Medium: dev_set_event_on_multiple_fence_completion reads *fences.add(i) for n > 0 without checking fences for null, so under Wine a call with n=1 and fences=NULL (which the runtime rejects with E_INVALIDARG) now takes an access violation inside XCL's hook. Returning E_INVALIDARG for a null array would match the runtime.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775912293 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4775912293). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T20:54:37Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 4290 ~~~~diff @@ -3999,6 +4276,21 @@ unsafe extern "system" fn dev_enqueue_make_resident( f(this, flags, n, objects, fence, value) } +/// device #31 CreateSharedHandle (Wine): the runtime gets its own fence, not the title's proxy +unsafe extern "system" fn dev_create_shared_handle(this: *mut c_void, object: *mut c_void, attributes: *const c_void, access: u32, name: *const u16, handle: *mut *mut c_void) -> HRESULT { + let f: unsafe extern "system" fn(*mut c_void, *mut c_void, *const c_void, u32, *const u16, *mut *mut c_void) -> HRESULT = + std::mem::transmute(orig_fn(this, pc_slot!("ID3D12Device", "CreateSharedHandle"))); + f(this, unwrap_fence(object), attributes, access, name, handle) +} + +/// device #45 SetEventOnMultipleFenceCompletion (Wine): the runtime gets its own fences, not the title's proxies +unsafe extern "system" fn dev_set_event_on_multiple_fence_completion(this: *mut c_void, fences: *const *mut c_void, values: *const u64, n: u32, flags: u32, event: *mut c_void) -> HRESULT { + let f: unsafe extern "system" fn(*mut c_void, *const *mut c_void, *const u64, u32, u32, *mut c_void) -> HRESULT = + std::mem::transmute(orig_fn(this, pc_slot!("ID3D12Device1", "SetEventOnMultipleFenceCompletion"))); + let pc: Vec<*mut c_void> = (0..n as usize).map(|i| unwrap_fence(*fences.add(i))).collect(); ~~~~ --- **Medium**: `dev_set_event_on_multiple_fence_completion` reads `*fences.add(i)` for `n > 0` without checking `fences` for null, so under Wine a call with n=1 and fences=NULL (which the runtime rejects with E_INVALIDARG) now takes an access violation inside XCL's hook. Returning E_INVALIDARG for a null array would match the runtime.
Foniass commented 2026-12-02 21:01:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:01:12Z.


Follow-up review of 2791e80c, since 0797336 (code reading only, not a merge-check; PR description red) · 1 high, 2 medium

In short: The PR keeps vkd3d-proton's own vtables under Wine and wraps the title's fences. Since 0797336e it was rebased onto 5ad98adb, and the one real change is an UnadoptGuard on the bundle in cl_execute_bundle, with a test. That guard is only on the path for callers that are not the title. A title's ExecuteBundle goes through the console slot in list_x and still hands vkd3d-proton the adopted bundle. The smoke pair names 0797336e, not this head, which is why PR description is red.

High

  1. The title's ExecuteBundle misses the new guard.

    • For command lists, console slot 27 is make_split(l::execute_bundle, cl_execute_bundle) (real.rs ~1938, ~1684). Calls from the game image go to list_x::execute_bundle (list_x.rs ~1266), which calls the runtime through pc(this, 27) with no guard.
    • Only callers outside the title reach cl_execute_bundle (real.rs ~11939), where the guard was added. So the case the commit message describes still happens on the path titles take.
    • The new test a_bundle_reaches_execute_bundle_with_its_native_table_only_under_wine (~15834) calls cl_execute_bundle directly and cannot catch it.

    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). Not tested mentions "one whole-suite run" on Windows, but Tested gives no counts for it, which CONTRIBUTING.md item 2 asks for.
  2. Size (still open). It is +1085/-78 in one commit. The reason given is about testing on Wine, not about review. 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: under Wine, title fences run XCL's GetCompletedValue / SetEventOnCompletion / Signal hooks on the runtime's fence (fence_pc_fn, real.rs ~5223).
  • Earlier finding fixed: the queue Signal / Wait overrides and the device's CreateSharedHandle / SetEventOnMultipleFenceCompletion unwrapping are added only under under_wine().
  • Earlier finding fixed: UnadoptGuard::new returns early when not under Wine, and enter checks skips_guard before taking the lock (~1463-1480).
  • Earlier finding fixed: the guard tests run the shipped UnadoptGuard body, and the native-table list warns past its 64 entries.
  • Earlier finding fixed: queue Signal / Wait unwrapping and the fence hooks have tests.
  • The rebase: the new fence and submit sites main gained in vram.rs go through native_queue_signal / native_queue_wait, which unwrap a proxy.
  • The overlap with #3099 (against amd-dev) was triaged earlier: this is the PR for main.

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

<!-- greyfinch-sync:ivall/xcl:comment:7358671710 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7358671710). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T21:01:12Z. --- **Follow-up review** of `2791e80c`, since `0797336` (code reading only, not a merge-check; `PR description` red) · 1 high, 2 medium **In short:** The PR keeps vkd3d-proton's own vtables under Wine and wraps the title's fences. Since `0797336e` it was rebased onto `5ad98adb`, and the one real change is an `UnadoptGuard` on the bundle in `cl_execute_bundle`, with a test. That guard is only on the path for callers that are not the title. A title's `ExecuteBundle` goes through the console slot in `list_x` and still hands vkd3d-proton the adopted bundle. The smoke pair names `0797336e`, not this head, which is why `PR description` is red. #### High 1. **The title's `ExecuteBundle` misses the new guard.** - For command lists, console slot 27 is `make_split(l::execute_bundle, cl_execute_bundle)` (`real.rs` ~1938, ~1684). Calls from the game image go to `list_x::execute_bundle` (`list_x.rs` ~1266), which calls the runtime through `pc(this, 27)` with no guard. - Only callers outside the title reach `cl_execute_bundle` (`real.rs` ~11939), where the guard was added. So the case the commit message describes still happens on the path titles take. - The new test `a_bundle_reaches_execute_bundle_with_its_native_table_only_under_wine` (~15834) calls `cl_execute_bundle` directly and cannot catch it. 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 2. **No Windows suite counts (still open).** **Not tested** mentions "one whole-suite run" on Windows, but **Tested** gives no counts for it, which CONTRIBUTING.md item 2 asks for. 3. **Size (still open).** It is +1085/-78 in one commit. The reason given is about testing on Wine, not about review. The stack suggested earlier still applies: - `create_raw_fence` at the call sites; - the in-place tables; - `UnadoptGuard`; - the fence proxy. <details><summary>Checked and fine</summary> - Earlier finding fixed: under Wine, title fences run XCL's `GetCompletedValue` / `SetEventOnCompletion` / `Signal` hooks on the runtime's fence (`fence_pc_fn`, `real.rs` ~5223). - Earlier finding fixed: the queue Signal / Wait overrides and the device's `CreateSharedHandle` / `SetEventOnMultipleFenceCompletion` unwrapping are added only under `under_wine()`. - Earlier finding fixed: `UnadoptGuard::new` returns early when not under Wine, and `enter` checks `skips_guard` before taking the lock (~1463-1480). - Earlier finding fixed: the guard tests run the shipped `UnadoptGuard` body, and the native-table list warns past its 64 entries. - Earlier finding fixed: queue Signal / Wait unwrapping and the fence hooks have tests. - The rebase: the new fence and submit sites `main` gained in `vram.rs` go through `native_queue_signal` / `native_queue_wait`, which unwrap a proxy. - The overlap with #3099 (against `amd-dev`) was triaged earlier: this is the PR for `main`. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Royalflamejlh commented 2026-12-02 21:22:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:22:40Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1732

@@ -1472,9 +1727,31 @@ unsafe fn class_for(obj: *mut c_void, orig: usize, kind: Kind) -> usize {
             *e = super::guard::make_before(*e, (i - 1) as u64, super::bind::before_list_call);
         }
     }
+    if in_place {
+        let register = || {
+            register_ext(orig);

This is the first review's point, answered above (the price of patching vkd3d-proton's table, and what it does in each case). On the new part, Release calls from inside the runtime: vkd3d-proton drops its own references with its internal refcount, not through the COM table. For example, the swap chain releases its back buffers with vkd3d_resource_decref (libs/vkd3d/swapchain.c:591 and :837 at 71cae091). So those calls do not reach res_release or its locks. Keeping these classes out of the in-place patch brings back the assertion this PR fixes. Left as is.

<!-- greyfinch-sync:ivall/xcl:review-comment:4776249367 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4776249367). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T21:22:40Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1732 ~~~~diff @@ -1472,9 +1727,31 @@ unsafe fn class_for(obj: *mut c_void, orig: usize, kind: Kind) -> usize { *e = super::guard::make_before(*e, (i - 1) as u64, super::bind::before_list_call); } } + if in_place { + let register = || { + register_ext(orig); ~~~~ --- This is the first review's point, answered above (the price of patching vkd3d-proton's table, and what it does in each case). On the new part, Release calls from inside the runtime: vkd3d-proton drops its own references with its internal refcount, not through the COM table. For example, the swap chain releases its back buffers with `vkd3d_resource_decref` (`libs/vkd3d/swapchain.c:591` and `:837` at `71cae091`). So those calls do not reach `res_release` or its locks. Keeping these classes out of the in-place patch brings back the assertion this PR fixes. Left as is.
Royalflamejlh commented 2026-12-02 21:22:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:22:43Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 11915

@@ -11457,7 +11911,10 @@ unsafe extern "system" fn cl_om_set_render_targets(this: *mut c_void, n: u32, rt
 pub(super) unsafe fn bind_pipeline_exact(this: *mut c_void, original: usize, raw: usize) {
     type F = unsafe extern "system" fn(*mut c_void, *mut c_void);
     let f: F = std::mem::transmute(orig_fn(this, slot!(this, "SetPipelineState")));
-    f(this, raw as *mut c_void);
+    {
+        let _pso_guard = UnadoptGuard::new(raw as *mut c_void);

This is the first review's point, answered above. slot_of is new here, and it is the same case. It needs a second thread calling a list, an allocator or a fallback pipeline while a guard is held on it. D3D12 does not let two threads use a list or an allocator at once, and the fallback was not taken in 250 of our runs. Calling through the original table would not help: vkd3d-proton reads the table of the object passed as an argument (ExecuteCommandLists, Reset, ExecuteBundle), not only the one called. Left as is.

<!-- greyfinch-sync:ivall/xcl:review-comment:4776250095 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4776250095). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T21:22:43Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 11915 ~~~~diff @@ -11457,7 +11911,10 @@ unsafe extern "system" fn cl_om_set_render_targets(this: *mut c_void, n: u32, rt pub(super) unsafe fn bind_pipeline_exact(this: *mut c_void, original: usize, raw: usize) { type F = unsafe extern "system" fn(*mut c_void, *mut c_void); let f: F = std::mem::transmute(orig_fn(this, slot!(this, "SetPipelineState"))); - f(this, raw as *mut c_void); + { + let _pso_guard = UnadoptGuard::new(raw as *mut c_void); ~~~~ --- This is the first review's point, answered above. `slot_of` is new here, and it is the same case. It needs a second thread calling a list, an allocator or a fallback pipeline while a guard is held on it. D3D12 does not let two threads use a list or an allocator at once, and the fallback was not taken in 250 of our runs. Calling through the original table would not help: vkd3d-proton reads the table of the object passed as an argument (`ExecuteCommandLists`, `Reset`, `ExecuteBundle`), not only the one called. Left as is.
Royalflamejlh commented 2026-12-02 21:22:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:22:48Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 5251

@@ -4839,6 +5156,126 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 {
 }
 creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]);
 
+/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying
+/// fence's native `lpVtbl` stays intact (`vkd3d-proton` compares `fence->lpVtbl` against
+/// `&d3d12_fence_vtbl` in `CommandQueue::Signal` / `Wait` and on its queue thread).
+#[repr(C)]
+struct FenceProxy {
+    vt: usize,
+    pc: *mut c_void,
+}
+
+static FENCE_PROXY_VT: std::sync::OnceLock<usize> = std::sync::OnceLock::new();
+
+fn fence_proxy_vtable() -> usize {
+    *FENCE_PROXY_VT.get_or_init(|| {
+        const SLOTS: usize = 32;
+        let mut v = vec![0usize; SLOTS];
+        for slot in 0..12 {
+            // mov rcx, [rcx + 8]; mov rax, [rcx]; jmp [rax + slot * 8]
+            let mut c = vec![0x48u8, 0x8B, 0x49, 0x08, 0x48, 0x8B, 0x01, 0xFF, 0xA0];
+            c.extend_from_slice(&((slot * 8) as u32).to_le_bytes());
+            let p = crate::stubs::alloc_code(c.len());
+            unsafe { std::ptr::copy_nonoverlapping(c.as_ptr(), p, c.len()) };
+            v[slot] = p as usize;
+        }
+        v[0] = fence_proxy_qi as usize;
+        v[2] = fence_proxy_release as usize;
+        v[8] = fence_get_completed_value as usize;
+        v[9] = fence_set_event_on_completion as usize;
+        v[10] = fence_signal as usize;
+        v[12] = super::fence_x::completed_value_address as usize;
+        for slot in 13..SLOTS {
+            let (addr, _) = stubs::make_stub_info(DLL, &format!("ID3D12Fence1::#{slot} (not on PC)"), 0);
+            v[slot] = addr;
+        }
+        Box::leak(v.into_boxed_slice()).as_ptr() as usize
+    })
+}
+
+unsafe extern "system" fn fence_proxy_qi(this: *mut c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT {
+    let pc = (*(this as *const FenceProxy)).pc;
+    let f: QiFn = std::mem::transmute(*vt(pc));
+    let hr = f(pc, riid, ppv);
+    if hr >= 0 && !ppv.is_null() && *ppv == pc {
+        *ppv = this;
+    } else if hr == E_NOINTERFACE && !riid.is_null() {
+        let s = layout::guid_string(&*riid);
+        if UNKNOWN_IIDS.lock().unwrap().insert(s.clone()) {
+            crate::xlog_warn!("D3D12.X: QueryInterface({s}) – interface unknown on the PC (console-only?)");
+        }
+    }
+    hr
+}
+
+unsafe extern "system" fn fence_proxy_release(this: *mut c_void) -> u32 {
+    let pc = (*(this as *const FenceProxy)).pc;
+    let f: RefFn = std::mem::transmute(*vt(pc).add(2));
+    let n = f(pc);
+    if n == 0 {
+        drop(Box::from_raw(this as *mut FenceProxy));
+    }
+    n
+}
+
+/// The fence a fence hook calls and its PC method `slot`: the runtime's fence behind a proxy, or
+/// the adopted fence's original.
+unsafe fn fence_pc_fn(this: *mut c_void, slot: usize) -> (*mut c_void, usize) {
+    if FENCE_PROXY_VT.get() == Some(&(vt(this) as usize)) {
+        let pc = (*(this as *const FenceProxy)).pc;
+        return (pc, *vt(pc).add(slot));
+    }
+    (this, orig_fn(this, slot))
+}
+
+unsafe fn wrap_fence_proxy(pc: *mut c_void) -> *mut c_void {
+    Box::into_raw(Box::new(FenceProxy { vt: fence_proxy_vtable(), pc })) as *mut c_void
+}
+
+unsafe fn unwrap_fence(p: *mut c_void) -> *mut c_void {
+    if crate::util::under_wine() { unwrap_fence_proxy(p) } else { p }
+}
+
+unsafe fn unwrap_fence_proxy(p: *mut c_void) -> *mut c_void {
+    if !p.is_null() && crate::gpu::shader::readable(p as usize, 16) && *(p as *const usize) == fence_proxy_vtable() {
+        (*(p as *const FenceProxy)).pc
+    } else {
+        p
+    }
+}
+
+/// Create an un-adopted, un-proxied `ID3D12Fence` for XCL's own internal queue tracking
+/// (`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> {

Right. On main every fence made through the device goes into FENCES (dev_create_fence), and under Wine create_raw_fence left its fences out. It now adds each one it makes (track_end_title_fence). That makes the call this PR had added for the list_x cell fences redundant, so that call is gone and ensure_cell_fence is back to main's shape. New test a_raw_fence_made_under_wine_is_signalled_at_the_title_end, red without it. Head 182896bc.

<!-- greyfinch-sync:ivall/xcl:review-comment:4776250921 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4776250921). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T21:22:48Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 5251 ~~~~diff @@ -4839,6 +5156,126 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 { } creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]); +/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying +/// fence's native `lpVtbl` stays intact (`vkd3d-proton` compares `fence->lpVtbl` against +/// `&d3d12_fence_vtbl` in `CommandQueue::Signal` / `Wait` and on its queue thread). +#[repr(C)] +struct FenceProxy { + vt: usize, + pc: *mut c_void, +} + +static FENCE_PROXY_VT: std::sync::OnceLock<usize> = std::sync::OnceLock::new(); + +fn fence_proxy_vtable() -> usize { + *FENCE_PROXY_VT.get_or_init(|| { + const SLOTS: usize = 32; + let mut v = vec![0usize; SLOTS]; + for slot in 0..12 { + // mov rcx, [rcx + 8]; mov rax, [rcx]; jmp [rax + slot * 8] + let mut c = vec![0x48u8, 0x8B, 0x49, 0x08, 0x48, 0x8B, 0x01, 0xFF, 0xA0]; + c.extend_from_slice(&((slot * 8) as u32).to_le_bytes()); + let p = crate::stubs::alloc_code(c.len()); + unsafe { std::ptr::copy_nonoverlapping(c.as_ptr(), p, c.len()) }; + v[slot] = p as usize; + } + v[0] = fence_proxy_qi as usize; + v[2] = fence_proxy_release as usize; + v[8] = fence_get_completed_value as usize; + v[9] = fence_set_event_on_completion as usize; + v[10] = fence_signal as usize; + v[12] = super::fence_x::completed_value_address as usize; + for slot in 13..SLOTS { + let (addr, _) = stubs::make_stub_info(DLL, &format!("ID3D12Fence1::#{slot} (not on PC)"), 0); + v[slot] = addr; + } + Box::leak(v.into_boxed_slice()).as_ptr() as usize + }) +} + +unsafe extern "system" fn fence_proxy_qi(this: *mut c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + let pc = (*(this as *const FenceProxy)).pc; + let f: QiFn = std::mem::transmute(*vt(pc)); + let hr = f(pc, riid, ppv); + if hr >= 0 && !ppv.is_null() && *ppv == pc { + *ppv = this; + } else if hr == E_NOINTERFACE && !riid.is_null() { + let s = layout::guid_string(&*riid); + if UNKNOWN_IIDS.lock().unwrap().insert(s.clone()) { + crate::xlog_warn!("D3D12.X: QueryInterface({s}) – interface unknown on the PC (console-only?)"); + } + } + hr +} + +unsafe extern "system" fn fence_proxy_release(this: *mut c_void) -> u32 { + let pc = (*(this as *const FenceProxy)).pc; + let f: RefFn = std::mem::transmute(*vt(pc).add(2)); + let n = f(pc); + if n == 0 { + drop(Box::from_raw(this as *mut FenceProxy)); + } + n +} + +/// The fence a fence hook calls and its PC method `slot`: the runtime's fence behind a proxy, or +/// the adopted fence's original. +unsafe fn fence_pc_fn(this: *mut c_void, slot: usize) -> (*mut c_void, usize) { + if FENCE_PROXY_VT.get() == Some(&(vt(this) as usize)) { + let pc = (*(this as *const FenceProxy)).pc; + return (pc, *vt(pc).add(slot)); + } + (this, orig_fn(this, slot)) +} + +unsafe fn wrap_fence_proxy(pc: *mut c_void) -> *mut c_void { + Box::into_raw(Box::new(FenceProxy { vt: fence_proxy_vtable(), pc })) as *mut c_void +} + +unsafe fn unwrap_fence(p: *mut c_void) -> *mut c_void { + if crate::util::under_wine() { unwrap_fence_proxy(p) } else { p } +} + +unsafe fn unwrap_fence_proxy(p: *mut c_void) -> *mut c_void { + if !p.is_null() && crate::gpu::shader::readable(p as usize, 16) && *(p as *const usize) == fence_proxy_vtable() { + (*(p as *const FenceProxy)).pc + } else { + p + } +} + +/// Create an un-adopted, un-proxied `ID3D12Fence` for XCL's own internal queue tracking +/// (`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> { ~~~~ --- Right. On `main` every fence made through the device goes into `FENCES` (`dev_create_fence`), and under Wine `create_raw_fence` left its fences out. It now adds each one it makes (`track_end_title_fence`). That makes the call this PR had added for the `list_x` cell fences redundant, so that call is gone and `ensure_cell_fence` is back to `main`'s shape. New test `a_raw_fence_made_under_wine_is_signalled_at_the_title_end`, red without it. Head `182896bc`.
Royalflamejlh commented 2026-12-02 21:22:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:22:50Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 4290

@@ -3999,6 +4276,21 @@ unsafe extern "system" fn dev_enqueue_make_resident(
     f(this, flags, n, objects, fence, value)
 }
 
+/// device #31 CreateSharedHandle (Wine): the runtime gets its own fence, not the title's proxy
+unsafe extern "system" fn dev_create_shared_handle(this: *mut c_void, object: *mut c_void, attributes: *const c_void, access: u32, name: *const u16, handle: *mut *mut c_void) -> HRESULT {
+    let f: unsafe extern "system" fn(*mut c_void, *mut c_void, *const c_void, u32, *const u16, *mut *mut c_void) -> HRESULT =
+        std::mem::transmute(orig_fn(this, pc_slot!("ID3D12Device", "CreateSharedHandle")));
+    f(this, unwrap_fence(object), attributes, access, name, handle)
+}
+
+/// device #45 SetEventOnMultipleFenceCompletion (Wine): the runtime gets its own fences, not the title's proxies
+unsafe extern "system" fn dev_set_event_on_multiple_fence_completion(this: *mut c_void, fences: *const *mut c_void, values: *const u64, n: u32, flags: u32, event: *mut c_void) -> HRESULT {
+    let f: unsafe extern "system" fn(*mut c_void, *const *mut c_void, *const u64, u32, u32, *mut c_void) -> HRESULT =
+        std::mem::transmute(orig_fn(this, pc_slot!("ID3D12Device1", "SetEventOnMultipleFenceCompletion")));
+    let pc: Vec<*mut c_void> = (0..n as usize).map(|i| unwrap_fence(*fences.add(i))).collect();

Not so on the runtime this hook runs over: the override is added under Wine only, and vkd3d-proton reads fences[0] with no null check for fence_count == 1 (libs/vkd3d/device.c:7396 at 71cae091). It rejects only a zero count and unknown flags. A null array faults there either way. Left as is.

<!-- greyfinch-sync:ivall/xcl:review-comment:4776251387 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4776251387). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T21:22:50Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 4290 ~~~~diff @@ -3999,6 +4276,21 @@ unsafe extern "system" fn dev_enqueue_make_resident( f(this, flags, n, objects, fence, value) } +/// device #31 CreateSharedHandle (Wine): the runtime gets its own fence, not the title's proxy +unsafe extern "system" fn dev_create_shared_handle(this: *mut c_void, object: *mut c_void, attributes: *const c_void, access: u32, name: *const u16, handle: *mut *mut c_void) -> HRESULT { + let f: unsafe extern "system" fn(*mut c_void, *mut c_void, *const c_void, u32, *const u16, *mut *mut c_void) -> HRESULT = + std::mem::transmute(orig_fn(this, pc_slot!("ID3D12Device", "CreateSharedHandle"))); + f(this, unwrap_fence(object), attributes, access, name, handle) +} + +/// device #45 SetEventOnMultipleFenceCompletion (Wine): the runtime gets its own fences, not the title's proxies +unsafe extern "system" fn dev_set_event_on_multiple_fence_completion(this: *mut c_void, fences: *const *mut c_void, values: *const u64, n: u32, flags: u32, event: *mut c_void) -> HRESULT { + let f: unsafe extern "system" fn(*mut c_void, *const *mut c_void, *const u64, u32, u32, *mut c_void) -> HRESULT = + std::mem::transmute(orig_fn(this, pc_slot!("ID3D12Device1", "SetEventOnMultipleFenceCompletion"))); + let pc: Vec<*mut c_void> = (0..n as usize).map(|i| unwrap_fence(*fences.add(i))).collect(); ~~~~ --- Not so on the runtime this hook runs over: the override is added under Wine only, and vkd3d-proton reads `fences[0]` with no null check for `fence_count == 1` (`libs/vkd3d/device.c:7396` at `71cae091`). It rejects only a zero count and unknown flags. A null array faults there either way. Left as is.
Royalflamejlh commented 2026-12-02 21:22:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:22:53Z.


On the two points outside the diff, at head 182896bc:

  • Fences that are not converted (list_x::note_submitted, console_heap.rs:244, gpu_awake.rs:297, uma_driver.rs:529/627, real.rs:593): each one reaches vkd3d-proton as its own fence. note_submitted, console_heap and the check at real.rs:593 signal through native_queue_signal, which unwraps (real.rs:1341). gpu_awake makes its fence inside own_work, so it is not wrapped (is_own_object). uma_driver makes its fences before the device is adopted. There is one proxy per queue or state, not one per call. main also keeps a reference to every fence the device makes, in FENCES. Left as is.
  • dev_enqueue_make_resident: answered in the comment above. vkd3d-proton calls ID3D12Fence_Signal on the fence (libs/vkd3d/device.c:7116 at 71cae091), a COM call, so a proxy works. Left as is.

The four inline points are answered in their threads.

<!-- greyfinch-sync:ivall/xcl:comment:7359197776 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7359197776). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T21:22:53Z. --- On the two points outside the diff, at head `182896bc`: - **Fences that are not converted (`list_x::note_submitted`, `console_heap.rs:244`, `gpu_awake.rs:297`, `uma_driver.rs:529`/`627`, `real.rs:593`):** each one reaches vkd3d-proton as its own fence. `note_submitted`, `console_heap` and the check at `real.rs:593` signal through `native_queue_signal`, which unwraps (`real.rs:1341`). `gpu_awake` makes its fence inside `own_work`, so it is not wrapped (`is_own_object`). `uma_driver` makes its fences before the device is adopted. There is one proxy per queue or state, not one per call. `main` also keeps a reference to every fence the device makes, in `FENCES`. Left as is. - **`dev_enqueue_make_resident`:** answered in the comment above. vkd3d-proton calls `ID3D12Fence_Signal` on the fence (`libs/vkd3d/device.c:7116` at `71cae091`), a COM call, so a proxy works. Left as is. The four inline points are answered in their threads.
Foniass commented 2026-12-02 21:24:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:24:46Z.


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

In short: This push moves the end_title tracking of raw fences into create_raw_fence (real.rs ~5251-5263). Every fence it makes under Wine is now in FENCES, as main's CreateFence does for the rest, not only the list_x cell fences. A Wine-only test covers it. The earlier High finding is unchanged: the title's ExecuteBundle still hands vkd3d-proton the adopted bundle. The smoke pair names 0797336e.

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 lists filtered runs only. CONTRIBUTING.md item 2 asks for the whole suite on a GPU.
  2. Size (still open). +1,172 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 new test does nothing off Wine. a_raw_fence_made_under_wine_is_signalled_at_the_title_end returns early when not under Wine, without skip_test, so on the Windows CI it passes without checking anything. Make it skip visibly, or drive the Wine branch the way the guard tests do.
Checked and fine
  • track_end_title_fence is now private and called from one place, create_raw_fence under Wine. Off Wine the fence goes through dev_create_fence, which tracks it as before, so nothing is added twice.
  • The SYNC_GRAPH cell code is back to its earlier shape. The fence is tracked when it is made, not when a cell installs it, so a fence that loses the race to a cell is also signalled at the end.
  • The earlier fixes (fence hooks on the runtime's fence, the overrides only under under_wine(), guard tests running the shipped body) are unchanged.

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

<!-- greyfinch-sync:ivall/xcl:comment:7359242800 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7359242800). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T21:24:46Z. --- **Follow-up review** of `182896bc`, since `2791e80c` (code reading only, not a merge-check; `PR description` red) · 1 high, 2 medium, 1 nit **In short:** This push moves the `end_title` tracking of raw fences into `create_raw_fence` (`real.rs` ~5251-5263). Every fence it makes under Wine is now in `FENCES`, as `main`'s `CreateFence` does for the rest, not only the `list_x` cell fences. A Wine-only test covers it. The earlier High finding is unchanged: the title's `ExecuteBundle` still hands vkd3d-proton the adopted bundle. The smoke pair names `0797336e`. #### 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 2. **No Windows suite counts (still open).** **Tested** lists filtered runs only. CONTRIBUTING.md item 2 asks for the whole suite on a GPU. 3. **Size (still open).** +1,172 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 4. **The new test does nothing off Wine.** `a_raw_fence_made_under_wine_is_signalled_at_the_title_end` returns early when not under Wine, without `skip_test`, so on the Windows CI it passes without checking anything. Make it skip visibly, or drive the Wine branch the way the guard tests do. <details><summary>Checked and fine</summary> - `track_end_title_fence` is now private and called from one place, `create_raw_fence` under Wine. Off Wine the fence goes through `dev_create_fence`, which tracks it as before, so nothing is added twice. - The `SYNC_GRAPH` cell code is back to its earlier shape. The fence is tracked when it is made, not when a cell installs it, so a fence that loses the race to a cell is also signalled at the end. - The earlier fixes (fence hooks on the runtime's fence, the overrides only under `under_wine()`, guard tests running the shipped body) are unchanged. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
bmjask commented 2026-12-02 21:56:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:56:18Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 5159

@@ -4839,6 +5156,128 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 {
 }
 creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]);
 
+/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4776646879 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4776646879). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T21:56:18Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 5159 ~~~~diff @@ -4839,6 +5156,128 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 { } creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]); +/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying ~~~~ --- **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.
bmjask commented 2026-12-02 21:56:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:56:18Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1252

@@ -1134,16 +1197,99 @@ pub(super) fn test_command_list_class(orig: usize, ext: usize) -> TestCommandLis
 }
 
 unsafe fn vt(obj: *mut c_void) -> *const usize {
-    *(obj as *const *const usize)
+    (*(obj as *const AtomicUsize)).load(Ordering::Acquire) as *const usize
 }
 
 /// Original function of `slot` for an adopted object.
 pub unsafe fn orig_fn(this: *mut c_void, slot: usize) -> usize {
     let ext = vt(this);
+    if let Some(f) = in_place_original(ext as usize, slot) {
+        return f;
+    }
+    if crate::util::under_wine() && is_known_native(ext as usize) {
+        // Another thread's UnadoptGuard temporarily restored the native vtable on this
+        // shared object (e.g. a pipeline state); `ext` is already the original table.
+        return *ext.add(slot);
+    }
     let orig = *ext.sub(1) as *const usize;
     *orig.add(slot)
 }
 
+// vkd3d-proton takes an object (as `this` of its own methods, or as an argument) only with its own
+// vtable: for heaps, resources, descriptor / query heaps, root signatures, pipeline states and
+// command signatures an assertion, which its release builds keep (the process ends). So under
+// Wine those classes keep their table and XCL's PC slots are written into it (`in_place_kind`), as
+// XAudio2's `patch` does; the entries it had before are kept here for `orig_fn`. Only
+// `class_for`'s Wine branch adds a table, so on Windows the list stays empty and `orig_fn` reads
+// ext[-1] as before.
+
+struct InPlace {
+    table: AtomicUsize,
+    /// the table's first `len` entries before XCL wrote its own
+    saved: AtomicUsize,
+    len: AtomicUsize,
+}
+
+const IN_PLACE_MAX: usize = 32;
+static IN_PLACE: [InPlace; IN_PLACE_MAX] = [const { InPlace { table: AtomicUsize::new(0), saved: AtomicUsize::new(0), len: AtomicUsize::new(0) } }; IN_PLACE_MAX];
+/// entries of `IN_PLACE` in use (published with Release after the entry is written)
+static IN_PLACE_N: AtomicUsize = AtomicUsize::new(0);
+static IN_PLACE_LOCK: Mutex<()> = Mutex::new(());
+
+/// For a vtable patched in place: the runtime's function of `slot` (lock-free: `orig_fn`).
+fn in_place_original(table: usize, slot: usize) -> Option<usize> {
+    let n = IN_PLACE_N.load(Ordering::Acquire);
+    let e = IN_PLACE[..n].iter().find(|e| e.table.load(Ordering::Relaxed) == table)?;
+    let len = e.len.load(Ordering::Relaxed);
+    // SAFETY: `saved` holds `len` entries (leaked); past them the table is the runtime's own
+    Some(unsafe { if slot < len { *(e.saved.load(Ordering::Relaxed) as *const usize).add(slot) } else { *(table as *const usize).add(slot) } })
+}
+
+/// The classes vkd3d-proton checks only by an assertion on their vtable, whose console slots all
+/// 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 {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4776646893 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4776646893). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T21:56:18Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1252 ~~~~diff @@ -1134,16 +1197,99 @@ pub(super) fn test_command_list_class(orig: usize, ext: usize) -> TestCommandLis } unsafe fn vt(obj: *mut c_void) -> *const usize { - *(obj as *const *const usize) + (*(obj as *const AtomicUsize)).load(Ordering::Acquire) as *const usize } /// Original function of `slot` for an adopted object. pub unsafe fn orig_fn(this: *mut c_void, slot: usize) -> usize { let ext = vt(this); + if let Some(f) = in_place_original(ext as usize, slot) { + return f; + } + if crate::util::under_wine() && is_known_native(ext as usize) { + // Another thread's UnadoptGuard temporarily restored the native vtable on this + // shared object (e.g. a pipeline state); `ext` is already the original table. + return *ext.add(slot); + } let orig = *ext.sub(1) as *const usize; *orig.add(slot) } +// vkd3d-proton takes an object (as `this` of its own methods, or as an argument) only with its own +// vtable: for heaps, resources, descriptor / query heaps, root signatures, pipeline states and +// command signatures an assertion, which its release builds keep (the process ends). So under +// Wine those classes keep their table and XCL's PC slots are written into it (`in_place_kind`), as +// XAudio2's `patch` does; the entries it had before are kept here for `orig_fn`. Only +// `class_for`'s Wine branch adds a table, so on Windows the list stays empty and `orig_fn` reads +// ext[-1] as before. + +struct InPlace { + table: AtomicUsize, + /// the table's first `len` entries before XCL wrote its own + saved: AtomicUsize, + len: AtomicUsize, +} + +const IN_PLACE_MAX: usize = 32; +static IN_PLACE: [InPlace; IN_PLACE_MAX] = [const { InPlace { table: AtomicUsize::new(0), saved: AtomicUsize::new(0), len: AtomicUsize::new(0) } }; IN_PLACE_MAX]; +/// entries of `IN_PLACE` in use (published with Release after the entry is written) +static IN_PLACE_N: AtomicUsize = AtomicUsize::new(0); +static IN_PLACE_LOCK: Mutex<()> = Mutex::new(()); + +/// For a vtable patched in place: the runtime's function of `slot` (lock-free: `orig_fn`). +fn in_place_original(table: usize, slot: usize) -> Option<usize> { + let n = IN_PLACE_N.load(Ordering::Acquire); + let e = IN_PLACE[..n].iter().find(|e| e.table.load(Ordering::Relaxed) == table)?; + let len = e.len.load(Ordering::Relaxed); + // SAFETY: `saved` holds `len` entries (leaked); past them the table is the runtime's own + Some(unsafe { if slot < len { *(e.saved.load(Ordering::Relaxed) as *const usize).add(slot) } else { *(table as *const usize).add(slot) } }) +} + +/// The classes vkd3d-proton checks only by an assertion on their vtable, whose console slots all +/// 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 { ~~~~ --- **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.
bmjask commented 2026-12-02 21:56:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:56:18Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ivall/xcl:review:6159731388 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#pullrequestreview-6159731388). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T21:56:18Z. **Review:** COMMENTED --- 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._
Royalflamejlh commented 2026-12-02 22:14:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:14:44Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 5159

@@ -4839,6 +5156,128 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 {
 }
 creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]);
 
+/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4776855756 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4776855756). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T22:14:44Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 5159 ~~~~diff @@ -4839,6 +5156,128 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 { } creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]); +/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying ~~~~ --- 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`.
Royalflamejlh commented 2026-12-02 22:14:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:14:46Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1252

@@ -1134,16 +1197,99 @@ pub(super) fn test_command_list_class(orig: usize, ext: usize) -> TestCommandLis
 }
 
 unsafe fn vt(obj: *mut c_void) -> *const usize {
-    *(obj as *const *const usize)
+    (*(obj as *const AtomicUsize)).load(Ordering::Acquire) as *const usize
 }
 
 /// Original function of `slot` for an adopted object.
 pub unsafe fn orig_fn(this: *mut c_void, slot: usize) -> usize {
     let ext = vt(this);
+    if let Some(f) = in_place_original(ext as usize, slot) {
+        return f;
+    }
+    if crate::util::under_wine() && is_known_native(ext as usize) {
+        // Another thread's UnadoptGuard temporarily restored the native vtable on this
+        // shared object (e.g. a pipeline state); `ext` is already the original table.
+        return *ext.add(slot);
+    }
     let orig = *ext.sub(1) as *const usize;
     *orig.add(slot)
 }
 
+// vkd3d-proton takes an object (as `this` of its own methods, or as an argument) only with its own
+// vtable: for heaps, resources, descriptor / query heaps, root signatures, pipeline states and
+// command signatures an assertion, which its release builds keep (the process ends). So under
+// Wine those classes keep their table and XCL's PC slots are written into it (`in_place_kind`), as
+// XAudio2's `patch` does; the entries it had before are kept here for `orig_fn`. Only
+// `class_for`'s Wine branch adds a table, so on Windows the list stays empty and `orig_fn` reads
+// ext[-1] as before.
+
+struct InPlace {
+    table: AtomicUsize,
+    /// the table's first `len` entries before XCL wrote its own
+    saved: AtomicUsize,
+    len: AtomicUsize,
+}
+
+const IN_PLACE_MAX: usize = 32;
+static IN_PLACE: [InPlace; IN_PLACE_MAX] = [const { InPlace { table: AtomicUsize::new(0), saved: AtomicUsize::new(0), len: AtomicUsize::new(0) } }; IN_PLACE_MAX];
+/// entries of `IN_PLACE` in use (published with Release after the entry is written)
+static IN_PLACE_N: AtomicUsize = AtomicUsize::new(0);
+static IN_PLACE_LOCK: Mutex<()> = Mutex::new(());
+
+/// For a vtable patched in place: the runtime's function of `slot` (lock-free: `orig_fn`).
+fn in_place_original(table: usize, slot: usize) -> Option<usize> {
+    let n = IN_PLACE_N.load(Ordering::Acquire);
+    let e = IN_PLACE[..n].iter().find(|e| e.table.load(Ordering::Relaxed) == table)?;
+    let len = e.len.load(Ordering::Relaxed);
+    // SAFETY: `saved` holds `len` entries (leaked); past them the table is the runtime's own
+    Some(unsafe { if slot < len { *(e.saved.load(Ordering::Relaxed) as *const usize).add(slot) } else { *(table as *const usize).add(slot) } })
+}
+
+/// The classes vkd3d-proton checks only by an assertion on their vtable, whose console slots all
+/// 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 {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4776856124 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4776856124). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T22:14:46Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1252 ~~~~diff @@ -1134,16 +1197,99 @@ pub(super) fn test_command_list_class(orig: usize, ext: usize) -> TestCommandLis } unsafe fn vt(obj: *mut c_void) -> *const usize { - *(obj as *const *const usize) + (*(obj as *const AtomicUsize)).load(Ordering::Acquire) as *const usize } /// Original function of `slot` for an adopted object. pub unsafe fn orig_fn(this: *mut c_void, slot: usize) -> usize { let ext = vt(this); + if let Some(f) = in_place_original(ext as usize, slot) { + return f; + } + if crate::util::under_wine() && is_known_native(ext as usize) { + // Another thread's UnadoptGuard temporarily restored the native vtable on this + // shared object (e.g. a pipeline state); `ext` is already the original table. + return *ext.add(slot); + } let orig = *ext.sub(1) as *const usize; *orig.add(slot) } +// vkd3d-proton takes an object (as `this` of its own methods, or as an argument) only with its own +// vtable: for heaps, resources, descriptor / query heaps, root signatures, pipeline states and +// command signatures an assertion, which its release builds keep (the process ends). So under +// Wine those classes keep their table and XCL's PC slots are written into it (`in_place_kind`), as +// XAudio2's `patch` does; the entries it had before are kept here for `orig_fn`. Only +// `class_for`'s Wine branch adds a table, so on Windows the list stays empty and `orig_fn` reads +// ext[-1] as before. + +struct InPlace { + table: AtomicUsize, + /// the table's first `len` entries before XCL wrote its own + saved: AtomicUsize, + len: AtomicUsize, +} + +const IN_PLACE_MAX: usize = 32; +static IN_PLACE: [InPlace; IN_PLACE_MAX] = [const { InPlace { table: AtomicUsize::new(0), saved: AtomicUsize::new(0), len: AtomicUsize::new(0) } }; IN_PLACE_MAX]; +/// entries of `IN_PLACE` in use (published with Release after the entry is written) +static IN_PLACE_N: AtomicUsize = AtomicUsize::new(0); +static IN_PLACE_LOCK: Mutex<()> = Mutex::new(()); + +/// For a vtable patched in place: the runtime's function of `slot` (lock-free: `orig_fn`). +fn in_place_original(table: usize, slot: usize) -> Option<usize> { + let n = IN_PLACE_N.load(Ordering::Acquire); + let e = IN_PLACE[..n].iter().find(|e| e.table.load(Ordering::Relaxed) == table)?; + let len = e.len.load(Ordering::Relaxed); + // SAFETY: `saved` holds `len` entries (leaked); past them the table is the runtime's own + Some(unsafe { if slot < len { *(e.saved.load(Ordering::Relaxed) as *const usize).add(slot) } else { *(table as *const usize).add(slot) } }) +} + +/// The classes vkd3d-proton checks only by an assertion on their vtable, whose console slots all +/// 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 { ~~~~ --- 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 commented 2026-12-02 22:14:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:14:48Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7360427811 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7360427811). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T22:14:48Z. --- 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 commented 2026-12-02 22:16:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T22:16:56Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7360477107 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7360477107). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T22:16:56Z. --- **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 2. **No Windows suite counts (still open).** **Tested** has filtered runs only. CONTRIBUTING.md item 2 asks for the whole suite on a GPU. 3. **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 4. **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`. <details><summary>Checked and fine</summary> - `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. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
bmjask commented 2026-12-02 22:33:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T22:33:26Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ivall/xcl:review:6160229815 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#pullrequestreview-6160229815). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T22:33:26Z. **Review:** COMMENTED --- 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._
bmjask commented 2026-12-02 22:33:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T22:33:27Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1141

@@ -1104,6 +1104,69 @@ struct Class {
 
 static CLASSES: Mutex<Vec<Class>> = Mutex::new(Vec::new());
 static EXTS: Mutex<Option<HashSet<usize>>> = Mutex::new(None);
+const EXT_FAST_CAP: usize = 64;
+static EXT_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP];
+static EXT_FAST_N: AtomicUsize = AtomicUsize::new(0);
+static NATIVE_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP];
+static NATIVE_FAST_N: AtomicUsize = AtomicUsize::new(0);
+static NATIVE_FAST_LOCK: Mutex<()> = Mutex::new(());
+
+fn register_ext(ext: usize) {
+    let mut g = EXTS.lock().unwrap();
+    if g.get_or_insert_with(HashSet::new).insert(ext) {
+        let n = EXT_FAST_N.load(Ordering::Relaxed);
+        if n < EXT_FAST_CAP {
+            EXT_FAST[n].store(ext, Ordering::Relaxed);
+            EXT_FAST_N.store(n + 1, Ordering::Release);
+        }
+    }
+}
+
+fn is_ext_fast(v: usize) -> bool {
+    let n = EXT_FAST_N.load(Ordering::Acquire);
+    for slot in &EXT_FAST[..n.min(EXT_FAST_CAP)] {
+        if slot.load(Ordering::Relaxed) == v {
+            return true;
+        }
+    }
+    n >= EXT_FAST_CAP && is_ext(v)
+}
+
+/// Whether `UnadoptGuard::new` leaves an object whose vtable is `cur` alone: not an extended
+/// vtable, or a runtime table XCL patched in place (its `ext[-1]` is not the native table).
+fn skips_guard(cur: usize) -> bool {
+    !is_ext_fast(cur) || in_place_original(cur, 0).is_some()
+}
+
+fn register_native(orig: usize) {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4777063304 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4777063304). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T22:33:27Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1141 ~~~~diff @@ -1104,6 +1104,69 @@ struct Class { static CLASSES: Mutex<Vec<Class>> = Mutex::new(Vec::new()); static EXTS: Mutex<Option<HashSet<usize>>> = Mutex::new(None); +const EXT_FAST_CAP: usize = 64; +static EXT_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP]; +static EXT_FAST_N: AtomicUsize = AtomicUsize::new(0); +static NATIVE_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP]; +static NATIVE_FAST_N: AtomicUsize = AtomicUsize::new(0); +static NATIVE_FAST_LOCK: Mutex<()> = Mutex::new(()); + +fn register_ext(ext: usize) { + let mut g = EXTS.lock().unwrap(); + if g.get_or_insert_with(HashSet::new).insert(ext) { + let n = EXT_FAST_N.load(Ordering::Relaxed); + if n < EXT_FAST_CAP { + EXT_FAST[n].store(ext, Ordering::Relaxed); + EXT_FAST_N.store(n + 1, Ordering::Release); + } + } +} + +fn is_ext_fast(v: usize) -> bool { + let n = EXT_FAST_N.load(Ordering::Acquire); + for slot in &EXT_FAST[..n.min(EXT_FAST_CAP)] { + if slot.load(Ordering::Relaxed) == v { + return true; + } + } + n >= EXT_FAST_CAP && is_ext(v) +} + +/// Whether `UnadoptGuard::new` leaves an object whose vtable is `cur` alone: not an extended +/// vtable, or a runtime table XCL patched in place (its `ext[-1]` is not the native table). +fn skips_guard(cur: usize) -> bool { + !is_ext_fast(cur) || in_place_original(cur, 0).is_some() +} + +fn register_native(orig: usize) { ~~~~ --- **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.
Royalflamejlh commented 2026-12-02 22:39:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:39:05Z.


@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")).
<!-- greyfinch-sync:ivall/xcl:comment:7360978605 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7360978605). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T22:39:05Z. --- @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")`).
Foniass commented 2026-12-02 22:40:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T22:40:48Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7361016434 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7361016434). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T22:40:48Z. --- **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. <details><summary>Checked and fine</summary> - 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. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Royalflamejlh commented 2026-12-02 22:42:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:42:55Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 1141

@@ -1104,6 +1104,69 @@ struct Class {
 
 static CLASSES: Mutex<Vec<Class>> = Mutex::new(Vec::new());
 static EXTS: Mutex<Option<HashSet<usize>>> = Mutex::new(None);
+const EXT_FAST_CAP: usize = 64;
+static EXT_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP];
+static EXT_FAST_N: AtomicUsize = AtomicUsize::new(0);
+static NATIVE_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP];
+static NATIVE_FAST_N: AtomicUsize = AtomicUsize::new(0);
+static NATIVE_FAST_LOCK: Mutex<()> = Mutex::new(());
+
+fn register_ext(ext: usize) {
+    let mut g = EXTS.lock().unwrap();
+    if g.get_or_insert_with(HashSet::new).insert(ext) {
+        let n = EXT_FAST_N.load(Ordering::Relaxed);
+        if n < EXT_FAST_CAP {
+            EXT_FAST[n].store(ext, Ordering::Relaxed);
+            EXT_FAST_N.store(n + 1, Ordering::Release);
+        }
+    }
+}
+
+fn is_ext_fast(v: usize) -> bool {
+    let n = EXT_FAST_N.load(Ordering::Acquire);
+    for slot in &EXT_FAST[..n.min(EXT_FAST_CAP)] {
+        if slot.load(Ordering::Relaxed) == v {
+            return true;
+        }
+    }
+    n >= EXT_FAST_CAP && is_ext(v)
+}
+
+/// Whether `UnadoptGuard::new` leaves an object whose vtable is `cur` alone: not an extended
+/// vtable, or a runtime table XCL patched in place (its `ext[-1]` is not the native table).
+fn skips_guard(cur: usize) -> bool {
+    !is_ext_fast(cur) || in_place_original(cur, 0).is_some()
+}
+
+fn register_native(orig: usize) {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4777161139 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4777161139). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T22:42:55Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 1141 ~~~~diff @@ -1104,6 +1104,69 @@ struct Class { static CLASSES: Mutex<Vec<Class>> = Mutex::new(Vec::new()); static EXTS: Mutex<Option<HashSet<usize>>> = Mutex::new(None); +const EXT_FAST_CAP: usize = 64; +static EXT_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP]; +static EXT_FAST_N: AtomicUsize = AtomicUsize::new(0); +static NATIVE_FAST: [AtomicUsize; EXT_FAST_CAP] = [const { AtomicUsize::new(0) }; EXT_FAST_CAP]; +static NATIVE_FAST_N: AtomicUsize = AtomicUsize::new(0); +static NATIVE_FAST_LOCK: Mutex<()> = Mutex::new(()); + +fn register_ext(ext: usize) { + let mut g = EXTS.lock().unwrap(); + if g.get_or_insert_with(HashSet::new).insert(ext) { + let n = EXT_FAST_N.load(Ordering::Relaxed); + if n < EXT_FAST_CAP { + EXT_FAST[n].store(ext, Ordering::Relaxed); + EXT_FAST_N.store(n + 1, Ordering::Release); + } + } +} + +fn is_ext_fast(v: usize) -> bool { + let n = EXT_FAST_N.load(Ordering::Acquire); + for slot in &EXT_FAST[..n.min(EXT_FAST_CAP)] { + if slot.load(Ordering::Relaxed) == v { + return true; + } + } + n >= EXT_FAST_CAP && is_ext(v) +} + +/// Whether `UnadoptGuard::new` leaves an object whose vtable is `cur` alone: not an extended +/// vtable, or a runtime table XCL patched in place (its `ext[-1]` is not the native table). +fn skips_guard(cur: usize) -> bool { + !is_ext_fast(cur) || in_place_original(cur, 0).is_some() +} + +fn register_native(orig: usize) { ~~~~ --- 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 commented 2026-12-02 22:42:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:42:58Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7361064826 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7361064826). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T22:42:58Z. --- 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`).
Foniass commented 2026-12-02 22:44:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T22:44:17Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7361094015 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7361094015). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T22:44:17Z. --- **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. <details><summary>Checked and fine</summary> - `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. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Royalflamejlh commented 2026-12-02 22:55:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:55:11Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7361329633 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7361329633). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T22:55:11Z. --- @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 commented 2026-12-02 23:01:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T23:01:48Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 5305

@@ -4863,7 +5302,21 @@ unsafe extern "system" fn dev_create_fence(this: *mut c_void, value: usize, flag
             crate::xlog_info!("D3D12.X: fence flags {:#x} – console-only bits dropped (passing {pc_flags:#x})", flags as u32);
         }
     }
-    let hr = dev_create_fence_pc(this, value, pc_flags, riid, ppv);
+    let hr = if crate::util::under_wine() {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4777354556 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4777354556). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T23:01:48Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 5305 ~~~~diff @@ -4863,7 +5302,21 @@ unsafe extern "system" fn dev_create_fence(this: *mut c_void, value: usize, flag crate::xlog_info!("D3D12.X: fence flags {:#x} – console-only bits dropped (passing {pc_flags:#x})", flags as u32); } } - let hr = dev_create_fence_pc(this, value, pc_flags, riid, ppv); + let hr = if crate::util::under_wine() { ~~~~ --- **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.
bmjask commented 2026-12-02 23:01:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T23:01:48Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 5251

@@ -4839,6 +5156,128 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 {
 }
 creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]);
 
+/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying
+/// fence's native `lpVtbl` stays intact (`vkd3d-proton` compares `fence->lpVtbl` against
+/// `&d3d12_fence_vtbl` in `CommandQueue::Signal` / `Wait` and on its queue thread).
+#[repr(C)]
+struct FenceProxy {
+    vt: usize,
+    pc: *mut c_void,
+}
+
+static FENCE_PROXY_VT: std::sync::OnceLock<usize> = std::sync::OnceLock::new();
+
+fn fence_proxy_vtable() -> usize {
+    *FENCE_PROXY_VT.get_or_init(|| {
+        const SLOTS: usize = 12 + EXTRA_SLOTS;
+        let mut v = vec![0usize; SLOTS];
+        for slot in 0..12 {
+            // mov rcx, [rcx + 8]; mov rax, [rcx]; jmp [rax + slot * 8]
+            let mut c = vec![0x48u8, 0x8B, 0x49, 0x08, 0x48, 0x8B, 0x01, 0xFF, 0xA0];
+            c.extend_from_slice(&((slot * 8) as u32).to_le_bytes());
+            let p = crate::stubs::alloc_code(c.len());
+            unsafe { std::ptr::copy_nonoverlapping(c.as_ptr(), p, c.len()) };
+            v[slot] = p as usize;
+        }
+        v[0] = fence_proxy_qi as usize;
+        v[2] = fence_proxy_release as usize;
+        v[8] = fence_get_completed_value as usize;
+        v[9] = fence_set_event_on_completion as usize;
+        v[10] = fence_signal as usize;
+        v[12] = super::fence_x::completed_value_address as usize;
+        for slot in 13..SLOTS {
+            let (addr, _) = stubs::make_stub_info(DLL, &format!("ID3D12Fence1::#{slot} (not on PC)"), 0);
+            v[slot] = addr;
+        }
+        Box::leak(v.into_boxed_slice()).as_ptr() as usize
+    })
+}
+
+unsafe extern "system" fn fence_proxy_qi(this: *mut c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT {
+    let pc = (*(this as *const FenceProxy)).pc;
+    let f: QiFn = std::mem::transmute(*vt(pc));
+    let hr = f(pc, riid, ppv);
+    if hr >= 0 && !ppv.is_null() && *ppv == pc {
+        *ppv = this;
+    } else if hr == E_NOINTERFACE && !riid.is_null() {
+        let s = layout::guid_string(&*riid);
+        if UNKNOWN_IIDS.lock().unwrap().insert(s.clone()) {
+            crate::xlog_warn!("D3D12.X: QueryInterface({s}) – interface unknown on the PC (console-only?)");
+        }
+    }
+    hr
+}
+
+unsafe extern "system" fn fence_proxy_release(this: *mut c_void) -> u32 {
+    let pc = (*(this as *const FenceProxy)).pc;
+    let f: RefFn = std::mem::transmute(*vt(pc).add(2));
+    let n = f(pc);
+    if n == 0 {
+        drop(Box::from_raw(this as *mut FenceProxy));
+    }
+    n
+}
+
+/// The fence a fence hook calls and its PC method `slot`: the runtime's fence behind a proxy, or
+/// the adopted fence's original.
+unsafe fn fence_pc_fn(this: *mut c_void, slot: usize) -> (*mut c_void, usize) {
+    if FENCE_PROXY_VT.get() == Some(&(vt(this) as usize)) {
+        let pc = (*(this as *const FenceProxy)).pc;
+        return (pc, *vt(pc).add(slot));
+    }
+    (this, orig_fn(this, slot))
+}
+
+unsafe fn wrap_fence_proxy(pc: *mut c_void) -> *mut c_void {
+    Box::into_raw(Box::new(FenceProxy { vt: fence_proxy_vtable(), pc })) as *mut c_void
+}
+
+unsafe fn unwrap_fence(p: *mut c_void) -> *mut c_void {
+    if crate::util::under_wine() { unwrap_fence_proxy(p) } else { p }
+}
+
+unsafe fn unwrap_fence_proxy(p: *mut c_void) -> *mut c_void {
+    if !p.is_null() && crate::gpu::shader::readable(p as usize, 16) && *(p as *const usize) == fence_proxy_vtable() {
+        (*(p as *const FenceProxy)).pc
+    } else {
+        p
+    }
+}
+
+/// Create an un-adopted, un-proxied `ID3D12Fence` for XCL's own internal queue tracking
+/// (`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> {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4777354563 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4777354563). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T23:01:48Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 5251 ~~~~diff @@ -4839,6 +5156,128 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 { } creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]); +/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying +/// fence's native `lpVtbl` stays intact (`vkd3d-proton` compares `fence->lpVtbl` against +/// `&d3d12_fence_vtbl` in `CommandQueue::Signal` / `Wait` and on its queue thread). +#[repr(C)] +struct FenceProxy { + vt: usize, + pc: *mut c_void, +} + +static FENCE_PROXY_VT: std::sync::OnceLock<usize> = std::sync::OnceLock::new(); + +fn fence_proxy_vtable() -> usize { + *FENCE_PROXY_VT.get_or_init(|| { + const SLOTS: usize = 12 + EXTRA_SLOTS; + let mut v = vec![0usize; SLOTS]; + for slot in 0..12 { + // mov rcx, [rcx + 8]; mov rax, [rcx]; jmp [rax + slot * 8] + let mut c = vec![0x48u8, 0x8B, 0x49, 0x08, 0x48, 0x8B, 0x01, 0xFF, 0xA0]; + c.extend_from_slice(&((slot * 8) as u32).to_le_bytes()); + let p = crate::stubs::alloc_code(c.len()); + unsafe { std::ptr::copy_nonoverlapping(c.as_ptr(), p, c.len()) }; + v[slot] = p as usize; + } + v[0] = fence_proxy_qi as usize; + v[2] = fence_proxy_release as usize; + v[8] = fence_get_completed_value as usize; + v[9] = fence_set_event_on_completion as usize; + v[10] = fence_signal as usize; + v[12] = super::fence_x::completed_value_address as usize; + for slot in 13..SLOTS { + let (addr, _) = stubs::make_stub_info(DLL, &format!("ID3D12Fence1::#{slot} (not on PC)"), 0); + v[slot] = addr; + } + Box::leak(v.into_boxed_slice()).as_ptr() as usize + }) +} + +unsafe extern "system" fn fence_proxy_qi(this: *mut c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + let pc = (*(this as *const FenceProxy)).pc; + let f: QiFn = std::mem::transmute(*vt(pc)); + let hr = f(pc, riid, ppv); + if hr >= 0 && !ppv.is_null() && *ppv == pc { + *ppv = this; + } else if hr == E_NOINTERFACE && !riid.is_null() { + let s = layout::guid_string(&*riid); + if UNKNOWN_IIDS.lock().unwrap().insert(s.clone()) { + crate::xlog_warn!("D3D12.X: QueryInterface({s}) – interface unknown on the PC (console-only?)"); + } + } + hr +} + +unsafe extern "system" fn fence_proxy_release(this: *mut c_void) -> u32 { + let pc = (*(this as *const FenceProxy)).pc; + let f: RefFn = std::mem::transmute(*vt(pc).add(2)); + let n = f(pc); + if n == 0 { + drop(Box::from_raw(this as *mut FenceProxy)); + } + n +} + +/// The fence a fence hook calls and its PC method `slot`: the runtime's fence behind a proxy, or +/// the adopted fence's original. +unsafe fn fence_pc_fn(this: *mut c_void, slot: usize) -> (*mut c_void, usize) { + if FENCE_PROXY_VT.get() == Some(&(vt(this) as usize)) { + let pc = (*(this as *const FenceProxy)).pc; + return (pc, *vt(pc).add(slot)); + } + (this, orig_fn(this, slot)) +} + +unsafe fn wrap_fence_proxy(pc: *mut c_void) -> *mut c_void { + Box::into_raw(Box::new(FenceProxy { vt: fence_proxy_vtable(), pc })) as *mut c_void +} + +unsafe fn unwrap_fence(p: *mut c_void) -> *mut c_void { + if crate::util::under_wine() { unwrap_fence_proxy(p) } else { p } +} + +unsafe fn unwrap_fence_proxy(p: *mut c_void) -> *mut c_void { + if !p.is_null() && crate::gpu::shader::readable(p as usize, 16) && *(p as *const usize) == fence_proxy_vtable() { + (*(p as *const FenceProxy)).pc + } else { + p + } +} + +/// Create an un-adopted, un-proxied `ID3D12Fence` for XCL's own internal queue tracking +/// (`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> { ~~~~ --- **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.
bmjask commented 2026-12-02 23:01:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T23:01:48Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ivall/xcl:review:6160582200 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#pullrequestreview-6160582200). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T23:01:48Z. **Review:** COMMENTED --- 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._
Royalflamejlh commented 2026-12-02 23:13:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T23:13:12Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 5305

@@ -4863,7 +5302,21 @@ unsafe extern "system" fn dev_create_fence(this: *mut c_void, value: usize, flag
             crate::xlog_info!("D3D12.X: fence flags {:#x} – console-only bits dropped (passing {pc_flags:#x})", flags as u32);
         }
     }
-    let hr = dev_create_fence_pc(this, value, pc_flags, riid, ppv);
+    let hr = if crate::util::under_wine() {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4777465562 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4777465562). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T23:13:12Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 5305 ~~~~diff @@ -4863,7 +5302,21 @@ unsafe extern "system" fn dev_create_fence(this: *mut c_void, value: usize, flag crate::xlog_info!("D3D12.X: fence flags {:#x} – console-only bits dropped (passing {pc_flags:#x})", flags as u32); } } - let hr = dev_create_fence_pc(this, value, pc_flags, riid, ppv); + let hr = if crate::util::under_wine() { ~~~~ --- 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.
Royalflamejlh commented 2026-12-02 23:13:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T23:13:14Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 5251

@@ -4839,6 +5156,128 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 {
 }
 creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]);
 
+/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying
+/// fence's native `lpVtbl` stays intact (`vkd3d-proton` compares `fence->lpVtbl` against
+/// `&d3d12_fence_vtbl` in `CommandQueue::Signal` / `Wait` and on its queue thread).
+#[repr(C)]
+struct FenceProxy {
+    vt: usize,
+    pc: *mut c_void,
+}
+
+static FENCE_PROXY_VT: std::sync::OnceLock<usize> = std::sync::OnceLock::new();
+
+fn fence_proxy_vtable() -> usize {
+    *FENCE_PROXY_VT.get_or_init(|| {
+        const SLOTS: usize = 12 + EXTRA_SLOTS;
+        let mut v = vec![0usize; SLOTS];
+        for slot in 0..12 {
+            // mov rcx, [rcx + 8]; mov rax, [rcx]; jmp [rax + slot * 8]
+            let mut c = vec![0x48u8, 0x8B, 0x49, 0x08, 0x48, 0x8B, 0x01, 0xFF, 0xA0];
+            c.extend_from_slice(&((slot * 8) as u32).to_le_bytes());
+            let p = crate::stubs::alloc_code(c.len());
+            unsafe { std::ptr::copy_nonoverlapping(c.as_ptr(), p, c.len()) };
+            v[slot] = p as usize;
+        }
+        v[0] = fence_proxy_qi as usize;
+        v[2] = fence_proxy_release as usize;
+        v[8] = fence_get_completed_value as usize;
+        v[9] = fence_set_event_on_completion as usize;
+        v[10] = fence_signal as usize;
+        v[12] = super::fence_x::completed_value_address as usize;
+        for slot in 13..SLOTS {
+            let (addr, _) = stubs::make_stub_info(DLL, &format!("ID3D12Fence1::#{slot} (not on PC)"), 0);
+            v[slot] = addr;
+        }
+        Box::leak(v.into_boxed_slice()).as_ptr() as usize
+    })
+}
+
+unsafe extern "system" fn fence_proxy_qi(this: *mut c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT {
+    let pc = (*(this as *const FenceProxy)).pc;
+    let f: QiFn = std::mem::transmute(*vt(pc));
+    let hr = f(pc, riid, ppv);
+    if hr >= 0 && !ppv.is_null() && *ppv == pc {
+        *ppv = this;
+    } else if hr == E_NOINTERFACE && !riid.is_null() {
+        let s = layout::guid_string(&*riid);
+        if UNKNOWN_IIDS.lock().unwrap().insert(s.clone()) {
+            crate::xlog_warn!("D3D12.X: QueryInterface({s}) – interface unknown on the PC (console-only?)");
+        }
+    }
+    hr
+}
+
+unsafe extern "system" fn fence_proxy_release(this: *mut c_void) -> u32 {
+    let pc = (*(this as *const FenceProxy)).pc;
+    let f: RefFn = std::mem::transmute(*vt(pc).add(2));
+    let n = f(pc);
+    if n == 0 {
+        drop(Box::from_raw(this as *mut FenceProxy));
+    }
+    n
+}
+
+/// The fence a fence hook calls and its PC method `slot`: the runtime's fence behind a proxy, or
+/// the adopted fence's original.
+unsafe fn fence_pc_fn(this: *mut c_void, slot: usize) -> (*mut c_void, usize) {
+    if FENCE_PROXY_VT.get() == Some(&(vt(this) as usize)) {
+        let pc = (*(this as *const FenceProxy)).pc;
+        return (pc, *vt(pc).add(slot));
+    }
+    (this, orig_fn(this, slot))
+}
+
+unsafe fn wrap_fence_proxy(pc: *mut c_void) -> *mut c_void {
+    Box::into_raw(Box::new(FenceProxy { vt: fence_proxy_vtable(), pc })) as *mut c_void
+}
+
+unsafe fn unwrap_fence(p: *mut c_void) -> *mut c_void {
+    if crate::util::under_wine() { unwrap_fence_proxy(p) } else { p }
+}
+
+unsafe fn unwrap_fence_proxy(p: *mut c_void) -> *mut c_void {
+    if !p.is_null() && crate::gpu::shader::readable(p as usize, 16) && *(p as *const usize) == fence_proxy_vtable() {
+        (*(p as *const FenceProxy)).pc
+    } else {
+        p
+    }
+}
+
+/// Create an un-adopted, un-proxied `ID3D12Fence` for XCL's own internal queue tracking
+/// (`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> {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4777465872 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#discussion_r4777465872). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T23:13:14Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 5251 ~~~~diff @@ -4839,6 +5156,128 @@ unsafe extern "system" fn mem_heap_release(this: *mut c_void) -> u32 { } creator!(dev_create_fence_pc, "CreateFence", Kind::Fence, [a1, a2]); +/// Thin COM proxy around `ID3D12Fence1` used under Wine/vkd3d-proton so the underlying +/// fence's native `lpVtbl` stays intact (`vkd3d-proton` compares `fence->lpVtbl` against +/// `&d3d12_fence_vtbl` in `CommandQueue::Signal` / `Wait` and on its queue thread). +#[repr(C)] +struct FenceProxy { + vt: usize, + pc: *mut c_void, +} + +static FENCE_PROXY_VT: std::sync::OnceLock<usize> = std::sync::OnceLock::new(); + +fn fence_proxy_vtable() -> usize { + *FENCE_PROXY_VT.get_or_init(|| { + const SLOTS: usize = 12 + EXTRA_SLOTS; + let mut v = vec![0usize; SLOTS]; + for slot in 0..12 { + // mov rcx, [rcx + 8]; mov rax, [rcx]; jmp [rax + slot * 8] + let mut c = vec![0x48u8, 0x8B, 0x49, 0x08, 0x48, 0x8B, 0x01, 0xFF, 0xA0]; + c.extend_from_slice(&((slot * 8) as u32).to_le_bytes()); + let p = crate::stubs::alloc_code(c.len()); + unsafe { std::ptr::copy_nonoverlapping(c.as_ptr(), p, c.len()) }; + v[slot] = p as usize; + } + v[0] = fence_proxy_qi as usize; + v[2] = fence_proxy_release as usize; + v[8] = fence_get_completed_value as usize; + v[9] = fence_set_event_on_completion as usize; + v[10] = fence_signal as usize; + v[12] = super::fence_x::completed_value_address as usize; + for slot in 13..SLOTS { + let (addr, _) = stubs::make_stub_info(DLL, &format!("ID3D12Fence1::#{slot} (not on PC)"), 0); + v[slot] = addr; + } + Box::leak(v.into_boxed_slice()).as_ptr() as usize + }) +} + +unsafe extern "system" fn fence_proxy_qi(this: *mut c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + let pc = (*(this as *const FenceProxy)).pc; + let f: QiFn = std::mem::transmute(*vt(pc)); + let hr = f(pc, riid, ppv); + if hr >= 0 && !ppv.is_null() && *ppv == pc { + *ppv = this; + } else if hr == E_NOINTERFACE && !riid.is_null() { + let s = layout::guid_string(&*riid); + if UNKNOWN_IIDS.lock().unwrap().insert(s.clone()) { + crate::xlog_warn!("D3D12.X: QueryInterface({s}) – interface unknown on the PC (console-only?)"); + } + } + hr +} + +unsafe extern "system" fn fence_proxy_release(this: *mut c_void) -> u32 { + let pc = (*(this as *const FenceProxy)).pc; + let f: RefFn = std::mem::transmute(*vt(pc).add(2)); + let n = f(pc); + if n == 0 { + drop(Box::from_raw(this as *mut FenceProxy)); + } + n +} + +/// The fence a fence hook calls and its PC method `slot`: the runtime's fence behind a proxy, or +/// the adopted fence's original. +unsafe fn fence_pc_fn(this: *mut c_void, slot: usize) -> (*mut c_void, usize) { + if FENCE_PROXY_VT.get() == Some(&(vt(this) as usize)) { + let pc = (*(this as *const FenceProxy)).pc; + return (pc, *vt(pc).add(slot)); + } + (this, orig_fn(this, slot)) +} + +unsafe fn wrap_fence_proxy(pc: *mut c_void) -> *mut c_void { + Box::into_raw(Box::new(FenceProxy { vt: fence_proxy_vtable(), pc })) as *mut c_void +} + +unsafe fn unwrap_fence(p: *mut c_void) -> *mut c_void { + if crate::util::under_wine() { unwrap_fence_proxy(p) } else { p } +} + +unsafe fn unwrap_fence_proxy(p: *mut c_void) -> *mut c_void { + if !p.is_null() && crate::gpu::shader::readable(p as usize, 16) && *(p as *const usize) == fence_proxy_vtable() { + (*(p as *const FenceProxy)).pc + } else { + p + } +} + +/// Create an un-adopted, un-proxied `ID3D12Fence` for XCL's own internal queue tracking +/// (`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> { ~~~~ --- 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 commented 2026-12-02 23:13:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T23:13:16Z.


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 #2477's approach, with what each case does.

No code change for them.

<!-- greyfinch-sync:ivall/xcl:comment:7361716528 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3492#issuecomment-7361716528). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T23:13:16Z. --- 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 #2477's approach, with what each case does. No code change for them.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3492:upstream-pr/3492'
git switch 'upstream-pr/3492'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3492'
git switch 'upstream-pr/3492'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3492'
git switch 'upstream-pr/3492'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3492'
git switch 'main'
git merge --squash 'upstream-pr/3492'
git switch 'main'
git merge --ff-only 'upstream-pr/3492'
git switch 'main'
git merge 'upstream-pr/3492'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3492
No description provided.