anv: Use an anv_address in anv_buffer
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 31 May 2018 01:05:54 +0000 (18:05 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 31 May 2018 23:51:46 +0000 (16:51 -0700)
Reviewed-by: Scott D Phillips <scott.d.phillips@intel.com>
src/intel/vulkan/anv_blorp.c
src/intel/vulkan/anv_descriptor_set.c
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/gen7_cmd_buffer.c
src/intel/vulkan/gen8_cmd_buffer.c
src/intel/vulkan/genX_cmd_buffer.c
src/intel/vulkan/genX_query.c

index c4a3e4a405edfc8f008866a920433a75871d68f9..359ebfb3ca1193582069bcde050d80d69569be7a 100644 (file)
@@ -154,8 +154,8 @@ get_blorp_surf_for_anv_buffer(struct anv_device *device,
    *blorp_surf = (struct blorp_surf) {
       .surf = isl_surf,
       .addr = {
-         .buffer = buffer->bo,
-         .offset = buffer->offset + offset,
+         .buffer = buffer->address.bo,
+         .offset = buffer->address.offset + offset,
          .mocs = device->default_mocs,
       },
    };
@@ -662,13 +662,13 @@ void anv_CmdCopyBuffer(
 
    for (unsigned r = 0; r < regionCount; r++) {
       struct blorp_address src = {
-         .buffer = src_buffer->bo,
-         .offset = src_buffer->offset + pRegions[r].srcOffset,
+         .buffer = src_buffer->address.bo,
+         .offset = src_buffer->address.offset + pRegions[r].srcOffset,
          .mocs = cmd_buffer->device->default_mocs,
       };
       struct blorp_address dst = {
-         .buffer = dst_buffer->bo,
-         .offset = dst_buffer->offset + pRegions[r].dstOffset,
+         .buffer = dst_buffer->address.bo,
+         .offset = dst_buffer->address.offset + pRegions[r].dstOffset,
          .mocs = cmd_buffer->device->default_mocs,
       };
 
@@ -720,8 +720,8 @@ void anv_CmdUpdateBuffer(
          .mocs = cmd_buffer->device->default_mocs,
       };
       struct blorp_address dst = {
-         .buffer = dst_buffer->bo,
-         .offset = dst_buffer->offset + dstOffset,
+         .buffer = dst_buffer->address.bo,
+         .offset = dst_buffer->address.offset + dstOffset,
          .mocs = cmd_buffer->device->default_mocs,
       };
 
index 0380e13a88c75b4de36301138ae6277c3093eb2c..9534ba81cdb4031198b14ba0040ec74d552254bd 100644 (file)
@@ -746,10 +746,7 @@ anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
 
       bview->format = anv_isl_format_for_descriptor_type(type);
       bview->range = anv_buffer_get_range(buffer, offset, range);
-      bview->address = (struct anv_address) {
-         .bo = buffer->bo,
-         .offset = buffer->offset + offset,
-      };
+      bview->address = anv_address_add(buffer->address, offset);
 
       /* If we're writing descriptors through a push command, we need to
        * allocate the surface state from the command buffer. Otherwise it will
index 3deeea5a86fbc4dee496fc80ed36cb840beb29cf..19fa1b708f5c5c5bfc7d35c6c5618755504014f3 100644 (file)
@@ -2516,11 +2516,12 @@ anv_bind_buffer_memory(const VkBindBufferMemoryInfo *pBindInfo)
 
    if (mem) {
       assert((buffer->usage & mem->type->valid_buffer_usage) == buffer->usage);
-      buffer->bo = mem->bo;
-      buffer->offset = pBindInfo->memoryOffset;
+      buffer->address = (struct anv_address) {
+         .bo = mem->bo,
+         .offset = pBindInfo->memoryOffset,
+      };
    } else {
-      buffer->bo = NULL;
-      buffer->offset = 0;
+      buffer->address = ANV_NULL_ADDRESS;
    }
 }
 
@@ -2686,8 +2687,7 @@ VkResult anv_CreateBuffer(
 
    buffer->size = pCreateInfo->size;
    buffer->usage = pCreateInfo->usage;
-   buffer->bo = NULL;
-   buffer->offset = 0;
+   buffer->address = ANV_NULL_ADDRESS;
 
    *pBuffer = anv_buffer_to_handle(buffer);
 
index 090d0615e41e311806d4453b89ab4403e0375aca..bbb740e2c628b4822a0202b6e19c41e6ea0ba302 100644 (file)
@@ -1471,10 +1471,7 @@ anv_CreateBufferView(VkDevice _device,
                                               pCreateInfo->range);
    view->range = align_down_npot_u32(view->range, format_bs);
 
-   view->address = (struct anv_address) {
-      .bo = buffer->bo,
-      .offset = buffer->offset + pCreateInfo->offset,
-   };
+   view->address = anv_address_add(buffer->address, pCreateInfo->offset);
 
    if (buffer->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) {
       view->surface_state = alloc_surface_state(device);
index 95d3e4d0936876935d466d7fe60bef0a81769afe..ecc0cb90595b878bacad7c5e52da385bbbfcce1c 100644 (file)
@@ -1558,8 +1558,7 @@ struct anv_buffer {
    VkBufferUsageFlags                           usage;
 
    /* Set when bound */
-   struct anv_bo *                              bo;
-   VkDeviceSize                                 offset;
+   struct anv_address                           address;
 };
 
 static inline uint64_t
index cbeb8389486e04f8d9b7dffaa860e3218a19cc51..aa4dcde46b9e51def8e7c933fc8354b9cebfd948 100644 (file)
@@ -247,10 +247,10 @@ genX(cmd_buffer_flush_dynamic_state)(struct anv_cmd_buffer *cmd_buffer)
          ib.IndexFormat                = cmd_buffer->state.gfx.gen7.index_type;
          ib.MemoryObjectControlState   = GENX(MOCS);
 
-         ib.BufferStartingAddress =
-            (struct anv_address) { buffer->bo, buffer->offset + offset };
-         ib.BufferEndingAddress =
-            (struct anv_address) { buffer->bo, buffer->offset + buffer->size };
+         ib.BufferStartingAddress      = anv_address_add(buffer->address,
+                                                         offset);
+         ib.BufferEndingAddress        = anv_address_add(buffer->address,
+                                                         buffer->size);
       }
    }
 
index 2999c99261d1b4a34a159725be5f955969d4abdd..ca2baf84a19b67c943c7ca77dad16b31423e4797 100644 (file)
@@ -566,8 +566,7 @@ void genX(CmdBindIndexBuffer)(
    anv_batch_emit(&cmd_buffer->batch, GENX(3DSTATE_INDEX_BUFFER), ib) {
       ib.IndexFormat                = vk_to_gen_index_type[indexType];
       ib.MemoryObjectControlState   = GENX(MOCS);
-      ib.BufferStartingAddress      =
-         (struct anv_address) { buffer->bo, buffer->offset + offset };
+      ib.BufferStartingAddress      = anv_address_add(buffer->address, offset);
       ib.BufferSize                 = buffer->size - offset;
    }
 
index d38c5f8cabbeeaee3aa101a9ddab8a979cd2ac22..65aea3f4aee18a691b586181c3e8993300115dbc 100644 (file)
@@ -2112,10 +2112,8 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
          /* Clamp the range to the buffer size */
          uint32_t range = MIN2(desc->range, desc->buffer->size - offset);
 
-         struct anv_address address = {
-            .bo = desc->buffer->bo,
-            .offset = desc->buffer->offset + offset,
-         };
+         struct anv_address address =
+            anv_address_add(desc->buffer->address, offset);
 
          surface_state =
             anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
@@ -2409,11 +2407,8 @@ cmd_buffer_flush_push_constants(struct anv_cmd_buffer *cmd_buffer,
 
                   read_len = MIN2(range->length,
                      DIV_ROUND_UP(buf_range, 32) - range->start);
-                  read_addr = (struct anv_address) {
-                     .bo = desc->buffer->bo,
-                     .offset = desc->buffer->offset + buf_offset +
-                               range->start * 32,
-                  };
+                  read_addr = anv_address_add(desc->buffer->address,
+                                              buf_offset + range->start * 32);
                }
 
                if (read_len > 0) {
@@ -2501,12 +2496,12 @@ genX(cmd_buffer_flush_state)(struct anv_cmd_buffer *cmd_buffer)
 
             .AddressModifyEnable = true,
             .BufferPitch = pipeline->binding_stride[vb],
-            .BufferStartingAddress = { buffer->bo, buffer->offset + offset },
+            .BufferStartingAddress = anv_address_add(buffer->address, offset),
 
 #if GEN_GEN >= 8
             .BufferSize = buffer->size - offset
 #else
-            .EndAddress = { buffer->bo, buffer->offset + buffer->size - 1},
+            .EndAddress = anv_address_add(buffer->address, buffer->size - 1),
 #endif
          };
 
@@ -2857,10 +2852,7 @@ void genX(CmdDrawIndirect)(
    genX(cmd_buffer_flush_state)(cmd_buffer);
 
    for (uint32_t i = 0; i < drawCount; i++) {
-      struct anv_address draw = {
-         .bo = buffer->bo,
-         .offset = buffer->offset + offset,
-      };
+      struct anv_address draw = anv_address_add(buffer->address, offset);
 
       if (vs_prog_data->uses_firstvertex ||
           vs_prog_data->uses_baseinstance)
@@ -2898,10 +2890,7 @@ void genX(CmdDrawIndexedIndirect)(
    genX(cmd_buffer_flush_state)(cmd_buffer);
 
    for (uint32_t i = 0; i < drawCount; i++) {
-      struct anv_address draw = {
-         .bo = buffer->bo,
-         .offset = buffer->offset + offset,
-      };
+      struct anv_address draw = anv_address_add(buffer->address, offset);
 
       /* TODO: We need to stomp base vertex to 0 somehow */
       if (vs_prog_data->uses_firstvertex ||
@@ -3153,10 +3142,7 @@ void genX(CmdDispatchIndirect)(
    ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
    struct anv_pipeline *pipeline = cmd_buffer->state.compute.base.pipeline;
    const struct brw_cs_prog_data *prog_data = get_cs_prog_data(pipeline);
-   struct anv_address addr = {
-      .bo = buffer->bo,
-      .offset = buffer->offset + offset,
-   };
+   struct anv_address addr = anv_address_add(buffer->address, offset);
    struct anv_batch *batch = &cmd_buffer->batch;
 
    anv_cmd_buffer_push_base_group_id(cmd_buffer, 0, 0, 0);
index 4efcc57e4754e8fe730877a2e27be58c4ed6d6d6..de409be04edacf6f3770e294ffe3ba9542e58232 100644 (file)
@@ -686,19 +686,14 @@ gpu_write_query_result(struct anv_batch *batch,
 
    anv_batch_emit(batch, GENX(MI_STORE_REGISTER_MEM), srm) {
       srm.RegisterAddress  = reg;
-      srm.MemoryAddress    = (struct anv_address) {
-         .bo = dst_buffer->bo,
-         .offset = dst_buffer->offset + dst_offset,
-      };
+      srm.MemoryAddress    = anv_address_add(dst_buffer->address, dst_offset);
    }
 
    if (flags & VK_QUERY_RESULT_64_BIT) {
       anv_batch_emit(batch, GENX(MI_STORE_REGISTER_MEM), srm) {
          srm.RegisterAddress  = reg + 4;
-         srm.MemoryAddress    = (struct anv_address) {
-            .bo = dst_buffer->bo,
-            .offset = dst_buffer->offset + dst_offset + 4,
-         };
+         srm.MemoryAddress    = anv_address_add(dst_buffer->address,
+                                                dst_offset + 4);
       }
    }
 }