From cf1886ca44c78de3424d96fd18023eb0db759af6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 2 Feb 2024 15:36:13 +0000 Subject: [PATCH] renderer: avoid unnecessary gpu resource deletions fixes #4594 --- src/render/OpenGL.cpp | 9 +++++---- src/render/Renderer.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index e855809a..889a23bb 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -212,13 +212,16 @@ void CHyprOpenGLImpl::begin(CMonitor* pMonitor, CRegion* pDamage, CFramebuffer* matrixProjection(m_RenderData.projection, pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y, WL_OUTPUT_TRANSFORM_NORMAL); + if (m_mMonitorRenderResources.contains(pMonitor) && m_mMonitorRenderResources.at(pMonitor).offloadFB.m_vSize != pMonitor->vecPixelSize) + destroyMonitorResources(pMonitor); + m_RenderData.pCurrentMonData = &m_mMonitorRenderResources[pMonitor]; if (!m_RenderData.pCurrentMonData->m_bShadersInitialized) initShaders(); // ensure a framebuffer for the monitor exists - if (!m_mMonitorRenderResources.contains(pMonitor) || m_RenderData.pCurrentMonData->offloadFB.m_vSize != pMonitor->vecPixelSize) { + if (m_RenderData.pCurrentMonData->offloadFB.m_vSize != pMonitor->vecPixelSize) { m_RenderData.pCurrentMonData->stencilTex.allocate(); m_RenderData.pCurrentMonData->offloadFB.m_pStencilTex = &m_RenderData.pCurrentMonData->stencilTex; @@ -230,8 +233,6 @@ void CHyprOpenGLImpl::begin(CMonitor* pMonitor, CRegion* pDamage, CFramebuffer* m_RenderData.pCurrentMonData->mirrorFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y, pMonitor->drmFormat); m_RenderData.pCurrentMonData->mirrorSwapFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y, pMonitor->drmFormat); m_RenderData.pCurrentMonData->offMainFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y, pMonitor->drmFormat); - - createBGTextureForMonitor(pMonitor); } if (m_RenderData.pCurrentMonData->monitorMirrorFB.isAllocated() && m_RenderData.pMonitor->mirrors.empty()) @@ -2000,7 +2001,7 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) { const auto CAIROSURFACE = cairo_image_surface_create(CAIROFORMAT, scaledSize.x, scaledSize.y); const auto CAIRO = cairo_create(CAIROSURFACE); - cairo_set_antialias(CAIRO, CAIRO_ANTIALIAS_BEST); + cairo_set_antialias(CAIRO, CAIRO_ANTIALIAS_GOOD); cairo_scale(CAIRO, scale, scale); cairo_rectangle(CAIRO, 0, 0, 100, 100); cairo_set_source_surface(CAIRO, CAIROISURFACE, 0, 0); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 38b5d151..68df3418 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1767,6 +1767,9 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR return true; } + const auto WAS10B = pMonitor->enabled10bit; + const auto OLDRES = pMonitor->vecPixelSize; + // Needed in case we are switching from a custom modeline to a standard mode pMonitor->customDrmMode = {}; bool autoScale = false; @@ -2107,8 +2110,8 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR pMonitor->updateMatrix(); - // update renderer (here because it will call rollback, so we cannot do this before committing) - g_pHyprOpenGL->destroyMonitorResources(pMonitor); + if (WAS10B != pMonitor->enabled10bit || OLDRES != pMonitor->vecPixelSize) + g_pHyprOpenGL->destroyMonitorResources(pMonitor); // updato wlroots g_pCompositor->arrangeMonitors();