freedreno: Move guardband calc to bind time
authorRob Clark <robdclark@chromium.org>
Sun, 16 Oct 2022 20:35:14 +0000 (13:35 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 28 Oct 2022 19:13:27 +0000 (19:13 +0000)
No point in re-calculating this at emit time.  Even more so when there
are multiple viewports.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19236>

src/gallium/drivers/freedreno/a6xx/fd6_emit.c
src/gallium/drivers/freedreno/freedreno_context.h
src/gallium/drivers/freedreno/freedreno_state.c

index a1245c0..44241c3 100644 (file)
@@ -34,7 +34,6 @@
 #include "util/u_string.h"
 #include "util/u_viewport.h"
 
-#include "common/freedreno_guardband.h"
 #include "freedreno_query_hw.h"
 #include "freedreno_resource.h"
 #include "freedreno_state.h"
@@ -982,13 +981,8 @@ fd6_emit_non_ring(struct fd_ringbuffer *ring, struct fd6_emit *emit) assert_dt
          A6XX_GRAS_SC_VIEWPORT_SCISSOR_BR(0, .x = scissor->maxx,
                                           .y = scissor->maxy));
 
-      unsigned guardband_x = fd_calc_guardband(vp->translate[0],
-                                               vp->scale[0], false);
-      unsigned guardband_y = fd_calc_guardband(vp->translate[1],
-                                               vp->scale[1], false);
-
-      OUT_REG(ring, A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ(.horz = guardband_x,
-                                                    .vert = guardband_y));
+      OUT_REG(ring, A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ(.horz = ctx->guardband.x,
+                                                    .vert = ctx->guardband.y));
    }
 
    /* The clamp ranges are only used when the rasterizer wants depth
index b2b117d..d9b0da5 100644 (file)
@@ -404,6 +404,9 @@ struct fd_context {
    struct pipe_poly_stipple stipple dt;
    struct pipe_viewport_state viewport[PIPE_MAX_VIEWPORTS] dt;
    struct pipe_scissor_state viewport_scissor[PIPE_MAX_VIEWPORTS] dt;
+   struct {
+      unsigned x, y;
+   } guardband dt;
    struct fd_constbuf_stateobj constbuf[PIPE_SHADER_TYPES] dt;
    struct fd_shaderbuf_stateobj shaderbuf[PIPE_SHADER_TYPES] dt;
    struct fd_shaderimg_stateobj shaderimg[PIPE_SHADER_TYPES] dt;
index 58729ed..a23870b 100644 (file)
@@ -31,6 +31,8 @@
 #include "util/u_string.h"
 #include "util/u_upload_mgr.h"
 
+#include "common/freedreno_guardband.h"
+
 #include "freedreno_context.h"
 #include "freedreno_gmem.h"
 #include "freedreno_query_hw.h"
@@ -407,6 +409,29 @@ fd_set_viewport_states(struct pipe_context *pctx, unsigned start_slot,
    }
 
    fd_context_dirty(ctx, FD_DIRTY_VIEWPORT);
+
+   /* Guardband is only used on a6xx so far: */
+   if (!is_a6xx(ctx->screen))
+      return;
+
+   ctx->guardband.x = ~0;
+   ctx->guardband.y = ~0;
+
+   bool is3x = is_a3xx(ctx->screen);
+
+   for (unsigned i = 0; i < PIPE_MAX_VIEWPORTS; i++) {
+      const struct pipe_viewport_state *vp = & ctx->viewport[i];
+
+      /* skip unused viewports: */
+      if (vp->scale[0] == 0)
+         continue;
+
+      unsigned gx = fd_calc_guardband(vp->translate[0], vp->scale[0], is3x);
+      unsigned gy = fd_calc_guardband(vp->translate[1], vp->scale[1], is3x);
+
+      ctx->guardband.x = MIN2(ctx->guardband.x, gx);
+      ctx->guardband.y = MIN2(ctx->guardband.y, gy);
+   }
 }
 
 static void