lima: add layer_stride field to lima_resource struct
authorArno Messiaen <arnomessiaen@gmail.com>
Sun, 29 Sep 2019 21:20:45 +0000 (23:20 +0200)
committerVasily Khoruzhick <anarsoul@gmail.com>
Thu, 31 Oct 2019 06:29:31 +0000 (06:29 +0000)
Signed-off-by: Arno Messiaen <arnomessiaen@gmail.com>
Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>
Reviewed-by: Erico Nunes <nunes.erico@gmail.com>
src/gallium/drivers/lima/lima_draw.c
src/gallium/drivers/lima/lima_resource.c
src/gallium/drivers/lima/lima_resource.h

index e4db471fe304bc8ec5d2cacbd094981aa1d9a50c..7706ee112aa9dcb96893669d4ae4f4bde1476dc3 100644 (file)
@@ -1393,12 +1393,13 @@ lima_pack_wb_cbuf_reg(struct lima_context *ctx, uint32_t *wb_reg, int wb_idx)
    struct lima_context_framebuffer *fb = &ctx->framebuffer;
    struct lima_resource *res = lima_resource(fb->base.cbufs[0]->texture);
    int level = fb->base.cbufs[0]->u.tex.level;
+   unsigned layer = fb->base.cbufs[0]->u.tex.first_layer;
    uint32_t format = lima_format_get_pixel(fb->base.cbufs[0]->format);
    bool swap_channels = lima_format_get_swap_rb(fb->base.cbufs[0]->format);
 
    struct lima_pp_wb_reg *wb = (void *)wb_reg;
    wb[wb_idx].type = 0x02; /* 2 for color buffer */
-   wb[wb_idx].address = res->bo->va + res->levels[level].offset;
+   wb[wb_idx].address = res->bo->va + res->levels[level].offset + layer * res->levels[level].layer_stride;
    wb[wb_idx].pixel_format = format;
    if (res->tiled) {
       wb[wb_idx].pixel_layout = 0x2;
index e01e60c04651618eff510fd8a3d8fd275b08fc52..5898670e397cf453ffbe4c8f3b8f0435c7327450 100644 (file)
@@ -116,6 +116,7 @@ setup_miptree(struct lima_resource *res,
       res->levels[level].width = aligned_width;
       res->levels[level].stride = stride;
       res->levels[level].offset = size;
+      res->levels[level].layer_stride = util_format_get_stride(pres->format, align(width, 16)) * align(height, 16);
 
       /* The start address of each level <= 10 must be 64-aligned
        * in order to be able to pass the addresses
@@ -595,20 +596,25 @@ lima_transfer_map(struct pipe_context *pctx,
 
       trans->staging = malloc(ptrans->stride * ptrans->box.height * ptrans->box.depth);
 
-      if (usage & PIPE_TRANSFER_READ)
-         panfrost_load_tiled_image(trans->staging, bo->map + res->levels[level].offset,
-                              &ptrans->box,
-                              ptrans->stride,
-                              res->levels[level].stride,
-                              util_format_get_blocksize(pres->format));
+      if (usage & PIPE_TRANSFER_READ) {
+         unsigned i;
+         for (i = 0; i < ptrans->box.depth; i++)
+            panfrost_load_tiled_image(
+               trans->staging + i * ptrans->stride * ptrans->box.height,
+               bo->map + res->levels[level].offset + (i + box->z) * res->levels[level].layer_stride,
+               &ptrans->box,
+               ptrans->stride,
+               res->levels[level].stride,
+               util_format_get_blocksize(pres->format));
+      }
 
       return trans->staging;
    } else {
       ptrans->stride = res->levels[level].stride;
-      ptrans->layer_stride = ptrans->stride * box->height;
+      ptrans->layer_stride = res->levels[level].layer_stride;
 
       return bo->map + res->levels[level].offset +
-         box->z * ptrans->layer_stride +
+         box->z * res->levels[level].layer_stride +
          box->y / util_format_get_blockheight(pres->format) * ptrans->stride +
          box->x / util_format_get_blockwidth(pres->format) *
          util_format_get_blocksize(pres->format);
@@ -635,12 +641,17 @@ lima_transfer_unmap(struct pipe_context *pctx,
 
    if (trans->staging) {
       pres = &res->base;
-      if (ptrans->usage & PIPE_TRANSFER_WRITE)
-         panfrost_store_tiled_image(bo->map + res->levels[ptrans->level].offset, trans->staging,
-                              &ptrans->box,
-                              res->levels[ptrans->level].stride,
-                              ptrans->stride,
-                              util_format_get_blocksize(pres->format));
+      if (ptrans->usage & PIPE_TRANSFER_WRITE) {
+         unsigned i;
+         for (i = 0; i < ptrans->box.depth; i++)
+            panfrost_store_tiled_image(
+               bo->map + res->levels[ptrans->level].offset + (i + ptrans->box.z) * res->levels[ptrans->level].layer_stride,
+               trans->staging + i * ptrans->stride * ptrans->box.height,
+               &ptrans->box,
+               res->levels[ptrans->level].stride,
+               ptrans->stride,
+               util_format_get_blocksize(pres->format));
+      }
       free(trans->staging);
    }
 
index 3c2afd8aa4c7ce31b5e651ad453fbfab6f24f1cf..d1f15eb502419c3431ec474808de9f2a8bd978a9 100644 (file)
@@ -36,6 +36,7 @@ struct lima_resource_level {
    uint32_t width;
    uint32_t stride;
    uint32_t offset;
+   uint32_t layer_stride;
 };
 
 struct lima_damage_region {