[Mesa-dev] [PATCH 09/17] i965: Refactor relocs into a brw_reloc_list structure.

Kenneth Graunke kenneth at whitecape.org
Wed Sep 6 00:09:42 UTC 2017


I'm planning on splitting batch and state into separate buffers, at
which point we'll need two relocation lists.  In preparation for that,
this patch refactors the relocation stuff into a structure we can
replicate...which looks a lot like anv_reloc_list.
---
 src/mesa/drivers/dri/i965/brw_context.h       | 12 ++++++---
 src/mesa/drivers/dri/i965/intel_batchbuffer.c | 39 ++++++++++++++++-----------
 2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index b3a8fa01aff..09fb66699fc 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -436,6 +436,12 @@ enum brw_gpu_ring {
    BLT_RING,
 };
 
+struct brw_reloc_list {
+   struct drm_i915_gem_relocation_entry *relocs;
+   int reloc_count;
+   int reloc_array_size;
+};
+
 struct intel_batchbuffer {
    /** Current batchbuffer being queued up. */
    struct brw_bo *bo;
@@ -455,9 +461,7 @@ struct intel_batchbuffer {
    bool needs_sol_reset;
    bool state_base_address_emitted;
 
-   struct drm_i915_gem_relocation_entry *relocs;
-   int reloc_count;
-   int reloc_array_size;
+   struct brw_reloc_list batch_relocs;
    unsigned int valid_reloc_flags;
 
    /** The validation list */
@@ -471,7 +475,7 @@ struct intel_batchbuffer {
 
    struct {
       uint32_t *map_next;
-      int reloc_count;
+      int batch_reloc_count;
       int exec_count;
    } saved;
 
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index 1f6a43e406d..8ada0bcdc9b 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -58,6 +58,15 @@ uint_key_hash(const void *key)
    return (uintptr_t) key;
 }
 
+static void
+init_reloc_list(struct brw_reloc_list *rlist, int count)
+{
+   rlist->reloc_count = 0;
+   rlist->reloc_array_size = count;
+   rlist->relocs = malloc(rlist->reloc_array_size *
+                          sizeof(struct drm_i915_gem_relocation_entry));
+}
+
 void
 intel_batchbuffer_init(struct intel_screen *screen,
                        struct intel_batchbuffer *batch)
@@ -65,10 +74,8 @@ intel_batchbuffer_init(struct intel_screen *screen,
    struct brw_bufmgr *bufmgr = screen->bufmgr;
    const struct gen_device_info *devinfo = &screen->devinfo;
 
-   batch->reloc_count = 0;
-   batch->reloc_array_size = 250;
-   batch->relocs = malloc(batch->reloc_array_size *
-                          sizeof(struct drm_i915_gem_relocation_entry));
+   init_reloc_list(&batch->batch_relocs, 250);
+
    batch->exec_count = 0;
    batch->exec_array_size = 100;
    batch->exec_bos =
@@ -177,7 +184,7 @@ void
 intel_batchbuffer_save_state(struct brw_context *brw)
 {
    brw->batch.saved.map_next = brw->batch.map_next;
-   brw->batch.saved.reloc_count = brw->batch.reloc_count;
+   brw->batch.saved.batch_reloc_count = brw->batch.batch_relocs.reloc_count;
    brw->batch.saved.exec_count = brw->batch.exec_count;
 }
 
@@ -188,7 +195,7 @@ intel_batchbuffer_reset_to_saved(struct brw_context *brw)
         i < brw->batch.exec_count; i++) {
       brw_bo_unreference(brw->batch.exec_bos[i]);
    }
-   brw->batch.reloc_count = brw->batch.saved.reloc_count;
+   brw->batch.batch_relocs.reloc_count = brw->batch.saved.batch_reloc_count;
    brw->batch.exec_count = brw->batch.saved.exec_count;
 
    brw->batch.map_next = brw->batch.saved.map_next;
@@ -202,7 +209,7 @@ intel_batchbuffer_free(struct intel_batchbuffer *batch)
    for (int i = 0; i < batch->exec_count; i++) {
       brw_bo_unreference(batch->exec_bos[i]);
    }
-   free(batch->relocs);
+   free(batch->batch_relocs.relocs);
    free(batch->exec_bos);
    free(batch->validation_list);
 
@@ -426,7 +433,7 @@ brw_new_batch(struct brw_context *brw)
       brw_bo_unreference(brw->batch.exec_bos[i]);
       brw->batch.exec_bos[i] = NULL;
    }
-   brw->batch.reloc_count = 0;
+   brw->batch.batch_relocs.reloc_count = 0;
    brw->batch.exec_count = 0;
    brw->batch.aperture_space = 0;
 
@@ -640,8 +647,8 @@ do_flush_locked(struct brw_context *brw, int in_fence_fd, int *out_fence_fd)
 
       struct drm_i915_gem_exec_object2 *entry = &batch->validation_list[0];
       assert(entry->handle == batch->bo->gem_handle);
-      entry->relocation_count = batch->reloc_count;
-      entry->relocs_ptr = (uintptr_t) batch->relocs;
+      entry->relocation_count = batch->batch_relocs.reloc_count;
+      entry->relocs_ptr = (uintptr_t) batch->batch_relocs.relocs;
 
       if (batch->use_batch_first) {
          flags |= I915_EXEC_BATCH_FIRST | I915_EXEC_HANDLE_LUT;
@@ -766,12 +773,14 @@ brw_emit_reloc(struct intel_batchbuffer *batch, uint32_t batch_offset,
                struct brw_bo *target, uint32_t target_offset,
                unsigned int reloc_flags)
 {
+   struct brw_reloc_list *rlist = &batch->batch_relocs;
+
    assert(target != NULL);
 
-   if (batch->reloc_count == batch->reloc_array_size) {
-      batch->reloc_array_size *= 2;
-      batch->relocs = realloc(batch->relocs,
-                              batch->reloc_array_size *
+   if (rlist->reloc_count == rlist->reloc_array_size) {
+      rlist->reloc_array_size *= 2;
+      rlist->relocs = realloc(rlist->relocs,
+                              rlist->reloc_array_size *
                               sizeof(struct drm_i915_gem_relocation_entry));
    }
 
@@ -784,7 +793,7 @@ brw_emit_reloc(struct intel_batchbuffer *batch, uint32_t batch_offset,
    if (reloc_flags)
       entry->flags |= reloc_flags & batch->valid_reloc_flags;
 
-   batch->relocs[batch->reloc_count++] =
+   rlist->relocs[rlist->reloc_count++] =
       (struct drm_i915_gem_relocation_entry) {
          .offset = batch_offset,
          .delta = target_offset,
-- 
2.14.1



More information about the mesa-dev mailing list