radeonsi: remove flushes at the beginning and end of IBs done by the kernel
[mesa.git] / src / gallium / drivers / freedreno / freedreno_gmem.c
index 473d2b891e3ae499067c271dadb2cddde2d17b4f..0d73349057c37b9877b4882eb06f5514a3fc0948 100644 (file)
@@ -77,21 +77,26 @@ static uint32_t bin_width(struct fd_context *ctx)
 }
 
 static uint32_t
-total_size(uint8_t cbuf_cpp[], uint8_t zsbuf_cpp,
+total_size(uint8_t cbuf_cpp[], uint8_t zsbuf_cpp[2],
                   uint32_t bin_w, uint32_t bin_h, struct fd_gmem_stateobj *gmem)
 {
        uint32_t total = 0, i;
 
-       for (i = 0; i < 4; i++) {
+       for (i = 0; i < MAX_RENDER_TARGETS; i++) {
                if (cbuf_cpp[i]) {
                        gmem->cbuf_base[i] = align(total, 0x4000);
                        total = gmem->cbuf_base[i] + cbuf_cpp[i] * bin_w * bin_h;
                }
        }
 
-       if (zsbuf_cpp) {
-               gmem->zsbuf_base = align(total, 0x4000);
-               total = gmem->zsbuf_base + zsbuf_cpp * bin_w * bin_h;
+       if (zsbuf_cpp[0]) {
+               gmem->zsbuf_base[0] = align(total, 0x4000);
+               total = gmem->zsbuf_base[0] + zsbuf_cpp[0] * bin_w * bin_h;
+       }
+
+       if (zsbuf_cpp[1]) {
+               gmem->zsbuf_base[1] = align(total, 0x4000);
+               total = gmem->zsbuf_base[1] + zsbuf_cpp[1] * bin_w * bin_h;
        }
 
        return total;
@@ -108,13 +113,18 @@ calculate_tiles(struct fd_context *ctx)
        uint32_t nbins_x = 1, nbins_y = 1;
        uint32_t bin_w, bin_h;
        uint32_t max_width = bin_width(ctx);
-       uint8_t cbuf_cpp[4] = {0}, zsbuf_cpp = 0;
+       uint8_t cbuf_cpp[MAX_RENDER_TARGETS] = {0}, zsbuf_cpp[2] = {0};
        uint32_t i, j, t, xoff, yoff;
        uint32_t tpp_x, tpp_y;
        bool has_zs = !!(ctx->resolve & (FD_BUFFER_DEPTH | FD_BUFFER_STENCIL));
+       int tile_n[ARRAY_SIZE(ctx->pipe)];
 
-       if (has_zs)
-               zsbuf_cpp = util_format_get_blocksize(pfb->zsbuf->format);
+       if (has_zs) {
+               struct fd_resource *rsc = fd_resource(pfb->zsbuf->texture);
+               zsbuf_cpp[0] = rsc->cpp;
+               if (rsc->stencil)
+                       zsbuf_cpp[1] = rsc->stencil->cpp;
+       }
        for (i = 0; i < pfb->nr_cbufs; i++) {
                if (pfb->cbufs[i])
                        cbuf_cpp[i] = util_format_get_blocksize(pfb->cbufs[i]->format);
@@ -122,7 +132,7 @@ calculate_tiles(struct fd_context *ctx)
                        cbuf_cpp[i] = 4;
        }
 
-       if (gmem->zsbuf_cpp == zsbuf_cpp &&
+       if (!memcmp(gmem->zsbuf_cpp, zsbuf_cpp, sizeof(zsbuf_cpp)) &&
                !memcmp(gmem->cbuf_cpp, cbuf_cpp, sizeof(cbuf_cpp)) &&
                !memcmp(&gmem->scissor, scissor, sizeof(gmem->scissor))) {
                /* everything is up-to-date */
@@ -152,12 +162,17 @@ calculate_tiles(struct fd_context *ctx)
                bin_w = align(width / nbins_x, 32);
        }
 
+       if (fd_mesa_debug & FD_DBG_MSGS) {
+               debug_printf("binning input: cbuf cpp:");
+               for (i = 0; i < pfb->nr_cbufs; i++)
+                       debug_printf(" %d", cbuf_cpp[i]);
+               debug_printf(", zsbuf cpp: %d; %dx%d\n",
+                               zsbuf_cpp[0], width, height);
+       }
+
        /* then find a bin width/height that satisfies the memory
         * constraints:
         */
-       DBG("binning input: cbuf cpp: %d %d %d %d, zsbuf cpp: %d; %dx%d",
-               cbuf_cpp[0], cbuf_cpp[1], cbuf_cpp[2], cbuf_cpp[3], zsbuf_cpp,
-               width, height);
        while (total_size(cbuf_cpp, zsbuf_cpp, bin_w, bin_h, gmem) > gmem_size) {
                if (bin_w > bin_h) {
                        nbins_x++;
@@ -172,7 +187,7 @@ calculate_tiles(struct fd_context *ctx)
 
        gmem->scissor = *scissor;
        memcpy(gmem->cbuf_cpp, cbuf_cpp, sizeof(cbuf_cpp));
-       gmem->zsbuf_cpp = zsbuf_cpp;
+       memcpy(gmem->zsbuf_cpp, zsbuf_cpp, sizeof(zsbuf_cpp));
        gmem->bin_h = bin_h;
        gmem->bin_w = bin_w;
        gmem->nbins_x = nbins_x;
@@ -238,6 +253,7 @@ calculate_tiles(struct fd_context *ctx)
        /* configure tiles: */
        t = 0;
        yoff = miny;
+       memset(tile_n, 0, sizeof(tile_n));
        for (i = 0; i < nbins_y; i++) {
                uint32_t bw, bh;
 
@@ -248,20 +264,17 @@ calculate_tiles(struct fd_context *ctx)
 
                for (j = 0; j < nbins_x; j++) {
                        struct fd_tile *tile = &ctx->tile[t];
-                       uint32_t n, p;
+                       uint32_t p;
 
                        assert(t < ARRAY_SIZE(ctx->tile));
 
                        /* pipe number: */
                        p = ((i / tpp_y) * div_round_up(nbins_x, tpp_x)) + (j / tpp_x);
 
-                       /* slot number: */
-                       n = ((i % tpp_y) * tpp_x) + (j % tpp_x);
-
                        /* clip bin width: */
                        bw = MIN2(bin_w, minx + width - xoff);
 
-                       tile->n = n;
+                       tile->n = tile_n[p]++;
                        tile->p = p;
                        tile->bin_w = bw;
                        tile->bin_h = bh;
@@ -318,7 +331,7 @@ render_tiles(struct fd_context *ctx)
                fd_hw_query_prepare_tile(ctx, i, ctx->ring);
 
                /* emit IB to drawcmds: */
-               OUT_IB(ctx->ring, ctx->draw_start, ctx->draw_end);
+               ctx->emit_ib(ctx->ring, ctx->draw_start, ctx->draw_end);
                fd_reset_wfi(ctx);
 
                /* emit gmem2mem to transfer tile back to system memory: */
@@ -336,7 +349,7 @@ render_sysmem(struct fd_context *ctx)
        fd_hw_query_prepare_tile(ctx, 0, ctx->ring);
 
        /* emit IB to drawcmds: */
-       OUT_IB(ctx->ring, ctx->draw_start, ctx->draw_end);
+       ctx->emit_ib(ctx->ring, ctx->draw_start, ctx->draw_end);
        fd_reset_wfi(ctx);
 }