frontend/dri: Implement mapping individual planes.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 25 May 2020 13:53:59 +0000 (15:53 +0200)
committerMarge Bot <eric+marge@anholt.net>
Fri, 29 May 2020 09:12:33 +0000 (09:12 +0000)
It is kinda surprising that

image2 = fromPlanar(image, 2, NULL)
mapImage(..., image2, ...)

does not map the third plane.

This implements that behavior in the case where the DRI frontend
lowers the multi-planar textures.

In the case it doesn't this would need driver support. AFAIU at
least etnaviv is impacted, and while it looks possible, I don't
have the etnaviv knowledge to implement it.

Instead of silently returning weird results (either always plane 0
or possibly something interleaved) this adds an error return on
mapping multi-planar textures otherwise.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5200>

src/gallium/frontends/dri/dri2.c
src/gallium/frontends/dri/dri_screen.h

index bfbaa1bd84aa6b4d4d101494bc8dccb7ffef94af..9facc47d1da0f6c8f7f3794181ca4eb69cc11ee3 100644 (file)
@@ -801,6 +801,7 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
    img->layer = 0;
    img->use = 0;
    img->loader_private = loaderPrivate;
    img->layer = 0;
    img->use = 0;
    img->loader_private = loaderPrivate;
+   img->lowered_yuv = use_lowered;
 
    return img;
 }
 
    return img;
 }
@@ -1010,6 +1011,7 @@ dri2_create_image_common(__DRIscreen *_screen,
    img->dri_fourcc = map->dri_fourcc;
    img->dri_components = 0;
    img->use = use;
    img->dri_fourcc = map->dri_fourcc;
    img->dri_components = 0;
    img->use = use;
+   img->lowered_yuv = false;
 
    img->loader_private = loaderPrivate;
    return img;
 
    img->loader_private = loaderPrivate;
    return img;
@@ -1260,6 +1262,7 @@ dri2_dup_image(__DRIimage *image, void *loaderPrivate)
    /* This should be 0 for sub images, but dup is also used for base images. */
    img->dri_components = image->dri_components;
    img->loader_private = loaderPrivate;
    /* This should be 0 for sub images, but dup is also used for base images. */
    img->dri_components = image->dri_components;
    img->loader_private = loaderPrivate;
+   img->lowered_yuv = image->lowered_yuv;
 
    return img;
 }
 
    return img;
 }
@@ -1542,20 +1545,30 @@ dri2_map_image(__DRIcontext *context, __DRIimage *image,
    struct dri_context *ctx = dri_context(context);
    struct pipe_context *pipe = ctx->st->pipe;
    enum pipe_transfer_usage pipe_access = 0;
    struct dri_context *ctx = dri_context(context);
    struct pipe_context *pipe = ctx->st->pipe;
    enum pipe_transfer_usage pipe_access = 0;
+   struct pipe_resource *resource = image->texture;
    struct pipe_transfer *trans;
    void *map;
 
    if (!image || !data || *data)
       return NULL;
 
    struct pipe_transfer *trans;
    void *map;
 
    if (!image || !data || *data)
       return NULL;
 
+   if (image->lowered_yuv) {
+      unsigned plane = image->plane;
+      if (plane >= dri2_get_mapping_by_format(image->dri_format)->nplanes)
+         return NULL;
+
+      while (plane--)
+         resource = resource->next;
+   } else if (dri2_get_mapping_by_format(image->dri_format)->nplanes > 1)
+      return NULL;
+
    if (flags & __DRI_IMAGE_TRANSFER_READ)
          pipe_access |= PIPE_TRANSFER_READ;
    if (flags & __DRI_IMAGE_TRANSFER_WRITE)
          pipe_access |= PIPE_TRANSFER_WRITE;
 
    if (flags & __DRI_IMAGE_TRANSFER_READ)
          pipe_access |= PIPE_TRANSFER_READ;
    if (flags & __DRI_IMAGE_TRANSFER_WRITE)
          pipe_access |= PIPE_TRANSFER_WRITE;
 
-   map = pipe_transfer_map(pipe, image->texture,
-                           0, 0, pipe_access, x0, y0, width, height,
-                           &trans);
+   map = pipe_transfer_map(pipe, resource, 0, 0, pipe_access, x0, y0,
+                           width, height, &trans);
    if (map) {
       *data = trans;
       *stride = trans->stride;
    if (map) {
       *data = trans;
       *stride = trans->stride;
index e330aa1f2acad74b330619c1d09343d275c97d87..d6f7850a2645a801682d7d930da9bad53d04f6d3 100644 (file)
@@ -106,6 +106,7 @@ struct __DRIimageRec {
    uint32_t dri_components;
    unsigned use;
    unsigned plane;
    uint32_t dri_components;
    unsigned use;
    unsigned plane;
+   bool lowered_yuv;
 
    void *loader_private;
 
 
    void *loader_private;