diff --git a/src/cpu_gpu.h b/src/cpu_gpu.h index aab8f30..c1525d3 100644 --- a/src/cpu_gpu.h +++ b/src/cpu_gpu.h @@ -14,6 +14,8 @@ #include #include #include "nvidia_info.h" +#include "memory.h" +#include "nvctrl.h" using namespace std; @@ -74,6 +76,7 @@ void *getNvidiaGpuInfo(void *){ getNvidiaInfo(); gpuLoad = nvidiaUtilization.gpu; gpuTemp = nvidiaTemp; + gpuMemUsed = nvidiaMemUsed(); } pthread_detach(nvidiaSmiThread); diff --git a/src/meson.build b/src/meson.build index b9d690c..2b241b5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -40,8 +40,10 @@ vklayer_files = files( 'nvml.cpp', 'file_utils.cpp', 'memory.cpp', + 'nvctrl.cpp', ) +lib_xnvctrl = cc.find_library('XNVCtrl') vklayer_mesa_overlay = shared_library( 'MangoHud', util_files, @@ -64,7 +66,8 @@ vklayer_mesa_overlay = shared_library( vulkan_wsi_deps, libimgui_core_dep, dep_dl, - dep_pthread], + dep_pthread, + lib_xnvctrl], include_directories : inc_common, link_args : cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro']), install : true diff --git a/src/nvctrl.cpp b/src/nvctrl.cpp new file mode 100644 index 0000000..763f9df --- /dev/null +++ b/src/nvctrl.cpp @@ -0,0 +1,13 @@ +#include "nvctrl.h" +Display *display = XOpenDisplay(NULL); + +int nvidiaMemUsed(){ + int ret; + XNVCTRLQueryTargetAttribute(display, + NV_CTRL_TARGET_TYPE_GPU, + 0, + 0, + NV_CTRL_USED_DEDICATED_GPU_MEMORY, + &ret); + return ret; +} \ No newline at end of file diff --git a/src/nvctrl.h b/src/nvctrl.h new file mode 100644 index 0000000..718b9af --- /dev/null +++ b/src/nvctrl.h @@ -0,0 +1,5 @@ +#include +#include "NVCtrl/NVCtrl.h" +#include "NVCtrl/NVCtrlLib.h" + +int nvidiaMemUsed(void); \ No newline at end of file diff --git a/src/nvml.cpp b/src/nvml.cpp index 213a920..2b96719 100644 --- a/src/nvml.cpp +++ b/src/nvml.cpp @@ -29,5 +29,5 @@ void getNvidiaInfo(){ nvml.nvmlDeviceGetHandleByIndex(0, &nvidiaDevice); nvml.nvmlDeviceGetUtilizationRates(nvidiaDevice, &nvidiaUtilization); nvml.nvmlDeviceGetTemperature(nvidiaDevice, NVML_TEMPERATURE_GPU, &nvidiaTemp); - nvml.nvmlDeviceGetMemoryInfo(nvidiaDevice, &nvidiaMemory); + // nvml.nvmlDeviceGetMemoryInfo(nvidiaDevice, &nvidiaMemory); } \ No newline at end of file