gallium: Modify default path for DMABUF to use DRM
Modify the code path taken in `u_pipe_screen_get_param_defaults` to call DRM to check if `PIPE_CAP_DMABUF` is supported. This is required for overriding the behavior in `dri2_init_screen_extensions` to support importing DMA bufs on drivers that don't support DRM, by simply changing how `PIPE_CAP_DMABUF` is handled in their driver. Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Reviewed-by: Eric Engestrom <eric@igalia.com> Reviewed-by: Rob Clark <robdclark@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21654>
This commit is contained in:
@@ -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
|
||||
|
@@ -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 <xf86drm.h>
|
||||
#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
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user