DirectStorage: EnqueueSignal takes a fence in memory VirtualQuery does not know #1803

Open
us3r40456 wants to merge 1 commit from upstream-pr/1813 into main
us3r40456 commented 2026-11-24 21:03:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by us3r40456 on 2026-11-24T21:03:36Z.


On a Mac, a DirectStorage fence is never signalled, so a title that waits on one waits forever. EnqueueSignal checks the fence and its table with gpu::shader::readable, which asks VirtualQuery. D3DMetal (CrossOver) keeps its D3D12 objects in memory that Wine's VirtualQuery does not know (the test title's fence is at 0x7fcc2d0f7540), so every fence is refused and its signal dropped, with nothing in the log. This PR reads the fence pointer and its table with read_own (ReadProcessMemory), the helper this file already uses for the page lists. It still refuses memory that cannot be read. Part of #258, found while testing #1329 there (https://github.com/xcl-dev/xcl/pull/1329#issuecomment-7139893893).

What is in it

  • crates/xcl/src/hle/dstorage.rs, queue_enqueue_signal: the fence's first word and the table's first 11 words are read with read_own. A null pointer, a null table or memory that cannot be read still enqueues nothing, as before. The Signal call itself is unchanged.
  • Test a_fence_of_the_hosts_d3d12_is_signalled: a fence from the host's D3D12 (WARP if there is no adapter, as in fence_x.rs) is taken by EnqueueSignal, and Submit signals it. A pointer to a reserved, uncommitted page is still not taken.

Tested

  • MacBook Pro, Apple M5 Pro (20-core GPU), 24 GB, macOS 27.2.1, Rosetta 2. CrossOver 26.3.0.39832 with D3DMetal 3.0. Cross-built with cargo-xwin 0.24.1 (Rust 1.100.0, clang-cl / lld 23.1.6), DXC 1.9.2609.
  • lib unit tests, debug, hle::dstorage:: one at a time (--test-threads=1), at this PR's head 4d19aed on main e9e94ce: 30 passed, 0 failed, the new test included (on the earlier base 9e3831e: 18 of 18).
  • The new test with the old queue_enqueue_signal (on 9e3831e) fails on D3DMetal: the host's fence was not taken (0 entries instead of 1). With this PR it passes.
  • The e2e test title (release, run as tests/e2e.rs runs it, with a fresh XCL_DATA_ROOT), with this change on the earlier base. Plain main stops on a Mac before the DirectStorage check, so this is on main 9e3831e + #750 + #1329 + Ahmet-Dedeler's pr/native-host-vtables (ddf3be7). With those, the title runs to its end:
    • without this PR: 46 PASS, 4 FAIL, including DirectStorage (xcrdapi): … the DirectStorage fence was not signalled;
    • with this PR: 47 PASS, 3 FAIL, and the DirectStorage check passes (3 runs with this version, 2 with an earlier IsBadReadPtr version). The other three are the window cloak (#1462), "no GPU timestamp" (#996) and XMA2 GetState (#890).

Regression run
This changes crates/xcl/src/hle, so it needs xcl-smoke pairs. I have no title. On Windows a D3D12 fence is in memory VirtualQuery knows, and both checks take it, so I expect nothing to change there. A Windows pair would confirm that, and a Mac pair would show the effect on a title. Draft until the pairs are here.

main:

PR:

Not tested

  • Windows and Linux / Wine with vkd3d-proton. The new test only needs a D3D12 device (WARP works), but I have not run it there.
  • The whole unit test suite; only hle::dstorage::.
  • A retail title.

AI use

  • Claude Code, Claude Opus 5.5 found the cause, wrote the change, the test and this description, and ran the tests on this machine.
<!-- greyfinch-sync:ivall/xcl:issue:5480295120 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1813). Originally posted by [us3r40456](https://github.com/us3r40456) on 2026-11-24T21:03:36Z. --- On a Mac, a DirectStorage fence is never signalled, so a title that waits on one waits forever. `EnqueueSignal` checks the fence and its table with `gpu::shader::readable`, which asks `VirtualQuery`. D3DMetal (CrossOver) keeps its D3D12 objects in memory that Wine's `VirtualQuery` does not know (the test title's fence is at `0x7fcc2d0f7540`), so every fence is refused and its signal dropped, with nothing in the log. This PR reads the fence pointer and its table with `read_own` (`ReadProcessMemory`), the helper this file already uses for the page lists. It still refuses memory that cannot be read. Part of #258, found while testing #1329 there (https://github.com/xcl-dev/xcl/pull/1329#issuecomment-7139893893). **What is in it** - `crates/xcl/src/hle/dstorage.rs`, `queue_enqueue_signal`: the fence's first word and the table's first 11 words are read with `read_own`. A null pointer, a null table or memory that cannot be read still enqueues nothing, as before. The Signal call itself is unchanged. - Test `a_fence_of_the_hosts_d3d12_is_signalled`: a fence from the host's D3D12 (WARP if there is no adapter, as in `fence_x.rs`) is taken by `EnqueueSignal`, and `Submit` signals it. A pointer to a reserved, uncommitted page is still not taken. **Tested** - MacBook Pro, Apple M5 Pro (20-core GPU), 24 GB, macOS 27.2.1, Rosetta 2. CrossOver 26.3.0.39832 with D3DMetal 3.0. Cross-built with cargo-xwin 0.24.1 (Rust 1.100.0, clang-cl / lld 23.1.6), DXC 1.9.2609. - lib unit tests, debug, `hle::dstorage::` one at a time (`--test-threads=1`), at this PR's head `4d19aed` on `main` `e9e94ce`: 30 passed, 0 failed, the new test included (on the earlier base `9e3831e`: 18 of 18). - The new test with the old `queue_enqueue_signal` (on `9e3831e`) fails on D3DMetal: `the host's fence was not taken` (0 entries instead of 1). With this PR it passes. - The e2e test title (release, run as `tests/e2e.rs` runs it, with a fresh `XCL_DATA_ROOT`), with this change on the earlier base. Plain `main` stops on a Mac before the DirectStorage check, so this is on `main` `9e3831e` + #750 + #1329 + Ahmet-Dedeler's `pr/native-host-vtables` (`ddf3be7`). With those, the title runs to its end: - without this PR: 46 PASS, 4 FAIL, including `DirectStorage (xcrdapi): … the DirectStorage fence was not signalled`; - with this PR: 47 PASS, 3 FAIL, and the DirectStorage check passes (3 runs with this version, 2 with an earlier `IsBadReadPtr` version). The other three are the window cloak (#1462), "no GPU timestamp" (#996) and XMA2 `GetState` (#890). **Regression run** This changes `crates/xcl/src/hle`, so it needs `xcl-smoke` pairs. I have no title. On Windows a D3D12 fence is in memory `VirtualQuery` knows, and both checks take it, so I expect nothing to change there. A Windows pair would confirm that, and a Mac pair would show the effect on a title. Draft until the pairs are here. main: PR: **Not tested** - Windows and Linux / Wine with vkd3d-proton. The new test only needs a D3D12 device (WARP works), but I have not run it there. - The whole unit test suite; only `hle::dstorage::`. - A retail title. **AI use** - Claude Code, Claude Opus 5.5 found the cause, wrote the change, the test and this description, and ran the tests on this machine.
us3r40456 commented 2026-11-24 22:06:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by us3r40456 on 2026-11-24T21:55:38Z.


Overlap with mac7. @Ahmet-Dedeler, your mac7 (dbd9d09) fixes the same thing more widely. In 105498f ("Mac host basics"), gpu::shader::readable probes memory by reading it, with IsBadReadPtr, when VirtualQuery reports it free and the host's D3D12 is native (NATIVE_HOST_MEMORY). That covers EnqueueSignal and every other readable caller, where this PR only changes EnqueueSignal.

On the test title, on this Mac (M5 Pro, CrossOver 26.3, D3DMetal), with mac7 + #615 + #750: the DirectStorage check passes without this PR. The title gets 48 PASS / 2 FAIL, the same in 2 runs. The two failures are the window cloak and Opus GetState: ctx=0x0, queued=1. Without #750, mac7 stops at the console-format shader check, the same D3DMetal crash #750 fixes.

So which do you prefer: will you send the readable change as its own PR, so I close this one in its favour, or should this one go on as the narrow fix until then? Either is fine with me.

AI use: Claude Code (Claude Opus 5.5) helped build, run and compare; the runs are on my Mac.

<!-- greyfinch-sync:ivall/xcl:comment:7145572275 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1813#issuecomment-7145572275). Originally posted by [us3r40456](https://github.com/us3r40456) on 2026-11-24T21:55:38Z. --- **Overlap with `mac7`.** @Ahmet-Dedeler, your `mac7` (`dbd9d09`) fixes the same thing more widely. In `105498f` ("Mac host basics"), `gpu::shader::readable` probes memory by reading it, with `IsBadReadPtr`, when `VirtualQuery` reports it free and the host's D3D12 is native (`NATIVE_HOST_MEMORY`). That covers `EnqueueSignal` and every other `readable` caller, where this PR only changes `EnqueueSignal`. On the test title, on this Mac (M5 Pro, CrossOver 26.3, D3DMetal), with `mac7` + #615 + #750: the DirectStorage check passes without this PR. The title gets 48 PASS / 2 FAIL, the same in 2 runs. The two failures are the window cloak and `Opus GetState: ctx=0x0, queued=1`. Without #750, `mac7` stops at the console-format shader check, the same D3DMetal crash #750 fixes. So which do you prefer: will you send the `readable` change as its own PR, so I close this one in its favour, or should this one go on as the narrow fix until then? Either is fine with me. AI use: Claude Code (Claude Opus 5.5) helped build, run and compare; the runs are on my Mac.
DavidM1911 commented 2026-11-25 01:10:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T00:28:10Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7148541300 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1813#issuecomment-7148541300). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T00:28:10Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Toons29 commented 2026-11-25 04:10:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:37:09Z.


Regression run of 4d19aed2 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 4d19aed29a13e54674fc551659a43683c8467577
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1629 (PresentX 1629)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14686 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 99 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7152083727 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1813#issuecomment-7152083727). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-25T03:37:09Z. --- Regression run of `4d19aed2` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: 4d19aed29a13e54674fc551659a43683c8467577 gpu: AMD Radeon RX 9070 title: 34df7c50 seconds: 60 exit: 0x0 frames shown: 1629 (PresentX 1629) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14686 MB ``` Against the limits in CONTRIBUTING.md: 101 % of `main`'s frames, 99 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; I checked the blocks before posting.
Foniass commented 2026-12-01 06:52:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:52:07Z.


Triage (#1607) – head 4d19aed

No open or merged PR makes the same change; main's queue_enqueue_signal in dstorage.rs still checks the fence with shader::readable (VirtualQuery). Reading the fence and vtable through the existing read_own is consistent with the rest of the file.
Problem: the new test a_fence_of_the_hosts_d3d12_is_signalled uses a Windows D3D12 fence, which VirtualQuery knows, so it also passes without the fix and does not exercise the CrossOver case it describes.
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:7303374714 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1813#issuecomment-7303374714). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:52:07Z. --- **Triage (#1607)** – head 4d19aed No open or merged PR makes the same change; main's `queue_enqueue_signal` in dstorage.rs still checks the fence with `shader::readable` (VirtualQuery). Reading the fence and vtable through the existing `read_own` is consistent with the rest of the file. Problem: the new test `a_fence_of_the_hosts_d3d12_is_signalled` uses a Windows D3D12 fence, which VirtualQuery knows, so it also passes without the fix and does not exercise the CrossOver case it describes. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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/1813:upstream-pr/1813'
git switch 'upstream-pr/1813'

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/1813'
git switch 'upstream-pr/1813'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1813'
git switch 'upstream-pr/1813'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1813'
git switch 'main'
git merge --squash 'upstream-pr/1813'
git switch 'main'
git merge --ff-only 'upstream-pr/1813'
git switch 'main'
git merge 'upstream-pr/1813'
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!1803
No description provided.