Module: Mesa
Branch: main
Commit: b1fc5390c6d7422adcc74020d45e8e590c4241ae
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b1fc5390c6d7422adcc74020d45e8e590c4241ae

Author: Rob Clark <robdcl...@chromium.org>
Date:   Mon Nov  6 13:17:32 2023 -0800

freedreno/a6xx: Fix antichamber trace replay assert

This app is generating viewports with scale[0]==0, so that is not a good
condition for testing viewport validity.  It would result in skipping
the only viewport, and ending up with gb x/y being ~0.  Triggering an
assert in the register builder.

The main reason this was done previously was to avoid an assert in
fd_calc_guardband().  Lets just flip it around and return 0x1ff on
errors instead of asserting.  This also makes it more consistent with
the other error cases.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7628
Signed-off-by: Rob Clark <robdcl...@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26086>

---

 src/freedreno/common/freedreno_guardband.h      | 13 +++++++++----
 src/gallium/drivers/freedreno/freedreno_state.c |  4 ----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/freedreno/common/freedreno_guardband.h 
b/src/freedreno/common/freedreno_guardband.h
index 7c72a830e29..0fa5e3d4623 100644
--- a/src/freedreno/common/freedreno_guardband.h
+++ b/src/freedreno/common/freedreno_guardband.h
@@ -28,6 +28,9 @@
 #include <math.h>
 #include <stdbool.h>
 
+/* All 1's but don't overflow the GUARDBAND_CLIP_ADJ bitfields: */
+#define MAX_GB 0x1ff
+
 static inline unsigned
 fd_calc_guardband(float offset, float scale, bool is_a3xx)
 {
@@ -57,13 +60,14 @@ fd_calc_guardband(float offset, float scale, bool is_a3xx)
    const float gb_adj = fminf(-gb_min_ndc, gb_max_ndc);
 
    /* The viewport should always be contained in the guardband. */
-   assert(gb_adj >= 1.0);
+   if (gb_adj < 1.0)
+      return MAX_GB;
 
    /* frexp returns an unspecified value if given an infinite value, which
     * can happen if scale == 0.
     */
    if (isinf(gb_adj))
-      return 0x1ff;
+      return MAX_GB;
 
    /* Convert gb_adj to 3.6 floating point, rounding down since it's always
     * safe to make the guard band smaller (but not the other way around!).
@@ -85,11 +89,12 @@ fd_calc_guardband(float offset, float scale, bool is_a3xx)
     */
    int gb_adj_exp;
    float gb_adj_mantissa = frexpf(gb_adj, &gb_adj_exp);
-   assert(gb_adj_exp > 0);
+   if (gb_adj_exp <= 0)
+      return MAX_GB;
 
    /* Round non-representable numbers down to the largest possible number. */
    if (gb_adj_exp > 8)
-      return 0x1ff;
+      return MAX_GB;
 
    return ((gb_adj_exp - 1) << 6) |
           ((unsigned)truncf(gb_adj_mantissa * (1 << 7)) - (1 << 6));
diff --git a/src/gallium/drivers/freedreno/freedreno_state.c 
b/src/gallium/drivers/freedreno/freedreno_state.c
index d060122498d..69164c1c25b 100644
--- a/src/gallium/drivers/freedreno/freedreno_state.c
+++ b/src/gallium/drivers/freedreno/freedreno_state.c
@@ -459,10 +459,6 @@ fd_set_viewport_states(struct pipe_context *pctx, unsigned 
start_slot,
    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);
 

Reply via email to