From ea905f357be0b6249c8df27f38022f8a23d62f52 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Tue, 4 Mar 2025 06:46:14 +0000 Subject: [PATCH] Added check for AVX on boot --- .gitmodules | 3 +++ UnleashedRecomp/CMakeLists.txt | 23 ++++++++++++++++++++--- UnleashedRecomp/locale/locale.cpp | 6 ++++++ UnleashedRecomp/main.cpp | 11 ++++++++++- UnleashedRecomp/os/host.h | 6 ++++++ UnleashedRecomp/os/linux/host_linux.cpp | 15 +++++++++++++++ UnleashedRecomp/os/win32/host_win32.cpp | 15 +++++++++++++++ thirdparty/cpuid | 1 + 8 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 UnleashedRecomp/os/host.h create mode 100644 UnleashedRecomp/os/linux/host_linux.cpp create mode 100644 UnleashedRecomp/os/win32/host_win32.cpp create mode 160000 thirdparty/cpuid diff --git a/.gitmodules b/.gitmodules index 03e721f6..b7382040 100644 --- a/.gitmodules +++ b/.gitmodules @@ -58,3 +58,6 @@ [submodule "thirdparty/json"] path = thirdparty/json url = https://github.com/nlohmann/json +[submodule "thirdparty/cpuid"] + path = thirdparty/cpuid + url = https://github.com/steinwurf/cpuid.git diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index ce05eb10..e8886f35 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -97,7 +97,19 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "Linux") "os/linux/user_linux.cpp" "os/linux/version_linux.cpp" ) -endif() +endif() + +if (WIN32) + set(UNLEASHED_RECOMP_OS_CXX_SOURCES_NO_AVX + "os/win32/host_win32.cpp" + ) +elseif (CMAKE_SYSTEM_NAME MATCHES "Linux") + set(UNLEASHED_RECOMP_OS_CXX_SOURCES_NO_AVX + "os/linux/host_linux.cpp" + ) +endif() + +list(APPEND UNLEASHED_RECOMP_OS_CXX_SOURCES ${UNLEASHED_RECOMP_OS_CXX_SOURCES_NO_AVX}) set(UNLEASHED_RECOMP_CPU_CXX_SOURCES "cpu/guest_thread.cpp" @@ -204,6 +216,7 @@ set(UNLEASHED_RECOMP_THIRDPARTY_SOURCES set(UNLEASHED_RECOMP_THIRDPARTY_INCLUDES "${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/concurrentqueue" + "${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/cpuid" "${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/ddspp" "${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/imgui" "${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/implot" @@ -222,7 +235,8 @@ if (UNLEASHED_RECOMP_D3D12) list(APPEND UNLEASHED_RECOMP_THIRDPARTY_INCLUDES "${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/D3D12MemoryAllocator/include") list(APPEND UNLEASHED_RECOMP_THIRDPARTY_SOURCES "${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/D3D12MemoryAllocator/src/D3D12MemAlloc.cpp") endif() - + +set_source_files_properties(${UNLEASHED_RECOMP_OS_CXX_SOURCES_NO_AVX} PROPERTIES COMPILE_FLAGS "-mno-avx" SKIP_PRECOMPILE_HEADERS ON) set_source_files_properties(${UNLEASHED_RECOMP_THIRDPARTY_SOURCES} PROPERTIES SKIP_PRECOMPILE_HEADERS ON) set(UNLEASHED_RECOMP_CXX_SOURCES @@ -354,6 +368,8 @@ if (WIN32) ) endif() +add_subdirectory("${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/cpuid" cpuid) + target_link_libraries(UnleashedRecomp PRIVATE fmt::fmt libzstd_static @@ -366,7 +382,8 @@ target_link_libraries(UnleashedRecomp PRIVATE tomlplusplus::tomlplusplus UnleashedRecompLib xxHash::xxhash - CURL::libcurl + CURL::libcurl + steinwurf::cpuid ) target_include_directories(UnleashedRecomp PRIVATE diff --git a/UnleashedRecomp/locale/locale.cpp b/UnleashedRecomp/locale/locale.cpp index 0f7789a7..6b6e0b6f 100644 --- a/UnleashedRecomp/locale/locale.cpp +++ b/UnleashedRecomp/locale/locale.cpp @@ -692,6 +692,12 @@ std::unordered_map> { ELanguage::Italian, "Impossibile creare un backend D3D12 (Windows) o Vulkan.\n\nAssicurati che:\n\n- Il tuo sistema soddisfi i requisiti minimi.\n- I driver della scheda grafica siano aggiornati.\n- Il tuo sistema operativo sia aggiornato." } } }, + { + "System_UnsupportedCPU", + { + { ELanguage::English, "Your CPU does not meet the minimum system requirements." } + } + }, { "Common_On", { diff --git a/UnleashedRecomp/main.cpp b/UnleashedRecomp/main.cpp index d3d12381..802b9ca6 100644 --- a/UnleashedRecomp/main.cpp +++ b/UnleashedRecomp/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -156,18 +157,20 @@ int main(int argc, char *argv[]) os::process::CheckConsole(); if (!os::registry::Init()) - LOGN_WARNING("OS doesn't support registry"); + LOGN_WARNING("OS does not support registry."); os::logger::Init(); bool forceInstaller = false; bool forceDLCInstaller = false; + bool bypassCPURequirements = false; const char *sdlVideoDriver = nullptr; for (uint32_t i = 1; i < argc; i++) { forceInstaller = forceInstaller || (strcmp(argv[i], "--install") == 0); forceDLCInstaller = forceDLCInstaller || (strcmp(argv[i], "--install-dlc") == 0); + bypassCPURequirements = bypassCPURequirements || (strcmp(argv[i], "--bypass-cpu-requirements") == 0); if (strcmp(argv[i], "--sdl-video-driver") == 0) { @@ -180,6 +183,12 @@ int main(int argc, char *argv[]) Config::Load(); + if (!bypassCPURequirements && !os::host::IsCapableCPU()) + { + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, GameWindow::GetTitle(), Localise("System_UnsupportedCPU").c_str(), GameWindow::s_pWindow); + std::_Exit(1); + } + // Check the time since the last time an update was checked. Store the new time if the difference is more than six hours. constexpr double TimeBetweenUpdateChecksInSeconds = 6 * 60 * 60; time_t timeNow = std::time(nullptr); diff --git a/UnleashedRecomp/os/host.h b/UnleashedRecomp/os/host.h new file mode 100644 index 00000000..81b94fa9 --- /dev/null +++ b/UnleashedRecomp/os/host.h @@ -0,0 +1,6 @@ +#pragma once + +namespace os::host +{ + bool IsCapableCPU(); +}; diff --git a/UnleashedRecomp/os/linux/host_linux.cpp b/UnleashedRecomp/os/linux/host_linux.cpp new file mode 100644 index 00000000..4f1c481d --- /dev/null +++ b/UnleashedRecomp/os/linux/host_linux.cpp @@ -0,0 +1,15 @@ +#include + +#if defined(__x86_64__) || defined(_M_X64) +#include +#endif + +bool os::host::IsCapableCPU() +{ +#if defined(__x86_64__) || defined(_M_X64) + cpuid::cpuinfo cpuid; + return cpuid.has_avx(); +#else + return true; +#endif +} diff --git a/UnleashedRecomp/os/win32/host_win32.cpp b/UnleashedRecomp/os/win32/host_win32.cpp new file mode 100644 index 00000000..4f1c481d --- /dev/null +++ b/UnleashedRecomp/os/win32/host_win32.cpp @@ -0,0 +1,15 @@ +#include + +#if defined(__x86_64__) || defined(_M_X64) +#include +#endif + +bool os::host::IsCapableCPU() +{ +#if defined(__x86_64__) || defined(_M_X64) + cpuid::cpuinfo cpuid; + return cpuid.has_avx(); +#else + return true; +#endif +} diff --git a/thirdparty/cpuid b/thirdparty/cpuid new file mode 160000 index 00000000..3d0b3b5b --- /dev/null +++ b/thirdparty/cpuid @@ -0,0 +1 @@ +Subproject commit 3d0b3b5bae4f352c68e8c67fd6894b4d74d1c984