<div dir="ltr">Thx for the suggestions.<div><br></div><div>Anyone familiar with _mesa_get_format_block_size and _mesa_get_format_bytes wants to review this patch ? </div></div><div class="gmail_extra"><br><div class="gmail_quote">On 9 November 2017 at 17:10, Eric Engestrom <span dir="ltr"><<a href="mailto:eric.engestrom@imgtec.com" target="_blank">eric.engestrom@imgtec.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thursday, 2017-11-09 17:03:13 +0000, Julien Isorce wrote:<br>
> v2: add early return if (flag & MAP_INTERNAL_MASK)<br>
> v3: take input rect into account and test with kmscube and piglit.<br>
> v4: handle wraparound and bo reference.<br>
><br>
> Already implemented for Gallium drivers.<br>
><br>
> Useful for gbm_bo_(un)map.<br>
><br>
> Tests:<br>
>   By porting wayland/weston/clients/simple-<wbr>dmabuf-drm.c to GBM.<br>
>   kmscube --mode=rgba<br>
>   kmscube --mode=nv12-1img<br>
>   kmscube --mode=nv12-2img<br>
>   piglit ext_image_dma_buf_import-<wbr>refcount -auto<br>
>   piglit ext_image_dma_buf_import-<wbr>transcode-nv12-as-r8-gr88 -auto<br>
>   piglit ext_image_dma_buf_import-<wbr>sample_rgb -fmt=AR24 -alpha-one -auto<br>
>   piglit ext_image_dma_buf_import-<wbr>sample_rgb -fmt=XR24 -auto<br>
>   piglit ext_image_dma_buf_import-<wbr>sample_yuv -fmt=NV12 -auto<br>
>   piglit ext_image_dma_buf_import-<wbr>sample_yuv -fmt=YU12 -auto<br>
>   piglit ext_image_dma_buf_import-<wbr>sample_yuv -fmt=YV12 -auto<br>
><br>
> Signed-off-by: Julien Isorce <<a href="mailto:jisorce@oblong.com">jisorce@oblong.com</a>><br>
> ---<br>
>  src/mesa/drivers/dri/i965/<wbr>intel_screen.c | 75 ++++++++++++++++++++++++++++++<wbr>+-<br>
>  1 file changed, 73 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_screen.c b/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
> index cdc36ad..6074ee8 100644<br>
> --- a/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
> +++ b/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
> @@ -755,6 +755,77 @@ intel_create_image(__DRIscreen *dri_screen,<br>
>                                 loaderPrivate);<br>
>  }<br>
><br>
> +static void *<br>
> +intel_map_image(__DRIcontext *context, __DRIimage *image,<br>
> +                int x0, int y0, int width, int height,<br>
> +                unsigned int flags, int *stride, void **map_info)<br>
> +{<br>
> +   struct brw_context *brw = NULL;<br>
> +   struct brw_bo *bo = NULL;<br>
> +   void *raw_data = NULL;<br>
> +<br>
> +   if (!context || !image || !stride || !map_info || *map_info)<br>
> +      return NULL;<br>
> +<br>
> +   if (x0 < 0 || x0 > image->width || width > image->width - x0)<br>
> +      return NULL;<br>
> +<br>
> +   if (y0 < 0 || y0 > image->height || height > image->height - y0)<br>
> +        return NULL;<br>
> +<br>
> +   if (flags & MAP_INTERNAL_MASK)<br>
> +      return NULL;<br>
> +<br>
> +   brw = context->driverPrivate;<br>
> +   bo = image->bo;<br>
> +<br>
> +   assert(brw);<br>
> +   assert(bo);<br>
> +<br>
> +   brw_bo_reference(bo);<br>
> +<br>
> +   /* DRI flags and GL_MAP.*_BIT flags are the same, so just pass them on. */<br>
> +   raw_data = brw_bo_map(brw, bo, flags);<br>
> +<br>
> +   if (raw_data) {<br>
> +      GLuint pix_w = 1;<br>
> +      GLuint pix_h = 1;<br>
> +      GLint pix_bytes = 1;<br>
> +<br>
> +      *map_info = raw_data;<br>
> +      *stride = image->pitch;<br>
> +<br>
> +      _mesa_get_format_block_size(<wbr>image->format, &pix_w, &pix_h);<br>
> +      pix_bytes = _mesa_get_format_bytes(image-><wbr>format);<br>
> +<br>
> +      assert(pix_w);<br>
> +      assert(pix_h);<br>
> +      assert(pix_bytes > 0);<br>
> +<br>
> +      raw_data += ((x0 / pix_w) * pix_bytes) + (y0 / pix_h) * image->pitch;<br>
> +   } else {<br>
> +      brw_bo_unreference(bo);<br>
> +   }<br>
<br>
</div></div>Feels really nit-picky, so don't send a new rev just for that, but:<br>
<br>
   if (!raw_data) {<br>
      brw_bo_unreference(bo);<br>
      return NULL;<br>
   }<br>
<br>
   /* code from the `if (raw_data)` branch */<br>
<br>
that way you don't have to carry around the indentation :)<br>
<div class="HOEnZb"><div class="h5"><br>
> +<br>
> +   return raw_data;<br>
> +}<br>
> +<br>
> +static void<br>
> +intel_unmap_image(__<wbr>DRIcontext *context, __DRIimage *image, void *map_info)<br>
> +{<br>
> +   struct brw_bo *bo = NULL;<br>
> +<br>
> +   if (!context || !image || !map_info)<br>
> +      return;<br>
> +<br>
> +   bo = image->bo;<br>
> +<br>
> +   assert(bo);<br>
> +<br>
> +   brw_bo_unmap(bo);<br>
> +   brw_bo_unreference(bo);<br>
> +}<br>
> +<br>
>  static __DRIimage *<br>
>  intel_create_image_with_<wbr>modifiers(__DRIscreen *dri_screen,<br>
>                                    int width, int height, int format,<br>
> @@ -1305,8 +1376,8 @@ static const __DRIimageExtension intelImageExtension = {<br>
>      .createImageFromDmaBufs             = intel_create_image_from_dma_<wbr>bufs,<br>
>      .blitImage                          = NULL,<br>
>      .getCapabilities                    = NULL,<br>
> -    .mapImage                           = NULL,<br>
> -    .unmapImage                         = NULL,<br>
> +    .mapImage                           = intel_map_image,<br>
> +    .unmapImage                         = intel_unmap_image,<br>
>      .createImageWithModifiers           = intel_create_image_with_<wbr>modifiers,<br>
>      .createImageFromDmaBufs2            = intel_create_image_from_dma_<wbr>bufs2,<br>
>      .queryDmaBufFormats                 = intel_query_dma_buf_formats,<br>
> --<br>
> 2.7.4<br>
><br>
</div></div></blockquote></div><br></div>