diff --git a/.gitmodules b/.gitmodules index 427c61ffbd..6f0cd78a5b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -108,3 +108,7 @@ path = 3rdparty/GPUOpen/VulkanMemoryAllocator url = ../../GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git ignore = dirty +[submodule "3rdparty/feralinteractive/feralinteractive"] + path = 3rdparty/feralinteractive/feralinteractive + url = ../../FeralInteractive/gamemode.git + ignore = dirty diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 6c49a889ba..94c6069271 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -357,6 +357,9 @@ add_subdirectory(opencv EXCLUDE_FROM_ALL) # FUSION add_subdirectory(fusion EXCLUDE_FROM_ALL) +# FERAL INTERACTIVE +add_subdirectory(feralinteractive EXCLUDE_FROM_ALL) + # add nice ALIAS targets for ease of use if(USE_SYSTEM_LIBUSB) add_library(3rdparty::libusb ALIAS usb-1.0-shared) @@ -389,3 +392,4 @@ add_library(3rdparty::miniupnpc ALIAS libminiupnpc-static) add_library(3rdparty::rtmidi ALIAS rtmidi) add_library(3rdparty::opencv ALIAS ${OPENCV_TARGET}) add_library(3rdparty::fusion ALIAS Fusion) +add_library(3rdparty::feralinteractive ALIAS 3rdparty_feralinteractive) diff --git a/3rdparty/feralinteractive/CMakeLists.txt b/3rdparty/feralinteractive/CMakeLists.txt new file mode 100644 index 0000000000..c7b136e5f0 --- /dev/null +++ b/3rdparty/feralinteractive/CMakeLists.txt @@ -0,0 +1,9 @@ +# Feral Interactive + +add_library(3rdparty_feralinteractive INTERFACE) + +if (CMAKE_SYSTEM MATCHES "Linux") + target_include_directories(3rdparty_feralinteractive INTERFACE feralinteractive/lib) + target_compile_definitions(3rdparty_feralinteractive INTERFACE -DGAMEMODE_AVAILABLE) + target_link_libraries(3rdparty_feralinteractive INTERFACE feralinteractive) +endif() diff --git a/3rdparty/feralinteractive/feralinteractive b/3rdparty/feralinteractive/feralinteractive new file mode 160000 index 0000000000..af07e169d5 --- /dev/null +++ b/3rdparty/feralinteractive/feralinteractive @@ -0,0 +1 @@ +Subproject commit af07e169d58b574fac2a093296aa37605313bb2b diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f633730fc..81b2a84ee6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,15 @@ if(NOT WIN32) add_compile_options(-pthread) endif() +## Look for Gamemode if its installed on Linux +if(LINUX) + find_program(GAMEMODE_FOUND gamemoded) ## Only works if gamemode is installed on system (might include lib32 case) + if(GAMEMODE_FOUND) + add_compile_definitions(GAMEMODE_AVAILABLE) + endif() + message(GAMEMODE_AVAILABLE="${GAMEMODE_AVAILABLE}") +endif() + # TODO: do real installation, including copying directory structure set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/bin") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/bin") diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 002075b5fa..fb0667c468 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -986,6 +986,7 @@ void Emulator::SetContinuousMode(bool continuous_mode) game_boot_result Emulator::Load(const std::string& title_id, bool is_disc_patch, usz recursion_count) { + if (recursion_count == 0 && m_restrict_emu_state_change) { return game_boot_result::currently_restricted; @@ -2477,6 +2478,11 @@ void Emulator::Run(bool start_playtime) { Emu.GetCallbacks().enable_display_sleep(false); } + + if (g_cfg.misc.enable_gamemode) + { + Emu.GetCallbacks().enable_gamemode(true); + } } void Emulator::RunPPU() @@ -3051,6 +3057,7 @@ extern bool try_lock_spu_threads_in_a_state_compatible_with_savestates(bool reve void Emulator::Kill(bool allow_autoexit, bool savestate, savestate_stage* save_stage) { + static const auto make_ptr = [](auto ptr) { return std::shared_ptr>(ptr); diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 417bef41b8..1053be3b3e 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -112,6 +112,8 @@ struct EmuCallbacks std::function enable_display_sleep; std::function check_microphone_permissions; std::function()> make_video_source; + std::function gamemode_supported; + std::function enable_gamemode; }; namespace utils diff --git a/rpcs3/Emu/system_config.h b/rpcs3/Emu/system_config.h index 92031a51db..2b35e70cb9 100644 --- a/rpcs3/Emu/system_config.h +++ b/rpcs3/Emu/system_config.h @@ -358,6 +358,7 @@ struct cfg_root : cfg::node cfg::_bool silence_all_logs{ this, "Silence All Logs", false, true }; cfg::string title_format{ this, "Window Title Format", "FPS: %F | %R | %V | %T [%t]", true }; cfg::_bool pause_during_home_menu{this, "Pause Emulation During Home Menu", false, false }; + cfg::_bool enable_gamemode{ this, "Enable GameMode", false, false }; } misc{ this }; diff --git a/rpcs3/gamemode_control.cpp b/rpcs3/gamemode_control.cpp new file mode 100644 index 0000000000..9d5a4268f7 --- /dev/null +++ b/rpcs3/gamemode_control.cpp @@ -0,0 +1,39 @@ +#include "gamemode_control.h" + +#ifdef GAMEMODE_AVAILABLE +#pragma GCC diagnostic ignored "-Wold-style-cast" +#endif +extern "C" { + #include "3rdparty/feralinteractive/feralinteractive/lib/gamemode_client.h" +} + +// Checks if Gamemode is supported on system +bool gamemode_supported() +{ +#if defined(GAMEMODE_AVAILABLE) + return true; +#else + return false; +#endif +} + +// TODO: Might add later +/* +static int gamemode_status() { + return gamemode_query_status(); +} +*/ + +// Enables and Disables GameMode based on user settings and system +void enable_gamemode(bool enabled) { + if (!gamemode_supported()) { + return; + } + + // Enable and Disable Gamemode + if (enabled) { + gamemode_request_start(); + } else { + gamemode_request_end(); + } +} diff --git a/rpcs3/gamemode_control.h b/rpcs3/gamemode_control.h new file mode 100644 index 0000000000..091bacd676 --- /dev/null +++ b/rpcs3/gamemode_control.h @@ -0,0 +1,5 @@ +#pragma once + +bool gamemode_supported(); +void enable_gamemode(bool enabled); +//static int gamemode_status(); // Might add later TODO diff --git a/rpcs3/main_application.cpp b/rpcs3/main_application.cpp index 65a8117b7f..137b82d803 100644 --- a/rpcs3/main_application.cpp +++ b/rpcs3/main_application.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "main_application.h" #include "display_sleep_control.h" +#include "gamemode_control.h" #include "util/types.hpp" #include "util/logs.hpp" diff --git a/rpcs3/rpcs3qt/CMakeLists.txt b/rpcs3/rpcs3qt/CMakeLists.txt index c49daf0346..7f7605cb74 100644 --- a/rpcs3/rpcs3qt/CMakeLists.txt +++ b/rpcs3/rpcs3qt/CMakeLists.txt @@ -133,6 +133,7 @@ add_library(rpcs3_ui STATIC welcome_dialog.ui ../display_sleep_control.cpp + ../gamemode_control.cpp ../headless_application.cpp ../main_application.cpp ../module_verifier.cpp diff --git a/rpcs3/rpcs3qt/emu_settings_type.h b/rpcs3/rpcs3qt/emu_settings_type.h index 0fda096705..2504d79dd4 100644 --- a/rpcs3/rpcs3qt/emu_settings_type.h +++ b/rpcs3/rpcs3qt/emu_settings_type.h @@ -186,6 +186,8 @@ enum class emu_settings_type ShowMouseAndKeyboardToggleHint, WindowTitleFormat, PauseDuringHomeMenu, + EnableGamemode, + // Network InternetStatus, @@ -388,6 +390,8 @@ inline static const std::map settings_location { emu_settings_type::SilenceAllLogs, { "Miscellaneous", "Silence All Logs" }}, { emu_settings_type::WindowTitleFormat, { "Miscellaneous", "Window Title Format" }}, { emu_settings_type::PauseDuringHomeMenu, { "Miscellaneous", "Pause Emulation During Home Menu" }}, + { emu_settings_type::EnableGamemode, { "Miscellaneous", "Enable GameMode" }}, + // Networking { emu_settings_type::InternetStatus, { "Net", "Internet enabled"}}, diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 82f29fcdbd..14ed3a2c7f 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -15,6 +15,7 @@ #include "qt_music_handler.h" #include "rpcs3_version.h" #include "display_sleep_control.h" +#include "gamemode_control.h" #ifdef WITH_DISCORD_RPC #include "_discord_utils.h" @@ -950,6 +951,9 @@ void gui_application::InitializeCallbacks() callbacks.display_sleep_control_supported = [](){ return display_sleep_control_supported(); }; callbacks.enable_display_sleep = [](bool enabled){ enable_display_sleep(enabled); }; + callbacks.gamemode_supported = [](){ return gamemode_supported(); }; + callbacks.enable_gamemode = [](bool enabled){ enable_gamemode(enabled); }; + callbacks.check_microphone_permissions = []() { Emu.BlockingCallFromMainThread([]() diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 547acd97d6..d238f8e6ab 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -96,6 +96,10 @@ #define RPCS3_UPDATE_SUPPORTED #endif +#ifdef GAMEMODE_AVAILABLE +#include "../gamemode_control.h" +#endif + LOG_CHANNEL(gui_log, "GUI"); extern atomic_t g_user_asked_for_frame_capture; @@ -285,6 +289,13 @@ bool main_window::Init([[maybe_unused]] bool with_cli_boot) update_gui_pad_thread(); + // Enable Gamemode +#if defined GAMEMODE_AVAILABLE && defined __linux__ + // NOTE: Compiler complains if I pass the config value directly so I have to do this + if (g_cfg.misc.enable_gamemode) { + enable_gamemode(true); + } +#endif return true; } diff --git a/rpcs3/rpcs3qt/settings_dialog.cpp b/rpcs3/rpcs3qt/settings_dialog.cpp index 7ad9023f4e..7569e5adca 100644 --- a/rpcs3/rpcs3qt/settings_dialog.cpp +++ b/rpcs3/rpcs3qt/settings_dialog.cpp @@ -1844,6 +1844,17 @@ settings_dialog::settings_dialog(std::shared_ptr gui_settings, std m_emu_settings->EnhanceCheckBox(ui->useNativeInterface, emu_settings_type::UseNativeInterface); SubscribeTooltip(ui->useNativeInterface, tooltips.settings.use_native_interface); +#if defined(__linux__) + ui->enableGamemode->setVisible(true); +#endif +#if defined(GAMEMODE_AVAILABLE) + ui->enableGamemode->setEnabled(true); + m_emu_settings->EnhanceCheckBox(ui->enableGamemode, emu_settings_type::EnableGamemode); + SubscribeTooltip(ui->enableGamemode, tooltips.settings.enable_gamemode); +#else + SubscribeTooltip(ui->enableGamemode, tooltips.settings.no_gamemode); +#endif + m_emu_settings->EnhanceCheckBox(ui->showShaderCompilationHint, emu_settings_type::ShowShaderCompilationHint); SubscribeTooltip(ui->showShaderCompilationHint, tooltips.settings.show_shader_compilation_hint); diff --git a/rpcs3/rpcs3qt/settings_dialog.ui b/rpcs3/rpcs3qt/settings_dialog.ui index 7a3d4951a8..f13b8344cd 100644 --- a/rpcs3/rpcs3qt/settings_dialog.ui +++ b/rpcs3/rpcs3qt/settings_dialog.ui @@ -3022,6 +3022,19 @@ + + + + false + + + false + + + Enable GameMode + + + diff --git a/rpcs3/rpcs3qt/tooltips.h b/rpcs3/rpcs3qt/tooltips.h index 41cfc1e6d8..0ef5ae76ec 100644 --- a/rpcs3/rpcs3qt/tooltips.h +++ b/rpcs3/rpcs3qt/tooltips.h @@ -129,6 +129,8 @@ public: // emulator + const QString enable_gamemode = tr("Activate Feral Interactive's GameMode.\nThis is a series of CPU and GPU optimizations and can potentially benefit game performance on some systems."); + const QString no_gamemode = tr("This requires Feral Interactive's GameMode to be installed.\nGameMode is a series of CPU and GPU optimizations and can potentially benefit game performance on some systems.\nTo install GameMode for your specific Linux distribution, go to the GitHub page:https://github.com/FeralInteractive/gamemode."); const QString exit_on_stop = tr("Automatically close RPCS3 when closing a game, or when a game closes itself."); const QString pause_on_focus_loss = tr("Automatically pause emulation when RPCS3 loses its focus or the application is inactive in order to save power and reduce CPU usage.\nDo note that emulation pausing in general is not perfect and may not be compatible with all games.\nAlthough it currently also pauses gameplay, it is not recommended to rely on it as this behavior may be changed in the future and it is not the purpose of this setting."); const QString start_game_fullscreen = tr("Automatically puts the game window in fullscreen.\nDouble click on the game window or press Alt+Enter to toggle fullscreen and windowed mode.");