[PR #2024] runtime: make RewrittenBlob COM refcount atomic in d3d12_xs_rootsig #2030

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

📋 Pull Request Information

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

Base: main ← Head: fix/rt-xs-rootsig-atomic-blob-refcount


📝 Commits (1)

  • f1d796c runtime: make RewrittenBlob COM refcount atomic in d3d12_xs_rootsig

📊 Changes

2 files changed (+84 additions, -3 deletions)

View changed files

📝 runtime/shims/d3d12_xs_rootsig.cpp (+4 -3)
📝 runtime/test/root_sig_test.cpp (+80 -0)

📄 Description

Coordination item: RT-XS-ROOTSIG-ATOMIC-BLOB-REFCOUNT (claimed on #1608).

Why

RewrittenBlob in runtime/shims/d3d12_xs_rootsig.cpp (returned by serialize_versioned_keeping_heap_flags and serialize_legacy_keeping_heap_flags when retrying directly-indexed root-signature flags) implements the COM ID3DBlob interface with a plain non-atomic ULONG refs_ = 1 incremented/decremented via ++refs_ / --refs_. COM objects handed back to the title can have AddRef/Release/QueryInterface called concurrently from multiple worker threads (e.g. pipeline/root-signature build threads), which causes a data race, lost increments/decrements, and premature delete this / use-after-free or leaks.

Changes

  • runtime/shims/d3d12_xs_rootsig.cpp: change RewrittenBlob::refs_ to std::atomic<ULONG> refs_{1} using fetch_add(1, std::memory_order_relaxed) + 1 in AddRef() and fetch_sub(1, std::memory_order_acq_rel) - 1 in Release().
  • runtime/test/root_sig_test.cpp: add test_rewritten_blob_concurrent_refcount() exercising serialize_versioned_keeping_heap_flags()'s retry path, verifying restored RTS0 flags, and stressing 4 threads × 20,000 concurrent AddRef/Release pairs on the returned RewrittenBlob.

Verification

  • AI-assisted: yes (Antigravity agent by Google DeepMind).
  • GPUs tested: none (CPU-only verification on macOS arm64 using minimal local d3d12.h COM/struct stubs; Windows CI / full root_sig_test covers the live host d3d12.dll paths).
  • Compiled runtime/shims/d3d12_xs_rootsig.cpp + concurrency test harness with clang++ -std=c++20 -Wall -Wextra -Werror:
    • ASan+UBSan (-O1 -g -fsanitize=address,undefined): 10/10 PASS.
    • TSan (-O1 -g -fsanitize=thread): 10/10 PASS, 0 data races (negative control against main's d3d12_xs_rootsig.cpp reliably tripped WARNING: ThreadSanitizer: data race in RewrittenBlob::AddRef).
    • Release (-O2): 10/10 PASS.
  • python3 -I scripts/check_no_game_data.py runtime/shims/d3d12_xs_rootsig.cpp runtime/test/root_sig_test.cpp: 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/2024 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-xs-rootsig-atomic-blob-refcount` --- ### 📝 Commits (1) - [`f1d796c`](https://github.com/ubiquitarianism/leonida/commit/f1d796cdaf14efd21828eb18af5a81cf46532969) runtime: make RewrittenBlob COM refcount atomic in d3d12_xs_rootsig ### 📊 Changes **2 files changed** (+84 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_xs_rootsig.cpp` (+4 -3) 📝 `runtime/test/root_sig_test.cpp` (+80 -0) </details> ### 📄 Description Coordination item: `RT-XS-ROOTSIG-ATOMIC-BLOB-REFCOUNT` (claimed on #1608). ### Why `RewrittenBlob` in `runtime/shims/d3d12_xs_rootsig.cpp` (returned by `serialize_versioned_keeping_heap_flags` and `serialize_legacy_keeping_heap_flags` when retrying directly-indexed root-signature flags) implements the COM `ID3DBlob` interface with a plain non-atomic `ULONG refs_ = 1` incremented/decremented via `++refs_` / `--refs_`. COM objects handed back to the title can have `AddRef`/`Release`/`QueryInterface` called concurrently from multiple worker threads (e.g. pipeline/root-signature build threads), which causes a data race, lost increments/decrements, and premature `delete this` / use-after-free or leaks. ### Changes - `runtime/shims/d3d12_xs_rootsig.cpp`: change `RewrittenBlob::refs_` to `std::atomic<ULONG> refs_{1}` using `fetch_add(1, std::memory_order_relaxed) + 1` in `AddRef()` and `fetch_sub(1, std::memory_order_acq_rel) - 1` in `Release()`. - `runtime/test/root_sig_test.cpp`: add `test_rewritten_blob_concurrent_refcount()` exercising `serialize_versioned_keeping_heap_flags()`'s retry path, verifying restored RTS0 flags, and stressing 4 threads × 20,000 concurrent `AddRef`/`Release` pairs on the returned `RewrittenBlob`. ### Verification - AI-assisted: yes (Antigravity agent by Google DeepMind). - GPUs tested: none (CPU-only verification on macOS arm64 using minimal local `d3d12.h` COM/struct stubs; Windows CI / full `root_sig_test` covers the live host `d3d12.dll` paths). - Compiled `runtime/shims/d3d12_xs_rootsig.cpp` + concurrency test harness with `clang++ -std=c++20 -Wall -Wextra -Werror`: - ASan+UBSan (`-O1 -g -fsanitize=address,undefined`): 10/10 PASS. - TSan (`-O1 -g -fsanitize=thread`): 10/10 PASS, 0 data races (negative control against `main`'s `d3d12_xs_rootsig.cpp` reliably tripped `WARNING: ThreadSanitizer: data race` in `RewrittenBlob::AddRef`). - Release (`-O2`): 10/10 PASS. - `python3 -I scripts/check_no_game_data.py runtime/shims/d3d12_xs_rootsig.cpp runtime/test/root_sig_test.cpp`: 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#2030
No description provided.