util: Move gallium's PIPE_FORMAT utils to /util/format/
[mesa.git] / src / gallium / drivers / nouveau / nvc0 / nvc0_transfer.c
index aaec60a5ac222b18d20eaf1f46334fd1348bf595..74ce56a5c5593dc2087a8c0c0a65452b8fbe88e0 100644 (file)
@@ -1,10 +1,8 @@
 
-#include "util/u_format.h"
+#include "util/format/u_format.h"
 
 #include "nvc0/nvc0_context.h"
 
-#include "nv50/nv50_defs.xml.h"
-
 struct nvc0_transfer {
    struct pipe_transfer base;
    struct nv50_m2mf_rect rect[2];
@@ -114,13 +112,27 @@ nve4_m2mf_transfer_rect(struct nvc0_context *nvc0,
                         const struct nv50_m2mf_rect *src,
                         uint32_t nblocksx, uint32_t nblocksy)
 {
+   static const struct {
+      int cs;
+      int nc;
+   } cpbs[] = {
+      [ 1] = { 1, 1 },
+      [ 2] = { 1, 2 },
+      [ 3] = { 1, 3 },
+      [ 4] = { 1, 4 },
+      [ 6] = { 2, 3 },
+      [ 8] = { 2, 4 },
+      [ 9] = { 3, 3 },
+      [12] = { 3, 4 },
+      [16] = { 4, 4 },
+   };
    struct nouveau_pushbuf *push = nvc0->base.pushbuf;
    struct nouveau_bufctx *bctx = nvc0->bufctx;
    uint32_t exec;
    uint32_t src_base = src->base;
    uint32_t dst_base = dst->base;
-   const int cpp = dst->cpp;
 
+   assert(dst->cpp < ARRAY_SIZE(cpbs) && cpbs[dst->cpp].cs);
    assert(dst->cpp == src->cpp);
 
    nouveau_bufctx_refn(bctx, 0, dst->bo, dst->domain | NOUVEAU_BO_WR);
@@ -128,35 +140,45 @@ nve4_m2mf_transfer_rect(struct nvc0_context *nvc0,
    nouveau_pushbuf_bufctx(push, bctx);
    nouveau_pushbuf_validate(push);
 
-   exec = 0x200 /* 2D_ENABLE */ | 0x6 /* UNK */;
+   exec = 0x400 /* REMAP_ENABLE */ | 0x200 /* 2D_ENABLE */ | 0x6 /* UNK */;
+
+   BEGIN_NVC0(push, SUBC_COPY(0x0708), 1);
+   PUSH_DATA (push, (cpbs[dst->cpp].nc - 1) << 24 |
+                    (cpbs[src->cpp].nc - 1) << 20 |
+                    (cpbs[src->cpp].cs - 1) << 16 |
+                    3 << 12 /* DST_W = SRC_W */ |
+                    2 <<  8 /* DST_Z = SRC_Z */ |
+                    1 <<  4 /* DST_Y = SRC_Y */ |
+                    0 <<  0 /* DST_X = SRC_X */);
 
-   if (!nouveau_bo_memtype(dst->bo)) {
+   if (nouveau_bo_memtype(dst->bo)) {
+      BEGIN_NVC0(push, SUBC_COPY(0x070c), 6);
+      PUSH_DATA (push, 0x1000 | dst->tile_mode);
+      PUSH_DATA (push, dst->width);
+      PUSH_DATA (push, dst->height);
+      PUSH_DATA (push, dst->depth);
+      PUSH_DATA (push, dst->z);
+      PUSH_DATA (push, (dst->y << 16) | dst->x);
+   } else {
       assert(!dst->z);
-      dst_base += dst->y * dst->pitch + dst->x * cpp;
+      dst_base += dst->y * dst->pitch + dst->x * dst->cpp;
       exec |= 0x100; /* DST_MODE_2D_LINEAR */
    }
-   if (!nouveau_bo_memtype(src->bo)) {
+
+   if (nouveau_bo_memtype(src->bo)) {
+      BEGIN_NVC0(push, SUBC_COPY(0x0728), 6);
+      PUSH_DATA (push, 0x1000 | src->tile_mode);
+      PUSH_DATA (push, src->width);
+      PUSH_DATA (push, src->height);
+      PUSH_DATA (push, src->depth);
+      PUSH_DATA (push, src->z);
+      PUSH_DATA (push, (src->y << 16) | src->x);
+   } else {
       assert(!src->z);
-      src_base += src->y * src->pitch + src->x * cpp;
+      src_base += src->y * src->pitch + src->x * src->cpp;
       exec |= 0x080; /* SRC_MODE_2D_LINEAR */
    }
 
-   BEGIN_NVC0(push, SUBC_COPY(0x070c), 6);
-   PUSH_DATA (push, 0x1000 | dst->tile_mode);
-   PUSH_DATA (push, dst->pitch);
-   PUSH_DATA (push, dst->height);
-   PUSH_DATA (push, dst->depth);
-   PUSH_DATA (push, dst->z);
-   PUSH_DATA (push, (dst->y << 16) | (dst->x * cpp));
-
-   BEGIN_NVC0(push, SUBC_COPY(0x0728), 6);
-   PUSH_DATA (push, 0x1000 | src->tile_mode);
-   PUSH_DATA (push, src->pitch);
-   PUSH_DATA (push, src->height);
-   PUSH_DATA (push, src->depth);
-   PUSH_DATA (push, src->z);
-   PUSH_DATA (push, (src->y << 16) | (src->x * cpp));
-
    BEGIN_NVC0(push, SUBC_COPY(0x0400), 8);
    PUSH_DATAh(push, src->bo->offset + src_base);
    PUSH_DATA (push, src->bo->offset + src_base);
@@ -164,7 +186,7 @@ nve4_m2mf_transfer_rect(struct nvc0_context *nvc0,
    PUSH_DATA (push, dst->bo->offset + dst_base);
    PUSH_DATA (push, src->pitch);
    PUSH_DATA (push, dst->pitch);
-   PUSH_DATA (push, nblocksx * cpp);
+   PUSH_DATA (push, nblocksx);
    PUSH_DATA (push, nblocksy);
 
    BEGIN_NVC0(push, SUBC_COPY(0x0300), 1);
@@ -188,14 +210,10 @@ nvc0_m2mf_push_linear(struct nouveau_context *nv,
    nouveau_pushbuf_validate(push);
 
    while (count) {
-      unsigned nr;
+      unsigned nr = MIN2(count, NV04_PFIFO_MAX_PACKET_LEN);
 
-      if (!PUSH_SPACE(push, 16))
+      if (!PUSH_SPACE(push, nr + 9))
          break;
-      nr = PUSH_AVAIL(push);
-      assert(nr >= 16);
-      nr = MIN2(count, nr - 9);
-      nr = MIN2(nr, NV04_PFIFO_MAX_PACKET_LEN);
 
       BEGIN_NVC0(push, NVC0_M2MF(OFFSET_OUT_HIGH), 2);
       PUSH_DATAh(push, dst->offset + offset);
@@ -234,14 +252,10 @@ nve4_p2mf_push_linear(struct nouveau_context *nv,
    nouveau_pushbuf_validate(push);
 
    while (count) {
-      unsigned nr;
+      unsigned nr = MIN2(count, (NV04_PFIFO_MAX_PACKET_LEN - 1));
 
-      if (!PUSH_SPACE(push, 16))
+      if (!PUSH_SPACE(push, nr + 10))
          break;
-      nr = PUSH_AVAIL(push);
-      assert(nr >= 16);
-      nr = MIN2(count, nr - 8);
-      nr = MIN2(nr, (NV04_PFIFO_MAX_PACKET_LEN - 1));
 
       BEGIN_NVC0(push, NVE4_P2MF(UPLOAD_DST_ADDRESS_HIGH), 2);
       PUSH_DATAh(push, dst->offset + offset);
@@ -348,8 +362,8 @@ nvc0_mt_sync(struct nvc0_context *nvc0, struct nv50_miptree *mt, unsigned usage)
       return !nouveau_bo_wait(mt->base.bo, access, nvc0->base.client);
    }
    if (usage & PIPE_TRANSFER_WRITE)
-      return !mt->base.fence || nouveau_fence_wait(mt->base.fence);
-   return !mt->base.fence_wr || nouveau_fence_wait(mt->base.fence_wr);
+      return !mt->base.fence || nouveau_fence_wait(mt->base.fence, &nvc0->base.debug);
+   return !mt->base.fence_wr || nouveau_fence_wait(mt->base.fence_wr, &nvc0->base.debug);
 }
 
 void *
@@ -400,15 +414,22 @@ nvc0_miptree_transfer_map(struct pipe_context *pctx,
    }
    tx->nlayers = box->depth;
 
-   tx->base.stride = tx->nblocksx * util_format_get_blocksize(res->format);
-   tx->base.layer_stride = tx->nblocksy * tx->base.stride;
-
    if (usage & PIPE_TRANSFER_MAP_DIRECTLY) {
-      tx->base.stride = align(tx->base.stride, 128);
+      tx->base.stride = mt->level[level].pitch;
+      tx->base.layer_stride = mt->layer_stride;
+      uint32_t offset = box->y * tx->base.stride +
+         util_format_get_stride(res->format, box->x);
+      if (!mt->layout_3d)
+         offset += mt->layer_stride * box->z;
+      else
+         offset += nvc0_mt_zslice_offset(mt, level, box->z);
       *ptransfer = &tx->base;
-      return mt->base.bo->map + mt->base.offset;
+      return mt->base.bo->map + mt->base.offset + offset;
    }
 
+   tx->base.stride = tx->nblocksx * util_format_get_blocksize(res->format);
+   tx->base.layer_stride = tx->nblocksy * tx->base.stride;
+
    nv50_m2mf_rect_setup(&tx->rect[0], res, level, box->x, box->y, box->z);
 
    size = tx->base.layer_stride;
@@ -571,9 +592,7 @@ nvc0_cb_bo_push(struct nouveau_context *nv,
    PUSH_DATA (push, bo->offset + base);
 
    while (words) {
-      unsigned nr = PUSH_AVAIL(push);
-      nr = MIN2(nr, words);
-      nr = MIN2(nr, NV04_PFIFO_MAX_PACKET_LEN - 1);
+      unsigned nr = MIN2(words, NV04_PFIFO_MAX_PACKET_LEN - 1);
 
       PUSH_SPACE(push, nr + 2);
       PUSH_REFN (push, bo, NOUVEAU_BO_WR | domain);