llvmpipe: move fences from per-bin to per-thread
authorKeith Whitwell <keithw@vmware.com>
Thu, 8 Jul 2010 14:13:35 +0000 (15:13 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Tue, 13 Jul 2010 16:23:48 +0000 (17:23 +0100)
Rather than inserting an lp_rast_fence command at the end of each
bin, have each rasterizer thread call this function directly once
it has run out of work to do on a particular scene.

This results in fewer calls to the mutex & related functions, but more
importantly makes it easier to recognize empty bins.

src/gallium/drivers/llvmpipe/lp_fence.c
src/gallium/drivers/llvmpipe/lp_fence.h
src/gallium/drivers/llvmpipe/lp_flush.c
src/gallium/drivers/llvmpipe/lp_rast.c
src/gallium/drivers/llvmpipe/lp_scene.c
src/gallium/drivers/llvmpipe/lp_scene.h
src/gallium/drivers/llvmpipe/lp_setup.c
src/gallium/drivers/llvmpipe/lp_setup.h

index 75d8d2b8251bf5e97121a13e1008a04747d69e24..f9805e5d6881fa1ac347f59306a9be55e694f2f2 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "pipe/p_screen.h"
 #include "util/u_memory.h"
-#include "util/u_inlines.h"
 #include "lp_debug.h"
 #include "lp_fence.h"
 
@@ -59,7 +58,7 @@ lp_fence_create(unsigned rank)
 
 
 /** Destroy a fence.  Called when refcount hits zero. */
-static void
+void
 lp_fence_destroy(struct lp_fence *fence)
 {
    pipe_mutex_destroy(fence->mutex);
@@ -77,12 +76,10 @@ llvmpipe_fence_reference(struct pipe_screen *screen,
                          struct pipe_fence_handle **ptr,
                          struct pipe_fence_handle *fence)
 {
-   struct lp_fence *old = (struct lp_fence *) *ptr;
+   struct lp_fence **old = (struct lp_fence **) ptr;
    struct lp_fence *f = (struct lp_fence *) fence;
 
-   if (pipe_reference(&old->reference, &f->reference)) {
-      lp_fence_destroy(old);
-   }
+   lp_fence_reference(old, f);
 }
 
 
index d9270f5784acb7ed5c5b61471d4ea52d9a7b3dca..13358fb99f2a89ddd3007706ab2fc4708691af23 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "os/os_thread.h"
 #include "pipe/p_state.h"
+#include "util/u_inlines.h"
 
 
 struct pipe_screen;
@@ -61,4 +62,21 @@ void
 llvmpipe_init_screen_fence_funcs(struct pipe_screen *screen);
 
 
+void
+lp_fence_destroy(struct lp_fence *fence);
+
+static INLINE void
+lp_fence_reference(struct lp_fence **ptr,
+                   struct lp_fence *f)
+{
+   struct lp_fence *old = *ptr;
+
+   if (pipe_reference(&old->reference, &f->reference)) {
+      lp_fence_destroy(old);
+   }
+   
+   *ptr = f;
+}
+
+
 #endif /* LP_FENCE_H */
index 0cd288bb73a7ad226343e10b15b0e3875f5638bd..d78656f462837144de2aaee2682a956cb5c4e66e 100644 (file)
@@ -51,16 +51,8 @@ llvmpipe_flush( struct pipe_context *pipe,
 
    draw_flush(llvmpipe->draw);
 
-   if (fence) {
-      /* if we're going to flush the setup/rasterization modules, emit
-       * a fence.
-       * XXX this (and the code below) may need fine tuning...
-       */
-      *fence = lp_setup_fence( llvmpipe->setup );
-   }
-
    /* ask the setup module to flush */
-   lp_setup_flush(llvmpipe->setup, flags);
+   lp_setup_flush(llvmpipe->setup, flags, fence);
 
    /* Enable to dump BMPs of the color/depth buffers each frame */
    if (0) {
index 1a82dd5694e36b399164b2185f753e97642e45a6..1dde327836c2efa19b52e942a23c0bc286339128 100644 (file)
@@ -815,6 +815,10 @@ rasterize_scene(struct lp_rasterizer_task *task,
       }
    }
 #endif
+
+   if (scene->fence) {
+      lp_rast_fence(task, lp_rast_arg_fence(scene->fence));
+   }
 }
 
 
index e8d36bbdc5038305b794da9c77133ef7228d933e..f2226a538a51cd6c22235941f0207c1c9804691c 100644 (file)
@@ -32,6 +32,7 @@
 #include "util/u_simple_list.h"
 #include "lp_scene.h"
 #include "lp_scene_queue.h"
+#include "lp_fence.h"
 
 
 /** List of texture references */
@@ -198,6 +199,8 @@ lp_scene_reset(struct lp_scene *scene )
       make_empty_list(ref_list);
    }
 
+   lp_fence_reference(&scene->fence, NULL);
+
    scene->scene_size = 0;
 
    scene->has_color_clear = FALSE;
index 4e55d43174697a1bae42823c17de096b8d4b0ce9..fa1b311fa1762d40badcbda4f8a5d602940d50aa 100644 (file)
@@ -112,6 +112,7 @@ struct resource_ref {
  */
 struct lp_scene {
    struct pipe_context *pipe;
+   struct lp_fence *fence;
 
    /** the framebuffer to render the scene into */
    struct pipe_framebuffer_state fb;
index 2bd6fcebe7f9b0a21b583dd467ea79819033ecaf..3b83f4e7428eb9f69185b4d18be1ebfe3ddb48b6 100644 (file)
@@ -271,7 +271,8 @@ set_scene_state( struct lp_setup_context *setup,
  */
 void
 lp_setup_flush( struct lp_setup_context *setup,
-                unsigned flags )
+                unsigned flags,
+                struct pipe_fence_handle **fence)
 {
    LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__);
 
@@ -288,6 +289,15 @@ lp_setup_flush( struct lp_setup_context *setup,
           */
          lp_scene_bin_everywhere(scene, lp_rast_store_color, dummy);
       }
+
+
+      if (fence) {
+         /* if we're going to flush the setup/rasterization modules, emit
+          * a fence.
+          */
+         *fence = lp_setup_fence( setup );
+      }
+
    }
 
    set_scene_state( setup, SETUP_FLUSHED );
@@ -433,24 +443,27 @@ lp_setup_clear( struct lp_setup_context *setup,
 struct pipe_fence_handle *
 lp_setup_fence( struct lp_setup_context *setup )
 {
-   if (setup->num_threads == 0) {
+   if (setup->scene == NULL)
       return NULL;
-   }
-   else {
+   else if (setup->num_threads == 0)
+      return NULL;
+   else
+   {
       struct lp_scene *scene = lp_setup_get_current_scene(setup);
-      const unsigned rank = lp_scene_get_num_bins( scene ); /* xxx */
-      struct lp_fence *fence = lp_fence_create(rank);
-
-      LP_DBG(DEBUG_SETUP, "%s rank %u\n", __FUNCTION__, rank);
+      const unsigned rank = setup->num_threads;
 
       set_scene_state( setup, SETUP_ACTIVE );
+      
+      assert(scene->fence == NULL);
 
-      /* insert the fence into all command bins */
-      lp_scene_bin_everywhere( scene,
-                               lp_rast_fence,
-                               lp_rast_arg_fence(fence) );
+      /* The caller gets a reference, we keep a copy too, so need to
+       * bump the refcount:
+       */
+      lp_fence_reference(&scene->fence, lp_fence_create(rank));
+
+      LP_DBG(DEBUG_SETUP, "%s rank %u\n", __FUNCTION__, rank);
 
-      return (struct pipe_fence_handle *) fence;
+      return (struct pipe_fence_handle *) scene->fence;
    }
 }
 
index 6a0dc551290ffb4800da7a17850fcc3790a62b55..73b1c85325a4ec5eb883f84dfe8daf094827b683 100644 (file)
@@ -84,7 +84,8 @@ lp_setup_fence( struct lp_setup_context *setup );
 
 void
 lp_setup_flush( struct lp_setup_context *setup,
-                unsigned flags );
+                unsigned flags,
+                struct pipe_fence_handle **fence);
 
 
 void