diff --git a/src/backend/vulkan/VulkanBackend.cpp b/src/backend/vulkan/VulkanBackend.cpp index 215910dad3..28b747526d 100644 --- a/src/backend/vulkan/VulkanBackend.cpp +++ b/src/backend/vulkan/VulkanBackend.cpp @@ -262,6 +262,18 @@ namespace backend { namespace vulkan { return mDeviceInfo; } + VkInstance Device::GetInstance() const { + return mInstance; + } + + VkPhysicalDevice Device::GetPhysicalDevice() const { + return mPhysicalDevice; + } + + VkDevice Device::GetVkDevice() const { + return mVkDevice; + } + MapReadRequestTracker* Device::GetMapReadRequestTracker() const { return mMapReadRequestTracker; } @@ -331,14 +343,6 @@ namespace backend { namespace vulkan { mNextSerial++; } - VkInstance Device::GetInstance() const { - return mInstance; - } - - VkDevice Device::GetVkDevice() const { - return mVkDevice; - } - bool Device::CreateInstance(VulkanGlobalKnobs* usedKnobs) { std::vector layersToRequest; std::vector extensionsToRequest; diff --git a/src/backend/vulkan/VulkanBackend.h b/src/backend/vulkan/VulkanBackend.h index e5319ac8cc..f05532ee26 100644 --- a/src/backend/vulkan/VulkanBackend.h +++ b/src/backend/vulkan/VulkanBackend.h @@ -100,6 +100,7 @@ namespace backend { namespace vulkan { const VulkanDeviceInfo& GetDeviceInfo() const; VkInstance GetInstance() const; + VkPhysicalDevice GetPhysicalDevice() const; VkDevice GetVkDevice() const; BufferUploader* GetBufferUploader() const; diff --git a/src/backend/vulkan/VulkanInfo.cpp b/src/backend/vulkan/VulkanInfo.cpp index a496e4b18e..e0c1b1f678 100644 --- a/src/backend/vulkan/VulkanInfo.cpp +++ b/src/backend/vulkan/VulkanInfo.cpp @@ -183,4 +183,71 @@ namespace backend { namespace vulkan { return true; } + bool GatherSurfaceInfo(const Device& device, VkSurfaceKHR surface, VulkanSurfaceInfo* info) { + VkPhysicalDevice physicalDevice = device.GetPhysicalDevice(); + + // Get the surface capabilities + { + VkResult result = device.fn.GetPhysicalDeviceSurfaceCapabilitiesKHR( + physicalDevice, surface, &info->capabilities); + if (result != VK_SUCCESS) { + return false; + } + } + + // Query which queue families support presenting this surface + { + size_t nQueueFamilies = device.GetDeviceInfo().queueFamilies.size(); + info->supportedQueueFamilies.resize(nQueueFamilies, false); + + for (uint32_t i = 0; i < nQueueFamilies; ++i) { + VkBool32 supported = VK_FALSE; + VkResult result = device.fn.GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, i, + surface, &supported); + + if (result != VK_SUCCESS) { + return false; + } + + info->supportedQueueFamilies[i] = (supported == VK_TRUE); + } + } + + // Gather supported formats + { + uint32_t count = 0; + VkResult result = device.fn.GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, + &count, nullptr); + if (result != VK_SUCCESS && result != VK_INCOMPLETE) { + return false; + } + + info->formats.resize(count); + result = device.fn.GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &count, + info->formats.data()); + if (result != VK_SUCCESS) { + return false; + } + } + + // Gather supported presents modes + { + uint32_t count = 0; + VkResult result = device.fn.GetPhysicalDeviceSurfacePresentModesKHR( + physicalDevice, surface, &count, nullptr); + if (result != VK_SUCCESS && result != VK_INCOMPLETE) { + return false; + } + + info->presentModes.resize(count); + result = device.fn.GetPhysicalDeviceSurfacePresentModesKHR( + physicalDevice, surface, &count, info->presentModes.data()); + if (result != VK_SUCCESS) { + return false; + } + } + + return true; + } + }} // namespace backend::vulkan diff --git a/src/backend/vulkan/VulkanInfo.h b/src/backend/vulkan/VulkanInfo.h index e7cac2a68f..97fff48061 100644 --- a/src/backend/vulkan/VulkanInfo.h +++ b/src/backend/vulkan/VulkanInfo.h @@ -65,11 +65,20 @@ namespace backend { namespace vulkan { // TODO(cwallez@chromium.org): layer instance extensions }; + struct VulkanSurfaceInfo { + VkSurfaceCapabilitiesKHR capabilities; + std::vector formats; + std::vector presentModes; + std::vector supportedQueueFamilies; + }; + bool GatherGlobalInfo(const Device& device, VulkanGlobalInfo* info); bool GetPhysicalDevices(const Device& device, std::vector* physicalDevices); bool GatherDeviceInfo(const Device& device, VkPhysicalDevice physicalDevice, VulkanDeviceInfo* info); + bool GatherSurfaceInfo(const Device& device, VkSurfaceKHR surface, VulkanSurfaceInfo* info); + }} // namespace backend::vulkan #endif // BACKEND_VULKAN_VULKANINFO_H_