From 7ca715fda3b055f6fb297b62190a7e822a97b8f6 Mon Sep 17 00:00:00 2001 From: flightlessmango Date: Tue, 14 Nov 2023 06:17:00 +0100 Subject: [PATCH] winesync wip --- src/hud_elements.cpp | 14 ++++++++- src/hud_elements.h | 3 ++ src/overlay_params.h | 1 + src/winesync.h | 67 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/winesync.h diff --git a/src/hud_elements.cpp b/src/hud_elements.cpp index 8a41bfc624b..71b10e9df80 100644 --- a/src/hud_elements.cpp +++ b/src/hud_elements.cpp @@ -1392,6 +1392,15 @@ void HudElements::refresh_rate() { } } +void HudElements::winesync() { + if (HUDElements.winesync_ptr->valid()) { + ImguiNextColumnFirstItem(); + HUDElements.TextColored(HUDElements.colors.engine, "%s", "SYNC"); + ImguiNextColumnOrNewRow(); + right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%s", HUDElements.winesync_ptr->get_method().c_str()); + } +} + void HudElements::sort_elements(const std::pair& option) { const auto& param = option.first; const auto& value = option.second; @@ -1436,7 +1445,8 @@ void HudElements::sort_elements(const std::pair& optio {"graphs", {graphs}}, {"fps_metrics", {fps_metrics}}, {"hdr", {hdr}}, - {"refresh_rate", {refresh_rate}} + {"refresh_rate", {refresh_rate}}, + {"winesync", {winesync}} }; auto check_param = display_params.find(param); @@ -1548,6 +1558,8 @@ void HudElements::legacy_elements(){ ordered_functions.push_back({exec_name, "exec_name", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_duration]) ordered_functions.push_back({duration, "duration", value}); + if (params->enabled[OVERLAY_PARAM_ENABLED_winesync]) + ordered_functions.push_back({winesync, "winesync", value}); } void HudElements::update_exec(){ diff --git a/src/hud_elements.h b/src/hud_elements.h index 01ae5600446..b38e15f40e1 100644 --- a/src/hud_elements.h +++ b/src/hud_elements.h @@ -5,6 +5,7 @@ #include #include "timing.hpp" #include +#include struct Function { std::function run; // Using std::function instead of a raw function pointer for more flexibility @@ -46,6 +47,7 @@ class HudElements{ uint32_t vendorID; int hdr_status = 0; int refresh = 0; + std::unique_ptr winesync_ptr = std::make_unique(); void sort_elements(const std::pair& option); void legacy_elements(); @@ -89,6 +91,7 @@ class HudElements{ static void fps_metrics(); static void hdr(); static void refresh_rate(); + static void winesync(); void convert_colors(const struct overlay_params& params); void convert_colors(bool do_conv, const struct overlay_params& params); diff --git a/src/overlay_params.h b/src/overlay_params.h index f561e641a72..8bea2643fe4 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -108,6 +108,7 @@ typedef unsigned long KeySym; OVERLAY_PARAM_BOOL(inherit) \ OVERLAY_PARAM_BOOL(hdr) \ OVERLAY_PARAM_BOOL(refresh_rate) \ + OVERLAY_PARAM_BOOL(winesync) \ OVERLAY_PARAM_CUSTOM(fps_sampling_period) \ OVERLAY_PARAM_CUSTOM(output_folder) \ OVERLAY_PARAM_CUSTOM(output_file) \ diff --git a/src/winesync.h b/src/winesync.h new file mode 100644 index 00000000000..4772cb1cbba --- /dev/null +++ b/src/winesync.h @@ -0,0 +1,67 @@ +#include "file_utils.h" +#include +#include + +namespace fs = ghc::filesystem; + +class WineSync { + private: + enum syncMethods { + NONE, + ESYNC, + FSYNC, + NTSYNC + }; + + int method = 0; + bool inside_wine; + + const char* methods[4] = { + "None", + "Esync", + "Fsync", + "NTsync" + }; + + public: + WineSync() { + // check that's were inside wine + std::string wineProcess = get_exe_path(); + auto n = wineProcess.find_last_of('/'); + std::string preloader = wineProcess.substr(n + 1); + if (preloader != "wine-preloader" && preloader != "wine64-preloader"){ + inside_wine = false; + return; + } + + // check which sync wine is using, if any. + fs::path path("/proc/self/map_files/"); + for (auto& p : fs::directory_iterator(path)) { + auto filename = p.path().string(); + auto sym = read_symlink(filename.c_str()); + if (sym.find("esync") != std::string::npos) + method = syncMethods::ESYNC; + else if (sym.find("fsync") != std::string::npos) + method = syncMethods::FSYNC; + else if (sym.find("ntsync") != std::string::npos) + method = syncMethods::NTSYNC; + else if (sym.find("winesync") != std::string::npos) + method = syncMethods::NTSYNC; + if (method){ + inside_wine = true; + break; + } + } + }; + + bool valid() { + return inside_wine; + } + + // return sync method as display name + std::string get_method() { + return methods[method]; + } +}; + +extern std::unique_ptr winesync_ptr; \ No newline at end of file