Commit 7a48ec6e authored by Xaver Hugl's avatar Xaver Hugl
Browse files

platforms/drm: some improvements for logging


(cherry picked from commit 9194c0c9)
parent a2962635
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2021 Xaver Hugl <xaver.hugl@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <epoxy/egl.h>
#include <QString>
static QString getEglErrorString(EGLint errorCode)
{
switch(errorCode) {
case EGL_SUCCESS: return QStringLiteral("EGL_SUCCESS");
case EGL_NOT_INITIALIZED: return QStringLiteral("EGL_NOT_INITIALIZED");
case EGL_BAD_ACCESS: return QStringLiteral("EGL_BAD_ACCESS");
case EGL_BAD_ALLOC: return QStringLiteral("EGL_BAD_ALLOC");
case EGL_BAD_ATTRIBUTE: return QStringLiteral("EGL_BAD_ATTRIBUTE");
case EGL_BAD_CONTEXT: return QStringLiteral("EGL_BAD_CONTEXT");
case EGL_BAD_CONFIG: return QStringLiteral("EGL_BAD_CONFIG");
case EGL_BAD_CURRENT_SURFACE: return QStringLiteral("EGL_BAD_CURRENT_SURFACE");
case EGL_BAD_DISPLAY: return QStringLiteral("EGL_BAD_DISPLAY");
case EGL_BAD_SURFACE: return QStringLiteral("EGL_BAD_SURFACE");
case EGL_BAD_MATCH: return QStringLiteral("EGL_BAD_MATCH");
case EGL_BAD_PARAMETER: return QStringLiteral("EGL_BAD_PARAMETER");
case EGL_BAD_NATIVE_PIXMAP: return QStringLiteral("EGL_BAD_NATIVE_PIXMAP");
case EGL_BAD_NATIVE_WINDOW: return QStringLiteral("EGL_BAD_NATIVE_WINDOW");
case EGL_CONTEXT_LOST: return QStringLiteral("EGL_CONTEXT_LOST");
default:
return QString::number(errorCode, 16);
}
}
static QString getEglErrorString()
{
return getEglErrorString(eglGetError());
}
......@@ -38,7 +38,7 @@ DrmDumbBuffer::DrmDumbBuffer(DrmGpu *gpu, const QSize &size)
createArgs.width = size.width();
createArgs.height = size.height();
if (drmIoctl(m_gpu->fd(), DRM_IOCTL_MODE_CREATE_DUMB, &createArgs) != 0) {
qCWarning(KWIN_DRM) << "DRM_IOCTL_MODE_CREATE_DUMB failed";
qCWarning(KWIN_DRM) << "DRM_IOCTL_MODE_CREATE_DUMB failed" << strerror(errno);
return;
}
m_handle = createArgs.handle;
......@@ -46,7 +46,7 @@ DrmDumbBuffer::DrmDumbBuffer(DrmGpu *gpu, const QSize &size)
m_stride = createArgs.pitch;
if (drmModeAddFB(m_gpu->fd(), size.width(), size.height(), 24, 32,
m_stride, createArgs.handle, &m_bufferId) != 0) {
qCWarning(KWIN_DRM) << "drmModeAddFB failed with errno" << errno;
qCWarning(KWIN_DRM) << "drmModeAddFB failed!" << strerror(errno);
}
}
......
......@@ -35,7 +35,7 @@ GbmBuffer::GbmBuffer(const QSharedPointer<GbmSurface> &surface)
if (m_bo) {
m_stride = gbm_bo_get_stride(m_bo);
} else {
qCWarning(KWIN_DRM) << "failed to lock front buffer!" << strerror(errno);
qCCritical(KWIN_DRM) << "failed to lock front buffer!" << strerror(errno);
}
}
......@@ -97,7 +97,6 @@ DrmGbmBuffer::DrmGbmBuffer(DrmGpu *gpu, const QSharedPointer<GbmSurface> &surfac
: DrmBuffer(gpu), GbmBuffer(surface)
{
if (!m_bo) {
qCWarning(KWIN_DRM) << "Locking front buffer failed";
return;
}
initialize();
......@@ -112,7 +111,9 @@ DrmGbmBuffer::DrmGbmBuffer(DrmGpu *gpu, gbm_bo *buffer, KWaylandServer::BufferIn
DrmGbmBuffer::~DrmGbmBuffer()
{
if (m_bufferId) {
drmModeRmFB(m_gpu->fd(), m_bufferId);
if (drmModeRmFB(m_gpu->fd(), m_bufferId) != 0) {
qCCritical(KWIN_DRM) << "drmModeRmFB on GPU" << m_gpu->devNode() << "failed!" << strerror(errno);
}
}
}
......@@ -124,6 +125,7 @@ void DrmGbmBuffer::releaseGbm()
void DrmGbmBuffer::initialize()
{
m_size = QSize(gbm_bo_get_width(m_bo), gbm_bo_get_height(m_bo));
uint32_t format = gbm_bo_get_format(m_bo);
uint32_t handles[4] = { };
uint32_t strides[4] = { };
uint32_t offsets[4] = { };
......@@ -143,14 +145,18 @@ void DrmGbmBuffer::initialize()
}
if (modifiers[0] != DRM_FORMAT_MOD_INVALID && m_gpu->addFB2ModifiersSupported()) {
if (drmModeAddFB2WithModifiers(m_gpu->fd(), m_size.width(), m_size.height(), gbm_bo_get_format(m_bo), handles, strides, offsets, modifiers, &m_bufferId, DRM_MODE_FB_MODIFIERS)) {
qCWarning(KWIN_DRM) << "drmModeAddFB2WithModifiers failed!" << strerror(errno);
if (drmModeAddFB2WithModifiers(m_gpu->fd(), m_size.width(), m_size.height(), format, handles, strides, offsets, modifiers, &m_bufferId, DRM_MODE_FB_MODIFIERS)) {
gbm_format_name_desc name;
gbm_format_get_name(format, &name);
qCCritical(KWIN_DRM) << "drmModeAddFB2WithModifiers on GPU" << m_gpu->devNode() << "failed for a buffer with format" << name.name << "and modifier" << modifiers[0] << strerror(errno);
}
} else {
if (drmModeAddFB2(m_gpu->fd(), m_size.width(), m_size.height(), gbm_bo_get_format(m_bo), handles, strides, offsets, &m_bufferId, 0)) {
if (drmModeAddFB2(m_gpu->fd(), m_size.width(), m_size.height(), format, handles, strides, offsets, &m_bufferId, 0)) {
// fallback
if (drmModeAddFB(m_gpu->fd(), m_size.width(), m_size.height(), 24, 32, strides[0], handles[0], &m_bufferId) != 0) {
qCWarning(KWIN_DRM) << "drmModeAddFB2 and drmModeAddFB both failed!" << strerror(errno);
gbm_format_name_desc name;
gbm_format_get_name(format, &name);
qCCritical(KWIN_DRM) << "drmModeAddFB2 and drmModeAddFB both failed on GPU" << m_gpu->devNode() << "for a buffer with format" << name.name << "and modifier" << modifiers[0] << strerror(errno);
}
}
}
......
......@@ -67,7 +67,7 @@ DrmGpu::DrmGpu(DrmBackend *backend, const QString &devNode, int fd, dev_t device
if (!qEnvironmentVariableIsSet("KWIN_DRM_NO_MODIFIERS")) {
m_addFB2ModifiersSupported = drmGetCap(fd, DRM_CAP_ADDFB2_MODIFIERS, &capability) == 0 && capability == 1;
qCDebug(KWIN_DRM) << "drmModeAddFB2WithModifiers is" << (m_addFB2ModifiersSupported ? "supported" : "not supported");
qCDebug(KWIN_DRM) << "drmModeAddFB2WithModifiers is" << (m_addFB2ModifiersSupported ? "supported" : "not supported") << "on GPU" << m_devNode;
}
// find out if this GPU is using the NVidia proprietary driver
......@@ -277,7 +277,6 @@ bool DrmGpu::updateOutputs()
output->m_primaryPlane = primary;
output->m_mode = connector->modes[0];
qCDebug(KWIN_DRM) << "For new output use mode " << output->m_mode.name << output->m_mode.hdisplay << output->m_mode.vdisplay;
if (!output->init(connector.data())) {
qCWarning(KWIN_DRM) << "Failed to create output for connector " << con->id();
delete output;
......@@ -286,7 +285,7 @@ bool DrmGpu::updateOutputs()
if (!output->initCursor(m_cursorSize)) {
m_backend->setSoftwareCursorForced(true);
}
qCDebug(KWIN_DRM) << "Found new output with uuid" << output->uuid() << "on gpu" << m_devNode;
qCDebug(KWIN_DRM, "For new output %s on GPU %s use mode %dx%d@%d", qPrintable(output->name()), qPrintable(m_devNode), output->m_mode.hdisplay, output->m_mode.vdisplay, output->refreshRate());
connectedOutputs << output;
emit outputAdded(output);
......
......@@ -21,6 +21,7 @@
#include "drm_gpu.h"
#include "linux_dmabuf.h"
#include "dumb_swapchain.h"
#include "kwineglutils_p.h"
// kwin libs
#include <kwinglplatform.h>
#include <kwineglimagetexture.h>
......@@ -171,7 +172,7 @@ EGLSurface EglGbmBackend::createEglSurface(QSharedPointer<GbmSurface> gbmSurface
auto eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(),
(void *)(gbmSurface->surface()), nullptr);
if (eglSurface == EGL_NO_SURFACE) {
qCCritical(KWIN_DRM) << "Creating EGL surface failed";
qCCritical(KWIN_DRM) << "Creating EGL surface failed:" << getEglErrorString();
return EGL_NO_SURFACE;
}
return eglSurface;
......@@ -193,7 +194,7 @@ bool EglGbmBackend::resetOutput(Output &output, DrmOutput *drmOutput)
GBM_FORMAT_XRGB8888,
flags);
if (!gbmSurface) {
qCCritical(KWIN_DRM) << "Creating GBM surface failed";
qCCritical(KWIN_DRM) << "Creating GBM surface failed" << strerror(errno);
return false;
}
auto eglSurface = createEglSurface(gbmSurface);
......@@ -328,7 +329,7 @@ int EglGbmBackend::exportFramebufferAsDmabuf(DrmOutput *output, uint32_t *format
}
int fd = gbm_bo_get_fd(it->secondaryBuffer->getBo());
if (fd == -1) {
qCDebug(KWIN_DRM) << "failed to export gbm_bo as dma-buf!";
qCWarning(KWIN_DRM) << "failed to export gbm_bo as dma-buf:" << strerror(errno);
return -1;
}
*format = gbm_bo_get_format(it->secondaryBuffer->getBo());
......@@ -541,7 +542,7 @@ bool EglGbmBackend::makeContextCurrent(const Output &output) const
return false;
}
if (eglMakeCurrent(eglDisplay(), surface, surface, context()) == EGL_FALSE) {
qCCritical(KWIN_DRM) << "Make Context Current failed" << eglGetError();
qCCritical(KWIN_DRM) << "eglMakeCurrent failed:" << getEglErrorString();
return false;
}
return true;
......@@ -565,7 +566,7 @@ bool EglGbmBackend::initBufferConfigs()
if (!eglChooseConfig(eglDisplay(), config_attribs, configs,
sizeof(configs) / sizeof(EGLConfig),
&count)) {
qCCritical(KWIN_DRM) << "choose config failed";
qCCritical(KWIN_DRM) << "eglChooseConfig failed:" << getEglErrorString();
return false;
}
......@@ -636,7 +637,7 @@ void EglGbmBackend::aboutToStartPainting(int screenId, const QRegion &damagedReg
const bool correct = eglSetDamageRegionKHR(eglDisplay(), output.eglSurface,
rects.data(), rects.count()/4);
if (!correct) {
qCWarning(KWIN_DRM) << "failed eglSetDamageRegionKHR" << eglGetError();
qCWarning(KWIN_DRM) << "eglSetDamageRegionKHR failed:" << getEglErrorString();
}
}
}
......@@ -648,12 +649,12 @@ bool EglGbmBackend::presentOnOutput(Output &output, const QRegion &damagedRegion
QVector<EGLint> rects = regionToRects(damagedRegion, output.output);
if (!eglSwapBuffersWithDamageEXT(eglDisplay(), output.eglSurface,
rects.data(), rects.count() / 4)) {
qCCritical(KWIN_DRM, "eglSwapBuffersWithDamageEXT() failed: %x", eglGetError());
qCCritical(KWIN_DRM) << "eglSwapBuffersWithDamageEXT() failed:" << getEglErrorString();
return false;
}
} else {
if (!eglSwapBuffers(eglDisplay(), output.eglSurface)) {
qCCritical(KWIN_DRM, "eglSwapBuffers() failed: %x", eglGetError());
qCCritical(KWIN_DRM) << "eglSwapBuffers() failed:" << getEglErrorString();
return false;
}
}
......@@ -813,7 +814,7 @@ bool EglGbmBackend::scanout(int screenId, SurfaceItem *surfaceItem)
}
if (!importedBuffer) {
if (errno != EINVAL) {
qCWarning(KWIN_DRM) << "Importing buffer for direct scanout failed!" << strerror(errno);
qCWarning(KWIN_DRM) << "Importing buffer for direct scanout failed:" << strerror(errno);
}
return false;
}
......
......@@ -21,6 +21,7 @@
#include <kwinglplatform.h>
#include "drm_gpu.h"
#include "dumb_swapchain.h"
#include "kwineglutils_p.h"
#include <QOpenGLContext>
#include <KWaylandServer/buffer_interface.h>
......@@ -208,7 +209,7 @@ void EglStreamBackend::attachStreamConsumer(KWaylandServer::SurfaceInterface *su
EGLStreamKHR stream = pEglCreateStreamAttribNV(eglDisplay(), streamAttribs.data());
if (stream == EGL_NO_STREAM_KHR) {
qCWarning(KWIN_DRM) << "Failed to create EGL stream";
qCWarning(KWIN_DRM) << "Failed to create EGL stream:" << getEglErrorString();
return;
}
......@@ -237,7 +238,7 @@ void EglStreamBackend::attachStreamConsumer(KWaylandServer::SurfaceInterface *su
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
if (!pEglStreamConsumerGLTextureExternalKHR(eglDisplay(), stream)) {
qCWarning(KWIN_DRM) << "Failed to bind EGL stream to texture";
qCWarning(KWIN_DRM) << "Failed to bind EGL stream to texture:" << getEglErrorString();
}
glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
}
......@@ -312,7 +313,7 @@ bool EglStreamBackend::resetOutput(Output &o, DrmOutput *drmOutput)
};
EGLStreamKHR stream = pEglCreateStreamAttribNV(eglDisplay(), streamAttribs);
if (stream == EGL_NO_STREAM_KHR) {
qCCritical(KWIN_DRM) << "Failed to create EGL stream for output";
qCCritical(KWIN_DRM) << "Failed to create EGL stream for output:" << getEglErrorString();
return false;
}
......@@ -342,7 +343,7 @@ bool EglStreamBackend::resetOutput(Output &o, DrmOutput *drmOutput)
EGLSurface eglSurface = pEglCreateStreamProducerSurfaceKHR(eglDisplay(), config(), stream,
streamProducerAttribs);
if (eglSurface == EGL_NO_SURFACE) {
qCCritical(KWIN_DRM) << "Failed to create EGL surface for output";
qCCritical(KWIN_DRM) << "Failed to create EGL surface for output:" << getEglErrorString();
return false;
}
......@@ -423,13 +424,13 @@ bool EglStreamBackend::makeContextCurrent(const Output &output)
}
if (eglMakeCurrent(eglDisplay(), surface, surface, context()) == EGL_FALSE) {
qCCritical(KWIN_DRM) << "Failed to make EGL context current";
qCCritical(KWIN_DRM) << "Failed to make EGL context current:" << getEglErrorString();
return false;
}
EGLint error = eglGetError();
if (error != EGL_SUCCESS) {
qCWarning(KWIN_DRM) << "Error occurred while making EGL context current" << error;
qCWarning(KWIN_DRM) << "Error occurred while making EGL context current:" << getEglErrorString(error);
return false;
}
......@@ -456,7 +457,7 @@ bool EglStreamBackend::initBufferConfigs()
EGLint count;
EGLConfig config;
if (!eglChooseConfig(eglDisplay(), configAttribs, &config, 1, &count)) {
qCCritical(KWIN_DRM) << "Failed to query available EGL configs";
qCCritical(KWIN_DRM) << "Failed to query available EGL configs:" << getEglErrorString();
return false;
}
if (count == 0) {
......@@ -498,7 +499,7 @@ void EglStreamBackend::endFrame(int screenId, const QRegion &renderedRegion, con
if (isPrimary()) {
buffer = renderOutput.buffer;
if (!eglSwapBuffers(eglDisplay(), renderOutput.eglSurface)) {
qCCritical(KWIN_DRM, "eglSwapBuffers() failed: %x", eglGetError());
qCCritical(KWIN_DRM) << "eglSwapBuffers() failed:" << getEglErrorString();
frameFailed = true;
}
} else {
......@@ -525,7 +526,7 @@ void EglStreamBackend::endFrame(int screenId, const QRegion &renderedRegion, con
EGL_NONE,
};
if (!pEglStreamConsumerAcquireAttribNV(eglDisplay(), renderOutput.eglStream, acquireAttribs)) {
qCWarning(KWIN_DRM) << "Failed to acquire output EGL stream frame";
qCWarning(KWIN_DRM) << "Failed to acquire output EGL stream frame:" << getEglErrorString();
}
}
}
......@@ -550,7 +551,7 @@ bool EglStreamTexture::acquireStreamFrame(EGLStreamKHR stream)
EGLAttrib streamState;
if (!pEglQueryStreamAttribNV(m_backend->eglDisplay(), stream,
EGL_STREAM_STATE_KHR, &streamState)) {
qCWarning(KWIN_DRM) << "Failed to query EGL stream state";
qCWarning(KWIN_DRM) << "Failed to query EGL stream state:" << getEglErrorString();
return false;
}
......@@ -558,7 +559,7 @@ bool EglStreamTexture::acquireStreamFrame(EGLStreamKHR stream)
if (pEglStreamConsumerAcquireAttribNV(m_backend->eglDisplay(), stream, nullptr)) {
return true;
} else {
qCWarning(KWIN_DRM) << "Failed to acquire EGL stream frame";
qCWarning(KWIN_DRM) << "Failed to acquire EGL stream frame:" << getEglErrorString();
}
}
......@@ -656,7 +657,7 @@ bool EglStreamTexture::loadTexture(WindowPixmap *pixmap)
if (acquireStreamFrame(st->stream)) {
copyExternalTexture(st->texture);
if (!pEglStreamConsumerReleaseKHR(m_backend->eglDisplay(), st->stream)) {
qCWarning(KWIN_DRM) << "Failed to release EGL stream";
qCWarning(KWIN_DRM) << "Failed to release EGL stream:" << getEglErrorString();
}
}
return true;
......@@ -680,7 +681,7 @@ void EglStreamTexture::updateTexture(WindowPixmap *pixmap, const QRegion &region
if (acquireStreamFrame(st->stream)) {
copyExternalTexture(st->texture);
if (!pEglStreamConsumerReleaseKHR(m_backend->eglDisplay(), st->stream)) {
qCWarning(KWIN_DRM) << "Failed to release EGL stream";
qCWarning(KWIN_DRM) << "Failed to release EGL stream:" << getEglErrorString();
}
}
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment