[Mesa-dev] [PATCH] i965: implement (un)mapImage
Chris Wilson
chris at chris-wilson.co.uk
Thu Nov 9 15:35:57 UTC 2017
Quoting Julien Isorce (2017-11-09 15:30:23)
> v2: add early return if (flag & MAP_INTERNAL_MASK)
> v3: take input rect into account and test with kmscube and piglit.
>
> Already implemented for Gallium drivers.
>
> Useful for gbm_bo_(un)map.
>
> Tests:
> By porting wayland/weston/clients/simple-dmabuf-drm.c to GBM.
> kmscube --mode=rgba
> kmscube --mode=nv12-1img
> kmscube --mode=nv12-2img
> piglit ext_image_dma_buf_import-refcount -auto
> piglit ext_image_dma_buf_import-transcode-nv12-as-r8-gr88 -auto
> piglit ext_image_dma_buf_import-sample_rgb -fmt=AR24 -alpha-one -auto
> piglit ext_image_dma_buf_import-sample_rgb -fmt=XR24 -auto
> piglit ext_image_dma_buf_import-sample_yuv -fmt=NV12 -auto
> piglit ext_image_dma_buf_import-sample_yuv -fmt=YU12 -auto
> piglit ext_image_dma_buf_import-sample_yuv -fmt=YV12 -auto
>
> Signed-off-by: Julien Isorce <jisorce at oblong.com>
> ---
> src/mesa/drivers/dri/i965/intel_screen.c | 68 +++++++++++++++++++++++++++++++-
> 1 file changed, 66 insertions(+), 2 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
> index cdc36ad..8de78b2 100644
> --- a/src/mesa/drivers/dri/i965/intel_screen.c
> +++ b/src/mesa/drivers/dri/i965/intel_screen.c
> @@ -755,6 +755,70 @@ intel_create_image(__DRIscreen *dri_screen,
> loaderPrivate);
> }
>
> +static void *
> +intel_map_image(__DRIcontext *context, __DRIimage *image,
> + int x0, int y0, int width, int height,
> + unsigned int flags, int *stride, void **map_info)
> +{
> + struct brw_context *brw = NULL;
> + struct brw_bo *bo = NULL;
> + void *raw_data = NULL;
> +
> + if (!context || !image || !stride || !map_info || *map_info)
> + return NULL;
> +
> + if (x0 < 0 || y0 < 0 || width <= 0 || height <= 0 ||
> + (x0 + width) > image->width || (y0 + height) > image->height)
Bah, you forgot about handling wraparound.
if (x0 < 0 || x0 > image->width || width > image->width - x0)
return NULL;
if (y0 < 0 || y0 > image->height || height > image->height - y0)
return NULL;
> + return NULL;
> +
> + if (flags & MAP_INTERNAL_MASK)
> + return NULL;
> +
> + brw = context->driverPrivate;
> + bo = image->bo;
Ben raised an interesting question in his patch: What is the lifetime of
the mapping vs the image? If the map can outlive the image, we need to
take a reference to image->bo and drop it in unmap.
-Chris
More information about the mesa-dev
mailing list