From b822e255d85793a841ef85a74cda21c5a9b5bc82 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 7 Aug 2021 19:49:55 -0400 Subject: [PATCH] [client] egl: attempt DMABUF import and fallback if it fails This should deal with drivers not supporting our DMABUF without attempting to identify the drivers and blacklist them. --- client/renderers/EGL/desktop.c | 28 +++++++++++++++++++++------- client/renderers/EGL/egl.c | 15 +-------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/client/renderers/EGL/desktop.c b/client/renderers/EGL/desktop.c index c5db389c..75b01ba6 100644 --- a/client/renderers/EGL/desktop.c +++ b/client/renderers/EGL/desktop.c @@ -72,6 +72,9 @@ struct EGL_Desktop // colorblind mode int cbMode; + + bool useDMA; + LG_RendererFormat format; }; // forwards @@ -146,6 +149,7 @@ bool egl_desktop_init(EGL_Desktop ** desktop, EGLDisplay * display, bool useDMA, (*desktop)->nvGain = option_get_int("egl", "nvGain" ); (*desktop)->cbMode = option_get_int("egl", "cbMode" ); (*desktop)->scaleAlgo = option_get_int("egl", "scale" ); + (*desktop)->useDMA = useDMA; return true; } @@ -226,6 +230,8 @@ void egl_desktop_config_ui(EGL_Desktop * desktop) bool egl_desktop_setup(EGL_Desktop * desktop, const LG_RendererFormat format) { + memcpy(&desktop->format, &format, sizeof(LG_RendererFormat)); + enum EGL_PixelFormat pixFmt; switch(format.type) { @@ -275,18 +281,26 @@ bool egl_desktop_setup(EGL_Desktop * desktop, const LG_RendererFormat format) bool egl_desktop_update(EGL_Desktop * desktop, const FrameBuffer * frame, int dmaFd, const FrameDamageRect * damageRects, int damageRectsCount) { - if (dmaFd >= 0) + if (desktop->useDMA && dmaFd >= 0) { - if (!egl_texture_update_from_dma(desktop->texture, frame, dmaFd)) + if (egl_texture_update_from_dma(desktop->texture, frame, dmaFd)) + return true; + + DEBUG_WARN("DMA update failed, disabling DMABUF imports"); + desktop->useDMA = false; + + egl_texture_free(&desktop->texture); + if (!egl_texture_init(&desktop->texture, desktop->display, EGL_TEXTYPE_FRAMEBUFFER, true)) + { + DEBUG_ERROR("Failed to initialize the desktop texture"); return false; - } - else - { - if (!egl_texture_update_from_frame(desktop->texture, frame, damageRects, damageRectsCount)) + } + + if (!egl_desktop_setup(desktop, desktop->format)) return false; } - return true; + return egl_texture_update_from_frame(desktop->texture, frame, damageRects, damageRectsCount); } bool egl_desktop_render(EGL_Desktop * desktop, const float x, const float y, diff --git a/client/renderers/EGL/egl.c b/client/renderers/EGL/egl.c index 9b2c49d3..0fd33e40 100644 --- a/client/renderers/EGL/egl.c +++ b/client/renderers/EGL/egl.c @@ -749,20 +749,7 @@ static bool egl_render_startup(void * opaque, bool useDMA) if (g_egl_dynProcs.glEGLImageTargetTexture2DOES) { if (util_hasGLExt(client_exts, "EGL_EXT_image_dma_buf_import")) - { - /* - * As of version 455.45.01 NVidia started advertising support for this - * feature, however even on the latest version 460.27.04 this is still - * broken and does not work, until this is fixed and we have way to detect - * this early just disable dma for all NVIDIA devices. - * - * ref: https://forums.developer.nvidia.com/t/egl-ext-image-dma-buf-import-broken-egl-bad-alloc-with-tons-of-free-ram/165552 - */ - if (strstr(vendor, "NVIDIA") != NULL) - DEBUG_WARN("NVIDIA driver detected, ignoring broken DMA support"); - else - this->dmaSupport = true; - } + this->dmaSupport = true; else DEBUG_INFO("EGL_EXT_image_dma_buf_import unavailable, DMA support disabled"); }