From a5cf130e2cffd73d54599493c0db62d93ddaea84 Mon Sep 17 00:00:00 2001 From: Er2 Date: Sat, 13 Apr 2024 21:13:23 +0300 Subject: [PATCH] Add FreeBSD support --- meson.build | 8 +++++++- package-native.sh | 16 ++++++++++++++-- src/util/thread.h | 4 ++++ src/util/util_env.cpp | 14 ++++++++++++++ src/util/util_win32_compat.h | 2 +- src/wsi/sdl2/wsi_platform_sdl2.h | 2 +- 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index e35a9de0..70a93eb1 100644 --- a/meson.build +++ b/meson.build @@ -131,7 +131,13 @@ else dxvk_wsi = get_option('dxvk_native_wsi') if dxvk_wsi == 'sdl2' - lib_sdl2 = cpp.find_library('SDL2') + if platform == 'freebsd' + # kinda hacky + dxvk_include_dirs += ['/usr/local/include'] + lib_sdl2 = dependency('SDL2', required: true) + else + lib_sdl2 = cpp.find_library('SDL2', required: true) + endif compiler_args += ['-DDXVK_WSI_SDL2'] elif dxvk_wsi == 'glfw' lib_glfw = cpp.find_library('glfw') diff --git a/package-native.sh b/package-native.sh index 56915e63..cbd4132e 100755 --- a/package-native.sh +++ b/package-native.sh @@ -25,6 +25,8 @@ shift 2 opt_nopackage=0 opt_devbuild=0 opt_buildid=false +opt_64_only=0 +opt_32_only=0 CC=${CC:="gcc"} CXX=${CXX:="g++"} @@ -41,6 +43,12 @@ while [ $# -gt 0 ]; do "--build-id") opt_buildid=true ;; + "--64-only") + opt_64_only=1 + ;; + "--32-only") + opt_32_only=1 + ;; *) echo "Unrecognized option: $1" >&2 exit 1 @@ -81,8 +89,12 @@ function package { rm -R "dxvk-native-$DXVK_VERSION" } -build_arch 64 lib -build_arch 32 lib32 +if [ $opt_32_only -eq 0 ]; then + build_arch 64 lib +fi +if [ $opt_64_only -eq 0 ]; then + build_arch 32 lib32 +fi if [ $opt_nopackage -eq 0 ]; then package diff --git a/src/util/thread.h b/src/util/thread.h index 6e25f407..2c20c02e 100644 --- a/src/util/thread.h +++ b/src/util/thread.h @@ -316,7 +316,11 @@ namespace dxvk { switch (priority) { default: case ThreadPriority::Normal: policy = SCHED_OTHER; break; +#ifndef __linux__ + case ThreadPriority::Lowest: policy = SCHED_OTHER; break; +#else case ThreadPriority::Lowest: policy = SCHED_IDLE; break; +#endif } ::pthread_setschedparam(this->native_handle(), policy, ¶m); } diff --git a/src/util/util_env.cpp b/src/util/util_env.cpp index 1b0901f6..6469b6a4 100644 --- a/src/util/util_env.cpp +++ b/src/util/util_env.cpp @@ -6,6 +6,9 @@ #ifdef __linux__ #include #include +#elif defined(__FreeBSD__) +#include +#include #endif #include "util_env.h" @@ -85,6 +88,17 @@ namespace dxvk::env { size_t count = readlink("/proc/self/exe", exePath.data(), exePath.size()); return std::string(exePath.begin(), exePath.begin() + count); +#elif defined(__FreeBSD__) + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid()}; + std::string exePath(PATH_MAX, '\0'); + size_t size = exePath.size(); + + if (sysctl(mib, 4, exePath.data(), &size, NULL, 0) != 0) { + // throw error here? + return ""; + } + + return exePath; #endif } diff --git a/src/util/util_win32_compat.h b/src/util/util_win32_compat.h index 74ea6ece..5b156c6e 100644 --- a/src/util/util_win32_compat.h +++ b/src/util/util_win32_compat.h @@ -1,6 +1,6 @@ #pragma once -#if defined(__linux__) +#if defined(__unix__) #include #include diff --git a/src/wsi/sdl2/wsi_platform_sdl2.h b/src/wsi/sdl2/wsi_platform_sdl2.h index 411fe8f6..70620201 100644 --- a/src/wsi/sdl2/wsi_platform_sdl2.h +++ b/src/wsi/sdl2/wsi_platform_sdl2.h @@ -18,4 +18,4 @@ namespace dxvk::wsi { return displayId < displayCount && displayId >= 0; } -} \ No newline at end of file +}