dri: Consistently use createImageFromDmabufs() not createImageFromFds()

They're calling the same thing in the backend, so reduce the proliferation
of interfaces consumed within our implementation.

driVkImageExtensionSw now sets dri2_from_dma_bufs, which means that
egl_dri2 will now expose EXT_image_dma_buf_import.  Given that it
previously set dri2_from_fds suggesting that it can import dmabufs, this
is presumably OK.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30245>
This commit is contained in:
Emma Anholt 2023-10-11 11:05:37 -07:00 committed by Marge Bot
parent b1bcda45be
commit 26c1354578
9 changed files with 67 additions and 55 deletions

View file

@ -3117,9 +3117,10 @@ dri2_wl_reference_buffer(void *user_data, uint32_t name, int fd,
dri2_dpy->dri_screen_render_gpu, buffer->width, buffer->height,
buffer->format, (int *)&name, 1, buffer->stride, buffer->offset, NULL);
else
img = dri2_dpy->image->createImageFromFds2(
img = dri2_dpy->image->createImageFromDmaBufs(
dri2_dpy->dri_screen_render_gpu, buffer->width, buffer->height,
buffer->format, &fd, 1, 0, buffer->stride, buffer->offset, NULL);
buffer->format, DRM_FORMAT_MOD_INVALID, &fd, 1, buffer->stride,
buffer->offset, 0, 0, 0, 0, 0, NULL, NULL);
if (img == NULL)
return;
@ -3172,8 +3173,7 @@ dri2_bind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy)
if (drmGetCap(dri2_dpy->fd_render_gpu, DRM_CAP_PRIME, &cap) == 0 &&
cap == (DRM_PRIME_CAP_IMPORT | DRM_PRIME_CAP_EXPORT) &&
dri2_dpy->image->base.version >= 7 &&
dri2_dpy->image->createImageFromFds != NULL)
dri2_dpy->image->createImageFromDmaBufs != NULL)
flags |= WAYLAND_DRM_PRIME;
dri2_dpy->wl_server_drm =

View file

@ -2316,12 +2316,12 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp)
dri2_wl_setup_swap_interval(disp);
if (dri2_dpy->wl_drm) {
/* To use Prime, we must have _DRI_IMAGE v7 at least. createImageFromFds
* support indicates that Prime export/import is supported by the driver.
* We deprecated the support to GEM names API, so we bail out if the
* driver does not support Prime. */
/* To use Prime, we must have _DRI_IMAGE v7 at least.
* createImageFromDmaBufs support indicates that Prime export/import is
* 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->createImageFromFds == NULL)) {
(dri2_dpy->image->createImageFromDmaBufs == NULL)) {
_eglLog(_EGL_WARNING, "wayland-egl: display does not support prime");
goto cleanup;
}

View file

@ -1842,21 +1842,25 @@ dri2_from_dma_bufs(__DRIscreen *screen,
enum __DRISampleRange sample_range,
enum __DRIChromaSiting horizontal_siting,
enum __DRIChromaSiting vertical_siting,
uint32_t flags,
uint32_t dri_flags,
unsigned *error,
void *loaderPrivate)
{
unsigned bind = 0;
__DRIimage *img;
/* Allow a NULL error arg since many callers don't care. */
unsigned unused_error;
if (!error)
error = &unused_error;
if (flags & __DRI_IMAGE_PROTECTED_CONTENT_FLAG)
bind |= PIPE_BIND_PROTECTED;
if (flags & __DRI_IMAGE_PRIME_LINEAR_BUFFER)
bind |= PIPE_BIND_PRIME_BLIT_DST;
uint32_t flags = 0;
if (dri_flags & __DRI_IMAGE_PROTECTED_CONTENT_FLAG)
flags |= PIPE_BIND_PROTECTED;
if (dri_flags & __DRI_IMAGE_PRIME_LINEAR_BUFFER)
flags |= PIPE_BIND_PRIME_BLIT_DST;
img = dri2_create_image_from_fd(screen, width, height, fourcc,
modifier, fds, num_fds, strides, offsets,
bind, error, loaderPrivate);
flags, error, loaderPrivate);
if (img == NULL)
return NULL;
@ -2115,6 +2119,7 @@ const __DRIimageExtension driVkImageExtensionSw = {
.createImageFromTexture = dri2_create_from_texture,
.createImageFromFds = dri2_from_fds,
.createImageFromFds2 = dri2_from_fds2,
.createImageFromDmaBufs = dri2_from_dma_bufs,
.blitImage = dri2_blit_image,
.getCapabilities = dri2_get_capabilities,
.mapImage = dri2_map_image,

View file

@ -278,17 +278,19 @@ dri3_create_image(xcb_connection_t *c,
stride = bp_reply->stride;
offset = 0;
/* createImageFromFds creates a wrapper __DRIimage structure which
/* createImageFromDmaBufs creates a wrapper __DRIimage structure which
* can deal with multiple planes for things like Yuv images. So, once
* we've gotten the planar wrapper, pull the single plane out of it and
* discard the wrapper.
*/
image_planar = image->createImageFromFds2(opaque_dri_screen(screen),
bp_reply->width,
bp_reply->height,
fourcc,
fds, 1,
0, &stride, &offset, loaderPrivate);
image_planar = image->createImageFromDmaBufs(opaque_dri_screen(screen),
bp_reply->width,
bp_reply->height,
fourcc,
DRM_FORMAT_MOD_INVALID, fds, 1,
&stride, &offset,
0, 0, 0, 0, 0,
NULL, loaderPrivate);
close(fds[0]);
if (!image_planar)
return NULL;
@ -328,7 +330,7 @@ handle_in_fence(struct dri_context *ctx, __DRIimage *img)
/** kopper_get_pixmap_buffer
*
* Get the DRM object for a pixmap from the X server and
* wrap that with a __DRIimage structure using createImageFromFds
* wrap that with a __DRIimage structure using createImageFromDmaBufs
*/
static struct pipe_resource *
kopper_get_pixmap_buffer(struct dri_drawable *drawable,

View file

@ -1676,7 +1676,7 @@ struct __DRIimageExtensionRec {
unsigned *error);
/**
* Like createImageFromFds, but takes additional attributes.
* Creates a DRI image from an array of dmabuf fds and their modifiers.
*
* See __DRI_IMAGE_*_FLAG for valid definitions of flags.
*/

View file

@ -778,18 +778,19 @@ gbm_dri_bo_import(struct gbm_device *gbm,
int fourcc;
/* GBM's GBM_FORMAT_* tokens are a strict superset of the DRI FourCC
* tokens accepted by createImageFromFds, except for not supporting
* tokens accepted by createImageFromDmaBufs, except for not supporting
* the sARGB format. */
fourcc = gbm_core.v0.format_canonicalize(fd_data->format);
image = dri->image->createImageFromFds2(dri->screen,
fd_data->width,
fd_data->height,
fourcc,
&fd_data->fd, 1,
0,
&stride, &offset,
NULL);
image = dri->image->createImageFromDmaBufs(dri->screen,
fd_data->width,
fd_data->height,
fourcc,
DRM_FORMAT_MOD_INVALID,
&fd_data->fd, 1,
&stride, &offset,
0, 0, 0, 0, 0,
NULL, NULL);
if (image == NULL) {
errno = EINVAL;
return NULL;

View file

@ -891,8 +891,8 @@ dri3_create_screen(int screen, struct glx_display * priv, bool driver_name_is_in
dri3_bind_extensions(psc, priv, driverName);
if (!psc->image || psc->image->base.version < 7 || !psc->image->createImageFromFds) {
ErrorMessageF("Version 7 or imageFromFds image extension not found\n");
if (!psc->image || !psc->image->createImageFromDmaBufs) {
ErrorMessageF("Version 7 or imageFromDmaBufs image extension not found\n");
goto handle_error;
}

View file

@ -1618,15 +1618,16 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
* need to make it visible to render GPU
*/
buffer->linear_buffer =
draw->ext->image->createImageFromFds2(draw->dri_screen_render_gpu,
width,
height,
loader_image_format_to_fourcc(format),
&buffer_fds[0], num_planes,
__DRI_IMAGE_PRIME_LINEAR_BUFFER,
&buffer->strides[0],
&buffer->offsets[0],
buffer);
draw->ext->image->createImageFromDmaBufs(draw->dri_screen_render_gpu,
width,
height,
loader_image_format_to_fourcc(format),
DRM_FORMAT_MOD_INVALID,
&buffer_fds[0], num_planes,
&buffer->strides[0],
&buffer->offsets[0],
0, 0, 0, 0, __DRI_IMAGE_PRIME_LINEAR_BUFFER,
NULL, buffer);
if (!buffer->linear_buffer)
goto no_buffer_attrib;
@ -1839,17 +1840,20 @@ loader_dri3_create_image(xcb_connection_t *c,
stride = bp_reply->stride;
offset = 0;
/* createImageFromFds creates a wrapper __DRIimage structure which
/* createImageFromDmaBufs creates a wrapper __DRIimage structure which
* can deal with multiple planes for things like Yuv images. So, once
* we've gotten the planar wrapper, pull the single plane out of it and
* discard the wrapper.
*/
image_planar = image->createImageFromFds2(dri_screen,
bp_reply->width,
bp_reply->height,
loader_image_format_to_fourcc(format),
fds, 1,
0, &stride, &offset, loaderPrivate);
image_planar = image->createImageFromDmaBufs(dri_screen,
bp_reply->width,
bp_reply->height,
loader_image_format_to_fourcc(format),
DRM_FORMAT_MOD_INVALID,
fds, 1,
&stride, &offset,
0, 0, 0, 0, 0,
NULL, loaderPrivate);
close(fds[0]);
if (!image_planar)
return NULL;
@ -1911,7 +1915,7 @@ loader_dri3_create_image_from_buffers(xcb_connection_t *c,
/** dri3_get_pixmap_buffer
*
* Get the DRM object for a pixmap from the X server and
* wrap that with a __DRIimage structure using createImageFromFds
* wrap that with a __DRIimage structure using createImageFromDmaBufs
*/
static struct loader_dri3_buffer *
dri3_get_pixmap_buffer(__DRIdrawable *driDrawable, unsigned int format,

View file

@ -116,9 +116,9 @@ bool dri_valid_swap_interval(__DRIscreen *driScreen,
}
/* the DRIimage createImage function takes __DRI_IMAGE_FORMAT codes, while
* the createImageFromFds call takes DRM_FORMAT codes. To avoid
* the createImageFromDmaBufs call takes DRM_FORMAT codes. To avoid
* complete confusion, just deal in __DRI_IMAGE_FORMAT codes for now and
* translate to DRM_FORMAT codes in the call to createImageFromFds
* translate to DRM_FORMAT codes in the call to createImageFromDmaBufs
*/
int
loader_image_format_to_fourcc(int format)