i915g/winsys: buffer validation support
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Sun, 27 Feb 2011 16:51:48 +0000 (17:51 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Sun, 27 Feb 2011 17:49:56 +0000 (18:49 +0100)
v2: Add the batch bo to the libdrm validation lost, for otherwise
libdrm won't take previously used buffers into account.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
src/gallium/drivers/i915/i915_winsys.h
src/gallium/winsys/i915/drm/i915_drm_batchbuffer.c
src/gallium/winsys/i915/sw/i915_sw_batchbuffer.c

index e915a886c9b7196adcbf58a659ae3e683a39cf8a..4ac2f5b9777840fd91c788b7e727c05a23aa2b71 100644 (file)
@@ -94,6 +94,18 @@ struct i915_winsys {
    struct i915_winsys_batchbuffer *
       (*batchbuffer_create)(struct i915_winsys *iws);
 
+   /**
+    * Validate buffers for usage in this batchbuffer.
+    * Does space-checking and asorted other book-keeping.
+    *
+    * @batch
+    * @buffers array to buffers to validate
+    * @num_of_buffers size of the passed array
+    */
+   boolean (*validate_buffers)(struct i915_winsys_batchbuffer *batch,
+                              struct i915_winsys_buffer **buffers,
+                              int num_of_buffers);
+
    /**
     * Emit a relocation to a buffer.
     * Target position in batchbuffer is the same as ptr.
index 54b2d7af2eb184da080462b2e419bd735804f3d8..7cc5af89639ec16565279dadb656b3f34a0c7246 100644 (file)
@@ -72,6 +72,26 @@ i915_drm_batchbuffer_create(struct i915_winsys *iws)
    return &batch->base;
 }
 
+static boolean
+i915_drm_batchbuffer_validate_buffers(struct i915_winsys_batchbuffer *batch,
+                                     struct i915_winsys_buffer **buffer,
+                                     int num_of_buffers)
+{
+   struct i915_drm_batchbuffer *drm_batch = i915_drm_batchbuffer(batch);
+   drm_intel_bo *bos[num_of_buffers + 1];
+   int i, ret;
+
+   bos[0] = drm_batch->bo;
+   for (i = 0; i < num_of_buffers; i++)
+      bos[i+1] = intel_bo(buffer[i]);
+
+   ret = drm_intel_bufmgr_check_aperture_space(bos, num_of_buffers);
+   if (ret != 0)
+      return FALSE;
+
+   return TRUE;
+}
+
 static int
 i915_drm_batchbuffer_reloc(struct i915_winsys_batchbuffer *ibatch,
                             struct i915_winsys_buffer *buffer,
@@ -211,6 +231,7 @@ i915_drm_batchbuffer_destroy(struct i915_winsys_batchbuffer *ibatch)
 void i915_drm_winsys_init_batchbuffer_functions(struct i915_drm_winsys *idws)
 {
    idws->base.batchbuffer_create = i915_drm_batchbuffer_create;
+   idws->base.validate_buffers = i915_drm_batchbuffer_validate_buffers;
    idws->base.batchbuffer_reloc = i915_drm_batchbuffer_reloc;
    idws->base.batchbuffer_flush = i915_drm_batchbuffer_flush;
    idws->base.batchbuffer_destroy = i915_drm_batchbuffer_destroy;
index d246bf64138dbb3be4f7cc385bc121e3e011f764..3d0c1fa622418ab54b98892a95ab3c83c763823b 100644 (file)
@@ -58,6 +58,14 @@ i915_sw_batchbuffer_create(struct i915_winsys *iws)
    return &batch->base;
 }
 
+static boolean
+i915_sw_batchbuffer_validate_buffers(struct i915_winsys_batchbuffer *batch,
+                                    struct i915_winsys_buffer **buffer,
+                                    int num_of_buffers)
+{
+   return TRUE;
+}
+
 static int
 i915_sw_batchbuffer_reloc(struct i915_winsys_batchbuffer *ibatch,
                           struct i915_winsys_buffer *buffer,
@@ -146,6 +154,7 @@ i915_sw_batchbuffer_destroy(struct i915_winsys_batchbuffer *ibatch)
 void i915_sw_winsys_init_batchbuffer_functions(struct i915_sw_winsys *isws)
 {
    isws->base.batchbuffer_create = i915_sw_batchbuffer_create;
+   isws->base.validate_buffers = i915_sw_batchbuffer_validate_buffers;
    isws->base.batchbuffer_reloc = i915_sw_batchbuffer_reloc;
    isws->base.batchbuffer_flush = i915_sw_batchbuffer_flush;
    isws->base.batchbuffer_destroy = i915_sw_batchbuffer_destroy;