anv: Use an anv_address in anv_buffer_view
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 31 May 2018 00:36:49 +0000 (17:36 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 31 May 2018 23:51:46 +0000 (16:51 -0700)
Instead of storing a BO and offset separately, use an anv_address.  This
changes anv_fill_buffer_surface_state to use anv_address and we now call
anv_address_physical and pass that into ISL.

Reviewed-by: Scott D Phillips <scott.d.phillips@intel.com>
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/genX_cmd_buffer.c

index 67511e4b28609d38ed9bc2d370f726a06a37cae4..0380e13a88c75b4de36301138ae6277c3093eb2c 100644 (file)
@@ -745,9 +745,11 @@ anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
          &set->buffer_views[bind_layout->buffer_index + element];
 
       bview->format = anv_isl_format_for_descriptor_type(type);
-      bview->bo = buffer->bo;
-      bview->offset = buffer->offset + offset;
       bview->range = anv_buffer_get_range(buffer, offset, range);
+      bview->address = (struct anv_address) {
+         .bo = buffer->bo,
+         .offset = buffer->offset + offset,
+      };
 
       /* If we're writing descriptors through a push command, we need to
        * allocate the surface state from the command buffer. Otherwise it will
@@ -758,7 +760,7 @@ anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
 
       anv_fill_buffer_surface_state(device, bview->surface_state,
                                     bview->format,
-                                    bview->offset, bview->range, 1);
+                                    bview->address, bview->range, 1);
 
       *desc = (struct anv_descriptor) {
          .type = type,
index 276e32bddda262680e852b4003bd14ad6b3955ba..3deeea5a86fbc4dee496fc80ed36cb840beb29cf 100644 (file)
@@ -2711,10 +2711,11 @@ void anv_DestroyBuffer(
 void
 anv_fill_buffer_surface_state(struct anv_device *device, struct anv_state state,
                               enum isl_format format,
-                              uint32_t offset, uint32_t range, uint32_t stride)
+                              struct anv_address address,
+                              uint32_t range, uint32_t stride)
 {
    isl_buffer_fill_state(&device->isl_dev, state.map,
-                         .address = offset,
+                         .address = anv_address_physical(address),
                          .mocs = device->default_mocs,
                          .size = range,
                          .format = format,
index 52882080fd09305c275a802e62bfca0cf659f6aa..090d0615e41e311806d4453b89ab4403e0375aca 100644 (file)
@@ -1467,18 +1467,21 @@ anv_CreateBufferView(VkDevice _device,
                                      VK_IMAGE_ASPECT_COLOR_BIT,
                                      VK_IMAGE_TILING_LINEAR);
    const uint32_t format_bs = isl_format_get_layout(view->format)->bpb / 8;
-   view->bo = buffer->bo;
-   view->offset = buffer->offset + pCreateInfo->offset;
    view->range = anv_buffer_get_range(buffer, pCreateInfo->offset,
                                               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,
+   };
+
    if (buffer->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) {
       view->surface_state = alloc_surface_state(device);
 
       anv_fill_buffer_surface_state(device, view->surface_state,
                                     view->format,
-                                    view->offset, view->range, format_bs);
+                                    view->address, view->range, format_bs);
    } else {
       view->surface_state = (struct anv_state){ 0 };
    }
@@ -1495,14 +1498,14 @@ anv_CreateBufferView(VkDevice _device,
 
       anv_fill_buffer_surface_state(device, view->storage_surface_state,
                                     storage_format,
-                                    view->offset, view->range,
+                                    view->address, view->range,
                                     (storage_format == ISL_FORMAT_RAW ? 1 :
                                      isl_format_get_layout(storage_format)->bpb / 8));
 
       /* Write-only accesses should use the original format. */
       anv_fill_buffer_surface_state(device, view->writeonly_storage_surface_state,
                                     view->format,
-                                    view->offset, view->range,
+                                    view->address, view->range,
                                     isl_format_get_layout(view->format)->bpb / 8);
 
       isl_buffer_fill_image_param(&device->isl_dev,
index a18a1d1bede5384e11beec85165a3f02f2fc78e8..95d3e4d0936876935d466d7fe60bef0a81769afe 100644 (file)
@@ -1388,10 +1388,10 @@ struct anv_descriptor_set {
 
 struct anv_buffer_view {
    enum isl_format format; /**< VkBufferViewCreateInfo::format */
-   struct anv_bo *bo;
-   uint32_t offset; /**< Offset into bo. */
    uint64_t range; /**< VkBufferViewCreateInfo::range */
 
+   struct anv_address address;
+
    struct anv_state surface_state;
    struct anv_state storage_surface_state;
    struct anv_state writeonly_storage_surface_state;
@@ -2993,8 +2993,8 @@ anv_sanitize_image_offset(const VkImageType imageType,
 void anv_fill_buffer_surface_state(struct anv_device *device,
                                    struct anv_state state,
                                    enum isl_format format,
-                                   uint32_t offset, uint32_t range,
-                                   uint32_t stride);
+                                   struct anv_address address,
+                                   uint32_t range, uint32_t stride);
 
 static inline void
 anv_clear_color_from_att_state(union isl_color_value *clear_color,
index ad792658a83b56519c2b9ee9e9b63a547d0cfd44..97fb8ea30bc998dfcedcffcb7cfee935adc3acea 100644 (file)
@@ -1978,7 +1978,9 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
       const enum isl_format format =
          anv_isl_format_for_descriptor_type(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
       anv_fill_buffer_surface_state(cmd_buffer->device, surface_state,
-                                    format, bo_offset, 12, 1);
+                                    format,
+                                    cmd_buffer->state.compute.num_workgroups,
+                                    12, 1);
 
       bt_map[0] = surface_state.offset + state_offset;
       add_surface_state_reloc(cmd_buffer, surface_state, bo, bo_offset);
@@ -2095,8 +2097,8 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
          surface_state = desc->buffer_view->surface_state;
          assert(surface_state.alloc_size);
          add_surface_state_reloc(cmd_buffer, surface_state,
-                                 desc->buffer_view->bo,
-                                 desc->buffer_view->offset);
+                                 desc->buffer_view->address.bo,
+                                 desc->buffer_view->address.offset);
          break;
 
       case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
@@ -2110,16 +2112,20 @@ 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,
+         };
+
          surface_state =
             anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
          enum isl_format format =
             anv_isl_format_for_descriptor_type(desc->type);
 
          anv_fill_buffer_surface_state(cmd_buffer->device, surface_state,
-                                       format, offset, range, 1);
+                                       format, address, range, 1);
          add_surface_state_reloc(cmd_buffer, surface_state,
-                                 desc->buffer->bo,
-                                 desc->buffer->offset + offset);
+                                 address.bo, address.offset);
          break;
       }
 
@@ -2129,8 +2135,8 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
             : desc->buffer_view->storage_surface_state;
          assert(surface_state.alloc_size);
          add_surface_state_reloc(cmd_buffer, surface_state,
-                                 desc->buffer_view->bo,
-                                 desc->buffer_view->offset);
+                                 desc->buffer_view->address.bo,
+                                 desc->buffer_view->address.offset);
 
          struct brw_image_param *image_param =
             &cmd_buffer->state.push_constants[stage]->images[image++];
@@ -2389,11 +2395,8 @@ cmd_buffer_flush_push_constants(struct anv_cmd_buffer *cmd_buffer,
                if (desc->type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) {
                   read_len = MIN2(range->length,
                      DIV_ROUND_UP(desc->buffer_view->range, 32) - range->start);
-                  read_addr = (struct anv_address) {
-                     .bo = desc->buffer_view->bo,
-                     .offset = desc->buffer_view->offset +
-                               range->start * 32,
-                  };
+                  read_addr = anv_address_add(desc->buffer_view->address,
+                                              range->start * 32);
                } else {
                   assert(desc->type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC);