gallium/dri: let the driver know if the imported image is DRI_PRIME buffer

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 <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13362>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2021-10-14 15:12:12 +02:00
parent 7a5de84249
commit e9c3dbd046
4 changed files with 25 additions and 9 deletions

View File

@ -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

View File

@ -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,

View File

@ -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)
/**

View File

@ -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;