Skip to content

Commit 3e21beb

Browse files
17314642flightlessmango
authored andcommitted
next: fdinfo: fix games that open /dev/dri/card* instead of renderD*
1 parent d5b0aba commit 3e21beb

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

mangohud-next/server/metrics/fdinfo.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace fs = std::filesystem;
99
using namespace std::chrono_literals;
1010

1111
FDInfoBase::FDInfoBase(const std::string& drm_node, const pid_t pid) : drm_node(drm_node), pid(pid) {
12+
card_node = get_card_node();
1213
init();
1314
}
1415

@@ -72,10 +73,10 @@ std::vector<std::string> FDInfoBase::find_fds() {
7273
continue;
7374
}
7475

76+
// comparison to both renderD* and card* is required because
7577
// for some reason supertuxkart opens /dev/dri/card and not renderD
7678
// inside podman container.
77-
// this is only for testing, so remove it later
78-
if (link.filename() != drm_node && link.string().substr(0, 13) != "/dev/dri/card")
79+
if (link.filename() != drm_node && link.filename() != card_node)
7980
continue;
8081

8182
fds.push_back(entry.path().filename());
@@ -121,6 +122,29 @@ void FDInfoBase::open_fds(const std::vector<std::string>& fds) {
121122
SPDLOG_DEBUG("Received {} ids, opened {} unique ids", fds.size(), total);
122123
}
123124

125+
std::string FDInfoBase::get_card_node() {
126+
const std::string device = "/sys/class/drm/" + drm_node + "/device/drm";
127+
128+
if (!std::filesystem::exists(device)) {
129+
SPDLOG_DEBUG("drm dir doesn't exist for {}", drm_node);
130+
return "";
131+
}
132+
133+
// Find first dir which starts with name "card"
134+
for (const auto& entry : fs::directory_iterator(device)) {
135+
std::filesystem::path path = entry.path();
136+
137+
if (path.filename().string().substr(0, 4) == "card") {
138+
const std::string filename = path.filename();
139+
SPDLOG_DEBUG("found card node for {}: {}", drm_node, filename);
140+
return filename;
141+
}
142+
}
143+
144+
SPDLOG_DEBUG("didn't find card node for {}", drm_node);
145+
return "";
146+
}
147+
124148
void FDInfoWrapper::add_pid(pid_t pid) {
125149
std::unique_lock lock(pids_mutex);
126150

mangohud-next/server/metrics/fdinfo.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ class FDInfoBase {
1313
private:
1414
std::vector<std::ifstream> fds_streams;
1515
chrono_timer last_init;
16+
std::string card_node;
1617

1718
std::vector<std::string> find_fds();
1819
void open_fds(const std::vector<std::string>& fds);
20+
std::string get_card_node();
1921

2022
public:
2123
const std::string drm_node;

0 commit comments

Comments
 (0)