From b68f018fad6f53abfb9e7b7153c9c701e175c239 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 19 Sep 2023 14:02:40 +0300 Subject: [PATCH] Added vulkanGetSurfaceCapabilities --- src/emulator.h | 8 +++++++- src/vulkan_util.cpp | 30 ++++++++++++++++++++++++++++++ src/vulkan_util.h | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/emulator.h b/src/emulator.h index 8d34ef67..2f3be030 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -16,7 +16,13 @@ struct VulkanExt { std::vector available_layers; }; -struct VulkanSurfaceCapabilities {}; +struct VulkanSurfaceCapabilities { + VkSurfaceCapabilitiesKHR capabilities{}; + std::vector formats; + std::vector present_modes; + bool is_format_srgb_bgra32 = false; + bool is_format_unorm_bgra32 = false; +}; struct VulkanQueues { u32 family_count = 0; diff --git a/src/vulkan_util.cpp b/src/vulkan_util.cpp index 9552332d..f37d0848 100644 --- a/src/vulkan_util.cpp +++ b/src/vulkan_util.cpp @@ -116,6 +116,8 @@ void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, V LOG_INFO_IF(log_file_vulkanutil,"Vulkan device: {}\n", device_properties.deviceName); auto qs = vulkanFindQueues(device, surface); + + vulkanGetSurfaceCapabilities(device, surface, out_capabilities); } } @@ -142,3 +144,31 @@ Emulator::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice devic return qs; } + +void Graphics::Vulkan::vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, Emulator::VulkanSurfaceCapabilities* surfaceCap) { + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &surfaceCap->capabilities); + + uint32_t formats_count = 0; + vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &formats_count, nullptr); + + surfaceCap->formats = std::vector(formats_count); + vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &formats_count, surfaceCap->formats.data()); + + uint32_t present_modes_count = 0; + vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &present_modes_count, nullptr); + + + surfaceCap->present_modes = std::vector(present_modes_count); + vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &present_modes_count, surfaceCap->present_modes.data()); + + for (const auto& f : surfaceCap->formats) { + if (f.format == VK_FORMAT_B8G8R8A8_SRGB && f.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) { + surfaceCap->is_format_srgb_bgra32 = true; + break; + } + if (f.format == VK_FORMAT_B8G8R8A8_UNORM && f.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) { + surfaceCap->is_format_unorm_bgra32 = true; + break; + } + } +} \ No newline at end of file diff --git a/src/vulkan_util.h b/src/vulkan_util.h index 995edefc..0afabddf 100644 --- a/src/vulkan_util.h +++ b/src/vulkan_util.h @@ -13,4 +13,6 @@ void vulkanGetInstanceExtensions(Emulator::VulkanExt* ext); void vulkanFindCompatiblePhysicalDevice(VkInstance instance, VkSurfaceKHR surface, const std::vector& device_extensions, Emulator::VulkanSurfaceCapabilities* out_capabilities, VkPhysicalDevice* out_device, Emulator::VulkanQueues* out_queues); Emulator::VulkanQueues vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface); +void vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, + Emulator::VulkanSurfaceCapabilities* surfaceCap); }; // namespace Graphics::Vulkan \ No newline at end of file