diff --git a/Common/Vulkan/VulkanContext.cpp b/Common/Vulkan/VulkanContext.cpp index 4ab1aa735d..869f776dbc 100644 --- a/Common/Vulkan/VulkanContext.cpp +++ b/Common/Vulkan/VulkanContext.cpp @@ -84,19 +84,7 @@ const char *PresentModeString(VkPresentModeKHR presentMode) { } VulkanContext::VulkanContext() { -#if SIMULATE_VULKAN_FAILURE == 1 - return; -#endif - if (!VulkanLoad()) { - init_error_ = "Failed to load Vulkan driver library"; - // No DLL? - return; - } - - // We can get the list of layers and extensions without an instance so we can use this information - // to enable the extensions we need that are available. - GetInstanceLayerProperties(); - GetInstanceLayerExtensionList(nullptr, instance_extension_properties_); + // Do nothing here. } VkResult VulkanContext::CreateInstance(const CreateInfo &info) { @@ -105,6 +93,11 @@ VkResult VulkanContext::CreateInstance(const CreateInfo &info) { return VK_ERROR_INITIALIZATION_FAILED; } + // We can get the list of layers and extensions without an instance so we can use this information + // to enable the extensions we need that are available. + GetInstanceLayerProperties(); + GetInstanceLayerExtensionList(nullptr, instance_extension_properties_); + if (!IsInstanceExtensionAvailable(VK_KHR_SURFACE_EXTENSION_NAME)) { // Cannot create a Vulkan display without VK_KHR_SURFACE_EXTENSION. init_error_ = "Vulkan not loaded - no surface extension"; diff --git a/SDL/SDLVulkanGraphicsContext.cpp b/SDL/SDLVulkanGraphicsContext.cpp index 123c016ef7..3cf55a78c5 100644 --- a/SDL/SDLVulkanGraphicsContext.cpp +++ b/SDL/SDLVulkanGraphicsContext.cpp @@ -24,14 +24,12 @@ bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, Version gitVer(PPSSPP_GIT_VERSION); - vulkan_ = new VulkanContext(); - if (vulkan_->InitError().size()) { - *error_message = vulkan_->InitError(); - delete vulkan_; - vulkan_ = nullptr; + if (!VulkanLoad()) { + *error_message = "Failed to load Vulkan driver library"; return false; } + vulkan_ = new VulkanContext(); int vulkanFlags = VULKAN_FLAG_PRESENT_MAILBOX; // vulkanFlags |= VULKAN_FLAG_VALIDATE; VulkanContext::CreateInfo info{}; diff --git a/Windows/GPU/WindowsVulkanContext.cpp b/Windows/GPU/WindowsVulkanContext.cpp index 59ca85f76e..09f9f16a08 100644 --- a/Windows/GPU/WindowsVulkanContext.cpp +++ b/Windows/GPU/WindowsVulkanContext.cpp @@ -89,14 +89,14 @@ bool WindowsVulkanContext::Init(HINSTANCE hInst, HWND hWnd, std::string *error_m g_LogOptions.msgBoxOnError = false; Version gitVer(PPSSPP_GIT_VERSION); - g_Vulkan = new VulkanContext(); - if (g_Vulkan->InitError().size()) { - *error_message = g_Vulkan->InitError(); - delete g_Vulkan; - g_Vulkan = nullptr; + + if (!VulkanLoad()) { + *error_message = "Failed to load Vulkan driver library"; return false; } - // int vulkanFlags = VULKAN_FLAG_PRESENT_FIFO_RELAXED; + + g_Vulkan = new VulkanContext(); + VulkanContext::CreateInfo info{}; info.app_name = "PPSSPP"; info.app_ver = gitVer.ToInteger(); diff --git a/android/jni/AndroidVulkanContext.cpp b/android/jni/AndroidVulkanContext.cpp index f20247145c..44a565d37b 100644 --- a/android/jni/AndroidVulkanContext.cpp +++ b/android/jni/AndroidVulkanContext.cpp @@ -92,9 +92,16 @@ bool AndroidVulkanContext::InitAPI() { ILOG("Creating Vulkan context"); Version gitVer(PPSSPP_GIT_VERSION); + if (!VulkanLoad()) { + ELOG("Failed to load Vulkan driver library"); + return false; + } + if (!g_Vulkan) { + // TODO: Assert if g_Vulkan already exists here? g_Vulkan = new VulkanContext(); } + VulkanContext::CreateInfo info{}; info.app_name = "PPSSPP"; info.app_ver = gitVer.ToInteger(); diff --git a/libretro/LibretroVulkanContext.cpp b/libretro/LibretroVulkanContext.cpp index 69679f16bc..ed5615b500 100644 --- a/libretro/LibretroVulkanContext.cpp +++ b/libretro/LibretroVulkanContext.cpp @@ -30,14 +30,20 @@ void LibretroVulkanContext::SwapBuffers() { static bool create_device(retro_vulkan_context *context, VkInstance instance, VkPhysicalDevice gpu, VkSurfaceKHR surface, PFN_vkGetInstanceProcAddr get_instance_proc_addr, const char **required_device_extensions, unsigned num_required_device_extensions, const char **required_device_layers, unsigned num_required_device_layers, const VkPhysicalDeviceFeatures *required_features) { init_glslang(); - vk = new VulkanContext; - if (!vk->InitError().empty()) { - ERROR_LOG(G3D, "%s", vk->InitError().c_str()); + if (!VulkanLoad()) { + // TODO: In the context of RetroArch, someone has already loaded the functions - + // we shouldn't need to load them again. On the other hand, it can't really hurt, we're gonna + // get the same pointers. + ERROR_LOG(G3D, "RetroArch called the Vulkan entry point without Vulkan available???"); return false; } + vk = new VulkanContext(); + vk_libretro_init(instance, gpu, surface, get_instance_proc_addr, required_device_extensions, num_required_device_extensions, required_device_layers, num_required_device_layers, required_features); + // TODO: Here we'll inject the instance and all of the stuff into the VulkanContext. + vk->CreateInstance({}); int physical_device = 0;