i965g: fix up batchbuffer confusion
authorKeith Whitwell <keithw@vmware.com>
Wed, 4 Nov 2009 21:05:34 +0000 (21:05 +0000)
committerKeith Whitwell <keithw@vmware.com>
Wed, 4 Nov 2009 21:05:34 +0000 (21:05 +0000)
src/gallium/drivers/i965/brw_batchbuffer.c
src/gallium/drivers/i965/brw_batchbuffer.h
src/gallium/drivers/i965/brw_pipe_flush.c

index fd6b34cb8a88512e4fd43d2c91b70218f6a80a8d..bfb7175f754b3f5d62b05346247ac9c4da92b294 100644 (file)
 #include "brw_debug.h"
 #include "brw_structs.h"
 
-#define USE_LOCAL_BUFFER 1
+#define USE_MALLOC_BUFFER 1
 #define ALWAYS_EMIT_MI_FLUSH 1
 
 void
 brw_batchbuffer_reset(struct brw_batchbuffer *batch)
 {
-   if (batch->buf != NULL) {
+   if (batch->buf) {
       batch->sws->bo_unreference(batch->buf);
       batch->buf = NULL;
    }
 
-   if (USE_LOCAL_BUFFER && !batch->buffer)
-      batch->buffer = MALLOC(BRW_BATCH_SIZE);
+   if (batch->use_malloc_buffer && !batch->malloc_buffer)
+      batch->malloc_buffer = MALLOC(BRW_BATCH_SIZE);
 
    batch->buf = batch->sws->bo_alloc(batch->sws,
                                     BRW_BUFFER_TYPE_BATCH,
                                     BRW_BATCH_SIZE, 4096);
-   if (batch->buffer)
-      batch->map = batch->buffer;
+
+   if (batch->malloc_buffer)
+      batch->map = batch->malloc_buffer;
    else 
       batch->map = batch->sws->bo_map(batch->buf, GL_TRUE);
 
@@ -67,6 +68,7 @@ brw_batchbuffer_alloc(struct brw_winsys_screen *sws)
 {
    struct brw_batchbuffer *batch = CALLOC_STRUCT(brw_batchbuffer);
 
+   batch->use_malloc_buffer = USE_MALLOC_BUFFER;
    batch->sws = sws;
    brw_batchbuffer_reset(batch);
 
@@ -76,16 +78,16 @@ brw_batchbuffer_alloc(struct brw_winsys_screen *sws)
 void
 brw_batchbuffer_free(struct brw_batchbuffer *batch)
 {
-   if (batch->map) {
+   if (batch->malloc_buffer) {
+      FREE(batch->malloc_buffer);
+      batch->map = NULL;
+   }
+   else if (batch->map) {
       batch->sws->bo_unmap(batch->buf);
       batch->map = NULL;
    }
 
-
    batch->sws->bo_unreference(batch->buf);
-   batch->buf = NULL;
-
-   FREE(batch->buffer);
    FREE(batch);
 }
 
@@ -127,8 +129,15 @@ _brw_batchbuffer_flush(struct brw_batchbuffer *batch,
    batch->ptr += 4;
    used = batch->ptr - batch->map;
 
-   batch->sws->bo_unmap(batch->buf);
-   batch->map = NULL;
+   if (batch->use_malloc_buffer) {
+      batch->sws->bo_subdata(batch->buf, 0, used, batch->map );
+      batch->map = NULL;
+   }
+   else {
+      batch->sws->bo_unmap(batch->buf);
+      batch->map = NULL;
+   }
+
    batch->ptr = NULL;
       
    batch->sws->bo_exec(batch->buf, used );
index 61374ffb006f32f1c965958b9e7c13aad7ee921a..1828324cc09a8a42f7c5002d9aeaf2032fb52bea 100644 (file)
@@ -35,7 +35,8 @@ struct brw_batchbuffer {
     * XXX: is this still necessary?
     * XXX: if so, can this be hidden inside the GEM-specific winsys code?
     */
-   uint8_t *buffer;
+   boolean use_malloc_buffer;
+   uint8_t *malloc_buffer;
 
    /**
     * Values exported to speed up the writing the batchbuffer,
index 6ae3c5776577067b9de9b2ff07768ffd05ff33d8..9dff2beeb1da8b412d6009ddf7b0aae7f292fca8 100644 (file)
@@ -42,7 +42,8 @@ brw_flush( struct pipe_context *pipe,
            struct pipe_fence_handle **fence )
 {
    brw_context_flush( brw_context( pipe ) );
-   *fence = NULL;
+   if (fence)
+      *fence = NULL;
 }
 
 static unsigned brw_is_buffer_referenced(struct pipe_context *pipe,