kwin/plugins/platforms/drm/drm_backend.cpp

647 lines
18 KiB
C++
Raw Normal View History

2020-08-03 01:22:19 +03:00
/*
KWin - the KDE window manager
This file is part of the KDE project.
2020-08-03 01:22:19 +03:00
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
2020-08-03 01:22:19 +03:00
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "drm_backend.h"
#include "drm_output.h"
#include "drm_object_connector.h"
#include "drm_object_crtc.h"
#include "drm_object_plane.h"
2015-04-13 10:23:03 +03:00
#include "composite.h"
#include "cursor.h"
#include "logging.h"
#include "logind.h"
#include "main.h"
#include "scene_qpainter_drm_backend.h"
#include "screens_drm.h"
#include "udev.h"
#include "wayland_server.h"
#if HAVE_GBM
#include "egl_gbm_backend.h"
#include <gbm.h>
#include "gbm_dmabuf.h"
#endif
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
#if HAVE_EGL_STREAMS
#include "egl_stream_backend.h"
#endif
// KWayland
#include <KWaylandServer/seat_interface.h>
// KF5
#include <KConfigGroup>
#include <KCoreAddons>
#include <KLocalizedString>
#include <KSharedConfig>
2015-04-13 10:23:03 +03:00
// Qt
#include <QCryptographicHash>
2015-04-13 10:23:03 +03:00
#include <QSocketNotifier>
#include <QPainter>
// system
#include <algorithm>
#include <unistd.h>
// drm
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <libdrm/drm_mode.h>
#include "drm_gpu.h"
#ifndef DRM_CAP_CURSOR_WIDTH
#define DRM_CAP_CURSOR_WIDTH 0x8
#endif
#ifndef DRM_CAP_CURSOR_HEIGHT
#define DRM_CAP_CURSOR_HEIGHT 0x9
#endif
#define KWIN_DRM_EVENT_CONTEXT_VERSION 2
namespace KWin
{
DrmBackend::DrmBackend(QObject *parent)
2016-04-07 10:18:10 +03:00
: Platform(parent)
, m_udev(new Udev)
, m_udevMonitor(m_udev->monitor())
, m_dpmsFilter()
{
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
#if HAVE_EGL_STREAMS
if (qEnvironmentVariableIsSet("KWIN_DRM_USE_EGL_STREAMS")) {
m_useEglStreams = true;
}
#endif
[colorcorrection] Night Color - blue light filter at nighttime With Wayland KWin needs to provide certain services, which were provided before that by the Xserver. One of these is gamma correction, which includes the - by many people beloved - functionality to reduce the blue light at nighttime. This patch provides the KWin part of that. It is self contained, but in the end will work in tandem with a lib in Plasma Workspace and a KCM in Plasma Desktop, which can be used to configure Night Color. * Three modi: ** Automatic: The location and sun timings are determined automatically (location data updates will be provided by the workspace) ** Location: The sun timings are determined by fixed location data ** Timings: The sun timings are set manually by the user * Color temperature value changes are smoothly applied: ** Configuration changes, which lead to other current values are changed in a quick way over a few seconds ** Changes on sunrise and sunset are applied slowly over the course of few minutes till several hours depending on the configuration * The current color value is set immediately at startup or after suspend phases and VT switches. There is no flickering. * All configuration is done via a DBus interface, changed values are tested on correctness and applied atomically * Self contained mechanism, speaks directly to the hardware by setting the gamma ramps on the CRTC * Currently working on DRM backend, extensible to other platform backends in the future * The code is written in a way to make the classes later easily extendable to also provide normal color correction, as it's currently done by KGamma on X Test Plan: Manually with the workspace parts and added integration tests in KWin using the virtual backend. BUG:371494 Reviewers: #kwin, graesslin Subscribers: kwin, plasma-devel, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D5928
2017-12-11 12:43:12 +03:00
setSupportsGammaControl(true);
supportsOutputChanges();
}
DrmBackend::~DrmBackend()
{
if (m_gpus.size() > 0) {
// wait for pageflips
while (m_pageFlipsPending != 0) {
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
}
qDeleteAll(m_gpus);
}
}
void DrmBackend::init()
{
LogindIntegration *logind = LogindIntegration::self();
auto takeControl = [logind, this]() {
if (logind->hasSessionControl()) {
openDrm();
} else {
logind->takeControl();
connect(logind, &LogindIntegration::hasSessionControlChanged, this, &DrmBackend::openDrm);
}
};
if (logind->isConnected()) {
takeControl();
} else {
connect(logind, &LogindIntegration::connectedChanged, this, takeControl);
}
}
void DrmBackend::prepareShutdown()
{
writeOutputsConfiguration();
for (DrmOutput *output : m_outputs) {
output->teardown();
}
Platform::prepareShutdown();
}
Outputs DrmBackend::outputs() const
{
return m_outputs;
}
Outputs DrmBackend::enabledOutputs() const
{
return m_enabledOutputs;
}
void DrmBackend::createDpmsFilter()
{
if (!m_dpmsFilter.isNull()) {
// already another output is off
return;
}
m_dpmsFilter.reset(new DpmsInputEventFilter(this));
2017-01-02 22:13:30 +03:00
input()->prependInputEventFilter(m_dpmsFilter.data());
}
void DrmBackend::turnOutputsOn()
{
m_dpmsFilter.reset();
for (auto it = m_enabledOutputs.constBegin(), end = m_enabledOutputs.constEnd(); it != end; it++) {
(*it)->updateDpms(KWaylandServer::OutputInterface::DpmsMode::On);
}
}
void DrmBackend::checkOutputsAreOn()
{
if (m_dpmsFilter.isNull()) {
// already disabled, all outputs are on
return;
}
for (auto it = m_enabledOutputs.constBegin(), end = m_enabledOutputs.constEnd(); it != end; it++) {
if (!(*it)->isDpmsEnabled()) {
// dpms still disabled, need to keep the filter
return;
}
}
// all outputs are on, disable the filter
m_dpmsFilter.reset();
}
void DrmBackend::activate(bool active)
{
if (active) {
qCDebug(KWIN_DRM) << "Activating session.";
reactivate();
} else {
qCDebug(KWIN_DRM) << "Deactivating session.";
deactivate();
}
}
void DrmBackend::reactivate()
{
if (m_active) {
return;
}
m_active = true;
if (!usesSoftwareCursor()) {
Cursor* cursor = Cursors::self()->mouse();
const QPoint cp = cursor->pos() - cursor->hotspot();
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
DrmOutput *o = *it;
// only relevant in atomic mode
o->m_modesetRequested = true;
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc To get an image from KWin to the screen in the DRM pipeline we combine a CRTC, an encoder and a connector. These objects are static in the sense, that they represent real hardware on the graphics card, which doesn't change in a session. See here for more details: https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html Until now we used DrmOutput as the main representation for such an active rendering pipeline. I.e. it gets created and destroyed on hot plug events of displays. On the other side we had no fixed representation of the static kernel objects throughout the lifetime of KWin. This has several disadvantages: * We always need to query all available static objects on an hot plug event. * We can't manipulate the frame buffer of a CRTC after an output has been disconnected * Adding functionality for driving multiple displays on a single CRTC (i.e. cloning) would be difficult * We can't destroy the last frame buffer on display disconnect because the CRTC still accesses it and have therefore a memory leak on every display disconnect This patch solves these issues by storing representations of all available CRTC and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector instances. On an hotplug event these vectors are looped for a fitting CRTC and Connector combinations. Buffer handling is moved to the respective CRTC instance. All changes in overview: * Query all available CRTCs and Connectors and save for subsequent hotplug events * Fix logic errors in `queryResources()` * Move framebuffers, buffer flip and blank logic in DrmCrtc * Remove `restoreSaved()`. It isn't necessary and is dangerous if the old framebuffer was deleted in the meantime. Also could reveal sensitive user info from old session. Test Plan: Login, logout, VT switching, connect and disconnect external monitor, energy saving mode. Reviewers: #kwin Subscribers: kwin, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 21:02:49 +03:00
o->m_crtc->blank();
o->showCursor();
o->moveCursor(cursor, cp);
}
}
// restart compositor
m_pageFlipsPending = 0;
if (Compositor *compositor = Compositor::self()) {
compositor->bufferSwapComplete();
compositor->addRepaintFull();
}
}
void DrmBackend::deactivate()
{
if (!m_active) {
return;
}
// block compositor
if (m_pageFlipsPending == 0 && Compositor::self()) {
Compositor::self()->aboutToSwapBuffers();
}
// hide cursor and disable
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
DrmOutput *o = *it;
o->hideCursor();
}
m_active = false;
}
2015-04-13 10:23:03 +03:00
void DrmBackend::pageFlipHandler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data)
{
Q_UNUSED(fd)
Q_UNUSED(frame)
Q_UNUSED(sec)
Q_UNUSED(usec)
auto output = reinterpret_cast<DrmOutput*>(data);
output->pageFlipped();
output->m_backend->m_pageFlipsPending--;
if (output->m_backend->m_pageFlipsPending == 0) {
// TODO: improve, this currently means we wait for all page flips or all outputs.
// It would be better to driver the repaint per output
if (Compositor::self()) {
Compositor::self()->bufferSwapComplete();
}
}
2015-04-13 10:23:03 +03:00
}
void DrmBackend::openDrm()
{
connect(LogindIntegration::self(), &LogindIntegration::sessionActiveChanged, this, &DrmBackend::activate);
std::vector<UdevDevice::Ptr> devices = m_udev->listGPUs();
if (devices.size() == 0) {
qCWarning(KWIN_DRM) << "Did not find a GPU";
return;
}
for (unsigned int gpu_index = 0; gpu_index < devices.size(); gpu_index++) {
auto device = std::move(devices.at(gpu_index));
auto devNode = QByteArray(device->devNode());
int fd = LogindIntegration::self()->takeDevice(devNode.constData());
if (fd < 0) {
qCWarning(KWIN_DRM) << "failed to open drm device at" << devNode;
return;
2015-04-13 10:23:03 +03:00
}
m_active = true;
QSocketNotifier *notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
connect(notifier, &QSocketNotifier::activated, this,
[fd] {
if (!LogindIntegration::self()->isActiveSession()) {
return;
}
drmEventContext e;
memset(&e, 0, sizeof e);
e.version = KWIN_DRM_EVENT_CONTEXT_VERSION;
e.page_flip_handler = pageFlipHandler;
drmHandleEvent(fd, &e);
}
);
DrmGpu *gpu = new DrmGpu(this, devNode, fd, device->sysNum());
connect(gpu, &DrmGpu::outputAdded, this, &DrmBackend::addOutput);
connect(gpu, &DrmGpu::outputRemoved, this, &DrmBackend::removeOutput);
m_gpus.append(gpu);
break;
}
// trying to activate Atomic Mode Setting (this means also Universal Planes)
if (!qEnvironmentVariableIsSet("KWIN_DRM_NO_AMS")) {
for (auto gpu : m_gpus)
gpu->tryAMS();
}
initCursor();
if (!updateOutputs())
return;
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc To get an image from KWin to the screen in the DRM pipeline we combine a CRTC, an encoder and a connector. These objects are static in the sense, that they represent real hardware on the graphics card, which doesn't change in a session. See here for more details: https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html Until now we used DrmOutput as the main representation for such an active rendering pipeline. I.e. it gets created and destroyed on hot plug events of displays. On the other side we had no fixed representation of the static kernel objects throughout the lifetime of KWin. This has several disadvantages: * We always need to query all available static objects on an hot plug event. * We can't manipulate the frame buffer of a CRTC after an output has been disconnected * Adding functionality for driving multiple displays on a single CRTC (i.e. cloning) would be difficult * We can't destroy the last frame buffer on display disconnect because the CRTC still accesses it and have therefore a memory leak on every display disconnect This patch solves these issues by storing representations of all available CRTC and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector instances. On an hotplug event these vectors are looped for a fitting CRTC and Connector combinations. Buffer handling is moved to the respective CRTC instance. All changes in overview: * Query all available CRTCs and Connectors and save for subsequent hotplug events * Fix logic errors in `queryResources()` * Move framebuffers, buffer flip and blank logic in DrmCrtc * Remove `restoreSaved()`. It isn't necessary and is dangerous if the old framebuffer was deleted in the meantime. Also could reveal sensitive user info from old session. Test Plan: Login, logout, VT switching, connect and disconnect external monitor, energy saving mode. Reviewers: #kwin Subscribers: kwin, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 21:02:49 +03:00
if (m_outputs.isEmpty()) {
qCDebug(KWIN_DRM) << "No connected outputs found on startup.";
}
// setup udevMonitor
if (m_udevMonitor) {
m_udevMonitor->filterSubsystemDevType("drm");
const int fd = m_udevMonitor->fd();
if (fd != -1) {
QSocketNotifier *notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
connect(notifier, &QSocketNotifier::activated, this,
[this] {
auto device = m_udevMonitor->getDevice();
if (!device) {
return;
}
bool drm = false;
for (auto gpu : m_gpus) {
if (gpu->drmId() == device->sysNum()) {
drm = true;
break;
}
}
if (!drm) {
return;
}
if (device->hasProperty("HOTPLUG", "1")) {
qCDebug(KWIN_DRM) << "Received hot plug event for monitored drm device";
updateOutputs();
updateCursor();
}
}
);
m_udevMonitor->enable();
}
}
setReady(true);
}
void DrmBackend::addOutput(DrmOutput *o)
{
m_outputs.append(o);
m_enabledOutputs.append(o);
emit o->gpu()->outputEnabled(o);
}
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc To get an image from KWin to the screen in the DRM pipeline we combine a CRTC, an encoder and a connector. These objects are static in the sense, that they represent real hardware on the graphics card, which doesn't change in a session. See here for more details: https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html Until now we used DrmOutput as the main representation for such an active rendering pipeline. I.e. it gets created and destroyed on hot plug events of displays. On the other side we had no fixed representation of the static kernel objects throughout the lifetime of KWin. This has several disadvantages: * We always need to query all available static objects on an hot plug event. * We can't manipulate the frame buffer of a CRTC after an output has been disconnected * Adding functionality for driving multiple displays on a single CRTC (i.e. cloning) would be difficult * We can't destroy the last frame buffer on display disconnect because the CRTC still accesses it and have therefore a memory leak on every display disconnect This patch solves these issues by storing representations of all available CRTC and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector instances. On an hotplug event these vectors are looped for a fitting CRTC and Connector combinations. Buffer handling is moved to the respective CRTC instance. All changes in overview: * Query all available CRTCs and Connectors and save for subsequent hotplug events * Fix logic errors in `queryResources()` * Move framebuffers, buffer flip and blank logic in DrmCrtc * Remove `restoreSaved()`. It isn't necessary and is dangerous if the old framebuffer was deleted in the meantime. Also could reveal sensitive user info from old session. Test Plan: Login, logout, VT switching, connect and disconnect external monitor, energy saving mode. Reviewers: #kwin Subscribers: kwin, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 21:02:49 +03:00
void DrmBackend::removeOutput(DrmOutput *o)
{
emit o->gpu()->outputDisabled(o);
m_outputs.removeOne(o);
m_enabledOutputs.removeOne(o);
}
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc To get an image from KWin to the screen in the DRM pipeline we combine a CRTC, an encoder and a connector. These objects are static in the sense, that they represent real hardware on the graphics card, which doesn't change in a session. See here for more details: https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html Until now we used DrmOutput as the main representation for such an active rendering pipeline. I.e. it gets created and destroyed on hot plug events of displays. On the other side we had no fixed representation of the static kernel objects throughout the lifetime of KWin. This has several disadvantages: * We always need to query all available static objects on an hot plug event. * We can't manipulate the frame buffer of a CRTC after an output has been disconnected * Adding functionality for driving multiple displays on a single CRTC (i.e. cloning) would be difficult * We can't destroy the last frame buffer on display disconnect because the CRTC still accesses it and have therefore a memory leak on every display disconnect This patch solves these issues by storing representations of all available CRTC and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector instances. On an hotplug event these vectors are looped for a fitting CRTC and Connector combinations. Buffer handling is moved to the respective CRTC instance. All changes in overview: * Query all available CRTCs and Connectors and save for subsequent hotplug events * Fix logic errors in `queryResources()` * Move framebuffers, buffer flip and blank logic in DrmCrtc * Remove `restoreSaved()`. It isn't necessary and is dangerous if the old framebuffer was deleted in the meantime. Also could reveal sensitive user info from old session. Test Plan: Login, logout, VT switching, connect and disconnect external monitor, energy saving mode. Reviewers: #kwin Subscribers: kwin, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 21:02:49 +03:00
bool DrmBackend::updateOutputs()
{
if (m_gpus.size() == 0) {
return false;
}
for (auto gpu : m_gpus)
gpu->updateOutputs();
std::sort(m_outputs.begin(), m_outputs.end(), [] (DrmOutput *a, DrmOutput *b) { return a->m_conn->id() < b->m_conn->id(); });
readOutputsConfiguration();
updateOutputsEnabled();
if (!m_outputs.isEmpty()) {
emit screensQueried();
}
return true;
}
void DrmBackend::readOutputsConfiguration()
{
if (m_outputs.isEmpty()) {
return;
}
const QByteArray uuid = generateOutputConfigurationUuid();
const auto outputGroup = kwinApp()->config()->group("DrmOutputs");
const auto configGroup = outputGroup.group(uuid);
// default position goes from left to right
QPoint pos(0, 0);
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
qCDebug(KWIN_DRM) << "Reading output configuration for [" << uuid << "] ["<< (*it)->uuid() << "]";
const auto outputConfig = configGroup.group((*it)->uuid());
(*it)->setGlobalPos(outputConfig.readEntry<QPoint>("Position", pos));
// TODO: add mode
if (outputConfig.hasKey("Scale"))
(*it)->setScale(outputConfig.readEntry("Scale", 1.0));
pos.setX(pos.x() + (*it)->geometry().width());
}
}
void DrmBackend::writeOutputsConfiguration()
{
if (m_outputs.isEmpty()) {
return;
}
const QByteArray uuid = generateOutputConfigurationUuid();
auto configGroup = KSharedConfig::openConfig()->group("DrmOutputs").group(uuid);
// default position goes from left to right
for (auto it = m_outputs.cbegin(); it != m_outputs.cend(); ++it) {
qCDebug(KWIN_DRM) << "Writing output configuration for [" << uuid << "] ["<< (*it)->uuid() << "]";
auto outputConfig = configGroup.group((*it)->uuid());
outputConfig.writeEntry("Scale", (*it)->scale());
}
}
QByteArray DrmBackend::generateOutputConfigurationUuid() const
{
auto it = m_outputs.constBegin();
if (m_outputs.size() == 1) {
// special case: one output
return (*it)->uuid();
}
QCryptographicHash hash(QCryptographicHash::Md5);
for (; it != m_outputs.constEnd(); ++it) {
hash.addData((*it)->uuid());
}
return hash.result().toHex().left(10);
}
void DrmBackend::enableOutput(DrmOutput *output, bool enable)
{
if (enable) {
Q_ASSERT(!m_enabledOutputs.contains(output));
m_enabledOutputs << output;
emit output->gpu()->outputEnabled(output);
} else {
Q_ASSERT(m_enabledOutputs.contains(output));
m_enabledOutputs.removeOne(output);
Q_ASSERT(!m_enabledOutputs.contains(output));
emit output->gpu()->outputDisabled(output);
}
updateOutputsEnabled();
checkOutputsAreOn();
emit screensQueried();
}
DrmOutput *DrmBackend::findOutput(quint32 connector)
{
auto it = std::find_if(m_outputs.constBegin(), m_outputs.constEnd(), [connector] (DrmOutput *o) {
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc To get an image from KWin to the screen in the DRM pipeline we combine a CRTC, an encoder and a connector. These objects are static in the sense, that they represent real hardware on the graphics card, which doesn't change in a session. See here for more details: https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html Until now we used DrmOutput as the main representation for such an active rendering pipeline. I.e. it gets created and destroyed on hot plug events of displays. On the other side we had no fixed representation of the static kernel objects throughout the lifetime of KWin. This has several disadvantages: * We always need to query all available static objects on an hot plug event. * We can't manipulate the frame buffer of a CRTC after an output has been disconnected * Adding functionality for driving multiple displays on a single CRTC (i.e. cloning) would be difficult * We can't destroy the last frame buffer on display disconnect because the CRTC still accesses it and have therefore a memory leak on every display disconnect This patch solves these issues by storing representations of all available CRTC and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector instances. On an hotplug event these vectors are looped for a fitting CRTC and Connector combinations. Buffer handling is moved to the respective CRTC instance. All changes in overview: * Query all available CRTCs and Connectors and save for subsequent hotplug events * Fix logic errors in `queryResources()` * Move framebuffers, buffer flip and blank logic in DrmCrtc * Remove `restoreSaved()`. It isn't necessary and is dangerous if the old framebuffer was deleted in the meantime. Also could reveal sensitive user info from old session. Test Plan: Login, logout, VT switching, connect and disconnect external monitor, energy saving mode. Reviewers: #kwin Subscribers: kwin, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 21:02:49 +03:00
return o->m_conn->id() == connector;
});
if (it != m_outputs.constEnd()) {
return *it;
}
return nullptr;
}
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
bool DrmBackend::present(DrmBuffer *buffer, DrmOutput *output)
{
if (!buffer || buffer->bufferId() == 0) {
if (m_deleteBufferAfterPageFlip) {
delete buffer;
}
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
return false;
}
if (output->present(buffer)) {
m_pageFlipsPending++;
if (m_pageFlipsPending == 1 && Compositor::self()) {
Compositor::self()->aboutToSwapBuffers();
}
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
return true;
} else if (m_deleteBufferAfterPageFlip) {
delete buffer;
2015-04-13 10:23:03 +03:00
}
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
return false;
}
void DrmBackend::initCursor()
{
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
#if HAVE_EGL_STREAMS
// Hardware cursors aren't currently supported with EGLStream backend,
// possibly an NVIDIA driver bug
if (m_useEglStreams) {
setSoftWareCursor(true);
}
#endif
m_cursorEnabled = waylandServer()->seat()->hasPointer();
connect(waylandServer()->seat(), &KWaylandServer::SeatInterface::hasPointerChanged, this,
[this] {
m_cursorEnabled = waylandServer()->seat()->hasPointer();
if (usesSoftwareCursor()) {
return;
}
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
if (m_cursorEnabled) {
if (!(*it)->showCursor()) {
setSoftWareCursor(true);
break;
}
} else {
(*it)->hideCursor();
}
}
}
);
uint64_t capability = 0;
QSize cursorSize;
cursorSize.setWidth(64);
for (auto gpu : m_gpus) {
if (drmGetCap(gpu->fd(), DRM_CAP_CURSOR_WIDTH, &capability) == 0) {
cursorSize.setWidth(capability);
}
}
cursorSize.setHeight(64);
for (auto gpu : m_gpus) {
if (drmGetCap(gpu->fd(), DRM_CAP_CURSOR_HEIGHT, &capability) == 0) {
cursorSize.setHeight(capability);
}
}
m_cursorSize = cursorSize;
// now we have screens and can set cursors, so start tracking
connect(Cursors::self(), &Cursors::currentCursorChanged, this, &DrmBackend::updateCursor);
connect(Cursors::self(), &Cursors::positionChanged, this, &DrmBackend::moveCursor);
}
void DrmBackend::setCursor()
{
if (m_cursorEnabled) {
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
if (!(*it)->showCursor()) {
setSoftWareCursor(true);
}
}
}
Cursors::self()->currentCursor()->markAsRendered();
}
void DrmBackend::updateCursor()
{
if (usesSoftwareCursor()) {
return;
}
if (isCursorHidden()) {
return;
}
auto cursor = Cursors::self()->currentCursor();
const QImage &cursorImage = cursor->image();
if (cursorImage.isNull()) {
doHideCursor();
return;
}
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
(*it)->updateCursor();
}
setCursor();
moveCursor(cursor, cursor->pos());
}
void DrmBackend::doShowCursor()
{
updateCursor();
}
void DrmBackend::doHideCursor()
{
if (!m_cursorEnabled || usesSoftwareCursor()) {
return;
}
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
(*it)->hideCursor();
}
}
void DrmBackend::moveCursor(Cursor *cursor, const QPoint &pos)
{
if (!m_cursorEnabled || isCursorHidden() || usesSoftwareCursor()) {
return;
}
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
(*it)->moveCursor(cursor, pos);
}
}
Screens *DrmBackend::createScreens(QObject *parent)
{
return new DrmScreens(this, parent);
}
QPainterBackend *DrmBackend::createQPainterBackend()
{
m_deleteBufferAfterPageFlip = false;
return new DrmQPainterBackend(this, m_gpus.at(0));
}
OpenGLBackend *DrmBackend::createOpenGLBackend()
{
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
#if HAVE_EGL_STREAMS
if (m_useEglStreams) {
m_deleteBufferAfterPageFlip = false;
return new EglStreamBackend(this, m_gpus.at(0));
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
}
#endif
#if HAVE_GBM
m_deleteBufferAfterPageFlip = true;
return new EglGbmBackend(this, m_gpus.at(0));
#else
2016-04-07 10:18:10 +03:00
return Platform::createOpenGLBackend();
#endif
}
void DrmBackend::updateOutputsEnabled()
{
bool enabled = false;
for (auto it = m_enabledOutputs.constBegin(); it != m_enabledOutputs.constEnd(); ++it) {
enabled = enabled || (*it)->isDpmsEnabled();
}
setOutputsEnabled(enabled);
}
QVector<CompositingType> DrmBackend::supportedCompositors() const
{
if (selectedCompositor() != NoCompositing) {
return {selectedCompositor()};
}
#if HAVE_GBM
return QVector<CompositingType>{OpenGLCompositing, QPainterCompositing};
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
#elif HAVE_EGL_STREAMS
return m_useEglStreams ?
QVector<CompositingType>{OpenGLCompositing, QPainterCompositing} :
QVector<CompositingType>{QPainterCompositing};
#else
return QVector<CompositingType>{QPainterCompositing};
#endif
}
QString DrmBackend::supportInformation() const
{
QString supportInfo;
QDebug s(&supportInfo);
s.nospace();
s << "Name: " << "DRM" << Qt::endl;
s << "Active: " << m_active << Qt::endl;
for (int g = 0; g < m_gpus.size(); g++) {
s << "Atomic Mode Setting on GPU " << g << ": " << m_gpus.at(g)->atomicModeSetting() << Qt::endl;
}
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
#if HAVE_EGL_STREAMS
s << "Using EGL Streams: " << m_useEglStreams << Qt::endl;
[platforms/drm] EGLStream DRM Backend Initial Implementation Summary: This is the initial implementation of a DRM backend based on the EGLDevice, EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using their proprietary driver. The new backend will be used if the environment variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to create an EGLDevice based on the DRM device currently in use and create EGLOutputs and EGLStreams for any attached displays. These are used to control presentation of the final composited frame. Additionally, it will register the wl_eglstream_controller Wayland interface so that native EGL windows created by clients can be attached to an EGLStream allowing buffer contents to be shared with the compositor as a GL texture. At this time there are two known bugs in the NVIDIA driver's EGL implementation affecting desktop functionality. The first can result in tooltip windows drawn by plasmashell to contain incorrect contents. The second prevents KWayland from being able to query the format of EGLStream-backed buffers which interferes with the blur effect. Fixes for both of these are currently in development and should appear in an upcoming NVIDIA driver release. Additionally, hardware cursors are currently not supported with this backend. Enabling them causes the desktop to intermittently hang for several seconds. This is also likely a bug in the NVIDIA DRM-KMS implementation but the root cause is still under investigation. Test Plan: On a system with an NVIDIA graphics card running a recent release of their proprietary driver * Ensure the nvidia_drm kernel module is loaded with the option "modeset=1" ("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y") * Ensure EGL external platform support is installed https://github.com/NVIDIA/eglexternalplatform * Ensure KWin was build with the CMake option KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default) * Start a plasma wayland session with the environment variable KWIN_DRM_USE_EGL_STREAMS set * Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL driver is in use (as opposed to Mesa / llvmpipe). * Desktop should be fully functional and perform smoothly. Reviewers: #kwin, romangg, davidedmundson Reviewed By: #kwin, romangg, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 17:26:22 +03:00
#endif
return supportInfo;
}
DmaBufTexture *DrmBackend::createDmaBufTexture(const QSize &size)
{
#if HAVE_GBM
// gpu_index is a fixed 0 here
// as the first GPU is assumed to always be the one used for scene rendering
// and this function is only used for Pipewire
return GbmDmaBuf::createBuffer(size, m_gpus.at(0)->gbmDevice());
#else
return nullptr;
#endif
}
}