From a7388f8e6f72b31fa05c824ae1c42bf86794f878 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 5 Apr 2013 14:56:21 -0700 Subject: [PATCH] i965: Only use brw_draw.c's trim() function when necessary. 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 Reviewed-by: Jordan Justen Reviewed-by: Eric Anholt --- 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 7195ec89179..8c37e0b5ef8 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) -- 2.30.2