Skip to content
Open
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
35 changes: 32 additions & 3 deletions src/platform/linux/cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,52 @@
return std::tolower(c);
});

// Look for the name of the primary node in sysfs
// Look for DRM nodes in sysfs — prefer render node (doesn't require DRM master)
try {
char sysfs_path[PATH_MAX];
std::snprintf(sysfs_path, sizeof(sysfs_path), "/sys/bus/pci/devices/%s/drm", pci_bus_id.data());
fs::path sysfs_dir {sysfs_path};

// First pass: look for render node (renderD*)
for (auto &entry : fs::directory_iterator {sysfs_dir}) {
auto file = entry.path().filename();
auto filestring = file.generic_string();
if (std::string_view {filestring}.substr(0, 7) != "renderD"sv) {
continue;
}

BOOST_LOG(debug) << "Found DRM render node: "sv << filestring;

fs::path dri_path {"/dev/dri"sv};
auto device_path = dri_path / file;
int fd = open(device_path.c_str(), O_RDWR);
if (fd >= 0) {
return fd;
}
char errbuf[256];

Check warning on line 273 in src/platform/linux/cuda.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "std::string" instead of a C-style char array.

See more on https://sonarcloud.io/project/issues?id=LizardByte_Sunshine&issues=AZ2WL4WsQtrCo_FefaUL&open=AZ2WL4WsQtrCo_FefaUL&pullRequest=4946
BOOST_LOG(warning) << "Failed to open render node "sv << device_path.string()
<< " ("sv << strerror_r(errno, errbuf, sizeof(errbuf)) << "), trying primary node"sv;
}

// Second pass: fallback to primary node (card*)
for (auto &entry : fs::directory_iterator {sysfs_dir}) {
auto file = entry.path().filename();
auto filestring = file.generic_string();
if (std::string_view {filestring}.substr(0, 4) != "card"sv) {
continue;
}

BOOST_LOG(debug) << "Found DRM primary node: "sv << filestring;
BOOST_LOG(debug) << "Found DRM primary node (fallback): "sv << filestring;

fs::path dri_path {"/dev/dri"sv};
auto device_path = dri_path / file;
return open(device_path.c_str(), O_RDWR);
int fd = open(device_path.c_str(), O_RDWR);
if (fd >= 0) {
return fd;
}
char errbuf[256];

Check warning on line 294 in src/platform/linux/cuda.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "std::string" instead of a C-style char array.

See more on https://sonarcloud.io/project/issues?id=LizardByte_Sunshine&issues=AZ2WL4WsQtrCo_FefaUM&open=AZ2WL4WsQtrCo_FefaUM&pullRequest=4946
BOOST_LOG(warning) << "Failed to open primary node "sv << device_path.string()
<< ": "sv << strerror_r(errno, errbuf, sizeof(errbuf));
}
} catch (const std::filesystem::filesystem_error &err) {
BOOST_LOG(error) << "Failed to read sysfs: "sv << err.what();
Expand Down
Loading