From f6388c367e55c7bf03973e88e6d3937672c52b0f Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Sun, 17 Sep 2023 20:01:29 +0300 Subject: [PATCH] added vulkan extension initialize --- CMakeLists.txt | 2 +- src/emulator.cpp | 2 ++ src/vulkan_util.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++ src/vulkan_util.h | 21 ++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/vulkan_util.cpp create mode 100644 src/vulkan_util.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f46f0c79..ef8319ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ add_executable(shadps4 src/Core/PS4/HLE/Kernel/event_queues.h src/Core/PS4/HLE/Kernel/cpu_management.cpp src/Core/PS4/HLE/Kernel/cpu_management.h - "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/Core/PS4/HLE/Graphics/graphics_ctx.h") + "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/Core/PS4/HLE/Graphics/graphics_ctx.h" "src/vulkan_util.cpp" "src/vulkan_util.h") find_package(OpenGL REQUIRED) target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY} vulkan-1 spirv-tools-opt spirv-tools) diff --git a/src/emulator.cpp b/src/emulator.cpp index 98c3dae0..d77138e7 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -1,6 +1,7 @@ #include "emulator.h" #include "Core/PS4/HLE/Graphics/video_out.h" +#include namespace Emulator { @@ -47,6 +48,7 @@ void emuRun() { { // init window and wait until init finishes CreateSdlWindow(g_window_ctx); + Graphics::Vulkan::vulkanCreate(g_window_ctx); g_window_ctx->m_is_graphic_initialized = true; g_window_ctx->m_graphic_initialized_cond.SignalCondVar(); } diff --git a/src/vulkan_util.cpp b/src/vulkan_util.cpp new file mode 100644 index 00000000..677f61b4 --- /dev/null +++ b/src/vulkan_util.cpp @@ -0,0 +1,54 @@ +#include "vulkan_util.h" +#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); + + VkApplicationInfo app_info{}; + app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + app_info.pNext = nullptr; + app_info.pApplicationName = "shadps4"; + app_info.applicationVersion = 1; + app_info.pEngineName = "shadps4"; + app_info.engineVersion = 1; + app_info.apiVersion = VK_API_VERSION_1_2; +} + +void Graphics::Vulkan::vulkanGetExtensions(VulkanExt* ext) { + u32 required_extensions_count = 0; + u32 available_extensions_count = 0; + u32 available_layers_count = 0; + auto result = SDL_Vulkan_GetInstanceExtensions(&required_extensions_count, nullptr); + + ext->required_extensions = std::vector(required_extensions_count); + + result = SDL_Vulkan_GetInstanceExtensions(&required_extensions_count, ext->required_extensions.data()); + + vkEnumerateInstanceExtensionProperties(nullptr, &available_extensions_count, nullptr); + + ext->available_extensions = std::vector(available_extensions_count); + + vkEnumerateInstanceExtensionProperties(nullptr, &available_extensions_count, ext->available_extensions.data()); + + vkEnumerateInstanceLayerProperties(&available_layers_count, nullptr); + ext->available_layers = std::vector(available_layers_count); + vkEnumerateInstanceLayerProperties(&available_layers_count, ext->available_layers.data()); + + for (const char* ext : ext->required_extensions) { + LOG_INFO_IF(log_file_vulkanutil, "Vulkan required extension = {}\n", ext); + } + + for (const auto& ext : ext->available_extensions) { + LOG_INFO_IF(log_file_vulkanutil, "Vulkan available extension: {}, version = {}\n", ext.extensionName, ext.specVersion); + } + + 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); + } +} diff --git a/src/vulkan_util.h b/src/vulkan_util.h new file mode 100644 index 00000000..cba04d26 --- /dev/null +++ b/src/vulkan_util.h @@ -0,0 +1,21 @@ +#pragma once +#include "emulator.h" +#include +#include +#include + +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