SpiecsEngine
 
Loading...
Searching...
No Matches

◆ QuerySwapChainSupport()

SwapChainSupportDetails Spices::VulkanDevice::QuerySwapChainSupport ( const VkPhysicalDevice & device,
const VkSurfaceKHR & surface,
GLFWwindow * window )
staticprivate

Query physical device's SwapChainSupport.

Parameters
[in]deviceVkPhysicalDevice.
[in]surfaceVkSurfaceKHR.
[in]windowThe row pointer of GLFW window.
Returns
Returns SwapChainSupportDetails.

Get VkSurfaceCapabilitiesKHR.

Get VkExtent2D From VkSurfaceCapabilitiesKHR or glfwWindow.

clamp to VkSurfaceCapabilitiesKHR's limit.

Get physicaldevice surfaceformat nums;

Get physicaldevice surfaceformat;

Get suitable surfaceformat.

Note
Remember this format is linear.

Get physicaldevice persentmode nums;

Get physicaldevice persentmode;

Get suitable persentmode.

Get VkSurfaceCapabilitiesKHR.

Get VkExtent2D From VkSurfaceCapabilitiesKHR or glfwWindow.

clamp to VkSurfaceCapabilitiesKHR's limit.

Get physicaldevice surfaceformat nums;

Get physicaldevice surfaceformat;

Get suitable surfaceformat.

Note
Remember this format is linear.

Get physicaldevice persentmode nums;

Get physicaldevice persentmode;

Get suitable persentmode.

Definition at line 718 of file VulkanDevice.cpp.

723 {
725
729 SwapChainSupportDetails swapChainSupportDetails = SwapChainSupportDetails{};
730 vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &swapChainSupportDetails.capabilities);
731
735 if (swapChainSupportDetails.capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max())
736 {
737 swapChainSupportDetails.surfaceSize = swapChainSupportDetails.capabilities.currentExtent;
738 }
739 else
740 {
741 int width, height;
742 glfwGetFramebufferSize(window, &width, &height);
743
744 VkExtent2D actualExtent =
745 {
746 static_cast<uint32_t>(width),
747 static_cast<uint32_t>(height)
748 };
749
753 actualExtent.width = std::clamp(actualExtent.width,
754 swapChainSupportDetails.capabilities.minImageExtent.width,
755 swapChainSupportDetails.capabilities.maxImageExtent.width);
756
757 actualExtent.height = std::clamp(actualExtent.height,
758 swapChainSupportDetails.capabilities.minImageExtent.height,
759 swapChainSupportDetails.capabilities.maxImageExtent.height);
760
761 swapChainSupportDetails.surfaceSize = actualExtent;
762 }
763
767 uint32_t formatCount;
768 vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);
769
770 if (formatCount != 0)
771 {
775 swapChainSupportDetails.formats.resize(formatCount);
776 vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, swapChainSupportDetails.formats.data());
777
782 swapChainSupportDetails.format = swapChainSupportDetails.formats[0];
783
784 for (const auto& availableFormat : swapChainSupportDetails.formats)
785 {
786 if (availableFormat.format == VK_FORMAT_A2B10G10R10_UNORM_PACK32 &&
787 availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
788 {
789 swapChainSupportDetails.format = availableFormat;
790 break;
791 }
792 }
793 }
794
798 uint32_t presentModeCount;
799 vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr);
800
801 if (presentModeCount != 0)
802 {
806 swapChainSupportDetails.presentModes.resize(presentModeCount);
807 vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, swapChainSupportDetails.presentModes.data());
808
812 swapChainSupportDetails.presentMode = swapChainSupportDetails.presentModes[0];
813
814 for (const auto& availablePresentMode : swapChainSupportDetails.presentModes)
815 {
816 if (availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR)
817 {
818 swapChainSupportDetails.presentMode = availablePresentMode;
819 break;
820 }
821 }
822 }
823
824 return swapChainSupportDetails;
825 }
#define SPICES_PROFILE_ZONE