runtime: check the GPU range windows without a device #1507

Merged
Asimmimx merged 1 commit from upstream-pr/1514 into main 2026-11-24 13:48:43 +00:00
Asimmimx commented 2026-11-24 13:25:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T13:25:00Z.


Change

Refs #874. This adds a device-free check for src/d3d12_xs_range.{h,cpp}, the desktop stand-in for the GPU range a D3D12ConfigureVirtualMemoryX configuration describes.

d3d12_xs_range::create reserves the range as reserved buffers ("windows") no larger than the adapter's per-resource limit. GetGPUVirtualAddress(offset, bytes) may return an address only when the whole span lies inside one window; a 0-byte span counts as 1.

The module's only test user is tests/vm_translation_check.cpp. On WARP, which reports 32 bits per resource, it builds nine windows of 4095 MiB with an 8 MiB last window. Five single-point mutants left the six WARP and device-free vm_translation tests passing:

  • a span that crosses a window edge by one byte gets an address;
  • a span that ends one byte past the range gets an address;
  • a 0-byte span gets no address;
  • the last window is requested at the full window size instead of the remainder;
  • a failed CheckFeatureSupport returns E_FAIL instead of its own HRESULT.

The first two hand a shader an address whose span runs past the reserved buffer.

d3d12_xs_range drives create through the injectable CreateWindowFn, so it needs no GPU:

  • A fake device answers only CheckFeatureSupport. It is a vtable with that method in slot 13; tests/cpu/dstorage_provider.cpp uses the same pattern. Any other call counts as unexpected and fails the test.
  • Fake counted ID3D12Resource windows start at (i + 1) << 44. The fake can fail on a chosen call and stops after 16 requests.
  • Expected values are worked by hand. With 32 bits and a size of 2 × (4 GiB − 64 KiB) + 192 KiB, the requested widths are 0xFFFF0000, 0xFFFF0000 and 0x30000.

It checks:

  • each span against the exact expected address: spans ending at or crossing a window edge or the range end, 0-byte spans and overflowing spans;
  • window references through GetWindow, Close() and a second Close(), with no window released twice;
  • 40 bits (4 GiB windows) and 17 bits (64 KiB windows);
  • refusal of a null output, a null device, size 0, two unaligned sizes, 2^64 − 64 KiB (more than UINT windows) and a failed feature query;
  • window creation failing at calls 1, 2 and 3, each leaving no window alive.

d3d12_xs_range_full_last_window_control runs --mutate full_last_window and must fail (WILL_FAIL).

The change is test, CMake and docs/experiments.md (the #874 range section) only. The CMake block follows the vm_translation registrations.

Verification

Commit 3c6273ac (main) plus this change, dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0, WARP 10.0.26100.9818.

ctest --preset dev --no-tests=error -R '^(d3d12_xs_range.*|vm_translation_.*(warp|shared_range))$' -V
#   8/8 passed, including the control (fails as intended); d3d12_xs_range runs in about 0.01 s

tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check passed.

Mutation probe

I applied each mutation to src/d3d12_xs_range.cpp alone, rebuilt, ran the tests, then reverted. None of this is committed.

Mutant Existing (6 WARP/device-free vm_translation) d3d12_xs_range
control: window-edge check removed killed fails
window not capped by the adapter limit killed fails
per-resource limit without - 64 KiB killed fails
last window requested at full window size survived fails
span ending 1 byte past the range accepted survived fails
span crossing a window edge by 1 byte accepted survived fails
0-byte span returns 0 survived fails
CheckFeatureSupport failure returned as E_FAIL survived fails
size not a multiple of 64 KiB accepted killed fails
window count above UINT not refused killed only by a 46 s timeout fails
no Release on a mid-way failure killed fails
failed window HRESULT skipped killed fails
GetWindow without AddRef killed fails
GetWindow accepts index == count killed by timeout or crash fails
Close leaves size_ set killed fails
count truncated (size / window) killed by timeout fails
if (!bytes) bytes = 1; deleted survived survived (equivalent)
minimum bits < 17 → < 16 survived survived (not pinned)
>= 64 → > 64 survived survived (not pinned)

Notes on the last three rows:

  • if (!bytes) bytes = 1; deleted. This is equivalent: once offset < size_ and the offset lies inside a window, a 1-byte span always fits.
  • < 17 → < 16. Fewer than 17 bits per resource would mean a 0-byte window, which no real adapter reports.
  • >= 64 → > 64. 1 << 64 is undefined behaviour, and on x64 the mutant behaves the same as the original.

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 (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582798983 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1514). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T13:25:00Z. --- ## Change Refs #874. This adds a device-free check for `src/d3d12_xs_range.{h,cpp}`, the desktop stand-in for the GPU range a `D3D12ConfigureVirtualMemoryX` configuration describes. `d3d12_xs_range::create` reserves the range as reserved buffers ("windows") no larger than the adapter's per-resource limit. `GetGPUVirtualAddress(offset, bytes)` may return an address only when the whole span lies inside one window; a 0-byte span counts as 1. The module's only test user is `tests/vm_translation_check.cpp`. On WARP, which reports 32 bits per resource, it builds nine windows of 4095 MiB with an 8 MiB last window. Five single-point mutants left the six WARP and device-free `vm_translation` tests passing: - a span that crosses a window edge by one byte gets an address; - a span that ends one byte past the range gets an address; - a 0-byte span gets no address; - the last window is requested at the full window size instead of the remainder; - a failed `CheckFeatureSupport` returns `E_FAIL` instead of its own HRESULT. The first two hand a shader an address whose span runs past the reserved buffer. `d3d12_xs_range` drives `create` through the injectable `CreateWindowFn`, so it needs no GPU: - A fake device answers only `CheckFeatureSupport`. It is a vtable with that method in slot 13; `tests/cpu/dstorage_provider.cpp` uses the same pattern. Any other call counts as unexpected and fails the test. - Fake counted `ID3D12Resource` windows start at `(i + 1) << 44`. The fake can fail on a chosen call and stops after 16 requests. - Expected values are worked by hand. With 32 bits and a size of 2 × (4 GiB − 64 KiB) + 192 KiB, the requested widths are `0xFFFF0000`, `0xFFFF0000` and `0x30000`. It checks: - each span against the exact expected address: spans ending at or crossing a window edge or the range end, 0-byte spans and overflowing spans; - window references through `GetWindow`, `Close()` and a second `Close()`, with no window released twice; - 40 bits (4 GiB windows) and 17 bits (64 KiB windows); - refusal of a null output, a null device, size 0, two unaligned sizes, 2^64 − 64 KiB (more than `UINT` windows) and a failed feature query; - window creation failing at calls 1, 2 and 3, each leaving no window alive. `d3d12_xs_range_full_last_window_control` runs `--mutate full_last_window` and must fail (`WILL_FAIL`). The change is test, CMake and `docs/experiments.md` (the #874 range section) only. The CMake block follows the `vm_translation` registrations. ## Verification Commit `3c6273ac` (`main`) plus this change, `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Windows SDK 10.0.26100.0, WARP 10.0.26100.9818. ```powershell ctest --preset dev --no-tests=error -R '^(d3d12_xs_range.*|vm_translation_.*(warp|shared_range))$' -V # 8/8 passed, including the control (fails as intended); d3d12_xs_range runs in about 0.01 s ``` `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` passed. ## Mutation probe I applied each mutation to `src/d3d12_xs_range.cpp` alone, rebuilt, ran the tests, then reverted. None of this is committed. | Mutant | Existing (6 WARP/device-free `vm_translation`) | `d3d12_xs_range` | |---|---|---| | control: window-edge check removed | killed | fails | | window not capped by the adapter limit | killed | fails | | per-resource limit without `- 64 KiB` | killed | fails | | last window requested at full window size | **survived** | fails | | span ending 1 byte past the range accepted | **survived** | fails | | span crossing a window edge by 1 byte accepted | **survived** | fails | | 0-byte span returns 0 | **survived** | fails | | `CheckFeatureSupport` failure returned as `E_FAIL` | **survived** | fails | | size not a multiple of 64 KiB accepted | killed | fails | | window count above `UINT` not refused | killed only by a 46 s timeout | fails | | no `Release` on a mid-way failure | killed | fails | | failed window HRESULT skipped | killed | fails | | `GetWindow` without `AddRef` | killed | fails | | `GetWindow` accepts index == count | killed by timeout or crash | fails | | `Close` leaves `size_` set | killed | fails | | count truncated (`size / window`) | killed by timeout | fails | | `if (!bytes) bytes = 1;` deleted | survived | survived (equivalent) | | minimum bits `< 17` → `< 16` | survived | survived (not pinned) | | `>= 64` → `> 64` | survived | survived (not pinned) | Notes on the last three rows: - **`if (!bytes) bytes = 1;` deleted.** This is equivalent: once `offset < size_` and the offset lies inside a window, a 1-byte span always fits. - **`< 17` → `< 16`.** Fewer than 17 bits per resource would mean a 0-byte window, which no real adapter reports. - **`>= 64` → `> 64`.** `1 << 64` is undefined behaviour, and on x64 the mutant behaves the same as the original. ## 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 (Claude Code).
upstream-sync closed this pull request 2026-11-24 14:03:05 +00:00
tedin7 commented 2026-11-24 15:01:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:09:22Z.

Review: COMMENTED


Technical review of commit b86bceaa0163aa2a8760a2c6335a74c47f208ef8:

Code & fixture audit

  • tests/d3d12_xs_range_check.cpp cleanly exercises src/d3d12_xs_range.{h,cpp} without a GPU via CreateWindowFn and a FakeDevice vtable (slot 13 CheckFeatureSupport).
  • Covers window sizing across 17/32/40-bit per-resource limits (including a non-full last window), boundary GetGPUVirtualAddress spans (0-byte, window-edge, range-end, and overflow), GetWindow refcounting + Close() idempotency, refusal paths (E_POINTER, E_INVALIDARG, DXGI_ERROR_UNSUPPORTED, mid-creation E_OUTOFMEMORY rollback), and the --mutate full_last_window negative control (WILL_FAIL TRUE).
  • docs/experiments.md and CMakeLists.txt updates are focused and match the fixture.

Verification

  • Lint & merge: tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check, and git merge-tree --write-tree origin/main HEAD all pass.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207):
    • Debug (--preset dev): built d3d12_xs_range_check (4.10s); ctest --preset dev -R '^d3d12_xs_range' --no-tests=error: 2/2 passed (d3d12_xs_range, d3d12_xs_range_full_last_window_control).
    • Release /O2 (--preset release): built d3d12_xs_range_check (1.39s); ctest --preset release -R '^d3d12_xs_range' --no-tests=error: 2/2 passed (d3d12_xs_range, d3d12_xs_range_full_last_window_control).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6040714279 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1514#pullrequestreview-6040714279). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T14:09:22Z. **Review:** COMMENTED --- Technical review of commit `b86bceaa0163aa2a8760a2c6335a74c47f208ef8`: ### Code & fixture audit - `tests/d3d12_xs_range_check.cpp` cleanly exercises `src/d3d12_xs_range.{h,cpp}` without a GPU via `CreateWindowFn` and a `FakeDevice` vtable (slot 13 `CheckFeatureSupport`). - Covers window sizing across 17/32/40-bit per-resource limits (including a non-full last window), boundary `GetGPUVirtualAddress` spans (0-byte, window-edge, range-end, and overflow), `GetWindow` refcounting + `Close()` idempotency, refusal paths (`E_POINTER`, `E_INVALIDARG`, `DXGI_ERROR_UNSUPPORTED`, mid-creation `E_OUTOFMEMORY` rollback), and the `--mutate full_last_window` negative control (`WILL_FAIL TRUE`). - `docs/experiments.md` and `CMakeLists.txt` updates are focused and match the fixture. ### Verification - **Lint & merge**: `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `git diff --check`, and `git merge-tree --write-tree origin/main HEAD` all pass. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207)**: - Debug (`--preset dev`): built `d3d12_xs_range_check` (`4.10s`); `ctest --preset dev -R '^d3d12_xs_range' --no-tests=error`: **2/2 passed** (`d3d12_xs_range`, `d3d12_xs_range_full_last_window_control`). - Release `/O2` (`--preset release`): built `d3d12_xs_range_check` (`1.39s`); `ctest --preset release -R '^d3d12_xs_range' --no-tests=error`: **2/2 passed** (`d3d12_xs_range`, `d3d12_xs_range_full_last_window_control`).
ChazY11 commented 2026-11-24 15:02:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T14:37:49Z.


Three of the five mutants reproduced independently, plus the in-tree control

Independent reviewer, not the author. Reviewed b86bceaa; nothing pushed to the branch. Mutations were made locally in
src/d3d12_xs_range.cpp, rebuilt, reverted; working tree is clean.

Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^d3d12_xs_range' -V

Unmodified branch:

d3d12_xs_range ......................... Passed   "d3d12_xs_range: window sizes, edge spans and references exact"
d3d12_xs_range_full_last_window_control  Passed   FAIL three buffer windows of 4 GiB - 64 KiB, 4 GiB - 64 KiB and 192 KiB are requested

The in-tree --mutate full_last_window control does what it says: it asserts the wrong window request is what comes out
and the ctest case passes only because the check reports it. Nice pattern — it keeps the negative control next to the
fixture instead of in a comment.

Independent mutations

- if (bytes > window_ - inside) return 0;
+ if (false) return 0;                       // span may cross a window edge
d3d12_xs_range ***Failed
- if (!bytes) bytes = 1;
+ if (!bytes) return 0;                     // a 0-byte span gets no address
d3d12_xs_range ***Failed
- if (offset >= size_ || bytes > size_ - offset) return 0;
+ if (offset >= size_) return 0;            // a span one byte past the end gets an address
d3d12_xs_range ***Failed

All three are caught by the plain case, with no help from the mutation flag, so the new check does carry the three
edge conditions it claims. I did not reproduce the remaining two (the window count and the per-resource limit path)
because they need the fake device to report different MaxGPUVirtualAddressBitsPerResource values; if you want those
confirmed as well, say so and I will drive them through the fake device.

What this adds over the WARP tests

vm_translation_range_warp already covers the create path, but only at WARP's 32 bits per resource and only for the
shapes that fit. The device-free check runs the same logic with the limits handed in, which is why it can cover
4 GiB-sized windows and the last-window case at all — my three mutants confirm it is exercising the span arithmetic
rather than just the create call.

Verdict

Reviewed b86bceaa. Builds clean, both cases pass, the in-tree control is genuine, and three independently injected
mutants are caught. No objection from me.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7134688869 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1514#issuecomment-7134688869). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T14:37:49Z. --- ## Three of the five mutants reproduced independently, plus the in-tree control Independent reviewer, not the author. Reviewed `b86bceaa`; nothing pushed to the branch. Mutations were made locally in `src/d3d12_xs_range.cpp`, rebuilt, reverted; working tree is clean. Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^d3d12_xs_range' -V ``` Unmodified branch: ```text d3d12_xs_range ......................... Passed "d3d12_xs_range: window sizes, edge spans and references exact" d3d12_xs_range_full_last_window_control Passed FAIL three buffer windows of 4 GiB - 64 KiB, 4 GiB - 64 KiB and 192 KiB are requested ``` The in-tree `--mutate full_last_window` control does what it says: it asserts the *wrong* window request is what comes out and the ctest case passes only because the check reports it. Nice pattern — it keeps the negative control next to the fixture instead of in a comment. ### Independent mutations ```diff - if (bytes > window_ - inside) return 0; + if (false) return 0; // span may cross a window edge ``` ```text d3d12_xs_range ***Failed ``` ```diff - if (!bytes) bytes = 1; + if (!bytes) return 0; // a 0-byte span gets no address ``` ```text d3d12_xs_range ***Failed ``` ```diff - if (offset >= size_ || bytes > size_ - offset) return 0; + if (offset >= size_) return 0; // a span one byte past the end gets an address ``` ```text d3d12_xs_range ***Failed ``` All three are caught by the plain case, with no help from the mutation flag, so the new check does carry the three edge conditions it claims. I did not reproduce the remaining two (the window count and the per-resource limit path) because they need the fake device to report different `MaxGPUVirtualAddressBitsPerResource` values; if you want those confirmed as well, say so and I will drive them through the fake device. ### What this adds over the WARP tests `vm_translation_range_warp` already covers the create path, but only at WARP's 32 bits per resource and only for the shapes that fit. The device-free check runs the same logic with the limits handed in, which is why it can cover 4 GiB-sized windows and the last-window case at all — my three mutants confirm it is exercising the span arithmetic rather than just the create call. ### Verdict Reviewed `b86bceaa`. Builds clean, both cases pass, the in-tree control is genuine, and three independently injected mutants are caught. No objection from me.
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!1507
No description provided.