| 791 | } |
| 792 | |
| 793 | SwapChainData::SwapChainData( vk::PhysicalDevice const & physicalDevice, |
| 794 | vk::Device const & device, |
| 795 | vk::SurfaceKHR const & surface, |
| 796 | vk::Extent2D const & extent, |
| 797 | vk::ImageUsageFlags usage, |
| 798 | vk::SwapchainKHR const & oldSwapChain, |
| 799 | uint32_t graphicsQueueFamilyIndex, |
| 800 | uint32_t presentQueueFamilyIndex ) |
| 801 | { |
| 802 | vk::SurfaceFormatKHR surfaceFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surface ) ); |
| 803 | colorFormat = surfaceFormat.format; |
| 804 | |
| 805 | vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface ); |
| 806 | vk::Extent2D swapchainExtent; |
| 807 | if ( surfaceCapabilities.currentExtent.width == ( std::numeric_limits<uint32_t>::max )() ) |
| 808 | { |
| 809 | // If the surface size is undefined, the size is set to the size of the images requested. |
| 810 | swapchainExtent.width = clamp( extent.width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width ); |
| 811 | swapchainExtent.height = clamp( extent.height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height ); |
| 812 | } |
| 813 | else |
| 814 | { |
| 815 | // If the surface size is defined, the swap chain size must match |
| 816 | swapchainExtent = surfaceCapabilities.currentExtent; |
| 817 | } |
| 818 | vk::SurfaceTransformFlagBitsKHR preTransform = ( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity ) |
| 819 | ? vk::SurfaceTransformFlagBitsKHR::eIdentity |
| 820 | : surfaceCapabilities.currentTransform; |
| 821 | vk::CompositeAlphaFlagBitsKHR compositeAlpha = |
| 822 | ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied |
| 823 | : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied |
| 824 | : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit ) ? vk::CompositeAlphaFlagBitsKHR::eInherit |
| 825 | : vk::CompositeAlphaFlagBitsKHR::eOpaque; |
| 826 | vk::PresentModeKHR presentMode = vk::su::pickPresentMode( physicalDevice.getSurfacePresentModesKHR( surface ) ); |
| 827 | vk::SwapchainCreateInfoKHR swapChainCreateInfo( |
| 828 | {}, |
| 829 | surface, |
| 830 | vk::su::clampSurfaceImageCount( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ), |
| 831 | colorFormat, |
| 832 | surfaceFormat.colorSpace, |
| 833 | swapchainExtent, |
| 834 | 1, |
| 835 | usage, |
| 836 | vk::SharingMode::eExclusive, |
| 837 | {}, |
| 838 | preTransform, |
| 839 | compositeAlpha, |
| 840 | presentMode, |
| 841 | true, |
| 842 | oldSwapChain ); |
| 843 | if ( graphicsQueueFamilyIndex != presentQueueFamilyIndex ) |
| 844 | { |
| 845 | uint32_t queueFamilyIndices[2] = { graphicsQueueFamilyIndex, presentQueueFamilyIndex }; |
| 846 | // If the graphics and present queues are from different queue families, we either have to explicitly transfer |
| 847 | // ownership of images between the queues, or we have to create the swapchain with imageSharingMode as |
| 848 | // vk::SharingMode::eConcurrent |
| 849 | swapChainCreateInfo.imageSharingMode = vk::SharingMode::eConcurrent; |
| 850 | swapChainCreateInfo.queueFamilyIndexCount = 2; |
nothing calls this directly
no test coverage detected