<div dir="ltr">Thx for pointing that.<div><br></div><div>Gentle ping, anyone wants to mark 'reviewed' this patch ?</div><div><div class="gmail_extra"><br><div class="gmail_quote">On 10 November 2017 at 16:18, Rafael Antognolli <span dir="ltr"><<a href="mailto:rafael.antognolli@intel.com" target="_blank">rafael.antognolli@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, Nov 10, 2017 at 10:46:03AM +0000, Julien Isorce wrote:<br>
> Thx for the suggestions.<br>
><br>
> Anyone familiar with _mesa_get_format_block_size and _mesa_get_format_bytes<br>
> wants to review this patch ?<br>
><br>
> On 9 November 2017 at 17:10, Eric Engestrom <<a href="mailto:eric.engestrom@imgtec.com">eric.engestrom@imgtec.com</a>> wrote:<br>
><br>
>     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>
</span>Just nitpick, but in case you need to respin a new version of this<br>
patch, please consider adding the changelog (v2-n) after the commit<br>
description. See other commits for some examples.<br>
<br>
Rafael<br>
<div><div class="h5"><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<br>
>     ++++++++++++++++++++++++++++++<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/<br>
>     dri/i965/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<br>
>     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-><br>
>     pitch;<br>
>     > +   } else {<br>
>     > +      brw_bo_unreference(bo);<br>
>     > +   }<br>
><br>
>     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>
><br>
>     > +<br>
>     > +   return raw_data;<br>
>     > +}<br>
>     > +<br>
>     > +static void<br>
>     > +intel_unmap_image(__<wbr>DRIcontext *context, __DRIimage *image, void<br>
>     *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<br>
>     intelImageExtension = {<br>
>     >      .createImageFromDmaBufs             = intel_create_image_from_dma_<br>
>     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_<br>
>     modifiers,<br>
>     >      .createImageFromDmaBufs2            = intel_create_image_from_dma_<br>
>     bufs2,<br>
>     >      .queryDmaBufFormats                 = intel_query_dma_buf_formats,<br>
>     > --<br>
>     > 2.7.4<br>
>     ><br>
><br>
><br>
<br>
</div></div>> ______________________________<wbr>_________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
<br>
</blockquote></div><br></div></div></div>