From 3768dfabfc3a36f806c20c38fb80850f12101270 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Wed, 20 Sep 2023 14:19:20 +0300 Subject: [PATCH] more work on vulkan queues --- src/emulator.h | 13 +++++++++++++ src/vulkan_util.cpp | 30 +++++++++++++++++++++--------- src/vulkan_util.h | 12 +++++++++--- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/emulator.h b/src/emulator.h index 2f3be030..e1519ab3 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -24,10 +24,23 @@ struct VulkanSurfaceCapabilities { bool is_format_unorm_bgra32 = false; }; +struct VulkanQueueInfo { + u32 family = 0; + u32 index = 0; + bool is_graphics = false; + bool is_compute = false; + bool is_transfer = false; + bool is_present = false; +}; + struct VulkanQueues { u32 family_count = 0; + std::vector available; + std::vector graphics; + std::vector family_used; }; + struct WindowCtx { HLE::Libs::Graphics::GraphicCtx m_graphic_ctx; Lib::Mutex m_mutex; diff --git a/src/vulkan_util.cpp b/src/vulkan_util.cpp index cb7db66e..18ef6b4e 100644 --- a/src/vulkan_util.cpp +++ b/src/vulkan_util.cpp @@ -3,8 +3,8 @@ #include #include #include -#include #include +#include constexpr bool log_file_vulkanutil = true; // disable it to disable logging @@ -104,7 +104,6 @@ void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, V Emulator::VulkanQueues found_best_queues; for (const auto& device : devices) { - VkPhysicalDeviceProperties device_properties{}; VkPhysicalDeviceFeatures2 device_features2{}; @@ -113,7 +112,7 @@ void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, V if (device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) { continue; // we don't want integrated gpu for now .Later we will check the requirements and see what we can support (TODO fix me) } - LOG_INFO_IF(log_file_vulkanutil,"Vulkan device: {}\n", device_properties.deviceName); + LOG_INFO_IF(log_file_vulkanutil, "Vulkan device: {}\n", device_properties.deviceName); auto qs = vulkanFindQueues(device, surface); @@ -126,8 +125,8 @@ void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, V *out_queues = found_best_queues; } -Emulator::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface) { - Emulator::VulkanQueues qs; +Emulator::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface) { + Emulator::VulkanQueues qs; u32 queue_family_count = 0; vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, nullptr); @@ -142,15 +141,29 @@ Emulator::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice devic vkGetPhysicalDeviceSurfaceSupportKHR(device, family, surface, &presentation_supported); LOG_INFO_IF(log_file_vulkanutil, "queue family: {}, count = {}, present = {}\n", string_VkQueueFlags(f.queueFlags).c_str(), f.queueCount, - (presentation_supported == VK_TRUE ? "true" : "false")); + (presentation_supported == VK_TRUE ? "true" : "false")); + for (uint32_t i = 0; i < f.queueCount; i++) { + Emulator::VulkanQueueInfo info; + info.family = family; + info.index = i; + info.is_graphics = (f.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0; + info.is_compute = (f.queueFlags & VK_QUEUE_COMPUTE_BIT) != 0; + info.is_transfer = (f.queueFlags & VK_QUEUE_TRANSFER_BIT) != 0; + info.is_present = (presentation_supported == VK_TRUE); + + qs.available.push_back(info); + } + + qs.family_used.push_back(0); family++; } - + // TODO finish it return qs; } -void Graphics::Vulkan::vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, Emulator::VulkanSurfaceCapabilities* surfaceCap) { +void Graphics::Vulkan::vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, + Emulator::VulkanSurfaceCapabilities* surfaceCap) { vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &surfaceCap->capabilities); uint32_t formats_count = 0; @@ -162,7 +175,6 @@ void Graphics::Vulkan::vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_de 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()); diff --git a/src/vulkan_util.h b/src/vulkan_util.h index 0afabddf..25e8e05d 100644 --- a/src/vulkan_util.h +++ b/src/vulkan_util.h @@ -8,11 +8,17 @@ namespace Graphics::Vulkan { +constexpr int VULKAN_QUEUES_NUM = 11; // Total of the above +constexpr int VULKAN_QUEUE_GRAPHICS_NUM = 1; +constexpr int VULKAN_QUEUE_TRANSFER_NUM = 1; +constexpr int VULKAN_QUEUE_PRESENT_NUM = 1; +constexpr int VULKAN_QUEUE_COMPUTE_NUM = 8; + void vulkanCreate(Emulator::WindowCtx* ctx); 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::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); +void vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, Emulator::VulkanSurfaceCapabilities* surfaceCap); }; // namespace Graphics::Vulkan \ No newline at end of file