De-linuxify enough for windows test

amd_ags
jackun 5 years ago committed by FlightlessMango
parent 3d503c9f29
commit e2c8a3a24b

@ -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()

@ -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'

@ -0,0 +1,67 @@
#include "file_utils.h"
#include "string_utils.h"
#include <iostream>
#include <fstream>
#include <cstring>
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<std::string> ls(const char* root, const char* prefix, LS_FLAGS flags)
{
std::vector<std::string> 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;
}

@ -1,5 +1,4 @@
#pragma once
#include <pthread.h>
#include <inttypes.h>
struct iostats {

@ -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<KeySym>& keys) {
return false;
}
#endif
#ifdef _WIN32
#include <windows.h>
bool keys_are_pressed(const std::vector<KeySym>& 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

@ -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()),

@ -1,3 +1,4 @@
#include <functional>
#include <chrono>
#include <unistd.h>
#include <fcntl.h>

@ -21,6 +21,10 @@
* IN THE SOFTWARE.
*/
#ifdef _WIN32
#include <windows.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <assert.h>
@ -30,6 +34,7 @@
#include <mutex>
#include <vector>
#include <list>
#include <array>
#include <vulkan/vulkan.h>
#include <vulkan/vk_layer.h>
@ -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 {

@ -1,9 +1,12 @@
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/sysinfo.h>
#include <wordexp.h>
#include <array>
#include "imgui.h"
#include <iostream>
#include <string>
@ -21,9 +24,13 @@
#include "loaders/loader_x11.h"
#endif
#ifdef __gnu_linux__
#ifdef HAVE_DBUS
#include "dbus_info.h"
#endif
//#include <sys/sysinfo.h>
#include <wordexp.h>
#endif
static enum overlay_param_position

Loading…
Cancel
Save