Overv / VulkanTutorial

Tutorial for the Vulkan graphics and compute API
https://vulkan-tutorial.com
Creative Commons Attribution Share Alike 4.0 International
3.06k stars 511 forks source link

There may be a problem with the `imageSharingMode` specified when creating the swap chain #337

Open Traveller23 opened 1 year ago

Traveller23 commented 1 year ago

In most of the examples in this tutorial, this is what is written when creating a swap chain:

QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
uint32_t queueFamilyIndices[] = {indices.graphicsFamily.value(), indices.presentFamily.value()};

if (indices.graphicsFamily != indices.presentFamily) {
    createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
    createInfo.queueFamilyIndexCount = 2;
    createInfo.pQueueFamilyIndices = queueFamilyIndices;
} else {
    createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
}

Also, semaphores are created and used in vkAcquireNextImageKHR and vkQueueSubmit.

According to the standard documentation, semaphores are only needed if imageSharingMode is specified as VK_SHARING_MODE_EXCLUSIVE. When VK_SHARING_MODE_CONCURRENT is specified, though the standard does not explain, but it appears that synchronization can be performed without using any synchronization semantics such as semaphores.

So, no matter how many queue families we use, as long as we use semaphores, we only need to set imageSharingMode to VK_SHARING_MODE_EXCLUSIVE, which will also improve the performance.

Note VK_SHARING_MODE_CONCURRENT may result in lower performance access to the buffer or image than VK_SHARING_MODE_EXCLUSIVE.