MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / createSwapChain

Method createSwapChain

cpp/5_Domain_Specific/simpleVulkan/VulkanBaseApp.cpp:692–754  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

690}
691
692void VulkanBaseApp::createSwapChain()
693{
694 VkSurfaceCapabilitiesKHR capabilities;
695 VkSurfaceFormatKHR format;
696 VkPresentModeKHR presentMode;
697 VkExtent2D extent;
698 uint32_t imageCount;
699
700 {
701 std::vector<VkSurfaceFormatKHR> formats;
702 std::vector<VkPresentModeKHR> presentModes;
703
704 getSwapChainProperties(m_physicalDevice, m_surface, capabilities, formats, presentModes);
705 format = chooseSwapSurfaceFormat(formats);
706 presentMode = chooseSwapPresentMode(presentModes);
707 extent = chooseSwapExtent(m_window, capabilities);
708 imageCount = capabilities.minImageCount + 1;
709 if (capabilities.maxImageCount > 0 && imageCount > capabilities.maxImageCount) {
710 imageCount = capabilities.maxImageCount;
711 }
712 }
713
714 VkSwapchainCreateInfoKHR createInfo = {};
715 createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
716 createInfo.surface = m_surface;
717
718 createInfo.minImageCount = imageCount;
719 createInfo.imageFormat = format.format;
720 createInfo.imageColorSpace = format.colorSpace;
721 createInfo.imageExtent = extent;
722 createInfo.imageArrayLayers = 1;
723 createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
724
725 uint32_t queueFamilyIndices[2];
726 findGraphicsQueueIndicies(m_physicalDevice, m_surface, queueFamilyIndices[0], queueFamilyIndices[1]);
727
728 if (queueFamilyIndices[0] != queueFamilyIndices[1]) {
729 createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
730 createInfo.queueFamilyIndexCount = countof(queueFamilyIndices);
731 createInfo.pQueueFamilyIndices = queueFamilyIndices;
732 }
733 else {
734 createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
735 }
736
737 createInfo.preTransform = capabilities.currentTransform;
738 createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
739 createInfo.presentMode = presentMode;
740 createInfo.clipped = VK_TRUE;
741
742 createInfo.oldSwapchain = VK_NULL_HANDLE;
743
744 if (vkCreateSwapchainKHR(m_device, &createInfo, nullptr, &m_swapChain) != VK_SUCCESS) {
745 throw std::runtime_error("failed to create swap chain!");
746 }
747
748 vkGetSwapchainImagesKHR(m_device, m_swapChain, &imageCount, nullptr);
749 m_swapChainImages.resize(imageCount);

Callers

nothing calls this directly

Calls 5

getSwapChainPropertiesFunction · 0.70
chooseSwapSurfaceFormatFunction · 0.70
chooseSwapPresentModeFunction · 0.70
chooseSwapExtentFunction · 0.70

Tested by

no test coverage detected