Skip to content

Commit

Permalink
Add a way to pass out error messages from VulkanLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 15, 2024
1 parent ddeb211 commit 0caebbf
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
16 changes: 9 additions & 7 deletions Common/GPU/Vulkan/VulkanLoader.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -545,9 +546,9 @@ bool VulkanMayBeAvailable() {
return g_vulkanMayBeAvailable;
}

bool VulkanLoad() {
bool VulkanLoad(std::string *errorStr) {
if (!vulkanLibrary) {
vulkanLibrary = VulkanLoadLibrary("VulkanLoad");
vulkanLibrary = VulkanLoadLibrary(errorStr);
if (!vulkanLibrary) {
return false;
}
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion Common/GPU/Vulkan/VulkanLoader.h
Expand Up @@ -32,6 +32,7 @@
#define VK_NO_PROTOTYPES

#include "ext/vulkan/vulkan.h"
#include <string>

// Hacky X11 header workaround
#ifdef Opposite
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions SDL/SDLVulkanGraphicsContext.cpp
Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions Windows/GPU/WindowsVulkanContext.cpp
Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions android/jni/AndroidVulkanContext.cpp
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions libretro/LibretroVulkanContext.cpp
Expand Up @@ -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;
}

Expand Down

0 comments on commit 0caebbf

Please sign in to comment.