[Mesa-dev] [RFC PATCH 07/14] anv: Update usage of block_pool->bo.

Rafael Antognolli rafael.antognolli at intel.com
Sat Dec 8 00:05:46 UTC 2018


Change block_pool->bo to be a pointer, and update its usage everywhere.
This makes it simpler to switch it later to a list of BOs.
---
 src/intel/vulkan/anv_allocator.c   | 31 +++++++++++++++++++-----------
 src/intel/vulkan/anv_batch_chain.c |  8 ++++----
 src/intel/vulkan/anv_blorp.c       |  2 +-
 src/intel/vulkan/anv_private.h     |  2 +-
 src/intel/vulkan/gen8_cmd_buffer.c |  6 +++---
 src/intel/vulkan/genX_blorp_exec.c |  4 ++--
 src/intel/vulkan/genX_cmd_buffer.c | 20 +++++++++----------
 7 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index acf3c80fbac..2eb191e98dc 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -441,11 +441,17 @@ anv_block_pool_init(struct anv_block_pool *pool,
    pool->bo_flags = bo_flags;
    pool->start_address = gen_canonical_address(start_address);
 
-   anv_bo_init(&pool->bo, 0, 0);
+   pool->bo = malloc(sizeof(*pool->bo));
+   if (!pool->bo)
+      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+   anv_bo_init(pool->bo, 0, 0);
 
    pool->fd = memfd_create("block pool", MFD_CLOEXEC);
-   if (pool->fd == -1)
-      return vk_error(VK_ERROR_INITIALIZATION_FAILED);
+   if (pool->fd == -1) {
+      result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
+      goto fail_bo;
+   }
 
    /* Just make it 2GB up-front.  The Linux kernel won't actually back it
     * with pages until we either map and fault on one of them or we use
@@ -478,6 +484,8 @@ anv_block_pool_init(struct anv_block_pool *pool,
    u_vector_finish(&pool->mmap_cleanups);
  fail_fd:
    close(pool->fd);
+ fail_bo:
+   free(pool->bo);
 
    return result;
 }
@@ -487,6 +495,7 @@ anv_block_pool_finish(struct anv_block_pool *pool)
 {
    struct anv_mmap_cleanup *cleanup;
 
+   free(pool->bo);
    u_vector_foreach(cleanup, &pool->mmap_cleanups) {
       if (cleanup->map)
          munmap(cleanup->map, cleanup->size);
@@ -590,13 +599,13 @@ anv_block_pool_expand_range(struct anv_block_pool *pool,
     * the EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag and the kernel does all of the
     * hard work for us.
     */
-   anv_bo_init(&pool->bo, gem_handle, size);
+   anv_bo_init(pool->bo, gem_handle, size);
    if (pool->bo_flags & EXEC_OBJECT_PINNED) {
-      pool->bo.offset = pool->start_address + BLOCK_POOL_MEMFD_CENTER -
+      pool->bo->offset = pool->start_address + BLOCK_POOL_MEMFD_CENTER -
          center_bo_offset;
    }
-   pool->bo.flags = pool->bo_flags;
-   pool->bo.map = map;
+   pool->bo->flags = pool->bo_flags;
+   pool->bo->map = map;
 
    return VK_SUCCESS;
 }
@@ -659,7 +668,7 @@ anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state)
 
    assert(state == &pool->state || back_used > 0);
 
-   uint32_t old_size = pool->bo.size;
+   uint32_t old_size = pool->bo->size;
 
    /* The block pool is always initialized to a nonzero size and this function
     * is always called after initialization.
@@ -685,7 +694,7 @@ anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state)
    while (size < back_required + front_required)
       size *= 2;
 
-   assert(size > pool->bo.size);
+   assert(size > pool->bo->size);
 
    /* We compute a new center_bo_offset such that, when we double the size
     * of the pool, we maintain the ratio of how much is used by each side.
@@ -722,7 +731,7 @@ anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state)
 
    result = anv_block_pool_expand_range(pool, center_bo_offset, size);
 
-   pool->bo.flags = pool->bo_flags;
+   pool->bo->flags = pool->bo_flags;
 
 done:
    pthread_mutex_unlock(&pool->device->mutex);
@@ -733,7 +742,7 @@ done:
        * needs to do so in order to maintain its concurrency model.
        */
       if (state == &pool->state) {
-         return pool->bo.size - pool->center_bo_offset;
+         return pool->bo->size - pool->center_bo_offset;
       } else {
          assert(pool->center_bo_offset > 0);
          return pool->center_bo_offset;
diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c
index 6c06858efe1..bec4d647b7e 100644
--- a/src/intel/vulkan/anv_batch_chain.c
+++ b/src/intel/vulkan/anv_batch_chain.c
@@ -501,7 +501,7 @@ anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer *cmd_buffer)
 {
    struct anv_state *bt_block = u_vector_head(&cmd_buffer->bt_block_states);
    return (struct anv_address) {
-      .bo = &anv_binding_table_pool(cmd_buffer->device)->block_pool.bo,
+      .bo = anv_binding_table_pool(cmd_buffer->device)->block_pool.bo,
       .offset = bt_block->offset,
    };
 }
@@ -1229,7 +1229,7 @@ adjust_relocations_to_state_pool(struct anv_state_pool *pool,
     * relocations that point to the pool bo with the correct offset.
     */
    for (size_t i = 0; i < relocs->num_relocs; i++) {
-      if (relocs->reloc_bos[i] == &pool->block_pool.bo) {
+      if (relocs->reloc_bos[i] == pool->block_pool.bo) {
          /* Adjust the delta value in the relocation to correctly
           * correspond to the new delta.  Initially, this value may have
           * been negative (if treated as unsigned), but we trust in
@@ -1337,7 +1337,7 @@ relocate_cmd_buffer(struct anv_cmd_buffer *cmd_buffer,
     * given time.  The only option is to always relocate them.
     */
    anv_reloc_list_apply(cmd_buffer->device, &cmd_buffer->surface_relocs,
-                        &cmd_buffer->device->surface_state_pool.block_pool.bo,
+                        cmd_buffer->device->surface_state_pool.block_pool.bo,
                         true /* always relocate surface states */);
 
    /* Since we own all of the batch buffers, we know what values are stored
@@ -1366,7 +1366,7 @@ setup_execbuf_for_cmd_buffer(struct anv_execbuf *execbuf,
 
    adjust_relocations_from_state_pool(ss_pool, &cmd_buffer->surface_relocs,
                                       cmd_buffer->last_ss_pool_center);
-   VkResult result = anv_execbuf_add_bo(execbuf, &ss_pool->block_pool.bo,
+   VkResult result = anv_execbuf_add_bo(execbuf, ss_pool->block_pool.bo,
                                         &cmd_buffer->surface_relocs, 0,
                                         &cmd_buffer->device->alloc);
    if (result != VK_SUCCESS)
diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c
index 478b8e7a3db..1de8977dd0b 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -719,7 +719,7 @@ void anv_CmdUpdateBuffer(
       anv_state_flush(cmd_buffer->device, tmp_data);
 
       struct blorp_address src = {
-         .buffer = &cmd_buffer->device->dynamic_state_pool.block_pool.bo,
+         .buffer = cmd_buffer->device->dynamic_state_pool.block_pool.bo,
          .offset = tmp_data.offset,
          .mocs = cmd_buffer->device->default_mocs,
       };
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index a364be8dad5..bf98c700873 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -632,7 +632,7 @@ struct anv_block_pool {
 
    uint64_t bo_flags;
 
-   struct anv_bo bo;
+   struct anv_bo *bo;
 
    /* The address where the start of the pool is pinned. The various bos that
     * are created as the pool grows will have addresses in the range
diff --git a/src/intel/vulkan/gen8_cmd_buffer.c b/src/intel/vulkan/gen8_cmd_buffer.c
index 752d04f3013..5d368ee6146 100644
--- a/src/intel/vulkan/gen8_cmd_buffer.c
+++ b/src/intel/vulkan/gen8_cmd_buffer.c
@@ -610,7 +610,7 @@ void genX(CmdSetEvent)(
       pc.DestinationAddressType  = DAT_PPGTT,
       pc.PostSyncOperation       = WriteImmediateData,
       pc.Address = (struct anv_address) {
-         &cmd_buffer->device->dynamic_state_pool.block_pool.bo,
+         cmd_buffer->device->dynamic_state_pool.block_pool.bo,
          event->state.offset
       };
       pc.ImmediateData           = VK_EVENT_SET;
@@ -634,7 +634,7 @@ void genX(CmdResetEvent)(
       pc.DestinationAddressType  = DAT_PPGTT;
       pc.PostSyncOperation       = WriteImmediateData;
       pc.Address = (struct anv_address) {
-         &cmd_buffer->device->dynamic_state_pool.block_pool.bo,
+         cmd_buffer->device->dynamic_state_pool.block_pool.bo,
          event->state.offset
       };
       pc.ImmediateData           = VK_EVENT_RESET;
@@ -663,7 +663,7 @@ void genX(CmdWaitEvents)(
          sem.CompareOperation    = COMPARE_SAD_EQUAL_SDD,
          sem.SemaphoreDataDword  = VK_EVENT_SET,
          sem.SemaphoreAddress = (struct anv_address) {
-            &cmd_buffer->device->dynamic_state_pool.block_pool.bo,
+            cmd_buffer->device->dynamic_state_pool.block_pool.bo,
             event->state.offset
          };
       }
diff --git a/src/intel/vulkan/genX_blorp_exec.c b/src/intel/vulkan/genX_blorp_exec.c
index 5af6abb0894..9d878cb867f 100644
--- a/src/intel/vulkan/genX_blorp_exec.c
+++ b/src/intel/vulkan/genX_blorp_exec.c
@@ -77,7 +77,7 @@ blorp_get_surface_base_address(struct blorp_batch *batch)
 {
    struct anv_cmd_buffer *cmd_buffer = batch->driver_batch;
    return (struct blorp_address) {
-      .buffer = &cmd_buffer->device->surface_state_pool.block_pool.bo,
+      .buffer = cmd_buffer->device->surface_state_pool.block_pool.bo,
       .offset = 0,
    };
 }
@@ -151,7 +151,7 @@ blorp_alloc_vertex_buffer(struct blorp_batch *batch, uint32_t size,
       anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, size, 64);
 
    *addr = (struct blorp_address) {
-      .buffer = &cmd_buffer->device->dynamic_state_pool.block_pool.bo,
+      .buffer = cmd_buffer->device->dynamic_state_pool.block_pool.bo,
       .offset = vb_state.offset,
       .mocs = cmd_buffer->device->default_mocs,
    };
diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c
index fb70cd2e386..75846bdef6e 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -95,7 +95,7 @@ genX(cmd_buffer_emit_state_base_address)(struct anv_cmd_buffer *cmd_buffer)
       sba.SurfaceStateBaseAddressModifyEnable = true;
 
       sba.DynamicStateBaseAddress =
-         (struct anv_address) { &device->dynamic_state_pool.block_pool.bo, 0 };
+         (struct anv_address) { device->dynamic_state_pool.block_pool.bo, 0 };
       sba.DynamicStateMemoryObjectControlState = GENX(MOCS);
       sba.DynamicStateBaseAddressModifyEnable = true;
 
@@ -104,7 +104,7 @@ genX(cmd_buffer_emit_state_base_address)(struct anv_cmd_buffer *cmd_buffer)
       sba.IndirectObjectBaseAddressModifyEnable = true;
 
       sba.InstructionBaseAddress =
-         (struct anv_address) { &device->instruction_state_pool.block_pool.bo, 0 };
+         (struct anv_address) { device->instruction_state_pool.block_pool.bo, 0 };
       sba.InstructionMemoryObjectControlState = GENX(MOCS);
       sba.InstructionBaseAddressModifyEnable = true;
 
@@ -884,7 +884,7 @@ genX(copy_fast_clear_dwords)(struct anv_cmd_buffer *cmd_buffer,
    assert(image->aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV);
 
    struct anv_address ss_clear_addr = {
-      .bo = &cmd_buffer->device->surface_state_pool.block_pool.bo,
+      .bo = cmd_buffer->device->surface_state_pool.block_pool.bo,
       .offset = surface_state.offset +
                 cmd_buffer->device->isl_dev.ss.clear_value_offset,
    };
@@ -1508,7 +1508,7 @@ genX(CmdExecuteCommands)(
           * we allocated for them in BeginCommandBuffer.
           */
          struct anv_bo *ss_bo =
-            &primary->device->surface_state_pool.block_pool.bo;
+            primary->device->surface_state_pool.block_pool.bo;
          struct anv_state src_state = primary->state.render_pass_states;
          struct anv_state dst_state = secondary->state.render_pass_states;
          assert(src_state.alloc_size == dst_state.alloc_size);
@@ -2094,7 +2094,7 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
             anv_cmd_buffer_alloc_surface_state(cmd_buffer);
 
          struct anv_address constant_data = {
-            .bo = &pipeline->device->dynamic_state_pool.block_pool.bo,
+            .bo = pipeline->device->dynamic_state_pool.block_pool.bo,
             .offset = pipeline->shaders[stage]->constant_data.offset,
          };
          unsigned constant_data_size =
@@ -2464,7 +2464,7 @@ cmd_buffer_flush_push_constants(struct anv_cmd_buffer *cmd_buffer,
                uint32_t read_len;
                if (binding->set == ANV_DESCRIPTOR_SET_SHADER_CONSTANTS) {
                   struct anv_address constant_data = {
-                     .bo = &pipeline->device->dynamic_state_pool.block_pool.bo,
+                     .bo = pipeline->device->dynamic_state_pool.block_pool.bo,
                      .offset = pipeline->shaders[stage]->constant_data.offset,
                   };
                   unsigned constant_data_size =
@@ -2512,7 +2512,7 @@ cmd_buffer_flush_push_constants(struct anv_cmd_buffer *cmd_buffer,
 
             if (state.alloc_size > 0) {
                c.ConstantBody.Buffer[n] = (struct anv_address) {
-                  .bo = &cmd_buffer->device->dynamic_state_pool.block_pool.bo,
+                  .bo = cmd_buffer->device->dynamic_state_pool.block_pool.bo,
                   .offset = state.offset,
                };
                c.ConstantBody.ReadLength[n] =
@@ -2722,7 +2722,7 @@ emit_base_vertex_instance(struct anv_cmd_buffer *cmd_buffer,
    anv_state_flush(cmd_buffer->device, id_state);
 
    struct anv_address addr = {
-      .bo = &cmd_buffer->device->dynamic_state_pool.block_pool.bo,
+      .bo = cmd_buffer->device->dynamic_state_pool.block_pool.bo,
       .offset = id_state.offset,
    };
 
@@ -2740,7 +2740,7 @@ emit_draw_index(struct anv_cmd_buffer *cmd_buffer, uint32_t draw_index)
    anv_state_flush(cmd_buffer->device, state);
 
    struct anv_address addr = {
-      .bo = &cmd_buffer->device->dynamic_state_pool.block_pool.bo,
+      .bo = cmd_buffer->device->dynamic_state_pool.block_pool.bo,
       .offset = state.offset,
    };
 
@@ -3202,7 +3202,7 @@ void genX(CmdDispatchBase)(
       sizes[2] = groupCountZ;
       anv_state_flush(cmd_buffer->device, state);
       cmd_buffer->state.compute.num_workgroups = (struct anv_address) {
-         .bo = &cmd_buffer->device->dynamic_state_pool.block_pool.bo,
+         .bo = cmd_buffer->device->dynamic_state_pool.block_pool.bo,
          .offset = state.offset,
       };
    }
-- 
2.17.1



More information about the mesa-dev mailing list