Skip to content

Update Swapchain image count to obey present mode constraints#1081

Open
SRSaunders wants to merge 4 commits intoRobertBeckebans:masterfrom
SRSaunders:swap-image-count
Open

Update Swapchain image count to obey present mode constraints#1081
SRSaunders wants to merge 4 commits intoRobertBeckebans:masterfrom
SRSaunders:swap-image-count

Conversation

@SRSaunders
Copy link
Copy Markdown

@SRSaunders SRSaunders commented Mar 27, 2026

This PR separates and updates how semaphores are used for Vulkan image acquisition and presentation sync. This follows best practices documented in https://docs.vulkan.org/guide/latest/swapchain_semaphore_reuse.html.

  1. Separates image presentation from image acquisition semaphores.
  2. Allocates NUM_FRAME_DATA image acquisition semaphores to match the number of frames-in-flight for the renderer, and continues to use a circular queue for cycling through image acquisition semaphores.
  3. Dynamically allocates an addressable vector of presentation semaphores, sized to match the number of swapchain images allocated during swapchain creation.
  4. If VK_EXT_surface_maintenance1 is available in the implementation, requests minImageCount and maxImageCount for the specific presentation mode selected for the swapchain, and uses these to bound the requested swapchain image count during swapchain creation.
  5. Uses the m_SwapChainIndex returned from vkAcquireNextImageKHR() to index into the presentation semaphore vector when synchronizing within vkPresentKHR(). This is to support potential out-of-order image acquisition which can occur in certain circumstances depending on the presentation engine.
  6. Dynamically destroys, resizes, and recreates the presentation semaphore vector to match the swapchain image count when changing present (vsync) modes.

This PR also updates a macOS-specific item:

  1. macOS-only: Simplifies and updates the MoltenVK-specific Optick trace calculations (command buffer submit, image acquisition, and Metal encode timings) for better accuracy. I decided to do this since I was using Optick to verify the semaphore changes above.

Fixes #1080.

Tested on Windows 11 Vulkan, Manjaro Linux, and macOS Sequoia.

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.

Vulkan: Semaphore validation error on linux game exit

1 participant