vk/surface_view: Add a destructor
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 9 Jun 2015 18:08:03 +0000 (11:08 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 9 Jun 2015 19:36:23 +0000 (12:36 -0700)
src/vulkan/device.c
src/vulkan/image.c
src/vulkan/private.h

index 46c6b10c401db5fe07dd796eec57ae65c9cd88db..acb0822c3dfed09598698b5c463b99ab06df3ee9 100644 (file)
@@ -1080,10 +1080,7 @@ VkResult anv_DestroyObject(
       return VK_SUCCESS;
 
    case VK_OBJECT_TYPE_BUFFER:
-   case VK_OBJECT_TYPE_BUFFER_VIEW:
    case VK_OBJECT_TYPE_IMAGE:
-   case VK_OBJECT_TYPE_IMAGE_VIEW:
-   case VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW:
    case VK_OBJECT_TYPE_DEPTH_STENCIL_VIEW:
    case VK_OBJECT_TYPE_SHADER:
    case VK_OBJECT_TYPE_PIPELINE_LAYOUT:
@@ -1104,6 +1101,9 @@ VkResult anv_DestroyObject(
    case VK_OBJECT_TYPE_FENCE:
    case VK_OBJECT_TYPE_QUERY_POOL:
    case VK_OBJECT_TYPE_FRAMEBUFFER:
+   case VK_OBJECT_TYPE_BUFFER_VIEW:
+   case VK_OBJECT_TYPE_IMAGE_VIEW:
+   case VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW:
       (object->destructor)(device, object, objType);
       return VK_SUCCESS;
 
@@ -1542,6 +1542,8 @@ VkResult anv_CreateBufferView(
    if (view == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
+   view->base.destructor = anv_surface_view_destroy;
+
    view->bo = buffer->bo;
    view->offset = buffer->offset + pCreateInfo->offset;
    view->surface_state =
index 529f7ad977499b0dc45f954134e413c073130d63..83f4a1bf0cbd0166da2f23b5618d4b84b1da0ff1 100644 (file)
@@ -162,6 +162,21 @@ VkResult anv_GetImageSubresourceInfo(
    stub_return(VK_UNSUPPORTED);
 }
 
+void
+anv_surface_view_destroy(struct anv_device *device,
+                         struct anv_object *obj, VkObjectType obj_type)
+{
+   struct anv_surface_view *view = (struct anv_surface_view *)obj;
+
+   assert(obj_type == VK_OBJECT_TYPE_BUFFER_VIEW ||
+          obj_type == VK_OBJECT_TYPE_IMAGE_VIEW ||
+          obj_type == VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW);
+
+   anv_state_pool_free(&device->surface_state_pool, view->surface_state);
+
+   anv_device_free(device, view);
+}
+
 void
 anv_image_view_init(struct anv_surface_view *view,
                     struct anv_device *device,
@@ -268,6 +283,8 @@ VkResult anv_CreateImageView(
 
    anv_image_view_init(view, device, pCreateInfo, NULL);
 
+   view->base.destructor = anv_surface_view_destroy;
+
    *pView = (VkImageView) view;
 
    return VK_SUCCESS;
@@ -352,6 +369,8 @@ VkResult anv_CreateColorAttachmentView(
 
    anv_color_attachment_view_init(view, device, pCreateInfo, NULL);
 
+   view->base.destructor = anv_surface_view_destroy;
+
    *pView = (VkColorAttachmentView) view;
 
    return VK_SUCCESS;
index 794449c27c66a77c2f580f06297e7058bf8c9e08..05016d21792e94f4d8ac6cc0db1920a430b2ccad 100644 (file)
@@ -756,6 +756,8 @@ struct anv_image {
 };
 
 struct anv_surface_view {
+   struct anv_object                            base;
+
    struct anv_state                             surface_state;
    struct anv_bo *                              bo;
    uint32_t                                     offset;
@@ -783,6 +785,9 @@ void anv_color_attachment_view_init(struct anv_surface_view *view,
                                     const VkColorAttachmentViewCreateInfo* pCreateInfo,
                                     struct anv_cmd_buffer *cmd_buffer);
 
+void anv_surface_view_destroy(struct anv_device *device,
+                              struct anv_object *obj, VkObjectType obj_type);
+
 struct anv_sampler {
    uint32_t state[4];
 };