diff --git a/meson.build b/meson.build index 6ac54da..6802efe 100644 --- a/meson.build +++ b/meson.build @@ -30,9 +30,11 @@ else endif # TODO: this is very incomplete +is_unixy = false if ['linux', 'cygwin', 'gnu'].contains(host_machine.system()) pre_args += '-D_GNU_SOURCE' pre_args += '-DHAVE_PTHREAD' + is_unixy = true endif if get_option('glibcxx_asserts') @@ -77,9 +79,16 @@ endforeach vulkan_wsi_args = [] vulkan_wsi_deps = [] -dep_x11 = dependency('x11', required: get_option('with_x11')) -dep_wayland_client = dependency('wayland-client', - required: get_option('with_wayland'), version : '>=1.11') +if is_unixy + dep_x11 = dependency('x11', required: get_option('with_x11')) + dep_wayland_client = dependency('wayland-client', + required: get_option('with_wayland'), version : '>=1.11') + dbus_dep = dependency('dbus-1', required: get_option('with_dbus')).partial_dependency(compile_args : true, includes : true) +else + dep_x11 = null_dep + dep_wayland_client = null_dep + dbus_dep = null_dep +endif if dep_x11.found() vulkan_wsi_args += ['-DVK_USE_PLATFORM_XLIB_KHR'] @@ -90,7 +99,7 @@ if dep_wayland_client.found() vulkan_wsi_deps += dep_wayland_client endif -if not dep_x11.found() and not dep_wayland_client.found() +if is_unixy and not dep_x11.found() and not dep_wayland_client.found() error('At least one of "with_x11" and "with_wayland" should be enabled') endif @@ -100,7 +109,6 @@ inc_common = [ dep_vulkan = dependency('vulkan', required: get_option('use_system_vulkan')) dep_pthread = dependency('threads') -dbus_dep = dependency('dbus-1', required: get_option('with_dbus')).partial_dependency(compile_args : true, includes : true) # Check for generic C arguments c_args = [] @@ -167,10 +175,14 @@ foreach a : cpp_args endforeach # check for dl support -if cc.has_function('dlopen') - dep_dl = null_dep +if is_unixy + if cc.has_function('dlopen') + dep_dl = null_dep + else + dep_dl = cc.find_library('dl') + endif else - dep_dl = cc.find_library('dl') + dep_dl = null_dep endif if dep_vulkan.found() diff --git a/mingw64.txt b/mingw64.txt new file mode 100644 index 0000000..c43a4a5 --- /dev/null +++ b/mingw64.txt @@ -0,0 +1,18 @@ +[binaries] +c = 'x86_64-w64-mingw32-gcc' +cpp = 'x86_64-w64-mingw32-g++' +ar = 'x86_64-w64-mingw32-ar' +strip = 'x86_64-w64-mingw32-strip' +pkgconfig = 'x86_64-w64-mingw32-pkg-config' +sh = '/usr/bin/sh' + +[properties] +c_link_args = ['-static', '-static-libgcc'] +cpp_link_args = ['-static', '-static-libgcc', '-static-libstdc++'] +needs_exe_wrapper = true + +[host_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' diff --git a/src/file_utils_win32.cpp b/src/file_utils_win32.cpp new file mode 100644 index 0000000..211ddd8 --- /dev/null +++ b/src/file_utils_win32.cpp @@ -0,0 +1,67 @@ +#include "file_utils.h" +#include "string_utils.h" +#include +#include +#include + +std::string read_line(const std::string& filename) +{ + std::string line; + std::ifstream file(filename); + std::getline(file, line); + return line; +} + +bool find_folder(const char* root, const char* prefix, std::string& dest) +{ + return false; +} + +bool find_folder(const std::string& root, const std::string& prefix, std::string& dest) +{ + return find_folder(root.c_str(), prefix.c_str(), dest); +} + +std::vector ls(const char* root, const char* prefix, LS_FLAGS flags) +{ + std::vector list; + return list; +} + +bool file_exists(const std::string& path) +{ + return false; +} + +bool dir_exists(const std::string& path) +{ + return false; +} + +std::string get_exe_path() +{ + return std::string(); +} + +bool get_wine_exe_name(std::string& name, bool keep_ext) +{ + return false; +} + +std::string get_home_dir() +{ + std::string path; + return path; +} + +std::string get_data_dir() +{ + std::string path; + return path; +} + +std::string get_config_dir() +{ + std::string path; + return path; +} diff --git a/src/iostats.h b/src/iostats.h index 6e48840..2480768 100644 --- a/src/iostats.h +++ b/src/iostats.h @@ -1,5 +1,4 @@ #pragma once -#include #include struct iostats { diff --git a/src/keybinds.h b/src/keybinds.h index 328990e..220c51f 100644 --- a/src/keybinds.h +++ b/src/keybinds.h @@ -1,6 +1,8 @@ #pragma once +#ifdef HAVE_X11 #include "shared_x11.h" #include "loaders/loader_x11.h" +#endif #ifndef KeySym typedef unsigned long KeySym; @@ -36,3 +38,21 @@ bool keys_are_pressed(const std::vector& keys) { return false; } #endif + +#ifdef _WIN32 +#include +bool keys_are_pressed(const std::vector& keys) { + size_t pressed = 0; + + for (KeySym ks : keys) { + if (GetAsyncKeyState(ks) & 0x8000) + pressed++; + } + + if (pressed > 0 && pressed == keys.size()) { + return true; + } + + return false; +} +#endif \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 34e3446..2b6b7af 100644 --- a/src/meson.build +++ b/src/meson.build @@ -23,69 +23,84 @@ vklayer_files = files( 'overlay_params.cpp', 'font_unispace.c', 'blacklist.cpp', - 'cpu.cpp', - 'loaders/loader_nvml.cpp', - 'nvml.cpp', - 'file_utils.cpp', - 'memory.cpp', 'config.cpp', - 'iostats.cpp', - 'gpu.cpp', - 'notify.cpp', - 'elfhacks.cpp', - 'real_dlsym.cpp', 'pci_ids.cpp', ) -opengl_files = files( - 'gl/glad.c', - 'gl/imgui_impl_opengl3.cpp', - 'gl/imgui_hud.cpp', - 'gl/inject_egl.cpp', -) - -if get_option('with_dlsym').enabled() - pre_args += '-DHOOK_DLSYM' -endif - -if get_option('with_xnvctrl').enabled() - - if not get_option('with_x11').enabled() - error('XNVCtrl also needs \'with_x11\'') - endif +opengl_files = [] - xnvctrl_h_found = cc.has_header('NVCtrl/NVCtrl.h') - if not xnvctrl_h_found - error('NVCtrl.h was not found. Disable with \'with_xnvctrl\' if this feature is not needed.') - endif - - pre_args += '-DHAVE_XNVCTRL' +if ['windows', 'mingw'].contains(host_machine.system()) vklayer_files += files( - 'loaders/loader_nvctrl.cpp', - 'nvctrl.cpp', + 'file_utils_win32.cpp', +# 'MangoHud.def', ) endif -if get_option('with_x11').enabled() - pre_args += '-DHAVE_X11' - +if is_unixy vklayer_files += files( - 'loaders/loader_x11.cpp', - 'shared_x11.cpp', + 'file_utils.cpp', + 'cpu.cpp', + 'memory.cpp', + 'iostats.cpp', + 'gpu.cpp', + 'notify.cpp', + 'elfhacks.cpp', + 'real_dlsym.cpp', + 'loaders/loader_nvml.cpp', + 'nvml.cpp', ) + pre_args += '-DHAVE_NVML' opengl_files += files( - 'loaders/loader_glx.cpp', - 'gl/inject_glx.cpp', + 'gl/glad.c', + 'gl/imgui_impl_opengl3.cpp', + 'gl/imgui_hud.cpp', + 'gl/inject_egl.cpp', ) -endif -if dbus_dep.found() and get_option('with_dbus').enabled() - pre_args += '-DHAVE_DBUS' - vklayer_files += files( - 'dbus.cpp', - 'loaders/loader_dbus.cpp', - ) + if get_option('with_dlsym').enabled() + pre_args += '-DHOOK_DLSYM' + endif + + if get_option('with_xnvctrl').enabled() + + if not get_option('with_x11').enabled() + error('XNVCtrl also needs \'with_x11\'') + endif + + xnvctrl_h_found = cc.has_header('NVCtrl/NVCtrl.h') + if not xnvctrl_h_found + error('NVCtrl.h was not found. Disable with \'with_xnvctrl\' if this feature is not needed.') + endif + + pre_args += '-DHAVE_XNVCTRL' + vklayer_files += files( + 'loaders/loader_nvctrl.cpp', + 'nvctrl.cpp', + ) + endif + + if get_option('with_x11').enabled() + pre_args += '-DHAVE_X11' + + vklayer_files += files( + 'loaders/loader_x11.cpp', + 'shared_x11.cpp', + ) + + opengl_files += files( + 'loaders/loader_glx.cpp', + 'gl/inject_glx.cpp', + ) + endif + + if dbus_dep.found() and get_option('with_dbus').enabled() + pre_args += '-DHAVE_DBUS' + vklayer_files += files( + 'dbus.cpp', + 'loaders/loader_dbus.cpp', + ) + endif endif vklayer_mesa_overlay = shared_library( @@ -121,28 +136,30 @@ vklayer_mesa_overlay = shared_library( install : true ) -mangohud_dlsym = shared_library( - 'MangoHud_dlsym', - files( - 'elfhacks.cpp', - 'real_dlsym.cpp', - 'hook_dlsym.cpp', - ), - c_args : [ - pre_args, - c_vis_args, - no_override_init_args, - ], - cpp_args : [ - pre_args, - cpp_vis_args, - ], - dependencies : [dep_dl], - include_directories : [inc_common], - link_args : cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro', '-Wl,--exclude-libs,ALL']), - install_dir : libdir_mangohud, - install : true -) +if is_unixy + mangohud_dlsym = shared_library( + 'MangoHud_dlsym', + files( + 'elfhacks.cpp', + 'real_dlsym.cpp', + 'hook_dlsym.cpp', + ), + c_args : [ + pre_args, + c_vis_args, + no_override_init_args, + ], + cpp_args : [ + pre_args, + cpp_vis_args, + ], + dependencies : [dep_dl], + include_directories : [inc_common], + link_args : cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro', '-Wl,--exclude-libs,ALL']), + install_dir : libdir_mangohud, + install : true + ) +endif configure_file(input : 'mangohud.json.in', output : '@0@.@1@.json'.format(meson.project_name(), target_machine.cpu_family()), diff --git a/src/notify.cpp b/src/notify.cpp index c375044..2ea2cd8 100644 --- a/src/notify.cpp +++ b/src/notify.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/src/overlay.cpp b/src/overlay.cpp index d58f0f5..16ee7aa 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -21,6 +21,10 @@ * IN THE SOFTWARE. */ +#ifdef _WIN32 +#include +#endif + #include #include #include @@ -30,6 +34,7 @@ #include #include #include +#include #include #include @@ -54,8 +59,6 @@ #include "logging.h" #include "keybinds.h" #include "cpu.h" -#include "loaders/loader_nvml.h" -#include "memory.h" #include "notify.h" #include "blacklist.h" #include "version.h" @@ -66,6 +69,10 @@ float g_overflow = 50.f /* 3333ms * 0.5 / 16.6667 / 2 (to edge and back) */; #endif +#ifdef __gnu_linux__ +#include "memory.h" +#endif + bool open = false; string gpuString; float offset_x, offset_y, hudSpacing; @@ -723,6 +730,7 @@ string exec(string command) { char buffer[128]; string result = ""; +#ifdef __gnu_linux__ // Open pipe to file FILE* pipe = popen(command.c_str(), "r"); if (!pipe) { @@ -738,16 +746,20 @@ string exec(string command) { } pclose(pipe); +#endif + return result; } void init_cpu_stats(overlay_params& params) { auto& enabled = params.enabled; +#ifdef __gnu_linux__ enabled[OVERLAY_PARAM_ENABLED_cpu_stats] = cpuStats.Init() && enabled[OVERLAY_PARAM_ENABLED_cpu_stats]; enabled[OVERLAY_PARAM_ENABLED_cpu_temp] = cpuStats.GetCpuFile() && enabled[OVERLAY_PARAM_ENABLED_cpu_temp]; +#endif } struct PCI_BUS { @@ -793,6 +805,7 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) } } +#ifdef __gnu_linux__ // NVIDIA or Intel but maybe has Optimus if (vendorID == 0x8086 || vendorID == 0x10de) { @@ -876,9 +889,11 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) } } parse_pciids(); +#endif } void init_system_info(){ +#ifdef __gnu_linux__ const char* ld_preload = getenv("LD_PRELOAD"); if (ld_preload) unsetenv("LD_PRELOAD"); @@ -908,6 +923,7 @@ void init_system_info(){ << "Gpu:" << gpu << "\n" << "Driver:" << driver << std::endl; #endif +#endif } void check_keybinds(struct overlay_params& params){ @@ -916,9 +932,8 @@ void check_keybinds(struct overlay_params& params){ elapsedF2 = (double)(now - last_f2_press); elapsedF12 = (double)(now - last_f12_press); elapsedReloadCfg = (double)(now - reload_cfg_press); - - if (elapsedF2 >= 500000){ -#ifdef HAVE_X11 + if (elapsedF2 >= 500000 && !params.output_file.empty()){ +#if defined(HAVE_X11) || defined(_WIN32) pressed = keys_are_pressed(params.toggle_logging); #else pressed = false; @@ -943,7 +958,7 @@ void check_keybinds(struct overlay_params& params){ } if (elapsedF12 >= 500000){ -#ifdef HAVE_X11 +#if defined(HAVE_X11) || defined(_WIN32) pressed = keys_are_pressed(params.toggle_hud); #else pressed = false; @@ -955,7 +970,7 @@ void check_keybinds(struct overlay_params& params){ } if (elapsedReloadCfg >= 500000){ -#ifdef HAVE_X11 +#if defined(HAVE_X11) || defined(_WIN32) pressed = keys_are_pressed(params.reload_cfg); #else pressed = false; @@ -1005,6 +1020,7 @@ void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& pa if (sw_stats.last_fps_update) { if (elapsed >= params.fps_sampling_period) { +#ifdef __gnu_linux__ if (params.enabled[OVERLAY_PARAM_ENABLED_cpu_stats]) { cpuStats.UpdateCPUData(); sw_stats.total_cpu = cpuStats.GetCPUDataTotal().percent; @@ -1031,6 +1047,8 @@ void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& pa gpuLoadLog = gpu_info.load; cpuLoadLog = sw_stats.total_cpu; +#endif + sw_stats.fps = fps; if (params.enabled[OVERLAY_PARAM_ENABLED_time]) { @@ -1272,7 +1290,9 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& { uint32_t f_idx = (data.n_frames - 1) % ARRAY_SIZE(data.frames_stats); uint64_t frame_timing = data.frames_stats[f_idx].stats[OVERLAY_PLOTS_frame_timing]; +#ifdef __gnu_linux__ static float char_width = ImGui::CalcTextSize("A").x; +#endif window_size = ImVec2(params.width, params.height); unsigned width = ImGui::GetIO().DisplaySize.x; unsigned height = ImGui::GetIO().DisplaySize.y; @@ -1287,6 +1307,7 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& if (params.enabled[OVERLAY_PARAM_ENABLED_time]){ ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.00f), "%s", data.time.c_str()); } +#ifdef __gnu_linux__ ImGui::BeginTable("hud", params.tableCols); if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats]){ ImGui::TableNextRow(); @@ -1448,7 +1469,8 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& ImGui::PopFont(); } ImGui::EndTable(); - +#endif + auto engine_color = ImGui::ColorConvertU32ToFloat4(params.engine_color); if (params.enabled[OVERLAY_PARAM_ENABLED_fps] && params.enabled[OVERLAY_PARAM_ENABLED_engine_version]){ ImGui::PushFont(data.font1); @@ -2488,7 +2510,6 @@ static VkResult overlay_CreateSwapchainKHR( } else if (prop.vendorID == 0x8086) { ss << " " << (prop.driverVersion >> 14); ss << "." << (prop.driverVersion & 0x3fff); - } #endif } else { ss << " " << VK_VERSION_MAJOR(prop.driverVersion); @@ -2857,10 +2878,12 @@ static VkResult overlay_CreateInstance( instance_data_map_physical_devices(instance_data, true); if (!is_blacklisted()) { + init_cpu_stats(instance_data->params); parse_overlay_config(&instance_data->params, getenv("MANGOHUD_CONFIG")); instance_data->notifier.params = &instance_data->params; +#ifdef __gnu_linux__ start_notifier(instance_data->notifier); - +#endif init_cpu_stats(instance_data->params); // Adjust height for DXVK/VKD3D version number @@ -2888,11 +2911,19 @@ static void overlay_DestroyInstance( struct instance_data *instance_data = FIND(struct instance_data, instance); instance_data_map_physical_devices(instance_data, false); instance_data->vtable.DestroyInstance(instance, pAllocator); +#ifdef __gnu_linux__ if (!is_blacklisted()) stop_notifier(instance_data->notifier); +#endif destroy_instance_data(instance_data); } +// Doesn't seem to define for windows +#ifdef _WIN32 + #undef VK_LAYER_EXPORT + #define VK_LAYER_EXPORT __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. +#endif + extern "C" VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL overlay_GetDeviceProcAddr(VkDevice dev, const char *funcName); static const struct { diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index 6ffa272..3f7f900 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -1,9 +1,12 @@ +#ifdef _WIN32 +#include +#endif + #include #include #include #include -#include -#include +#include #include "imgui.h" #include #include @@ -21,9 +24,13 @@ #include "loaders/loader_x11.h" #endif +#ifdef __gnu_linux__ #ifdef HAVE_DBUS #include "dbus_info.h" #endif +//#include +#include +#endif static enum overlay_param_position