runtime: guard memory SRV wrapper allocation failures #2727

Manually merged
github merged 2 commits from gh-pr/2727/head into gh-pr/2727/base 2026-11-27 01:18:38 +00:00
Owner

@⁠chadhyatt on GitHub · 2026-11-26 04:09 UTC · original
chadhyatt:backport/memory-srv-wrap-allocation → main · +25 −4 · 3 files · 2 commits · merged 2026-11-26 04:36 UTC

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.

**@⁠chadhyatt** on GitHub · 2026-11-26 04:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2727) `chadhyatt:backport/memory-srv-wrap-allocation` → `main` · +25 −4 · 3 files · 2 commits · merged 2026-11-26 04:36 UTC 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.
After the nullable wrapper allocation change, these helpers should return no resource when allocation fails. Keep their existing ownership and caller refusal behavior.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:18:37 +00:00
github manually merged commit b630c8bc96 into gh-pr/2727/base 2026-11-27 01:18:38 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 04:21 UTC · original · reviewed

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.

**@⁠tedin7** on GitHub · 2026-11-26 04:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2727#pullrequestreview-6068510359) · **reviewed** 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.
Author
Owner

@⁠chadhyatt on GitHub · 2026-11-26 04:21 UTC · original

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** on GitHub · 2026-11-26 04:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2727#issuecomment-7182530541) 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.
Author
Owner

@⁠chadhyatt on GitHub · 2026-11-26 04:32 UTC · original

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

**@⁠chadhyatt** on GitHub · 2026-11-26 04:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2727#issuecomment-7182684029) Thanks for adding the source-built fixture in b630c8bc960. I will not duplicate your change; waiting for the exact new-head CI results.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-26 04:33 UTC · original · approved these changes

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.

**@⁠R0Y00** on GitHub · 2026-11-26 04:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2727#pullrequestreview-6068585584) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.