runtime: guard memory SRV wrapper allocation failures #2719

Merged
chadhyatt merged 2 commits from upstream-pr/2727 into main 2026-11-26 04:36:26 +00:00
chadhyatt commented 2026-11-26 04:09:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chadhyatt on 2026-11-26T04:09:37Z.


AI-assisted backport patch from x2w-microlift.

Refs #2656. The two memory-SRV resource helpers now check the nullable wrapper allocation result before initializing wrapper metadata. Existing callers already refuse a missing resource; successful resource/backing ownership is unchanged. No other behavior is changed.

Verified at 1d04e4d1d8e3c340383d4d56ee4cc4b99bd93d58 on upstream base 2215c26d3019299764ba1b3149fcf6e2ee403916, macOS ARM64 with Homebrew Clang 23.1.6 and MinGW Windows-target headers:

CXX=/opt/homebrew/opt/llvm/bin/clang++
W=/opt/homebrew/opt/mingw-w64/toolchain-x86_64
G=$(x86_64-w64-mingw32-g++ -dumpversion)
"$CXX" --target=x86_64-w64-windows-gnu --sysroot="$W/x86_64-w64-mingw32" -std=c++17 -fms-extensions -fsyntax-only -ferror-limit=12 -isystem "$W/x86_64-w64-mingw32/include/c++/$G" -isystem "$W/x86_64-w64-mingw32/include/c++/$G/x86_64-w64-mingw32" -isystem "$W/x86_64-w64-mingw32/include/c++/$G/backward" -isystem "$W/x86_64-w64-mingw32/include" -DWIN32_LEAN_AND_MEAN -DNOMINMAX -Isrc src/startup_stubs/d3d12_xs_device.cpp

Exit 0; two pre-existing warnings. Windows D3D12 runtime tests were not run on this host. No game inputs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6619308141 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2727). Originally posted by [chadhyatt](https://github.com/chadhyatt) on 2026-11-26T04:09:37Z. --- AI-assisted backport patch from x2w-microlift. Refs #2656. The two memory-SRV resource helpers now check the nullable wrapper allocation result before initializing wrapper metadata. Existing callers already refuse a missing resource; successful resource/backing ownership is unchanged. No other behavior is changed. Verified at `1d04e4d1d8e3c340383d4d56ee4cc4b99bd93d58` on upstream base `2215c26d3019299764ba1b3149fcf6e2ee403916`, macOS ARM64 with Homebrew Clang 23.1.6 and MinGW Windows-target headers: ```sh CXX=/opt/homebrew/opt/llvm/bin/clang++ W=/opt/homebrew/opt/mingw-w64/toolchain-x86_64 G=$(x86_64-w64-mingw32-g++ -dumpversion) "$CXX" --target=x86_64-w64-windows-gnu --sysroot="$W/x86_64-w64-mingw32" -std=c++17 -fms-extensions -fsyntax-only -ferror-limit=12 -isystem "$W/x86_64-w64-mingw32/include/c++/$G" -isystem "$W/x86_64-w64-mingw32/include/c++/$G/x86_64-w64-mingw32" -isystem "$W/x86_64-w64-mingw32/include/c++/$G/backward" -isystem "$W/x86_64-w64-mingw32/include" -DWIN32_LEAN_AND_MEAN -DNOMINMAX -Isrc src/startup_stubs/d3d12_xs_device.cpp ``` Exit 0; two pre-existing warnings. Windows D3D12 runtime tests were not run on this host. No game inputs.
upstream-sync closed this pull request 2026-11-26 05:02:18 +00:00
tedin7 commented 2026-11-26 05:02:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:21:17Z.

Review: COMMENTED


Review of head 1d04e4d1 against current main (comment only).

Code: correct and minimal. wrap() can return nullptr (fixture hook wraps_to_fail, and _aligned_malloc failure), and both new guards sit right before the first dereference (unplaced_memory_buffer, publish_tiled_texture). Every caller already treats a null result as "unavailable" and refuses the SRV (d3d12_memory_srv.inl lines ~687, 705, 734, 748), so no new contract. The native resource is held by a ComPtr in the first helper, so the early return does not leak.

Gap: no test guards the change. tests/startup_wrap_allocation.cpp already arms x2w_d3d12_fail_wraps per slot, but it does not call the memory-SRV slot (buffer and tiled-texture paths), so reverting both lines would still pass. Please add one armed call for each of the two helpers (expect the refusal, no crash) to that existing fixture, so a mutation removing the guards fails it.

Not exercised on a game; this only reviews code. No runtime result is claimed.

Commands run locally:

  • git diff --stat origin/main...HEAD (1 file, +2)
  • git diff --check origin/main...HEAD (clean)
  • python3 tests/docs_links_check.py (ok)
  • python3 tests/bidi_controls_check.py (ok)
  • rg over callers of both helpers and over wraps_to_fail users

Not merged: waiting for the test above.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068510359 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2727#pullrequestreview-6068510359). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T04:21:17Z. **Review:** COMMENTED --- Review of head 1d04e4d1 against current main (comment only). Code: correct and minimal. `wrap()` can return nullptr (fixture hook `wraps_to_fail`, and `_aligned_malloc` failure), and both new guards sit right before the first dereference (`unplaced_memory_buffer`, `publish_tiled_texture`). Every caller already treats a null result as "unavailable" and refuses the SRV (`d3d12_memory_srv.inl` lines ~687, 705, 734, 748), so no new contract. The native resource is held by a ComPtr in the first helper, so the early return does not leak. Gap: no test guards the change. `tests/startup_wrap_allocation.cpp` already arms `x2w_d3d12_fail_wraps` per slot, but it does not call the memory-SRV slot (buffer and tiled-texture paths), so reverting both lines would still pass. Please add one armed call for each of the two helpers (expect the refusal, no crash) to that existing fixture, so a mutation removing the guards fails it. Not exercised on a game; this only reviews code. No runtime result is claimed. Commands run locally: - `git diff --stat origin/main...HEAD` (1 file, +2) - `git diff --check origin/main...HEAD` (clean) - `python3 tests/docs_links_check.py` (ok) - `python3 tests/bidi_controls_check.py` (ok) - `rg` over callers of both helpers and over `wraps_to_fail` users Not merged: waiting for the test above. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-26 05:02:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T04:33:05Z.

Review: APPROVED


I added focused coverage using the existing wrapper-failure hook. The unplaced buffer and new tiled texture each preserve the previous 32-byte descriptor on failure, then publish successfully on retry. Windows Release: cmake --build --preset release --target startup_stream_consumer; ctest --preset release --no-tests=error -j 1 -R "^startup_address_(buffer_srv|single_element)_(warp|hardware)$" -V passed 4/4 on WARP and RTX 4060 Laptop, with no skips. The caller refusals remain in place and the retries match their usual GPU pixel readbacks.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068585584 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2727#pullrequestreview-6068585584). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T04:33:05Z. **Review:** APPROVED --- I added focused coverage using the existing wrapper-failure hook. The unplaced buffer and new tiled texture each preserve the previous 32-byte descriptor on failure, then publish successfully on retry. Windows Release: cmake --build --preset release --target startup_stream_consumer; ctest --preset release --no-tests=error -j 1 -R "^startup_address_(buffer_srv|single_element)_(warp|hardware)$" -V passed 4/4 on WARP and RTX 4060 Laptop, with no skips. The caller refusals remain in place and the retries match their usual GPU pixel readbacks.
chadhyatt commented 2026-11-26 05:02:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chadhyatt on 2026-11-26T04:21:56Z.


Thanks, agreed on extending the existing allocation-refusal fixture for both paths. I will add source-built checks for the expected refusal/normal retry contract; no game run is needed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182530541 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2727#issuecomment-7182530541). Originally posted by [chadhyatt](https://github.com/chadhyatt) on 2026-11-26T04:21:56Z. --- Thanks, agreed on extending the existing allocation-refusal fixture for both paths. I will add source-built checks for the expected refusal/normal retry contract; no game run is needed.
chadhyatt commented 2026-11-26 05:02:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chadhyatt on 2026-11-26T04:32:27Z.


Thanks for adding the source-built fixture in b630c8bc96. I will not duplicate your change; waiting for the exact new-head CI results.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182684029 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2727#issuecomment-7182684029). Originally posted by [chadhyatt](https://github.com/chadhyatt) on 2026-11-26T04:32:27Z. --- Thanks for adding the source-built fixture in b630c8bc960. I will not duplicate your change; waiting for the exact new-head CI results.
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!2719
No description provided.