d3d12: break title buffer device reference cycle (RT-TITLE-WINDOW-CLEANUP) #1521

Closed
exoticLgk wants to merge 1 commit from upstream-pr/1521 into main
exoticLgk commented 2026-11-25 03:18:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by exoticLgk on 2026-11-25T03:18:03Z.


Claimed in the coordination issue as: RT-TITLE-WINDOW-CLEANUP (#14).

What and why

Fix a COM reference cycle between the D3D12 device and its internally owned title-memory buffers.

The device retains buffers created by make_title_buffer() in title_buffers_, while each buffer retains a reference to the device. This prevents normal device destruction and resource cleanup.

With Vulkan validation enabled, both d3d12_title_index_window and d3d12_title_vertex_window previously passed despite reporting 11 leaked Vulkan objects each (VUID-vkDestroyDevice-device-05137).

This PR:

  • Removes the device back-reference from internally owned title buffers.
  • Releases retained title buffers after waiting for device idle and before draining deferred resource destruction.
  • Adds explicit resource cleanup and strict device reference-count assertions to the title-window tests.
  • Restores the strict reference-count assertion for xbox_geometry_upload_batch, previously relaxed in commit 7be70a9f5.
  • Checks Vulkan validation errors after test teardown, so destruction-time errors can no longer silently pass these tests.

Tested

Built successfully using scripts/build_runtime.ps1 on Windows.

With LEONIDA_VK_VALIDATION=1:

  • d3d12_draw: PASS
  • d3d12_title_index_window: PASS
  • d3d12_title_vertex_window: PASS
  • xbox_geometry_upload_batch: PASS

The previously observed Vulkan object leaks were no longer reported after the runtime fix. All four tests also pass with strict device reference-count assertions enabled.

Additional targeted regression tests: 10/10 passed.

Full runtime CTest suite:

  • 402 configured tests
  • 390 passed
  • 10 skipped
  • 2 disabled
  • 0 failed
  • Total runtime: 389.92 seconds

Tested against main f78385646, with a successful conflict-free merge simulation against 1cfc29af7. The newer merged tree has not been independently tested.

GPUs tested

NVIDIA GeForce RTX 4070 SUPER (12 GB)

  • Driver: 591.86
  • OS: Windows 11 Pro, build 26200
  • Vulkan SDK: 1.4.363.0

AMD, Linux and actual game execution have not been tested. XMA and SDL3-dependent GameInput coverage was unavailable in the local build.

AI-assisted

ChatGPT assisted with diagnosis, patch design, implementation, test selection and preparation of this PR. Compilation and tests were executed locally, and their actual outputs were reviewed.

Checklist

  • Claimed in the coordination issue before implementing the fix.
  • One focused topic.
  • Tested locally with Vulkan validation enabled.
  • Checked for merge conflicts against current main.
  • No game files, copyrighted game assets or generated game data included.
  • AI assistance disclosed.

No shader translator changes.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5484498028 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1521). Originally posted by [exoticLgk](https://github.com/exoticLgk) on 2026-11-25T03:18:03Z. --- Claimed in the coordination issue as: RT-TITLE-WINDOW-CLEANUP (#14). ## What and why Fix a COM reference cycle between the D3D12 device and its internally owned title-memory buffers. The device retains buffers created by `make_title_buffer()` in `title_buffers_`, while each buffer retains a reference to the device. This prevents normal device destruction and resource cleanup. With Vulkan validation enabled, both `d3d12_title_index_window` and `d3d12_title_vertex_window` previously passed despite reporting 11 leaked Vulkan objects each (`VUID-vkDestroyDevice-device-05137`). This PR: - Removes the device back-reference from internally owned title buffers. - Releases retained title buffers after waiting for device idle and before draining deferred resource destruction. - Adds explicit resource cleanup and strict device reference-count assertions to the title-window tests. - Restores the strict reference-count assertion for `xbox_geometry_upload_batch`, previously relaxed in commit `7be70a9f5`. - Checks Vulkan validation errors after test teardown, so destruction-time errors can no longer silently pass these tests. ## Tested Built successfully using `scripts/build_runtime.ps1` on Windows. With `LEONIDA_VK_VALIDATION=1`: - `d3d12_draw`: PASS - `d3d12_title_index_window`: PASS - `d3d12_title_vertex_window`: PASS - `xbox_geometry_upload_batch`: PASS The previously observed Vulkan object leaks were no longer reported after the runtime fix. All four tests also pass with strict device reference-count assertions enabled. Additional targeted regression tests: 10/10 passed. Full runtime CTest suite: - 402 configured tests - 390 passed - 10 skipped - 2 disabled - 0 failed - Total runtime: 389.92 seconds Tested against main `f78385646`, with a successful conflict-free merge simulation against `1cfc29af7`. The newer merged tree has not been independently tested. ## GPUs tested NVIDIA GeForce RTX 4070 SUPER (12 GB) - Driver: 591.86 - OS: Windows 11 Pro, build 26200 - Vulkan SDK: 1.4.363.0 AMD, Linux and actual game execution have not been tested. XMA and SDL3-dependent GameInput coverage was unavailable in the local build. ## AI-assisted ChatGPT assisted with diagnosis, patch design, implementation, test selection and preparation of this PR. Compilation and tests were executed locally, and their actual outputs were reviewed. ## Checklist - [x] Claimed in the coordination issue before implementing the fix. - [x] One focused topic. - [x] Tested locally with Vulkan validation enabled. - [x] Checked for merge conflicts against current main. - [x] No game files, copyrighted game assets or generated game data included. - [x] AI assistance disclosed. No shader translator changes.
ytsodacan commented 2026-11-25 03:34:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ytsodacan on 2026-11-25T03:34:04Z.


[KEEP]

  • Fix is well motivated: runtime/shims/d3d12_vulkan_device.cpp detaches the device back-reference from internal title buffers (attach_device(nullptr)) and releases title_buffers_ after vkDeviceWaitIdle and before drain_deleted_resources, breaking the reference cycle.
  • Tests in runtime/test/d3d12_draw_test.cpp restore the strict device_proxy_ref_count == 1 assertion and add a post-teardown Vulkan validation check.
  • No CI checks have reported for this PR, and the verification is a Windows-only local run, so lifetime and use-after-release risk is unconfirmed on CI. It needs a green run (or maintainer sign-off on runtime lifetime changes) first.
  • No conflicts; several other open d3d12 title-buffer PRs (#1160, #1273) touch nearby code, so check ordering.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7152034627 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1521#issuecomment-7152034627). Originally posted by [ytsodacan](https://github.com/ytsodacan) on 2026-11-25T03:34:04Z. --- **[KEEP]** - Fix is well motivated: `runtime/shims/d3d12_vulkan_device.cpp` detaches the device back-reference from internal title buffers (`attach_device(nullptr)`) and releases `title_buffers_` after `vkDeviceWaitIdle` and before `drain_deleted_resources`, breaking the reference cycle. - Tests in `runtime/test/d3d12_draw_test.cpp` restore the strict `device_proxy_ref_count == 1` assertion and add a post-teardown Vulkan validation check. - No CI checks have reported for this PR, and the verification is a Windows-only local run, so lifetime and use-after-release risk is unconfirmed on CI. It needs a green run (or maintainer sign-off on runtime lifetime changes) first. - No conflicts; several other open d3d12 title-buffer PRs (#1160, #1273) touch nearby code, so check ordering.
whoalin1 commented 2026-11-25 07:52:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T07:52:53Z.


Independent verification on both GPUs (native Windows 11, validation on):

  • NVIDIA RTX 4070 SUPER: 4/4 pass — d3d12_draw, d3d12_title_index_window, d3d12_title_vertex_window, xbox_geometry_upload_batch.
  • Leak claim confirmed: the unmodified parent prints vkDestroyDevice(): 11 leaked objects (VUID-vkDestroyDevice-device-05137) under --title-index-window; the PR build is clean (exit 0). --title-vertex-window also clean.
  • AMD Radeon iGPU (gfx1036, LEONIDA_PC_TAIL_UBO=1): all 4 fail identically on PR and unmodified-parent baseline — "pipelines need 144 bytes of push constants, device max 128". Pre-existing iGPU limit, not a regression.
  • PR is MERGEABLE.

AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7156356338 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1521#issuecomment-7156356338). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T07:52:53Z. --- Independent verification on both GPUs (native Windows 11, validation on): - **NVIDIA RTX 4070 SUPER**: 4/4 pass — `d3d12_draw`, `d3d12_title_index_window`, `d3d12_title_vertex_window`, `xbox_geometry_upload_batch`. - **Leak claim confirmed**: the unmodified parent prints `vkDestroyDevice(): 11 leaked objects (VUID-vkDestroyDevice-device-05137)` under `--title-index-window`; the PR build is clean (exit 0). `--title-vertex-window` also clean. - **AMD Radeon iGPU** (gfx1036, `LEONIDA_PC_TAIL_UBO=1`): all 4 fail identically on PR and unmodified-parent baseline — "pipelines need 144 bytes of push constants, device max 128". Pre-existing iGPU limit, not a regression. - PR is MERGEABLE. AI-assisted verification.
ammonium231 commented 2026-11-26 02:16:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ammonium231 on 2026-11-26T02:16:22Z.


RTX 3090 / 621.40, validation on: clears the device-teardown leak in d3d12_title_index_window, d3d12_title_vertex_window and xbox_geometry_upload_batch (main leaks 11, 11 and 20 objects, with this PR 0). Needs a trivial conflict resolve in d3d12_draw_test.cpp against current main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7180634031 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1521#issuecomment-7180634031). Originally posted by [ammonium231](https://github.com/ammonium231) on 2026-11-26T02:16:22Z. --- RTX 3090 / 621.40, validation on: clears the device-teardown leak in d3d12_title_index_window, d3d12_title_vertex_window and xbox_geometry_upload_batch (main leaks 11, 11 and 20 objects, with this PR 0). Needs a trivial conflict resolve in d3d12_draw_test.cpp against current main.
RenoThaGutta commented 2026-11-28 04:58:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by RenoThaGutta on 2026-11-28T04:58:45Z.


Independent RTX 4080 check of a local runtime-only adaptation of d31444234e91a2feb38aa0b7e4625a0a6f0b6b68 on baseline 02f71ccfe78160997a02950607be583af87e1180. Windows 11 Pro 25H2, NVIDIA 621.01, Khronos Vulkan validation enabled. Synthetic fixtures only. No GTA VI files were used.

The full PR patch conflicted with this baseline. I moved only its two runtime additions to the corresponding sites: dropping the internal buffers' device back-reference and releasing the retained buffers before draining deferred destruction. Both builds used the baseline test code.

MEASURED at device teardown (VUID-vkDestroyDevice-device-05137):

CTest case Baseline leaked objects With local adaptation
xbox_geometry_upload_batch 20 0
d3d12_title_index_window 11 0
d3d12_title_vertex_window 11 0

All six selected CTest cases passed in both builds. The teardown logs distinguish the two runs. These results cover the local adaptation only. Validation of the full PR will require a separate run after it applies cleanly.

Independent evidence review completed. AI-assisted: OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7234377393 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1521#issuecomment-7234377393). Originally posted by [RenoThaGutta](https://github.com/RenoThaGutta) on 2026-11-28T04:58:45Z. --- Independent RTX 4080 check of a **local runtime-only adaptation** of `d31444234e91a2feb38aa0b7e4625a0a6f0b6b68` on baseline `02f71ccfe78160997a02950607be583af87e1180`. Windows 11 Pro 25H2, NVIDIA 621.01, Khronos Vulkan validation enabled. Synthetic fixtures only. No GTA VI files were used. The full PR patch conflicted with this baseline. I moved only its two runtime additions to the corresponding sites: dropping the internal buffers' device back-reference and releasing the retained buffers before draining deferred destruction. Both builds used the baseline test code. **MEASURED** at device teardown (`VUID-vkDestroyDevice-device-05137`): | CTest case | Baseline leaked objects | With local adaptation | | --- | ---: | ---: | | `xbox_geometry_upload_batch` | 20 | 0 | | `d3d12_title_index_window` | 11 | 0 | | `d3d12_title_vertex_window` | 11 | 0 | All six selected CTest cases passed in both builds. The teardown logs distinguish the two runs. These results cover the local adaptation only. Validation of the full PR will require a separate run after it applies cleanly. Independent evidence review completed. AI-assisted: OpenAI Codex.
MoonEyes commented 2026-11-28 17:59:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:59:31Z.


Hi @exoticLgk, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/test/d3d12_draw_test.cpp), 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:7243443988 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1521#issuecomment-7243443988). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T17:59:31Z. --- Hi @exoticLgk, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/test/d3d12_draw_test.cpp`), 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).
enlight3d commented 2026-11-29 12:34:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T12:34:09Z.


Run of #1521 on a native Windows GPU (NVIDIA RTX 3090, Vulkan validation layer on). Synthetic tests only, no game files.

Heads: PR d31444234, main 8fb974878.
Merged or head-only: head-only. git merge --no-ff of the PR into main conflicts in runtime/test/d3d12_draw_test.cpp, so everything below ran on the PR head itself (detached at d31444234, merge base f78385646).

Commands:

git checkout --detach pr-1521
cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build -j 8 --target d3d12_draw_test gta6rt
ctest -R "^(d3d12_draw|d3d12_title_index_window|d3d12_title_vertex_window|xbox_geometry_upload_batch)$" --output-on-failure -j1
set LEONIDA_VK_VALIDATION=1   (and the same ctest line again)

Green: all 4 Passed, both without and with LEONIDA_VK_VALIDATION=1 (no leak or VUID message).

Red (behavioural): the PR's only non-test change, runtime/shims/d3d12_vulkan_device.cpp, reverted to the merge base, test changes kept. 3 of 4 fail, with and without validation:

  • xbox_geometry_upload_batch: d3d12_draw_test.cpp:1255 device_proxy_ref_count == 1; with validation also vkDestroyDevice(): 20 leaked objects (VUID-vkDestroyDevice-device-05137)
  • d3d12_title_index_window and d3d12_title_vertex_window: d3d12_draw_test.cpp:556 device_proxy_ref_count == 1; with validation also 11 leaked objects each
  • d3d12_draw passes in both states.
    All 4 pass again with the PR restored.

Link: no new imports vs the merge base f78385646 (gta6rt.exe built at both, 651 entries, identical lists). Against current main 8fb974878 (714 entries) the only entry present here and not in main is api-ms-win-crt-stdio-l1-1-0.dll!__stdio_common_vswscanf, which the merge-base build already has, so it is not from this PR.

Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44, RelWithDebInfo, Ninja, Vulkan SDK 1.4.363.1.

The branch conflicts with main in runtime/test/d3d12_draw_test.cpp; could you merge main into it so it can be tested merged?

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7255906163 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1521#issuecomment-7255906163). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T12:34:09Z. --- Run of #1521 on a native Windows GPU (NVIDIA RTX 3090, Vulkan validation layer on). Synthetic tests only, no game files. Heads: PR `d31444234`, main `8fb974878`. Merged or head-only: **head-only**. `git merge --no-ff` of the PR into main conflicts in `runtime/test/d3d12_draw_test.cpp`, so everything below ran on the PR head itself (detached at `d31444234`, merge base `f78385646`). Commands: ``` git checkout --detach pr-1521 cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON cmake --build runtime/build -j 8 --target d3d12_draw_test gta6rt ctest -R "^(d3d12_draw|d3d12_title_index_window|d3d12_title_vertex_window|xbox_geometry_upload_batch)$" --output-on-failure -j1 set LEONIDA_VK_VALIDATION=1 (and the same ctest line again) ``` Green: all 4 Passed, both without and with `LEONIDA_VK_VALIDATION=1` (no leak or VUID message). Red (behavioural): the PR's only non-test change, `runtime/shims/d3d12_vulkan_device.cpp`, reverted to the merge base, test changes kept. 3 of 4 fail, with and without validation: - `xbox_geometry_upload_batch`: `d3d12_draw_test.cpp:1255` `device_proxy_ref_count == 1`; with validation also `vkDestroyDevice(): 20 leaked objects` (VUID-vkDestroyDevice-device-05137) - `d3d12_title_index_window` and `d3d12_title_vertex_window`: `d3d12_draw_test.cpp:556` `device_proxy_ref_count == 1`; with validation also 11 leaked objects each - `d3d12_draw` passes in both states. All 4 pass again with the PR restored. Link: no new imports vs the merge base `f78385646` (gta6rt.exe built at both, 651 entries, identical lists). Against current main `8fb974878` (714 entries) the only entry present here and not in main is `api-ms-win-crt-stdio-l1-1-0.dll!__stdio_common_vswscanf`, which the merge-base build already has, so it is not from this PR. Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44, RelWithDebInfo, Ninja, Vulkan SDK 1.4.363.1. The branch conflicts with main in `runtime/test/d3d12_draw_test.cpp`; could you merge main into it so it can be tested merged?
aslan2142 commented 2026-12-01 16:36:42 +00:00 (Migrated from github.com)

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


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