From d86f39e7cf2be741ba9787588da8fe12c1ed394b Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 29 Jul 2024 09:58:33 -0400 Subject: [PATCH] egl: swap DRI_IMAGE checks for dmabuf/modifier support for driver check this probably also enables usage on swrast when available Reviewed-by: Adam Jackson Part-of: --- src/egl/drivers/dri2/egl_dri2.c | 32 +++++++++++++------------ src/egl/drivers/dri2/egl_dri2.h | 4 +++- src/egl/drivers/dri2/platform_wayland.c | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 41bbabf97f0..52935f18077 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -719,6 +719,17 @@ dri2_setup_screen(_EGLDisplay *disp) struct pipe_screen *pscreen = screen->base.screen; unsigned int api_mask = screen->api_mask; +#ifdef HAVE_DRI3 + bool has_modifiers = true; + if (disp->Platform == _EGL_PLATFORM_X11 || + disp->Platform == _EGL_PLATFORM_XCB) + has_modifiers = dri2_dpy->multibuffers_available; + int caps = get_screen_param(disp, PIPE_CAP_DMABUF); + /* set if both import and export are suported */ + dri2_dpy->has_modifiers = has_modifiers && util_bitcount(caps) == 2; + dri2_dpy->has_dmabuf_import = has_modifiers && caps & DRM_PRIME_CAP_IMPORT; +#endif + /* * EGL 1.5 specification defines the default value to 1. Moreover, * eglSwapInterval() is required to clamp requested value to the supported @@ -800,8 +811,7 @@ dri2_setup_screen(_EGLDisplay *disp) if (dri2_dpy->image) { #ifdef HAVE_LIBDRM - if (dri2_dpy->image->base.version >= 11 && - get_screen_param(disp, PIPE_CAP_DMABUF) & DRM_PRIME_CAP_EXPORT) { + if (get_screen_param(disp, PIPE_CAP_DMABUF) & DRM_PRIME_CAP_EXPORT) { disp->Extensions.MESA_image_dma_buf_export = true; } #endif @@ -817,8 +827,7 @@ dri2_setup_screen(_EGLDisplay *disp) disp->Extensions.KHR_gl_texture_3D_image = EGL_TRUE; #ifdef HAVE_LIBDRM - if (dri2_dpy->image->base.version >= 8 && - dri2_dpy->image->createImageFromDmaBufs) { + if (dri2_dpy->has_dmabuf_import) { disp->Extensions.EXT_image_dma_buf_import = EGL_TRUE; disp->Extensions.EXT_image_dma_buf_import_modifiers = EGL_TRUE; } @@ -937,9 +946,7 @@ dri2_setup_extensions(_EGLDisplay *disp) #ifdef HAVE_X11_PLATFORM if (dri2_dpy->conn) { bool err; - dri2_dpy->multibuffers_available = x11_dri3_check_multibuffer(dri2_dpy->conn, &err) && - !err && - (dri2_dpy->image && dri2_dpy->image->base.version >= 15); + dri2_dpy->multibuffers_available = x11_dri3_check_multibuffer(dri2_dpy->conn, &err); } #endif if (disp->Options.Zink && !disp->Options.ForceSoftware && @@ -2598,8 +2605,7 @@ dri2_query_dma_buf_formats(_EGLDisplay *disp, EGLint max, EGLint *formats, goto fail; } - if (dri2_dpy->image->base.version < 15 || - dri2_dpy->image->queryDmaBufFormats == NULL) + if (!dri2_dpy->has_dmabuf_import) goto fail; if (!dri_query_dma_buf_formats(dri2_dpy->dri_screen_render_gpu, @@ -2646,8 +2652,7 @@ dri2_query_dma_buf_modifiers(_EGLDisplay *disp, EGLint format, EGLint max, return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, "invalid modifiers array"); - if (dri2_dpy->image->base.version < 15 || - dri2_dpy->image->queryDmaBufModifiers == NULL) { + if (!dri2_dpy->has_dmabuf_import) { mtx_unlock(&dri2_dpy->lock); return EGL_FALSE; } @@ -3065,7 +3070,6 @@ dri2_bind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy) }; int flags = 0; char *device_name; - uint64_t cap; if (dri2_dpy->wl_server_drm) goto fail; @@ -3076,9 +3080,7 @@ dri2_bind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy) if (!device_name) goto fail; - if (drmGetCap(dri2_dpy->fd_render_gpu, DRM_CAP_PRIME, &cap) == 0 && - cap == (DRM_PRIME_CAP_IMPORT | DRM_PRIME_CAP_EXPORT) && - dri2_dpy->image->createImageFromDmaBufs != NULL) + if (dri2_dpy->has_modifiers) flags |= WAYLAND_DRM_PRIME; dri2_dpy->wl_server_drm = diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index eab854032f9..4024e72d899 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -282,12 +282,14 @@ struct dri2_egl_display { const __DRIextension **loader_extensions; const __DRIextension **driver_extensions; + bool has_dmabuf_import; + bool has_modifiers; + bool multibuffers_available; #ifdef HAVE_X11_PLATFORM xcb_connection_t *conn; xcb_screen_t *screen; bool swap_available; #ifdef HAVE_DRI3 - bool multibuffers_available; struct loader_screen_resources screen_resources; #endif #endif diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index adcb2c74f76..f1f9ad9e2a4 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -2318,7 +2318,7 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) * supported by the driver. We deprecated the support to GEM names API, so * we bail out if the driver does not support Prime. */ if (!(dri2_dpy->capabilities & WL_DRM_CAPABILITY_PRIME) || - (dri2_dpy->image->createImageFromDmaBufs == NULL)) { + !dri2_dpy->has_dmabuf_import) { _eglLog(_EGL_WARNING, "wayland-egl: display does not support prime"); goto cleanup; }