From 3c4716ba5f3b5476b648938a85f4e162a187a440 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 21 Sep 2023 18:20:13 +0300 Subject: [PATCH] vulkanCreateQueues --- src/Core/PS4/HLE/Graphics/graphics_ctx.h | 11 +++++++++++ src/vulkan_util.cpp | 24 ++++++++++++++++++++++++ src/vulkan_util.h | 7 +++++++ 3 files changed, 42 insertions(+) diff --git a/src/Core/PS4/HLE/Graphics/graphics_ctx.h b/src/Core/PS4/HLE/Graphics/graphics_ctx.h index 82ca6b05..074e8626 100644 --- a/src/Core/PS4/HLE/Graphics/graphics_ctx.h +++ b/src/Core/PS4/HLE/Graphics/graphics_ctx.h @@ -1,13 +1,24 @@ #pragma once #include #include +#include +#include "Lib/Threads.h" namespace HLE::Libs::Graphics { + +struct VulkanQueueInfo { + Lib::Mutex* mutex = nullptr; + u32 family = static_cast(-1); + u32 index = static_cast(-1); + VkQueue vk_queue = nullptr; +}; + struct GraphicCtx { u32 screen_width = 0; u32 screen_height = 0; VkInstance m_instance = nullptr; VkPhysicalDevice m_physical_device = nullptr; VkDevice m_device = nullptr; + VulkanQueueInfo queues[11]; //VULKAN_QUEUES_NUM }; } // namespace HLE::Libs::Graphics \ No newline at end of file diff --git a/src/vulkan_util.cpp b/src/vulkan_util.cpp index e648759b..9512e5e9 100644 --- a/src/vulkan_util.cpp +++ b/src/vulkan_util.cpp @@ -70,6 +70,30 @@ void Graphics::Vulkan::vulkanCreate(Emulator::WindowCtx* ctx) { LOG_CRITICAL_IF(log_file_vulkanutil, "Can't create vulkan device\n"); std::exit(0); } + + vulkanCreateQueues(&ctx->m_graphic_ctx, queues); + +} + +void Graphics::Vulkan::vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, const Emulator::VulkanQueues& queues) { + + auto get_queue = [ctx](int id, const Emulator::VulkanQueueInfo& info, bool with_mutex = false) { + ctx->queues[id].family = info.family; + ctx->queues[id].index = info.index; + vkGetDeviceQueue(ctx->m_device, ctx->queues[id].family, ctx->queues[id].index, &ctx->queues[id].vk_queue); + if (with_mutex) { + ctx->queues[id].mutex = new Lib::Mutex; + } + }; + + get_queue(VULKAN_QUEUE_GFX, queues.graphics.at(0)); + get_queue(VULKAN_QUEUE_UTIL, queues.transfer.at(0)); + get_queue(VULKAN_QUEUE_PRESENT, queues.present.at(0)); + + for (int id = 0; id < VULKAN_QUEUE_COMPUTE_NUM; id++) { + bool with_mutex = (VULKAN_QUEUE_COMPUTE_NUM == queues.compute.size()); + get_queue(id, queues.compute.at(id % queues.compute.size()), with_mutex); + } } VkDevice Graphics::Vulkan::vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const Emulator::VulkanExt* r, diff --git a/src/vulkan_util.h b/src/vulkan_util.h index f653fae1..8b70b2c4 100644 --- a/src/vulkan_util.h +++ b/src/vulkan_util.h @@ -14,6 +14,11 @@ constexpr int VULKAN_QUEUE_TRANSFER_NUM = 1; constexpr int VULKAN_QUEUE_PRESENT_NUM = 1; constexpr int VULKAN_QUEUE_COMPUTE_NUM = 8; +constexpr int VULKAN_QUEUE_GFX = 8; +constexpr int VULKAN_QUEUE_UTIL = 9; +constexpr int VULKAN_QUEUE_PRESENT = 10; + + void vulkanCreate(Emulator::WindowCtx* ctx); void vulkanGetInstanceExtensions(Emulator::VulkanExt* ext); void vulkanFindCompatiblePhysicalDevice(VkInstance instance, VkSurfaceKHR surface, const std::vector& device_extensions, @@ -23,4 +28,6 @@ VkDevice vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surfa const Emulator::VulkanQueues& queues, const std::vector& device_extensions); Emulator::VulkanQueues vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface); void vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, Emulator::VulkanSurfaceCapabilities* surfaceCap); +void vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, const Emulator::VulkanQueues& queues); + }; // namespace Graphics::Vulkan \ No newline at end of file