d3d12: implement ID3D12Device5::CreateLifetimeTracker and ID3D12LifetimeTracker::DestroyOwnedObject (D3D-LIFETIME-TRACKER) #438

Closed
jujumoneylol wants to merge 1 commit from upstream-pr/438 into main
jujumoneylol commented 2026-11-24 05:20:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by jujumoneylol on 2026-11-24T05:20:18Z.


Claimed in the coordination issue as: D3D-LIFETIME-TRACKER (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7122816234)

What and why

Implements PC ID3D12Device5::CreateLifetimeTracker and ID3D12LifetimeTracker::DestroyOwnedObject in the Vulkan D3D12 shim (runtime/shims/d3d12_vulkan_device.cpp), replacing the E_NOTIMPL stub.

  • Adds LifetimeTracker (ID3D12LifetimeTracker / ID3D12DeviceChild / ID3D12Object) holding a non-owning ID3D12LifetimeOwner* pointer (matching Windows D3D12, which does not AddRef the owner at creation).
  • Matches Windows 11 D3D12 (d3d12.dll) parameter validation on CreateLifetimeTracker:
    • owner == nullptr → E_INVALIDARG (0x80070057)
    • out == nullptr → E_UNEXPECTED (0x8000FFFF)
    • unknown riid → E_NOINTERFACE (0x80004002)
    • valid create → S_OK, owner refcount delta (+0 -> +0), 0 callbacks at creation, GetDevice returns the owning device.
  • Implements DestroyOwnedObject(ID3D12DeviceChild*): rejects nullptr and foreign-device objects with E_INVALIDARG, drains submitted Vulkan work (vkDeviceWaitIdle under submit_mutex()), and invokes owner->LifetimeStateUpdated(D3D12_LIFETIME_STATE_NOT_IN_USE).
  • Adds d3d12_lifetime_tracker_test comparing our Vulkan device side-by-side against host Windows D3D12 (WARP).
  • Note: this implements the PC ID3D12Device5 / ID3D12LifetimeTracker contract; it does not make any assumptions about Xbox Series device slot 57 semantics beyond PC fallback.

Tested

  • Built d3d12_lifetime_tracker_test and d3d12_existing_heap_test with MSVC 19.44 (vcvars64) + Ninja on top of main 8f481cf16.
  • d3d12_lifetime_tracker_test: ALL CHECKS PASSED — EXACT MATCH against host Windows D3D12 (WARP) on CreateLifetimeTracker error codes, refcounting, and GetDevice, plus DestroyOwnedObject valid/null/foreign-device checks on Vulkan.
  • d3d12_existing_heap_test: PASSED — existing-heap and lifetime-tracker refusal checks match both host GTX 1650 D3D12 and WARP (8/8 OpenExistingHeapFromAddress cases match).
  • py -3.13 -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/test/d3d12_lifetime_tracker_test.cpp runtime/CMakeLists.txt: clean.

GPUs tested: NVIDIA GeForce GTX 1650 (driver 592.00, Windows 11 26200) and Microsoft WARP (d3d12.dll, Windows 11 26200)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — runtime D3D12 shim only)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5466595321 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/438). Originally posted by [jujumoneylol](https://github.com/jujumoneylol) on 2026-11-24T05:20:18Z. --- Claimed in the coordination issue as: D3D-LIFETIME-TRACKER (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7122816234) ### What and why Implements PC `ID3D12Device5::CreateLifetimeTracker` and `ID3D12LifetimeTracker::DestroyOwnedObject` in the Vulkan D3D12 shim (`runtime/shims/d3d12_vulkan_device.cpp`), replacing the `E_NOTIMPL` stub. - Adds `LifetimeTracker` (`ID3D12LifetimeTracker` / `ID3D12DeviceChild` / `ID3D12Object`) holding a non-owning `ID3D12LifetimeOwner*` pointer (matching Windows D3D12, which does not `AddRef` the owner at creation). - Matches Windows 11 D3D12 (`d3d12.dll`) parameter validation on `CreateLifetimeTracker`: - `owner == nullptr` → `E_INVALIDARG` (`0x80070057`) - `out == nullptr` → `E_UNEXPECTED` (`0x8000FFFF`) - unknown `riid` → `E_NOINTERFACE` (`0x80004002`) - valid create → `S_OK`, owner refcount delta `(+0 -> +0)`, 0 callbacks at creation, `GetDevice` returns the owning device. - Implements `DestroyOwnedObject(ID3D12DeviceChild*)`: rejects `nullptr` and foreign-device objects with `E_INVALIDARG`, drains submitted Vulkan work (`vkDeviceWaitIdle` under `submit_mutex()`), and invokes `owner->LifetimeStateUpdated(D3D12_LIFETIME_STATE_NOT_IN_USE)`. - Adds `d3d12_lifetime_tracker_test` comparing our Vulkan device side-by-side against host Windows D3D12 (WARP). - Note: this implements the PC `ID3D12Device5` / `ID3D12LifetimeTracker` contract; it does not make any assumptions about Xbox Series device slot 57 semantics beyond PC fallback. ### Tested - Built `d3d12_lifetime_tracker_test` and `d3d12_existing_heap_test` with MSVC 19.44 (`vcvars64`) + Ninja on top of `main` `8f481cf16`. - `d3d12_lifetime_tracker_test`: ALL CHECKS PASSED — `EXACT MATCH` against host Windows D3D12 (WARP) on `CreateLifetimeTracker` error codes, refcounting, and `GetDevice`, plus `DestroyOwnedObject` valid/null/foreign-device checks on Vulkan. - `d3d12_existing_heap_test`: PASSED — existing-heap and lifetime-tracker refusal checks match both host GTX 1650 D3D12 and WARP (8/8 `OpenExistingHeapFromAddress` cases match). - `py -3.13 -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/test/d3d12_lifetime_tracker_test.cpp runtime/CMakeLists.txt`: clean. GPUs tested: NVIDIA GeForce GTX 1650 (driver 592.00, Windows 11 26200) and Microsoft WARP (`d3d12.dll`, Windows 11 26200) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — runtime D3D12 shim only)
Sangonapou commented 2026-11-24 18:56:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Sangonapou on 2026-11-24T18:56:12Z.


Tested 811039f9 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: pass

Built at this head with scripts\build_runtime.ps1 (MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0). No game files.

ctest -R ^d3d12_lifetime_tracker$ -V: passed, Parity against real Windows D3D12 (WARP): EXACT MATCH on CreateLifetimeTracker & refcounting, ALL CHECKS PASSED.

For whoever reviews the Destroy part, the two lines as printed here (the destroy fields differ between the layer and WARP; the parity line covers creation and refcounting):

[vulkan] null_owner=0x80070057 null_out=0x8000FFFF bad_iid=0x80004002 ok=0x00000000 owner_ref_delta=(+0 -> +0) cb_create=0 destroy_null=0x80070057 destroy_ok=0x00000000 cb_destroy=1 last_state=1 destroy_foreign=0x80070057 get_dev=1
[host-warp] null_owner=0x80070057 null_out=0x8000FFFF bad_iid=0x80004002 ok=0x00000000 owner_ref_delta=(+0 -> +0) cb_create=0 destroy_null=0x00000000 destroy_ok=0x80070057 cb_destroy=0 last_state=-1 destroy_foreign=0x00000000 get_dev=1
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7141359993 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/438#issuecomment-7141359993). Originally posted by [Sangonapou](https://github.com/Sangonapou) on 2026-11-24T18:56:12Z. --- Tested 811039f9 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: pass Built at this head with `scripts\build_runtime.ps1` (MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0). No game files. `ctest -R ^d3d12_lifetime_tracker$ -V`: passed, `Parity against real Windows D3D12 (WARP): EXACT MATCH on CreateLifetimeTracker & refcounting`, `ALL CHECKS PASSED`. For whoever reviews the Destroy part, the two lines as printed here (the destroy fields differ between the layer and WARP; the parity line covers creation and refcounting): ``` [vulkan] null_owner=0x80070057 null_out=0x8000FFFF bad_iid=0x80004002 ok=0x00000000 owner_ref_delta=(+0 -> +0) cb_create=0 destroy_null=0x80070057 destroy_ok=0x00000000 cb_destroy=1 last_state=1 destroy_foreign=0x80070057 get_dev=1 [host-warp] null_owner=0x80070057 null_out=0x8000FFFF bad_iid=0x80004002 ok=0x00000000 owner_ref_delta=(+0 -> +0) cb_create=0 destroy_null=0x00000000 destroy_ok=0x80070057 cb_destroy=0 last_state=-1 destroy_foreign=0x00000000 get_dev=1 ```
madhyn commented 2026-11-24 22:45:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by madhyn on 2026-11-24T22:45:09Z.


Tested 811039f96 on Arch Linux + Wine 11.22 (clang-cl + xwin) with an NVIDIA GeForce RTX 3060 Ti:

  • d3d12_lifetime_tracker_test.exe:
    • [vulkan] (the layer): all checks passed (null_owner=0x80070057 null_out=0x8000FFFF bad_iid=0x80004002 ok=0x00000000 owner_ref_delta=(+0 -> +0) cb_create=0 destroy_null=0x80070057 destroy_ok=0x00000000 cb_destroy=1 last_state=1 destroy_foreign=0x80070057 get_dev=1).
    • [host-warp] (Wine vkd3d): failed at line 103 (FAIL [host-warp] line 103: SUCCEEDED(obs.create_ok) && tracker.p != nullptr) because Wine's vkd3d currently stubs d3d12_device_CreateLifetimeTracker.

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7146602525 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/438#issuecomment-7146602525). Originally posted by [madhyn](https://github.com/madhyn) on 2026-11-24T22:45:09Z. --- Tested `811039f96` on Arch Linux + Wine 11.22 (clang-cl + xwin) with an NVIDIA GeForce RTX 3060 Ti: - `d3d12_lifetime_tracker_test.exe`: - `[vulkan]` (the layer): **all checks passed** (`null_owner=0x80070057 null_out=0x8000FFFF bad_iid=0x80004002 ok=0x00000000 owner_ref_delta=(+0 -> +0) cb_create=0 destroy_null=0x80070057 destroy_ok=0x00000000 cb_destroy=1 last_state=1 destroy_foreign=0x80070057 get_dev=1`). - `[host-warp]` (Wine vkd3d): failed at line 103 (`FAIL [host-warp] line 103: SUCCEEDED(obs.create_ok) && tracker.p != nullptr`) because Wine's `vkd3d` currently stubs `d3d12_device_CreateLifetimeTracker`. AI-assisted: yes
MoonEyes commented 2026-11-27 23:19:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:19:44Z.


Hi @jujumoneylol, 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:7230055089 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/438#issuecomment-7230055089). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:19:44Z. --- Hi @jujumoneylol, 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).
aslan2142 commented 2026-12-01 16:30:13 +00:00 (Migrated from github.com)

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


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:7317714291 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/438#issuecomment-7317714291). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:30:13Z. --- 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!438
No description provided.