llvmpipe: rearrange queries
authorKeith Whitwell <keithw@vmware.com>
Tue, 7 Sep 2010 11:45:23 +0000 (12:45 +0100)
committerKeith Whitwell <keithw@vmware.com>
Tue, 7 Sep 2010 13:01:50 +0000 (14:01 +0100)
src/gallium/drivers/llvmpipe/lp_query.c
src/gallium/drivers/llvmpipe/lp_rast.c
src/gallium/drivers/llvmpipe/lp_rast.h
src/gallium/drivers/llvmpipe/lp_setup.c

index 76d0231fd1cabd9da5b63d2ebd5ea36a1bfcb5df..ff0e207a54babd9c3a490aac0359a04aa1a960d3 100644 (file)
@@ -123,6 +123,16 @@ llvmpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q)
    struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
    struct llvmpipe_query *pq = llvmpipe_query(q);
 
+   /* Check if the query is already in the scene.  If so, we need to
+    * flush the scene now.  Real apps shouldn't re-use a query in a
+    * frame of rendering.
+    */
+   if (pq->fence && !lp_fence_issued(pq->fence)) {
+      llvmpipe_finish(pipe, __FUNCTION__);
+   }
+
+
+   memset(pq->count, 0, sizeof(pq->count));
    lp_setup_begin_query(llvmpipe->setup, pq);
 
    llvmpipe->active_query_count++;
index c022153b4388da8fb46722aec77f946457ef15fe..694b007eb8b807b0aa241fae4c223c6ba7a0999a 100644 (file)
@@ -327,8 +327,7 @@ lp_rast_clear_zstencil(struct lp_rasterizer_task *task,
  * This is a bin command which is stored in all bins.
  */
 void
-lp_rast_store_linear_color( struct lp_rasterizer_task *task,
-                            const union lp_rast_cmd_arg arg)
+lp_rast_store_linear_color( struct lp_rasterizer_task *task )
 {
    struct lp_rasterizer *rast = task->rast;
    struct lp_scene *scene = rast->curr_scene;
@@ -489,6 +488,38 @@ lp_rast_shade_quads_mask(struct lp_rasterizer_task *task,
 
 
 
+/**
+ * Begin a new occlusion query.
+ * This is a bin command put in all bins.
+ * Called per thread.
+ */
+void
+lp_rast_begin_query(struct lp_rasterizer_task *task,
+                    const union lp_rast_cmd_arg arg)
+{
+   struct llvmpipe_query *pq = arg.query_obj;
+
+   assert(task->query == NULL);
+   task->vis_counter = 0;
+   task->query = pq;
+}
+
+
+/**
+ * End the current occlusion query.
+ * This is a bin command put in all bins.
+ * Called per thread.
+ */
+void
+lp_rast_end_query(struct lp_rasterizer_task *task,
+                  const union lp_rast_cmd_arg arg)
+{
+   task->query->count[task->thread_index] += task->vis_counter;
+   task->query = NULL;
+}
+
+
+
 /**
  * Set top row and left column of the tile's pixels to white.  For debugging.
  */
@@ -567,10 +598,7 @@ lp_rast_tile_end(struct lp_rasterizer_task *task)
    (void) outline_subtiles;
 #endif
 
-   {
-      union lp_rast_cmd_arg dummy = {0};
-      lp_rast_store_linear_color(task, dummy);
-   }
+   lp_rast_store_linear_color(task);
 
    if (task->query) {
       union lp_rast_cmd_arg dummy = {0};
@@ -584,64 +612,6 @@ lp_rast_tile_end(struct lp_rasterizer_task *task)
 
 
 
-/**
- * Signal on a fence.  This is called during bin execution/rasterization.
- * Called per thread.
- */
-void
-lp_rast_fence(struct lp_rasterizer_task *task,
-              const union lp_rast_cmd_arg arg)
-{
-   struct lp_fence *fence = arg.fence;
-   lp_fence_signal(fence);
-}
-
-
-/**
- * Begin a new occlusion query.
- * This is a bin command put in all bins.
- * Called per thread.
- */
-void
-lp_rast_begin_query(struct lp_rasterizer_task *task,
-                    const union lp_rast_cmd_arg arg)
-{
-   struct llvmpipe_query *pq = arg.query_obj;
-
-   assert(task->query == NULL);
-   task->vis_counter = 0;
-   task->query = pq;
-   pq->count[task->thread_index] = 0;
-}
-
-
-/* Much like begin_query, but don't reset the counter to zero.
- */
-void
-lp_rast_restart_query(struct lp_rasterizer_task *task,
-                      const union lp_rast_cmd_arg arg)
-{
-   struct llvmpipe_query *pq = arg.query_obj;
-
-   assert(task->query == NULL);
-   task->vis_counter = 0;
-   task->query = pq;
-}
-
-/**
- * End the current occlusion query.
- * This is a bin command put in all bins.
- * Called per thread.
- */
-void
-lp_rast_end_query(struct lp_rasterizer_task *task,
-                  const union lp_rast_cmd_arg arg)
-{
-   task->query->count[task->thread_index] += task->vis_counter;
-   task->query = NULL;
-}
-
 
 
 /**
@@ -672,50 +642,6 @@ rasterize_bin(struct lp_rasterizer_task *task,
 }
 
 
-#define RAST(x) { lp_rast_##x, #x }
-
-static struct {
-   lp_rast_cmd cmd;
-   const char *name;
-} cmd_names[] = 
-{
-   RAST(clear_color),
-   RAST(clear_zstencil),
-   RAST(triangle_1),
-   RAST(triangle_2),
-   RAST(triangle_3),
-   RAST(triangle_4),
-   RAST(triangle_5),
-   RAST(triangle_6),
-   RAST(triangle_7),
-   RAST(shade_tile),
-   RAST(shade_tile_opaque),
-   RAST(store_linear_color),
-   RAST(fence),
-   RAST(begin_query),
-   RAST(restart_query),
-   RAST(end_query),
-};
-
-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
@@ -727,7 +653,6 @@ debug_bin( const struct cmd_bin *bin )
 static boolean
 is_empty_bin( const struct cmd_bin *bin )
 {
-   if (0) debug_bin(bin);
    return bin->commands.head == NULL;
 }
 
@@ -766,7 +691,7 @@ rasterize_scene(struct lp_rasterizer_task *task,
 #endif
 
    if (scene->fence) {
-      lp_rast_fence(task, lp_rast_arg_fence(scene->fence));
+      lp_fence_signal(scene->fence);
    }
 }
 
index f43e714a922279a7fe8245643d334bd71d7c75a3..4697054e8d4f5a50c80872ba75413ee5d11ed44e 100644 (file)
@@ -259,8 +259,7 @@ void lp_rast_shade_tile_opaque( struct lp_rasterizer_task *,
 void lp_rast_fence( struct lp_rasterizer_task *,
                     const union lp_rast_cmd_arg );
 
-void lp_rast_store_linear_color( struct lp_rasterizer_task *,
-                          const union lp_rast_cmd_arg );
+void lp_rast_store_linear_color( struct lp_rasterizer_task *);
 
 
 void lp_rast_begin_query(struct lp_rasterizer_task *,
index 476d23fcee50e44514120eb218b7317284290361..4cb6166badd8a190f9442360166e8b21746bc39c 100644 (file)
@@ -155,10 +155,13 @@ begin_binning( struct lp_setup_context *setup )
    struct lp_scene *scene = lp_setup_get_current_scene(setup);
    boolean need_zsload = FALSE;
 
-   /* Always create a fence when threads are active:
+   assert(scene);
+   assert(scene->fence == NULL);
+
+   /* Always create a fence:
     */
-   if (setup->num_threads)
-      scene->fence = lp_fence_create(setup->num_threads);
+   scene->fence = lp_fence_create(MAX2(1, setup->num_threads));
+
 
    if (setup->fb.zsbuf &&
        ((setup->clear.flags & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) &&
@@ -193,7 +196,7 @@ begin_binning( struct lp_setup_context *setup )
 
    if (setup->active_query) {
       ok = lp_scene_bin_everywhere( scene,
-                                    lp_rast_restart_query,
+                                    lp_rast_begin_query,
                                     lp_rast_arg_query(setup->active_query) );
       assert(ok);
    }