[Mesa-stable] [PATCH] i965: Only use brw_draw.c's trim() function when necessary.

Paul Berry stereotype441 at gmail.com
Thu Jul 25 15:11:01 PDT 2013


brw_draw.c contains a trim() function which modifies the vertex count
for quads and quad strips in order to discard dangling vertices.  In
principle this shouldn't be necessary, since hardware since Gen4 is
capable of discarding dangling vertices by itself.  However, it's
necessary because as a hack to speed up rendering on Gen 4-5, we
sometimes convert quads to trifans and quad strips to tristrips.  The
trim() function isn't necessary on Gen6 and up.

This patch documents why and when the trim() function is necessary,
and avoids calling it when it's not needed.

This will avoid creating problems when we enable hardware support for
primitive restart of quads and quad strips on Haswell.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Jordan Justen <jordan.l.justen at intel.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
(cherry picked from commit a7388f8e6f72b31fa05c824ae1c42bf86794f878)

This patch is a prerequisite for commit
34efd9214d4daabb56f7f39bdbd6836472979b76 (i965/gen7.5: Allow HW
primitive restart for all primitive types.), which was cherry-picked
to 9.1 in commit f1c0c7b3b341abe4ad3f31ef3066ef6bb428b692.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=65490

CC: mesa-stable at lists.freedesktop.org
---
 src/mesa/drivers/dri/i965/brw_draw.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c
index 2c2b826..988eef6 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -136,6 +136,14 @@ static void gen6_set_prim(struct brw_context *brw,
 }
 
 
+/**
+ * The hardware is capable of removing dangling vertices on its own; however,
+ * prior to Gen6, we sometimes convert quads into trifans (and quad strips
+ * into tristrips), since pre-Gen6 hardware requires a GS to render quads.
+ * This function manually trims dangling vertices from a draw call involving
+ * quads so that those dangling vertices won't get drawn when we convert to
+ * trifans/tristrips.
+ */
 static GLuint trim(GLenum prim, GLuint length)
 {
    if (prim == GL_QUAD_STRIP)
@@ -171,7 +179,11 @@ static void brw_emit_prim(struct brw_context *brw,
       start_vertex_location += brw->vb.start_vertex_bias;
    }
 
-   verts_per_instance = trim(prim->mode, prim->count);
+   /* We only need to trim the primitive count on pre-Gen6. */
+   if (intel->gen < 6)
+      verts_per_instance = trim(prim->mode, prim->count);
+   else
+      verts_per_instance = prim->count;
 
    /* If nothing to emit, just return. */
    if (verts_per_instance == 0)
@@ -228,7 +240,7 @@ static void gen7_emit_prim(struct brw_context *brw,
       start_vertex_location += brw->vb.start_vertex_bias;
    }
 
-   verts_per_instance = trim(prim->mode, prim->count);
+   verts_per_instance = prim->count;
 
    /* If nothing to emit, just return. */
    if (verts_per_instance == 0)
-- 
1.8.3.4



More information about the mesa-stable mailing list