runtime: guard null out/backing and skip expired entries in PlacedDepthTextures #2048

Closed
IlyassRS3 wants to merge 1 commit from upstream-pr/2048 into main
IlyassRS3 commented 2026-11-25 19:00:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T19:00:02Z.


Claim ID: RT-PLACED-DEPTH-NULL-OUT-AND-EXPIRED-RACE

Summary

Fixes four edge-case correctness and concurrency issues in rt::d3d12_xs::PlacedDepthTextures::create() (runtime/shims/d3d12_xs_placed_depth.h):

  1. Validate out and clear *out up front: Reject out == nullptr with E_POINTER before acquiring mutex_ or invoking create_backing (avoiding a wasted GPU depth/stencil texture allocation and dead ranges_ entry), and clear *out = nullptr immediately so every failure path (E_INVALIDARG, E_NOTIMPL, backing creation failure, E_OUTOFMEMORY) leaves *out null per COM rules.
  2. Guard null backing on S_OK: If create_backing(&resource) returns S_OK with resource == nullptr, return E_FAIL instead of constructing a PlacedDepthTexture with a null backing pointer and custom deleter [](ID3D12Resource* r) { r->Release(); } (which also now null-checks r).
  3. Close concurrent expiration race in overlap scan: Lock it->second.backing.lock() at the start of each iteration over ranges_ and erase/skip any entry that expired concurrently between std::erase_if and the loop, preventing spurious E_NOTIMPL rejections against an already-released placement and reusing the already-locked std::shared_ptr directly.
  4. Regression check: Adds a dirty-*out failure-clearing assertion in runtime/test/d3d12_placed_depth_test.h.

Verification

  • AI-assisted: yes (Antigravity agent by Google DeepMind)
  • GPUs tested: none (verified locally on macOS arm64 with Apple Clang 17 and minimal Win32/D3D12 stubs; Windows MSVC / Vulkan GPU CI verification of d3d12_depth_stencil_uav pending)
  • Sanitizers & tests (standalone harness exercising PlacedDepthTextures::create):
    • clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror: PASS (failures=0)
    • clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror (4 threads x 2,000 concurrent create/release alternating incompatible shapes at the same address): PASS (failures=0)
    • clang++ -std=c++20 -O2 -Wall -Wextra -Werror: PASS (failures=0)
    • Negative control on main: failed 3 assertions (invoked create_backing on out == nullptr, left *out dirty on E_INVALIDARG, and accepted S_OK with null resource, exit 1).
  • Repository checks: python3 -I scripts/check_no_game_data.py clean; python3 -I tests/test_text_write_line_endings.py (3/3 OK).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5497359001 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2048). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T19:00:02Z. --- Claim ID: `RT-PLACED-DEPTH-NULL-OUT-AND-EXPIRED-RACE` ### Summary Fixes four edge-case correctness and concurrency issues in `rt::d3d12_xs::PlacedDepthTextures::create()` (`runtime/shims/d3d12_xs_placed_depth.h`): 1. **Validate `out` and clear `*out` up front:** Reject `out == nullptr` with `E_POINTER` before acquiring `mutex_` or invoking `create_backing` (avoiding a wasted GPU depth/stencil texture allocation and dead `ranges_` entry), and clear `*out = nullptr` immediately so every failure path (`E_INVALIDARG`, `E_NOTIMPL`, backing creation failure, `E_OUTOFMEMORY`) leaves `*out` null per COM rules. 2. **Guard null backing on `S_OK`:** If `create_backing(&resource)` returns `S_OK` with `resource == nullptr`, return `E_FAIL` instead of constructing a `PlacedDepthTexture` with a null `backing` pointer and custom deleter `[](ID3D12Resource* r) { r->Release(); }` (which also now null-checks `r`). 3. **Close concurrent expiration race in overlap scan:** Lock `it->second.backing.lock()` at the start of each iteration over `ranges_` and erase/skip any entry that expired concurrently between `std::erase_if` and the loop, preventing spurious `E_NOTIMPL` rejections against an already-released placement and reusing the already-locked `std::shared_ptr` directly. 4. **Regression check:** Adds a dirty-`*out` failure-clearing assertion in `runtime/test/d3d12_placed_depth_test.h`. ### Verification - **AI-assisted:** yes (Antigravity agent by Google DeepMind) - **GPUs tested:** none (verified locally on macOS arm64 with Apple Clang 17 and minimal Win32/D3D12 stubs; Windows MSVC / Vulkan GPU CI verification of `d3d12_depth_stencil_uav` pending) - **Sanitizers & tests (standalone harness exercising `PlacedDepthTextures::create`):** - `clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror`: PASS (`failures=0`) - `clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror` (4 threads x 2,000 concurrent create/release alternating incompatible shapes at the same address): PASS (`failures=0`) - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror`: PASS (`failures=0`) - Negative control on `main`: failed 3 assertions (invoked `create_backing` on `out == nullptr`, left `*out` dirty on `E_INVALIDARG`, and accepted `S_OK` with null `resource`, exit `1`). - **Repository checks:** `python3 -I scripts/check_no_game_data.py` clean; `python3 -I tests/test_text_write_line_endings.py` (3/3 OK).
copilot-pull-request-reviewer[bot] commented 2026-11-25 19:00:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T19:00:20Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6063318340 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2048#pullrequestreview-6063318340). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T19:00:20Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
zmasi commented 2026-11-28 11:36:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:36:19Z.


#2048 | head f5ad49eaaf (merged cleanly with main 4a54aedcb6) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^d3d12_depth_stencil_uav$" --output-on-failure (LEONIDA_VK_VALIDATION=1) + direct PlacedDepthTextures::create probe | red on main: direct PlacedDepthTextures::create probe fails on main (hr=0x80070057 leaves dirty *out non-null; note: the added d3d12_placed_depth_test.h check calls xbox slot 133 in d3d12_xs_device.cpp, which already zeroes *out before delegating to PlacedDepthTextures::create, so unmodified d3d12_depth_stencil_uav passes on both main and PR+main) | green on PR+main: d3d12_depth_stencil_uav passes (both unmodified and with the direct PlacedDepthTextures::create null-out / dirty-*out / null-backing probe) on RTX 3090 with 0 Khronos validation errors; check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238661768 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2048#issuecomment-7238661768). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T11:36:19Z. --- #2048 | head f5ad49eaaf6fd3482f503bf90bdbdd453d84ac1d (merged cleanly with main 4a54aedcb6b66525e0c9f72a6ea10263337c9141) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^d3d12_depth_stencil_uav$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) + direct `PlacedDepthTextures::create` probe | red on main: direct `PlacedDepthTextures::create` probe fails on `main` (`hr=0x80070057` leaves dirty `*out` non-null; note: the added `d3d12_placed_depth_test.h` check calls `xbox` slot 133 in `d3d12_xs_device.cpp`, which already zeroes `*out` before delegating to `PlacedDepthTextures::create`, so unmodified `d3d12_depth_stencil_uav` passes on both `main` and `PR+main`) | green on PR+main: `d3d12_depth_stencil_uav` passes (both unmodified and with the direct `PlacedDepthTextures::create` null-`out` / dirty-`*out` / null-backing probe) on RTX 3090 with `0` Khronos validation errors; `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
OreoFR commented 2026-11-28 21:58:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:58:59Z.


Verified by OreoFR

  • Base: main c1ecf04ed + PR head f5ad49eaa; green run in a merge package of 16 PRs, no new ctest failure vs main
  • Test: ctest -R ^d3d12_depth_stencil_uav$
  • Red on main: OK (PR test diff applied; main changed the file)
  • Green with the PR: OK
  • Verdict: NO RED (the new case already passes on main)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246412055 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2048#issuecomment-7246412055). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:58:59Z. --- **Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `f5ad49eaa`; green run in a merge package of 16 PRs, no new ctest failure vs main - Test: `ctest -R ^d3d12_depth_stencil_uav$` - Red on main: OK (PR test diff applied; main changed the file) - Green with the PR: OK - Verdict: NO RED (the new case already passes on main) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
enlight3d commented 2026-11-29 00:45:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T00:45:22Z.


Run of #2048 (ctest), by enlight3d. Nothing pushed. Result: green, but no red could be obtained from the committed test.

Heads: PR f5ad49eaa (base 9f9a7c5f3, older than main), main 1bc055e6c. git merge-tree --write-tree main <PR head> is clean (no conflicts; main changed runtime/test/d3d12_placed_depth_test.h since the base).
The PR changes runtime/shims/d3d12_xs_placed_depth.h (null out, null backing on S_OK, expired-entry handling in the overlap scan) and adds one check to runtime/test/d3d12_placed_depth_test.h. That header is included by d3d12_depth_stencil_uav_test (ctest d3d12_depth_stencil_uav), which needs a D3D12 device; it ran on the GPU below (not skipped).

Machine: NVIDIA GeForce RTX 3090 24 GB, driver 621.40, Windows 11 Pro (build 10.0.26300), MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo.

Commands (vcvars64 environment, only this target built, glslangValidator from the Vulkan SDK):

cmake -S runtime -B bld -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build bld --target d3d12_depth_stencil_uav_test -j 8
ctest --test-dir bld -R "^d3d12_depth_stencil_uav$" --output-on-failure
  • GREEN (PR head): d3d12_depth_stencil_uav Passed (1/1, 2.0 s), device is the RTX 3090.
  • RED attempt (PR head with d3d12_xs_placed_depth.h taken from main, new test check kept): still Passed. No red.
  • Why: the only caller of PlacedDepthTextures::create (the slot 133 handler in d3d12_xs_device.cpp) tests out for null before the call and sets *out = nullptr before the call and again after a refusal. The new check goes through that handler, so it cannot see the *out = nullptr added in create(). The null-backing and expired-entry changes are not exercised by any committed test. So this PR's fixes are defensive hardening for direct callers, and its test passes on main's header too. I did not invent a red. The description's negative control comes from a standalone harness that is not in the PR.

Question for the author: could you add a committed test that reaches PlacedDepthTextures::create directly (null backing on S_OK, an expired entry in the overlap scan)? With one, the fixes would have a red/green here.
Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248329066 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2048#issuecomment-7248329066). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T00:45:22Z. --- Run of #2048 (ctest), by enlight3d. Nothing pushed. Result: green, but no red could be obtained from the committed test. Heads: PR `f5ad49eaa` (base `9f9a7c5f3`, older than main), main `1bc055e6c`. `git merge-tree --write-tree main <PR head>` is clean (no conflicts; main changed `runtime/test/d3d12_placed_depth_test.h` since the base). The PR changes `runtime/shims/d3d12_xs_placed_depth.h` (null `out`, null backing on S_OK, expired-entry handling in the overlap scan) and adds one check to `runtime/test/d3d12_placed_depth_test.h`. That header is included by `d3d12_depth_stencil_uav_test` (ctest `d3d12_depth_stencil_uav`), which needs a D3D12 device; it ran on the GPU below (not skipped). Machine: NVIDIA GeForce RTX 3090 24 GB, driver 621.40, Windows 11 Pro (build 10.0.26300), MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo. Commands (vcvars64 environment, only this target built, glslangValidator from the Vulkan SDK): ``` cmake -S runtime -B bld -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON cmake --build bld --target d3d12_depth_stencil_uav_test -j 8 ctest --test-dir bld -R "^d3d12_depth_stencil_uav$" --output-on-failure ``` - GREEN (PR head): `d3d12_depth_stencil_uav` Passed (1/1, 2.0 s), device is the RTX 3090. - RED attempt (PR head with `d3d12_xs_placed_depth.h` taken from main, new test check kept): still Passed. No red. - Why: the only caller of `PlacedDepthTextures::create` (the slot 133 handler in `d3d12_xs_device.cpp`) tests `out` for null before the call and sets `*out = nullptr` before the call and again after a refusal. The new check goes through that handler, so it cannot see the `*out = nullptr` added in `create()`. The null-backing and expired-entry changes are not exercised by any committed test. So this PR's fixes are defensive hardening for direct callers, and its test passes on main's header too. I did not invent a red. The description's negative control comes from a standalone harness that is not in the PR. Question for the author: could you add a committed test that reaches `PlacedDepthTextures::create` directly (null backing on S_OK, an expired entry in the overlap scan)? With one, the fixes would have a red/green here. Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.
aslan2142 commented 2026-12-01 16:41:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:41:34Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318046435 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2048#issuecomment-7318046435). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:41:34Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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!2048
No description provided.