Merge branch '7.8'
[mesa.git] / src / gallium / drivers / i965 / brw_batchbuffer.c
index 080c92046b891e4c60616b083d3534503329842a..003b1fd5bf0f807be9fdc6bd8fe397587470152d 100644 (file)
 
 #include "util/u_memory.h"
 
-#include "pipe/p_error.h"
-
 #include "brw_batchbuffer.h"
-//#include "brw_decode.h"
 #include "brw_reg.h"
 #include "brw_winsys.h"
 #include "brw_debug.h"
 #include "brw_structs.h"
 
-#define BATCH_SIZE (32*1024)
-#define USE_LOCAL_BUFFER 1
 #define ALWAYS_EMIT_MI_FLUSH 1
 
-void
+enum pipe_error
 brw_batchbuffer_reset(struct brw_batchbuffer *batch)
 {
-   if (batch->buf != NULL) {
-      batch->sws->bo_unreference(batch->buf);
-      batch->buf = NULL;
-   }
+   enum pipe_error ret;
 
-   if (USE_LOCAL_BUFFER && !batch->buffer)
-      batch->buffer = MALLOC(BATCH_SIZE);
+   ret = batch->sws->bo_alloc( batch->sws,
+                               BRW_BUFFER_TYPE_BATCH,
+                               BRW_BATCH_SIZE, 4096,
+                               &batch->buf );
+   if (ret)
+      return ret;
 
-   batch->buf = batch->sws->bo_alloc(batch->sws,
-                                    BRW_BUFFER_TYPE_BATCH,
-                                    BATCH_SIZE, 4096);
-   if (batch->buffer)
-      batch->map = batch->buffer;
-   else 
-      batch->map = batch->sws->bo_map(batch->buf, GL_TRUE);
+   batch->size = BRW_BATCH_SIZE;
+
+   /* With map_range semantics, the winsys can decide whether to
+    * inject a malloc'ed bounce buffer instead of mapping directly.
+    */
+   batch->map = batch->sws->bo_map(batch->buf,
+                                   BRW_DATA_BATCH_BUFFER,
+                                   0, batch->size,
+                                   GL_TRUE,
+                                   GL_TRUE,
+                                   GL_TRUE);
 
-   batch->size = BATCH_SIZE;
    batch->ptr = batch->map;
+   return PIPE_OK;
 }
 
 struct brw_batchbuffer *
-brw_batchbuffer_alloc(struct brw_winsys_screen *sws)
+brw_batchbuffer_alloc(struct brw_winsys_screen *sws,
+                      struct brw_chipset chipset)
 {
    struct brw_batchbuffer *batch = CALLOC_STRUCT(brw_batchbuffer);
 
    batch->sws = sws;
+   batch->chipset = chipset;
    brw_batchbuffer_reset(batch);
 
    return batch;
@@ -82,11 +84,7 @@ brw_batchbuffer_free(struct brw_batchbuffer *batch)
       batch->map = NULL;
    }
 
-
-   batch->sws->bo_unreference(batch->buf);
-   batch->buf = NULL;
-
-   FREE(batch->buffer);
+   bo_reference(&batch->buf, NULL);
    FREE(batch);
 }
 
@@ -109,7 +107,7 @@ _brw_batchbuffer_flush(struct brw_batchbuffer *batch,
                   file, line, used);
 
    if (ALWAYS_EMIT_MI_FLUSH) {
-      *(GLuint *) (batch->ptr) = ((MI_FLUSH << 16) | BRW_FLUSH_STATE_CACHE);
+      *(GLuint *) (batch->ptr) = MI_FLUSH | BRW_FLUSH_STATE_CACHE;
       batch->ptr += 4;
       used = batch->ptr - batch->map;
    }
@@ -128,24 +126,12 @@ _brw_batchbuffer_flush(struct brw_batchbuffer *batch,
    batch->ptr += 4;
    used = batch->ptr - batch->map;
 
+   batch->sws->bo_flush_range(batch->buf, 0, used);
    batch->sws->bo_unmap(batch->buf);
    batch->map = NULL;
    batch->ptr = NULL;
       
-   batch->sws->bo_exec(batch->buf, used, NULL, 0, 0 );
-
-#if 0      
-   if (BRW_DEBUG & DEBUG_BATCH) {
-      void *ptr = batch->sws->bo_map(batch->buf, GL_FALSE);
-
-      intel_decode(ptr,
-                  used / 4, 
-                  batch->buf->offset,
-                  batch->chipset.pci_id);
-
-      batch->sws->bo_unmap(batch->buf);
-   }
-#endif
+   batch->sws->bo_exec(batch->buf, used );
 
    if (BRW_DEBUG & DEBUG_SYNC) {
       /* Abuse map/unmap to achieve wait-for-fence.
@@ -154,8 +140,7 @@ _brw_batchbuffer_flush(struct brw_batchbuffer *batch,
        * interface.
        */
       debug_printf("waiting for idle\n");
-      batch->sws->bo_map(batch->buf, GL_TRUE);
-      batch->sws->bo_unmap(batch->buf);
+      batch->sws->bo_wait_idle(batch->buf);
    }
 
    /* Reset the buffer:
@@ -169,9 +154,9 @@ _brw_batchbuffer_flush(struct brw_batchbuffer *batch,
  */
 enum pipe_error
 brw_batchbuffer_emit_reloc(struct brw_batchbuffer *batch,
-                             struct brw_winsys_buffer *buffer,
-                             uint32_t read_domains, uint32_t write_domain,
-                            uint32_t delta)
+                          struct brw_winsys_buffer *buffer,
+                          enum brw_buffer_usage usage,
+                          uint32_t delta)
 {
    int ret;
 
@@ -183,20 +168,18 @@ brw_batchbuffer_emit_reloc(struct brw_batchbuffer *batch,
    }
 
    ret = batch->sws->bo_emit_reloc(batch->buf,
-                                  read_domains,
-                                  write_domain,
+                                  usage,
                                   delta, 
                                   batch->ptr - batch->map,
                                   buffer);
    if (ret != 0)
       return ret;
 
-   /*
-    * Using the old buffer offset, write in what the right data would be, in case
-    * the buffer doesn't move and we can short-circuit the relocation processing
-    * in the kernel
+   /* bo_emit_reloc was resposible for writing a zero into the
+    * batchbuffer if necessary.  Just need to update our pointer.
     */
-   brw_batchbuffer_emit_dword (batch, buffer->offset + delta);
+   batch->ptr += 4;
+
    return 0;
 }