<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Jan 22, 2017 at 10:42 PM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Previously we disabled the guardband when the viewport was smaller than<br>
the framebuffer on Gen6-7.5, to prevent portions of primitives from<br>
being draw outside of the viewport.  On Gen8+, we relied on the viewport<br>
extents test to effectively scissor this away for us.<br>
<br>
We can simply always enable scissoring instead.  We already include the<br>
viewport in the scissor rectangle, so this will effectively do the<br>
viewport extents test for us.  (The only difference is that the scissor<br>
rectangle doesn't support sub-pixel values.  I think that's okay.)<br>
<br>
Given that the viewport extents test is essentially a second scissor,<br>
and is enabled for basically all 3D drawing on Gen8+, it stands to<br>
reason that scissoring is cheap.  Enabling the guardband reduces the<br>
cost of clipping, which is expensive.<br>
<br>
The Windows driver appears to never disable guardband clipping, and<br>
appears to use scissoring in this case.  I don't know if they leave<br>
it on universally though.<br>
<br>
This fixes misrendering in Blender, where the "floor plane" grid lines<br>
started rendering at wrong angles after I disabled XY clipping of line<br>
primitives.  Enabling the guardband seems to solve the issue.<br>
<br>
Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=99339" rel="noreferrer" target="_blank">https://bugs.freedesktop.org/<wbr>show_bug.cgi?id=99339</a><br>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
---<br>
 src/mesa/drivers/dri/i965/<wbr>gen6_clip_state.c | 26 --------------------------<br>
 src/mesa/drivers/dri/i965/<wbr>gen6_sf_state.c   | 15 +++------------<br>
 src/mesa/drivers/dri/i965/<wbr>gen7_sf_state.c   | 12 ++----------<br>
 3 files changed, 5 insertions(+), 48 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>gen6_clip_state.c b/src/mesa/drivers/dri/i965/<wbr>gen6_clip_state.c<br>
index 0b3c7f16f18..8e893f5668f 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>gen6_clip_state.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>gen6_clip_state.c<br>
@@ -203,32 +203,6 @@ upload_clip_state(struct brw_context *brw)<br>
       }<br>
    }<br>
<br>
-   /* If the viewport dimensions are smaller than the drawable dimensions,<br>
-    * we have to disable guardband clipping prior to Gen8.  We always program<br>
-    * the guardband to a fixed size, which is almost always larger than the<br>
-    * viewport.  Any geometry which intersects the viewport but lies within<br>
-    * the guardband would bypass the 3D clipping stage, so it wouldn't be<br>
-    * clipped to the viewport.  Rendering would happen beyond the viewport,<br>
-    * but still inside the drawable.<br>
-    *<br>
-    * Gen8+ introduces a viewport extents test which restricts rendering to<br>
-    * the viewport, so we can ignore this restriction.<br>
-    */<br>
-   if (brw->gen < 8) {<br>
-      const float fb_width = (float)_mesa_geometric_width(<wbr>fb);<br>
-      const float fb_height = (float)_mesa_geometric_height(<wbr>fb);<br>
-<br>
-      for (unsigned i = 0; i < viewport_count; i++) {<br>
-         if (ctx->ViewportArray[i].X != 0 ||<br>
-             ctx->ViewportArray[i].Y != 0 ||<br>
-             ctx->ViewportArray[i].Width != fb_width ||<br>
-             ctx->ViewportArray[i].Height != fb_height) {<br>
-            dw2 &= ~GEN6_CLIP_GB_TEST;<br>
-            break;<br>
-         }<br>
-      }<br>
-   }<br>
-<br>
    /* BRW_NEW_RASTERIZER_DISCARD */<br>
    if (ctx->RasterDiscard) {<br>
       dw2 |= GEN6_CLIP_MODE_REJECT_ALL;<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>gen6_sf_state.c b/src/mesa/drivers/dri/i965/<wbr>gen6_sf_state.c<br>
index 738e4f03cda..dd547790c9a 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>gen6_sf_state.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>gen6_sf_state.c<br>
@@ -286,13 +286,12 @@ upload_sf_state(struct brw_context *brw)<br>
<br>
    dw1 = GEN6_SF_SWIZZLE_ENABLE | num_outputs << GEN6_SF_NUM_OUTPUTS_SHIFT;<br>
    dw2 = GEN6_SF_STATISTICS_ENABLE;<br>
+   dw3 = GEN6_SF_SCISSOR_ENABLE;<br>
+   dw4 = 0;<br></blockquote><div><br></div><div>We could, in theory, only scissor if one of our viewports is actually smaller than the framebuffer.  Then again, I agree that scissoring should be cheap so why not.<br><br></div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
    if (brw->sf.viewport_transform_<wbr>enable)<br>
        dw2 |= GEN6_SF_VIEWPORT_TRANSFORM_<wbr>ENABLE;<br>
<br>
-   dw3 = 0;<br>
-   dw4 = 0;<br>
-<br>
    /* _NEW_POLYGON */<br>
    if (ctx->Polygon._FrontBit == render_to_fbo)<br>
       dw2 |= GEN6_SF_WINDING_CCW;<br>
@@ -340,13 +339,6 @@ upload_sf_state(struct brw_context *brw)<br>
        unreachable("not reached");<br>
    }<br>
<br>
-   /* _NEW_SCISSOR | _NEW_POLYGON,<br>
-    * BRW_NEW_GS_PROG_DATA | BRW_NEW_TES_PROG_DATA | BRW_NEW_PRIMITIVE<br>
-    */<br>
-   if (ctx->Scissor.EnableFlags ||<br>
-       brw_is_drawing_points(brw) || brw_is_drawing_lines(brw))<br>
-      dw3 |= GEN6_SF_SCISSOR_ENABLE;<br>
-<br>
    /* _NEW_POLYGON */<br>
    if (ctx->Polygon.CullFlag) {<br>
       switch (ctx->Polygon.CullFaceMode) {<br>
@@ -449,8 +441,7 @@ const struct brw_tracked_state gen6_sf_state = {<br>
                _NEW_MULTISAMPLE |<br>
                _NEW_POINT |<br>
                _NEW_POLYGON |<br>
-               _NEW_PROGRAM |<br>
-               _NEW_SCISSOR,<br>
+               _NEW_PROGRAM,<br>
       .brw   = BRW_NEW_BLORP |<br>
                BRW_NEW_CONTEXT |<br>
                BRW_NEW_FRAGMENT_PROGRAM |<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>gen7_sf_state.c b/src/mesa/drivers/dri/i965/<wbr>gen7_sf_state.c<br>
index f1b3169cdcc..d577a360153 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>gen7_sf_state.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>gen7_sf_state.c<br>
@@ -173,7 +173,7 @@ upload_sf_state(struct brw_context *brw)<br>
        unreachable("not reached");<br>
    }<br>
<br>
-   dw2 = 0;<br>
+   dw2 = GEN6_SF_SCISSOR_ENABLE;<br>
<br>
    if (ctx->Polygon.CullFlag) {<br>
       switch (ctx->Polygon.CullFaceMode) {<br>
@@ -193,13 +193,6 @@ upload_sf_state(struct brw_context *brw)<br>
       dw2 |= GEN6_SF_CULL_NONE;<br>
    }<br>
<br>
-   /* _NEW_SCISSOR | _NEW_POLYGON,<br>
-    * BRW_NEW_GS_PROG_DATA | BRW_NEW_PRIMITIVE | BRW_NEW_TES_PROG_DATA<br>
-    */<br>
-   if (ctx->Scissor.EnableFlags ||<br>
-       brw_is_drawing_points(brw) || brw_is_drawing_lines(brw))<br>
-      dw2 |= GEN6_SF_SCISSOR_ENABLE;<br>
-<br>
    /* _NEW_LINE */<br>
    {<br>
       uint32_t line_width_u3_7 = brw_get_line_width(brw);<br>
@@ -260,8 +253,7 @@ const struct brw_tracked_state gen7_sf_state = {<br>
                _NEW_MULTISAMPLE |<br>
                _NEW_POINT |<br>
                _NEW_POLYGON |<br>
-               _NEW_PROGRAM |<br>
-               _NEW_SCISSOR,<br>
+               _NEW_PROGRAM,<br>
       .brw   = BRW_NEW_BLORP |<br>
                BRW_NEW_CONTEXT |<br>
                BRW_NEW_GS_PROG_DATA |<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.11.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>