Add support for turnip and driver file redirection via libadrenotools

This commit is contained in:
Billy Laws 2021-12-08 23:10:54 +00:00 committed by PixelyIon
parent dd91d063a5
commit b4927d0138
3 changed files with 31 additions and 6 deletions

5
.gitmodules vendored
View File

@ -54,8 +54,3 @@
[submodule "libadrenotools"]
path = app/libraries/adrenotools
url = https://github.com/bylaws/libadrenotools/
branch = master
[submodule "app/libraries/adrenotools"]
path = app/libraries/adrenotools
url = https://github.com/bylaws/libadrenotools/
branch = master

View File

@ -60,6 +60,7 @@ add_compile_definitions(VK_USE_PLATFORM_ANDROID_KHR) # We want all the Android-s
add_compile_definitions(VULKAN_HPP_NO_SPACESHIP_OPERATOR) # libcxx doesn't implement operator<=> for std::array which breaks this
add_compile_definitions(VULKAN_HPP_NO_STRUCT_CONSTRUCTORS) # We want to use designated initializers in Vulkan-Hpp
add_compile_definitions(VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) # We use the dynamic loader rather than the static one to avoid an additional level of indirection
add_compile_definitions(VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL=0) # We disable the dynamic loader tool so we can supply our own getInstanceProcAddress function from a custom driver
include_directories(SYSTEM "libraries/vkhpp")
include_directories(SYSTEM "libraries/vkhpp/Vulkan-Headers/include") # We use base Vulkan headers from this to ensure version parity with Vulkan-Hpp

View File

@ -1,6 +1,9 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/)
#include <dlfcn.h>
#include <adrenotools/driver.h>
#include <os.h>
#include <jvm.h>
#include "gpu.h"
@ -208,8 +211,34 @@ namespace skyline::gpu {
});
}
static PFN_vkGetInstanceProcAddr LoadVulkanDriver(const DeviceState &state) {
// Try turnip first, if not then fallback to regular with file redirect then plain dlopen
auto libvulkanHandle{adrenotools_open_libvulkan(RTLD_NOW,
ADRENOTOOLS_DRIVER_CUSTOM,
nullptr, // We require Android 10 so don't need to supply
state.os->nativeLibraryPath.c_str(),
(state.os->appFilesPath + "turnip/").c_str(),
"libvulkan_freedreno.so",
nullptr)};
if (!libvulkanHandle) {
libvulkanHandle = adrenotools_open_libvulkan(RTLD_NOW,
ADRENOTOOLS_DRIVER_FILE_REDIRECT,
nullptr, // We require Android 10 so don't need to supply
state.os->nativeLibraryPath.c_str(),
nullptr,
nullptr,
(state.os->appFilesPath + "vk_file_redirect/").c_str());
if (!libvulkanHandle)
libvulkanHandle = dlopen("libvulkan.so", RTLD_NOW);
}
return reinterpret_cast<PFN_vkGetInstanceProcAddr>(dlsym(libvulkanHandle, "vkGetInstanceProcAddr"));
}
GPU::GPU(const DeviceState &state)
: vkInstance(CreateInstance(state, vkContext)),
: vkContext(LoadVulkanDriver(state)),
vkInstance(CreateInstance(state, vkContext)),
vkDebugReportCallback(CreateDebugReportCallback(vkInstance)),
vkPhysicalDevice(CreatePhysicalDevice(vkInstance)),
vkDevice(CreateDevice(vkContext, vkPhysicalDevice, vkQueueFamilyIndex, traits)),