Fix VRAM memory leak when releasing snapshots

This commit is contained in:
vaxerski 2022-07-12 23:11:34 +02:00
parent f9985a36b3
commit bf762f566f
6 changed files with 29 additions and 17 deletions

View file

@ -852,9 +852,12 @@ void CCompositor::moveWindowToTop(CWindow* pWindow) {
} }
} }
void CCompositor::cleanupFadingOut() { void CCompositor::cleanupFadingOut(const int& monid) {
for (auto& w : m_vWindowsFadingOut) { for (auto& w : m_vWindowsFadingOut) {
if (w->m_iMonitorID != (long unsigned int)monid)
continue;
bool valid = windowExists(w); bool valid = windowExists(w);
if (!valid || !w->m_bFadingOut || w->m_fAlpha.fl() == 0.f) { if (!valid || !w->m_bFadingOut || w->m_fAlpha.fl() == 0.f) {
@ -867,11 +870,16 @@ void CCompositor::cleanupFadingOut() {
m_vWindowsFadingOut.erase(std::remove(m_vWindowsFadingOut.begin(), m_vWindowsFadingOut.end(), w)); m_vWindowsFadingOut.erase(std::remove(m_vWindowsFadingOut.begin(), m_vWindowsFadingOut.end(), w));
Debug::log(LOG, "Cleanup: destroyed a window"); Debug::log(LOG, "Cleanup: destroyed a window");
glFlush(); // to free mem NOW.
return; return;
} }
} }
for (auto& ls : m_vSurfacesFadingOut) { for (auto& ls : m_vSurfacesFadingOut) {
if (ls->monitorID != monid)
continue;
if (ls->fadingOut && ls->readyToDelete && !ls->alpha.isBeingAnimated()) { if (ls->fadingOut && ls->readyToDelete && !ls->alpha.isBeingAnimated()) {
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
for (auto& lsl : m->m_aLayerSurfaceLists) { for (auto& lsl : m->m_aLayerSurfaceLists) {
@ -887,6 +895,7 @@ void CCompositor::cleanupFadingOut() {
Debug::log(LOG, "Cleanup: destroyed a layersurface"); Debug::log(LOG, "Cleanup: destroyed a layersurface");
glFlush(); // to free mem NOW.
return; return;
} }
} }

View file

@ -124,7 +124,7 @@ public:
bool doesSeatAcceptInput(wlr_surface*); bool doesSeatAcceptInput(wlr_surface*);
bool isWindowActive(CWindow*); bool isWindowActive(CWindow*);
void moveWindowToTop(CWindow*); void moveWindowToTop(CWindow*);
void cleanupFadingOut(); void cleanupFadingOut(const int& monid);
CWindow* getWindowInDirection(CWindow*, char); CWindow* getWindowInDirection(CWindow*, char);
void deactivateAllWLRWorkspaces(wlr_ext_workspace_handle_v1* exclude = nullptr); void deactivateAllWLRWorkspaces(wlr_ext_workspace_handle_v1* exclude = nullptr);
CWindow* getNextWindowOnWorkspace(CWindow*); CWindow* getNextWindowOnWorkspace(CWindow*);

View file

@ -186,7 +186,6 @@ void Events::listener_monitorFrame(void* owner, void* data) {
if (PMONITOR->ID == pMostHzMonitor->ID || !*PNOVFR) { // unfortunately with VFR we don't have the guarantee mostHz is going to be updated all the time, so we have to ignore that if (PMONITOR->ID == pMostHzMonitor->ID || !*PNOVFR) { // unfortunately with VFR we don't have the guarantee mostHz is going to be updated all the time, so we have to ignore that
g_pCompositor->sanityCheckWorkspaces(); g_pCompositor->sanityCheckWorkspaces();
g_pAnimationManager->tick(); g_pAnimationManager->tick();
g_pCompositor->cleanupFadingOut();
HyprCtl::tickHyprCtl(); // so that we dont get that race condition multithread bullshit HyprCtl::tickHyprCtl(); // so that we dont get that race condition multithread bullshit
@ -229,6 +228,9 @@ void Events::listener_monitorFrame(void* owner, void* data) {
return; return;
} }
// we need to cleanup fading out when rendering the appropriate context
g_pCompositor->cleanupFadingOut(PMONITOR->ID);
if (!hasChanged && *PDAMAGETRACKINGMODE != DAMAGE_TRACKING_NONE && PMONITOR->forceFullFrames == 0 && damageBlinkCleanup == 0) { if (!hasChanged && *PDAMAGETRACKINGMODE != DAMAGE_TRACKING_NONE && PMONITOR->forceFullFrames == 0 && damageBlinkCleanup == 0) {
pixman_region32_fini(&damage); pixman_region32_fini(&damage);
wlr_output_rollback(PMONITOR->output); wlr_output_rollback(PMONITOR->output);

View file

@ -3,14 +3,13 @@
bool CFramebuffer::alloc(int w, int h) { bool CFramebuffer::alloc(int w, int h) {
bool firstAlloc = false; bool firstAlloc = false;
if (m_iFb == (uint32_t)-1)
{ if (m_iFb == (uint32_t)-1) {
firstAlloc = true; firstAlloc = true;
glGenFramebuffers(1, &m_iFb); glGenFramebuffers(1, &m_iFb);
} }
if (m_cTex.m_iTexID == 0) if (m_cTex.m_iTexID == 0) {
{
firstAlloc = true; firstAlloc = true;
glGenTextures(1, &m_cTex.m_iTexID); glGenTextures(1, &m_cTex.m_iTexID);
glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID); glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
@ -20,13 +19,11 @@ bool CFramebuffer::alloc(int w, int h) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
} }
if (firstAlloc || m_Size != Vector2D(w, h)) if (firstAlloc || m_Size != Vector2D(w, h)) {
{
glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID); glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindFramebuffer(GL_FRAMEBUFFER, m_iFb); glBindFramebuffer(GL_FRAMEBUFFER, m_iFb);
glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_cTex.m_iTexID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_cTex.m_iTexID, 0);
@ -37,7 +34,6 @@ bool CFramebuffer::alloc(int w, int h) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0);
glBindFramebuffer(GL_FRAMEBUFFER, m_iFb); glBindFramebuffer(GL_FRAMEBUFFER, m_iFb);
glBindTexture(GL_TEXTURE_2D, m_pStencilTex->m_iTexID);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_pStencilTex->m_iTexID, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_pStencilTex->m_iTexID, 0);
} }
@ -78,3 +74,7 @@ void CFramebuffer::release() {
m_cTex.m_iTexID = 0; m_cTex.m_iTexID = 0;
m_iFb = -1; m_iFb = -1;
} }
CFramebuffer::~CFramebuffer() {
release();
}

View file

@ -6,6 +6,8 @@
class CFramebuffer { class CFramebuffer {
public: public:
~CFramebuffer();
bool alloc(int w, int h); bool alloc(int w, int h);
void bind(); void bind();
void release(); void release();

View file

@ -702,8 +702,6 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) {
begin(PMONITOR, &fakeDamage, true); begin(PMONITOR, &fakeDamage, true);
pixman_region32_fini(&fakeDamage);
clear(CColor(0,0,0,0)); // JIC clear(CColor(0,0,0,0)); // JIC
timespec now; timespec now;
@ -742,9 +740,10 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) {
#else #else
glBindFramebuffer(GL_FRAMEBUFFER, m_iCurrentOutputFb); glBindFramebuffer(GL_FRAMEBUFFER, m_iCurrentOutputFb);
#endif #endif
end(); end();
pixman_region32_fini(&fakeDamage);
wlr_output_rollback(PMONITOR->output); wlr_output_rollback(PMONITOR->output);
} }
@ -762,8 +761,6 @@ void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) {
begin(PMONITOR, &fakeDamage, true); begin(PMONITOR, &fakeDamage, true);
pixman_region32_fini(&fakeDamage);
const auto PFRAMEBUFFER = &m_mLayerFramebuffers[pLayer]; const auto PFRAMEBUFFER = &m_mLayerFramebuffers[pLayer];
glViewport(0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y); glViewport(0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y);
@ -792,6 +789,8 @@ void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) {
end(); end();
pixman_region32_fini(&fakeDamage);
wlr_output_rollback(PMONITOR->output); wlr_output_rollback(PMONITOR->output);
} }