d3d12: refuse section-backed imports that RADV silently substitutes #199

Open
github-bot wants to merge 2 commits from github-bot/gh-199 into main AGit
Owner

@⁠smith-3 on GitHub · 2026-11-25 21:11 UTC · original
smith-3:codex/radv-section-import-probe → main · +141 −7 · 5 files · 2 commits · open

On RADV, every GPU import of XMem physical pages silently reads zeros. XMem pages are section views, which Wine maps as shared memory. RADV refuses shared memory as a host pointer, and vkd3d-proton then allocates unrelated memory while OpenExistingHeapFromAddress still succeeds. Strict mode (TUXBOX_REQUIRE_BUFFER_IMPORT=1) does not notice, because a CPU Map of the heap still returns the guest pointer. This matches the buffer-remap failure in #189.

This PR probes once per device with a GPU copy from an imported section view. When the copy misses the canary, imports of section-backed ranges fail with E_NOTIMPL and a log line, instead of aliasing nothing. If the probe itself cannot run, the previous behaviour is kept. The first commit only improves the buffer-remap diagnostic so it reports every wrong copy.

This does not make AMD work. XMem-backed buffers still cannot be imported on RADV. They now fail visibly instead of reading zeros. A real fix needs private (non-shared) backing for guest pages or a different import path, and is out of scope here.

Evidence

Ryzen 7 9700X iGPU (1002:13c0, RADV 25.2.8) and RTX 4080 SUPER (10de:2702, NVIDIA 570.211.01), same machine, Proton Experimental 11.0-20261014.

buffer-remap control:

Runtime AMD 1002:13c0 RTX 10de:2702
main + diagnostic copy 0: 256/256 wrong, [0]=0 expected 0x12340000; copy 1: 256/256 wrong ...; copy 2: 256/256 wrong, [0]=0 expected 0x98760000 PASS words=768/768 identical=1 replacement=1
this PR place remapped buffer failed: 0x80004001, plus the log line below PASS words=768/768 identical=1 replacement=1
TuxBox d3d12_xs: the host driver does not import section-backed guest memory: the GPU read unrelated memory after a successful import. Imports of XMem physical pages fail with E_NOTIMPL

Wine trace on AMD before the fix:

win32u_vkAllocateMemory Failed to allocate memory, res -13
vkd3d-proton:vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000e.

Native Vulkan probe (VK_EXT_external_memory_host, vkAllocateMemory result). vkGetMemoryHostPointerPropertiesEXT succeeds in every case, so it cannot predict the failure.

Mapping NVIDIA RADV
anonymous private 0 0
memfd shared 0 -13
anonymous shared 0 -13

Checks

  • Rust tests, D3D12 Windows typecheck and the build pass in tuxbox.py check.
  • D3D12 regression controls on the RTX all pass: tables, heaps, placement, stream, frame, indirect, null-usage and null-disabled.
  • I did not run the guest GPU suites of tuxbox.py check (Lanes, shader translator). Proton's steam.exe aborts in lsteamclient when the Steam client is not running on this machine. The change only affects imports of section-backed memory on drivers that fail the probe, and NVIDIA passes the probe.

🤖 Generated with Claude Code

**@⁠smith-3** on GitHub · 2026-11-25 21:11 UTC · [original](https://github.com/brcly/TuxBox/pull/199) `smith-3:codex/radv-section-import-probe` → `main` · +141 −7 · 5 files · 2 commits · open On RADV, every GPU import of XMem physical pages silently reads zeros. XMem pages are section views, which Wine maps as shared memory. RADV refuses shared memory as a host pointer, and vkd3d-proton then allocates unrelated memory while `OpenExistingHeapFromAddress` still succeeds. Strict mode (`TUXBOX_REQUIRE_BUFFER_IMPORT=1`) does not notice, because a CPU `Map` of the heap still returns the guest pointer. This matches the `buffer-remap` failure in #189. This PR probes once per device with a GPU copy from an imported section view. When the copy misses the canary, imports of section-backed ranges fail with `E_NOTIMPL` and a log line, instead of aliasing nothing. If the probe itself cannot run, the previous behaviour is kept. The first commit only improves the `buffer-remap` diagnostic so it reports every wrong copy. **This does not make AMD work.** XMem-backed buffers still cannot be imported on RADV. They now fail visibly instead of reading zeros. A real fix needs private (non-shared) backing for guest pages or a different import path, and is out of scope here. ### Evidence Ryzen 7 9700X iGPU (`1002:13c0`, RADV 25.2.8) and RTX 4080 SUPER (`10de:2702`, NVIDIA 570.211.01), same machine, Proton Experimental 11.0-20261014. `buffer-remap` control: | Runtime | AMD `1002:13c0` | RTX `10de:2702` | | --- | --- | --- | | main + diagnostic | `copy 0: 256/256 wrong, [0]=0 expected 0x12340000; copy 1: 256/256 wrong ...; copy 2: 256/256 wrong, [0]=0 expected 0x98760000` | `PASS words=768/768 identical=1 replacement=1` | | this PR | `place remapped buffer failed: 0x80004001`, plus the log line below | `PASS words=768/768 identical=1 replacement=1` | ``` TuxBox d3d12_xs: the host driver does not import section-backed guest memory: the GPU read unrelated memory after a successful import. Imports of XMem physical pages fail with E_NOTIMPL ``` Wine trace on AMD before the fix: ``` win32u_vkAllocateMemory Failed to allocate memory, res -13 vkd3d-proton:vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000e. ``` Native Vulkan probe (`VK_EXT_external_memory_host`, `vkAllocateMemory` result). `vkGetMemoryHostPointerPropertiesEXT` succeeds in every case, so it cannot predict the failure. | Mapping | NVIDIA | RADV | | --- | --- | --- | | anonymous private | 0 | 0 | | memfd shared | 0 | -13 | | anonymous shared | 0 | -13 | ### Checks - Rust tests, D3D12 Windows typecheck and the build pass in `tuxbox.py check`. - D3D12 regression controls on the RTX all pass: tables, heaps, placement, stream, frame, indirect, null-usage and null-disabled. - I did not run the guest GPU suites of `tuxbox.py check` (Lanes, shader translator). Proton's `steam.exe` aborts in `lsteamclient` when the Steam client is not running on this machine. The change only affects imports of section-backed memory on drivers that fail the probe, and NVIDIA passes the probe. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The remap check stopped at the first differing word. It now reports
each of the three copies that read wrong data, with the count and the
first bad word, so a failure shows whether one alias or every import
read unrelated memory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
XMem physical pages are section views, which Wine maps as shared
memory. RADV rejects shared memory as a host pointer (VK error -13),
and vkd3d-proton then allocates unrelated memory while still reporting
a successful import. The GPU reads zeros where the title wrote data,
and neither the import result nor a CPU Map of the heap shows it.

Probe once per device with a GPU copy from an imported section view.
When the copy does not read the canary, imports of section-backed
ranges fail with E_NOTIMPL instead of silently aliasing nothing. A
probe that cannot run keeps the previous behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:37:53 +00:00
Author
Owner

@⁠tsunderejay on GitHub · 2026-11-25 21:23 UTC · original

Static review found a blocking lifetime issue: the fence is created after submission, so CreateFence/Signal/SetEventOnCompletion failure can return and unmap the section while the GPU copy is still running. Create the fence before submission and ensure every post-submit path waits (or retains the mapping/objects). Also add a bounded wait so a stuck probe cannot hang the title. The remap diagnostic counter has a separate bug: actual != expected && !wrong++ stops incrementing after the first mismatch, so it reports 1/256 instead of 256/256.

**@⁠tsunderejay** on GitHub · 2026-11-25 21:23 UTC · [original](https://github.com/brcly/TuxBox/pull/199#issuecomment-7175014527) Static review found a blocking lifetime issue: the fence is created after submission, so CreateFence/Signal/SetEventOnCompletion failure can return and unmap the section while the GPU copy is still running. Create the fence before submission and ensure every post-submit path waits (or retains the mapping/objects). Also add a bounded wait so a stuck probe cannot hang the title. The remap diagnostic counter has a separate bug: `actual != expected && !wrong++` stops incrementing after the first mismatch, so it reports 1/256 instead of 256/256.
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 21:11 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 21:11 UTC · [original](https://github.com/brcly/TuxBox/pull/199#pullrequestreview-6065046483) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
This pull request has changes conflicting with the target branch.
  • runtime/d3d12/src/device/heap/import.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/199/head:github-bot/gh-199'
git switch 'github-bot/gh-199'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-199'
git switch 'github-bot/gh-199'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-199'
git switch 'github-bot/gh-199'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-199'
git switch 'main'
git merge --squash 'github-bot/gh-199'
git switch 'main'
git merge --ff-only 'github-bot/gh-199'
git switch 'main'
git merge 'github-bot/gh-199'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.