[Mesa-dev] [PATCH 15/19] i965: Change type of brw_context.primitive from GLenum to hardware primitive

Chad Versace chad at chad-versace.us
Fri Sep 23 17:37:45 PDT 2011


For example, GL_TRIANLES is converted to _3DPRIM_TRILIST.

The conversion is necessary because HiZ and MSAA resolve operations emit
a 3DPRIM_RECTLIST, which cannot be conveyed by GLenum.

As a consequence, brw_gs_prog_key.primitive is also converted.

Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 src/mesa/drivers/dri/i965/brw_context.h |    2 +-
 src/mesa/drivers/dri/i965/brw_draw.c    |   67 ++++++++++++++++---------------
 src/mesa/drivers/dri/i965/brw_gs.c      |   44 +++++++++++---------
 src/mesa/drivers/dri/i965/brw_gs.h      |    2 +-
 4 files changed, 62 insertions(+), 53 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 177aa67..96c3733 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -585,7 +585,7 @@ struct brw_query_object {
 struct brw_context 
 {
    struct intel_context intel;  /**< base class, must be first field */
-   GLuint primitive;
+   uint32_t primitive; /**< Hardware primitive, one of _3DPRIM_*. */
 
    GLboolean emit_state_always;
    GLboolean has_surface_tile_offset;
diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c
index a7becb3..351f351 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -59,18 +59,22 @@ static GLuint prim_to_hw_prim[GL_POLYGON+1] = {
    _3DPRIM_POLYGON
 };
 
-
-static const GLenum reduced_prim[GL_POLYGON+1] = {  
-   GL_POINTS,
-   GL_LINES,
-   GL_LINES,
-   GL_LINES,
-   GL_TRIANGLES,
-   GL_TRIANGLES,
-   GL_TRIANGLES,
-   GL_TRIANGLES,
-   GL_TRIANGLES,
-   GL_TRIANGLES
+static const GLenum
+brw_get_reduced_prim(uint32_t hw_prim)
+{
+   switch (hw_prim) {
+   case _3DPRIM_POINTLIST:  return GL_POINTS;
+   case _3DPRIM_LINELIST:   return GL_LINES;
+   case _3DPRIM_LINELOOP:   return GL_LINES;
+   case _3DPRIM_LINESTRIP:  return GL_LINES;
+   case _3DPRIM_TRILIST:    return GL_TRIANGLES;
+   case _3DPRIM_TRISTRIP:   return GL_TRIANGLES;
+   case _3DPRIM_TRIFAN:     return GL_TRIANGLES;
+   case _3DPRIM_QUADLIST:   return GL_TRIANGLES;
+   case _3DPRIM_QUADSTRIP:  return GL_TRIANGLES;
+   case _3DPRIM_POLYGON:    return GL_TRIANGLES;
+   default:                 assert(0); return 0;
+   }
 };
 
 
@@ -79,41 +83,40 @@ static const GLenum reduced_prim[GL_POLYGON+1] = {
  * programs be immune to the active primitive (ie. cope with all
  * possibilities).  That may not be realistic however.
  */
-static GLuint brw_set_prim(struct brw_context *brw,
+static void brw_set_prim(struct brw_context *brw,
 			   const struct _mesa_prim *prim)
 {
    struct gl_context *ctx = &brw->intel.ctx;
-   GLenum mode = prim->mode;
+   uint32_t hw_prim;
 
    DBG("PRIM: %s\n", _mesa_lookup_enum_by_nr(prim->mode));
 
    /* Slight optimization to avoid the GS program when not needed:
     */
-   if (mode == GL_QUAD_STRIP &&
-       ctx->Light.ShadeModel != GL_FLAT &&
-       ctx->Polygon.FrontMode == GL_FILL &&
-       ctx->Polygon.BackMode == GL_FILL)
-      mode = GL_TRIANGLE_STRIP;
-
-   if (prim->mode == GL_QUADS && prim->count == 4 &&
+   if (prim->mode == GL_QUAD_STRIP &&
        ctx->Light.ShadeModel != GL_FLAT &&
        ctx->Polygon.FrontMode == GL_FILL &&
        ctx->Polygon.BackMode == GL_FILL) {
-      mode = GL_TRIANGLE_FAN;
+      hw_prim = _3DPRIM_TRISTRIP;
+   } else if (prim->mode == GL_QUADS && prim->count == 4 &&
+	      ctx->Light.ShadeModel != GL_FLAT &&
+	      ctx->Polygon.FrontMode == GL_FILL &&
+	      ctx->Polygon.BackMode == GL_FILL) {
+      hw_prim = _3DPRIM_TRIFAN;
+   } else {
+      hw_prim = prim_to_hw_prim[prim->mode];
    }
 
-   if (mode != brw->primitive) {
-      brw->primitive = mode;
+   if (hw_prim != brw->primitive) {
+      brw->primitive = hw_prim;
       brw->state.dirty.brw |= BRW_NEW_PRIMITIVE;
 
       if (brw->intel.gen < 6 &&
-	  reduced_prim[mode] != brw->intel.reduced_primitive) {
-	 brw->intel.reduced_primitive = reduced_prim[mode];
+	  brw->intel.reduced_primitive != brw_get_reduced_prim(hw_prim)) {
+	 brw->intel.reduced_primitive = brw_get_reduced_prim(hw_prim);
 	 brw->state.dirty.brw |= BRW_NEW_REDUCED_PRIMITIVE;
       }
    }
-
-   return prim_to_hw_prim[mode];
 }
 
 
@@ -319,7 +322,6 @@ static GLboolean brw_try_draw_prims( struct gl_context *ctx,
    intel_prepare_render(intel);
 
    for (i = 0; i < nr_prims; i++) {
-      uint32_t hw_prim;
       int estimated_max_prim_size;
 
       estimated_max_prim_size = 512; /* batchbuffer commands */
@@ -336,7 +338,8 @@ static GLboolean brw_try_draw_prims( struct gl_context *ctx,
        */
       intel_batchbuffer_require_space(intel, estimated_max_prim_size, false);
 
-      hw_prim = brw_set_prim(brw, &prim[i]);
+      brw_set_prim(brw, &prim[i]);
+
       if (brw->state.dirty.brw) {
 	 brw_validate_state(brw);
 
@@ -372,9 +375,9 @@ static GLboolean brw_try_draw_prims( struct gl_context *ctx,
       }
 
       if (intel->gen >= 7)
-	 gen7_emit_prim(brw, &prim[i], hw_prim);
+	 gen7_emit_prim(brw, &prim[i], brw->primitive);
       else
-	 brw_emit_prim(brw, &prim[i], hw_prim);
+	 brw_emit_prim(brw, &prim[i], brw->primitive);
 
       intel->no_batch_wrap = GL_FALSE;
 
diff --git a/src/mesa/drivers/dri/i965/brw_gs.c b/src/mesa/drivers/dri/i965/brw_gs.c
index 0a37485..9101d48 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_gs.c
@@ -86,13 +86,13 @@ static void compile_gs_prog( struct brw_context *brw,
     */
 
    switch (key->primitive) {
-   case GL_QUADS:
+   case _3DPRIM_QUADLIST:
       brw_gs_quads( &c, key );
       break;
-   case GL_QUAD_STRIP:
+   case _3DPRIM_QUADSTRIP:
       brw_gs_quad_strip( &c, key );
       break;
-   case GL_LINE_LOOP:
+   case _3DPRIM_LINELOOP:
       brw_gs_lines( &c );
       break;
    default:
@@ -122,17 +122,22 @@ static void compile_gs_prog( struct brw_context *brw,
    ralloc_free(mem_ctx);
 }
 
-static const GLenum gs_prim[GL_POLYGON+1] = {  
-   GL_POINTS,
-   GL_LINES,
-   GL_LINE_LOOP,
-   GL_LINES,
-   GL_TRIANGLES,
-   GL_TRIANGLES,
-   GL_TRIANGLES,
-   GL_QUADS,
-   GL_QUAD_STRIP,
-   GL_TRIANGLES
+static const int brw_gs_get_prim(int hw_prim)
+{
+   switch (hw_prim) {
+   case _3DPRIM_POINTLIST:  return _3DPRIM_POINTLIST;
+   case _3DPRIM_LINELIST:   return _3DPRIM_LINELIST;
+   case _3DPRIM_LINELOOP:   return _3DPRIM_LINELOOP;
+   case _3DPRIM_LINESTRIP:  return _3DPRIM_LINELIST;
+   case _3DPRIM_TRILIST:    return _3DPRIM_TRILIST;
+   case _3DPRIM_TRISTRIP:   return _3DPRIM_TRILIST;
+   case _3DPRIM_TRIFAN:     return _3DPRIM_TRILIST;
+   case _3DPRIM_QUADLIST:   return _3DPRIM_QUADLIST;
+   case _3DPRIM_QUADSTRIP:  return _3DPRIM_QUADSTRIP;
+   case _3DPRIM_POLYGON:    return _3DPRIM_TRILIST;
+   case _3DPRIM_RECTLIST:   return _3DPRIM_RECTLIST;
+   default:                 assert(0); return 0;
+   }
 };
 
 static void populate_key( struct brw_context *brw,
@@ -147,11 +152,12 @@ static void populate_key( struct brw_context *brw,
    key->attrs = brw->vs.prog_data->outputs_written;
 
    /* BRW_NEW_PRIMITIVE */
-   key->primitive = gs_prim[brw->primitive];
+   key->primitive = brw_gs_get_prim(brw->primitive);
 
    /* _NEW_LIGHT */
    key->pv_first = (ctx->Light.ProvokingVertex == GL_FIRST_VERTEX_CONVENTION);
-   if (key->primitive == GL_QUADS && ctx->Light.ShadeModel != GL_FLAT) {
+   if (key->primitive == _3DPRIM_QUADLIST &&
+       ctx->Light.ShadeModel != GL_FLAT) {
       /* Provide consistent primitive order with brw_set_prim's
        * optimization of single quads to trifans.
        */
@@ -163,9 +169,9 @@ static void populate_key( struct brw_context *brw,
 
    key->need_gs_prog = (intel->gen >= 6)
       ? 0
-      : (brw->primitive == GL_QUADS ||
-	 brw->primitive == GL_QUAD_STRIP ||
-	 brw->primitive == GL_LINE_LOOP);
+      : (brw->primitive == _3DPRIM_QUADLIST ||
+	 brw->primitive == _3DPRIM_QUADSTRIP ||
+	 brw->primitive == _3DPRIM_LINELOOP);
 }
 
 /* Calculate interpolants for triangle and line rasterization.
diff --git a/src/mesa/drivers/dri/i965/brw_gs.h b/src/mesa/drivers/dri/i965/brw_gs.h
index d8637c8..5986529 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.h
+++ b/src/mesa/drivers/dri/i965/brw_gs.h
@@ -41,7 +41,7 @@
 
 struct brw_gs_prog_key {
    GLbitfield64 attrs;
-   GLuint primitive:4;
+   GLuint primitive:8; /*< Hardware primitive, one of _3DPRIM_*. */
    GLuint pv_first:1;
    GLuint need_gs_prog:1;
    GLuint nr_userclip:4;
-- 
1.7.6.2



More information about the mesa-dev mailing list