runtime: check the struct-return adapter's refusals and heap type #1711

Merged
Asimmimx merged 1 commit from upstream-pr/1718 into main 2026-11-24 18:07:46 +00:00
Asimmimx commented 2026-11-24 17:40:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:40:22Z.


Refs #1149.

Change

src/d3d12x_struct_return.h declares d3d12x_struct_return::get_custom_heap_properties, the adapter for the struct-returning GetCustomHeapProperties call. It gets two candidate pointers and the live device, takes the candidate that is not the device as the output buffer, and writes the desktop method's result there. It returns that buffer, or nullptr when it cannot tell the two apart (src/d3d12x_struct_return.cpp).

One test reaches it: d3d12x_device_struct_return_warp (and its _hardware twin), the struct-return scenario of tests/d3d12x_device_check.cpp. It calls the adapter with D3D12_HEAP_TYPE_UPLOAD and the device and output buffer in both orders, once with a stale vtable word in the buffer. Every call has exactly one candidate equal to the device, so none of the nullptr paths ran, and only one heap type was used. 9 of 13 single-point mutants left the test passing (table below).

New cases in struct_return_checks, after the existing three (no existing case changed):

Case What it pins
default and readback, device first and return buffer first heap_type reaches the device. A DEFAULT heap has no CPU page property on any adapter, so its properties differ from UPLOAD's. The check fails if they are equal on an adapter. On a cache-coherent UMA adapter UPLOAD and READBACK can return the same properties, so READBACK alone would not be enough.
reject null_first: (nullptr, device) returns nullptr instead of writing through a null pointer
reject null_second: (device, nullptr) same for the second candidate
reject device_twice: (device, device) returns nullptr instead of writing over the device object
reject neither_is_device: two buffers, each seeded with the device's vtable word returns nullptr and writes neither buffer. Only the address comparison tells the buffers from the device
reject null_device: (buffer, device) with a null live device returns nullptr

Each reject case also checks that both guarded buffers are unchanged byte for byte.

Negative control: d3d12x_device_struct_return_neither_control_warp builds tests/d3d12x_device_check.cpp against a build-tree copy of d3d12x_struct_return.cpp. In that copy the final else writes through the second candidate (output = second; instead of return nullptr;). CMake makes the copy with a regex that tolerates CRLF, stops with FATAL_ERROR if the anchor is gone, and re-runs when the source file changes (CMAKE_CONFIGURE_DEPENDS). The test uses PASS_REGULAR_EXPRESSION "FAIL: struct_return reject neither_is_device: returned " instead of WILL_FAIL, so it passes only when the check reports this specific defect. A crash does not pass it. When run directly, the control prints FAIL: struct_return reject neither_is_device: returned 0000001F494FEE10 instead of nullptr after the earlier cases pass, and exits 1.

The change touches tests/d3d12x_device_check.cpp (74 added lines), adds 21 lines to CMakeLists.txt directly after the d3d12x_device_* registrations and updates the d3d12x_device_struct_return_* row in docs/experiments.md. It also adds a row for the control there. src/d3d12x_struct_return.* is unchanged.

Verification

Commit 37608bfc on 18a2942a (main), dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Microsoft Basic Render Driver (WARP) 10.0.26100.9818, debug layer enabled. No _hardware test was run.

cmake --preset dev
cmake --build --preset dev --target d3d12x_device_check d3d12x_device_struct_return_control
ctest --preset dev --no-tests=error -R '^d3d12x_device_(create|negative|struct_return|struct_return_neither_control)_warp$' --repeat until-fail:10
#   4/4 passed, 10 repetitions each
ctest --preset dev --no-tests=error -R '^d3d12x_pso_(static_sampler_warp|reject_warp)$'
#   2/2 passed (same executable, other scenarios)

d3d12x_device_struct_return_warp now prints 12 struct_return lines (3 existing, 4 heap-type, 5 reject) and d3d12x_device_check struct-return warp: PASS.

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

Mutation probe

I applied each mutation to src/d3d12x_struct_return.cpp alone, rebuilt d3d12x_device_check, ran d3d12x_device_struct_return_warp and reverted. None of this is committed. For mutants that remove the control's anchor, I probed with the CMAKE_CONFIGURE_DEPENDS line taken out, so the configure guard would not stop the build.

Mutant Existing check With the new cases
!device test dropped survived survived (equivalent, see below)
!first test dropped survived killed (null write, crash)
!second test dropped survived killed (null write, crash)
first == second test dropped survived killed (FAIL: struct_return reject device_twice)
neither candidate is the device: write through first survived killed (neither_is_device)
neither candidate is the device: write through second (the control) survived killed (neither_is_device)
heap_type replaced by D3D12_HEAP_TYPE_UPLOAD survived killed (default device_first)
node_mask replaced by 0 survived survived
node_mask replaced by 1 survived survived
branches swapped (output is the device) killed killed
result not written killed killed
device pointer returned killed killed
candidates classified by vtable word instead of address killed killed

Not pinned

  • node_mask forwarding. The fixture device has one node, so masks 0 and 1 return the same properties, and other masks are invalid there. A multi-node adapter would be needed.
  • The !device test. With a null device, two distinct non-null candidates match neither branch, so the function returns nullptr either way. The null_device case documents the contract but cannot kill this mutant.
  • The two null-candidate mutants fail by an access violation, not a FAIL: line. The adapter writes through the null pointer before it returns, so the check cannot report first.

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:6587822709 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1718). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T17:40:22Z. --- Refs #1149. ## Change `src/d3d12x_struct_return.h` declares `d3d12x_struct_return::get_custom_heap_properties`, the adapter for the struct-returning `GetCustomHeapProperties` call. It gets two candidate pointers and the live device, takes the candidate that is not the device as the output buffer, and writes the desktop method's result there. It returns that buffer, or `nullptr` when it cannot tell the two apart (`src/d3d12x_struct_return.cpp`). One test reaches it: `d3d12x_device_struct_return_warp` (and its `_hardware` twin), the `struct-return` scenario of `tests/d3d12x_device_check.cpp`. It calls the adapter with `D3D12_HEAP_TYPE_UPLOAD` and the device and output buffer in both orders, once with a stale vtable word in the buffer. Every call has exactly one candidate equal to the device, so none of the `nullptr` paths ran, and only one heap type was used. 9 of 13 single-point mutants left the test passing (table below). New cases in `struct_return_checks`, after the existing three (no existing case changed): | Case | What it pins | |---|---| | `default` and `readback`, device first and return buffer first | `heap_type` reaches the device. A `DEFAULT` heap has no CPU page property on any adapter, so its properties differ from `UPLOAD`'s. The check fails if they are equal on an adapter. On a cache-coherent UMA adapter `UPLOAD` and `READBACK` can return the same properties, so `READBACK` alone would not be enough. | | reject `null_first`: `(nullptr, device)` | returns `nullptr` instead of writing through a null pointer | | reject `null_second`: `(device, nullptr)` | same for the second candidate | | reject `device_twice`: `(device, device)` | returns `nullptr` instead of writing over the device object | | reject `neither_is_device`: two buffers, each seeded with the device's vtable word | returns `nullptr` and writes neither buffer. Only the address comparison tells the buffers from the device | | reject `null_device`: `(buffer, device)` with a null live device | returns `nullptr` | Each reject case also checks that both guarded buffers are unchanged byte for byte. Negative control: `d3d12x_device_struct_return_neither_control_warp` builds `tests/d3d12x_device_check.cpp` against a build-tree copy of `d3d12x_struct_return.cpp`. In that copy the final `else` writes through the second candidate (`output = second;` instead of `return nullptr;`). CMake makes the copy with a regex that tolerates CRLF, stops with `FATAL_ERROR` if the anchor is gone, and re-runs when the source file changes (`CMAKE_CONFIGURE_DEPENDS`). The test uses `PASS_REGULAR_EXPRESSION "FAIL: struct_return reject neither_is_device: returned "` instead of `WILL_FAIL`, so it passes only when the check reports this specific defect. A crash does not pass it. When run directly, the control prints `FAIL: struct_return reject neither_is_device: returned 0000001F494FEE10 instead of nullptr` after the earlier cases pass, and exits 1. The change touches `tests/d3d12x_device_check.cpp` (74 added lines), adds 21 lines to `CMakeLists.txt` directly after the `d3d12x_device_*` registrations and updates the `d3d12x_device_struct_return_*` row in `docs/experiments.md`. It also adds a row for the control there. `src/d3d12x_struct_return.*` is unchanged. ## Verification Commit `37608bfc` on `18a2942a` (`main`), `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260, Microsoft Basic Render Driver (WARP) 10.0.26100.9818, debug layer enabled. No `_hardware` test was run. ```powershell cmake --preset dev cmake --build --preset dev --target d3d12x_device_check d3d12x_device_struct_return_control ctest --preset dev --no-tests=error -R '^d3d12x_device_(create|negative|struct_return|struct_return_neither_control)_warp$' --repeat until-fail:10 # 4/4 passed, 10 repetitions each ctest --preset dev --no-tests=error -R '^d3d12x_pso_(static_sampler_warp|reject_warp)$' # 2/2 passed (same executable, other scenarios) ``` `d3d12x_device_struct_return_warp` now prints 12 `struct_return` lines (3 existing, 4 heap-type, 5 reject) and `d3d12x_device_check struct-return warp: PASS`. `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` passed. ## Mutation probe I applied each mutation to `src/d3d12x_struct_return.cpp` alone, rebuilt `d3d12x_device_check`, ran `d3d12x_device_struct_return_warp` and reverted. None of this is committed. For mutants that remove the control's anchor, I probed with the `CMAKE_CONFIGURE_DEPENDS` line taken out, so the configure guard would not stop the build. | Mutant | Existing check | With the new cases | |---|---|---| | `!device` test dropped | survived | survived (equivalent, see below) | | `!first` test dropped | **survived** | killed (null write, crash) | | `!second` test dropped | **survived** | killed (null write, crash) | | `first == second` test dropped | **survived** | killed (`FAIL: struct_return reject device_twice`) | | neither candidate is the device: write through `first` | **survived** | killed (`neither_is_device`) | | neither candidate is the device: write through `second` (the control) | **survived** | killed (`neither_is_device`) | | `heap_type` replaced by `D3D12_HEAP_TYPE_UPLOAD` | **survived** | killed (`default device_first`) | | `node_mask` replaced by `0` | survived | survived | | `node_mask` replaced by `1` | survived | survived | | branches swapped (output is the device) | killed | killed | | result not written | killed | killed | | device pointer returned | killed | killed | | candidates classified by vtable word instead of address | killed | killed | ## Not pinned - `node_mask` forwarding. The fixture device has one node, so masks 0 and 1 return the same properties, and other masks are invalid there. A multi-node adapter would be needed. - The `!device` test. With a null device, two distinct non-null candidates match neither branch, so the function returns `nullptr` either way. The `null_device` case documents the contract but cannot kill this mutant. - The two null-candidate mutants fail by an access violation, not a `FAIL:` line. The adapter writes through the null pointer before it returns, so the check cannot report first. ## 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).
tedin7 commented 2026-11-24 18:02:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:46:59Z.

Review: COMMENTED


Review of head 37608bfc3f59d6fdaa9953f96480d8048be6f254. Changes: tests/d3d12x_device_check.cpp (+74), test-only CMake (a build-tree control target and one ctest entry), and a docs table row; no production code, src/d3d12x_struct_return.cpp untouched. Verdict: 0 P1, 0 P2.

Linux limits. Linux x86_64. No Windows, no D3D12, no WARP, no DXC: d3d12x_device_check and the new control executable were not run, and neither was CMake configure/build of the repository. Below, the PR's struct_return_checks function was compiled verbatim with MinGW and run under wine against a fake device (a hand-built vtable whose GetCustomHeapProperties returns values derived from node mask and heap type), so heap-type pass-through and the address logic are exercised, the real desktop call is not.

What I ran

  • x86_64-w64-mingw32-g++ -std=c++17 -Wall -Wextra -fsyntax-only tests/d3d12x_device_check.cpp (with a stub for the DXC-generated d3d12x_pso_cs.h): no errors.
  • Verbatim struct_return_checks + the real adapter, fake device, wine: all cases pass, including DEFAULT/READBACK in both orders and the five reject cases.
  • Mutations on a copy of the adapter, each rebuilt and run:
    • neither candidate is the device -> write through the second (the PR's own control): FAILED struct_return reject neither_is_device: returned ..., which is the exact text the new CTest control requires.
    • heap type fixed to UPLOAD: FAILED (default device_first).
    • first == second allowed: FAILED (device_twice).
    • !second check dropped: caught, the run faults (null write).
    • output chosen the wrong way round: FAILED (device_first: did not return the caller's output pointer).
    • !device check dropped: PASSED, not caught. I believe it is redundant: with a null device neither candidate can equal it, so the function returns nullptr anyway; the null_device case passes either way.
  • CMake: the string(REGEX REPLACE "} else {(\r?\n +)return nullptr;" ...) anchor changes the real file when run in a cmake -P script, and the FATAL_ERROR guard fires if it stops matching; d3d12x_pso_header is defined above its use. The PASS_REGULAR_EXPRESSION text matches the message the check prints.
  • git diff --check, docs_links_check, bidi_controls_check clean; no non-ASCII bytes in the diff. Existing assertions untouched (additions only after the existing loop).

Notes

  • The control requires PASS_REGULAR_EXPRESSION only, so it passes when the line appears whatever the exit code; fine for a negative control, but it only runs on WARP.
  • Not run: the Windows CTest entries (d3d12x_device_struct_return_{warp,hardware} and the new control).

Not approving (comment only).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044449329 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1718#pullrequestreview-6044449329). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:46:59Z. **Review:** COMMENTED --- Review of head `37608bfc3f59d6fdaa9953f96480d8048be6f254`. Changes: `tests/d3d12x_device_check.cpp` (+74), test-only CMake (a build-tree control target and one ctest entry), and a docs table row; no production code, `src/d3d12x_struct_return.cpp` untouched. **Verdict: 0 P1, 0 P2.** **Linux limits.** Linux x86_64. No Windows, no D3D12, no WARP, no DXC: `d3d12x_device_check` and the new control executable were not run, and neither was CMake configure/build of the repository. Below, the PR's `struct_return_checks` function was compiled verbatim with MinGW and run under wine against a **fake device** (a hand-built vtable whose `GetCustomHeapProperties` returns values derived from node mask and heap type), so heap-type pass-through and the address logic are exercised, the real desktop call is not. **What I ran** - `x86_64-w64-mingw32-g++ -std=c++17 -Wall -Wextra -fsyntax-only tests/d3d12x_device_check.cpp` (with a stub for the DXC-generated `d3d12x_pso_cs.h`): no errors. - Verbatim `struct_return_checks` + the real adapter, fake device, wine: all cases pass, including DEFAULT/READBACK in both orders and the five reject cases. - Mutations on a copy of the adapter, each rebuilt and run: - neither candidate is the device -> write through the second (the PR's own control): FAILED `struct_return reject neither_is_device: returned ...`, which is the exact text the new CTest control requires. - heap type fixed to UPLOAD: FAILED (`default device_first`). - `first == second` allowed: FAILED (`device_twice`). - `!second` check dropped: caught, the run faults (null write). - output chosen the wrong way round: FAILED (`device_first: did not return the caller's output pointer`). - `!device` check dropped: PASSED, not caught. I believe it is redundant: with a null device neither candidate can equal it, so the function returns `nullptr` anyway; the `null_device` case passes either way. - CMake: the `string(REGEX REPLACE "} else {(\r?\n +)return nullptr;" ...)` anchor changes the real file when run in a `cmake -P` script, and the `FATAL_ERROR` guard fires if it stops matching; `d3d12x_pso_header` is defined above its use. The `PASS_REGULAR_EXPRESSION` text matches the message the check prints. - `git diff --check`, `docs_links_check`, `bidi_controls_check` clean; no non-ASCII bytes in the diff. Existing assertions untouched (additions only after the existing loop). **Notes** - The control requires `PASS_REGULAR_EXPRESSION` only, so it passes when the line appears whatever the exit code; fine for a negative control, but it only runs on WARP. - Not run: the Windows CTest entries (`d3d12x_device_struct_return_{warp,hardware}` and the new control). Not approving (comment only). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 18:02:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:50:21Z.

Review: COMMENTED


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) and Linux at commit 37608bfc3f59d6fdaa9953f96480d8048be6f254 (0 P1, 0 P2; test-only CMake + test + docs, zero production files changed, zero assertions weakened):

  • Linux checks:
    • git diff --check origin/main...HEAD: PASS
    • python3 tests/docs_links_check.py: PASS (17 Markdown files, 364 links)
    • python3 tests/bidi_controls_check.py: PASS (1283 tracked files)
  • Win2025 Debug (--preset dev):
    • cmake --build --preset dev --target cpu_trap cpu_trap_drop cpu_trap_harness cpu_trap_lifted cpu_trap_nostore cpu_trap_swap d3d12_xs_shim d3d12x_device_check d3d12x_device_struct_return_control -- -j 6: PASS (4.80s)
    • ctest --preset dev -R '^(cpu_aot_trap|d3d12x_device_create_warp|d3d12x_device_negative_warp|d3d12x_device_struct_return_neither_control_warp|d3d12x_device_struct_return_warp|d3d12x_pso_reject_warp|d3d12x_pso_static_sampler_warp)$' --parallel 4 --no-tests=error --output-on-failure: 7/7 passed (1.83s)
  • Win2025 Release /O2 (--preset release):
    • cmake --build --preset release --target cpu_trap cpu_trap_drop cpu_trap_harness cpu_trap_lifted cpu_trap_nostore cpu_trap_swap d3d12_xs_shim d3d12x_device_check d3d12x_device_struct_return_control -- -j 6: PASS (3.12s)
    • ctest --preset release -R '^(cpu_aot_trap|d3d12x_device_create_warp|d3d12x_device_negative_warp|d3d12x_device_struct_return_neither_control_warp|d3d12x_device_struct_return_warp|d3d12x_pso_reject_warp|d3d12x_pso_static_sampler_warp)$' --parallel 4 --no-tests=error --output-on-failure: 7/7 passed (1.83s)
  • Mutation checks:
    • Mutated src/d3d12x_struct_return.cpp on Win2025 (heap_type -> D3D12_HEAP_TYPE_UPLOAD): d3d12x_device_struct_return_warp failed as expected (FAIL: struct_return default device_first: pointer, guards or properties differ from the desktop call).
    • Built-in negative control d3d12x_device_struct_return_neither_control_warp (return nullptr; -> output = second;): passed in both Debug and Release /O2.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044496739 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1718#pullrequestreview-6044496739). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:50:21Z. **Review:** COMMENTED --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) and Linux at commit `37608bfc3f59d6fdaa9953f96480d8048be6f254` (0 P1, 0 P2; test-only CMake + test + docs, zero production files changed, zero assertions weakened): - **Linux checks**: - `git diff --check origin/main...HEAD`: PASS - `python3 tests/docs_links_check.py`: PASS (17 Markdown files, 364 links) - `python3 tests/bidi_controls_check.py`: PASS (1283 tracked files) - **Win2025 Debug (`--preset dev`)**: - `cmake --build --preset dev --target cpu_trap cpu_trap_drop cpu_trap_harness cpu_trap_lifted cpu_trap_nostore cpu_trap_swap d3d12_xs_shim d3d12x_device_check d3d12x_device_struct_return_control -- -j 6`: PASS (`4.80s`) - `ctest --preset dev -R '^(cpu_aot_trap|d3d12x_device_create_warp|d3d12x_device_negative_warp|d3d12x_device_struct_return_neither_control_warp|d3d12x_device_struct_return_warp|d3d12x_pso_reject_warp|d3d12x_pso_static_sampler_warp)$' --parallel 4 --no-tests=error --output-on-failure`: **7/7 passed** (`1.83s`) - **Win2025 Release `/O2` (`--preset release`)**: - `cmake --build --preset release --target cpu_trap cpu_trap_drop cpu_trap_harness cpu_trap_lifted cpu_trap_nostore cpu_trap_swap d3d12_xs_shim d3d12x_device_check d3d12x_device_struct_return_control -- -j 6`: PASS (`3.12s`) - `ctest --preset release -R '^(cpu_aot_trap|d3d12x_device_create_warp|d3d12x_device_negative_warp|d3d12x_device_struct_return_neither_control_warp|d3d12x_device_struct_return_warp|d3d12x_pso_reject_warp|d3d12x_pso_static_sampler_warp)$' --parallel 4 --no-tests=error --output-on-failure`: **7/7 passed** (`1.83s`) - **Mutation checks**: - Mutated `src/d3d12x_struct_return.cpp` on Win2025 (`heap_type` -> `D3D12_HEAP_TYPE_UPLOAD`): `d3d12x_device_struct_return_warp` failed as expected (`FAIL: struct_return default device_first: pointer, guards or properties differ from the desktop call`). - Built-in negative control `d3d12x_device_struct_return_neither_control_warp` (`return nullptr;` -> `output = second;`): passed in both Debug and Release `/O2`. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 19:01:05 +00:00
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!1711
No description provided.