freedreno: avoid mem2gmem for invalidated buffers
authorRob Clark <robdclark@gmail.com>
Sun, 19 Nov 2017 17:50:50 +0000 (12:50 -0500)
committerRob Clark <robdclark@gmail.com>
Sun, 3 Dec 2017 19:17:41 +0000 (14:17 -0500)
Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/freedreno_draw.c
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_resource.h

index 3f70c89..bcd21a2 100644 (file)
@@ -54,6 +54,7 @@ resource_written(struct fd_batch *batch, struct pipe_resource *prsc)
 {
        if (!prsc)
                return;
+       fd_resource(prsc)->valid = true;
        fd_batch_resource_used(batch, fd_resource(prsc), true);
 }
 
@@ -64,7 +65,7 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
        struct fd_batch *batch = ctx->batch;
        struct pipe_framebuffer_state *pfb = &batch->framebuffer;
        struct pipe_scissor_state *scissor = fd_context_get_scissor(ctx);
-       unsigned i, prims, buffers = 0;
+       unsigned i, prims, buffers = 0, restore_buffers = 0;
 
        if (!info->count_from_stream_output && !info->indirect &&
            !info->primitive_restart &&
@@ -127,12 +128,16 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
        mtx_lock(&ctx->screen->lock);
 
        if (fd_depth_enabled(ctx)) {
+               if (fd_resource(pfb->zsbuf->texture)->valid)
+                       restore_buffers |= FD_BUFFER_DEPTH;
                buffers |= FD_BUFFER_DEPTH;
                resource_written(batch, pfb->zsbuf->texture);
                batch->gmem_reason |= FD_GMEM_DEPTH_ENABLED;
        }
 
        if (fd_stencil_enabled(ctx)) {
+               if (fd_resource(pfb->zsbuf->texture)->valid)
+                       restore_buffers |= FD_BUFFER_DEPTH;
                buffers |= FD_BUFFER_STENCIL;
                resource_written(batch, pfb->zsbuf->texture);
                batch->gmem_reason |= FD_GMEM_STENCIL_ENABLED;
@@ -150,6 +155,10 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
                surf = pfb->cbufs[i]->texture;
 
                resource_written(batch, surf);
+
+               if (fd_resource(surf)->valid)
+                       restore_buffers |= PIPE_CLEAR_COLOR0 << i;
+
                buffers |= PIPE_CLEAR_COLOR0 << i;
 
                if (surf->nr_samples > 1)
@@ -223,7 +232,7 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
        ctx->stats.prims_generated += prims;
 
        /* any buffers that haven't been cleared yet, we need to restore: */
-       batch->restore |= buffers & (FD_BUFFER_ALL & ~batch->cleared);
+       batch->restore |= restore_buffers & (FD_BUFFER_ALL & ~batch->cleared);
        /* and any buffers used, need to be resolved: */
        batch->resolve |= buffers;
 
index 54b66c0..8ba43a1 100644 (file)
@@ -672,6 +672,9 @@ fd_resource_transfer_map(struct pipe_context *pctx,
                offset = 0;
        }
 
+       if (usage & PIPE_TRANSFER_WRITE)
+               rsc->valid = true;
+
        *pptrans = ptrans;
 
        return buf + offset;
@@ -1195,6 +1198,8 @@ fd_invalidate_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
                        }
                }
        }
+
+       rsc->valid = false;
 }
 
 void
index 5bdb007..539470c 100644 (file)
@@ -73,6 +73,7 @@ struct fd_resource {
        struct fd_resource_slice slices[MAX_MIP_LEVELS];
        /* buffer range that has been initialized */
        struct util_range valid_buffer_range;
+       bool valid;
 
        /* reference to the resource holding stencil data for a z32_s8 texture */
        /* TODO rename to secondary or auxiliary? */