Skip to content

Commit

Permalink
fix: add patches
Browse files Browse the repository at this point in the history
  • Loading branch information
sangjanai committed Dec 17, 2024
1 parent af18012 commit 224a066
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
Binary file added .github/patches/linux/libvulkan.so
Binary file not shown.
Binary file added .github/patches/windows/vulkan-1.dll
Binary file not shown.
6 changes: 6 additions & 0 deletions engine/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,9 @@ set_target_properties(${TARGET_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)

if(UNIX AND NOT APPLE)
configure_file("${PROJECT_SOURCE_DIR}/../../.github/patches/linux/libvulkan.so" "${CMAKE_BINARY_DIR}/libvulkan.so" COPYONLY)
elseif(MSVC)
configure_file("${PROJECT_SOURCE_DIR}/../../.github/patches/windows/vulkan-1.dll" "${CMAKE_BINARY_DIR}/vulkan-1.dll" COPYONLY)
endif()
32 changes: 29 additions & 3 deletions engine/utils/hardware/gpu/vulkan/vulkan_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <vector>

#include "common/hardware_common.h"
#include "utils/file_manager_utils.h"
#include "utils/logging_utils.h"
#include "utils/result.hpp"
#include "vulkan.h"

Expand Down Expand Up @@ -191,7 +193,7 @@ GetGpuUsage() {
}
}
} catch (const std::exception& ex) {
std::cerr << "Error: " << ex.what() << std::endl;
std::cerr << "Error: " << ex.what() << std::endl;
return cpp::fail("Error: " + std::string(ex.what()));
}

Expand Down Expand Up @@ -234,13 +236,37 @@ inline int FreeLibrary(void* pLibrary) {
#endif

inline cpp::result<std::vector<cortex::hw::GPU>, std::string> GetGpuInfoList() {
namespace fmu = file_manager_utils;
auto get_vulkan_path = [](const std::string& lib_vulkan)
-> cpp::result<std::filesystem::path, std::string> {
if (std::filesystem::exists(fmu::GetExecutableFolderContainerPath() /
lib_vulkan)) {
return fmu::GetExecutableFolderContainerPath() / lib_vulkan;
// fallback to deps path
} else if (std::filesystem::exists(fmu::GetCortexDataPath() / "deps" /
lib_vulkan)) {
return fmu::GetCortexDataPath() / "deps" / lib_vulkan;
} else {
CTL_WRN("Could not found " << lib_vulkan);
return cpp::fail("Could not found " + lib_vulkan);
}
};
// Load the Vulkan library
#if defined(__APPLE__) && defined(__MACH__)
void* vulkanLibrary = nullptr;
#elif defined(__linux__)
void* vulkanLibrary = dlopen("libvulkan.so", RTLD_LAZY | RTLD_GLOBAL);
auto vulkan_path = get_vulkan_path("libvulkan.so");
if (vulkan_path.has_error()) {
return cpp::fail(vulkan_path.error());
}
void* vulkanLibrary =
dlopen(vulkan_path.value().string().c_str(), RTLD_LAZY | RTLD_GLOBAL);
#else
HMODULE vulkanLibrary = LoadLibraryW(L"vulkan-1.dll");
auto vulkan_path = get_vulkan_path("vulkan-1.dll");
if (vulkan_path.has_error()) {
return cpp::fail(vulkan_path.error());
}
HMODULE vulkanLibrary = LoadLibraryW(vulkan_path.value().string());
#endif
if (!vulkanLibrary) {
std::cerr << "Failed to load the Vulkan library." << std::endl;
Expand Down

0 comments on commit 224a066

Please sign in to comment.