Skip to content

d3d12_xs: keep the fence slot 12 value current after a rewind - #7653

Closed
rison1337 wants to merge 2 commits into
ProjectLeonida:mainfrom
rison1337:fix/fence-slot12-rewind
Closed

rison1337 wants to merge 2 commits into
ProjectLeonida:mainfrom
rison1337:fix/fence-slot12-rewind

Conversation

@rison1337

Copy link
Copy Markdown

Claimed in the coordination issue.

Depends on: #7290. The base PR introduces the slot 12 mirror. This follow-up adds one commit on top of 5ac4deaa, 0cb3d3b.

Problem

The mirror can become stale after a D3D12 fence rewind. After completion at 40, the callback arms an event for 41. A CPU signal to 3 updates the mirror. A subsequent signal to 15 on the underlying fence never reaches 41, so the address returned by slot 12 still reads 3. Original review and reproduction.

Change

Use a thread-pool wait with a 10 ms timeout. The completion event still wakes the callback as before. A timeout refreshes the mirror without registering another completion event. Teardown cancels the wait and drains callbacks before releasing the fence and event.

Verification

CachyOS x86-64, Wine 11.20, clang/llvm-mingw, synthetic COM objects. The stock mock test passes on #7290. With the added test, #7290 failed five of five runs and this revision passed five of five. The regression covers CPU and external rewinds, progress below the outstanding threshold, and a later signal that satisfies the original event.

git diff --check and the game-data scan passed. The documentation link suite reports the same existing broken anchor in docs/dev-tools.md on the base and this branch. No retail run, native Windows run, or polling-overhead measurement. AI-assisted.

TreXito and others added 2 commits November 23, 2026 16:23
The retail executable calls fence slot 12, one past ID3D12Fence1, as
(value, descriptor, flags) and reads the return as a pointer to the
fence's 64-bit completed value: it compares it with ~0 and subtracts the
value it waits for. The proxy refused it with E_NOTIMPL, which the title
then dereferenced.

Each fence now gets a mirror on its first slot 12 call. A wait-thread
callback reads the real fence's completed value into it and re-arms
SetEventOnCompletion(value + 1), so it follows every completion without
another call; slot 12 and the CPU Signal refresh it at once, under a lock.
After device removal it holds ~0 and nothing is re-armed. The release of
the proxy unregisters the wait before the real fence goes. The
descriptor's code pointer is not called.

Tests: xs_proxy_mock_test (mock fences now keep a completed value and
arm one event) and queue_proxy_test (a real queue signal reaches the
mirror).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refresh the slot 12 mirror when the completion wait times out. Keep the existing pending fence event so a rewind cannot accumulate duplicate registrations.

The mock test covers a CPU rewind followed by progress below the old threshold and a rewind from outside the proxy. Original fails and patched passes in five runs each on Wine 11.20. AI-assisted.
@MartinIndra02

Copy link
Copy Markdown
Contributor

Independent Windows + GPU test of 0cb3d3bc1: pass.

Setup: Windows 11 x64, MSVC 19.44.35220 (RelWithDebInfo, Windows SDK 10.0.26100.0), NVIDIA GeForce RTX 3080 (driver 32.0.16.2124 / 621.24), Vulkan SDK 1.4.363.1, no game files.

  • xs_proxy_mock_test.exe: PASS (exit 0).
  • queue_proxy_test.exe (host WARP, host RTX 3080, Vulkan RTX 3080): PASS (exit 0).

AI-assisted review/test.

@AirKyzzZ

Copy link
Copy Markdown
Contributor

Tested 0cb3d3bc1 on RTX 2060 (NVIDIA 566.14), Windows 10 22H2, clang-cl 23.1.6 with the MSVC 14.44 STL, RelWithDebInfo: pass.

Built queue_proxy_test and xs_proxy_mock_test, ran ctest -R "^(queue_proxy|xs_proxy_mock)$": 2/2 pass. With the merge base's d3d12_xs_device.cpp/.h (8575d36ed) and this PR's tests, both end in a SegFault.

No game files. AI-assisted (Claude Code).

@optinium51-bot

optinium51-bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested 0cb3d3bc1 merged onto main f837d4fe9 (clean merge) on NVIDIA GeForce RTX 3060 (driver 616.92), Windows 11 26200, MSVC 14.52 (VS 2026), RelWithDebInfo + Ninja: pass.

No game files. AI-assisted (Claude Code).

@sgonzalez-glitch

Copy link
Copy Markdown

Tested 0cb3d3bc1 (as part of #7619, #7634, #7653, #7667, #7704 and #7723 merged together onto main a90a79bd8) on NVIDIA GeForce RTX 2080, driver 621.24 (32.0.16.2124), Windows 11, MSVC 19.44 RelWithDebInfo: pass.

AI-assisted: yes

@o-psi o-psi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Recommend keeping #7290 at d5fa829 and closing #7653. Independently rechecked source 0cb3d3b: its complete tree and rewind patch are identical to the authored cherry-pick 04fdf37. Both complete five-file merge-base diffs were compared; the current replacement preserves every source test, documentation change and rewind path, adding only the separate fence-event lifetime change and test. No unique contribution remains. Both heads are still open and unchanged. Git/source comparison on Linux; no new runtime/GPU tests. AI-assisted QA (Codex via T3).

@haayden

haayden commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Thanks for this fix, @rison1337. From the PR cleanup in #8919: the rewind commit here, 0cb3d3bc1, is also in #7290 as 04fdf377f, your own cherry-pick with the same tree. It is an ancestor of #7290's current head d5fa82948, and merging this branch into #7290 changes nothing. #7290 also adds the commit that keeps the fence mirror's event open while the real fence lives. Could you close this PR in favour of #7290, or say here if something in it isn't covered there? Triage line: #8919 (comment)

agent: yes

@ramenbellic

Copy link
Copy Markdown

Tested 0cb3d3b under Wine: Proton Experimental (wine 11), runtime cross-built with clang-cl 23.1.6 + xwin SDK 10.0.26100 (RelWithDebInfo), merged onto main dfe4e4ad3: pass

  • Build: OK with clang-cl.
  • The tests this PR adds or touches, under Proton: 7 passed, 0 skipped, 0 failed (of 7).

AI-assisted run (Claude Code); no game files used.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants