Only show the Vulkan setting if Vulkan might be available.

This commit is contained in:
Henrik Rydgård 2017-05-30 10:38:17 +02:00
parent d21a1f8813
commit fede9a05fb
3 changed files with 34 additions and 13 deletions

View file

@ -195,16 +195,34 @@ static void *vulkanLibrary;
#define LOAD_DEVICE_FUNC(instance, x) x = (PFN_ ## x)vkGetDeviceProcAddr(instance, #x); if (!x) {ILOG("Missing (device): %s", #x);}
#define LOAD_GLOBAL_FUNC(x) x = (PFN_ ## x)dlsym(vulkanLibrary, #x); if (!x) {ILOG("Missing (global): %s", #x);}
bool VulkanLoad() {
bool VulkanMayBeAvailable() {
if (vulkanLibrary)
return true;
bool available = false;
#ifndef _WIN32
vulkanLibrary = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
void *lib = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
available = lib != nullptr;
dlclose(lib);
#else
// LoadLibrary etc
vulkanLibrary = LoadLibrary(L"vulkan-1.dll");
HINSTANCE lib = LoadLibrary(L"vulkan-1.dll");
available = lib != 0;
FreeLibrary(lib);
#endif
return available;
}
bool VulkanLoad() {
if (!vulkanLibrary) {
return false;
#ifndef _WIN32
vulkanLibrary = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
#else
// LoadLibrary etc
vulkanLibrary = LoadLibrary(L"vulkan-1.dll");
#endif
if (!vulkanLibrary) {
return false;
}
}
LOAD_GLOBAL_FUNC(vkCreateInstance);
@ -391,13 +409,12 @@ void VulkanLoadDeviceFunctions(VkDevice device) {
}
void VulkanFree() {
if (vulkanLibrary) {
#ifdef _WIN32
if (vulkanLibrary) {
FreeLibrary(vulkanLibrary);
}
#else
if (vulkanLibrary) {
dlclose(vulkanLibrary);
}
#endif
vulkanLibrary = nullptr;
}
}

View file

@ -191,6 +191,9 @@ extern PFN_vkQueuePresentKHR vkQueuePresentKHR;
extern PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallbackEXT;
extern PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT;
// Way to do a quick check before even attempting to load.
bool VulkanMayBeAvailable();
bool VulkanLoad();
void VulkanLoadInstanceFunctions(VkInstance instance);
void VulkanLoadDeviceFunctions(VkDevice device);

View file

@ -48,6 +48,7 @@
#include "Common/KeyMap.h"
#include "Common/FileUtil.h"
#include "Common/OSVersion.h"
#include "Common/Vulkan/VulkanLoader.h"
#include "Core/Config.h"
#include "Core/Host.h"
#include "Core/System.h"
@ -187,10 +188,10 @@ void GameSettingsScreen::CreateViews() {
renderingBackendChoice->HideChoice(2); // D3D11
}
#endif
#if !defined(_WIN32) && !PPSSPP_PLATFORM(ANDROID)
// TODO: Add dynamic runtime check for Vulkan support on Android
renderingBackendChoice->HideChoice(3);
#endif
if (!VulkanMayBeAvailable()) {
renderingBackendChoice->HideChoice(3);
}
static const char *renderingMode[] = { "Non-Buffered Rendering", "Buffered Rendering", "Read Framebuffers To Memory (CPU)", "Read Framebuffers To Memory (GPU)"};
PopupMultiChoice *renderingModeChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iRenderingMode, gr->T("Mode"), renderingMode, 0, ARRAY_SIZE(renderingMode), gr->GetName(), screenManager()));
renderingModeChoice->OnChoice.Add([=](EventParams &e) {