From a5081498826384ea9e3a9e97118356b599cd3047 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Tue, 20 Dec 2022 21:24:48 +0900 Subject: [PATCH] dmabuf: Create buffers without the SCANOUT flag gbm_bo_create_with_modifiers implies the GBM_BO_USE_SCANOUT flag, which disables complex (tiled or compressed) formats that cannot be used for scanout. This reduces performance. We don't need to scan out buffers created for sceencasting/etc., so this is suboptimal. By switching to gbm_bo_create_with_modifiers2, we can explicitly pass the flags and avoid falling back to lower performance formats. Also add a config check and fall back to the old version, to retain compatibility with older mesa versions. --- CMakeLists.txt | 5 +++++ src/backends/drm/gbm_dmabuf.h | 9 +++++++++ src/config-kwin.h.cmake | 1 + 3 files changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fcd72dc541..8d66f919b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -248,6 +248,11 @@ if (${gbm_VERSION} GREATER_EQUAL 21.1) else() set(HAVE_GBM_BO_GET_FD_FOR_PLANE 0) endif() +if (${gbm_VERSION} GREATER_EQUAL 21.3) + set(HAVE_GBM_BO_CREATE_WITH_MODIFIERS2 1) +else() + set(HAVE_GBM_BO_CREATE_WITH_MODIFIERS2 0) +endif() pkg_check_modules(Libxcvt IMPORTED_TARGET libxcvt>=0.1.1 REQUIRED) add_feature_info(Libxcvt Libxcvt_FOUND "Required for generating modes in the drm backend") diff --git a/src/backends/drm/gbm_dmabuf.h b/src/backends/drm/gbm_dmabuf.h index 79a5915948..d8c778d97e 100644 --- a/src/backends/drm/gbm_dmabuf.h +++ b/src/backends/drm/gbm_dmabuf.h @@ -58,11 +58,20 @@ inline gbm_bo *createGbmBo(gbm_device *device, const QSize &size, quint32 format { gbm_bo *bo = nullptr; if (modifiers.count() > 0 && !(modifiers.count() == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID)) { +#if HAVE_GBM_BO_CREATE_WITH_MODIFIERS2 + bo = gbm_bo_create_with_modifiers2(device, + size.width(), + size.height(), + format, + modifiers.constData(), modifiers.count(), + GBM_BO_USE_RENDERING); +#else bo = gbm_bo_create_with_modifiers(device, size.width(), size.height(), format, modifiers.constData(), modifiers.count()); +#endif } if (!bo && (modifiers.isEmpty() || modifiers.contains(DRM_FORMAT_MOD_INVALID))) { diff --git a/src/config-kwin.h.cmake b/src/config-kwin.h.cmake index d5cde5bb37..da947c85dd 100644 --- a/src/config-kwin.h.cmake +++ b/src/config-kwin.h.cmake @@ -14,6 +14,7 @@ #cmakedefine01 HAVE_X11_XCB #cmakedefine01 HAVE_X11_XINPUT #cmakedefine01 HAVE_GBM_BO_GET_FD_FOR_PLANE +#cmakedefine01 HAVE_GBM_BO_CREATE_WITH_MODIFIERS2 #cmakedefine01 HAVE_MEMFD #cmakedefine01 HAVE_BREEZE_DECO #cmakedefine01 HAVE_SCHED_RESET_ON_FORK