i915: Rework of batchbuffer code
authorJakob Bornecrantz <jakob@aurora.(none)>
Mon, 2 Jun 2008 12:55:06 +0000 (14:55 +0200)
committerJakob Bornecrantz <jakob@tungstengraphics.com>
Mon, 2 Jun 2008 15:24:30 +0000 (17:24 +0200)
src/gallium/drivers/i915simple/i915_batch.h
src/gallium/drivers/i915simple/i915_context.c
src/gallium/drivers/i915simple/i915_context.h
src/gallium/drivers/i915simple/i915_debug.c

index 4ea06ce02bf34abd814cd91ea549601015817082..6c62e84bc38608b58c3cdbf056af8e43f55afa24 100644 (file)
 #include "i915_winsys.h"
 #include "i915_debug.h"
 
+struct i915_batchbuffer
+{
+   struct pipe_buffer *buffer;
+   struct i915_winsys *winsys;
+
+   unsigned char *map;
+   unsigned char *ptr;
+
+   size_t size;
+
+   size_t relocs;
+   size_t max_relocs;
+};
+
+static INLINE boolean
+i915_batchbuffer_check( struct i915_batchbuffer *batch,
+                       size_t dwords,
+                       size_t relocs )
+{
+#if 0 /* To be used */
+   /** TODO JB: Check relocs */
+   return dwords * 4 <= batch->size - (batch->ptr - batch->map);
+#else
+   if (batch->winsys->batch_start( batch->winsys, dwords, relocs ))
+      return 1;
+   return 0;
+#endif
+}
+
+static INLINE size_t
+i915_batchbuffer_space( struct i915_batchbuffer *batch )
+{
+#if 0 /* To be used */
+   return batch->size - (batch->ptr - batch->map);
+#else
+   return 0;
+#endif
+}
+
+static INLINE void
+i915_batchbuffer_dword( struct i915_batchbuffer *batch,
+                       unsigned dword )
+{
+#if 0 /* To be used */
+   if (i915_batchbuffer_space(batch) < 4)
+      return;
+
+   *(unsigned *)batch->ptr = dword;
+   batch->ptr += 4;
+#else
+   batch->winsys->batch_dword( batch->winsys, dword );
+#endif
+}
+
+static INLINE void
+i915_batchbuffer_write( struct i915_batchbuffer *batch,
+                       void *data,
+                       size_t size )
+{
+#if 0 /* To be used */
+   if (i915_batchbuffer_space(batch) < size)
+      return;
+
+   memcpy(data, batch->ptr, size);
+   batch->ptr += size;
+#else
+#endif
+}
+
+static INLINE void
+i915_batchbuffer_reloc( struct i915_batchbuffer *batch,
+                       struct pipe_buffer *buffer,
+                       size_t flags,
+                       size_t offset )
+{
+   batch->winsys->batch_reloc( batch->winsys, buffer, flags, offset );
+}
+
+static INLINE void
+i915_batchbuffer_flush( struct i915_batchbuffer *batch,
+                       struct pipe_fence_handle **fence )
+{
+   batch->winsys->batch_flush( batch->winsys, fence );
+}
+
 #define BATCH_LOCALS
 
 #define BEGIN_BATCH( dwords, relocs ) \
-   (i915->batch_start = i915->winsys->batch_start( i915->winsys, dwords, relocs ))
+   (i915_batchbuffer_check( i915->batch, dwords, relocs ))
 
 #define OUT_BATCH( dword ) \
-   i915->winsys->batch_dword( i915->winsys, dword )
+   i915_batchbuffer_dword( i915->batch, dword )
 
 #define OUT_RELOC( buf, flags, delta ) \
-   i915->winsys->batch_reloc( i915->winsys, buf, flags, delta )
+   i915_batchbuffer_reloc( i915->batch, buf, flags, delta )
 
 #define ADVANCE_BATCH()
 
 #define FLUSH_BATCH(fence) do {                        \
    if (0) i915_dump_batchbuffer( i915 );               \
    i915->winsys->batch_flush( i915->winsys, fence );   \
-   i915->batch_start = NULL;                           \
    i915->hardware_dirty = ~0;                          \
 } while (0)
 
index 81cab757381490c6f4e372f9728d425e0f6b695f..378e4a5d4db54864a49d4575c833ec0b138df8ce 100644 (file)
@@ -181,7 +181,8 @@ struct pipe_context *i915_create_context( struct pipe_screen *screen,
 
    /* Batch stream debugging is a bit hacked up at the moment:
     */
-   i915->batch_start = NULL;
+   i915->batch = CALLOC_STRUCT(i915_batchbuffer);
+   i915->batch->winsys = i915_winsys;
 
    return &i915->pipe;
 }
index 2da90ae49d9fa03942e62b8691795e779ee09c11..2ee0381648d1e2a37ab68322b9833e89262885bb 100644 (file)
@@ -209,6 +209,8 @@ struct i915_texture {
    struct pipe_buffer *buffer;
 };
 
+struct i915_batchbuffer;
+
 struct i915_context
 {
    struct pipe_context pipe;
@@ -241,7 +243,7 @@ struct i915_context
    unsigned num_vertex_elements;
    unsigned num_vertex_buffers;
 
-   unsigned *batch_start;
+   struct i915_batchbuffer *batch;
 
    /** Vertex buffer */
    struct pipe_buffer *vbo;
index 9b9111167f81b38bbab99b6c2d00b4761943179e..a121dc0af4825d1016ba63a27f476b5ceb1ed01e 100644 (file)
@@ -861,7 +861,7 @@ void
 i915_dump_batchbuffer( struct i915_context *i915 )
 {
    struct debug_stream stream;
-   unsigned *start = i915->batch_start;
+   unsigned *start = 0;/*i915->batch_start;*/
    unsigned *end = i915->winsys->batch_start( i915->winsys, 0, 0 );
    unsigned long bytes = (unsigned long) (end - start) * 4;
    boolean done = FALSE;