[Mesa-dev] [PATCH] i965: Allow creating image from different dma_buf fds

Eric Engestrom eric at engestrom.ch
Wed Aug 31 07:58:56 UTC 2016


On Tue, Aug 30, 2016 at 04:49:53PM -0700, krh at bitplanet.net wrote:
> From: "Kristian H. Kristensen" <hoegsberg at chromium.org>
> 
> As long as the dma_buf fds import to the same drm_intel_bo, we're fine.
> 
> Reviewed-by: Stéphane Marchesin <marcheu at chromium.org>

Looks good to me.
Reviewed-by: Eric Engestrom <eric at engestrom.ch>

> ---
>  src/mesa/drivers/dri/i965/intel_screen.c | 36 +++++++++++++++++++++++---------
>  1 file changed, 26 insertions(+), 10 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
> index 84977a7..560935d 100644
> --- a/src/mesa/drivers/dri/i965/intel_screen.c
> +++ b/src/mesa/drivers/dri/i965/intel_screen.c
> @@ -706,11 +706,6 @@ intel_create_image_from_fds(__DRIscreen *screen,
>     if (fds == NULL || num_fds < 1)
>        return NULL;
>  
> -   /* We only support all planes from the same bo */
> -   for (i = 0; i < num_fds; i++)
> -      if (fds[0] != fds[i])
> -         return NULL;
> -
>     f = intel_image_format_lookup(fourcc);
>     if (f == NULL)
>        return NULL;
> @@ -740,11 +735,25 @@ intel_create_image_from_fds(__DRIscreen *screen,
>           size = end;
>     }
>  
> -   image->bo = drm_intel_bo_gem_create_from_prime(intelScreen->bufmgr,
> -                                                  fds[0], size);
> -   if (image->bo == NULL) {
> -      free(image);
> -      return NULL;
> +   /* We only support all planes from the same bo, but the fds may be
> +    * different. Make sure all fds import to the same bo. The kernel and
> +    * libdrm guarantees this, if the fds refer to the same kernel bo. */
> +   for (i = 0; i < num_fds; i++) {
> +      drm_intel_bo *bo =
> +         drm_intel_bo_gem_create_from_prime(intelScreen->bufmgr, fds[i], size);
> +      if (bo == NULL)
> +         goto err_out;
> +
> +      if (i == 0) {
> +         image->bo = bo;
> +      } else {
> +         /* We need to unref the bo in either case, so do it up front. We can
> +          * still compare the pointers below to see if the bo matches.
> +          */
> +         drm_intel_bo_unreference(bo);
> +         if (image->bo != bo)
> +            goto err_out;
> +      }
>     }
>  
>     if (f->nplanes == 1) {
> @@ -753,6 +762,13 @@ intel_create_image_from_fds(__DRIscreen *screen,
>     }
>  
>     return image;
> +
> +err_out:
> +   if (image->bo)
> +      drm_intel_bo_unreference(image->bo);
> +   free(image);
> +
> +   return NULL;
>  }
>  
>  static __DRIimage *
> -- 
> 2.8.0.rc3.226.g39d4020
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list