Improve KMS debuggability and avoid known broken cases

This commit is contained in:
Cameron Gutman
2024-03-12 18:08:14 -05:00
parent e383ab9956
commit d8877982ff

View File

@@ -15,6 +15,7 @@
#include <filesystem> #include <filesystem>
#include <thread> #include <thread>
#include "src/config.h"
#include "src/logging.h" #include "src/logging.h"
#include "src/platform/common.h" #include "src/platform/common.h"
#include "src/round_robin.h" #include "src/round_robin.h"
@@ -298,6 +299,9 @@ namespace platf {
return -1; 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. // Open the render node for this card to share with libva.
// If it fails, we'll just share the primary node instead. // If it fails, we'll just share the primary node instead.
char *rendernode_path = drmGetRenderDeviceNameFromFd(fd.el); char *rendernode_path = drmGetRenderDeviceNameFromFd(fd.el);
@@ -316,12 +320,21 @@ namespace platf {
} }
if (drmSetClientCap(fd.el, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1)) { 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; return -1;
} }
if (drmSetClientCap(fd.el, DRM_CLIENT_CAP_ATOMIC, 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)); plane_res.reset(drmModeGetPlaneResources(fd.el));
@@ -640,8 +653,7 @@ namespace platf {
} }
if (!fb->handles[0]) { if (!fb->handles[0]) {
BOOST_LOG(error) BOOST_LOG(error) << "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Probably not permitted"sv;
<< "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Possibly not permitted: do [sudo setcap cap_sys_admin+p sunshine]"sv;
return -1; return -1;
} }
@@ -909,12 +921,14 @@ namespace platf {
if (!prop_crtc_w || !prop_crtc_h || !prop_crtc_x || !prop_crtc_y) { 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) << "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; cursor_plane_id = -1;
captured_cursor.visible = false; captured_cursor.visible = false;
return; return;
} }
if (!prop_src_x || !prop_src_y || !prop_src_w || !prop_src_h) { 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) << "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; cursor_plane_id = -1;
captured_cursor.visible = false; captured_cursor.visible = false;
return; return;
@@ -1072,8 +1086,7 @@ namespace platf {
} }
if (!fb->handles[0]) { if (!fb->handles[0]) {
BOOST_LOG(error) BOOST_LOG(error) << "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Probably not permitted"sv;
<< "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Possibly not permitted: do [sudo setcap cap_sys_admin+p sunshine]"sv;
return capture_e::error; return capture_e::error;
} }
@@ -1647,8 +1660,9 @@ namespace platf {
} }
if (!fb->handles[0]) { if (!fb->handles[0]) {
BOOST_LOG(error) BOOST_LOG(error) << "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Probably not permitted"sv;
<< "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((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; break;
} }