Skip to content

dxgi, vulkan_present: release the swapchain before the device, make c… - #8163

Open
chase16647 wants to merge 1 commit into
ItsNotRexed:mainfrom
chase16647:claude/d3d-818-819
Open

chase16647 wants to merge 1 commit into
ItsNotRexed:mainfrom
chase16647:claude/d3d-818-819

Conversation

@chase16647

Copy link
Copy Markdown

Claimed in the coordination issue as: D3D-818, D3D-819

What and why

D3D-818: SwapChain::~SwapChain() (runtime/shims/dxgi_com.cpp) released device_ in its body, but the VulkanSwapchain swapchain_ member is destroyed after the body and still calls vkDestroySwapchainKHR / vkDestroyCommandPool / vkDestroyFence on that VkDevice, which may already be gone if that was the last reference. VulkanSwapchain (runtime/shims/dxgi_swapchain.h) now has an idempotent release(); the destructor calls it before dropping the device reference, and ~VulkanSwapchain() calling it again is a no-op.

D3D-819: VulkanPresenter::finish_image() (runtime/src/vulkan_present.h) copied the swapchain image into the host-mapped capture buffer with no TRANSFER -> HOST barrier, so read_back() waiting on the frame fence was not guaranteed to see the transfer write. Adds a buffer barrier (TRANSFER_WRITE -> HOST_READ, TRANSFER -> HOST stage) after the copy.

Tested

Not compiled or run yet: written in a Linux container with no Windows SDK or Vulkan headers. Needs a Windows build and the vk_presenter_sync / dxgi_swapchain_count / xbox_present tests.

AI-assisted: yes

Checklist

  • 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, no translator change)

…apture copies host-visible (D3D-818, D3D-819)

D3D-818: SwapChain's destructor released device_ in its body, but the
VulkanSwapchain member was destroyed after it and still called vkDestroy*
on that VkDevice. VulkanSwapchain gets an idempotent release(), called
before the device reference is dropped.

D3D-819: the presenter's capture copy had no TRANSFER -> HOST barrier, so
read_back() could read the mapped buffer before the transfer write was
available to the host. Adds the buffer barrier after the copy.

AI-assisted. Not compiled or run: no Windows SDK or Vulkan headers here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TkBVaqvpxzN45gFT7vSdoL
@Valentinlqx

Copy link
Copy Markdown

Built and ran 5def7369a (on main dde82f27e) on Windows, since the description says it wasn't compiled yet. Windows 11 Pro 26200, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0, NVIDIA RTX 4060 (617.14). Implicit overlay layers off. No game files.

  • It compiles: vk_presenter_sync_test, dxgi_device_test, xbox_present_test, dxgi_swapchain_test and dxgi_swapchain_count_test build with 0 errors. The only warning in the changed files, C4189 at vulkan_present.h:669 ('device' unused), is also on main; it isn't from this change.
  • ctest -R "^(vk_presenter_sync|dxgi_device|xbox_present|dxgi_swapchain|dxgi_swapchain_count)$": 5/5 pass, and 5/5 again with LEONIDA_VK_VALIDATION=1 VK_KHRONOS_VALIDATION_VALIDATE_SYNC=1 (dxgi_swapchain_test: "0 validation errors").
  • Control: main passes the same 5, plain and under the same validation, with 0 validation errors as well. So on this GPU none of these tests exercises D3D-818 (the swapchain outliving its device) or D3D-819 (the missing TRANSFER → HOST barrier). The change doesn't break them, but they don't confirm it either. A test that drops the last device reference before the swapchain, or sync validation over read_back(), would.

AI-assisted (Claude Code).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants