Skip to content

Wine: raw internal fences + native-vtable guards at host-runtime calls (rebased on amd-dev) - #3099

Open
crazymanjared wants to merge 6 commits into
xcl-dev:amd-devfrom
crazymanjared:raw-fence-7c
Open

crazymanjared wants to merge 6 commits into
xcl-dev:amd-devfrom
crazymanjared:raw-fence-7c

Conversation

@crazymanjared

@crazymanjared crazymanjared commented Nov 28, 2026 •

Copy link
Copy Markdown

What

Makes XCL's internal D3D12.X object usage correct against a host vkd3d-proton that identifies its own objects by vtable-table equality — which is exactly what happens when XCL runs on Wine with d3d12/d3d12core as native vkd3d-proton DLLs. Two violation classes, 6 commits, each a single-variable step. Run data for every claim lives in #846 (I'm crazymanjared there; the run-numbered entries in commit messages map 1:1 to that thread).

Rebased 2026-11-29: the branch is now the guard/fence stack ported onto current amd-dev (36e16cf4, includes #3369 and the submit_thread/#3304 split-entry machinery) as 6 clean commits. The previous 7c-based head (fe6a8c26, a 292-commit face against the then-base) is superseded; everything it proved still stands, see Results.

Why this fails on Wine today

  1. Adopted (vtable-swapped) console objects passed into host runtime calls. The host d3d12_command_list_from_iface-style checks compare lpVtbl against its own embedded/default/profiled tables and return NULL for ext-table objects; several call sites then dereference without a NULL check. Bare amd-dev (7c-era, same face as runs 85/86 on the 8942 base) dies at title boot on Wine with E_INVALIDARG int-3 (game+0x2478b7b / game+0x2474ce1), 0.5 s after prep completes, 0 presents — deterministic 2/2. Without UnadoptGuard (git log -S UnadoptGuard finds nothing upstream) nothing else on this path is even testable.
  2. Adopted FenceProxy objects reaching the host submission path. vkd3d-proton's submission worker blind-casts fences it receives — a vtable-swapped proxy faults. XCL hands fences into queue Signals from the vram retire/seal machinery (vram.rs, run88 wall at t22.783) and from sparse copy-back submits (GreemSC hit the same class independently — The retail title 1.0.2.1 (RTX 5070): reaches the end of the first-run setup, then deterministic 0xC0000005 write at 0x0 in game_scarlett_master.exe+0x23cf683 #846 comment 7225087672).
  3. Query-hazard scan NULL deref. Once the title binds query heaps, vkd3d's vkd3d_submission_has_query_reset_hazard calls d3d12_command_list_from_iface(command_lists[i]) and dereferences list->query_ranges.count without a NULL check — an XCL ext-table list in an ECL batch = AV read at NULL+0x2b28 (observed at d3d12core+0x4c75d7, run 87 at t126.817 on the 8942 base). This PR makes XCL's sparse readback/upload lists and allocs unwrapped runtime objects at creation; a host-side NULL check next to that scan would be the complementary fix.

The stack (on amd-dev 36e16cf4)

commit what
ec26e0ac create_raw_fence (orig-slot pattern) — helper for everything below; the tree has the vtable machinery but not this helper
48438cdd UnadoptGuard + FenceProxy core: guard machinery (fast tables, orig-fn native-table passthrough) + guarded host-call sites (CreateCommandList, placed resources, heap, RTV, PSO bind, allocator Reset incl. reset_pc_allocator, ExecuteCommandLists both paths) + queue Signal/Wait fences unwrapped (queue_signal_now / queue_wait_now / PC-caller entries)
dfeaac47 same for the list_x/alloc_pool sites: kickoff_x exec/reset, split/deferred_segment/record_deferred/reset_list guards + sync-graph, copy_scratch and alloc_pool.executed fences → create_raw_fence
e9e44984 missed multi-line CLASSES lock conversion from the RwLock switch (compile follow-up)
66a49b3c sparse readback/upload lists + allocs created raw (unwrapped runtime objects): new_state upload slots / rb list / take_or_alloc_rb_job — kills the query-hazard class (3) at the source
b8ec6a4f vram.rs: device-queue signal + heap-retirement fence sites → create_raw_fence (run88 wall: signal_device_queues fanned FenceProxy ptrs into queue Signals → dual AV)

Rebase notes (deltas vs the 7c-era face): the XG CopyFromSubresource 7-arg ABI commit is gone as content — current amd-dev carries the newer 4-argument-copy_args form natively; readback_after's bounded-wait guard is gone — the function was refactored into the async rb-queue design; ExecuteCommandLists now goes through the base's caller-split entries with the UnadoptGuards kept inside both branches; queue_wait_now gained the fence unwrap the base only had on the Signal side.

Results on Wine (GE-Proton11-14, RX 6950 XT / RDNA2, vkd3d-proton master, RADV 26.3.1)

Every commit's content is proven by an actual GTA6 title run on this box (run numbers in messages ↔ #846), first on the 7c lineage, then re-proven end-to-end on the 8942 lineage:

The rebased chain here compiles clean (cargo build --release -p xcl --target x86_64-pc-windows-gnu, 0 errors); the run-proven trees it ports from are runs 87–90. Not NVIDIA/Windows-tested — these paths only activate where the host runtime is vkd3d-proton under Wine, so Windows/NVIDIA behavior should be untouched by construction (guards adopt/unwrap only in ext contexts); would appreciate a maintainer sanity pass on that framing.

Follow-up candidates (deliberately NOT in this PR): sparse.rs's async-rb fences on the new base (lines ~2948/~4041, dev.CreateFence — the FenceProxy design may cover them, pending our own fault data on this base); vram.rs site ~917 (unported, no observed face).

Review request: @GreemSC — you independently hit class (2); a second pair of eyes on the vram + ECL guard sites would be great. @tiagonleal — per #846 this is the guard-set landing place including the Reset(allocator, pso) coverage you asked for (reset_pc_allocator wraps the raw allocator reset in UnadoptGuard).

Hermes added 6 commits November 29, 2026 12:00
… only dependency, 7c has the vtable machinery but not the helper
… run58 boot crash (adopted allocator/PSO/fence args rejected by Wine-host vkd3d from-iface check; E_INVALIDARG at first CreateCommandListX, deterministic 2/2). Guard machinery (EXT_FAST/NATIVE_FAST fast tables, orig_fn native-table passthrough) + guarded runtime call-sites (CreateCommandList/1, Reset, placed resources, RTV, Set/ClearState, alloc Reset, ExecuteCommandLists both paths) + FenceProxy per e4f88d68 (fences keep native vtble under Wine). create_raw_fence NOT duplicated (f90b6cd version kept). Skipped: uav ensure_lazy_mapped, q_release forget_queue, tests (7c lacks those sparse helpers / test hunk). Not for merge (matches e4f88d68 posture).

(cherry picked from commit eb05e33)
…8 (run59 boot wall: E_INVALIDARG int-3 at game+0x2474ce1 right after allocator wrap, BEFORE queue xcl-dev#35 ExecuteCommandListsX entry log = console submit/reset path unguarded: kickoff_x exec x2 + reset, split/deferred_segment/record_deferred/reset_pc reset_list guards + sync-graph & copy_scratch & alloc_pool.executed fences -> create_raw_fence (FenceProxy consistency). Same 0x80070057 pattern = per next-order item 1c. Skipped (7c lacks helpers/tests): ensure_lazy_mapped, note_queue_wait, log_sync_state, all test hunks.

(cherry picked from commit a4fedba)
…tats() (E0599 follow-up to 4b60f6ca RwLock switch; this exact working tree built the deployed run87 exe b39a343b7f52a93a0d0ec15533c55b2b)
…me objects

XCL submits its readback/upload command lists straight onto its internal
queue; under Wine the runtime's from-iface check (query-hazard scan of
ExecuteCommandLists, command.c) answers NULL for class-wrapped lists and
the following list->query_ranges read faults with 0xc0000005 at a fixed
offset (observed on retail titles at ~2.5 min in, under shader-storm
load). Create them through the runtime's own CreateCommandList/Allocator
slots, as create_raw_fence already does for fences.

(cherry picked from commit 603026b3be7d5ce01e733c35f4562c42e903bf8f)
…evice queues / heap retirement with raw fences, not CreateFence FenceProxies (run88 wall t22.783: vram::signal_device_queues -> q.Signal(FenceProxy) onto device queue; vkd3d submission worker d3d12_fence_add_pending_signal_locked read all-ones + title thread faulted mid d3d12_command_queue_signal trace. Same face as the old 16 s signal_queues_with f.clone() crash, fixed x1 on amd-wine; never went upstream (dev.CreateFence unfixed on 8942/f33 per xcl-dev#56(a)). Both sites match amd-wine-pre-rebase-1126's proven face (2349+2368). Site 917 left unchanged (single variable).
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 29, 2026
@crazymanjared crazymanjared changed the title Wine: raw internal fences + native-vtable guards at host-runtime calls + XG CopyFromSubresource 7-arg ABI Wine: raw internal fences + native-vtable guards at host-runtime calls (rebased on amd-dev) Nov 29, 2026
@tiagonleal

Copy link
Copy Markdown
Contributor

merge-check
base: 36e16cf
head: b8ec6a4
merge: clean (the head sits on amd-dev 36e16cf4; tested as it is)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2153 passed, 18 failed, 48 ignored; SKIPPED: 23; failing: 15 distinct tests, every one of which also fails on the base on this PC (base alone, one run: 2141 passed, 30 failed, 48 ignored, 27 distinct). amd-dev is not clean on NVIDIA here to begin with (the four fuzz_validate_and_gpu_*, gpu_fract_f32_edges, f32_programs_on_the_gpu, several sparse and title_textures tests with PoisonError after a first failure), so this says "no new failure in one run", not more.
review: whole diff read (+439/-49). You asked whether Windows is untouched by construction. Partly. Three things are behind under_wine(): UnadoptGuard::new returns None off Wine (real.rs:963), fences are wrapped in a FenceProxy only under Wine, and unwrap_fence does nothing off Wine. These are not gated, and run on Windows too:

  1. q_execute_command_lists now sends every submit made inside own_work() straight to the PC ExecuteCommandLists (real.rs, the new || is_own_work() at the top). On the base those submits went on through the rest of the function. The comment gives a deadlock reason that has nothing to do with Wine, and the commit table in the description does not list it. It deserves its own PR or at least its own line, with what bookkeeping it now skips.
  2. create_raw_fence (real.rs:5054) takes the original CreateFence slot whenever the device is adopted, which it is on Windows. So the fences of the sync graph, copy_scratch, alloc_pool.executed, the device-queue signal and the heap retirement in vram.rs, and drain_gpu are no longer adopted on Windows either, and their Signal no longer goes through the hooked fence_signal.
  3. create_raw_command_allocator / create_raw_command_list, used for the sparse upload and readback lists (sparse.rs), are unconditional in the same way.
  4. The queue gets Signal / Wait overrides (q_signal_pc, q_wait_pc), and reset_pc_allocator now also calls console_list::allocator_reset.
    Whether 2 and 3 change anything that matters on Windows I could not settle by reading; if the base already makes those objects inside own_work() they were never adopted anyway. Gating them on under_wine() would make the claim true without that question. No test covers the raw objects or the new submit path, and UnadoptGuard::enter (#[cfg(test)]) is never called.
    For whoever merges: five of the six commit subjects start with Local: and one says "Not for merge"; the PR description check is red because the body has no Tested, Not tested and AI use sections and no xcl-smoke blocks; the body names the title.
    performance: on Windows a branch per guard site, an atomic load per vtable read, and orig_fn + slot_of on every queue Signal / Wait XCL makes. scripts/smoke.ps1 -Seconds 60 (retail title, menus, release, XCL_PREPARE=0): this head 1709 frames, peak commit 13591 MB; base 1693 and 1707 frames, 12671 and 13174 MB. No difference outside the spread of the base. The menus do not exercise the sparse readback path much, and I did not run the world on this branch.
    verdict: not yet: the description check is red, and items 1 to 4 run on Windows although the description says nothing does; gate or justify them
    hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (617.42), AMD Ryzen 7 9800X3D, Windows 11 Pro 26300, rustc 1.100.0, debug suite and release smoke; nothing run under Wine / Claude Code: Claude Fable 5.2 ran the builds, suites and smoke; Claude Opus 5.5 read the diff.
  • Tiago

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head b8ec6a4

This PR targets amd-dev. UnadoptGuard, FenceProxy and create_raw_fence are not on amd-dev or main. #3492 makes the same Wine/vkd3d-proton fix against main: it ports #867 and #2477 and also adds in-place vtables, and its description points to this PR for the amd-dev side. The lines shared with #3111/#3112/#3335/#3361 are amd-dev history, not this change.
No problems found in the diff (read the guard/fence code in real.rs). The swap of a shared object's vtable during a host call is the riskiest part, and it only runs under Wine.
Recommendation: keep open.

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

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head b8ec6a4, diff read, not a merge-check; base amd-dev, conflicts with it, PR description red):

Fine: the Wine-only parts (UnadoptGuard::new, wrapping and unwrapping of fences) are gated, and the Wine runs in the description show what it fixes.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants