diff --git a/docs/gallium/screen.rst b/docs/gallium/screen.rst index 53efdc303d2..a7ab998146f 100644 --- a/docs/gallium/screen.rst +++ b/docs/gallium/screen.rst @@ -565,6 +565,11 @@ The integer capabilities: execution. 0 = throttling is disabled. * ``PIPE_CAP_DMABUF``: Whether Linux DMABUF handles are supported by resource_from_handle and resource_get_handle. + Possible bit field values: + + 1. ``DRM_PRIME_CAP_IMPORT``: resource_from_handle is supported + 2. ``DRM_PRIME_CAP_EXPORT``: resource_get_handle is supported + * ``PIPE_CAP_PREFER_COMPUTE_FOR_MULTIMEDIA``: Whether VDPAU, VAAPI, and OpenMAX should use a compute-based blit instead of pipe_context::blit and compute pipeline for compositing images. * ``PIPE_CAP_FRAGMENT_SHADER_INTERLOCK``: True if fragment shader interlock diff --git a/src/gallium/auxiliary/util/u_screen.c b/src/gallium/auxiliary/util/u_screen.c index 22c20e0c638..c8f1c5f990e 100644 --- a/src/gallium/auxiliary/util/u_screen.c +++ b/src/gallium/auxiliary/util/u_screen.c @@ -31,6 +31,11 @@ #include "util/simple_mtx.h" #include "util/u_hash_table.h" #include "util/u_pointer.h" +#include "util/macros.h" + +#ifdef HAVE_LIBDRM +#include +#endif /** * Helper to use from a pipe_screen->get_param() implementation to return @@ -43,6 +48,9 @@ int u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen, enum pipe_cap param) { + UNUSED uint64_t cap; + UNUSED int fd; + assert(param < PIPE_CAP_LAST); /* Let's keep these sorted by position in p_defines.h. */ @@ -435,8 +443,12 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen, return 0; case PIPE_CAP_DMABUF: -#if DETECT_OS_LINUX || DETECT_OS_BSD - return 1; +#if defined(HAVE_LIBDRM) && (DETECT_OS_LINUX || DETECT_OS_BSD) + fd = pscreen->get_screen_fd(pscreen); + if (fd != -1 && (drmGetCap(fd, DRM_CAP_PRIME, &cap) == 0)) + return cap; + else + return 0; #else return 0; #endif diff --git a/src/gallium/frontends/dri/dri2.c b/src/gallium/frontends/dri/dri2.c index df504124285..f45f95b659d 100644 --- a/src/gallium/frontends/dri/dri2.c +++ b/src/gallium/frontends/dri/dri2.c @@ -2218,24 +2218,19 @@ dri2_init_screen_extensions(struct dri_screen *screen, screen->image_extension.setInFenceFd = dri2_set_in_fence_fd; } - if (pscreen->get_param(pscreen, PIPE_CAP_DMABUF)) { - uint64_t cap; - - if (drmGetCap(screen->fd, DRM_CAP_PRIME, &cap) == 0 && - (cap & DRM_PRIME_CAP_IMPORT)) { - screen->image_extension.createImageFromFds = dri2_from_fds; - screen->image_extension.createImageFromFds2 = dri2_from_fds2; - screen->image_extension.createImageFromDmaBufs = dri2_from_dma_bufs; - screen->image_extension.createImageFromDmaBufs2 = dri2_from_dma_bufs2; - screen->image_extension.createImageFromDmaBufs3 = dri2_from_dma_bufs3; - screen->image_extension.queryDmaBufFormats = - dri2_query_dma_buf_formats; - screen->image_extension.queryDmaBufModifiers = - dri2_query_dma_buf_modifiers; - if (!is_kms_screen) { - screen->image_extension.queryDmaBufFormatModifierAttribs = - dri2_query_dma_buf_format_modifier_attribs; - } + if (pscreen->get_param(pscreen, PIPE_CAP_DMABUF) & DRM_PRIME_CAP_IMPORT) { + screen->image_extension.createImageFromFds = dri2_from_fds; + screen->image_extension.createImageFromFds2 = dri2_from_fds2; + screen->image_extension.createImageFromDmaBufs = dri2_from_dma_bufs; + screen->image_extension.createImageFromDmaBufs2 = dri2_from_dma_bufs2; + screen->image_extension.createImageFromDmaBufs3 = dri2_from_dma_bufs3; + screen->image_extension.queryDmaBufFormats = + dri2_query_dma_buf_formats; + screen->image_extension.queryDmaBufModifiers = + dri2_query_dma_buf_modifiers; + if (!is_kms_screen) { + screen->image_extension.queryDmaBufFormatModifierAttribs = + dri2_query_dma_buf_format_modifier_attribs; } } *nExt++ = &screen->image_extension.base;