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('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('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.CoreClock = nvidiaCoreClock;
gpu_info.MemClock = nvidiaMemClock;
} else if (nvctrlSuccess) {
}
#ifdef HAVE_XNVCTRL
else if (nvctrlSuccess) {
getNvctrlInfo();
gpu_info.load = nvctrl_info.load;
gpu_info.temp = nvctrl_info.temp;
@ -22,6 +24,7 @@ void *getNvidiaGpuInfo(void *){
gpu_info.CoreClock = nvctrl_info.CoreClock;
gpu_info.MemClock = nvctrl_info.MemClock;
}
#endif
pthread_detach(gpuThread);
return NULL;

@ -44,7 +44,6 @@ vklayer_files = files(
'font_unispace.c',
'cpu.cpp',
'loaders/loader_nvml.cpp',
'loaders/loader_nvctrl.cpp',
'nvml.cpp',
'file_utils.cpp',
'memory.cpp',
@ -53,7 +52,6 @@ vklayer_files = files(
'gpu.cpp',
'notify.cpp',
'elfhacks.cpp',
'nvctrl.cpp',
)
opengl_files = files(
@ -63,10 +61,18 @@ opengl_files = files(
'loaders/loader_gl.cpp',
'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'
inc_opengl = include_directories('gl/gl3w')
# lib_xnvctrl = cc.find_library('XNVCtrl')
vklayer_mesa_overlay = shared_library(
'MangoHud',
util_files,

@ -1,4 +1,4 @@
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <sstream>
#include <unordered_map>
@ -18,12 +18,12 @@ bool checkXNVCtrl()
{
if (nvctrl.IsLoaded()) {
nvctrlSuccess = nvctrl.XNVCTRLIsNvScreen(display, 0);
if (!nvctrlSuccess)
std::cerr << "MANGOHUD: XNVCtrl didn't find the correct display" << std::endl;
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;
}
@ -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* c = nullptr;
if (!nvctrl.XNVCTRLQueryTargetStringAttribute(display, target_type, target_id, 0, attr, &c)) {
fprintf(stderr, "Failed to query attribute '%d'.\n", attr);
}
return c;
char* c = nullptr;
if (!nvctrl.XNVCTRLQueryTargetStringAttribute(display, target_type, target_id, 0, attr, &c)) {
std::cerr << "Failed to query attribute '" << attr << "'.\n";
}
return c;
}
void getNvctrlInfo(){

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

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

@ -710,13 +710,14 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params)
if (vendorID == 0x8086
|| vendorID == 0x10de) {
if (checkNVML())
getNVMLInfo();
bool nvSuccess = (checkNVML() && getNVMLInfo());
if (!nvmlSuccess)
checkXNVCtrl();
#ifdef HAVE_XNVCTRL
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;
}
}

Loading…
Cancel
Save