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

Open
github-bot wants to merge 1 commit from github-bot/gh-2048 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 19:00 UTC · original
IlyassRS3:rt/placed-depth-null-out-and-expired-race → main · +22 −4 · 2 files · 1 commits · open

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).
**@⁠IlyassRS3** on GitHub · 2026-11-25 19:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2048) `IlyassRS3:rt/placed-depth-null-out-and-expired-race` → `main` · +22 −4 · 2 files · 1 commits · open 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:16:02 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 19:00 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 19:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2048#pullrequestreview-6063318340) · **reviewed** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2048/head:github-bot/gh-2048'
git switch 'github-bot/gh-2048'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2048'
git switch 'github-bot/gh-2048'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2048'
git switch 'github-bot/gh-2048'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2048'
git switch 'main'
git merge --squash 'github-bot/gh-2048'
git switch 'main'
git merge --ff-only 'github-bot/gh-2048'
git switch 'main'
git merge 'github-bot/gh-2048'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.