vk: Drop anv_surface_view
authorChad Versace <chad.versace@intel.com>
Mon, 5 Oct 2015 23:24:53 +0000 (16:24 -0700)
committerChad Versace <chad.versace@intel.com>
Tue, 6 Oct 2015 00:46:04 +0000 (17:46 -0700)
Push the members of struct anv_surface_view into anv_image_view and
anv_buffer_view, then remove struct anv_surface_view. Observe that
anv_surface_view::range is not needed for anv_image_view, and so was
dropped there.

This prepares for the merge of VkAttachmentView into VkImageView. Remove
the common parent of anv_buffer_view and anv_image_view (that is,
anv_surface_view) will make the merge easier.

src/vulkan/anv_cmd_buffer.c
src/vulkan/anv_device.c
src/vulkan/anv_image.c
src/vulkan/anv_meta.c
src/vulkan/anv_private.h
src/vulkan/gen7_state.c
src/vulkan/gen8_state.c

index 50f8304f9b3e5ad9d7eb33574bd55bc039045a44..008eeed40d67dadb36d8a86ba45fd79603925ce9 100644 (file)
@@ -440,11 +440,11 @@ anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
       const struct anv_color_attachment_view *cview =
          (const struct anv_color_attachment_view *) aview;
 
-      const struct anv_surface_view *sview = &cview->surface_view;
+      const struct anv_image_view *iview = &cview->image_view;
 
-      bt_map[a] = sview->surface_state.offset + state_offset;
-      add_surface_state_reloc(cmd_buffer, sview->surface_state,
-                              sview->bo, sview->offset);
+      bt_map[a] = iview->surface_state.offset + state_offset;
+      add_surface_state_reloc(cmd_buffer, iview->surface_state,
+                              iview->bo, iview->offset);
    }
 
    if (layout == NULL)
@@ -462,14 +462,28 @@ anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
          struct anv_descriptor *desc =
             &d->set->descriptors[surface_slots[b].index];
 
-         if (desc->type != ANV_DESCRIPTOR_TYPE_SURFACE_VIEW)
-            continue;
+         const struct anv_state *surface_state;
+         struct anv_bo *bo;
+         uint32_t bo_offset;
 
-         const struct anv_surface_view *sview = desc->surface_view;
+         switch (desc->type) {
+         case ANV_DESCRIPTOR_TYPE_EMPTY:
+         case ANV_DESCRIPTOR_TYPE_SAMPLER:
+            continue;
+         case ANV_DESCRIPTOR_TYPE_BUFFER_VIEW:
+            surface_state = &desc->buffer_view->surface_state;
+            bo = desc->buffer_view->bo;
+            bo_offset = desc->buffer_view->offset;
+            break;
+         case ANV_DESCRIPTOR_TYPE_IMAGE_VIEW:
+            surface_state = &desc->image_view->surface_state;
+            bo = desc->image_view->bo;
+            bo_offset = desc->image_view->offset;
+            break;
+         }
 
-         bt_map[start + b] = sview->surface_state.offset + state_offset;
-         add_surface_state_reloc(cmd_buffer, sview->surface_state,
-                                 sview->bo, sview->offset);
+         bt_map[start + b] = surface_state->offset + state_offset;
+         add_surface_state_reloc(cmd_buffer, *surface_state, bo, bo_offset);
       }
    }
 
index b2c8027fcf93bc2341cef65198c569ea2eb51d18..5302ee5cd7316a5d1b670265ac6599d508b372fa 100644 (file)
@@ -1408,7 +1408,7 @@ anv_buffer_view_create(
    if (bview == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   bview->surface_view = (struct anv_surface_view) {
+   *bview = (struct anv_buffer_view) {
       .bo = buffer->bo,
       .offset = buffer->offset + pCreateInfo->offset,
       .surface_state = anv_state_pool_alloc(&device->surface_state_pool, 64, 64),
@@ -1428,7 +1428,7 @@ VkResult anv_DestroyBufferView(
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_buffer_view, bview, _bview);
 
-   anv_surface_view_fini(device, &bview->surface_view);
+   anv_state_pool_free(&device->surface_state_pool, bview->surface_state);
    anv_device_free(device, bview);
 
    return VK_SUCCESS;
@@ -1754,8 +1754,8 @@ VkResult anv_UpdateDescriptorSets(
                             write->pDescriptors[j].imageView);
 
             set->descriptors[write->destBinding + j] = (struct anv_descriptor) {
-               .type = ANV_DESCRIPTOR_TYPE_SURFACE_VIEW,
-               .surface_view = &iview->surface_view,
+               .type = ANV_DESCRIPTOR_TYPE_IMAGE_VIEW,
+               .image_view = iview,
             };
          }
          break;
@@ -1778,8 +1778,8 @@ VkResult anv_UpdateDescriptorSets(
                             write->pDescriptors[j].bufferView);
 
             set->descriptors[write->destBinding + j] = (struct anv_descriptor) {
-               .type = ANV_DESCRIPTOR_TYPE_SURFACE_VIEW,
-               .surface_view = &bview->surface_view,
+               .type = ANV_DESCRIPTOR_TYPE_BUFFER_VIEW,
+               .buffer_view = bview,
             };
          }
 
index 1900432029828e52176ceed0cf5936cb8a83ba42..75233d1fe61500ef61a946f7a44359b8837b6012 100644 (file)
@@ -372,13 +372,6 @@ VkResult anv_GetImageSubresourceLayout(
    stub_return(VK_UNSUPPORTED);
 }
 
-void
-anv_surface_view_fini(struct anv_device *device,
-                      struct anv_surface_view *sview)
-{
-   anv_state_pool_free(&device->surface_state_pool, sview->surface_state);
-}
-
 VkResult
 anv_validate_CreateImageView(VkDevice _device,
                              const VkImageViewCreateInfo *pCreateInfo,
@@ -499,13 +492,20 @@ anv_CreateImageView(VkDevice _device,
    return VK_SUCCESS;
 }
 
+static void
+anv_image_view_fini(struct anv_device *device,
+                    struct anv_image_view *iview)
+{
+   anv_state_pool_free(&device->surface_state_pool, iview->surface_state);
+}
+
 VkResult
 anv_DestroyImageView(VkDevice _device, VkImageView _iview)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_image_view, iview, _iview);
 
-   anv_surface_view_fini(device, &iview->surface_view);
+   anv_image_view_fini(device, iview);
    anv_device_free(device, iview);
 
    return VK_SUCCESS;
@@ -643,7 +643,7 @@ anv_DestroyAttachmentView(VkDevice _device, VkAttachmentView _aview)
       struct anv_color_attachment_view *cview =
          (struct anv_color_attachment_view *) aview;
 
-      anv_surface_view_fini(device, &cview->surface_view);
+      anv_image_view_fini(device, &cview->image_view);
    }
 
    anv_device_free(device, aview);
index fe235e23fb0262e8fb4f15666e105aeef65d1ae0..1574830e0b8fd98c2009f25403c6bd3a80cdf558 100644 (file)
@@ -739,7 +739,7 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
 {
    struct anv_device *device = cmd_buffer->device;
    struct anv_attachment_view *dest_aview = &dest_cview->attachment_view;
-   struct anv_surface_view *dest_sview = &dest_cview->surface_view;
+   struct anv_image_view *dest_iview = &dest_cview->image_view;
    VkDescriptorPool dummy_desc_pool = { .handle = 1 };
 
    struct blit_vb_data {
@@ -854,7 +854,7 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
          .attachmentCount = 1,
          .pAttachments = &(VkAttachmentDescription) {
             .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION,
-            .format = dest_sview->format->vk_format,
+            .format = dest_iview->format->vk_format,
             .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
             .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
             .initialLayout = VK_IMAGE_LAYOUT_GENERAL,
@@ -1561,7 +1561,7 @@ void anv_CmdClearColorImage(
                cmd_buffer);
 
             struct anv_attachment_view *aview = &cview.attachment_view;
-            struct anv_surface_view *sview = &cview.surface_view;
+            struct anv_image_view *iview = &cview.image_view;
 
             VkFramebuffer fb;
             anv_CreateFramebuffer(anv_device_to_handle(cmd_buffer->device),
@@ -1586,7 +1586,7 @@ void anv_CmdClearColorImage(
                   .attachmentCount = 1,
                   .pAttachments = &(VkAttachmentDescription) {
                      .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION,
-                     .format = sview->format->vk_format,
+                     .format = iview->format->vk_format,
                      .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
                      .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
                      .initialLayout = VK_IMAGE_LAYOUT_GENERAL,
index 09890730fd69e097e7f6b1236c515b788073cd05..8c4c9efdc6fd85ff20c2fd4d8fb2c0309d6c3cf2 100644 (file)
@@ -730,14 +730,16 @@ struct anv_descriptor_set_layout {
 
 enum anv_descriptor_type {
    ANV_DESCRIPTOR_TYPE_EMPTY = 0,
+   ANV_DESCRIPTOR_TYPE_BUFFER_VIEW,
+   ANV_DESCRIPTOR_TYPE_IMAGE_VIEW,
    ANV_DESCRIPTOR_TYPE_SAMPLER,
-   ANV_DESCRIPTOR_TYPE_SURFACE_VIEW,
 };
 
 struct anv_descriptor {
    union {
+      struct anv_buffer_view *buffer_view;
+      struct anv_image_view *image_view;
       struct anv_sampler *sampler;
-      struct anv_surface_view *surface_view;
    };
 
    enum anv_descriptor_type type;
@@ -1233,20 +1235,19 @@ struct anv_image {
    };
 };
 
-struct anv_surface_view {
+struct anv_buffer_view {
    struct anv_state surface_state; /**< RENDER_SURFACE_STATE */
    struct anv_bo *bo;
-   uint32_t offset; /**< VkBufferCreateInfo::offset */
-   uint32_t range; /**< VkBufferCreateInfo::range */
-   const struct anv_format *format; /**< VkBufferCreateInfo::format */
-};
-
-struct anv_buffer_view {
-   struct anv_surface_view surface_view;
+   uint32_t offset; /**< Offset into bo. */
+   uint32_t range; /**< VkBufferViewCreateInfo::range */
+   const struct anv_format *format; /**< VkBufferViewCreateInfo::format */
 };
 
 struct anv_image_view {
-   struct anv_surface_view surface_view;
+   struct anv_state surface_state; /**< RENDER_SURFACE_STATE */
+   struct anv_bo *bo;
+   uint32_t offset; /**< Offset into bo. */
+   const struct anv_format *format; /**< VkImageViewCreateInfo::format */
    VkExtent3D extent;
 };
 
@@ -1262,7 +1263,7 @@ struct anv_attachment_view {
 
 struct anv_color_attachment_view {
    struct anv_attachment_view attachment_view;
-   struct anv_surface_view surface_view;
+   struct anv_image_view image_view;
 };
 
 struct anv_depth_stencil_view {
@@ -1334,9 +1335,6 @@ void gen7_fill_buffer_surface_state(void *state, const struct anv_format *format
 void gen8_fill_buffer_surface_state(void *state, const struct anv_format *format,
                                     uint32_t offset, uint32_t range);
 
-void anv_surface_view_fini(struct anv_device *device,
-                           struct anv_surface_view *sview);
-
 struct anv_sampler {
    uint32_t state[4];
 };
index a782690718bbbd6f11dd6fc03b0e5e12974e8341..5031db5edea46537af0b83d4c549a3f22fda0a98 100644 (file)
@@ -75,9 +75,8 @@ VkResult gen7_CreateBufferView(
    const struct anv_format *format =
       anv_format_for_vk_format(pCreateInfo->format);
 
-   gen7_fill_buffer_surface_state(bview->surface_view.surface_state.map,
-                                  format, bview->surface_view.offset,
-                                  pCreateInfo->range);
+   gen7_fill_buffer_surface_state(bview->surface_state.map, format,
+                                  bview->offset, pCreateInfo->range);
 
    *pView = anv_buffer_view_to_handle(bview);
 
@@ -273,7 +272,6 @@ gen7_image_view_init(struct anv_image_view *iview,
    ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
 
    const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange;
-   struct anv_surface_view *sview = &iview->surface_view;
    struct anv_surface *surface =
       anv_image_get_surface_for_aspect_mask(image, range->aspectMask);
 
@@ -286,9 +284,9 @@ gen7_image_view_init(struct anv_image_view *iview,
    if (pCreateInfo->viewType != VK_IMAGE_VIEW_TYPE_2D)
       anv_finishme("non-2D image views");
 
-   sview->bo = image->bo;
-   sview->offset = image->offset + surface->offset;
-   sview->format = anv_format_for_vk_format(pCreateInfo->format);
+   iview->bo = image->bo;
+   iview->offset = image->offset + surface->offset;
+   iview->format = anv_format_for_vk_format(pCreateInfo->format);
 
    iview->extent = (VkExtent3D) {
       .width = anv_minify(image->extent.width, range->baseMipLevel),
@@ -346,18 +344,18 @@ gen7_image_view_init(struct anv_image_view *iview,
       .BlueClearColor = 0,
       .AlphaClearColor = 0,
       .ResourceMinLOD = 0.0,
-      .SurfaceBaseAddress = { NULL, sview->offset },
+      .SurfaceBaseAddress = { NULL, iview->offset },
    };
 
    if (cmd_buffer) {
-      sview->surface_state =
+      iview->surface_state =
          anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
    } else {
-      sview->surface_state =
+      iview->surface_state =
          anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
    }
 
-   GEN7_RENDER_SURFACE_STATE_pack(NULL, sview->surface_state.map,
+   GEN7_RENDER_SURFACE_STATE_pack(NULL, iview->surface_state.map,
                                   &surface_state);
 }
 
@@ -369,7 +367,7 @@ gen7_color_attachment_view_init(struct anv_color_attachment_view *cview,
 {
    ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
    struct anv_attachment_view *aview = &cview->attachment_view;
-   struct anv_surface_view *sview = &cview->surface_view;
+   struct anv_image_view *iview = &cview->image_view;
    struct anv_surface *surface =
       anv_image_get_surface_for_color_attachment(image);
 
@@ -379,9 +377,9 @@ gen7_color_attachment_view_init(struct anv_color_attachment_view *cview,
    anv_assert(pCreateInfo->mipLevel < image->levels);
    anv_assert(pCreateInfo->baseArraySlice + pCreateInfo->arraySize <= image->array_size);
 
-   sview->bo = image->bo;
-   sview->offset = image->offset + surface->offset;
-   sview->format = anv_format_for_vk_format(pCreateInfo->format);
+   iview->bo = image->bo;
+   iview->offset = image->offset + surface->offset;
+   iview->format = anv_format_for_vk_format(pCreateInfo->format);
 
    aview->extent = (VkExtent3D) {
       .width = anv_minify(image->extent.width, pCreateInfo->mipLevel),
@@ -397,17 +395,17 @@ gen7_color_attachment_view_init(struct anv_color_attachment_view *cview,
    }
 
    if (cmd_buffer) {
-      sview->surface_state =
+      iview->surface_state =
          anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
    } else {
-      sview->surface_state =
+      iview->surface_state =
          anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
    }
 
    struct GEN7_RENDER_SURFACE_STATE surface_state = {
       .SurfaceType = SURFTYPE_2D,
       .SurfaceArray = image->array_size > 1,
-      .SurfaceFormat = sview->format->surface_format,
+      .SurfaceFormat = iview->format->surface_format,
       .SurfaceVerticalAlignment = anv_valign[surface->v_align],
       .SurfaceHorizontalAlignment = anv_halign[surface->h_align],
 
@@ -447,10 +445,10 @@ gen7_color_attachment_view_init(struct anv_color_attachment_view *cview,
       .BlueClearColor = 0,
       .AlphaClearColor = 0,
       .ResourceMinLOD = 0.0,
-      .SurfaceBaseAddress = { NULL, sview->offset },
+      .SurfaceBaseAddress = { NULL, iview->offset },
 
    };
 
-   GEN7_RENDER_SURFACE_STATE_pack(NULL, sview->surface_state.map,
+   GEN7_RENDER_SURFACE_STATE_pack(NULL, iview->surface_state.map,
                                   &surface_state);
 }
index c47d317d2a36e91f7f1b7ffc1611468cc2813935..2b820a3177d78cc95785724103a5627421ca2e7c 100644 (file)
@@ -119,9 +119,8 @@ VkResult gen8_CreateBufferView(
    const struct anv_format *format =
       anv_format_for_vk_format(pCreateInfo->format);
 
-   gen8_fill_buffer_surface_state(bview->surface_view.surface_state.map,
-                                  format, bview->surface_view.offset,
-                                  pCreateInfo->range);
+   gen8_fill_buffer_surface_state(bview->surface_state.map, format,
+                                  bview->offset, pCreateInfo->range);
 
    *pView = anv_buffer_view_to_handle(bview);
 
@@ -149,7 +148,6 @@ gen8_image_view_init(struct anv_image_view *iview,
    ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
 
    const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange;
-   struct anv_surface_view *sview = &iview->surface_view;
    struct anv_surface *surface =
       anv_image_get_surface_for_aspect_mask(image, range->aspectMask);
 
@@ -162,9 +160,9 @@ gen8_image_view_init(struct anv_image_view *iview,
    const struct anv_image_view_info view_type_info =
       anv_image_view_info_for_vk_image_view_type(pCreateInfo->viewType);
 
-   sview->bo = image->bo;
-   sview->offset = image->offset + surface->offset;
-   sview->format = format_info;
+   iview->bo = image->bo;
+   iview->offset = image->offset + surface->offset;
+   iview->format = format_info;
 
    iview->extent = (VkExtent3D) {
       .width = anv_minify(image->extent.width, range->baseMipLevel),
@@ -267,18 +265,18 @@ gen8_image_view_init(struct anv_image_view *iview,
       .ShaderChannelSelectBlue = vk_to_gen_swizzle[pCreateInfo->channels.b],
       .ShaderChannelSelectAlpha = vk_to_gen_swizzle[pCreateInfo->channels.a],
       .ResourceMinLOD = 0.0,
-      .SurfaceBaseAddress = { NULL, sview->offset },
+      .SurfaceBaseAddress = { NULL, iview->offset },
    };
 
    if (cmd_buffer) {
-      sview->surface_state =
+      iview->surface_state =
          anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
    } else {
-      sview->surface_state =
+      iview->surface_state =
          anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
    }
 
-   GEN8_RENDER_SURFACE_STATE_pack(NULL, sview->surface_state.map,
+   GEN8_RENDER_SURFACE_STATE_pack(NULL, iview->surface_state.map,
                                   &surface_state);
 }
 
@@ -290,7 +288,7 @@ gen8_color_attachment_view_init(struct anv_color_attachment_view *cview,
 {
    ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
    struct anv_attachment_view *aview = &cview->attachment_view;
-   struct anv_surface_view *sview = &cview->surface_view;
+   struct anv_image_view *iview = &cview->image_view;
    struct anv_surface *surface =
       anv_image_get_surface_for_color_attachment(image);
    const struct anv_format *format_info =
@@ -305,9 +303,9 @@ gen8_color_attachment_view_init(struct anv_color_attachment_view *cview,
    anv_assert(pCreateInfo->mipLevel < image->levels);
    anv_assert(pCreateInfo->baseArraySlice + pCreateInfo->arraySize <= image->array_size);
 
-   sview->bo = image->bo;
-   sview->offset = image->offset + surface->offset;
-   sview->format = anv_format_for_vk_format(pCreateInfo->format);
+   iview->bo = image->bo;
+   iview->offset = image->offset + surface->offset;
+   iview->format = anv_format_for_vk_format(pCreateInfo->format);
 
    aview->extent = (VkExtent3D) {
       .width = anv_minify(image->extent.width, pCreateInfo->mipLevel),
@@ -355,10 +353,10 @@ gen8_color_attachment_view_init(struct anv_color_attachment_view *cview,
    }
 
    if (cmd_buffer) {
-      sview->surface_state =
+      iview->surface_state =
          anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
    } else {
-      sview->surface_state =
+      iview->surface_state =
          anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
    }
 
@@ -411,10 +409,10 @@ gen8_color_attachment_view_init(struct anv_color_attachment_view *cview,
       .ShaderChannelSelectBlue = SCS_BLUE,
       .ShaderChannelSelectAlpha = SCS_ALPHA,
       .ResourceMinLOD = 0.0,
-      .SurfaceBaseAddress = { NULL, sview->offset },
+      .SurfaceBaseAddress = { NULL, iview->offset },
    };
 
-   GEN8_RENDER_SURFACE_STATE_pack(NULL, sview->surface_state.map,
+   GEN8_RENDER_SURFACE_STATE_pack(NULL, iview->surface_state.map,
                                   &surface_state);
 }