[Mesa-dev] [PATCH v13 12/36] st/dri: implement DRIimage creation from dmabufs with modifiers
Lucas Stach
l.stach at pengutronix.de
Fri May 19 14:47:47 UTC 2017
Am Freitag, den 19.05.2017, 10:37 +0100 schrieb Daniel Stone:
> From: Varad Gautam <varad.gautam at collabora.com>
>
> support importing dmabufs into DRIimage while taking format modifiers
> in account, as per DRIimage extension version 15.
>
> bump __DRIimageExtension to 15.
>
> v2: initialize winsys modifier to DRM_FORMAT_MOD_INVALID (Daniel Stone)
>
> Signed-off-by: Varad Gautam <varad.gautam at collabora.com>
> Signed-off-by: Daniel Stone <daniels at collabora.com>
Reviewed-by: Lucas Stach <l.stach at pengutronix.de>
> ---
> src/gallium/include/state_tracker/drm_driver.h | 2 ++
> src/gallium/state_trackers/dri/dri2.c | 48 +++++++++++++++++++++++---
> 2 files changed, 45 insertions(+), 5 deletions(-)
>
> diff --git a/src/gallium/include/state_tracker/drm_driver.h b/src/gallium/include/state_tracker/drm_driver.h
> index c80fb09dbc..8b9d6bc621 100644
> --- a/src/gallium/include/state_tracker/drm_driver.h
> +++ b/src/gallium/include/state_tracker/drm_driver.h
> @@ -45,6 +45,8 @@ struct winsys_handle
> * Output for texture_get_handle.
> */
> unsigned offset;
> +
> + uint64_t modifier;
> };
>
>
> diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
> index 713f482181..3f83cc96cc 100644
> --- a/src/gallium/state_trackers/dri/dri2.c
> +++ b/src/gallium/state_trackers/dri/dri2.c
> @@ -878,7 +878,7 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
> img->layer = 0;
> img->dri_format = format;
> img->use = 0;
> - img->modifier = DRM_FORMAT_MOD_INVALID;
> + img->modifier = whandle[0].modifier;
> img->loader_private = loaderPrivate;
>
> return img;
> @@ -895,6 +895,7 @@ dri2_create_image_from_name(__DRIscreen *_screen,
> memset(&whandle, 0, sizeof(whandle));
> whandle.type = DRM_API_HANDLE_TYPE_SHARED;
> whandle.handle = name;
> + whandle.modifier = DRM_FORMAT_MOD_INVALID;
>
> pf = dri2_format_to_pipe_format (format);
> if (pf == PIPE_FORMAT_NONE)
> @@ -910,7 +911,7 @@ static __DRIimage *
> dri2_create_image_from_fd(__DRIscreen *_screen,
> int width, int height, int fourcc,
> int *fds, int num_fds, int *strides,
> - int *offsets, unsigned *error,
> + int *offsets, uint64_t *modifiers, unsigned *error,
> int *dri_components, void *loaderPrivate)
> {
> struct winsys_handle whandles[3];
> @@ -941,6 +942,7 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
> whandles[i].handle = (unsigned)fds[i];
> whandles[i].stride = (unsigned)strides[i];
> whandles[i].offset = (unsigned)offsets[i];
> + whandles[i].modifier = modifiers ? modifiers[i] : DRM_FORMAT_MOD_INVALID;
> }
>
> if (fourcc == __DRI_IMAGE_FOURCC_YVU420) {
> @@ -1219,6 +1221,7 @@ dri2_from_names(__DRIscreen *screen, int width, int height, int format,
> whandle.handle = names[0];
> whandle.stride = strides[0];
> whandle.offset = offsets[0];
> + whandle.modifier = DRM_FORMAT_MOD_INVALID;
>
> img = dri2_create_image_from_winsys(screen, width, height,
> f->planes[0].dri_format,
> @@ -1331,7 +1334,7 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, int fourcc,
> int dri_components;
>
> img = dri2_create_image_from_fd(screen, width, height, fourcc,
> - fds, num_fds, strides, offsets, NULL,
> + fds, num_fds, strides, offsets, NULL, NULL,
> &dri_components, loaderPrivate);
> if (img == NULL)
> return NULL;
> @@ -1356,7 +1359,7 @@ dri2_from_dma_bufs(__DRIscreen *screen,
> int dri_components;
>
> img = dri2_create_image_from_fd(screen, width, height, fourcc,
> - fds, num_fds, strides, offsets, error,
> + fds, num_fds, strides, offsets, NULL, error,
> &dri_components, loaderPrivate);
> if (img == NULL)
> return NULL;
> @@ -1371,6 +1374,38 @@ dri2_from_dma_bufs(__DRIscreen *screen,
> return img;
> }
>
> +static __DRIimage *
> +dri2_from_dma_bufs2(__DRIscreen *screen,
> + int width, int height, int fourcc,
> + int *fds, int num_fds,
> + int *strides, int *offsets,
> + uint64_t *modifiers,
> + enum __DRIYUVColorSpace yuv_color_space,
> + enum __DRISampleRange sample_range,
> + enum __DRIChromaSiting horizontal_siting,
> + enum __DRIChromaSiting vertical_siting,
> + unsigned *error,
> + void *loaderPrivate)
> +{
> + __DRIimage *img;
> + int dri_components;
> +
> + img = dri2_create_image_from_fd(screen, width, height, fourcc,
> + fds, num_fds, strides, offsets, modifiers,
> + error, &dri_components, loaderPrivate);
> + if (img == NULL)
> + return NULL;
> +
> + img->yuv_color_space = yuv_color_space;
> + img->sample_range = sample_range;
> + img->horizontal_siting = horizontal_siting;
> + img->vertical_siting = vertical_siting;
> + img->dri_components = dri_components;
> +
> + *error = __DRI_IMAGE_ERROR_SUCCESS;
> + return img;
> +}
> +
> static void
> dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
> int dstx0, int dsty0, int dstwidth, int dstheight,
> @@ -1474,7 +1509,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
>
> /* The extension is modified during runtime if DRI_PRIME is detected */
> static __DRIimageExtension dri2ImageExtension = {
> - .base = { __DRI_IMAGE, 14 },
> + .base = { __DRI_IMAGE, 15 },
>
> .createImageFromName = dri2_create_image_from_name,
> .createImageFromRenderbuffer = dri2_create_image_from_renderbuffer,
> @@ -1493,6 +1528,7 @@ static __DRIimageExtension dri2ImageExtension = {
> .mapImage = dri2_map_image,
> .unmapImage = dri2_unmap_image,
> .createImageWithModifiers = NULL,
> + .createImageFromDmaBufs2 = NULL,
> };
>
>
> @@ -2038,6 +2074,7 @@ dri2_init_screen(__DRIscreen * sPriv)
> (cap & DRM_PRIME_CAP_IMPORT)) {
> dri2ImageExtension.createImageFromFds = dri2_from_fds;
> dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
> + dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
> }
> }
>
> @@ -2114,6 +2151,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
> (cap & DRM_PRIME_CAP_IMPORT)) {
> dri2ImageExtension.createImageFromFds = dri2_from_fds;
> dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
> + dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
> }
>
> sPriv->extensions = dri_screen_extensions;
More information about the mesa-dev
mailing list