Skip to content

Commit

Permalink
[Vulkan] Support different swapchain compositeAlpha modes
Browse files Browse the repository at this point in the history
Not all systems support VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR.
Add VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR support, and check capabilities.supportedCompositeAlpha.
  • Loading branch information
past-due committed Aug 28, 2023
1 parent fa72ffe commit 2b43608
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/ivis_opengl/gfx_api_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4082,13 +4082,29 @@ bool VkRoot::createSwapchain()
surfaceFormat = chooseSwapSurfaceFormat(swapChainSupport.formats);
debug(LOG_3D, "Using surface format: %s - %s", to_string(surfaceFormat.format).c_str(), to_string(surfaceFormat.colorSpace).c_str());

// pick compositeAlpha
vk::CompositeAlphaFlagBitsKHR compositeAlphaMode = vk::CompositeAlphaFlagBitsKHR::eOpaque;
if (swapChainSupport.capabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eOpaque)
{
compositeAlphaMode = vk::CompositeAlphaFlagBitsKHR::eOpaque;
}
else if (swapChainSupport.capabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit)
{
compositeAlphaMode = vk::CompositeAlphaFlagBitsKHR::eInherit;
}
else
{
debug(LOG_INFO, "Unable to find expected supportedCompositeAlpha option (value is: %s) - will attempt opaque", to_string(swapChainSupport.capabilities.supportedCompositeAlpha).c_str());
}
debug(LOG_3D, "Using supportedCompositeAlpha: %s", to_string(compositeAlphaMode).c_str());

vk::SwapchainCreateInfoKHR createSwapchainInfo = vk::SwapchainCreateInfoKHR()
.setSurface(surface)
.setMinImageCount(swapchainDesiredImageCount)
.setPresentMode(presentMode)
.setImageUsage(vk::ImageUsageFlagBits::eColorAttachment)
.setImageArrayLayers(1)
.setCompositeAlpha(vk::CompositeAlphaFlagBitsKHR::eOpaque)
.setCompositeAlpha(compositeAlphaMode)
.setClipped(true)
.setImageExtent(swapchainSize)
.setImageFormat(surfaceFormat.format)
Expand Down

0 comments on commit 2b43608

Please sign in to comment.