From 78bafe88face6f245afbbf0673e8a7310034b271 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 18 Sep 2023 14:52:16 +0300 Subject: [PATCH] even more vulkan init --- src/Core/PS4/HLE/Graphics/graphics_ctx.h | 1 + src/emulator.h | 17 +++++++++++ src/vulkan_util.cpp | 39 +++++++++++++++++++++--- src/vulkan_util.h | 24 ++++++--------- 4 files changed, 61 insertions(+), 20 deletions(-) diff --git a/src/Core/PS4/HLE/Graphics/graphics_ctx.h b/src/Core/PS4/HLE/Graphics/graphics_ctx.h index 330fad57..39f553b7 100644 --- a/src/Core/PS4/HLE/Graphics/graphics_ctx.h +++ b/src/Core/PS4/HLE/Graphics/graphics_ctx.h @@ -7,5 +7,6 @@ struct GraphicCtx { u32 screen_width = 0; u32 screen_height = 0; VkInstance m_instance = nullptr; + VkPhysicalDevice physical_device = nullptr; }; } // namespace HLE::Libs::Graphics \ No newline at end of file diff --git a/src/emulator.h b/src/emulator.h index 143eb18f..bcb9e775 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -2,8 +2,24 @@ #include #include #include +#include + namespace Emulator { + +struct VulkanExt { + bool enable_validation_layers = false; + + std::vector required_extensions; + std::vector available_extensions; + std::vector required_layers; + std::vector available_layers; +}; + +struct VulkanSurfaceCapabilities {}; + +struct VulkanQueues {}; + struct WindowCtx { HLE::Libs::Graphics::GraphicCtx m_graphic_ctx; Lib::Mutex m_mutex; @@ -12,6 +28,7 @@ struct WindowCtx { SDL_Window* m_window = nullptr; bool is_window_hidden = true; VkSurfaceKHR m_surface = nullptr; + VulkanSurfaceCapabilities* m_surface_capabilities = nullptr; }; struct EmuPrivate { diff --git a/src/vulkan_util.cpp b/src/vulkan_util.cpp index 28cb185f..6c191496 100644 --- a/src/vulkan_util.cpp +++ b/src/vulkan_util.cpp @@ -1,14 +1,15 @@ #include "vulkan_util.h" + +#include #include #include -#include #include constexpr bool log_file_vulkanutil = true; // disable it to disable logging void Graphics::Vulkan::vulkanCreate(Emulator::WindowCtx* ctx) { - VulkanExt ext; - vulkanGetExtensions(&ext); + Emulator::VulkanExt ext; + vulkanGetInstanceExtensions(&ext); VkApplicationInfo app_info{}; app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; @@ -42,9 +43,19 @@ void Graphics::Vulkan::vulkanCreate(Emulator::WindowCtx* ctx) { LOG_CRITICAL_IF(log_file_vulkanutil, "Can't create an vulkan surface\n"); std::exit(0); } + + // TODO i am not sure if it's that it is neccesary or if it needs more + std::vector device_extensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME, + VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME, "VK_KHR_maintenance1"}; + + ctx->m_surface_capabilities = new Emulator::VulkanSurfaceCapabilities{}; + Emulator::VulkanQueues queues; + + vulkanFindCompatiblePhysicalDevice(ctx->m_graphic_ctx.m_instance, ctx->m_surface, device_extensions, ctx->m_surface_capabilities, + &ctx->m_graphic_ctx.physical_device, &queues); } -void Graphics::Vulkan::vulkanGetExtensions(VulkanExt* ext) { +void Graphics::Vulkan::vulkanGetInstanceExtensions(Emulator::VulkanExt* ext) { u32 required_extensions_count = 0; u32 available_extensions_count = 0; u32 available_layers_count = 0; @@ -73,6 +84,24 @@ void Graphics::Vulkan::vulkanGetExtensions(VulkanExt* ext) { } for (const auto& l : ext->available_layers) { - LOG_INFO_IF(log_file_vulkanutil, "Vulkan available layer: {}, specVersion = {}, implVersion = {}, {}\n", l.layerName, l.specVersion,l.implementationVersion,l.description); + LOG_INFO_IF(log_file_vulkanutil, "Vulkan available layer: {}, specVersion = {}, implVersion = {}, {}\n", l.layerName, l.specVersion, + l.implementationVersion, l.description); + } +} + +void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, VkSurfaceKHR surface, + const std::vector& device_extensions, + Emulator::VulkanSurfaceCapabilities* out_capabilities, VkPhysicalDevice* out_device, + Emulator::VulkanQueues* out_queues) { + u32 count_devices = 0; + vkEnumeratePhysicalDevices(instance, &count_devices, nullptr); + + std::vector devices(count_devices); + vkEnumeratePhysicalDevices(instance, &count_devices, devices.data()); + + VkPhysicalDevice found_best_device = nullptr; + Emulator::VulkanQueues found_best_queues; + + for (const auto& device : devices) { } } diff --git a/src/vulkan_util.h b/src/vulkan_util.h index cba04d26..a7299118 100644 --- a/src/vulkan_util.h +++ b/src/vulkan_util.h @@ -1,21 +1,15 @@ #pragma once -#include "emulator.h" #include -#include #include +#include + +#include "emulator.h" + namespace Graphics::Vulkan { -struct VulkanExt { - bool enable_validation_layers = false; - - std::vector required_extensions; - std::vector available_extensions; - std::vector required_layers; - std::vector available_layers; -}; - -void vulkanCreate(Emulator::WindowCtx *ctx); -void vulkanGetExtensions(VulkanExt* ext); - -}; \ No newline at end of file +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); +}; // namespace Graphics::Vulkan \ No newline at end of file