gpu: check the CPU/GPU range translation against a desktop D3D12 heap #905

Merged
lukaslw-lab merged 2 commits from upstream-pr/912 into main 2026-11-23 17:25:29 +00:00
lukaslw-lab commented 2026-11-23 16:55:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T16:55:39Z.


Change

Adds the translation test requested on #874 after #891. A source-built consumer mirrors the main executable's CPU/GPU range helpers against desktop D3D12. On the CPU→GPU path, gpu = cpu - A + B. On the GPU→CPU path, an address in [B, B + size) maps to gpu - B + A and anything else passes through. Refs #874, #870.

  • vm_translation_shared_range: the no-device case, kept separate. A and B are one range, so both directions are the identity, and addresses just outside pass through.
  • vm_translation_device_warp / _hardware: a committed 64 MiB range is opened once with ID3D12Device3::OpenExistingHeapFromAddress, with one cross-adapter buffer placed over all of it. That buffer's GPU address is B. The compute shader receives only root UAV addresses computed from CPU pointers or taken from a live resource.

No shim export is added; the production D3D12ConfigureVirtualMemoryX behavior stays open. The device helper tests/xmem_test_device.h is reused unchanged apart from its comment.

Verification

Commit b68ef35 on Windows 10 22H2 (build 19045), Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7. D3D12 10.0.19041.7291. GPUs: NVIDIA GeForce RTX 3080 Ti (driver 32.0.16.1047) and in-box WARP 10.0.19041.7811.

ctest --preset dev --no-tests=error -R '^(vm_translation_.*|d3d12_xs_shim_.*|xmem_shim_working_set_.*|cpu_native_configure_vm|docs_links)$'
12 total: 12 passed, 0 skipped, 0 failed

The same with --preset release: 12 passed, 0 skipped, 0 failed. tests/bidi_controls_check.py and tests/docs_links_check.py passed.

vm_translation_check device_hardware (Release), abridged:

reserve-only range hr=0x80070057
interior address hr=0x80070057
committed range hr=0x00000000
ok GPU reads CPU-written words and writes CPU-visible words through p - A + B
placed buffer at +0x200000: gpu - B = 0x200000
ok GPU writes through the live resource's address are visible at the translated CPU address
ok an unrelated buffer's GPU address lies outside [B, B + size) and passes through untranslated
B shifted by 64 KiB: 1024/1024 words wrong at the intended destination
vm_translation device_hardware: PASS

WARP gives the same lines.

Evidence and follow-up

  • Fixture: source-built (C++, HLSL compiled by DXC at build time), MIT. The A/B layout and both helpers come from the static read posted on #874. No title bytes are included.
  • Controls:
    • mismatched range: an unrelated committed buffer passes through untranslated;
    • wrong base: B shifted by 64 KiB leaves all 1,024 intended words unwritten;
    • refusals: a reserve-only range and an interior address fail to open with E_INVALIDARG.
  • Mutations: replacing the GPU→CPU helper with three wrong versions made the device tests fail: no range check, dropping the offset, and always passing through. The last one first crashed on the bogus pointer, so the test now reports a translation mismatch without dereferencing it.
  • Measured constraints:
    • one GPU base needs all of A committed and wrapped once;
    • two separately wrapped allocations got different GPU bases in a local probe;
    • committing the full 16/24 GiB up front would exceed this PC's commit limit (27.5 GiB, about 22.7 GiB in use);
    • the placed buffer reporting B + offset is observed on both adapters; D3D12 does not document it.
  • Follow-up:
    • how a production path makes the title's B equal the wrapped buffer's GPU address, given that B is reserved before the device exists;
    • whether pages mapped later (#902, the mapping work after #880) can share one wrapped range.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6564367158 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/912). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-23T16:55:39Z. --- ## Change Adds the translation test requested on #874 after #891. A source-built consumer mirrors the main executable's CPU/GPU range helpers against desktop D3D12. On the CPU→GPU path, `gpu = cpu - A + B`. On the GPU→CPU path, an address in `[B, B + size)` maps to `gpu - B + A` and anything else passes through. Refs #874, #870. - `vm_translation_shared_range`: the no-device case, kept separate. A and B are one range, so both directions are the identity, and addresses just outside pass through. - `vm_translation_device_warp` / `_hardware`: a committed 64 MiB range is opened once with `ID3D12Device3::OpenExistingHeapFromAddress`, with one cross-adapter buffer placed over all of it. That buffer's GPU address is B. The compute shader receives only root UAV addresses computed from CPU pointers or taken from a live resource. No shim export is added; the production `D3D12ConfigureVirtualMemoryX` behavior stays open. The device helper `tests/xmem_test_device.h` is reused unchanged apart from its comment. ## Verification Commit `b68ef35` on Windows 10 22H2 (build 19045), Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7. D3D12 10.0.19041.7291. GPUs: NVIDIA GeForce RTX 3080 Ti (driver 32.0.16.1047) and in-box WARP 10.0.19041.7811. ctest --preset dev --no-tests=error -R '^(vm_translation_.*|d3d12_xs_shim_.*|xmem_shim_working_set_.*|cpu_native_configure_vm|docs_links)$' 12 total: 12 passed, 0 skipped, 0 failed The same with `--preset release`: 12 passed, 0 skipped, 0 failed. `tests/bidi_controls_check.py` and `tests/docs_links_check.py` passed. `vm_translation_check device_hardware` (Release), abridged: reserve-only range hr=0x80070057 interior address hr=0x80070057 committed range hr=0x00000000 ok GPU reads CPU-written words and writes CPU-visible words through p - A + B placed buffer at +0x200000: gpu - B = 0x200000 ok GPU writes through the live resource's address are visible at the translated CPU address ok an unrelated buffer's GPU address lies outside [B, B + size) and passes through untranslated B shifted by 64 KiB: 1024/1024 words wrong at the intended destination vm_translation device_hardware: PASS WARP gives the same lines. ## Evidence and follow-up - **Fixture:** source-built (C++, HLSL compiled by DXC at build time), MIT. The A/B layout and both helpers come from the static read posted on #874. No title bytes are included. - **Controls:** - mismatched range: an unrelated committed buffer passes through untranslated; - wrong base: B shifted by 64 KiB leaves all 1,024 intended words unwritten; - refusals: a reserve-only range and an interior address fail to open with `E_INVALIDARG`. - **Mutations:** replacing the GPU→CPU helper with three wrong versions made the device tests fail: no range check, dropping the offset, and always passing through. The last one first crashed on the bogus pointer, so the test now reports a translation mismatch without dereferencing it. - **Measured constraints:** - one GPU base needs all of A committed and wrapped once; - two separately wrapped allocations got different GPU bases in a local probe; - committing the full 16/24 GiB up front would exceed this PC's commit limit (27.5 GiB, about 22.7 GiB in use); - the placed buffer reporting `B + offset` is observed on both adapters; D3D12 does not document it. - **Follow-up:** - how a production path makes the title's B equal the wrapped buffer's GPU address, given that B is reserved before the device exists; - whether pages mapped later (#902, the mapping work after #880) can share one wrapped range. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:22 +00:00
R0Y00 commented 2026-11-24 06:49:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T17:02:30Z.


The range and shifted-window control look useful. One lifetime issue needs fixing on this candidate: device_checks releases A while whole and heap are still alive, including the branch where CreatePlacedResource fails after the heap opens. Wait for any submitted work, then release the resource and heap before freeing the backing allocation on every path. Also make a failed reserve-only VirtualAlloc a setup error so the negative cannot pass by testing nullptr. Please rerun shared range and WARP/hardware after this change and report any capability skip separately.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7108059921 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/912#issuecomment-7108059921). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T17:02:30Z. --- The range and shifted-window control look useful. One lifetime issue needs fixing on this candidate: device_checks releases A while whole and heap are still alive, including the branch where CreatePlacedResource fails after the heap opens. Wait for any submitted work, then release the resource and heap before freeing the backing allocation on every path. Also make a failed reserve-only VirtualAlloc a setup error so the negative cannot pass by testing nullptr. Please rerun shared range and WARP/hardware after this change and report any capability skip separately.
lukaslw-lab commented 2026-11-24 06:49:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T17:07:28Z.


Fixed in af0590a.

  • Lifetime: each VirtualAlloc range is owned by a holder declared before the heap and the resources that use it, so they are destroyed first. A guard declared after them waits for all submitted work. On every return, including a failed placement after the heap opened and the 77 skip, the order is: wait for idle, release the resources and heap, free the range.
  • Reserve-only setup: a failed reserve-only VirtualAlloc now returns 1 with setup error: reserve-only VirtualAlloc failed, before any heap call. The committed range gets the same treatment.

Checks at af0590a on the same machine (Windows 10 19045, RTX 3080 Ti driver 32.0.16.1047, in-box WARP 10.0.19041.7811):

ctest --preset dev --no-tests=error -R '^vm_translation_'
3 total: 3 passed, 0 skipped, 0 failed

--preset release gave 3 passed, 0 skipped, 0 failed. vm_translation_shared_range, vm_translation_device_warp and vm_translation_device_hardware each passed, with no capability skips.

Failure path: a local build that places the buffer at an invalid offset, after the heap has opened, exits with 1 on both adapters (FAIL wrap the committed range and place one buffer over it). It doesn't crash, and it releases everything in order. The unchanged source passes again.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7108184659 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/912#issuecomment-7108184659). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-23T17:07:28Z. --- Fixed in `af0590a`. - **Lifetime:** each `VirtualAlloc` range is owned by a holder declared before the heap and the resources that use it, so they are destroyed first. A guard declared after them waits for all submitted work. On every return, including a failed placement after the heap opened and the 77 skip, the order is: wait for idle, release the resources and heap, free the range. - **Reserve-only setup:** a failed reserve-only `VirtualAlloc` now returns 1 with `setup error: reserve-only VirtualAlloc failed`, before any heap call. The committed range gets the same treatment. Checks at `af0590a` on the same machine (Windows 10 19045, RTX 3080 Ti driver 32.0.16.1047, in-box WARP 10.0.19041.7811): ctest --preset dev --no-tests=error -R '^vm_translation_' 3 total: 3 passed, 0 skipped, 0 failed `--preset release` gave 3 passed, 0 skipped, 0 failed. `vm_translation_shared_range`, `vm_translation_device_warp` and `vm_translation_device_hardware` each passed, with no capability skips. Failure path: a local build that places the buffer at an invalid offset, after the heap has opened, exits with 1 on both adapters (`FAIL wrap the committed range and place one buffer over it`). It doesn't crash, and it releases everything in order. The unchanged source passes again. _AI-assisted (Claude Code)._
R0Y00 commented 2026-11-24 06:49:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T17:12:55Z.


Independent check of af0590a: Windows 11 26200.9974, RTX 4060 Laptop (616.56), and in-box WARP. The fixture does not enable the debug layer. The shared-range, WARP and hardware cases passed 3/3 in both Debug and Release. The hardware run observed distinct CPU/GPU bases, preserved the +0x200000 placement offset, and the +64 KiB mutation missed all 1,024 intended words. The new lifetime order addresses my review finding.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7108322970 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/912#issuecomment-7108322970). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T17:12:55Z. --- Independent check of af0590a: Windows 11 26200.9974, RTX 4060 Laptop (616.56), and in-box WARP. The fixture does not enable the debug layer. The shared-range, WARP and hardware cases passed 3/3 in both Debug and Release. The hardware run observed distinct CPU/GPU bases, preserved the +0x200000 placement offset, and the +64 KiB mutation missed all 1,024 intended words. The new lifetime order addresses my review finding.
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
R0Y00/Xbox2Windows!905
No description provided.