Skip to content

Commit

Permalink
Improve KMS debuggability and avoid known broken cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Mar 13, 2024
1 parent e383ab9 commit d887798
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/platform/linux/kmsgrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <filesystem>
#include <thread>

#include "src/config.h"
#include "src/logging.h"
#include "src/platform/common.h"
#include "src/round_robin.h"
Expand Down Expand Up @@ -298,6 +299,9 @@ namespace platf {
return -1;
}

version_t ver { drmGetVersion(fd.el) };
BOOST_LOG(info) << path << " -> "sv << ((ver && ver->name) ? ver->name : "UNKNOWN");

// Open the render node for this card to share with libva.
// If it fails, we'll just share the primary node instead.
char *rendernode_path = drmGetRenderDeviceNameFromFd(fd.el);
Expand All @@ -316,12 +320,21 @@ namespace platf {
}

if (drmSetClientCap(fd.el, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1)) {
BOOST_LOG(error) << "Couldn't expose some/all drm planes for card: "sv << path;
BOOST_LOG(error) << "GPU driver doesn't support universal planes: "sv << path;
return -1;
}

if (drmSetClientCap(fd.el, DRM_CLIENT_CAP_ATOMIC, 1)) {
BOOST_LOG(warning) << "Couldn't expose some properties for card: "sv << path;
BOOST_LOG(warning) << "GPU driver doesn't support atomic mode-setting: "sv << path;
#if defined(SUNSHINE_BUILD_X11)
// We won't be able to capture the mouse cursor with KMS on non-atomic drivers,
// so fall back to X11 if it's available and the user didn't explicitly force KMS.
if (window_system == window_system_e::X11 && config::video.capture != "kms") {
BOOST_LOG(info) << "Avoiding KMS capture under X11 due to lack of atomic mode-setting"sv;
return -1;
}
#endif
BOOST_LOG(warning) << "Cursor capture may fail without atomic mode-setting support!"sv;
}

plane_res.reset(drmModeGetPlaneResources(fd.el));
Expand Down Expand Up @@ -640,8 +653,7 @@ namespace platf {
}

if (!fb->handles[0]) {
BOOST_LOG(error)
<< "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Possibly not permitted: do [sudo setcap cap_sys_admin+p sunshine]"sv;
BOOST_LOG(error) << "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Probably not permitted"sv;
return -1;
}

Expand Down Expand Up @@ -909,12 +921,14 @@ namespace platf {

if (!prop_crtc_w || !prop_crtc_h || !prop_crtc_x || !prop_crtc_y) {
BOOST_LOG(error) << "Cursor plane is missing required plane CRTC properties!"sv;
BOOST_LOG(error) << "Atomic mode-setting must be enabled to capture the cursor!"sv;
cursor_plane_id = -1;
captured_cursor.visible = false;
return;
}
if (!prop_src_x || !prop_src_y || !prop_src_w || !prop_src_h) {
BOOST_LOG(error) << "Cursor plane is missing required plane SRC properties!"sv;
BOOST_LOG(error) << "Atomic mode-setting must be enabled to capture the cursor!"sv;
cursor_plane_id = -1;
captured_cursor.visible = false;
return;
Expand Down Expand Up @@ -1072,8 +1086,7 @@ namespace platf {
}

if (!fb->handles[0]) {
BOOST_LOG(error)
<< "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Possibly not permitted: do [sudo setcap cap_sys_admin+p sunshine]"sv;
BOOST_LOG(error) << "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Probably not permitted"sv;
return capture_e::error;
}

Expand Down Expand Up @@ -1647,8 +1660,9 @@ namespace platf {
}

if (!fb->handles[0]) {
BOOST_LOG(error)
<< "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Possibly not permitted: do [sudo setcap cap_sys_admin+p sunshine]"sv;
BOOST_LOG(error) << "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Probably not permitted"sv;
BOOST_LOG((window_system != window_system_e::X11 || config::video.capture == "kms") ? fatal : error)
<< "You must run [sudo setcap cap_sys_admin+p $(readlink -f sunshine)] for KMS display capture to work!"sv;
break;
}

Expand Down

0 comments on commit d887798

Please sign in to comment.