Skip to content

Commit b4cf549

Browse files
Your Namemisyltoad
authored andcommitted
DRMBackend: Don't require overlay planes
Virtio-gpu KMS driver has only one primary plane and one universal cursor plane. Gamescope fails to start using virtio-gpu driver because it has assumption about KMS driver always having one or more overlay planes available when DRM backend selects plane formats. Check presence of overlay planes when picking plane format. This enables gamescope to work in KMS mode with virtio-gpu driver on virtual machines.
1 parent 962e792 commit b4cf549

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

src/Backends/DRMBackend.cpp

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,23 @@ static gamescope::CDRMPlane *find_primary_plane(struct drm_t *drm)
713713
return nullptr;
714714
}
715715

716+
static bool have_overlay_planes(struct drm_t *drm)
717+
{
718+
if ( !drm->pCRTC )
719+
return false;
720+
721+
for ( std::unique_ptr< gamescope::CDRMPlane > &pPlane : drm->planes )
722+
{
723+
if ( pPlane->GetModePlane()->possible_crtcs & drm->pCRTC->GetCRTCMask() )
724+
{
725+
if ( pPlane->GetProperties().type->GetCurrentValue() == DRM_PLANE_TYPE_OVERLAY )
726+
return true;
727+
}
728+
}
729+
730+
return false;
731+
}
732+
716733
extern void mangoapp_output_update( uint64_t vblanktime );
717734
static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, unsigned int crtc_id, void *data)
718735
{
@@ -1333,17 +1350,33 @@ bool init_drm(struct drm_t *drm, int width, int height, int refresh)
13331350
}
13341351
}
13351352

1336-
// ARGB8888 is the Xformat and AFormat here in this function as we want transparent overlay
1337-
g_nDRMFormatOverlay = pick_plane_format(&drm->primary_formats, DRM_FORMAT_ARGB2101010, DRM_FORMAT_ARGB2101010);
1338-
if ( g_nDRMFormatOverlay == DRM_FORMAT_INVALID ) {
1339-
g_nDRMFormatOverlay = pick_plane_format(&drm->primary_formats, DRM_FORMAT_ABGR2101010, DRM_FORMAT_ABGR2101010);
1353+
if (have_overlay_planes(drm)) {
1354+
// ARGB8888 is the Xformat and AFormat here in this function as we want transparent overlay
1355+
g_nDRMFormatOverlay = pick_plane_format(&drm->formats, DRM_FORMAT_ARGB2101010, DRM_FORMAT_ARGB2101010);
13401356
if ( g_nDRMFormatOverlay == DRM_FORMAT_INVALID ) {
1341-
g_nDRMFormatOverlay = pick_plane_format(&drm->primary_formats, DRM_FORMAT_ARGB8888, DRM_FORMAT_ARGB8888);
1357+
g_nDRMFormatOverlay = pick_plane_format(&drm->formats, DRM_FORMAT_ABGR2101010, DRM_FORMAT_ABGR2101010);
13421358
if ( g_nDRMFormatOverlay == DRM_FORMAT_INVALID ) {
1343-
drm_log.errorf("Overlay plane doesn't support any formats >= 8888");
1344-
return false;
1359+
g_nDRMFormatOverlay = pick_plane_format(&drm->formats, DRM_FORMAT_ARGB8888, DRM_FORMAT_ARGB8888);
1360+
if ( g_nDRMFormatOverlay == DRM_FORMAT_INVALID ) {
1361+
drm_log.errorf("Overlay plane doesn't support any formats >= 8888");
1362+
return false;
1363+
}
13451364
}
13461365
}
1366+
} else {
1367+
switch (g_nDRMFormat) {
1368+
case DRM_FORMAT_XRGB2101010:
1369+
g_nDRMFormatOverlay = DRM_FORMAT_ARGB2101010;
1370+
break;
1371+
case DRM_FORMAT_ABGR2101010:
1372+
g_nDRMFormatOverlay = DRM_FORMAT_ABGR2101010;
1373+
break;
1374+
case DRM_FORMAT_XRGB8888:
1375+
g_nDRMFormatOverlay = DRM_FORMAT_ARGB8888;
1376+
break;
1377+
default:
1378+
return false;
1379+
}
13471380
}
13481381

13491382
std::thread flip_handler_thread( flip_handler_thread_run );

0 commit comments

Comments
 (0)