i965: Change type of brw_context.primitive from GLenum to hardware primitive
authorChad Versace <chad@chad-versace.us>
Mon, 26 Sep 2011 23:23:26 +0000 (16:23 -0700)
committerChad Versace <chad@chad-versace.us>
Mon, 10 Oct 2011 20:24:11 +0000 (13:24 -0700)
For example, GL_TRIANLGES 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.

v2
----
- [anholt] Split brw_set_prim into brw/gen6 variants in previous commit,
  since not much code is really shared between the two.
- [anholt] Replace switch statements with table lookups, since this is
  a hot path.

Reviewed-by: Eric Anholt <eric@anho.net>
Signed-off-by: Chad Versace <chad@chad-versace.us>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_draw.c
src/mesa/drivers/dri/i965/brw_gs.c
src/mesa/drivers/dri/i965/brw_gs.h

index b335954e9a93da20d1e412e37a8624158e53cdc4..bdad9fbc2fbe7d312eb1486d7af0e9d1f87c81ab 100644 (file)
@@ -583,7 +583,7 @@ struct brw_query_object {
 struct brw_context 
 {
    struct intel_context intel;  /**< base class, must be first field */
-   GLuint primitive;
+   GLuint primitive; /**< Hardware primitive, such as _3DPRIM_TRILIST. */
 
    GLboolean emit_state_always;
    GLboolean has_surface_tile_offset;
index 39d38a57a4a9492e05eb6974ac0ff56d01c19231..f58da557da1570a7262cdb6dd74aa834c177afea 100644 (file)
@@ -79,53 +79,51 @@ 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,
-                          const struct _mesa_prim *prim)
+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 = prim_to_hw_prim[prim->mode];
 
    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 &&
+   if (prim->mode == GL_QUAD_STRIP &&
        ctx->Light.ShadeModel != GL_FLAT &&
        ctx->Polygon.FrontMode == GL_FILL &&
        ctx->Polygon.BackMode == GL_FILL)
-      mode = GL_TRIANGLE_STRIP;
+      hw_prim = _3DPRIM_TRISTRIP;
 
    if (prim->mode == GL_QUADS && prim->count == 4 &&
        ctx->Light.ShadeModel != GL_FLAT &&
        ctx->Polygon.FrontMode == GL_FILL &&
        ctx->Polygon.BackMode == GL_FILL) {
-      mode = GL_TRIANGLE_FAN;
+      hw_prim = _3DPRIM_TRIFAN;
    }
 
-   if (mode != brw->primitive) {
-      brw->primitive = mode;
+   if (hw_prim != brw->primitive) {
+      brw->primitive = hw_prim;
       brw->state.dirty.brw |= BRW_NEW_PRIMITIVE;
 
-      if (reduced_prim[mode] != brw->intel.reduced_primitive) {
-        brw->intel.reduced_primitive = reduced_prim[mode];
+      if (reduced_prim[prim->mode] != brw->intel.reduced_primitive) {
+        brw->intel.reduced_primitive = reduced_prim[prim->mode];
         brw->state.dirty.brw |= BRW_NEW_REDUCED_PRIMITIVE;
       }
    }
-
-   return prim_to_hw_prim[mode];
 }
 
-static GLuint gen6_set_prim(struct brw_context *brw,
-                            const struct _mesa_prim *prim)
+static void gen6_set_prim(struct brw_context *brw,
+                          const struct _mesa_prim *prim)
 {
+   uint32_t hw_prim = prim_to_hw_prim[prim->mode];
+
    DBG("PRIM: %s\n", _mesa_lookup_enum_by_nr(prim->mode));
 
-   if (prim->mode != brw->primitive) {
-      brw->primitive = prim->mode;
+   if (hw_prim != brw->primitive) {
+      brw->primitive = hw_prim;
       brw->state.dirty.brw |= BRW_NEW_PRIMITIVE;
    }
-
-   return prim_to_hw_prim[mode];
 }
 
 
@@ -331,7 +329,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 */
@@ -349,9 +346,9 @@ static GLboolean brw_try_draw_prims( struct gl_context *ctx,
       intel_batchbuffer_require_space(intel, estimated_max_prim_size, false);
 
       if (intel->gen < 6)
-        hw_prim = brw_set_prim(brw, &prim[i]);
+        brw_set_prim(brw, &prim[i]);
       else
-        hw_prim = gen6_set_prim(brw, &prim[i]);
+        gen6_set_prim(brw, &prim[i]);
 
       if (brw->state.dirty.brw) {
         brw_validate_state(brw);
@@ -388,9 +385,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;
 
index 3b56aae821b4d58f8d7cfecfcadfe1302d3b6e30..91cdb1e72e52ec92c38eeaace68ced34ae89bfc5 100644 (file)
@@ -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,18 @@ 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 GLenum gs_prim[] = {
+   [_3DPRIM_POINTLIST]  = _3DPRIM_POINTLIST,
+   [_3DPRIM_LINELIST]   = _3DPRIM_LINELIST,
+   [_3DPRIM_LINELOOP]   = _3DPRIM_LINELOOP,
+   [_3DPRIM_LINESTRIP]  = _3DPRIM_LINELIST,
+   [_3DPRIM_TRILIST]    = _3DPRIM_TRILIST,
+   [_3DPRIM_TRISTRIP]   = _3DPRIM_TRILIST,
+   [_3DPRIM_TRIFAN]     = _3DPRIM_TRILIST,
+   [_3DPRIM_QUADLIST]   = _3DPRIM_QUADLIST,
+   [_3DPRIM_QUADSTRIP]  = _3DPRIM_QUADSTRIP,
+   [_3DPRIM_POLYGON]    = _3DPRIM_TRILIST,
+   [_3DPRIM_RECTLIST]   = _3DPRIM_RECTLIST,
 };
 
 static void populate_key( struct brw_context *brw,
@@ -151,7 +152,7 @@ static void populate_key( struct brw_context *brw,
 
    /* _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 +164,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.
index cee7467628b939a72f0627e0762dc933dc3b4a1d..0e4ff3fedf6d17e2d604d2acdf5a7bd5b9b75853 100644 (file)
@@ -41,7 +41,7 @@
 
 struct brw_gs_prog_key {
    GLbitfield64 attrs;
-   GLuint primitive:4;
+   GLuint primitive:8; /**< Hardware primitive, such as _3DPRIM_TRILIST. */
    GLuint pv_first:1;
    GLuint need_gs_prog:1;
    GLuint userclip_active:1;