diff --git a/bin/MangoHud.conf b/bin/MangoHud.conf index b3a39d79..62c2998a 100644 --- a/bin/MangoHud.conf +++ b/bin/MangoHud.conf @@ -94,6 +94,10 @@ background_alpha=0.5 ### Show Spotify metadata # media_player +### Specify gpu with pci bus id for amdgpu and NVML stats. +### Set to 'domain:bus:slot.function' +# pci_dev = 0:0a:0.0 + ################## INTERACTION ################# ### Change toggle keybinds for the hud & logging diff --git a/src/overlay.cpp b/src/overlay.cpp index e8ecc649..91d0e1cc 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -721,17 +721,32 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) PCI_BUS pci; bool pci_bus_parsed = false; - const char* env_pci_dev = getenv("MANGOHUD_PCI_DEV"); + const char *pci_dev = nullptr; + if (!params.pci_dev.empty()) + pci_dev = params.pci_dev.c_str(); // for now just checks if pci bus parses correctly, if at all necessary - if (env_pci_dev) { - if (sscanf(env_pci_dev, "%04x:%02x:%02x.%x", + if (pci_dev) { + if (sscanf(pci_dev, "%04x:%02x:%02x.%x", &pci.domain, &pci.bus, &pci.slot, &pci.func) == 4) { pci_bus_parsed = true; + // reformat back to sysfs file name's and nvml's expected format + // so config file param's value format doesn't have to be as strict + std::stringstream ss; + ss << std::hex + << std::setw(4) << std::setfill('0') << pci.domain << ":" + << std::setw(2) << pci.bus << ":" + << std::setw(2) << pci.slot << "." + << std::setw(1) << pci.func; + params.pci_dev = ss.str(); + pci_dev = params.pci_dev.c_str(); +#ifndef NDEBUG + std::cerr << "MANGOHUD: PCI device ID: '" << pci_dev << "'\n"; +#endif } else { - std::cerr << "MANGOHUD: Failed to parse PCI device ID: " << env_pci_dev << "\n"; - std::cerr << "MANGOHUD: It has to be formatted as 'xxxx:xx:xx.x' (domain:bus:slot.func)\n"; + std::cerr << "MANGOHUD: Failed to parse PCI device ID: '" << pci_dev << "'\n"; + std::cerr << "MANGOHUD: Specify it as 'domain:bus:slot.func'\n"; } } @@ -739,7 +754,7 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) if (vendorID == 0x8086 || vendorID == 0x10de) { - bool nvSuccess = (checkNVML(env_pci_dev) && getNVMLInfo()); + bool nvSuccess = (checkNVML(pci_dev) && getNVMLInfo()); #ifdef HAVE_XNVCTRL if (!nvSuccess) @@ -771,12 +786,12 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) continue; path += "/device"; - if (pci_bus_parsed && env_pci_dev) { + if (pci_bus_parsed && pci_dev) { string pci_device = readlink(path.c_str()); #ifndef NDEBUG std::cerr << "PCI device symlink: " << pci_device << "\n"; #endif - if (!ends_with(pci_device, env_pci_dev)) { + if (!ends_with(pci_device, pci_dev)) { std::cerr << "MANGOHUD: skipping GPU, no PCI ID match\n"; continue; } diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index e90d9ef6..8e24c4e0 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -204,6 +204,7 @@ parse_path(const char *str) #define parse_font_file(s) parse_path(s) #define parse_io_read(s) parse_unsigned(s) #define parse_io_write(s) parse_unsigned(s) +#define parse_pci_dev(s) parse_str(s) #define parse_crosshair_color(s) parse_color(s) #define parse_cpu_color(s) parse_color(s) diff --git a/src/overlay_params.h b/src/overlay_params.h index 1952bded..431b06d8 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -99,6 +99,7 @@ typedef unsigned long KeySym; OVERLAY_PARAM_CUSTOM(text_color) \ OVERLAY_PARAM_CUSTOM(alpha) \ OVERLAY_PARAM_CUSTOM(log_duration) \ + OVERLAY_PARAM_CUSTOM(pci_dev) \ OVERLAY_PARAM_CUSTOM(help) enum overlay_param_position { @@ -147,6 +148,7 @@ struct overlay_params { KeySym toggle_logging; KeySym reload_cfg; std::string time_format, output_file, font_file; + std::string pci_dev; std::string config_file_path; std::unordered_map options;