Add a way to pass out error messages from VulkanLoad

This commit is contained in:
Henrik Rydgård 2024-01-15 11:06:06 +01:00
parent ddeb2112cc
commit 0caebbfaa6
6 changed files with 25 additions and 16 deletions

View file

@ -288,7 +288,7 @@ static const char * const so_names[] = {
};
#endif
static VulkanLibraryHandle VulkanLoadLibrary(const char *logname) {
static VulkanLibraryHandle VulkanLoadLibrary(std::string *errorString) {
#if PPSSPP_PLATFORM(SWITCH)
// Always unavailable, for now.
return nullptr;
@ -329,7 +329,7 @@ static VulkanLibraryHandle VulkanLoadLibrary(const char *logname) {
for (int i = 0; i < ARRAY_SIZE(so_names); i++) {
lib = dlopen(so_names[i], RTLD_NOW | RTLD_LOCAL);
if (lib) {
INFO_LOG(G3D, "%s: Library loaded ('%s')", logname, so_names[i]);
INFO_LOG(G3D, "Vulkan library loaded with AdrenoTools ('%s')", so_names[i]);
break;
}
}
@ -378,9 +378,10 @@ bool VulkanMayBeAvailable() {
}
INFO_LOG(G3D, "VulkanMayBeAvailable: Device allowed ('%s')", name.c_str());
VulkanLibraryHandle lib = VulkanLoadLibrary("VulkanMayBeAvailable");
std::string errorStr;
VulkanLibraryHandle lib = VulkanLoadLibrary(&errorStr);
if (!lib) {
INFO_LOG(G3D, "Vulkan loader: Library not available");
INFO_LOG(G3D, "Vulkan loader: Library not available: %s", errorStr.c_str());
g_vulkanAvailabilityChecked = true;
g_vulkanMayBeAvailable = false;
return false;
@ -545,9 +546,9 @@ bail:
return g_vulkanMayBeAvailable;
}
bool VulkanLoad() {
bool VulkanLoad(std::string *errorStr) {
if (!vulkanLibrary) {
vulkanLibrary = VulkanLoadLibrary("VulkanLoad");
vulkanLibrary = VulkanLoadLibrary(errorStr);
if (!vulkanLibrary) {
return false;
}
@ -565,7 +566,8 @@ bool VulkanLoad() {
INFO_LOG(G3D, "VulkanLoad: Base functions loaded.");
return true;
} else {
ERROR_LOG(G3D, "VulkanLoad: Failed to load Vulkan base functions.");
*errorStr = "Failed to load Vulkan base functions";
ERROR_LOG(G3D, "VulkanLoad: %s", errorStr->c_str());
VulkanFreeLibrary(vulkanLibrary);
return false;
}

View file

@ -32,6 +32,7 @@
#define VK_NO_PROTOTYPES
#include "ext/vulkan/vulkan.h"
#include <string>
// Hacky X11 header workaround
#ifdef Opposite
@ -266,7 +267,7 @@ struct VulkanExtensions {
bool VulkanMayBeAvailable();
void VulkanSetAvailable(bool available);
bool VulkanLoad();
bool VulkanLoad(std::string *errorStr);
void VulkanLoadInstanceFunctions(VkInstance instance, const VulkanExtensions &enabledExtensions);
void VulkanLoadDeviceFunctions(VkDevice device, const VulkanExtensions &enabledExtensions);
void VulkanFree();

View file

@ -56,8 +56,10 @@ bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int w, in
Version gitVer(PPSSPP_GIT_VERSION);
if (!VulkanLoad()) {
*error_message = "Failed to load Vulkan driver library";
std::string errorStr;
if (!VulkanLoad(&errorStr)) {
*error_message = "Failed to load Vulkan driver library: ";
(*error_message) += errorStr;
return false;
}

View file

@ -92,8 +92,10 @@ bool WindowsVulkanContext::Init(HINSTANCE hInst, HWND hWnd, std::string *error_m
Version gitVer(PPSSPP_GIT_VERSION);
if (!VulkanLoad()) {
*error_message = "Failed to load Vulkan driver library";
std::string errorStr;
if (!VulkanLoad(&errorStr)) {
*error_message = "Failed to load Vulkan driver library: ";
(*error_message) += errorStr;
return false;
}

View file

@ -52,8 +52,9 @@ bool AndroidVulkanContext::InitAPI() {
INFO_LOG(G3D, "Creating Vulkan context");
Version gitVer(PPSSPP_GIT_VERSION);
if (!VulkanLoad()) {
ERROR_LOG(G3D, "Failed to load Vulkan driver library");
std::string errorStr;
if (!VulkanLoad(&errorStr)) {
ERROR_LOG(G3D, "Failed to load Vulkan driver library: %s", errorStr.c_str());
state_ = GraphicsContextState::FAILED_INIT;
return false;
}

View file

@ -31,10 +31,11 @@ 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();
if (!VulkanLoad()) {
std::string errorStr;
if (!VulkanLoad(&errorStr)) {
// TODO: In the context of RetroArch, someone has already loaded the functions.
// But grabbing the pointers for ourselves can't really be a bad thing.
ERROR_LOG(G3D, "RetroArch called the Vulkan entry point without Vulkan available???");
ERROR_LOG(G3D, "RetroArch called the Vulkan entry point without Vulkan available??? %s", errorStr.c_str());
return false;
}