vk: Define struct anv_image_view, anv_buffer_view
authorChad Versace <chad.versace@intel.com>
Wed, 15 Jul 2015 19:00:27 +0000 (12:00 -0700)
committerChad Versace <chad.versace@intel.com>
Wed, 15 Jul 2015 19:19:29 +0000 (12:19 -0700)
Follow the pattern of anv_attachment_view. We need these structs to
implement the type-safety that arrived in the 0.132 header.

src/vulkan/device.c
src/vulkan/image.c
src/vulkan/meta.c
src/vulkan/private.h

index fd0b80d272b0583725e7f1e64d08cf650bcceb62..c59814fb4e611d2f505518be458d1261678acac2 100644 (file)
@@ -1722,15 +1722,17 @@ VkResult anv_CreateBufferView(
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
+   struct anv_buffer_view *bview;
    struct anv_surface_view *view;
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO);
 
-   view = anv_device_alloc(device, sizeof(*view), 8,
-                           VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-   if (view == NULL)
+   bview = anv_device_alloc(device, sizeof(*view), 8,
+                            VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
+   if (bview == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
+   view = &bview->view;
    view->bo = buffer->bo;
    view->offset = buffer->offset + pCreateInfo->offset;
    view->surface_state =
@@ -1741,20 +1743,20 @@ VkResult anv_CreateBufferView(
    fill_buffer_surface_state(view->surface_state.map,
                              pCreateInfo->format, view->offset, pCreateInfo->range);
 
-   *pView = (VkBufferView) view;
+   *pView = anv_buffer_view_to_handle(bview);
 
    return VK_SUCCESS;
 }
 
 VkResult anv_DestroyBufferView(
     VkDevice                                    _device,
-    VkBufferView                                _view)
+    VkBufferView                                _bview)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
-   struct anv_surface_view *view = (struct anv_surface_view *)_view;
+   ANV_FROM_HANDLE(anv_buffer_view, bview, _bview);
 
-   anv_surface_view_fini(device, view);
-   anv_device_free(device, view);
+   anv_surface_view_fini(device, &bview->view);
+   anv_device_free(device, bview);
 
    return VK_SUCCESS;
 }
@@ -2131,8 +2133,9 @@ VkResult anv_UpdateDescriptorSets(
       case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
       case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
          for (uint32_t j = 0; j < write->count; j++) {
-            set->descriptors[write->destBinding + j].view =
-               (struct anv_surface_view *)write->pDescriptors[j].imageView;
+            ANV_FROM_HANDLE(anv_image_view, iview,
+                            write->pDescriptors[j].imageView);
+            set->descriptors[write->destBinding + j].view = &iview->view;
          }
          break;
 
@@ -2150,8 +2153,9 @@ VkResult anv_UpdateDescriptorSets(
       case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
       case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
          for (uint32_t j = 0; j < write->count; j++) {
-            set->descriptors[write->destBinding + j].view =
-               (struct anv_surface_view *)write->pDescriptors[j].bufferView;
+            ANV_FROM_HANDLE(anv_buffer_view, bview,
+                            write->pDescriptors[j].bufferView);
+            set->descriptors[write->destBinding + j].view = &bview->view;
          }
 
       default:
index c29c6939ffbc1fe5a4ab1e083cdd05d926595bf7..d05f42667ea50fd7e7cd680919aab4c9914f29ba 100644 (file)
@@ -333,13 +333,15 @@ anv_surface_view_fini(struct anv_device *device,
 }
 
 void
-anv_image_view_init(struct anv_surface_view *view,
+anv_image_view_init(struct anv_image_view *iview,
                     struct anv_device *device,
                     const VkImageViewCreateInfo* pCreateInfo,
                     struct anv_cmd_buffer *cmd_buffer)
 {
    ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
+
    const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange;
+   struct anv_surface_view *view = &iview->view;
    struct anv_surface *surface;
 
    const struct anv_format *format_info =
@@ -537,7 +539,7 @@ anv_CreateImageView(VkDevice _device,
                     VkImageView *pView)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
-   struct anv_surface_view *view;
+   struct anv_image_view *view;
 
    view = anv_device_alloc(device, sizeof(*view), 8,
                            VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
@@ -546,19 +548,19 @@ anv_CreateImageView(VkDevice _device,
 
    anv_image_view_init(view, device, pCreateInfo, NULL);
 
-   *pView = (VkImageView) view;
+   *pView = anv_image_view_to_handle(view);
 
    return VK_SUCCESS;
 }
 
 VkResult
-anv_DestroyImageView(VkDevice _device, VkImageView _view)
+anv_DestroyImageView(VkDevice _device, VkImageView _iview)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
-   struct anv_surface_view *view = (struct anv_surface_view *)_view;
+   ANV_FROM_HANDLE(anv_image_view, iview, _iview);
 
-   anv_surface_view_fini(device, view);
-   anv_device_free(device, view);
+   anv_surface_view_fini(device, &iview->view);
+   anv_device_free(device, iview);
 
    return VK_SUCCESS;
 }
index bf8bb6f9d309a1a348e46b15571cc0631178a71d..c467b1961f6839660a25dbef6e4982e58d425b8a 100644 (file)
@@ -762,7 +762,7 @@ do_buffer_copy(struct anv_cmd_buffer *cmd_buffer,
    anv_image_from_handle(dest_image)->bo = dest;
    anv_image_from_handle(dest_image)->offset = dest_offset;
 
-   struct anv_surface_view src_view;
+   struct anv_image_view src_view;
    anv_image_view_init(&src_view, cmd_buffer->device,
       &(VkImageViewCreateInfo) {
          .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
@@ -798,7 +798,7 @@ do_buffer_copy(struct anv_cmd_buffer *cmd_buffer,
       cmd_buffer);
 
    meta_emit_blit(cmd_buffer,
-                  &src_view,
+                  &src_view.view,
                   (VkOffset3D) { 0, 0, 0 },
                   (VkExtent3D) { width, height, 1 },
                   &dest_view,
@@ -902,7 +902,7 @@ void anv_CmdCopyImage(
    meta_prepare_blit(cmd_buffer, &saved_state);
 
    for (unsigned r = 0; r < regionCount; r++) {
-      struct anv_surface_view src_view;
+      struct anv_image_view src_view;
       anv_image_view_init(&src_view, cmd_buffer->device,
          &(VkImageViewCreateInfo) {
             .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
@@ -938,7 +938,7 @@ void anv_CmdCopyImage(
          cmd_buffer);
 
       meta_emit_blit(cmd_buffer,
-                     &src_view,
+                     &src_view.view,
                      pRegions[r].srcOffset,
                      pRegions[r].extent,
                      &dest_view,
@@ -970,7 +970,7 @@ void anv_CmdBlitImage(
    meta_prepare_blit(cmd_buffer, &saved_state);
 
    for (unsigned r = 0; r < regionCount; r++) {
-      struct anv_surface_view src_view;
+      struct anv_image_view src_view;
       anv_image_view_init(&src_view, cmd_buffer->device,
          &(VkImageViewCreateInfo) {
             .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
@@ -1006,7 +1006,7 @@ void anv_CmdBlitImage(
          cmd_buffer);
 
       meta_emit_blit(cmd_buffer,
-                     &src_view,
+                     &src_view.view,
                      pRegions[r].srcOffset,
                      pRegions[r].srcExtent,
                      &dest_view,
@@ -1066,7 +1066,7 @@ void anv_CmdCopyBufferToImage(
       src_image->bo = src_buffer->bo;
       src_image->offset = src_buffer->offset + pRegions[r].bufferOffset;
 
-      struct anv_surface_view src_view;
+      struct anv_image_view src_view;
       anv_image_view_init(&src_view, cmd_buffer->device,
          &(VkImageViewCreateInfo) {
             .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
@@ -1102,7 +1102,7 @@ void anv_CmdCopyBufferToImage(
          cmd_buffer);
 
       meta_emit_blit(cmd_buffer,
-                     &src_view,
+                     &src_view.view,
                      (VkOffset3D) { 0, 0, 0 },
                      pRegions[r].imageExtent,
                      &dest_view,
@@ -1137,7 +1137,7 @@ void anv_CmdCopyImageToBuffer(
       if (pRegions[r].bufferImageHeight != 0)
          anv_finishme("bufferImageHeight not supported in CopyBufferToImage");
 
-      struct anv_surface_view src_view;
+      struct anv_image_view src_view;
       anv_image_view_init(&src_view, cmd_buffer->device,
          &(VkImageViewCreateInfo) {
             .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
@@ -1200,7 +1200,7 @@ void anv_CmdCopyImageToBuffer(
          cmd_buffer);
 
       meta_emit_blit(cmd_buffer,
-                     &src_view,
+                     &src_view.view,
                      pRegions[r].imageOffset,
                      pRegions[r].imageExtent,
                      &dest_view,
index c1f04dfbc19c198fcfb16421e34d219009a190c5..5693a80af3d0b127f57f6c192188e1db2c45a444 100644 (file)
@@ -854,6 +854,15 @@ struct anv_surface_view {
    VkFormat                                     format;
 };
 
+struct anv_buffer_view {
+   /* FINISHME: Trim unneeded data from this struct. */
+   struct anv_surface_view view;
+};
+
+struct anv_image_view {
+   struct anv_surface_view view;
+};
+
 enum anv_attachment_view_type {
    ANV_ATTACHMENT_VIEW_TYPE_COLOR,
    ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL,
@@ -894,7 +903,7 @@ VkResult anv_image_create(VkDevice _device,
                           const struct anv_image_create_info *info,
                           VkImage *pImage);
 
-void anv_image_view_init(struct anv_surface_view *view,
+void anv_image_view_init(struct anv_image_view *view,
                          struct anv_device *device,
                          const VkImageViewCreateInfo* pCreateInfo,
                          struct anv_cmd_buffer *cmd_buffer);
@@ -995,6 +1004,8 @@ ANV_DEFINE_CASTS(anv_pipeline, VkPipeline)
 ANV_DEFINE_CASTS(anv_image, VkImage)
 ANV_DEFINE_CASTS(anv_sampler, VkSampler)
 ANV_DEFINE_CASTS(anv_attachment_view, VkAttachmentView)
+ANV_DEFINE_CASTS(anv_buffer_view, VkBufferView);
+ANV_DEFINE_CASTS(anv_image_view, VkImageView);
 ANV_DEFINE_CASTS(anv_framebuffer, VkFramebuffer)
 ANV_DEFINE_CASTS(anv_render_pass, VkRenderPass)
 ANV_DEFINE_CASTS(anv_query_pool, VkQueryPool)