Add 'use_xnvctrl' feature to allow building without libXNVCtrl support

pull/131/head
jackun 4 years ago
parent fd6e742474
commit 049e960589
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -3,3 +3,4 @@ option('use_system_vulkan', type : 'feature', value : 'disabled', description: '
option('mangohud_prefix', type : 'string', value : '', description: 'Add prefix to cross-compiled library, like "lib32-".') option('mangohud_prefix', type : 'string', value : '', description: 'Add prefix to cross-compiled library, like "lib32-".')
option('append_libdir_mangohud', type : 'boolean', value : true, description: 'Append "mangohud" to libdir path or not.') option('append_libdir_mangohud', type : 'boolean', value : true, description: 'Append "mangohud" to libdir path or not.')
option('include_doc', type : 'boolean', value : true, description: 'Include the example config') option('include_doc', type : 'boolean', value : true, description: 'Include the example config')
option('use_xnvctrl', type : 'feature', value : 'enabled', description: 'Enable XNVCtrl support')

@ -14,7 +14,9 @@ void *getNvidiaGpuInfo(void *){
gpu_info.memoryUsed = nvidiaMemory.used / (1024.f * 1024.f * 1024.f); gpu_info.memoryUsed = nvidiaMemory.used / (1024.f * 1024.f * 1024.f);
gpu_info.CoreClock = nvidiaCoreClock; gpu_info.CoreClock = nvidiaCoreClock;
gpu_info.MemClock = nvidiaMemClock; gpu_info.MemClock = nvidiaMemClock;
} else if (nvctrlSuccess) { }
#ifdef HAVE_XNVCTRL
else if (nvctrlSuccess) {
getNvctrlInfo(); getNvctrlInfo();
gpu_info.load = nvctrl_info.load; gpu_info.load = nvctrl_info.load;
gpu_info.temp = nvctrl_info.temp; gpu_info.temp = nvctrl_info.temp;
@ -22,6 +24,7 @@ void *getNvidiaGpuInfo(void *){
gpu_info.CoreClock = nvctrl_info.CoreClock; gpu_info.CoreClock = nvctrl_info.CoreClock;
gpu_info.MemClock = nvctrl_info.MemClock; gpu_info.MemClock = nvctrl_info.MemClock;
} }
#endif
pthread_detach(gpuThread); pthread_detach(gpuThread);
return NULL; return NULL;

@ -44,7 +44,6 @@ vklayer_files = files(
'font_unispace.c', 'font_unispace.c',
'cpu.cpp', 'cpu.cpp',
'loaders/loader_nvml.cpp', 'loaders/loader_nvml.cpp',
'loaders/loader_nvctrl.cpp',
'nvml.cpp', 'nvml.cpp',
'file_utils.cpp', 'file_utils.cpp',
'memory.cpp', 'memory.cpp',
@ -53,7 +52,6 @@ vklayer_files = files(
'gpu.cpp', 'gpu.cpp',
'notify.cpp', 'notify.cpp',
'elfhacks.cpp', 'elfhacks.cpp',
'nvctrl.cpp',
) )
opengl_files = files( opengl_files = files(
@ -63,10 +61,18 @@ opengl_files = files(
'loaders/loader_gl.cpp', 'loaders/loader_gl.cpp',
'gl/gl3w/GL/gl3w.c', 'gl/gl3w/GL/gl3w.c',
) )
if get_option('use_xnvctrl').enabled()
pre_args += '-DHAVE_XNVCTRL'
vklayer_files += files(
'loaders/loader_nvctrl.cpp',
'nvctrl.cpp',
)
endif
pre_args += '-DHOOK_DLSYM' pre_args += '-DHOOK_DLSYM'
inc_opengl = include_directories('gl/gl3w') inc_opengl = include_directories('gl/gl3w')
# lib_xnvctrl = cc.find_library('XNVCtrl')
vklayer_mesa_overlay = shared_library( vklayer_mesa_overlay = shared_library(
'MangoHud', 'MangoHud',
util_files, util_files,

@ -1,4 +1,4 @@
#include <stdio.h> #include <iostream>
#include <cstring> #include <cstring>
#include <sstream> #include <sstream>
#include <unordered_map> #include <unordered_map>
@ -18,12 +18,12 @@ bool checkXNVCtrl()
{ {
if (nvctrl.IsLoaded()) { if (nvctrl.IsLoaded()) {
nvctrlSuccess = nvctrl.XNVCTRLIsNvScreen(display, 0); nvctrlSuccess = nvctrl.XNVCTRLIsNvScreen(display, 0);
if (!nvctrlSuccess)
std::cerr << "MANGOHUD: XNVCtrl didn't find the correct display" << std::endl;
return nvctrlSuccess; return nvctrlSuccess;
} else {
printf("MANGOHUD: XNVCtrl failed to load");
} }
if (!nvctrlSuccess)
printf("MANGOHUD: XNVCtrl didn't find the correct display"); std::cerr << "MANGOHUD: XNVCtrl failed to load\n";
return false; return false;
} }
@ -46,13 +46,11 @@ void parse_token(std::string token, string_map& options) {
} }
char* get_attr_target_string(int attr, int target_type, int target_id) { char* get_attr_target_string(int attr, int target_type, int target_id) {
char* c = nullptr; char* c = nullptr;
if (!nvctrl.XNVCTRLQueryTargetStringAttribute(display, target_type, target_id, 0, attr, &c)) {
if (!nvctrl.XNVCTRLQueryTargetStringAttribute(display, target_type, target_id, 0, attr, &c)) { std::cerr << "Failed to query attribute '" << attr << "'.\n";
fprintf(stderr, "Failed to query attribute '%d'.\n", attr); }
return c;
}
return c;
} }
void getNvctrlInfo(){ void getNvctrlInfo(){

@ -10,4 +10,4 @@ extern struct nvmlMemory_st nvidiaMemory;
extern bool nvmlSuccess; extern bool nvmlSuccess;
bool checkNVML(void); bool checkNVML(void);
void getNVMLInfo(void); bool getNVMLInfo(void);

@ -25,7 +25,7 @@ bool checkNVML(){
return false; return false;
} }
void getNVMLInfo(){ bool getNVMLInfo(){
nvmlReturn_t response; nvmlReturn_t response;
nvml.nvmlDeviceGetHandleByIndex(0, &nvidiaDevice); nvml.nvmlDeviceGetHandleByIndex(0, &nvidiaDevice);
response = nvml.nvmlDeviceGetUtilizationRates(nvidiaDevice, &nvidiaUtilization); response = nvml.nvmlDeviceGetUtilizationRates(nvidiaDevice, &nvidiaUtilization);
@ -35,4 +35,5 @@ void getNVMLInfo(){
nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_MEM, &nvidiaMemClock); nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_MEM, &nvidiaMemClock);
if (response == NVML_ERROR_NOT_SUPPORTED) if (response == NVML_ERROR_NOT_SUPPORTED)
nvmlSuccess = false; nvmlSuccess = false;
return nvmlSuccess;
} }

@ -710,13 +710,14 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params)
if (vendorID == 0x8086 if (vendorID == 0x8086
|| vendorID == 0x10de) { || vendorID == 0x10de) {
if (checkNVML()) bool nvSuccess = (checkNVML() && getNVMLInfo());
getNVMLInfo();
if (!nvmlSuccess) #ifdef HAVE_XNVCTRL
checkXNVCtrl(); if (!nvSuccess)
nvSuccess = checkXNVCtrl();
#endif
if ((params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = (nvmlSuccess || nvctrlSuccess))) { if ((params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = nvSuccess)) {
vendorID = 0x10de; vendorID = 0x10de;
} }
} }

Loading…
Cancel
Save