From e81fa52c76258c037c6ac0af7f25b39a75456469 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 7 Jun 2023 15:32:33 +0300 Subject: [PATCH] backends/drm: Prefer egl import mode The egl import mode ensures that there's a local buffer, which is preferred as it minimizes the number of data transfers over PCIe. With dmabuf, it's unclear what the driver will do. But the main takeaway from discussion with mesa developers is that it's undesired for gbm_bo_import() to migrate or perform data transfers behind the user's back, it should be done explicitly. --- src/backends/drm/drm_egl_layer_surface.cpp | 33 +++++++++++----------- src/backends/drm/drm_egl_layer_surface.h | 1 + 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/backends/drm/drm_egl_layer_surface.cpp b/src/backends/drm/drm_egl_layer_surface.cpp index 6d9fde7e38..0f2caf40de 100644 --- a/src/backends/drm/drm_egl_layer_surface.cpp +++ b/src/backends/drm/drm_egl_layer_surface.cpp @@ -241,25 +241,24 @@ std::optional EglGbmLayerSurface::createSurface(con }; const auto testFormats = [this, &sort, &doTestFormats](QVector &formats) -> std::optional { std::sort(formats.begin(), formats.end(), sort); - if (const auto surface = doTestFormats(formats, MultiGpuImportMode::Dmabuf)) { - if (m_gpu != m_eglBackend->gpu()) { - qCDebug(KWIN_DRM) << "chose dmabuf import with format" << formatName(surface->gbmSwapchain->format()).name << "and modifier" << surface->gbmSwapchain->modifier(); - } + if (m_gpu == m_eglBackend->gpu()) { + return doTestFormats(formats, MultiGpuImportMode::None); + } + if (const auto surface = doTestFormats(formats, MultiGpuImportMode::Egl)) { + qCDebug(KWIN_DRM) << "chose egl import with format" << formatName(surface->gbmSwapchain->format()).name << "and modifier" << surface->gbmSwapchain->modifier(); return surface; } - if (m_gpu != m_eglBackend->gpu()) { - if (const auto surface = doTestFormats(formats, MultiGpuImportMode::LinearDmabuf)) { - qCDebug(KWIN_DRM) << "chose linear dmabuf import with format" << formatName(surface->gbmSwapchain->format()).name << "and modifier" << surface->gbmSwapchain->modifier(); - return surface; - } - if (const auto surface = doTestFormats(formats, MultiGpuImportMode::Egl)) { - qCDebug(KWIN_DRM) << "chose egl import with format" << formatName(surface->gbmSwapchain->format()).name << "and modifier" << surface->gbmSwapchain->modifier(); - return surface; - } - if (const auto surface = doTestFormats(formats, MultiGpuImportMode::DumbBuffer)) { - qCDebug(KWIN_DRM) << "chose cpu import with format" << formatName(surface->gbmSwapchain->format()).name << "and modifier" << surface->gbmSwapchain->modifier(); - return surface; - } + if (const auto surface = doTestFormats(formats, MultiGpuImportMode::Dmabuf)) { + qCDebug(KWIN_DRM) << "chose dmabuf import with format" << formatName(surface->gbmSwapchain->format()).name << "and modifier" << surface->gbmSwapchain->modifier(); + return surface; + } + if (const auto surface = doTestFormats(formats, MultiGpuImportMode::LinearDmabuf)) { + qCDebug(KWIN_DRM) << "chose linear dmabuf import with format" << formatName(surface->gbmSwapchain->format()).name << "and modifier" << surface->gbmSwapchain->modifier(); + return surface; + } + if (const auto surface = doTestFormats(formats, MultiGpuImportMode::DumbBuffer)) { + qCDebug(KWIN_DRM) << "chose cpu import with format" << formatName(surface->gbmSwapchain->format()).name << "and modifier" << surface->gbmSwapchain->modifier(); + return surface; } return std::nullopt; }; diff --git a/src/backends/drm/drm_egl_layer_surface.h b/src/backends/drm/drm_egl_layer_surface.h index 2b46bff126..b7561e5456 100644 --- a/src/backends/drm/drm_egl_layer_surface.h +++ b/src/backends/drm/drm_egl_layer_surface.h @@ -65,6 +65,7 @@ public: private: enum class MultiGpuImportMode { + None, Dmabuf, LinearDmabuf, Egl,