Get deviceID

pull/197/head
FlightlessMango 4 years ago
parent beee2b08c7
commit a2cc14f738

@ -8,12 +8,12 @@
#include "loaders/loader_nvctrl.h"
#include "loaders/loader_x11.h"
#include "string_utils.h"
#include "overlay.h"
typedef std::unordered_map<std::string, std::string> string_map;
static std::unique_ptr<Display, std::function<void(Display*)>> display;
libnvctrl_loader nvctrl("libXNVCtrl.so.0");
struct nvctrlInfo nvctrl_info;
bool nvctrlSuccess = false;
@ -61,6 +61,17 @@ bool checkXNVCtrl()
local_x11->XCloseDisplay(dpy);
}
};
// get device id at init
int64_t pci_id;
char pci_device_id[16];
nvctrl.XNVCTRLQueryTargetAttribute64(display.get(),
NV_CTRL_TARGET_TYPE_GPU,
0,
0,
NV_CTRL_PCI_ID,
&pci_id);
snprintf(pci_device_id, 16, "0x%04x", (pci_id & 0xFFFF));
deviceID = strtol(pci_device_id, NULL, 16);
return true;
}

@ -1,11 +1,13 @@
#include "loaders/loader_nvml.h"
#include "nvidia_info.h"
#include <iostream>
#include "overlay.h"
libnvml_loader nvml("libnvidia-ml.so.1");
nvmlReturn_t result;
nvmlDevice_t nvidiaDevice;
nvmlPciInfo_t nvidiaPciInfo;
bool nvmlSuccess = false;
unsigned int nvidiaTemp, nvidiaCoreClock, nvidiaMemClock;
struct nvmlUtilization_st nvidiaUtilization;
@ -45,6 +47,9 @@ bool getNVMLInfo(){
nvml.nvmlDeviceGetMemoryInfo(nvidiaDevice, &nvidiaMemory);
nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_GRAPHICS, &nvidiaCoreClock);
nvml.nvmlDeviceGetClockInfo(nvidiaDevice, NVML_CLOCK_MEM, &nvidiaMemClock);
nvml.nvmlDeviceGetPciInfo_v3(nvidiaDevice, &nvidiaPciInfo);
deviceID = nvidiaPciInfo.pciDeviceId >> 16;
if (response == NVML_ERROR_NOT_SUPPORTED)
nvmlSuccess = false;
return nvmlSuccess;

@ -71,6 +71,7 @@ float offset_x, offset_y, hudSpacing;
int hudFirstRow, hudSecondRow;
struct amdGpu amdgpu;
struct fps_limit fps_limit_stats;
int32_t deviceID;
/* Mapped from VkInstace/VkPhysicalDevice */
struct instance_data {
@ -780,7 +781,8 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params)
#ifndef NDEBUG
std::cerr << "amdgpu path check: " << path << "/device/vendor" << std::endl;
#endif
string device = read_line(path + "/device/device");
deviceID = strtol(device.c_str(), NULL, 16);
string line = read_line(path + "/device/vendor");
trim(line);
if (line != "0x1002" || !file_exists(path + "/device/gpu_busy_percent"))

@ -47,6 +47,7 @@ struct fps_limit {
};
extern struct fps_limit fps_limit_stats;
extern int32_t deviceID;
void position_layer(struct overlay_params& params, ImVec2 window_size);
void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan);

Loading…
Cancel
Save