Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add i915 integrated gpu support, fix fdinfo in gamescope and continuously poll fdinfo needed for some games #1526

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ subprojects/imgui-*/
subprojects/spdlog-*/
subprojects/nlohmann_json-*/
subprojects/implot-*/
subprojects/cmocka/

#GNU Global Metadata
**/GPATH
Expand Down
3 changes: 3 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ static void msg_read_thread(){
if (msg_size != size_t(-1))
{
if (hdr->version == 1){
if (msg_size > offsetof(struct mangoapp_msg_v1, pid))
HUDElements.g_gamescopePid = mangoapp_v1->pid;

if (msg_size > offsetof(struct mangoapp_msg_v1, visible_frametime_ns)){
bool should_new_frame = false;
if (mangoapp_v1->visible_frametime_ns != ~(0lu) && (!params.no_display || logger->is_active())) {
Expand Down
4 changes: 2 additions & 2 deletions src/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class GPU {
void pause() {
if (nvidia)
nvidia->pause();

if (amdgpu)
amdgpu->pause();

Expand Down Expand Up @@ -106,7 +106,7 @@ class GPU {

return nullptr;
}

std::string gpu_text();
std::string vram_text();

Expand Down
30 changes: 29 additions & 1 deletion src/gpu_fdinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#include "gpu_fdinfo.h"

#ifndef TEST_ONLY
#include "hud_elements.h"
#endif

namespace fs = ghc::filesystem;

void GPU_fdinfo::find_fd()
{
auto path = fs::path("/proc/self/fdinfo");
fdinfo.clear();
fdinfo_data.clear();

auto dir = std::string("/proc/") + std::to_string(pid) + "/fdinfo";
auto path = fs::path(dir);

SPDLOG_DEBUG("fdinfo_dir = {}", dir);

if (!fs::exists(path)) {
SPDLOG_DEBUG("{} does not exist", path.string());
Expand Down Expand Up @@ -482,6 +493,23 @@ void GPU_fdinfo::main_thread()
std::unique_lock<std::mutex> lock(metrics_mutex);
cond_var.wait(lock, [this]() { return !paused || stop_thread; });

#ifndef TEST_ONLY
if (HUDElements.g_gamescopePid > 0 && HUDElements.g_gamescopePid != pid)
{
pid = HUDElements.g_gamescopePid;
find_fd();
}
#endif

// Recheck fds every 10secs, fixes Mass Effect 1, maybe some others too
{
auto t = os_time_get_nano() / 1'000'000;
if (t - fdinfo_last_update_ms >= 10'000) {
find_fd();
fdinfo_last_update_ms = t;
}
}

gather_fdinfo_data();
get_current_hwmon_readings();

Expand Down
47 changes: 28 additions & 19 deletions src/gpu_fdinfo.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
#pragma once
#include <cstdint>
#include <filesystem.h>

#include <inttypes.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <cstdint>
#include <thread>
#include <atomic>
#include <map>
#include <set>
#include <regex>

#ifdef TEST_ONLY
#include <../src/mesa/util/os_time.h>
#else
#include "mesa/util/os_time.h"
#endif

#include "gpu_metrics_util.h"
#include <atomic>
#include <spdlog/spdlog.h>
#include <map>
#include <set>
#include <regex>
#include <filesystem.h>

#include "gpu_metrics_util.h"

struct hwmon_sensor {
std::regex rx;
Expand Down Expand Up @@ -53,6 +56,7 @@ class GPU_fdinfo {
mutable std::mutex metrics_mutex;

std::vector<std::ifstream> fdinfo;
uint64_t fdinfo_last_update_ms = 0;

std::map<std::string, hwmon_sensor> hwmon_sensors;

Expand Down Expand Up @@ -116,21 +120,10 @@ class GPU_fdinfo {

if (module == "i915") {
drm_engine_type = "drm-engine-render";
drm_memory_type = "drm-total-local0";
drm_memory_type = "drm-resident-local0";
} else if (module == "xe") {
drm_engine_type = "drm-total-cycles-rcs";
drm_memory_type = "drm-resident-vram0";

if (
fdinfo_data.size() > 0 &&
fdinfo_data[0].find(drm_memory_type) == fdinfo_data[0].end()
) {
SPDLOG_DEBUG(
"\"{}\" is not found, you probably have an integrated GPU. "
"Using \"drm-resident-gtt\".", drm_memory_type
);
drm_memory_type = "drm-resident-gtt";
}
} else if (module == "amdgpu") {
drm_engine_type = "drm-engine-gfx";
drm_memory_type = "drm-memory-vram";
Expand All @@ -139,6 +132,22 @@ class GPU_fdinfo {
drm_engine_type = "drm-engine-gpu";
}

if (fdinfo_data.size() > 0 &&
fdinfo_data[0].find(drm_memory_type) == fdinfo_data[0].end())
{
auto old_type = drm_memory_type;

if (module == "i915")
drm_memory_type = "drm-resident-system0";
else if (module == "xe")
drm_memory_type = "drm-resident-gtt";

SPDLOG_DEBUG(
"\"{}\" is not found, you probably have an integrated GPU. "
"Using \"{}\"", old_type, drm_memory_type
);
}

SPDLOG_DEBUG(
"drm_engine_type = {}, drm_memory_type = {}",
drm_engine_type, drm_memory_type
Expand Down
3 changes: 2 additions & 1 deletion src/hud_elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class HudElements{
int place;
int text_column = 1;
int table_columns_count = 0;
pid_t g_gamescopePid = -1;
int g_fsrUpscale = -1;
int g_fsrSharpness = -1;
Clock::time_point last_exec;
Expand All @@ -55,7 +56,7 @@ class HudElements{
int hdr_status = 0;
int refresh = 0;
unsigned int vsync = 10;

enum display_servers {
UNKNOWN,
WAYLAND,
Expand Down
Loading