From e9c3dbd046137aebcc18e1d7a1040dc669a0c140 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 14 Oct 2021 15:12:12 +0200 Subject: [PATCH] gallium/dri: let the driver know if the imported image is DRI_PRIME buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use createImageFromFds2 together with __DRI_IMAGE_PRIME_LINEAR_BUFFER, so the driver's resource_from_handle hook will be aware that this specific image is the linear buffer. Reviewed-by: Marek Olšák Part-of: --- include/GL/internal/dri_interface.h | 1 + src/gallium/frontends/dri/dri2.c | 2 ++ src/gallium/include/pipe/p_defines.h | 1 + src/loader/loader_dri3_helper.c | 30 +++++++++++++++++++--------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h index cd30046fde2..5e06912ffb5 100644 --- a/include/GL/internal/dri_interface.h +++ b/include/GL/internal/dri_interface.h @@ -1411,6 +1411,7 @@ enum __DRIChromaSiting { * Flags for createImageFromDmaBufs3 and createImageFromFds2 */ #define __DRI_IMAGE_PROTECTED_CONTENT_FLAG 0x00000001 +#define __DRI_IMAGE_PRIME_LINEAR_BUFFER 0x00000002 /** * queryDmaBufFormatModifierAttribs attributes diff --git a/src/gallium/frontends/dri/dri2.c b/src/gallium/frontends/dri/dri2.c index 8c8630586eb..0bf82bbe72a 100644 --- a/src/gallium/frontends/dri/dri2.c +++ b/src/gallium/frontends/dri/dri2.c @@ -1526,6 +1526,8 @@ dri2_from_fds2(__DRIscreen *screen, int width, int height, int fourcc, unsigned bind = 0; if (flags & __DRI_IMAGE_PROTECTED_CONTENT_FLAG) bind |= PIPE_BIND_PROTECTED; + if (flags & __DRI_IMAGE_PRIME_LINEAR_BUFFER) + bind |= PIPE_BIND_DRI_PRIME; return dri2_create_image_from_fd(screen, width, height, fourcc, DRM_FORMAT_MOD_INVALID, fds, num_fds, diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index 608667b1468..c88aee3936f 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -514,6 +514,7 @@ enum pipe_flush_flags #define PIPE_BIND_LINEAR (1 << 21) #define PIPE_BIND_PROTECTED (1 << 22) /* Resource will be protected/encrypted */ #define PIPE_BIND_SAMPLER_REDUCTION_MINMAX (1 << 23) /* PIPE_CAP_SAMPLER_REDUCTION_MINMAX */ +#define PIPE_BIND_DRI_PRIME (1 << 24) /** diff --git a/src/loader/loader_dri3_helper.c b/src/loader/loader_dri3_helper.c index fc043bd0533..b9019b6cd25 100644 --- a/src/loader/loader_dri3_helper.c +++ b/src/loader/loader_dri3_helper.c @@ -1545,15 +1545,27 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format, /* The linear buffer was created in the display GPU's vram, so we * need to make it visible to render GPU */ - buffer->linear_buffer = - draw->ext->image->createImageFromFds(draw->dri_screen, - width, - height, - image_format_to_fourcc(format), - &buffer_fds[0], num_planes, - &buffer->strides[0], - &buffer->offsets[0], - buffer); + if (draw->ext->image->base.version >= 20) + buffer->linear_buffer = + draw->ext->image->createImageFromFds2(draw->dri_screen, + width, + height, + image_format_to_fourcc(format), + &buffer_fds[0], num_planes, + __DRI_IMAGE_PRIME_LINEAR_BUFFER, + &buffer->strides[0], + &buffer->offsets[0], + buffer); + else + buffer->linear_buffer = + draw->ext->image->createImageFromFds(draw->dri_screen, + width, + height, + image_format_to_fourcc(format), + &buffer_fds[0], num_planes, + &buffer->strides[0], + &buffer->offsets[0], + buffer); if (!buffer->linear_buffer) goto no_buffer_attrib;