Merge pull request #15468 from unknownbrackets/switch-merge

Cleanup Switch ignoring of Vulkan
This commit is contained in:
Henrik Rydgård 2022-04-08 14:48:04 +02:00 committed by GitHub
commit 0eea0acf13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 63 additions and 53 deletions

View File

@ -83,7 +83,7 @@ if(NOT ANDROID AND NOT IOS)
endif()
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND NOT USE_LIBNX)
set(LINUX ON)
add_definitions(-D__STDC_CONSTANT_MACROS)
endif()
@ -146,6 +146,7 @@ option(UNITTEST "Set to ON to generate the unittest target" ${UNITTEST})
option(SIMULATOR "Set to ON when targeting an x86 simulator of an ARM platform" ${SIMULATOR})
option(LIBRETRO "Set to ON to generate the libretro target" OFF)
# :: Options
option(USE_LIBNX "Set to ON to build for Switch(libnx)" OFF)
option(USE_FFMPEG "Build with FFMPEG support" ON)
option(USE_DISCORD "Build with Discord support" ON)
option(USE_MINIUPNPC "Build with miniUPnPc support" ON)
@ -1147,8 +1148,12 @@ elseif(TARGET SDL2::SDL2)
SDL/SDLJoystick.cpp
SDL/SDLMain.cpp
SDL/SDLGLGraphicsContext.cpp
SDL/SDLVulkanGraphicsContext.cpp
)
if(NOT USE_LIBNX)
set(nativeExtra ${nativeExtra}
SDL/SDLVulkanGraphicsContext.cpp
)
endif()
set(nativeExtraLibs ${nativeExtraLibs} SDL2::SDL2)
if(APPLE)
set(nativeExtra ${nativeExtra} SDL/SDLMain.h SDL/SDLMain.mm SDL/SDLCocoaMetalLayer.h SDL/SDLCocoaMetalLayer.mm)

View File

@ -26,7 +26,7 @@
cInterfaceBase* HostGL_CreateGLInterface(){
#ifdef __ANDROID__
return new cInterfaceEGLAndroid;
#elif if PPSSPP_PLATFORM(SWITCH)
#elif PPSSPP_PLATFORM(SWITCH)
return new cInterfaceEGLSwitch;
#elif defined(__APPLE__)
return new cInterfaceAGL;

View File

@ -24,7 +24,7 @@
#include "Common/Log.h"
#include "Common/System/System.h"
#ifndef _WIN32
#if !PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(SWITCH)
#include <dlfcn.h>
#endif
@ -224,11 +224,17 @@ PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR;
using namespace PPSSPP_VK;
#ifdef _WIN32
static HINSTANCE vulkanLibrary;
#if PPSSPP_PLATFORM(SWITCH)
typedef void *VulkanLibraryHandle;
static VulkanLibraryHandle vulkanLibrary;
#define dlsym(x, y) nullptr
#elif PPSSPP_PLATFORM(WINDOWS)
typedef HINSTANCE VulkanLibraryHandle;
static VulkanLibraryHandle vulkanLibrary;
#define dlsym(x, y) GetProcAddress(x, y)
#else
static void *vulkanLibrary;
typedef void *VulkanLibraryHandle;
static VulkanLibraryHandle vulkanLibrary;
#endif
const char *VulkanResultToString(VkResult res);
@ -261,6 +267,38 @@ static const char *so_names[] = {
};
#endif
static VulkanLibraryHandle VulkanLoadLibrary(const char *logname) {
#if PPSSPP_PLATFORM(SWITCH)
// Always unavailable, for now.
return nullptr;
#elif PPSSPP_PLATFORM(WINDOWS)
return LoadLibrary(L"vulkan-1.dll");
#else
void *lib = nullptr;
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]);
break;
}
}
return lib;
#endif
}
static void VulkanFreeLibrary(VulkanLibraryHandle &h) {
if (h) {
#if PPSSPP_PLATFORM(SWITCH)
// Can't load, and can't free.
#elif PPSSPP_PLATFORM(WINDOWS)
FreeLibrary(h);
#else
dlclose(h);
#endif
h = nullptr;
}
}
void VulkanSetAvailable(bool available) {
g_vulkanAvailabilityChecked = true;
g_vulkanMayBeAvailable = available;
@ -282,19 +320,7 @@ bool VulkanMayBeAvailable() {
}
INFO_LOG(G3D, "VulkanMayBeAvailable: Device allowed ('%s')", name.c_str());
#ifndef _WIN32
void *lib = nullptr;
for (int i = 0; i < ARRAY_SIZE(so_names); i++) {
lib = dlopen(so_names[i], RTLD_NOW | RTLD_LOCAL);
if (lib) {
INFO_LOG(G3D, "VulkanMayBeAvailable: Library loaded ('%s')", so_names[i]);
break;
}
}
#else
// LoadLibrary etc
HINSTANCE lib = LoadLibrary(L"vulkan-1.dll");
#endif
VulkanLibraryHandle lib = VulkanLoadLibrary("VulkanMayBeAvailable");
if (!lib) {
INFO_LOG(G3D, "Vulkan loader: Library not available");
g_vulkanAvailabilityChecked = true;
@ -452,11 +478,7 @@ bail:
localDestroyInstance(instance, nullptr);
}
if (lib) {
#ifndef _WIN32
dlclose(lib);
#else
FreeLibrary(lib);
#endif
VulkanFreeLibrary(lib);
} else {
ERROR_LOG(G3D, "Vulkan with working device not detected.");
}
@ -465,18 +487,7 @@ bail:
bool VulkanLoad() {
if (!vulkanLibrary) {
#ifndef _WIN32
for (int i = 0; i < ARRAY_SIZE(so_names); i++) {
vulkanLibrary = dlopen(so_names[i], RTLD_NOW | RTLD_LOCAL);
if (vulkanLibrary) {
INFO_LOG(G3D, "VulkanLoad: Found library '%s'", so_names[i]);
break;
}
}
#else
// LoadLibrary etc
vulkanLibrary = LoadLibrary(L"vulkan-1.dll");
#endif
vulkanLibrary = VulkanLoadLibrary("VulkanLoad");
if (!vulkanLibrary) {
return false;
}
@ -495,12 +506,7 @@ bool VulkanLoad() {
return true;
} else {
ERROR_LOG(G3D, "VulkanLoad: Failed to load Vulkan base functions.");
#ifndef _WIN32
dlclose(vulkanLibrary);
#else
FreeLibrary(vulkanLibrary);
#endif
vulkanLibrary = nullptr;
VulkanFreeLibrary(vulkanLibrary);
return false;
}
}
@ -706,12 +712,5 @@ void VulkanLoadDeviceFunctions(VkDevice device, const VulkanExtensions &enabledE
}
void VulkanFree() {
if (vulkanLibrary) {
#ifdef _WIN32
FreeLibrary(vulkanLibrary);
#else
dlclose(vulkanLibrary);
#endif
vulkanLibrary = nullptr;
}
VulkanFreeLibrary(vulkanLibrary);
}

View File

@ -2211,7 +2211,7 @@ int initNetwork(SceNetAdhocctlAdhocId *adhoc_id){
u64 now = (u64)(time_now_d() * 1000000.0);
if (coreState == CORE_POWERDOWN)
return iResult;
if (now - startTime > (getSockError((int)metasocket) == EINPROGRESS ? adhocDefaultTimeout*2LL: adhocDefaultTimeout))
if (now - startTime > (u64)(getSockError((int)metasocket) == EINPROGRESS ? adhocDefaultTimeout*2LL: adhocDefaultTimeout))
break;
sleep_ms(10);
}

View File

@ -95,6 +95,7 @@ bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw) {
#else
return false;
#endif
#if !PPSSPP_PLATFORM(SWITCH)
case GPUCORE_VULKAN:
if (!ctx) {
ERROR_LOG(G3D, "Unable to init Vulkan GPU backend, no context");
@ -102,6 +103,7 @@ bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw) {
}
SetGPU(new GPU_Vulkan(ctx, draw));
break;
#endif
}
return gpu != NULL;

View File

@ -741,6 +741,7 @@ int main(int argc, char *argv[]) {
printf("GL init error '%s'\n", error_message.c_str());
}
graphicsContext = ctx;
#if !PPSSPP_PLATFORM(SWITCH)
} else if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN) {
SDLVulkanGraphicsContext *ctx = new SDLVulkanGraphicsContext();
if (!ctx->Init(window, x, y, mode, &error_message)) {
@ -754,6 +755,7 @@ int main(int argc, char *argv[]) {
} else {
graphicsContext = ctx;
}
#endif
}
bool useEmuThread = g_Config.iGPUBackend == (int)GPUBackend::OPENGL;

View File

@ -1496,7 +1496,7 @@ void EmuScreen::renderUI() {
DrawFrameTimes(ctx, ctx->GetLayoutBounds());
}
#if !PPSSPP_PLATFORM(UWP)
#if !PPSSPP_PLATFORM(UWP) && !PPSSPP_PLATFORM(SWITCH)
if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN && g_Config.bShowAllocatorDebug) {
DrawAllocatorVis(ctx, gpu);
}

View File

@ -109,6 +109,7 @@ LibretroGraphicsContext *LibretroGraphicsContext::CreateGraphicsContext() {
delete ctx;
}
#ifndef HAVE_LIBNX
if (preferred == RETRO_HW_CONTEXT_DUMMY || preferred == RETRO_HW_CONTEXT_VULKAN) {
ctx = new LibretroVulkanContext();
@ -117,6 +118,7 @@ LibretroGraphicsContext *LibretroGraphicsContext::CreateGraphicsContext() {
}
delete ctx;
}
#endif
#ifdef _WIN32
if (preferred == RETRO_HW_CONTEXT_DUMMY || preferred == RETRO_HW_CONTEXT_DIRECT3D) {