From 901103af3f95b0dfacc1fca77c773955b5e64f74 Mon Sep 17 00:00:00 2001 From: "Pierre-Loup A. Griffais" Date: Mon, 13 Jan 2020 22:09:55 -0800 Subject: [PATCH] wlserver: anti-fd exhaustion measures. If we only take the first commit, we leave a bunch in the queue, which makes us that much more likely to run out of FDs when importing the myriad of buffer referenced coming from a non-vsynced client. Fixes crashes with vblank_mode=0 glxgears after the recent changes. We were always subject to such crashes, just getting lucky/fast before. --- src/steamcompmgr.c | 22 ++++++++++++---------- src/wlserver.c | 9 +++++++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/steamcompmgr.c b/src/steamcompmgr.c index 4b66a18..056ad76 100644 --- a/src/steamcompmgr.c +++ b/src/steamcompmgr.c @@ -349,6 +349,13 @@ ensure_win_resources (Display *dpy, win *w) // We'll also need a copy for Vulkan to consume below. int fdCopy = dup( w->dmabuf_attribs.fd[0] ); + + if ( fdCopy == -1 ) + { + w->dmabuf_attribs_valid = False; + close( w->dmabuf_attribs.fd[0] ); + return; + } w->fb_id = drm_fbid_from_dmabuf( &g_DRM, &w->dmabuf_attribs ); assert( w->fb_id != 0 ); @@ -779,18 +786,10 @@ paint_all (Display *dpy) if (drawDebugInfo) paint_debug_info(dpy); - for ( int i = 0; i < k_nMaxLayers; i++ ) + if ( BIsNested() == false ) { - bool bHasSeenZero = false; - - if ( pipeline.layerBindings[ i ].tex == 0 ) + if ( pipeline.layerBindings[ 0 ].fbid == 0 ) { - bHasSeenZero = true; - } - else if ( bHasSeenZero == true ) - { - // We have a hole in this binding that will cause GPU crashes. - // TODO write compacting code here return; } } @@ -1635,6 +1634,9 @@ void check_new_wayland_res(void) // Existing data here hasn't been consumed - need to consume the dma-buf fd close(w->dmabuf_attribs.fd[0]); } + + assert( newEntry.attribs.fd[0] != -1 ); + w->dmabuf_attribs = newEntry.attribs; w->dmabuf_attribs_valid = True; diff --git a/src/wlserver.c b/src/wlserver.c index b4da4c7..b085d26 100644 --- a/src/wlserver.c +++ b/src/wlserver.c @@ -67,9 +67,14 @@ static void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) { bool result = False; result = wlr_texture_to_dmabuf( tex, &dmabuf_attribs ); - if (result == False) + assert( result == true ); + if ( result == false || dmabuf_attribs.fd[0] == -1 ) { - // + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + wlr_surface_send_frame_done( wlr_surface, &now ); + return; } gpuvis_trace_printf( "xwayland_surface_role_commit wlr_surface %p\n", wlr_surface );