backends: don't duplicate file descriptors as often

Instead, move them when possible
This commit is contained in:
Xaver Hugl 2024-04-19 19:32:43 +00:00 committed by Vlad Zahorodnii
parent 7bd6b92110
commit 48197a4f5b
6 changed files with 15 additions and 15 deletions

View file

@ -198,7 +198,7 @@ bool EglGbmLayerSurface::endRendering(const QRegion &damagedRegion)
glDisable(GL_BLEND);
m_surface->currentShadowSlot->texture()->render(m_surface->gbmSwapchain->size());
EGLNativeFence fence(m_surface->context->displayObject());
m_surface->shadowSwapchain->release(m_surface->currentShadowSlot, fence.fileDescriptor().duplicate());
m_surface->shadowSwapchain->release(m_surface->currentShadowSlot, fence.takeFileDescriptor());
GLFramebuffer::popFramebuffer();
}
m_surface->damageJournal.add(damagedRegion);
@ -211,7 +211,7 @@ bool EglGbmLayerSurface::endRendering(const QRegion &damagedRegion)
glFinish();
}
m_surface->gbmSwapchain->release(m_surface->currentSlot, sourceFence.fileDescriptor().duplicate());
const auto buffer = importBuffer(m_surface.get(), m_surface->currentSlot.get(), sourceFence.fileDescriptor());
const auto buffer = importBuffer(m_surface.get(), m_surface->currentSlot.get(), sourceFence.takeFileDescriptor());
m_surface->renderEnd = std::chrono::steady_clock::now();
if (buffer) {
m_surface->currentFramebuffer = buffer;
@ -533,14 +533,14 @@ std::shared_ptr<DrmFramebuffer> EglGbmLayerSurface::doRenderTestBuffer(Surface *
}
}
std::shared_ptr<DrmFramebuffer> EglGbmLayerSurface::importBuffer(Surface *surface, EglSwapchainSlot *slot, const FileDescriptor &readFence) const
std::shared_ptr<DrmFramebuffer> EglGbmLayerSurface::importBuffer(Surface *surface, EglSwapchainSlot *slot, FileDescriptor &&readFence) const
{
if (surface->bufferTarget == BufferTarget::Dumb || surface->importMode == MultiGpuImportMode::DumbBuffer) {
return importWithCpu(surface, slot);
} else if (surface->importMode == MultiGpuImportMode::Egl) {
return importWithEgl(surface, slot->buffer(), readFence);
return importWithEgl(surface, slot->buffer(), std::move(readFence));
} else {
const auto ret = m_gpu->importBuffer(slot->buffer(), readFence.duplicate());
const auto ret = m_gpu->importBuffer(slot->buffer(), std::move(readFence));
if (!ret) {
qCWarning(KWIN_DRM, "Failed to create framebuffer: %s", strerror(errno));
}
@ -548,7 +548,7 @@ std::shared_ptr<DrmFramebuffer> EglGbmLayerSurface::importBuffer(Surface *surfac
}
}
std::shared_ptr<DrmFramebuffer> EglGbmLayerSurface::importWithEgl(Surface *surface, GraphicsBuffer *sourceBuffer, const FileDescriptor &readFence) const
std::shared_ptr<DrmFramebuffer> EglGbmLayerSurface::importWithEgl(Surface *surface, GraphicsBuffer *sourceBuffer, FileDescriptor &&readFence) const
{
Q_ASSERT(surface->importGbmSwapchain);
@ -564,7 +564,7 @@ std::shared_ptr<DrmFramebuffer> EglGbmLayerSurface::importWithEgl(Surface *surfa
surface->importTimeQuery->begin();
if (readFence.isValid()) {
const auto destinationFence = EGLNativeFence::importFence(surface->importContext->displayObject(), readFence.duplicate());
const auto destinationFence = EGLNativeFence::importFence(surface->importContext->displayObject(), std::move(readFence));
destinationFence.waitSync();
}
@ -609,7 +609,7 @@ std::shared_ptr<DrmFramebuffer> EglGbmLayerSurface::importWithEgl(Surface *surfa
// restore the old context
m_eglBackend->makeCurrent();
return m_gpu->importBuffer(slot->buffer(), endFence.fileDescriptor().duplicate());
return m_gpu->importBuffer(slot->buffer(), endFence.takeFileDescriptor());
}
std::shared_ptr<DrmFramebuffer> EglGbmLayerSurface::importWithCpu(Surface *surface, EglSwapchainSlot *source) const

View file

@ -118,8 +118,8 @@ private:
std::shared_ptr<EglSwapchain> createGbmSwapchain(DrmGpu *gpu, EglContext *context, const QSize &size, uint32_t format, const QList<uint64_t> &modifiers, MultiGpuImportMode importMode, BufferTarget bufferTarget) const;
std::shared_ptr<DrmFramebuffer> doRenderTestBuffer(Surface *surface) const;
std::shared_ptr<DrmFramebuffer> importBuffer(Surface *surface, EglSwapchainSlot *source, const FileDescriptor &readFence) const;
std::shared_ptr<DrmFramebuffer> importWithEgl(Surface *surface, GraphicsBuffer *sourceBuffer, const FileDescriptor &readFence) const;
std::shared_ptr<DrmFramebuffer> importBuffer(Surface *surface, EglSwapchainSlot *source, FileDescriptor &&readFence) const;
std::shared_ptr<DrmFramebuffer> importWithEgl(Surface *surface, GraphicsBuffer *sourceBuffer, FileDescriptor &&readFence) const;
std::shared_ptr<DrmFramebuffer> importWithCpu(Surface *surface, EglSwapchainSlot *source) const;
std::unique_ptr<Surface> m_surface;

View file

@ -92,7 +92,7 @@ bool VirtualEglGbmLayer::endFrame(const QRegion &renderedRegion, const QRegion &
m_damageJournal.add(damagedRegion);
EGLNativeFence releaseFence{m_eglBackend->eglDisplayObject()};
m_gbmSwapchain->release(m_currentSlot, releaseFence.fileDescriptor().duplicate());
m_gbmSwapchain->release(m_currentSlot, releaseFence.takeFileDescriptor());
return true;
}

View file

@ -110,7 +110,7 @@ bool WaylandEglPrimaryLayer::endFrame(const QRegion &renderedRegion, const QRegi
EGLNativeFence releaseFence{m_backend->eglDisplayObject()};
m_presentationBuffer = m_backend->backend()->importBuffer(m_buffer->buffer());
m_swapchain->release(m_buffer, releaseFence.fileDescriptor().duplicate());
m_swapchain->release(m_buffer, releaseFence.takeFileDescriptor());
m_damageJournal.add(damagedRegion);
return true;
@ -217,7 +217,7 @@ bool WaylandEglCursorLayer::endFrame(const QRegion &renderedRegion, const QRegio
m_output->cursor()->update(buffer, scale(), hotspot().toPoint());
EGLNativeFence releaseFence{m_backend->eglDisplayObject()};
m_swapchain->release(m_buffer, releaseFence.fileDescriptor().duplicate());
m_swapchain->release(m_buffer, releaseFence.takeFileDescriptor());
return true;
}

View file

@ -51,7 +51,7 @@ const FileDescriptor &EGLNativeFence::fileDescriptor() const
return m_fileDescriptor;
}
FileDescriptor &&EGLNativeFence::fileDescriptor()
FileDescriptor &&EGLNativeFence::takeFileDescriptor()
{
return std::move(m_fileDescriptor);
}

View file

@ -27,7 +27,7 @@ public:
bool isValid() const;
const FileDescriptor &fileDescriptor() const;
FileDescriptor &&fileDescriptor();
FileDescriptor &&takeFileDescriptor();
bool waitSync() const;
static EGLNativeFence importFence(EglDisplay *display, FileDescriptor &&fd);