From 23b7948a72b91a4c84e637e64de3c96f1cb1a4c3 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Sun, 16 Oct 2022 13:35:14 -0700 Subject: [PATCH] freedreno: Move guardband calc to bind time No point in re-calculating this at emit time. Even more so when there are multiple viewports. Signed-off-by: Rob Clark Part-of: --- src/gallium/drivers/freedreno/a6xx/fd6_emit.c | 10 ++------- src/gallium/drivers/freedreno/freedreno_context.h | 3 +++ src/gallium/drivers/freedreno/freedreno_state.c | 25 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_emit.c b/src/gallium/drivers/freedreno/a6xx/fd6_emit.c index a1245c0..44241c3 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_emit.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_emit.c @@ -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 diff --git a/src/gallium/drivers/freedreno/freedreno_context.h b/src/gallium/drivers/freedreno/freedreno_context.h index b2b117d..d9b0da5 100644 --- a/src/gallium/drivers/freedreno/freedreno_context.h +++ b/src/gallium/drivers/freedreno/freedreno_context.h @@ -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; diff --git a/src/gallium/drivers/freedreno/freedreno_state.c b/src/gallium/drivers/freedreno/freedreno_state.c index 58729ed..a23870b 100644 --- a/src/gallium/drivers/freedreno/freedreno_state.c +++ b/src/gallium/drivers/freedreno/freedreno_state.c @@ -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 -- 2.7.4