rbug: Fix draw blocking
authorJakob Bornecrantz <jakob@vmware.com>
Wed, 12 May 2010 17:55:42 +0000 (18:55 +0100)
committerJakob Bornecrantz <jakob@vmware.com>
Wed, 12 May 2010 19:15:23 +0000 (20:15 +0100)
src/gallium/drivers/rbug/rbug_context.c
src/gallium/drivers/rbug/rbug_context.h
src/gallium/drivers/rbug/rbug_core.c

index 323d6d6dd6c670fa34bf70efdcb0a0eb22b02716..59f005ec16ccb99bccf49ea178d07056f9aa0646 100644 (file)
@@ -31,6 +31,8 @@
 #include "util/u_inlines.h"
 #include "util/u_simple_list.h"
 
+#include "rbug/rbug_context.h"
+
 #include "rbug_context.h"
 #include "rbug_objects.h"
 
@@ -46,6 +48,68 @@ rbug_destroy(struct pipe_context *_pipe)
    FREE(rb_pipe);
 }
 
+static void
+rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
+{
+
+   if (rb_pipe->draw_blocker & flag) {
+      rb_pipe->draw_blocked |= flag;
+   } else if ((rb_pipe->draw_rule.blocker & flag) &&
+              (rb_pipe->draw_blocker & RBUG_BLOCK_RULE)) {
+      int k;
+      boolean block = FALSE;
+      debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__,
+                   (void *) rb_pipe->draw_rule.fs, (void *) rb_pipe->curr.fs,
+                   (void *) rb_pipe->draw_rule.vs, (void *) rb_pipe->curr.vs,
+                   (void *) rb_pipe->draw_rule.surf, 0,
+                   (void *) rb_pipe->draw_rule.texture, 0);
+      if (rb_pipe->draw_rule.fs &&
+          rb_pipe->draw_rule.fs == rb_pipe->curr.fs)
+         block = TRUE;
+      if (rb_pipe->draw_rule.vs &&
+          rb_pipe->draw_rule.vs == rb_pipe->curr.vs)
+         block = TRUE;
+      if (rb_pipe->draw_rule.surf &&
+          rb_pipe->draw_rule.surf == rb_pipe->curr.zsbuf)
+            block = TRUE;
+      if (rb_pipe->draw_rule.surf)
+         for (k = 0; k < rb_pipe->curr.nr_cbufs; k++)
+            if (rb_pipe->draw_rule.surf == rb_pipe->curr.cbufs[k])
+               block = TRUE;
+      if (rb_pipe->draw_rule.texture) {
+         for (k = 0; k < rb_pipe->curr.num_fs_views; k++)
+            if (rb_pipe->draw_rule.texture == rb_pipe->curr.fs_texs[k])
+               block = TRUE;
+         for (k = 0; k < rb_pipe->curr.num_vs_views; k++) {
+            if (rb_pipe->draw_rule.texture == rb_pipe->curr.vs_texs[k]) {
+               block = TRUE;
+            }
+         }
+      }
+
+      if (block)
+         rb_pipe->draw_blocked |= (flag | RBUG_BLOCK_RULE);
+   }
+
+   if (rb_pipe->draw_blocked)
+      rbug_notify_draw_blocked(rb_pipe);
+
+   /* wait for rbug to clear the blocked flag */
+   while (rb_pipe->draw_blocked & flag) {
+      rb_pipe->draw_blocked |= flag;
+#ifdef PIPE_THREAD_HAVE_CONDVAR
+      pipe_condvar_wait(rb_pipe->draw_cond, rb_pipe->draw_mutex);
+#else
+      pipe_mutex_unlock(rb_pipe->draw_mutex);
+#ifdef PIPE_SUBSYSTEM_WINDOWS_USER
+      Sleep(1);
+#endif
+      pipe_mutex_lock(rb_pipe->draw_mutex);
+#endif
+   }
+
+}
+
 static void
 rbug_draw_arrays(struct pipe_context *_pipe,
                  unsigned prim,
@@ -55,10 +119,16 @@ rbug_draw_arrays(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   pipe_mutex_lock(rb_pipe->draw_mutex);
+   rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
+
    pipe->draw_arrays(pipe,
                      prim,
                      start,
                      count);
+
+   rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
+   pipe_mutex_unlock(rb_pipe->draw_mutex);
 }
 
 static void
@@ -75,6 +145,9 @@ rbug_draw_elements(struct pipe_context *_pipe,
    struct pipe_context *pipe = rb_pipe->pipe;
    struct pipe_resource *indexResource = rb_resource->resource;
 
+   pipe_mutex_lock(rb_pipe->draw_mutex);
+   rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
+
    pipe->draw_elements(pipe,
                        indexResource,
                        indexSize,
@@ -82,6 +155,9 @@ rbug_draw_elements(struct pipe_context *_pipe,
                        prim,
                        start,
                        count);
+
+   rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
+   pipe_mutex_unlock(rb_pipe->draw_mutex);
 }
 
 static void
@@ -100,6 +176,9 @@ rbug_draw_range_elements(struct pipe_context *_pipe,
    struct pipe_context *pipe = rb_pipe->pipe;
    struct pipe_resource *indexResource = rb_resource->resource;
 
+   pipe_mutex_lock(rb_pipe->draw_mutex);
+   rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
+
    pipe->draw_range_elements(pipe,
                              indexResource,
                              indexSize,
@@ -109,6 +188,9 @@ rbug_draw_range_elements(struct pipe_context *_pipe,
                              mode,
                              start,
                              count);
+
+   rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
+   pipe_mutex_unlock(rb_pipe->draw_mutex);
 }
 
 static struct pipe_query *
index 0c99d60f2db8e098054ac5b7df4b79a113cfda9f..80c803da83f4a931092a705ce906b4a3e76b3c64 100644 (file)
@@ -74,7 +74,7 @@ struct rbug_context {
       struct rbug_shader *fs;
       struct rbug_shader *vs;
 
-      struct rbug_sampler_view *sampler_view;
+      struct rbug_resource *texture;
       struct rbug_resource *surf;
 
       int blocker;
index 503183518c9324aebf6b30c97839bcf62b62dc20..959e168767a69c3fe1656a60e308e3aeaff3f477 100644 (file)
@@ -467,7 +467,7 @@ rbug_context_draw_rule(struct rbug_rbug *tr_rbug, struct rbug_header *header, ui
    pipe_mutex_lock(rb_context->draw_mutex);
    rb_context->draw_rule.vs = U642VOID(rule->vertex);
    rb_context->draw_rule.fs = U642VOID(rule->fragment);
-   rb_context->draw_rule.sampler_view = U642VOID(rule->texture);
+   rb_context->draw_rule.texture = U642VOID(rule->texture);
    rb_context->draw_rule.surf = U642VOID(rule->surface);
    rb_context->draw_rule.blocker = rule->block;
    rb_context->draw_blocker |= RBUG_BLOCK_RULE;