radeon: Improve state emit code.
authorPauli Nieminen <suokkos@gmail.com>
Fri, 21 Aug 2009 17:44:54 +0000 (20:44 +0300)
committerPauli Nieminen <suokkos@gmail.com>
Fri, 21 Aug 2009 17:47:35 +0000 (20:47 +0300)
Trying to make understanding code easier with small refactoring and renaming.

src/mesa/drivers/dri/r200/r200_swtcl.c
src/mesa/drivers/dri/r200/r200_tcl.c
src/mesa/drivers/dri/r300/r300_draw.c
src/mesa/drivers/dri/radeon/radeon_common.c
src/mesa/drivers/dri/radeon/radeon_common.h
src/mesa/drivers/dri/radeon/radeon_dma.c
src/mesa/drivers/dri/radeon/radeon_swtcl.c
src/mesa/drivers/dri/radeon/radeon_tcl.c

index 8dd2e69d33d698658afaffe566081db133b885ee..56930c7863a7fc9fab76f9f7e430417b56866037 100644 (file)
@@ -269,7 +269,7 @@ void r200_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
 {
    r200ContextPtr rmesa = R200_CONTEXT(ctx);
    rcommonEnsureCmdBufSpace(&rmesa->radeon,
-                           radeonCountEmitSize(&rmesa->radeon) + (12*sizeof(int)),
+                           radeonCountStateEmitSize(&rmesa->radeon) + (12*sizeof(int)),
                            __FUNCTION__);
 
 
index d8020df97c07a4443d6491747484f2630c5e28b1..0f5e501c1a61172681c76702a4b964dad42645c2 100644 (file)
@@ -387,7 +387,7 @@ static void r200EnsureEmitSize( GLcontext * ctx , GLubyte* vimap_rev )
 
   {
     /* count the prediction for state size */
-    space_required = radeonCountEmitSize( &rmesa->radeon );
+    space_required = radeonCountStateEmitSize( &rmesa->radeon );
     /* vtx may be changed in r200EmitArrays so account for it if not dirty */
     if (!rmesa->hw.vtx.dirty)
       space_required += rmesa->hw.vtx.check(rmesa->radeon.glCtx, &rmesa->hw.vtx);
index 1437535760c578d7006f11dbe3118cb5808d0633..c8d2f44fa18236a90bbd051416c4b92deb3541a7 100644 (file)
@@ -582,12 +582,12 @@ static GLuint r300PredictTryDrawPrimsSize(GLcontext *ctx, GLuint nr_prims)
                + SCISSORS_BUFSZ
                + FIREAOS_BUFSZ )*nr_prims;
 
-       state_size= radeonCountEmitSize(&r300->radeon);
+       state_size = radeonCountStateEmitSize(&r300->radeon);
        flushed = rcommonEnsureCmdBufSpace(&r300->radeon,
                        dwords + state_size,
                        __FUNCTION__);
        if (flushed)
-               dwords += radeonCountEmitSize(&r300->radeon);
+               dwords += radeonCountStateEmitSize(&r300->radeon);
        else
                dwords += state_size;
 
index 6c3f7a57e504b205dcfa52afd3d3622dc1104ce6..4088ef303cf1bcfcce3068bd3a5d6dd0beb948da 100644 (file)
@@ -895,7 +895,7 @@ void radeon_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei he
        ctx->Driver.Viewport = old_viewport;
 }
 
-static void radeon_print_state_atom(radeonContextPtr radeon, struct radeon_state_atom *state)
+static void radeon_print_state_atom_prekmm(radeonContextPtr radeon, struct radeon_state_atom *state)
 {
        int i, j, reg;
        int dwords = (*state->check) (radeon->glCtx, state);
@@ -920,13 +920,22 @@ static void radeon_print_state_atom(radeonContextPtr radeon, struct radeon_state
        }
 }
 
-static void radeon_print_state_atom_kmm(radeonContextPtr radeon, struct radeon_state_atom *state)
+static void radeon_print_state_atom(radeonContextPtr radeon, struct radeon_state_atom *state)
 {
        int i, j, reg, count;
-       int dwords = (*state->check) (radeon->glCtx, state);
+       int dwords;
        uint32_t packet0;
+       if (! (DEBUG_CMDBUF || RADEON_DEBUG & DEBUG_STATE))
+               return;
 
-       fprintf(stderr, "  emit %s %d/%d\n", state->name, state->cmd_size, dwords);
+       if (!radeon->radeonScreen->kernel_mm) {
+               radeon_print_state_atom_prekmm(radeon, state);
+               return;
+       }
+
+       dwords = (*state->check) (radeon->glCtx, state);
+
+       fprintf(stderr, "  emit %s %d/%d\n", state->name, dwords, state->cmd_size);
 
        if (RADEON_DEBUG & DEBUG_VERBOSE) {
                for (i = 0; i < state->cmd_size;) {
@@ -949,60 +958,68 @@ static void radeon_print_state_atom_kmm(radeonContextPtr radeon, struct radeon_s
 /**
  * Count total size for next state emit.
  **/
-GLuint radeonCountEmitSize(radeonContextPtr radeon)
+GLuint radeonCountStateEmitSize(radeonContextPtr radeon)
 {
-   struct radeon_state_atom *atom;
-   int dwords = 0;
-   /* check if we are going to emit full state */
-   if (radeon->cmdbuf.cs->cdw && !radeon->hw.all_dirty) {
-      if (!radeon->hw.is_dirty)
-        return dwords;
-      foreach(atom, &radeon->hw.atomlist) {
-         if (atom->dirty)
-            dwords += atom->check(radeon->glCtx, atom);
-      }
-   } else {
-      foreach(atom, &radeon->hw.atomlist) {
-        dwords += atom->check(radeon->glCtx, atom);
-      }
-   }
-   return dwords;
+       struct radeon_state_atom *atom;
+       int dwords = 0;
+       /* check if we are going to emit full state */
+       if (radeon->cmdbuf.cs->cdw && !radeon->hw.all_dirty) {
+               if (!radeon->hw.is_dirty)
+                       return dwords;
+               foreach(atom, &radeon->hw.atomlist) {
+                       if (atom->dirty)
+                               dwords += atom->check(radeon->glCtx, atom);
+               }
+       } else {
+               foreach(atom, &radeon->hw.atomlist) {
+                       dwords += atom->check(radeon->glCtx, atom);
+               }
+       }
+       return dwords;
 }
 
-static INLINE void radeonEmitAtoms(radeonContextPtr radeon, GLboolean dirty)
+static INLINE void radeon_emit_atom(radeonContextPtr radeon, struct radeon_state_atom *atom)
 {
        BATCH_LOCALS(radeon);
-       struct radeon_state_atom *atom;
        int dwords;
 
+       dwords = (*atom->check) (radeon->glCtx, atom);
+       if (dwords) {
+
+               radeon_print_state_atom(radeon, atom);
+
+               if (atom->emit) {
+                       (*atom->emit)(radeon->glCtx, atom);
+               } else {
+                       BEGIN_BATCH_NO_AUTOSTATE(dwords);
+                       OUT_BATCH_TABLE(atom->cmd, dwords);
+                       END_BATCH();
+               }
+       } else {
+               if (DEBUG_CMDBUF && RADEON_DEBUG & DEBUG_STATE) {
+                       fprintf(stderr, "  skip state %s\n",
+                                       atom->name);
+               }
+       }
+       atom->dirty = GL_FALSE;
+
+}
+
+static INLINE void radeonEmitAtoms(radeonContextPtr radeon, GLboolean emitAll)
+{
+       struct radeon_state_atom *atom;
+
        if (radeon->vtbl.pre_emit_atoms)
                radeon->vtbl.pre_emit_atoms(radeon);
 
        /* Emit actual atoms */
-       foreach(atom, &radeon->hw.atomlist) {
-               if ((atom->dirty || radeon->hw.all_dirty) == dirty) {
-                       dwords = (*atom->check) (radeon->glCtx, atom);
-                       if (dwords) {
-                               if (DEBUG_CMDBUF && RADEON_DEBUG & DEBUG_STATE) {
-                                       if (radeon->radeonScreen->kernel_mm)
-                                               radeon_print_state_atom_kmm(radeon, atom);
-                                       else
-                                               radeon_print_state_atom(radeon, atom);
-                               }
-                               if (atom->emit) {
-                                       (*atom->emit)(radeon->glCtx, atom);
-                               } else {
-                                       BEGIN_BATCH_NO_AUTOSTATE(dwords);
-                                       OUT_BATCH_TABLE(atom->cmd, dwords);
-                                       END_BATCH();
-                               }
-                               atom->dirty = GL_FALSE;
-                       } else {
-                               if (DEBUG_CMDBUF && RADEON_DEBUG & DEBUG_STATE) {
-                                       fprintf(stderr, "  skip state %s\n",
-                                               atom->name);
-                               }
-                       }
+       if (radeon->hw.all_dirty || emitAll) {
+               foreach(atom, &radeon->hw.atomlist)
+                       radeon_emit_atom( radeon, atom );
+       } else {
+               foreach(atom, &radeon->hw.atomlist) {
+                       if ( atom->dirty )
+                               radeon_emit_atom( radeon, atom );
                }
        }
 
@@ -1036,16 +1053,17 @@ void radeonEmitState(radeonContextPtr radeon)
                if (RADEON_DEBUG & DEBUG_STATE)
                        fprintf(stderr, "Begin reemit state\n");
 
+               radeonEmitAtoms(radeon, GL_TRUE);
+       } else {
+
+               if (RADEON_DEBUG & DEBUG_STATE)
+                       fprintf(stderr, "Begin dirty state\n");
+
                radeonEmitAtoms(radeon, GL_FALSE);
        }
 
-       if (RADEON_DEBUG & DEBUG_STATE)
-               fprintf(stderr, "Begin dirty state\n");
-
-       radeonEmitAtoms(radeon, GL_TRUE);
        radeon->hw.is_dirty = GL_FALSE;
        radeon->hw.all_dirty = GL_FALSE;
-
 }
 
 
index 6e81100d667196c3c86caf00aab88e9032841c03..a9e1ca49eb97f0aa3da96dc4ad833dd8e79917c5 100644 (file)
@@ -24,7 +24,7 @@ void radeonUpdatePageFlipping(radeonContextPtr rmesa);
 void radeonFlush(GLcontext *ctx);
 void radeonFinish(GLcontext * ctx);
 void radeonEmitState(radeonContextPtr radeon);
-GLuint radeonCountEmitSize(radeonContextPtr radeon);
+GLuint radeonCountStateEmitSize(radeonContextPtr radeon);
 
 void radeon_clear_tris(GLcontext *ctx, GLbitfield mask);
 
index 79b2b77d30a5ed4a96cdee322f4d94bccdc560bf..7e8f50e3df26bd684045ea543e05c0846e3d4bff 100644 (file)
@@ -431,7 +431,7 @@ restart:
         if (!rmesa->dma.flush) {
                /* make sure we have enough space to use this in cmdbuf */
                rcommonEnsureCmdBufSpace(rmesa,
-                             radeonCountEmitSize( rmesa ) + (20*sizeof(int)),
+                             radeonCountStateEmitSize( rmesa ) + (20*sizeof(int)),
                              __FUNCTION__);
                /* if cmdbuf flushed DMA restart */
                if (is_empty_list(&rmesa->dma.reserved))
index a1b398e560b80fabd9fde71cf4b845113787705a..20ce6c470b4ecb6258b40aa8cbd60aa0dcede703 100644 (file)
@@ -285,7 +285,7 @@ void r100_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
    r100ContextPtr rmesa = R100_CONTEXT(ctx);
 
    rcommonEnsureCmdBufSpace(&rmesa->radeon,
-                           radeonCountEmitSize( &rmesa->radeon ) + (12*sizeof(int)),
+                           radeonCountStateEmitSize( &rmesa->radeon ) + (12*sizeof(int)),
                            __FUNCTION__);
 
 
index c5a73a281896c1834d93a54551b92b71cb492f7e..908b3c9f0615703710da0984cf3dce98c4101d07 100644 (file)
@@ -388,7 +388,7 @@ static void radeonEnsureEmitSize( GLcontext * ctx , GLuint inputs )
 
   {
     /* count the prediction for state size */
-    space_required = radeonCountEmitSize( &rmesa->radeon );
+    space_required = radeonCountStateEmitSize( &rmesa->radeon );
     /* tcl may be changed in radeonEmitArrays so account for it if not dirty */
     if (!rmesa->hw.tcl.dirty)
       space_required += rmesa->hw.tcl.check( rmesa->radeon.glCtx, &rmesa->hw.tcl );