llvmpipe: add bin debugger
authorKeith Whitwell <keithw@vmware.com>
Wed, 13 Jan 2010 20:14:04 +0000 (20:14 +0000)
committerKeith Whitwell <keithw@vmware.com>
Wed, 13 Jan 2010 20:14:04 +0000 (20:14 +0000)
Adjust definition of empty_bin according to what's actually in empty
bins.  We often have a state packet before/after load commands.

Still need to do something about the fence packets.

src/gallium/drivers/llvmpipe/lp_rast.c

index 7753f9bb3f63428aa9cf30a740cc0cbb5817a640..6c7ece9fdbf969a08abc7d8aea49c0da4704c02e 100644 (file)
@@ -608,6 +608,44 @@ rasterize_bin( struct lp_rasterizer *rast,
    lp_rast_end_tile( rast, thread_index );
 }
 
+
+#define RAST(x) { lp_rast_##x, #x }
+
+static struct {
+   lp_rast_cmd cmd;
+   const char *name;
+} cmd_names[] = 
+{
+   RAST(load_color),
+   RAST(load_zstencil),
+   RAST(clear_color),
+   RAST(clear_zstencil),
+   RAST(triangle),
+   RAST(shade_tile),
+   RAST(set_state),
+   RAST(fence),
+};
+
+static void
+debug_bin( const struct cmd_bin *bin )
+{
+   const struct cmd_block *head = bin->commands.head;
+   int i, j;
+
+   for (i = 0; i < head->count; i++) {
+      debug_printf("%d: ", i);
+      for (j = 0; j < Elements(cmd_names); j++) {
+         if (head->cmd[i] == cmd_names[j].cmd) {
+            debug_printf("%s\n", cmd_names[j].name);
+            break;
+         }
+      }
+      if (j == Elements(cmd_names))
+         debug_printf("...other\n");
+   }
+
+}
+
 /* An empty bin is one that just loads the contents of the tile and
  * stores them again unchanged.  This typically happens when bins have
  * been flushed for some reason in the middle of a frame, or when
@@ -620,19 +658,28 @@ is_empty_bin( const struct cmd_bin *bin )
 {
    const struct cmd_block *head = bin->commands.head;
    int i;
-
+   
+   if (0)
+      debug_bin(bin);
+   
    /* We emit at most two load-tile commands at the start of the first
-    * command block.  If there are more than two commands in the
-    * block, we know that the bin is non-empty.
+    * command block.  In addition we seem to emit a couple of
+    * set-state commands even in empty bins.
+    *
+    * As a heuristic, if a bin has more than 4 commands, consider it
+    * non-empty.
     */
    if (head->next != NULL ||
-       head->count > 2)
+       head->count > 4) {
       return FALSE;
+   }
 
    for (i = 0; i < head->count; i++)
       if (head->cmd[i] != lp_rast_load_color &&
-          head->cmd[i] != lp_rast_load_zstencil)
+          head->cmd[i] != lp_rast_load_zstencil &&
+          head->cmd[i] != lp_rast_set_state) {
          return FALSE;
+      }
 
    return TRUE;
 }