i915g: Improve flushing using heuristics.
authorStéphane Marchesin <marcheu@chromium.org>
Wed, 6 Jul 2011 09:19:48 +0000 (02:19 -0700)
committerStéphane Marchesin <marcheu@chromium.org>
Wed, 6 Jul 2011 09:49:58 +0000 (02:49 -0700)
src/gallium/drivers/i915/i915_batch.h
src/gallium/drivers/i915/i915_clear.c
src/gallium/drivers/i915/i915_context.h
src/gallium/drivers/i915/i915_flush.c
src/gallium/drivers/i915/i915_prim_emit.c
src/gallium/drivers/i915/i915_prim_vbuf.c
src/gallium/drivers/i915/i915_winsys.h
src/gallium/winsys/i915/drm/i915_drm_buffer.c

index ce2691b2fd7a789d94ea61023ca53bef2596f47f..a1f8bcae802e712981adb5bb76a9242818fbb720 100644 (file)
@@ -29,6 +29,7 @@
 #define I915_BATCH_H
 
 #include "i915_batchbuffer.h"
+#include "i915_context.h"
 
 
 #define BEGIN_BATCH(dwords) \
 #define FLUSH_BATCH(fence) \
    i915_flush(i915, fence)
 
-
 /************************************************************************
  * i915_flush.c
  */
 void i915_flush(struct i915_context *i915, struct pipe_fence_handle **fence);
 
+/*
+ * Flush if the current color buf is idle and we have more than 256 vertices
+ * queued, or if the current color buf is busy and we have more than 4096
+ * vertices queued.
+ */
+static INLINE void i915_flush_heuristically(struct i915_context* i915,
+                                            int num_vertex)
+{
+   struct i915_winsys *iws = i915->iws;
+   i915->vertices_since_last_flush += num_vertex;
+   if ( i915->vertices_since_last_flush > 4096
+      || ( i915->vertices_since_last_flush > 256 &&
+           !iws->buffer_is_busy(iws, i915->current.cbuf_bo)) )
+      FLUSH_BATCH(NULL);
+}
+
 
 #endif
index fcb208d6dae2f4cf9c7e68bb301c14e78b30e587..e1d6a749cdc8cf6038029070b94f22e20f48f93c 100644 (file)
@@ -120,6 +120,11 @@ i915_clear_emit(struct pipe_context *pipe, unsigned buffers, const float *rgba,
    OUT_BATCH_F(desty + height);
    OUT_BATCH_F(destx);
    OUT_BATCH_F(desty);
+
+   /* Flush after clear, its expected to be a costly operation.
+    * This is not required, just a heuristic
+    */
+   FLUSH_BATCH(NULL);
 }
 
 /**
index c964208fedddfa883a173454952c362dc32040ce..84862351ffeedbab8e04d51fcc036bbe7e832bd3 100644 (file)
@@ -264,6 +264,8 @@ struct i915_context {
    struct util_slab_mempool transfer_pool;
    struct util_slab_mempool texture_transfer_pool;
 
+   int vertices_since_last_flush;
+
    /** blitter/hw-clear */
    struct blitter_context* blitter;
 
index b4e81147c4fddda8497d63ea3afca16d099a7623..6d76afa9dbc668e9760ff8e585f64d428e6fc9e2 100644 (file)
@@ -77,4 +77,5 @@ void i915_flush(struct i915_context *i915, struct pipe_fence_handle **fence)
    i915->static_dirty = ~0;
    /* kernel emits flushes in between batchbuffers */
    i915->flush_dirty = 0;
+   i915->vertices_since_last_flush = 0;
 }
index 85656cd784626ac0436ece27b20772c5bd03f038..1acde97d4bdcb78e633ec4a312d29c5cd943f13c 100644 (file)
@@ -166,6 +166,8 @@ emit_prim( struct draw_stage *stage,
 
    for (i = 0; i < nr; i++)
       emit_hw_vertex(i915, prim->v[i]);
+
+   i915_flush_heuristically(i915, nr);
 }
 
 
index 79db3b650ebebf600cad591bc8cc88b132feb84a..d8ae1de29632d7c23da9230ddd04626dc52a6123 100644 (file)
@@ -487,6 +487,7 @@ draw_arrays_fallback(struct vbuf_render *render,
 
    draw_arrays_generate_indices(render, start, nr, i915_render->fallback);
 
+   i915_flush_heuristically(i915, nr_indices);
 out:
    return;
 }
@@ -534,6 +535,7 @@ i915_vbuf_render_draw_arrays(struct vbuf_render *render,
              nr);
    OUT_BATCH(start); /* Beginning vertex index */
 
+   i915_flush_heuristically(i915, nr);
 out:
    return;
 }
@@ -657,6 +659,7 @@ i915_vbuf_render_draw_elements(struct vbuf_render *render,
                          save_nr_indices,
                          i915_render->fallback);
 
+   i915_flush_heuristically(i915, nr_indices);
 out:
    return;
 }
index 21cfdc9613ef5d2aa551fb343b2639c347ae6dda..20438609e072d1219473736e2eef5a3ce2616ab5 100644 (file)
@@ -207,6 +207,12 @@ struct i915_winsys {
 
    void (*buffer_destroy)(struct i915_winsys *iws,
                           struct i915_winsys_buffer *buffer);
+
+   /**
+    * Check if a buffer is busy.
+    */
+   boolean (*buffer_is_busy)(struct i915_winsys *iws,
+                             struct i915_winsys_buffer *buffer);
    /*@}*/
 
 
index 01dd4bf062f943079441bacd9e2b3b2fdd5b07fc..89d8e89e6a750be85c3675f0dd30875ad40ebee0 100644 (file)
@@ -213,6 +213,15 @@ i915_drm_buffer_destroy(struct i915_winsys *iws,
    FREE(buffer);
 }
 
+static boolean
+i915_drm_buffer_is_busy(struct i915_winsys *iws,
+                        struct i915_winsys_buffer *buffer)
+{
+   struct i915_drm_buffer* i915_buffer = i915_drm_buffer(buffer);
+   return drm_intel_bo_busy(i915_buffer->bo);
+}
+
+
 void
 i915_drm_winsys_init_buffer_functions(struct i915_drm_winsys *idws)
 {
@@ -224,4 +233,5 @@ i915_drm_winsys_init_buffer_functions(struct i915_drm_winsys *idws)
    idws->base.buffer_unmap = i915_drm_buffer_unmap;
    idws->base.buffer_write = i915_drm_buffer_write;
    idws->base.buffer_destroy = i915_drm_buffer_destroy;
+   idws->base.buffer_is_busy = i915_drm_buffer_is_busy;
 }