Merge pull request #703 from evelikov/misc-mixes

Remove libdrm_amdgpu and other unnecessary code
pull/710/head
jackun 2 years ago committed by GitHub
commit 11142b5b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -24,7 +24,3 @@ indent_size = 3
[meson.build]
indent_size = 2
[Makefile]
indent_style = tab
indent_size = 4

@ -49,7 +49,6 @@ Install necessary development packages.
- vulkan headers if using `-Duse_system_vulkan=enabled` option with `meson`
- libGL/libEGL (libglvnd, mesa-common-dev, mesa-libGL-devel etc)
- X11 (libx11-dev)
- libdrm (libdrm-dev)
- XNVCtrl (libxnvctrl-dev), optional, use `-Dwith_xnvctrl=disabled` option with `meson` to disable
- D-Bus (libdbus-1-dev), optional, use `-Dwith_dbus=disabled` option with `meson` to disable
@ -353,7 +352,6 @@ Parameters that are enabled by default have to be explicitly disabled. These (cu
| `battery` | Display current battery percent and energy consumption |
| `battery_icon` | Display battery icon instead of percent |
| `battery_color` | Change the BATT text color |
| `force_amdgpu_hwmon` | Use hwmon sysfs instead of libdrm for amdgpu stats |
| `fps_only` | Show FPS without the engine name e.g. DXVK/VULAKAN etc. |
| `gamepad_battery` | Display battey of wireless gamepads (xone,xpadneo,ds4) |
| `gamepad_battery_icon` | Display gamepad battery percent with icon. *enabled by default |

@ -28,7 +28,7 @@ dependencies() {
}
echo "# Checking Dependencies"
DEPS=(${LOCAL_CC}-multilib ${LOCAL_CXX}-multilib unzip libdrm-dev)
DEPS=(${LOCAL_CC}-multilib ${LOCAL_CXX}-multilib unzip)
install

@ -100,7 +100,7 @@ dependencies() {
MANAGER_QUERY="rpm -q"
MANAGER_INSTALL="zypper install"
DEPS="{gcc-c++,gcc-c++-32bit,libpkgconf-devel,ninja,python3-pip,python3-Mako,libX11-devel,glslang-devel,glibc-devel,glibc-devel-32bit,libstdc++-devel,libstdc++-devel-32bit,Mesa-libGL-devel,dbus-1-devel,libdrm-devel,${PACKMAN_PKGS}}"
DEPS="{gcc-c++,gcc-c++-32bit,libpkgconf-devel,ninja,python3-pip,python3-Mako,libX11-devel,glslang-devel,glibc-devel,glibc-devel-32bit,libstdc++-devel,libstdc++-devel-32bit,Mesa-libGL-devel,dbus-1-devel,${PACKMAN_PKGS}}"
dep_install
if [[ $(pip3 show meson; echo $?) == 1 ]]; then

@ -88,14 +88,10 @@ if is_unixy
dep_wayland_client = dependency('wayland-client',
required: get_option('with_wayland'), version : '>=1.11')
dbus_dep = dependency('dbus-1', required: get_option('with_dbus')).partial_dependency(compile_args : true, includes : true)
dep_libdrm = dependency('libdrm', required: get_option('with_libdrm_amdgpu')).partial_dependency(compile_args : true, includes : true)
# dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>=2.4.79', required: get_option('with_libdrm_amdgpu')).partial_dependency(compile_args : true, includes : true)
else
dep_x11 = null_dep
dep_wayland_client = null_dep
dbus_dep = null_dep
dep_libdrm = null_dep
# dep_libdrm_amdgpu = null_dep
endif
if dep_x11.found()

@ -13,7 +13,6 @@ option('with_x11', type : 'feature', value : 'enabled')
option('with_wayland', type : 'feature', value : 'disabled')
option('with_dbus', type : 'feature', value : 'enabled')
option('with_dlsym', type : 'feature', value : 'disabled')
option('with_libdrm_amdgpu', type : 'feature', value : 'enabled', description: 'Get amdgpu sensor info through libdrm_amdgpu')
option('loglevel', type: 'combo', choices : ['trace', 'debug', 'info', 'warn', 'err', 'critical', 'off'], value : 'info', description: 'Max log level in non-debug build')
option('mangoapp', type: 'boolean', value : 'false')
option('mangohudctl', type: 'boolean', value : 'false')

@ -43,4 +43,4 @@ void amdgpu_get_metrics()
gpu_info.apu_cpu_temp = cpu_temp / 100;
}
}
}
}

@ -1,56 +0,0 @@
/*
Inspired by radeontop
*/
#include "auth.h"
#include <xcb/xcb.h>
#include <xcb/dri2.h>
#include <xf86drm.h>
#include <libdrm/amdgpu_drm.h>
#include <libdrm/amdgpu.h>
#include <cstdlib>
#include <cstdio>
/* Try to authenticate the DRM client with help from the X server. */
bool authenticate_drm_xcb(drm_magic_t magic) {
xcb_connection_t *conn = xcb_connect(NULL, NULL);
if (!conn) {
return false;
}
if (xcb_connection_has_error(conn)) {
xcb_disconnect(conn);
return false;
}
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
xcb_window_t window = screen->root;
/* Authenticate our client via the X server using the magic. */
xcb_dri2_authenticate_cookie_t auth_cookie =
xcb_dri2_authenticate(conn, window, magic);
xcb_dri2_authenticate_reply_t *auth_reply =
xcb_dri2_authenticate_reply(conn, auth_cookie, NULL);
free(auth_reply);
xcb_disconnect(conn);
return true;
}
bool authenticate_drm(int fd) {
drm_magic_t magic;
/* Obtain magic for our DRM client. */
if (drmGetMagic(fd, &magic) < 0) {
return false;
}
/* Try self-authenticate (if we are somehow the master). */
if (drmAuthMagic(fd, magic) == 0) {
if (drmDropMaster(fd)) {
perror("MANGOHUD: Failed to drop DRM master");
fprintf(stderr, "\n\tWARNING: other DRM clients will crash on VT switch\n");
}
return true;
}
return authenticate_drm_xcb(magic);
}

@ -1,5 +0,0 @@
#pragma once
#include <libdrm/drm.h>
bool authenticate_drm_xcb(drm_magic_t magic);
bool authenticate_drm(int fd);

@ -33,34 +33,6 @@ std::string get_basename(const std::string&& path)
}
#ifdef __linux__
bool find_folder(const char* root, const char* prefix, std::string& dest)
{
struct dirent* dp;
DIR* dirp = opendir(root);
if (!dirp) {
SPDLOG_ERROR("Error opening directory '{}': {}", root, strerror(errno));
return false;
}
// XXX xfs/jfs need stat() for inode type
while ((dp = readdir(dirp))) {
if ((dp->d_type == DT_LNK || dp->d_type == DT_DIR) && starts_with(dp->d_name, prefix)) {
dest = dp->d_name;
closedir(dirp);
return true;
}
}
closedir(dirp);
return false;
}
bool find_folder(const std::string& root, const std::string& prefix, std::string& dest)
{
return find_folder(root.c_str(), prefix.c_str(), dest);
}
std::vector<std::string> ls(const char* root, const char* prefix, LS_FLAGS flags)
{
std::vector<std::string> list;
@ -78,7 +50,8 @@ std::vector<std::string> ls(const char* root, const char* prefix, LS_FLAGS flags
|| !strcmp(dp->d_name, ".."))
continue;
if (dp->d_type == DT_LNK) {
switch (dp->d_type) {
case DT_LNK: {
struct stat s;
std::string path(root);
if (path.back() != '/')
@ -89,13 +62,19 @@ std::vector<std::string> ls(const char* root, const char* prefix, LS_FLAGS flags
continue;
if (((flags & LS_DIRS) && S_ISDIR(s.st_mode))
|| ((flags & LS_FILES) && !S_ISDIR(s.st_mode))) {
|| ((flags & LS_FILES) && S_ISREG(s.st_mode))) {
list.push_back(dp->d_name);
}
} else if (((flags & LS_DIRS) && dp->d_type == DT_DIR)
|| ((flags & LS_FILES) && dp->d_type == DT_REG)
) {
list.push_back(dp->d_name);
break;
}
case DT_DIR:
if (flags & LS_DIRS)
list.push_back(dp->d_name);
break;
case DT_REG:
if (flags & LS_FILES)
list.push_back(dp->d_name);
break;
}
}

@ -7,14 +7,11 @@
enum LS_FLAGS
{
LS_ALL = 0x00,
LS_DIRS = 0x01,
LS_FILES = 0x02,
};
std::string read_line(const std::string& filename);
bool find_folder(const char* root, const char* prefix, std::string& dest);
bool find_folder(const std::string& root, const std::string& prefix, std::string& dest);
std::vector<std::string> ls(const char* root, const char* prefix = nullptr, LS_FLAGS flags = LS_DIRS);
bool file_exists(const std::string& path);
bool dir_exists(const std::string& path);

@ -3,16 +3,6 @@
#include <fstream>
#include <string>
bool find_folder(const char* root, const char* prefix, std::string& dest)
{
return false;
}
bool find_folder(const std::string& root, const std::string& prefix, std::string& dest)
{
return find_folder(root.c_str(), prefix.c_str(), dest);
}
std::vector<std::string> ls(const char* root, const char* prefix, LS_FLAGS flags)
{
std::vector<std::string> list;

@ -11,15 +11,6 @@
#include "nvidia_info.h"
#endif
#ifdef HAVE_LIBDRM_AMDGPU
//#include "auth.h"
#include <xf86drm.h>
#include <libdrm/amdgpu_drm.h>
#include <libdrm/amdgpu.h>
#include <unistd.h>
#include <fcntl.h>
#include "loaders/loader_libdrm.h"
#endif
#include "amdgpu.h"
using namespace std::chrono_literals;
@ -141,176 +132,3 @@ void getAmdGpuInfo(){
gpu_info.memoryUsed = float(value) / (1024 * 1024 * 1024);
}
}
#ifdef HAVE_LIBDRM_AMDGPU
#define DRM_ATLEAST_VERSION(ver, maj, min) \
(ver->version_major > maj || (ver->version_major == maj && ver->version_minor >= min))
enum {
GRBM_STATUS = 0x8010,
};
static std::unique_ptr<libdrm_amdgpu_loader> libdrm_amdgpu_ptr;
static int getgrbm_amdgpu(amdgpu_device_handle dev, uint32_t *out) {
return libdrm_amdgpu_ptr->amdgpu_read_mm_registers(dev, GRBM_STATUS / 4, 1,
0xffffffff, 0, out);
}
struct amdgpu_handles
{
amdgpu_device_handle dev;
int fd;
uint32_t version_major, version_minor, gui_percent {0};
uint32_t ticks = 60, ticks_per_sec = 120;
std::chrono::nanoseconds sleep_interval {};
bool quit = false;
std::thread collector;
amdgpu_handles(amdgpu_device_handle dev_, int fd_, uint32_t major, uint32_t minor)
: dev(dev_)
, fd(fd_)
, version_major(major)
, version_minor(minor)
{
set_sampling_period(500000000 /* 500ms */);
collector = std::thread(&amdgpu_handles::amdgpu_poll, this);
}
~amdgpu_handles()
{
quit = true;
if (collector.joinable())
collector.join();
libdrm_amdgpu_ptr->amdgpu_device_deinitialize(dev);
close(fd);
}
void set_sampling_period(uint32_t period)
{
if (period < 10000000)
period = 10000000; /* 10ms */
ticks = ticks_per_sec * std::chrono::nanoseconds(period) / 1s;
sleep_interval = std::chrono::nanoseconds(period) / ticks;
SPDLOG_DEBUG("ticks: {}, {}ns", ticks, sleep_interval.count());
}
void amdgpu_poll()
{
uint32_t stat = 0, gui = 0, curr = 0;
while (!quit)
{
getgrbm_amdgpu(dev, &stat);
if (stat & (1U << 31)) // gui
gui++;
std::this_thread::sleep_for(sleep_interval);
curr++;
curr %= ticks;
if (!curr)
{
gui_percent = gui * 100 / ticks;
gui = 0;
}
}
}
};
typedef std::unique_ptr<amdgpu_handles> amdgpu_ptr;
static amdgpu_ptr amdgpu_dev;
void amdgpu_set_sampling_period(uint32_t period)
{
if (amdgpu_dev)
amdgpu_dev->set_sampling_period(period);
}
bool amdgpu_open(const char *path) {
if (!g_libdrm.IsLoaded())
return false;
if (!libdrm_amdgpu_ptr)
libdrm_amdgpu_ptr = std::make_unique<libdrm_amdgpu_loader>();
if (!libdrm_amdgpu_ptr->IsLoaded())
return false;
int fd = open(path, O_RDWR | O_CLOEXEC);
if (fd < 0) {
SPDLOG_ERROR("Failed to open DRM device: {}", strerror(errno));
return false;
}
drmVersionPtr ver = g_libdrm.drmGetVersion(fd);
if (!ver) {
SPDLOG_ERROR("Failed to query driver version: {}", strerror(errno));
close(fd);
return false;
}
if (strcmp(ver->name, "amdgpu") || !DRM_ATLEAST_VERSION(ver, 3, 11)) {
SPDLOG_ERROR("Unsupported driver/version: {} {}.{}.{}", ver->name, ver->version_major, ver->version_minor, ver->version_patchlevel);
close(fd);
g_libdrm.drmFreeVersion(ver);
return false;
}
g_libdrm.drmFreeVersion(ver);
/*
if (!authenticate_drm(fd)) {
close(fd);
return false;
}
*/
uint32_t drm_major, drm_minor;
amdgpu_device_handle dev;
if (libdrm_amdgpu_ptr->amdgpu_device_initialize(fd, &drm_major, &drm_minor, &dev)){
SPDLOG_ERROR("Failed to initialize amdgpu device: {}", strerror(errno));
close(fd);
return false;
}
amdgpu_dev = std::make_unique<amdgpu_handles>(dev, fd, drm_major, drm_minor);
return true;
}
void getAmdGpuInfo_libdrm()
{
uint64_t value = 0;
uint32_t value32 = 0;
if (!amdgpu_dev || !DRM_ATLEAST_VERSION(amdgpu_dev, 3, 11))
{
getAmdGpuInfo();
getAmdGpuInfo_actual = getAmdGpuInfo;
return;
}
if (!libdrm_amdgpu_ptr->amdgpu_query_info(amdgpu_dev->dev, AMDGPU_INFO_VRAM_USAGE, sizeof(uint64_t), &value))
gpu_info.memoryUsed = float(value) / (1024 * 1024 * 1024);
// FIXME probably not correct sensor
if (!libdrm_amdgpu_ptr->amdgpu_query_info(amdgpu_dev->dev, AMDGPU_INFO_MEMORY, sizeof(uint64_t), &value))
gpu_info.memoryTotal = float(value) / (1024 * 1024 * 1024);
if (!libdrm_amdgpu_ptr->amdgpu_query_sensor_info(amdgpu_dev->dev, AMDGPU_INFO_SENSOR_GFX_SCLK, sizeof(uint32_t), &value32))
gpu_info.CoreClock = value32;
if (!libdrm_amdgpu_ptr->amdgpu_query_sensor_info(amdgpu_dev->dev, AMDGPU_INFO_SENSOR_GFX_MCLK, sizeof(uint32_t), &value32)) // XXX Doesn't work on APUs
gpu_info.MemClock = value32;
//if (!libdrm_amdgpu_ptr->amdgpu_query_sensor_info(amdgpu_dev->dev, AMDGPU_INFO_SENSOR_GPU_LOAD, sizeof(uint32_t), &value32))
// gpu_info.load = value32;
gpu_info.load = amdgpu_dev->gui_percent;
if (!libdrm_amdgpu_ptr->amdgpu_query_sensor_info(amdgpu_dev->dev, AMDGPU_INFO_SENSOR_GPU_TEMP, sizeof(uint32_t), &value32))
gpu_info.temp = value32 / 1000;
if (!libdrm_amdgpu_ptr->amdgpu_query_sensor_info(amdgpu_dev->dev, AMDGPU_INFO_SENSOR_GPU_AVG_POWER, sizeof(uint32_t), &value32))
gpu_info.powerUsage = value32;
}
#endif

@ -7,10 +7,11 @@
struct amdgpu_files
{
FILE *busy;
FILE *temp;
FILE *vram_total;
FILE *vram_used;
/* The following can be NULL, in that case we're using the gpu_metrics node */
FILE *busy;
FILE *temp;
FILE *core_clock;
FILE *memory_clock;
FILE *power_usage;
@ -34,11 +35,6 @@ extern struct gpuInfo gpu_info;
void getNvidiaGpuInfo(void);
void getAmdGpuInfo(void);
#ifdef HAVE_LIBDRM_AMDGPU
void getAmdGpuInfo_libdrm();
bool amdgpu_open(const char *path);
void amdgpu_set_sampling_period(uint32_t period);
#endif
extern decltype(&getAmdGpuInfo) getAmdGpuInfo_actual;
bool checkNvidia(const char *pci_dev);
extern void nvapi_util();

@ -5,7 +5,6 @@
void check_keybinds(struct overlay_params& params, uint32_t vendorID){
using namespace std::chrono_literals;
bool pressed = false; // FIXME just a placeholder until wayland support
auto now = Clock::now(); /* us */
auto elapsedF2 = now - last_f2_press;
auto elapsedFpsLimitToggle = now - toggle_fps_limit_press;
@ -20,95 +19,59 @@ void check_keybinds(struct overlay_params& params, uint32_t vendorID){
auto keyPressDelay = 400ms;
if (elapsedF2 >= keyPressDelay){
#if defined(HAVE_X11) || defined(_WIN32)
pressed = keys_are_pressed(params.toggle_logging);
#else
pressed = false;
#endif
if (pressed) {
last_f2_press = now;
if (logger->is_active()) {
if (elapsedF2 >= keyPressDelay &&
keys_are_pressed(params.toggle_logging)) {
last_f2_press = now;
if (logger->is_active()) {
logger->stop_logging();
} else {
} else {
logger->start_logging();
std::thread(update_hw_info, std::ref(params), vendorID)
.detach();
std::thread(update_hw_info, std::ref(params), vendorID).detach();
benchmark.fps_data.clear();
}
}
}
}
if (elapsedFpsLimitToggle >= keyPressDelay){
#if defined(HAVE_X11) || defined(_WIN32)
pressed = keys_are_pressed(params.toggle_fps_limit);
#else
pressed = false;
#endif
if (pressed){
toggle_fps_limit_press = now;
for (size_t i = 0; i < params.fps_limit.size(); i++){
uint32_t fps_limit = params.fps_limit[i];
// current fps limit equals vector entry, use next / first
if((fps_limit > 0 && fps_limit_stats.targetFrameTime == std::chrono::duration_cast<Clock::duration>(std::chrono::duration<double>(1) / params.fps_limit[i]))
|| (fps_limit == 0 && fps_limit_stats.targetFrameTime == fps_limit_stats.targetFrameTime.zero())) {
uint32_t newFpsLimit = i+1 == params.fps_limit.size() ? params.fps_limit[0] : params.fps_limit[i+1];
if(newFpsLimit > 0) {
fps_limit_stats.targetFrameTime = std::chrono::duration_cast<Clock::duration>(std::chrono::duration<double>(1) / newFpsLimit);
} else {
fps_limit_stats.targetFrameTime = {};
}
break;
if (elapsedFpsLimitToggle >= keyPressDelay &&
keys_are_pressed(params.toggle_fps_limit)) {
toggle_fps_limit_press = now;
for (size_t i = 0; i < params.fps_limit.size(); i++){
uint32_t fps_limit = params.fps_limit[i];
// current fps limit equals vector entry, use next / first
if((fps_limit > 0 && fps_limit_stats.targetFrameTime == std::chrono::duration_cast<Clock::duration>(std::chrono::duration<double>(1) / params.fps_limit[i]))
|| (fps_limit == 0 && fps_limit_stats.targetFrameTime == fps_limit_stats.targetFrameTime.zero())) {
uint32_t newFpsLimit = i+1 == params.fps_limit.size() ? params.fps_limit[0] : params.fps_limit[i+1];
if(newFpsLimit > 0) {
fps_limit_stats.targetFrameTime = std::chrono::duration_cast<Clock::duration>(std::chrono::duration<double>(1) / newFpsLimit);
} else {
fps_limit_stats.targetFrameTime = {};
}
break;
}
}
}
if (elapsedF12 >= keyPressDelay){
#if defined(HAVE_X11) || defined(_WIN32)
pressed = keys_are_pressed(params.toggle_hud);
#else
pressed = false;
#endif
if (pressed){
last_f12_press = now;
params.no_display = !params.no_display;
}
if (elapsedF12 >= keyPressDelay &&
keys_are_pressed(params.toggle_hud)) {
last_f12_press = now;
params.no_display = !params.no_display;
}
if (elapsedReloadCfg >= keyPressDelay){
#if defined(HAVE_X11) || defined(_WIN32)
pressed = keys_are_pressed(params.reload_cfg);
#else
pressed = false;
#endif
if (pressed){
parse_overlay_config(&params, getenv("MANGOHUD_CONFIG"));
_params = &params;
reload_cfg_press = now;
}
if (elapsedReloadCfg >= keyPressDelay &&
keys_are_pressed(params.reload_cfg)) {
parse_overlay_config(&params, getenv("MANGOHUD_CONFIG"));
_params = &params;
reload_cfg_press = now;
}
if (params.permit_upload && elapsedUpload >= keyPressDelay){
#if defined(HAVE_X11) || defined(_WIN32)
pressed = keys_are_pressed(params.upload_log);
#else
pressed = false;
#endif
if (pressed){
last_upload_press = now;
logger->upload_last_log();
}
if (params.permit_upload && elapsedUpload >= keyPressDelay &&
keys_are_pressed(params.upload_log)) {
last_upload_press = now;
logger->upload_last_log();
}
if (params.permit_upload && elapsedUpload >= keyPressDelay){
#if defined(HAVE_X11) || defined(_WIN32)
pressed = keys_are_pressed(params.upload_logs);
#else
pressed = false;
#endif
if (pressed){
last_upload_press = now;
logger->upload_last_logs();
}
if (params.permit_upload && elapsedUpload >= keyPressDelay &&
keys_are_pressed(params.upload_logs)) {
last_upload_press = now;
logger->upload_last_logs();
}
}

@ -13,7 +13,7 @@ typedef unsigned long KeySym;
Clock::time_point last_f2_press, toggle_fps_limit_press , last_f12_press, reload_cfg_press, last_upload_press;
#ifdef HAVE_X11
#if defined(HAVE_X11)
bool keys_are_pressed(const std::vector<KeySym>& keys) {
if (!init_x11())
@ -39,9 +39,7 @@ bool keys_are_pressed(const std::vector<KeySym>& keys) {
return false;
}
#endif //HAVE_X11
#ifdef _WIN32
#elif defined(_WIN32)
#include <windows.h>
bool keys_are_pressed(const std::vector<KeySym>& keys) {
size_t pressed = 0;
@ -57,6 +55,10 @@ bool keys_are_pressed(const std::vector<KeySym>& keys) {
return false;
}
#else // XXX: Add wayland support
bool keys_are_pressed(const std::vector<KeySym>& keys) {
return false;
}
#endif
#endif //MANGOHUD_KEYBINDS_H

@ -1,177 +0,0 @@
#include "loaders/loader_libdrm.h"
#include <iostream>
#include <spdlog/spdlog.h>
// Put these sanity checks here so that they fire at most once
// (to avoid cluttering the build output).
#if !defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) && !defined(LIBRARY_LOADER_LIBDRM_H_DT_NEEDED)
#error neither LIBRARY_LOADER_LIBDRM_H_DLOPEN nor LIBRARY_LOADER_LIBDRM_H_DT_NEEDED defined
#endif
#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) && defined(LIBRARY_LOADER_LIBDRM_H_DT_NEEDED)
#error both LIBRARY_LOADER_LIBDRM_H_DLOPEN and LIBRARY_LOADER_LIBDRM_H_DT_NEEDED defined
#endif
libdrm_loader::libdrm_loader() : loaded_(false) {
Load();
}
libdrm_loader::~libdrm_loader() {
CleanUp(loaded_);
}
bool libdrm_loader::Load() {
if (loaded_) {
return true;
}
#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN)
library = dlopen("libdrm.so.2", RTLD_LAZY);
if (!library) {
SPDLOG_ERROR("Failed to open " MANGOHUD_ARCH " libdrm.so.2: {}", dlerror());
return false;
}
drmGetVersion =
reinterpret_cast<decltype(this->drmGetVersion)>(
dlsym(library, "drmGetVersion"));
if (!drmGetVersion) {
CleanUp(true);
return false;
}
drmFreeVersion =
reinterpret_cast<decltype(this->drmFreeVersion)>(
dlsym(library, "drmFreeVersion"));
if (!drmFreeVersion) {
CleanUp(true);
return false;
}
drmCommandWriteRead =
reinterpret_cast<decltype(this->drmCommandWriteRead)>(
dlsym(library, "drmCommandWriteRead"));
if (!drmCommandWriteRead) {
CleanUp(true);
return false;
}
#endif
#if defined(LIBRARY_LOADER_LIBDRM_H_DT_NEEDED)
drmGetVersion = &::drmGetVersion;
drmFreeVersion = &::drmFreeVersion;
drmCommandWriteRead = &::drmCommandWriteRead;
#endif
loaded_ = true;
return true;
}
void libdrm_loader::CleanUp(bool unload) {
#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN)
if (unload) {
dlclose(library);
library = nullptr;
}
#endif
loaded_ = false;
drmGetVersion = nullptr;
drmFreeVersion = nullptr;
drmCommandWriteRead = nullptr;
}
libdrm_amdgpu_loader::libdrm_amdgpu_loader() : loaded_(false) {
Load();
}
libdrm_amdgpu_loader::~libdrm_amdgpu_loader() {
CleanUp(loaded_);
}
bool libdrm_amdgpu_loader::Load() {
if (loaded_) {
return true;
}
#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN)
library = dlopen("libdrm_amdgpu.so.1", RTLD_LAZY);
if (!library) {
SPDLOG_ERROR("Failed to open " MANGOHUD_ARCH " libdrm_amdgpu.so.1: {}", dlerror());
CleanUp(true);
return false;
}
amdgpu_device_initialize =
reinterpret_cast<decltype(this->amdgpu_device_initialize)>(
dlsym(library, "amdgpu_device_initialize"));
if (!amdgpu_device_initialize) {
CleanUp(true);
return false;
}
amdgpu_device_deinitialize =
reinterpret_cast<decltype(this->amdgpu_device_deinitialize)>(
dlsym(library, "amdgpu_device_deinitialize"));
if (!amdgpu_device_deinitialize) {
CleanUp(true);
return false;
}
amdgpu_query_info =
reinterpret_cast<decltype(this->amdgpu_query_info)>(
dlsym(library, "amdgpu_query_info"));
if (!amdgpu_query_info) {
CleanUp(true);
return false;
}
amdgpu_query_sensor_info =
reinterpret_cast<decltype(this->amdgpu_query_sensor_info)>(
dlsym(library, "amdgpu_query_sensor_info"));
if (!amdgpu_query_sensor_info) {
CleanUp(true);
return false;
}
amdgpu_read_mm_registers =
reinterpret_cast<decltype(this->amdgpu_read_mm_registers)>(
dlsym(library, "amdgpu_read_mm_registers"));
if (!amdgpu_read_mm_registers) {
CleanUp(true);
return false;
}
#endif
#if defined(LIBRARY_LOADER_LIBDRM_H_DT_NEEDED)
amdgpu_device_initialize = &::amdgpu_device_initialize;
amdgpu_device_deinitialize = &::amdgpu_device_deinitialize;
amdgpu_query_info = &::amdgpu_query_info;
amdgpu_query_sensor_info = &::amdgpu_query_sensor_info;
amdgpu_read_mm_registers = &::amdgpu_read_mm_registers;
#endif
loaded_ = true;
return true;
}
void libdrm_amdgpu_loader::CleanUp(bool unload) {
#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN)
if (unload) {
dlclose(library);
library = nullptr;
}
#endif
loaded_ = false;
amdgpu_device_initialize = nullptr;
amdgpu_device_deinitialize = nullptr;
amdgpu_query_info = nullptr;
amdgpu_query_sensor_info = nullptr;
amdgpu_read_mm_registers = nullptr;
}
libdrm_loader g_libdrm;

@ -1,82 +0,0 @@
#ifndef LIBRARY_LOADER_LIBDRM_H
#define LIBRARY_LOADER_LIBDRM_H
#define LIBRARY_LOADER_LIBDRM_H_DLOPEN
#include <dlfcn.h>
#include <xf86drm.h>
//#include <libdrm/amdgpu_drm.h>
//#include <libdrm/amdgpu.h>
typedef struct amdgpu_device *amdgpu_device_handle;
int amdgpu_device_initialize(int fd,
uint32_t *major_version,
uint32_t *minor_version,
amdgpu_device_handle *device_handle);
int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
unsigned size, void *value);
int amdgpu_query_sensor_info(amdgpu_device_handle dev, unsigned sensor_type,
unsigned size, void *value);
int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset,
unsigned count, uint32_t instance, uint32_t flags,
uint32_t *values);
class libdrm_loader {
public:
libdrm_loader();
~libdrm_loader();
bool Load();
bool IsLoaded() { return loaded_; }
decltype(&::drmGetVersion) drmGetVersion;
decltype(&::drmFreeVersion) drmFreeVersion;
decltype(&::drmCommandWriteRead) drmCommandWriteRead;
private:
void CleanUp(bool unload);
#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN)
void* library;
#endif
bool loaded_;
// Disallow copy constructor and assignment operator.
libdrm_loader(const libdrm_loader&);
void operator=(const libdrm_loader&);
};
class libdrm_amdgpu_loader {
public:
libdrm_amdgpu_loader();
~libdrm_amdgpu_loader();
bool Load();
bool IsLoaded() { return loaded_; }
decltype(&::amdgpu_device_initialize) amdgpu_device_initialize;
decltype(&::amdgpu_device_deinitialize) amdgpu_device_deinitialize;
decltype(&::amdgpu_query_info) amdgpu_query_info;
decltype(&::amdgpu_query_sensor_info) amdgpu_query_sensor_info;
decltype(&::amdgpu_read_mm_registers) amdgpu_read_mm_registers;
private:
void CleanUp(bool unload);
#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN)
void* library;
#endif
bool loaded_;
// Disallow copy constructor and assignment operator.
libdrm_amdgpu_loader(const libdrm_amdgpu_loader&);
void operator=(const libdrm_amdgpu_loader&);
};
extern libdrm_loader g_libdrm;
#endif // LIBRARY_LOADER_LIBDRM_H

@ -152,16 +152,6 @@ if is_unixy
'loaders/loader_dbus.cpp',
)
endif
# if get_option('with_libdrm_amdgpu').enabled() and dep_libdrm.found() and dep_libdrm_amdgpu.found()
if get_option('with_libdrm_amdgpu').enabled() and dep_libdrm.found()
pre_args += '-DHAVE_LIBDRM_AMDGPU'
#if dep_xcb.found() and dep_xcb_dri2.found()
vklayer_files += files(
'loaders/loader_libdrm.cpp',
)
#endif
endif
endif
link_args = cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro', '-Wl,--exclude-libs,ALL', '-lGL'])
@ -190,8 +180,6 @@ vklayer_mesa_overlay = shared_library(
vulkan_wsi_deps,
dearimgui_dep,
spdlog_dep,
dep_libdrm,
#dep_libdrm_amdgpu,
dbus_dep,
dep_dl,
dep_rt,
@ -255,7 +243,6 @@ if get_option('mangoapp') and sizeof_ptr == 8
dep_dl,
spdlog_dep,
dbus_dep,
dep_libdrm,
dep_x11,
glfw3_dep,
],

@ -587,7 +587,6 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para
string path;
string drm = "/sys/class/drm/";
getAmdGpuInfo_actual = getAmdGpuInfo;
bool using_libdrm = false;
auto dirs = ls(drm.c_str(), "card");
for (auto& dir : dirs) {
@ -619,9 +618,6 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para
fclose(fp);
}
if (!file_exists(path + "/device/gpu_busy_percent"))
continue;
if (pci_bus_parsed && pci_dev) {
string pci_device = read_symlink((path + "/device").c_str());
SPDLOG_DEBUG("PCI device symlink: '{}'", pci_device);
@ -639,57 +635,38 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para
metrics_path = gpu_metrics_path;
SPDLOG_DEBUG("Using gpu_metrics");
}
#ifdef HAVE_LIBDRM_AMDGPU
else {
int idx = -1;
//TODO make neater
int res = sscanf(path.c_str(), "/sys/class/drm/card%d", &idx);
std::string dri_path = "/dev/dri/card" + std::to_string(idx);
if (!params.enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon] && res == 1 && amdgpu_open(dri_path.c_str())) {
vendorID = 0x1002;
using_libdrm = true;
getAmdGpuInfo_actual = getAmdGpuInfo_libdrm;
amdgpu_set_sampling_period(params.fps_sampling_period);
SPDLOG_DEBUG("Using libdrm");
// fall through and open sysfs handles for fallback or check DRM version beforehand
} else if (!params.enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon]) {
SPDLOG_ERROR("Failed to open device '/dev/dri/card{}' with libdrm, falling back to using hwmon sysfs.", idx);
} else if (params.enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon]) {
SPDLOG_DEBUG("Using amdgpu hwmon");
}
}
#endif
path += "/device";
if (!amdgpu.busy)
amdgpu.busy = fopen((path + "/gpu_busy_percent").c_str(), "r");
if (!amdgpu.vram_total)
amdgpu.vram_total = fopen((path + "/mem_info_vram_total").c_str(), "r");
if (!amdgpu.vram_used)
amdgpu.vram_used = fopen((path + "/mem_info_vram_used").c_str(), "r");
if (!metrics_path.empty())
break;
// The card output nodes - cardX-output, will point to the card node
// As such the actual metrics nodes will be missing.
amdgpu.busy = fopen((path + "/gpu_busy_percent").c_str(), "r");
if (!amdgpu.busy)
continue;
path += "/hwmon/";
string tempFolder;
if (find_folder(path, "hwmon", tempFolder)) {
auto dirs = ls(path.c_str(), "hwmon", LS_DIRS);
for (auto& dir : dirs) {
if (!amdgpu.core_clock)
amdgpu.core_clock = fopen((path + tempFolder + "/freq1_input").c_str(), "r");
amdgpu.core_clock = fopen((path + dir + "/freq1_input").c_str(), "r");
if (!amdgpu.memory_clock)
amdgpu.memory_clock = fopen((path + tempFolder + "/freq2_input").c_str(), "r");
amdgpu.memory_clock = fopen((path + dir + "/freq2_input").c_str(), "r");
if (!amdgpu.temp)
amdgpu.temp = fopen((path + tempFolder + "/temp1_input").c_str(), "r");
amdgpu.temp = fopen((path + dir + "/temp1_input").c_str(), "r");
if (!amdgpu.power_usage)
amdgpu.power_usage = fopen((path + tempFolder + "/power1_average").c_str(), "r");
vendorID = 0x1002;
break;
amdgpu.power_usage = fopen((path + dir + "/power1_average").c_str(), "r");
}
break;
}
// don't bother then
if (!using_libdrm && !amdgpu.busy && !amdgpu.temp && !amdgpu.vram_total && !amdgpu.vram_used) {
if (metrics_path.empty() && !amdgpu.busy) {
params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = false;
}
}
@ -704,13 +681,13 @@ void init_system_info(){
if (ld_preload)
unsetenv("LD_PRELOAD");
ram = exec("cat /proc/meminfo | grep 'MemTotal' | awk '{print $2}'");
ram = exec("sed -n 's/^MemTotal: *\\([0-9]*\\).*/\\1/p' /proc/meminfo");
trim(ram);
cpu = exec("cat /proc/cpuinfo | grep 'model name' | tail -n1 | sed 's/^.*: //' | sed 's/([^)]*)/()/g' | tr -d '(/)'");
cpu = exec("sed -n 's/^model name.*: \\(.*\\)/\\1/p' /proc/cpuinfo | sed 's/([^)]*)//g' | tail -n1");
trim(cpu);
kernel = exec("uname -r");
trim(kernel);
os = exec("cat /etc/*-release | grep 'PRETTY_NAME' | cut -d '=' -f 2-");
os = exec("sed -n 's/PRETTY_NAME=\\(.*\\)/\\1/p' /etc/*-release");
os.erase(remove(os.begin(), os.end(), '\"' ), os.end());
trim(os);
cpusched = read_line("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor");
@ -718,7 +695,7 @@ void init_system_info(){
const char* mangohud_recursion = getenv("MANGOHUD_RECURSION");
if (!mangohud_recursion) {
setenv("MANGOHUD_RECURSION", "1", 1);
driver = exec("glxinfo -B | grep 'OpenGL version' | sed 's/^.*: //' | sed 's/([^()]*)//g' | tr -s ' '");
driver = exec("glxinfo -B | sed -n 's/^OpenGL version.*: \\(.*\\)/\\1/p' | sed 's/([^)]*)//g;s/ / /g'");
trim(driver);
unsetenv("MANGOHUD_RECURSION");
} else {

@ -522,7 +522,6 @@ parse_overlay_env(struct overlay_params *params,
params->enabled[OVERLAY_PARAM_ENABLED_gpu_load_change] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_cpu_load_change] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_fps_only] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_fps_color_change] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_core_load_change] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_battery_icon] = 0;
@ -674,7 +673,6 @@ parse_overlay_config(struct overlay_params *params,
params->enabled[OVERLAY_PARAM_ENABLED_histogram] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_fps_only] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_battery_icon] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_mangoapp_steam] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_hide_fsr_sharpness] = 0;
params->options.erase("full");

@ -73,7 +73,6 @@ typedef unsigned long KeySym;
OVERLAY_PARAM_BOOL(gamemode) \
OVERLAY_PARAM_BOOL(battery) \
OVERLAY_PARAM_BOOL(battery_icon) \
OVERLAY_PARAM_BOOL(force_amdgpu_hwmon) \
OVERLAY_PARAM_BOOL(fps_only) \
OVERLAY_PARAM_BOOL(fsr) \
OVERLAY_PARAM_BOOL(mangoapp_steam) \

Loading…
Cancel
Save