runtime: guard null out pointers, add inspection helpers and unit tests for PlacedDepthTextures (RT-XS-PLACED-DEPTH-GUARDS-AND-TESTS) #2046

Merged
abnalstlll-byte merged 1 commit from upstream-pr/2046 into main 2026-11-29 14:14:57 +00:00
abnalstlll-byte commented 2026-11-25 18:56:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-25T18:56:49Z.


Claimed in the coordination issue as: RT-XS-PLACED-DEPTH-GUARDS-AND-TESTS (claim)

What and why

runtime/shims/d3d12_xs_placed_depth.h manages GPU backing for slot-133 depth/UAV textures keyed by Xbox placement ranges.

  1. Null out pointer guards:

    • PlacedDepthTextures::create: If out is null, returns E_POINTER immediately before attempting any allocations or lookups.
    • If out is non-null, sets *out = nullptr at entry so failures (E_INVALIDARG, E_NOTIMPL, or backing creation failures) guarantee callers receive null.
  2. Inspection and cleanup helpers:

    • Added clear(), size(), and empty() to PlacedDepthTextures (marking mutex_ mutable for const query methods).
  3. Portability:

    • Supports MinGW and MSVC COM virtual dispatch signatures for ID3D12Resource::GetDesc in PlacedDepthTexture.
  4. Unit test suite (runtime/test/d3d12_xs_placed_depth_test.cpp):

    • 46 assertions covering:
      • Null out pointer returning E_POINTER.
      • Invalid arguments (address == 0, Alignment == 0, unaligned address, SizeInBytes == 0, address+size overflow) setting *out = nullptr and returning E_INVALIDARG.
      • create_backing failure propagation and clearing *out.
      • Valid creation, GPU VA verification, and texture_backing resolution.
      • QueryInterface forwarding (kVulkanResourceTag delegating to backing, ID3D12Resource returning wrapper).
      • Identical placement aliasing (sharing backing, distinct COM identities).
      • Refusal of incompatible shapes with non-opaque layouts (E_NOTIMPL).
      • Refusal of overlapping non-opaque layouts (E_NOTIMPL).
      • Separate backings for alternating shapes under opaque layouts.
      • Weak reference expiration (std::erase_if) when all aliases are released.
      • clear() and empty().
      • OptimizedClear mismatch refusal.

Registers d3d12_xs_placed_depth_test and CTest in runtime/CMakeLists.txt.

Tested

  • Unit test execution: 46/46 checks passed (0 failures).
  • python -I tests/test_ci_registration.py: 16/16 pass.
  • python -I tests/test_text_write_line_endings.py: 3/3 pass.
  • python -I scripts/check_no_game_data.py: clean (0 violations, no game data).

AI-assisted (Claude Code)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5497315702 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2046). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-25T18:56:49Z. --- Claimed in the coordination issue as: RT-XS-PLACED-DEPTH-GUARDS-AND-TESTS ([claim](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171516197)) ### What and why `runtime/shims/d3d12_xs_placed_depth.h` manages GPU backing for slot-133 depth/UAV textures keyed by Xbox placement ranges. 1. **Null out pointer guards**: - `PlacedDepthTextures::create`: If `out` is null, returns `E_POINTER` immediately before attempting any allocations or lookups. - If `out` is non-null, sets `*out = nullptr` at entry so failures (`E_INVALIDARG`, `E_NOTIMPL`, or backing creation failures) guarantee callers receive null. 2. **Inspection and cleanup helpers**: - Added `clear()`, `size()`, and `empty()` to `PlacedDepthTextures` (marking `mutex_` mutable for const query methods). 3. **Portability**: - Supports MinGW and MSVC COM virtual dispatch signatures for `ID3D12Resource::GetDesc` in `PlacedDepthTexture`. 4. **Unit test suite (`runtime/test/d3d12_xs_placed_depth_test.cpp`)**: - 46 assertions covering: - Null `out` pointer returning `E_POINTER`. - Invalid arguments (`address == 0`, `Alignment == 0`, unaligned address, `SizeInBytes == 0`, address+size overflow) setting `*out = nullptr` and returning `E_INVALIDARG`. - `create_backing` failure propagation and clearing `*out`. - Valid creation, GPU VA verification, and `texture_backing` resolution. - `QueryInterface` forwarding (`kVulkanResourceTag` delegating to backing, `ID3D12Resource` returning wrapper). - Identical placement aliasing (sharing backing, distinct COM identities). - Refusal of incompatible shapes with non-opaque layouts (`E_NOTIMPL`). - Refusal of overlapping non-opaque layouts (`E_NOTIMPL`). - Separate backings for alternating shapes under opaque layouts. - Weak reference expiration (`std::erase_if`) when all aliases are released. - `clear()` and `empty()`. - `OptimizedClear` mismatch refusal. Registers `d3d12_xs_placed_depth_test` and CTest in `runtime/CMakeLists.txt`. ### Tested - Unit test execution: `46/46 checks passed` (0 failures). - `python -I tests/test_ci_registration.py`: 16/16 pass. - `python -I tests/test_text_write_line_endings.py`: 3/3 pass. - `python -I scripts/check_no_game_data.py`: clean (0 violations, no game data). AI-assisted (Claude Code)
MoonEyes commented 2026-11-28 02:48:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:48:51Z.


Hi @abnalstlll-byte, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/CMakeLists.txt), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232610340 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2046#issuecomment-7232610340). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T02:48:51Z. --- Hi @abnalstlll-byte, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/CMakeLists.txt`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
OreoFR commented 2026-11-29 11:36:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T11:36:38Z.


TAKEN by OreoFR (Windows, RTX 4070 8 GB)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7255228923 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2046#issuecomment-7255228923). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T11:36:38Z. --- TAKEN by OreoFR (Windows, RTX 4070 8 GB)
OreoFR commented 2026-11-29 12:38:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T12:38:20Z.


Verified by OreoFR — READY

  • Base: main 8fb974878 + this PR (head 0233a9ec7) merged with --no-ff (still no conflict with main cc0f662a7; the runtime/CMakeLists.txt conflict in the needs-rebase note is gone)
  • Red (main + this PR's test + its CMake registration, plus only the PR's clear()/size()/empty() accessors so the test compiles, without the null-out guards): d3d12_xs_placed_depth fails 9 of 46 checks. A null out still registers a range ("pool remains empty on null out"), and *out is not cleared on the 8 refusal paths.
  • Green (merge): 46/46; ctest in its own package (main + #2046 only): 502 tests, new failures vs main: none (failures: xbox_present and dxgi_waitable_latency as on main, plus xmem, xmem_no_write_watch and d3d12_mesh_heavy_cache once; all pass 5/5 when rerun alone on main and on the merge). ctest settings: Ninja RelWithDebInfo, all targets, gta6rt launchers excluded; main alone 501 tests, 2 failures (xbox_present, dxgi_waitable_latency).
  • gta6rt.exe links without the XMA decoder (LEONIDA_CARGO=OFF, LEONIDA_XMA2_DECODER_LIB empty); imports unchanged vs main (25 DLLs, no WS2_32)
  • Diff read: no issue. The only caller (proxy_create_placed_resource_slot133) already checks out, so the E_POINTER path changes nothing in game. The new accessors and the __MINGW32__ GetDesc branch are additive.
  • Other runs: none before this one.
  • Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44

AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.

Ready to merge per the maintainers' plan (green, no conflict, tested).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7255956853 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2046#issuecomment-7255956853). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T12:38:20Z. --- **Verified by OreoFR** — READY - Base: main 8fb974878 + this PR (head 0233a9ec7) merged with --no-ff (still no conflict with main cc0f662a7; the `runtime/CMakeLists.txt` conflict in the needs-rebase note is gone) - Red (main + this PR's test + its CMake registration, plus only the PR's `clear()/size()/empty()` accessors so the test compiles, without the null-out guards): `d3d12_xs_placed_depth` fails 9 of 46 checks. A null `out` still registers a range ("pool remains empty on null out"), and `*out` is not cleared on the 8 refusal paths. - Green (merge): 46/46; ctest in its own package (main + #2046 only): 502 tests, new failures vs main: none (failures: xbox_present and dxgi_waitable_latency as on main, plus xmem, xmem_no_write_watch and d3d12_mesh_heavy_cache once; all pass 5/5 when rerun alone on main and on the merge). ctest settings: Ninja RelWithDebInfo, all targets, gta6rt launchers excluded; main alone 501 tests, 2 failures (xbox_present, dxgi_waitable_latency). - gta6rt.exe links without the XMA decoder (`LEONIDA_CARGO=OFF`, `LEONIDA_XMA2_DECODER_LIB` empty); imports unchanged vs main (25 DLLs, no WS2_32) - Diff read: no issue. The only caller (`proxy_create_placed_resource_slot133`) already checks `out`, so the E_POINTER path changes nothing in game. The new accessors and the `__MINGW32__` GetDesc branch are additive. - Other runs: none before this one. - Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44 AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR. Ready to merge per the maintainers' plan (green, no conflict, tested).
enlight3d commented 2026-11-29 14:09:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T14:09:20Z.


I could not run the Linux build locally, so this is only what I found from the CI log and the current workflow.

  • The red linux-gpu-tools run (2026-11-26, head 0233a9e) failed at Build with vk_null_descriptor_test.cpp:97: error: 'LEONIDA_TEST_NULL_DESCRIPTORS_SPV' was not declared in this scope. That file is not touched by this PR; the PR only changes runtime/CMakeLists.txt, d3d12_xs_placed_depth.h and its test.
  • On current main, vk_null_descriptor_test.cpp wraps that code in #ifdef LEONIDA_TEST_NULL_DESCRIPTORS_SPV, so the error from that run should not reproduce after a rebase.
  • The PR has one commit and no newer CI run on this branch, so I cannot say it builds now. A rebase on main (or a re-run) would show it.
  • My WSL Ubuntu 24.04 has gcc/g++ 13.3 but no cmake, ninja, Vulkan headers or llvm-19, and installing them needs sudo, so I did not build.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7257082893 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2046#issuecomment-7257082893). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T14:09:20Z. --- I could not run the Linux build locally, so this is only what I found from the CI log and the current workflow. - The red `linux-gpu-tools` run (2026-11-26, head 0233a9e) failed at Build with `vk_null_descriptor_test.cpp:97: error: 'LEONIDA_TEST_NULL_DESCRIPTORS_SPV' was not declared in this scope`. That file is not touched by this PR; the PR only changes `runtime/CMakeLists.txt`, `d3d12_xs_placed_depth.h` and its test. - On current main, `vk_null_descriptor_test.cpp` wraps that code in `#ifdef LEONIDA_TEST_NULL_DESCRIPTORS_SPV`, so the error from that run should not reproduce after a rebase. - The PR has one commit and no newer CI run on this branch, so I cannot say it builds now. A rebase on main (or a re-run) would show it. - My WSL Ubuntu 24.04 has gcc/g++ 13.3 but no cmake, ninja, Vulkan headers or llvm-19, and installing them needs sudo, so I did not build.
MoonEyes commented 2026-11-29 14:19:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T14:19:16Z.


Merged at head 0233a9e. Tested by OreoFR on this head (Windows, RTX 4070): READY, new test red on main and green with the PR. Its red CI steps of 26/11 (linux Build, windows CPU runtime tests) were red on main the same day; Thib traced the Build one to vk_null_descriptor_test.cpp, which this PR does not touch. AI-assisted: yes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7257211438 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2046#issuecomment-7257211438). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T14:19:16Z. --- Merged at head 0233a9e. Tested by OreoFR on this head (Windows, RTX 4070): READY, new test red on main and green with the PR. Its red CI steps of 26/11 (linux Build, windows CPU runtime tests) were red on main the same day; Thib traced the Build one to vk_null_descriptor_test.cpp, which this PR does not touch. AI-assisted: yes.
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
ProjectLeonida/mandy!2046
No description provided.