diff options
| author | Tom Englund <tomenglund26@gmail.com> | 2024-10-31 00:20:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-30 23:20:32 +0000 |
| commit | 7c7a84ff60f8c1e00c6a0de3f7656f0bbd933d56 (patch) | |
| tree | 0ffb3d3664a5cad95197ddf66c5062b1dfddab82 /src/render/Renderer.cpp | |
| parent | a0b2169ed600b71627188dcd208b26911da8d583 (diff) | |
internal: more profiling less calls and local copies (#8300)
* compositor: reduce amount of window box copies
mousemoveunified can call this very frequently, the cbox copying
actually shows up as an impact in such cases, move it down in the scope
and only do it when necessery.
* core: constify and reference frequent calls
profiling shows these as frequent called functions try to reduce the
amount of copies with references and const the variables.
* pointermgr: remove not used local copy, const ref
remove unneded local copies and const ref cursorsize.
* inputmgr: reduce amount of calls to vectortowindow
the amount of calls to g_pCompositor->vectorToWindowUnified fast ramps
up in cpu usage with enough windows existing and moving the mouse, move
the PWINDOWIDEAL up and reuse it if its already the same.
* protocol: compositor remove unused local copy
remove unused local copy of accumulateCurrentBufferDamage and const
previousBuffer.
* renderer: reduce scope of variables and refactor
move a few variables down in their scopes to reduce the amount of calls
and copies when not needed, also add one more for loop in
renderWorkspaceWindows and store the windows in a vector with
weakpointers that should be rendered, this adds a loop but reduces the
amount of repeated calls to shouldRenderWindow and also makes the rest
of the loops go over way smaller vector when many windows exist.
Diffstat (limited to 'src/render/Renderer.cpp')
| -rw-r--r-- | src/render/Renderer.cpp | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 1c38eb4e..1dedcc7d 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -158,9 +158,7 @@ static void renderSurface(SP<CWLSurfaceResource> surface, int x, int y, void* da if (!surface->current.texture) return; - const auto& TEXTURE = surface->current.texture; - const auto RDATA = (SRenderData*)data; - const auto INTERACTIVERESIZEINPROGRESS = RDATA->pWindow && g_pInputManager->currentlyDraggedWindow && g_pInputManager->dragMode == MBIND_RESIZE; + const auto& TEXTURE = surface->current.texture; // this is bad, probably has been logged elsewhere. Means the texture failed // uploading to the GPU. @@ -175,6 +173,8 @@ static void renderSurface(SP<CWLSurfaceResource> surface, int x, int y, void* da } } + const auto RDATA = (SRenderData*)data; + const auto INTERACTIVERESIZEINPROGRESS = RDATA->pWindow && g_pInputManager->currentlyDraggedWindow && g_pInputManager->dragMode == MBIND_RESIZE; TRACY_GPU_ZONE("RenderSurface"); double outputX = -RDATA->pMonitor->vecPosition.x, outputY = -RDATA->pMonitor->vecPosition.y; @@ -484,36 +484,43 @@ void CHyprRenderer::renderWorkspaceWindows(PHLMONITOR pMonitor, PHLWORKSPACE pWo EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS); - // Non-floating main + std::vector<PHLWINDOWREF> windows; + windows.reserve(g_pCompositor->m_vWindows.size()); + for (auto const& w : g_pCompositor->m_vWindows) { if (w->isHidden() || (!w->m_bIsMapped && !w->m_bFadingOut)) continue; - if (w->m_bIsFloating) - continue; // floating are in the second pass - if (!shouldRenderWindow(w, pMonitor)) continue; + windows.push_back(w); + } + + // Non-floating main + for (auto& w : windows) { + if (w->m_bIsFloating) + continue; // floating are in the second pass + if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace()) continue; // render active window after all others of this pass if (w == g_pCompositor->m_pLastWindow) { - lastWindow = w; + lastWindow = w.lock(); continue; } // render the bad boy - renderWindow(w, pMonitor, time, true, RENDER_PASS_MAIN); + renderWindow(w.lock(), pMonitor, time, true, RENDER_PASS_MAIN); } if (lastWindow) renderWindow(lastWindow, pMonitor, time, true, RENDER_PASS_MAIN); // Non-floating popup - for (auto const& w : g_pCompositor->m_vWindows) { - if (w->isHidden() || (!w->m_bIsMapped && !w->m_bFadingOut)) + for (auto& w : windows) { + if (!w) continue; if (w->m_bIsFloating) @@ -522,24 +529,19 @@ void CHyprRenderer::renderWorkspaceWindows(PHLMONITOR pMonitor, PHLWORKSPACE pWo if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace()) continue; - if (!shouldRenderWindow(w, pMonitor)) - continue; - // render the bad boy - renderWindow(w, pMonitor, time, true, RENDER_PASS_POPUP); + renderWindow(w.lock(), pMonitor, time, true, RENDER_PASS_POPUP); + w.reset(); } // floating on top - for (auto const& w : g_pCompositor->m_vWindows) { - if (w->isHidden() || (!w->m_bIsMapped && !w->m_bFadingOut)) + for (auto& w : windows) { + if (!w) continue; if (!w->m_bIsFloating || w->m_bPinned) continue; - if (!shouldRenderWindow(w, pMonitor)) - continue; - if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace()) continue; @@ -547,7 +549,7 @@ void CHyprRenderer::renderWorkspaceWindows(PHLMONITOR pMonitor, PHLWORKSPACE pWo continue; // special on another are rendered as a part of the base pass // render the bad boy - renderWindow(w, pMonitor, time, true, RENDER_PASS_ALL); + renderWindow(w.lock(), pMonitor, time, true, RENDER_PASS_ALL); } } @@ -1093,8 +1095,8 @@ void CHyprRenderer::calculateUVForSurface(PHLWINDOW pWindow, SP<CWLSurfaceResour if (pSurface->current.viewport.hasSource) { // we stretch it to dest. if no dest, to 1,1 - Vector2D bufferSize = pSurface->current.bufferSize; - auto bufferSource = pSurface->current.viewport.source; + Vector2D const& bufferSize = pSurface->current.bufferSize; + auto const& bufferSource = pSurface->current.viewport.source; // calculate UV for the basic src_box. Assume dest == size. Scale to dest later uvTL = Vector2D(bufferSource.x / bufferSize.x, bufferSource.y / bufferSize.y); @@ -1904,10 +1906,11 @@ void CHyprRenderer::damageBox(CBox* pBox, bool skipFrameSchedule) { if (m->isMirror()) continue; // don't damage mirrors traditionally - CBox damageBox = {pBox->x - m->vecPosition.x, pBox->y - m->vecPosition.y, pBox->width, pBox->height}; - damageBox.scale(m->scale); - if (!skipFrameSchedule) + if (!skipFrameSchedule) { + CBox damageBox = {pBox->x - m->vecPosition.x, pBox->y - m->vecPosition.y, pBox->width, pBox->height}; + damageBox.scale(m->scale); m->addDamage(&damageBox); + } } static auto PLOGDAMAGE = CConfigValue<Hyprlang::INT>("debug:log_damage"); |
