Skip to content

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

Open
exoticLgk wants to merge 1 commit into
ProjectLeonida:mainfrom
exoticLgk:fix-title-window-cleanup
Open

exoticLgk wants to merge 1 commit into
ProjectLeonida:mainfrom
exoticLgk:fix-title-window-cleanup

Conversation

@exoticLgk

Copy link
Copy Markdown
Contributor

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.

@ytsodacan

ytsodacan commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

[KEEP]

@whoalin1

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@ammonium231

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants