diff --git a/.gitmodules b/.gitmodules index 6b96dbce..b26c0070 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 291fe527..b6379cd9 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -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 diff --git a/app/src/main/cpp/skyline/gpu.cpp b/app/src/main/cpp/skyline/gpu.cpp index 97ec9e16..626245e3 100644 --- a/app/src/main/cpp/skyline/gpu.cpp +++ b/app/src/main/cpp/skyline/gpu.cpp @@ -1,6 +1,9 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/) +#include +#include +#include #include #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(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)),