D3D12.X: check at start-up that the GPU sees CPU writes to unified memory #220

Manually merged
github merged 1 commit from gh-pr/220/head into gh-pr/220/base 2026-11-26 04:16:06 +00:00
Owner

@⁠Kalmarv on GitHub · 2026-11-23 21:15 UTC · original
Kalmarv:fix/uma-import-check → main · +101 −0 · 2 files · 1 commits · merged 2026-11-23 21:24 UTC

XCL's coherent UMA windows reach the GPU through OpenExistingHeapFromAddress. A runtime that can't import the memory may still return success with memory of its own. vkd3d-proton does this under a Wine without userfaultfd write watches (#175): vkd3d_import_host_memory logs a WARN and falls back to a separate allocation. Shaders then read zeros where the title wrote, and XCL's log shows nothing. On such a stack five gpu::recomp memory-window tests fail that way.

Change

In open_uma (hle/d3d12x/real.rs), after the coherent windows are opened:

  • Take a block of each coherent window from the UMA allocator (alloc_in), so no title data is touched. Write a canary word (0x58434C00 | window), copy it on the GPU into a readback buffer, compare, and free the block.
  • A mismatch is logged with xlog_error!, naming the likely cause, for example: "the GPU does not see what the CPU writes to unified memory (window 3: wrote 0x58434c03, the GPU read 0x0): the host-memory import fell back to memory of its own (Wine without userfaultfd write watches?) …".
  • It is recorded in report.json as d3d12.uma_import_check: "ok, N window(s), T µs", "off (XCL_UMA_CHECK=0)", or the failure. The new field is #[serde(default)].
  • On by default; XCL_UMA_CHECK=0 turns it off.
  • It only reports: nothing changes in how UMA is used.

Test: gpu_uma_import_check_at_init runs real::init() and expects ok (or off).

Tested

Linux: Ubuntu 24.04, RTX 2060 (Turing), NVIDIA 595.91.07, Wine 11.21 Staging (Kron4ek wow64), vkd3d-proton master 30b0eb9 relaxed as in #175, DXVK 3.1.1 dxgi. Cross-built for x86_64-pc-windows-gnu, release, no warnings.

Build / setting gpu_uma_import_check_at_init Logged
this branch FAIL, as intended (this stack has the fallback) UMA import check: the GPU does not see … (window 3: wrote 0x58434c03, the GPU read 0x0) …
this branch, XCL_UMA_CHECK=0 pass UMA import check: off (XCL_UMA_CHECK=0)
this branch with MEM_WRITE_WATCH = 0 in gpu/uma.rs (experiment only: the import then works on this stack) pass, 3 of 3 runs UMA import check: ok, 1 window(s) in 5655 / 5001 / 4760 µs

Cost on this stack is about 5 ms once at device creation, mostly the queue, list and fence through vkd3d-proton and Wine.

Windows: Windows 11 Pro 26200, RTX 5070 Ti, NVIDIA 610.74, MSVC release, cargo test --release -p xcl --lib gpu_uma_import_check_at_init -- --nocapture --test-threads=1: pass 3 of 3, logged UMA import check: ok, 1 window(s) in 20 388 / 20 706 / 28 997 µs (once, at device creation). Runs 1–2 were at 2558a2f on main 956a476, run 3 after the rebase on 6da33fa (5ceb8fc).

Not tested

  • The check writes into a fresh UMA block, which marks that page in the write watch once. No texture lives there at that point.
  • Not run with a title, in the e2e binaries, or on AMD.
  • Sparse VRAM windows aren't checked: they aren't imported host memory.
  • One small gap in the check itself: if a window's buffer can't be borrowed for the copy, that probe still counts and would report a false mismatch. It hasn't happened in any run.

AI use: Claude Code, Claude Opus 5.5 (written and Linux-tested by one agent, Windows run by another).

Closes nothing; follows #175.

**@⁠Kalmarv** on GitHub · 2026-11-23 21:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/220) `Kalmarv:fix/uma-import-check` → `main` · +101 −0 · 2 files · 1 commits · merged 2026-11-23 21:24 UTC XCL's coherent UMA windows reach the GPU through `OpenExistingHeapFromAddress`. A runtime that can't import the memory may still return success with memory of its own. vkd3d-proton does this under a Wine without `userfaultfd` write watches (#175): `vkd3d_import_host_memory` logs a WARN and falls back to a separate allocation. Shaders then read zeros where the title wrote, and XCL's log shows nothing. On such a stack five `gpu::recomp` memory-window tests fail that way. ### Change In `open_uma` (`hle/d3d12x/real.rs`), after the coherent windows are opened: - Take a block of each coherent window from the UMA allocator (`alloc_in`), so no title data is touched. Write a canary word (`0x58434C00 | window`), copy it on the GPU into a readback buffer, compare, and free the block. - A mismatch is logged with `xlog_error!`, naming the likely cause, for example: "the GPU does not see what the CPU writes to unified memory (window 3: wrote 0x58434c03, the GPU read 0x0): the host-memory import fell back to memory of its own (Wine without userfaultfd write watches?) …". - It is recorded in `report.json` as `d3d12.uma_import_check`: `"ok, N window(s), T µs"`, `"off (XCL_UMA_CHECK=0)"`, or the failure. The new field is `#[serde(default)]`. - On by default; `XCL_UMA_CHECK=0` turns it off. - It only reports: nothing changes in how UMA is used. Test: `gpu_uma_import_check_at_init` runs `real::init()` and expects `ok` (or `off`). ### Tested Linux: Ubuntu 24.04, RTX 2060 (Turing), NVIDIA 595.91.07, Wine 11.21 Staging (Kron4ek wow64), vkd3d-proton `master` 30b0eb9 relaxed as in #175, DXVK 3.1.1 `dxgi`. Cross-built for `x86_64-pc-windows-gnu`, release, no warnings. | Build / setting | `gpu_uma_import_check_at_init` | Logged | |---|---|---| | this branch | **FAIL, as intended** (this stack has the fallback) | `UMA import check: the GPU does not see … (window 3: wrote 0x58434c03, the GPU read 0x0) …` | | this branch, `XCL_UMA_CHECK=0` | pass | `UMA import check: off (XCL_UMA_CHECK=0)` | | this branch with `MEM_WRITE_WATCH` = 0 in `gpu/uma.rs` (experiment only: the import then works on this stack) | pass, 3 of 3 runs | `UMA import check: ok, 1 window(s)` in 5655 / 5001 / 4760 µs | Cost on this stack is about 5 ms once at device creation, mostly the queue, list and fence through vkd3d-proton and Wine. Windows: Windows 11 Pro 26200, RTX 5070 Ti, NVIDIA 610.74, MSVC release, `cargo test --release -p xcl --lib gpu_uma_import_check_at_init -- --nocapture --test-threads=1`: pass 3 of 3, logged `UMA import check: ok, 1 window(s)` in 20 388 / 20 706 / 28 997 µs (once, at device creation). Runs 1–2 were at 2558a2f on main 956a476, run 3 after the rebase on 6da33fa (5ceb8fc). ### Not tested - The check writes into a fresh UMA block, which marks that page in the write watch once. No texture lives there at that point. - Not run with a title, in the e2e binaries, or on AMD. - Sparse VRAM windows aren't checked: they aren't imported host memory. - One small gap in the check itself: if a window's buffer can't be borrowed for the copy, that probe still counts and would report a false mismatch. It hasn't happened in any run. **AI use:** Claude Code, Claude Opus 5.5 (written and Linux-tested by one agent, Windows run by another). Closes nothing; follows #175.
The coherent UMA windows reach the GPU through OpenExistingHeapFromAddress. A runtime
that cannot import the memory may still return success with memory of its own:
vkd3d-proton does so under a Wine without userfaultfd write watches (#175), and
shaders then read zeros where the title wrote, with nothing in XCL's log.

open_uma now writes a word into a block of each coherent window, copies it out on
the GPU and compares. A mismatch is logged as an error naming the likely cause and
recorded in report.json (d3d12.uma_import_check: "ok, N window(s), T µs", "off" or
the failure). XCL_UMA_CHECK=0 turns it off. gpu_uma_import_check_at_init covers it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:16:02 +00:00
github manually merged commit 5ceb8fcf59 into gh-pr/220/base 2026-11-26 04:16:06 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 21:24 UTC · original

Merged (main d4f17ca). Checked on an RX 9070 (RDNA4) with 11 PRs merged together on main af20b4b: cargo build --workspace && cargo test --workspace -- --test-threads=4 - 605 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed; and the retail game still reaches its first menu at 30 fps (720 draws per 2 s).

**@⁠ivall** on GitHub · 2026-11-23 21:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/220#issuecomment-7114417963) Merged (main d4f17ca). Checked on an RX 9070 (RDNA4) with 11 PRs merged together on main af20b4b: `cargo build --workspace && cargo test --workspace -- --test-threads=4` - 605 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed; and the retail game still reaches its first menu at 30 fps (720 draws per 2 s).
This discussion has been locked. Commenting is limited to contributors.
No description provided.