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

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

@⁠exoticLgk on GitHub · 2026-11-25 03:18 UTC · original
exoticLgk:fix-title-window-cleanup → main · +28 −7 · 2 files · 1 commits · open

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.

**@⁠exoticLgk** on GitHub · 2026-11-25 03:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1521) `exoticLgk:fix-title-window-cleanup` → `main` · +28 −7 · 2 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:13 +00:00
Author
Owner

@⁠ytsodacan on GitHub · 2026-11-25 03:34 UTC · original · edited 2026-11-25 03:45 UTC

[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.
**@⁠ytsodacan** on GitHub · 2026-11-25 03:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1521#issuecomment-7152034627) · edited 2026-11-25 03:45 UTC **[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.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 07:52 UTC · original

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.

**@⁠whoalin1** on GitHub · 2026-11-25 07:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1521#issuecomment-7156356338) 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.
Author
Owner

@⁠ammonium231 on GitHub · 2026-11-26 02:16 UTC · original

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.

**@⁠ammonium231** on GitHub · 2026-11-26 02:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1521#issuecomment-7180634031) 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.
This pull request has changes conflicting with the target branch.
  • runtime/test/d3d12_draw_test.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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