De-linuxify enough for windows test

d3d11
jackun 4 years ago
parent 29e5c4e460
commit c02e52d323
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -45,9 +45,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')
@ -92,9 +94,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']
@ -105,7 +114,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
@ -115,7 +124,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 = []
@ -182,10 +190,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;
}

@ -7,7 +7,10 @@
using namespace std;
extern FILE *amdGpuFile, *amdTempFile, *amdGpuVramTotalFile, *amdGpuVramUsedFile, *amdGpuCoreClockFile, *amdGpuMemoryClockFile;
#ifdef __gnu_linux__
extern pthread_t cpuThread, gpuThread, cpuInfoThread;
#endif
struct amdGpu {
int load;

@ -2,6 +2,7 @@
#include "string_utils.h"
#include <fstream>
#ifdef __gnu_linux__
pthread_t ioThread;
void *getIoStats(void *args) {
iostats *io = reinterpret_cast<iostats *>(args);
@ -25,3 +26,4 @@ void *getIoStats(void *args) {
pthread_detach(ioThread);
return NULL;
}
#endif

@ -1,8 +1,10 @@
#pragma once
#include <pthread.h>
#include <inttypes.h>
#ifdef __gnu_linux__
#include <pthread.h>
extern pthread_t ioThread;
#endif
struct iostats {
struct {

@ -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;
@ -8,7 +10,6 @@ typedef unsigned long KeySym;
double elapsedF2, elapsedF12, elapsedReloadCfg;
uint64_t last_f2_press, last_f12_press, reload_cfg_press;
pthread_t f2;
#ifdef HAVE_X11
bool key_is_pressed(KeySym ks) {
@ -22,4 +23,11 @@ bool key_is_pressed(KeySym ks) {
bool isPressed = !!(keys_return[kc2 >> 3] & (1 << (kc2 & 7)));
return isPressed;
}
#endif
#endif
#ifdef _WIN32
#include <windows.h>
bool key_is_pressed(KeySym ks) {
return GetAsyncKeyState(ks) & 0x8000;
}
#endif

@ -37,8 +37,8 @@ void writeFile(string filename){
logArray.clear();
}
void *logging(void *params_void){
overlay_params *params = reinterpret_cast<overlay_params *>(params_void);
void *logging(overlay_params* params){
time_t now_log = time(0);
tm *log_time = localtime(&now_log);
string date = to_string(log_time->tm_year + 1900) + "-" +
@ -65,5 +65,5 @@ void *logging(void *params_void){
}
writeFile(params->output_file + date);
return NULL;
return NULL;
}

@ -43,68 +43,83 @@ 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',
)
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(
@ -140,28 +155,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>
@ -9,28 +10,26 @@
#define EVENT_SIZE ( sizeof (struct inotify_event) )
#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
static void *fileChanged(void *params_void) {
notify_thread *nt = reinterpret_cast<notify_thread *>(params_void);
static void fileChanged(notify_thread& nt) {
int length, i = 0;
char buffer[EVENT_BUF_LEN];
overlay_params local_params = *nt->params;
overlay_params local_params = *nt.params;
while (!nt->quit) {
length = read( nt->fd, buffer, EVENT_BUF_LEN );
while (!nt.quit) {
length = read( nt.fd, buffer, EVENT_BUF_LEN );
while (i < length) {
struct inotify_event *event =
(struct inotify_event *) &buffer[i];
i += EVENT_SIZE + event->len;
if (event->mask & IN_MODIFY) {
parse_overlay_config(&local_params, getenv("MANGOHUD_CONFIG"));
std::lock_guard<std::mutex> lk(nt->mutex);
*nt->params = local_params;
std::lock_guard<std::mutex> lk(nt.mutex);
*nt.params = local_params;
}
}
i = 0;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
return nullptr;
}
bool start_notifier(notify_thread& nt)
@ -48,7 +47,7 @@ bool start_notifier(notify_thread& nt)
return false;
}
pthread_create(&nt.thread, NULL, &fileChanged, &nt);
nt.thread = std::thread(fileChanged, std::ref(nt));
return true;
}
@ -63,5 +62,6 @@ void stop_notifier(notify_thread& nt)
close(nt.fd);
nt.fd = -1;
pthread_join(nt.thread, nullptr);
if (nt.thread.joinable())
nt.thread.join();
}

@ -8,7 +8,7 @@ struct notify_thread
overlay_params *params = nullptr;
bool quit = false;
std::mutex mutex;
pthread_t thread;
std::thread thread;
};
bool start_notifier(notify_thread& nt);

@ -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"
@ -64,6 +67,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;
@ -680,6 +687,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) {
@ -695,16 +703,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 {
@ -735,6 +747,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) {
@ -814,9 +827,11 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params)
params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = false;
}
}
#endif
}
void init_system_info(){
#ifdef __gnu_linux__
const char* ld_preload = getenv("LD_PRELOAD");
if (ld_preload)
unsetenv("LD_PRELOAD");
@ -845,6 +860,7 @@ void init_system_info(){
<< "Os:" << os << "\n"
<< "Gpu:" << gpu << "\n"
<< "Driver:" << driver << std::endl;
#endif
#endif
if (!log_period_env || !try_stoi(log_period, log_period_env))
@ -859,7 +875,7 @@ void check_keybinds(struct overlay_params& params){
elapsedReloadCfg = (double)(now - reload_cfg_press);
if (elapsedF2 >= 500000 && !params.output_file.empty()){
#ifdef HAVE_X11
#if defined(HAVE_X11) || defined(_WIN32)
pressed = key_is_pressed(params.toggle_logging);
#else
pressed = false;
@ -869,14 +885,15 @@ void check_keybinds(struct overlay_params& params){
log_start = now;
loggingOn = !loggingOn;
if (loggingOn && log_period != 0)
pthread_create(&f2, NULL, &logging, &params);
if (loggingOn && log_period != 0) {
auto f2 = std::thread(logging, &params); //std::ref(params));
f2.detach(); //FIXME hackish
}
}
}
if (elapsedF12 >= 500000){
#ifdef HAVE_X11
#if defined(HAVE_X11) || defined(_WIN32)
pressed = key_is_pressed(params.toggle_hud);
#else
pressed = false;
@ -888,7 +905,7 @@ void check_keybinds(struct overlay_params& params){
}
if (elapsedReloadCfg >= 500000){
#ifdef HAVE_X11
#if defined(HAVE_X11) || defined(_WIN32)
pressed = key_is_pressed(params.reload_cfg);
#else
pressed = false;
@ -915,6 +932,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;
@ -941,6 +959,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]) {
@ -1116,7 +1136,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;
@ -1126,6 +1148,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();
@ -1266,6 +1289,7 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
ImGui::PopFont();
}
ImGui::EndTable();
#endif
if (params.enabled[OVERLAY_PARAM_ENABLED_fps]){
ImGui::PushFont(data.font1);
@ -2591,10 +2615,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
@ -2620,11 +2646,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 {

@ -20,13 +20,15 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#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>
@ -41,9 +43,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
@ -375,6 +381,20 @@ parse_overlay_config(struct overlay_params *params,
params->reload_cfg = XK_F4;
#endif
#ifdef _WIN32
params->toggle_hud = VK_F12;
params->toggle_logging = VK_F2;
params->reload_cfg = VK_F4;
#undef parse_toggle_hud
#undef parse_toggle_logging
#undef parse_reload_cfg
#define parse_toggle_hud(x) params->toggle_hud
#define parse_toggle_logging(x) params->toggle_logging
#define parse_reload_cfg(x) params->reload_cfg
#endif
// first pass with env var
if (env)
parse_overlay_env(params, env);

Loading…
Cancel
Save