[PR #2048] runtime: guard null out/backing and skip expired entries in PlacedDepthTextures #2054

Open
opened 2026-11-26 21:19:52 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2048
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: rt/placed-depth-null-out-and-expired-race


📝 Commits (1)

  • f5ad49e runtime: guard null out/backing and skip expired entries in PlacedDepthTextures

📊 Changes

2 files changed (+22 additions, -4 deletions)

View changed files

📝 runtime/shims/d3d12_xs_placed_depth.h (+17 -4)
📝 runtime/test/d3d12_placed_depth_test.h (+5 -0)

📄 Description

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).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2048 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `rt/placed-depth-null-out-and-expired-race` --- ### 📝 Commits (1) - [`f5ad49e`](https://github.com/ubiquitarianism/leonida/commit/f5ad49eaaf6fd3482f503bf90bdbdd453d84ac1d) runtime: guard null out/backing and skip expired entries in PlacedDepthTextures ### 📊 Changes **2 files changed** (+22 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_xs_placed_depth.h` (+17 -4) 📝 `runtime/test/d3d12_placed_depth_test.h` (+5 -0) </details> ### 📄 Description 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2054
No description provided.