From 953c8d0e0f9b4c7f3746097c04e2735f5260afd5 Mon Sep 17 00:00:00 2001 From: jackun Date: Tue, 9 Jun 2020 13:44:41 +0300 Subject: [PATCH] Add meson option `with_nvml` --- meson_options.txt | 1 + src/gpu.cpp | 6 +++++- src/meson.build | 20 +++++++++++++++++--- src/overlay.cpp | 6 ++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index e357e8d1..1f458059 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -4,6 +4,7 @@ option('use_system_nvml', type : 'boolean', value : false, description : 'Use sy 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('with_nvml', type : 'combo', value : 'enabled', choices: ['enabled', 'system', 'disabled'], description: 'Enable NVML support') option('with_xnvctrl', type : 'feature', value : 'enabled', description: 'Enable XNVCtrl support') option('with_x11', type : 'feature', value : 'enabled') option('with_wayland', type : 'feature', value : 'disabled') diff --git a/src/gpu.cpp b/src/gpu.cpp index 876feab0..f1e164fa 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -6,6 +6,7 @@ struct gpuInfo gpu_info; amdgpu_files amdgpu {}; void getNvidiaGpuInfo(){ +#ifdef HAVE_NVML if (nvmlSuccess){ getNVMLInfo(); gpu_info.load = nvidiaUtilization.gpu; @@ -14,9 +15,11 @@ void getNvidiaGpuInfo(){ gpu_info.CoreClock = nvidiaCoreClock; gpu_info.MemClock = nvidiaMemClock; gpu_info.powerUsage = nvidiaPowerUsage / 1000; + return; } +#endif #ifdef HAVE_XNVCTRL - else if (nvctrlSuccess) { + if (nvctrlSuccess) { getNvctrlInfo(); gpu_info.load = nvctrl_info.load; gpu_info.temp = nvctrl_info.temp; @@ -24,6 +27,7 @@ void getNvidiaGpuInfo(){ gpu_info.CoreClock = nvctrl_info.CoreClock; gpu_info.MemClock = nvctrl_info.MemClock; gpu_info.powerUsage = 0; + return; } #endif } diff --git a/src/meson.build b/src/meson.build index 34e3446e..5790fcf5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -24,8 +24,6 @@ vklayer_files = files( 'font_unispace.c', 'blacklist.cpp', 'cpu.cpp', - 'loaders/loader_nvml.cpp', - 'nvml.cpp', 'file_utils.cpp', 'memory.cpp', 'config.cpp', @@ -48,6 +46,22 @@ if get_option('with_dlsym').enabled() pre_args += '-DHOOK_DLSYM' endif +nvml_h_found = get_option('with_nvml') == 'enabled' +if get_option('with_nvml') == 'system' + nvml_h_found = cc.has_header('nvml.h') + if not nvml_h_found + error('nvml.h was not found. Disable with \'-Dwith_nvml=disabled\' if gpu stats by NVML is not needed.') + endif +endif + +if nvml_h_found + pre_args += '-DHAVE_NVML' + vklayer_files += files( + 'nvml.cpp', + 'loaders/loader_nvml.cpp', + ) +endif + if get_option('with_xnvctrl').enabled() if not get_option('with_x11').enabled() @@ -56,7 +70,7 @@ if get_option('with_xnvctrl').enabled() 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.') + error('NVCtrl.h was not found. Disable with \'-Dwith_xnvctrl=disabled\' if gpu stats by XNVCtrl is not needed.') endif pre_args += '-DHAVE_XNVCTRL' diff --git a/src/overlay.cpp b/src/overlay.cpp index 79c7b46c..13608a56 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -797,8 +797,10 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) if (vendorID == 0x8086 || vendorID == 0x10de) { - bool nvSuccess = (checkNVML(pci_dev) && getNVMLInfo()); - + bool nvSuccess = false; +#ifdef HAVE_NVML + nvSuccess = checkNVML(pci_dev) && getNVMLInfo(); +#endif #ifdef HAVE_XNVCTRL if (!nvSuccess) nvSuccess = checkXNVCtrl();