r300g: implement fences using dummy relocations
authorMarek Olšák <maraeo@gmail.com>
Tue, 15 Feb 2011 00:41:16 +0000 (01:41 +0100)
committerMarek Olšák <maraeo@gmail.com>
Tue, 15 Feb 2011 03:00:46 +0000 (04:00 +0100)
So finally we have them.

src/gallium/drivers/r300/r300_context.c
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_flush.c
src/gallium/drivers/r300/r300_screen.c

index 3608c04dc93035a3cee09b1a072710d85b93f8a1..a89bf7fac3176f138ceb18c3fd9c881f97b5a332 100644 (file)
@@ -532,28 +532,3 @@ fail:
     r300_destroy_context(&r300->context);
     return NULL;
 }
-
-void r300_finish(struct r300_context *r300)
-{
-    struct pipe_framebuffer_state *fb;
-    unsigned i;
-
-    /* This is a preliminary implementation of glFinish.
-     *
-     * The ideal implementation should use something like EmitIrqLocked and
-     * WaitIrq, or better, real fences.
-     */
-    if (r300->fb_state.state) {
-        fb = r300->fb_state.state;
-
-        for (i = 0; i < fb->nr_cbufs; i++) {
-            if (fb->cbufs[i]->texture) {
-                r300->rws->buffer_wait(r300_resource(fb->cbufs[i]->texture)->buf);
-                return;
-            }
-        }
-        if (fb->zsbuf && fb->zsbuf->texture) {
-            r300->rws->buffer_wait(r300_resource(fb->zsbuf->texture)->buf);
-        }
-    }
-}
index 58a7129849c799fe8be0e570bf02edf9994ba5ca..883b5f99c072f7ff22a39e0884f9efd4128b552e 100644 (file)
@@ -284,22 +284,6 @@ struct r300_query {
     struct r300_query* next;
 };
 
-/* Fence object.
- *
- * This is a fake fence. Instead of syncing with the fence, we sync
- * with the context, which is inefficient but compliant.
- *
- * This is not a subclass of pipe_fence_handle because pipe_fence_handle is
- * never actually fully defined. So, rather than have it as a member, and do
- * subclass-style casting, we treat pipe_fence_handle as an opaque, and just
- * trust that our state tracker does not ever mess up fence objects.
- */
-struct r300_fence {
-    struct pipe_reference reference;
-    struct r300_context *ctx;
-    boolean signalled;
-};
-
 struct r300_surface {
     struct pipe_surface base;
 
@@ -651,7 +635,6 @@ static INLINE void r300_mark_atom_dirty(struct r300_context *r300,
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
                                          void *priv);
 
-void r300_finish(struct r300_context *r300);
 void r300_flush_cb(void *data);
 
 /* Context initialization. */
index 0db13657027dbd072058d9579d0652c5c168618f..bfc15ceae72943727bbb50551f7300c140a22470 100644 (file)
@@ -37,11 +37,23 @@ static void r300_flush(struct pipe_context* pipe,
 {
     struct r300_context *r300 = r300_context(pipe);
     struct r300_atom *atom;
-    struct r300_fence **rfence = (struct r300_fence**)fence;
+    struct r300_winsys_bo **rfence = (struct r300_winsys_bo**)fence;
 
     if (r300->draw && !r300->draw_vbo_locked)
        r300_draw_flush_vbuf(r300);
 
+    if (rfence) {
+        /* Create a fence, which is a dummy BO. */
+        *rfence = r300->rws->buffer_create(r300->rws, 1, 1,
+                                           PIPE_BIND_VERTEX_BUFFER,
+                                           PIPE_USAGE_STATIC,
+                                           R300_DOMAIN_GTT);
+        /* Add the fence as a dummy relocation. */
+        r300->rws->cs_add_reloc(r300->cs,
+                                r300->rws->buffer_get_cs_handle(*rfence),
+                                R300_DOMAIN_GTT, R300_DOMAIN_GTT);
+    }
+
     if (r300->dirty_hw) {
         r300_emit_hyperz_end(r300);
         r300_emit_query_end(r300);
@@ -70,16 +82,17 @@ static void r300_flush(struct pipe_context* pipe,
         r300->upload_vb_validated = FALSE;
         r300->upload_ib_validated = FALSE;
     } else {
-        /* Even if hw is not dirty, we should at least reset the CS in case
-         * the space checking failed for the first draw operation. */
-        r300->rws->cs_flush(r300->cs);
-    }
-
-    /* Create a new fence. */
-    if (rfence) {
-        *rfence = CALLOC_STRUCT(r300_fence);
-        pipe_reference_init(&(*rfence)->reference, 1);
-        (*rfence)->ctx = r300;
+        if (rfence) {
+            /* We have to create a fence object, but the command stream is empty
+             * and we cannot emit an empty CS. We must write some regs then. */
+            CS_LOCALS(r300);
+            OUT_CS_REG(RB3D_COLOR_CHANNEL_MASK, 0);
+            r300->rws->cs_flush(r300->cs);
+        } else {
+            /* Even if hw is not dirty, we should at least reset the CS in case
+             * the space checking failed for the first draw operation. */
+            r300->rws->cs_flush(r300->cs);
+        }
     }
 }
 
index 0b0220654a7371103910109c459423c5dc95eb38..ed47315f42da2b12a1f707a675a6a7a55832c17d 100644 (file)
@@ -409,32 +409,28 @@ static void r300_fence_reference(struct pipe_screen *screen,
                                  struct pipe_fence_handle **ptr,
                                  struct pipe_fence_handle *fence)
 {
-    struct r300_fence **oldf = (struct r300_fence**)ptr;
-    struct r300_fence *newf = (struct r300_fence*)fence;
-
-    if (pipe_reference(&(*oldf)->reference, &newf->reference))
-        FREE(*oldf);
-
-    *ptr = fence;
+    r300_winsys_bo_reference((struct r300_winsys_bo**)ptr,
+                             (struct r300_winsys_bo*)fence);
 }
 
 static int r300_fence_signalled(struct pipe_screen *screen,
                                 struct pipe_fence_handle *fence,
                                 unsigned flags)
 {
-    struct r300_fence *rfence = (struct r300_fence*)fence;
+    struct r300_winsys_screen *rws = r300_screen(screen)->rws;
+    struct r300_winsys_bo *rfence = (struct r300_winsys_bo*)fence;
 
-    return rfence->signalled ? 0 : 1; /* 0 == success */
+    return !rws->buffer_is_busy(rfence) ? 0 : 1; /* 0 == success */
 }
 
 static int r300_fence_finish(struct pipe_screen *screen,
                              struct pipe_fence_handle *fence,
                              unsigned flags)
 {
-    struct r300_fence *rfence = (struct r300_fence*)fence;
+    struct r300_winsys_screen *rws = r300_screen(screen)->rws;
+    struct r300_winsys_bo *rfence = (struct r300_winsys_bo*)fence;
 
-    r300_finish(rfence->ctx);
-    rfence->signalled = TRUE;
+    rws->buffer_wait(rfence);
     return 0; /* 0 == success */
 }