0
0
mirror of https://github.com/Ishan09811/pine.git synced 2025-04-24 08:55:10 +00:00

Integrate GPU memory mapping using adrenotools_mem_gpu_allocate and adrenotools_mem_cpu_map (#30)

This commit is contained in:
Ishan09811 2024-10-05 18:39:06 +05:30 committed by GitHub
parent 1d0b0ec14d
commit 3fdef75d03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -343,7 +343,8 @@ namespace skyline::gpu {
static PFN_vkGetInstanceProcAddr LoadVulkanDriver(const DeviceState &state, adrenotools_gpu_mapping *mapping) {
void *libvulkanHandle{};
void *userMappingHandle = nullptr; // New void* pointer for user mapping handle
void *userMappingHandle = nullptr;
uint64_t gpuMemSize = 0;
// If the user has selected a custom driver, try to load it
if (!(*state.settings->gpuDriver).empty()) {
@ -355,15 +356,24 @@ namespace skyline::gpu {
(state.os->privateAppFilesPath + "gpu_drivers/" + *state.settings->gpuDriver + "/").c_str(),
(*state.settings->gpuDriverLibraryName).c_str(),
(state.os->publicAppFilesPath + "gpu/vk_file_redirect/").c_str(),
reinterpret_cast<void**>(&userMappingHandle) // Use reinterpret_cast to pass as void**
reinterpret_cast<void**>(&userMappingHandle)
);
// Cast the userMappingHandle back to adrenotools_gpu_mapping*
if (libvulkanHandle) {
mapping = reinterpret_cast<adrenotools_gpu_mapping*>(userMappingHandle);
}
if (!libvulkanHandle) {
// GPU memory allocation
if (!adrenotools_mem_gpu_allocate(userMappingHandle, &gpuMemSize)) {
LOGW("Failed to allocate GPU memory.");
return nullptr;
}
// CPU-side memory mapping
if (!adrenotools_mem_cpu_map(userMappingHandle, mapping->host_ptr, gpuMemSize)) {
LOGW("Failed to map GPU memory to CPU.");
return nullptr;
}
} else {
char *error = dlerror();
LOGW("Failed to load custom Vulkan driver {}/{}: {}", *state.settings->gpuDriver, *state.settings->gpuDriverLibraryName, error ? error : "");
}
@ -378,15 +388,24 @@ namespace skyline::gpu {
nullptr,
nullptr,
(state.os->publicAppFilesPath + "gpu/vk_file_redirect/").c_str(),
reinterpret_cast<void**>(&userMappingHandle) // Use reinterpret_cast for user mapping handle
reinterpret_cast<void**>(&userMappingHandle)
);
// Cast the userMappingHandle back to adrenotools_gpu_mapping*
if (libvulkanHandle) {
mapping = reinterpret_cast<adrenotools_gpu_mapping*>(userMappingHandle);
}
if (!libvulkanHandle) {
// GPU memory allocation
if (!adrenotools_mem_gpu_allocate(userMappingHandle, &gpuMemSize)) {
LOGW("Failed to allocate GPU memory.");
return nullptr;
}
// CPU-side memory mapping
if (!adrenotools_mem_cpu_map(userMappingHandle, mapping->host_ptr, gpuMemSize)) {
LOGW("Failed to map GPU memory to CPU.");
return nullptr;
}
} else {
char *error = dlerror();
LOGW("Failed to load builtin Vulkan driver: {}", error ? error : "");
}
@ -398,6 +417,7 @@ namespace skyline::gpu {
}
GPU::GPU(const DeviceState &state)
: state(state),
vkContext(LoadVulkanDriver(state, &adrenotoolsImportMapping)),