vulkanCreateQueues

This commit is contained in:
georgemoralis 2023-09-21 18:20:13 +03:00
parent b1d812bb32
commit 3c4716ba5f
3 changed files with 42 additions and 0 deletions

View File

@ -1,13 +1,24 @@
#pragma once
#include <types.h>
#include <vulkan/vulkan_core.h>
#include <emulator.h>
#include "Lib/Threads.h"
namespace HLE::Libs::Graphics {
struct VulkanQueueInfo {
Lib::Mutex* mutex = nullptr;
u32 family = static_cast<u32>(-1);
u32 index = static_cast<u32>(-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

View File

@ -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,

View File

@ -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<const char*>& device_extensions,
@ -23,4 +28,6 @@ VkDevice vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surfa
const Emulator::VulkanQueues& queues, const std::vector<const char*>& 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