freedreno: skip depth resolve if not written
authorRob Clark <robdclark@gmail.com>
Wed, 26 Dec 2018 19:09:55 +0000 (14:09 -0500)
committerRob Clark <robdclark@gmail.com>
Thu, 3 Jan 2019 13:09:24 +0000 (08:09 -0500)
For multi-pass rendering, it is common to keep the same depth buffer
from previous pass, to discard geometry that would be hidden by later
draws.  In the later passes with depth-test enabled, but depth-write
disabled, there is no reason to do gmem2mem resolve.

TODO probably do something similar for stencil.. although stencil
buffer isn't used as commonly these days

Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/freedreno_draw.c
src/gallium/drivers/freedreno/freedreno_gmem.c
src/gallium/drivers/freedreno/freedreno_state.h

index f17cb56306326adfd318022dda0a2b8a95429c32..8b4073da476354fa40856ba33afbfff87d264032 100644 (file)
@@ -144,9 +144,13 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
                        } else {
                                batch->invalidated |= FD_BUFFER_DEPTH;
                        }
-                       buffers |= FD_BUFFER_DEPTH;
-                       resource_written(batch, pfb->zsbuf->texture);
                        batch->gmem_reason |= FD_GMEM_DEPTH_ENABLED;
+                       if (fd_depth_write_enabled(ctx)) {
+                               buffers |= FD_BUFFER_DEPTH;
+                               resource_written(batch, pfb->zsbuf->texture);
+                       } else {
+                               resource_read(batch, pfb->zsbuf->texture);
+                       }
                }
 
                if (fd_stencil_enabled(ctx)) {
@@ -155,9 +159,9 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
                        } else {
                                batch->invalidated |= FD_BUFFER_STENCIL;
                        }
+                       batch->gmem_reason |= FD_GMEM_STENCIL_ENABLED;
                        buffers |= FD_BUFFER_STENCIL;
                        resource_written(batch, pfb->zsbuf->texture);
-                       batch->gmem_reason |= FD_GMEM_STENCIL_ENABLED;
                }
        }
 
index bb15f0a3e164d529c4fddb02ad49fd24cf2f2ab6..0814a0c76315e9f8e9f87653bd1bff84b7e751cc 100644 (file)
@@ -120,7 +120,8 @@ calculate_tiles(struct fd_batch *batch)
        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 = !!(batch->resolve & (FD_BUFFER_DEPTH | FD_BUFFER_STENCIL));
+       bool has_zs = !!((batch->resolve | batch->restore) &
+                       (FD_BUFFER_DEPTH | FD_BUFFER_STENCIL));
        int tile_n[npipes];
 
        if (has_zs) {
index 35584e41e3a80c8576b3271666440c925bca0aa8..ad2c4943ec8b9ad22e9cea037cf06db479af10de 100644 (file)
@@ -35,6 +35,11 @@ static inline bool fd_depth_enabled(struct fd_context *ctx)
        return ctx->zsa && ctx->zsa->depth.enabled;
 }
 
+static inline bool fd_depth_write_enabled(struct fd_context *ctx)
+{
+       return ctx->zsa && ctx->zsa->depth.writemask;
+}
+
 static inline bool fd_stencil_enabled(struct fd_context *ctx)
 {
        return ctx->zsa && ctx->zsa->stencil[0].enabled;