vk/meta: Clean up temporary objects
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 9 Jun 2015 18:08:51 +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/meta.c
src/vulkan/private.h

index acb0822c3dfed09598698b5c463b99ab06df3ee9..d6bd78999191177fe65c67011a1dcca28431ebf5 100644 (file)
@@ -410,6 +410,7 @@ VkResult anv_DestroyDevice(
 
    anv_compiler_destroy(device->compiler);
 
+   anv_device_finish_meta(device);
 
    anv_bo_pool_finish(&device->batch_bo_pool);
    anv_block_pool_finish(&device->dynamic_state_block_pool);
index 285c0202dee668133e4e673375d3e29d4c5541f6..2167d29da6a5c476c4ea46a9c0ace88735cd34d1 100644 (file)
@@ -411,15 +411,13 @@ anv_device_init_meta_blit_state(struct anv_device *device)
    anv_CreateDescriptorSetLayout((VkDevice) device, &ds_layout_info,
                                  &device->meta_state.blit.ds_layout);
 
-   VkPipelineLayoutCreateInfo pipeline_layout_info = {
-      .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
-      .descriptorSetCount = 1,
-      .pSetLayouts = &device->meta_state.blit.ds_layout,
-   };
-
-   VkPipelineLayout pipeline_layout;
-   anv_CreatePipelineLayout((VkDevice) device, &pipeline_layout_info,
-                            &pipeline_layout);
+   anv_CreatePipelineLayout((VkDevice) device,
+      &(VkPipelineLayoutCreateInfo) {
+         .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
+         .descriptorSetCount = 1,
+         .pSetLayouts = &device->meta_state.blit.ds_layout,
+      },
+      &device->meta_state.blit.pipeline_layout);
 
    VkPipelineRsStateCreateInfo rs_create_info = {
       .sType = VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
@@ -445,7 +443,7 @@ anv_device_init_meta_blit_state(struct anv_device *device)
       .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
       .pNext = &cb_create_info,
       .flags = 0,
-      .layout = pipeline_layout,
+      .layout = device->meta_state.blit.pipeline_layout,
    };
 
    anv_pipeline_create((VkDevice) device, &pipeline_info,
@@ -647,6 +645,14 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
    anv_CmdDraw((VkCmdBuffer) cmd_buffer, 0, 3, 0, 1);
 
    anv_CmdEndRenderPass((VkCmdBuffer) cmd_buffer, pass);
+
+   /* At the point where we emit the draw call, all data from the
+    * descriptor sets, etc. has been used.  We are free to delete it.
+    */
+   anv_DestroyObject((VkDevice) device, VK_OBJECT_TYPE_DESCRIPTOR_SET, set);
+   anv_DestroyObject((VkDevice) device, VK_OBJECT_TYPE_FRAMEBUFFER,
+                     (VkFramebuffer) fb);
+   anv_DestroyObject((VkDevice) device, VK_OBJECT_TYPE_RENDER_PASS, pass);
 }
 
 static void
@@ -756,6 +762,9 @@ do_buffer_copy(struct anv_cmd_buffer *cmd_buffer,
                   &dest_view,
                   (VkOffset3D) { 0, 0, 0 },
                   (VkExtent3D) { width, height, 1 });
+
+   anv_DestroyObject(vk_device, VK_OBJECT_TYPE_IMAGE, (VkImage) src_image);
+   anv_DestroyObject(vk_device, VK_OBJECT_TYPE_IMAGE, (VkImage) dest_image);
 }
 
 void anv_CmdCopyBuffer(
@@ -1049,6 +1058,8 @@ void anv_CmdCopyBufferToImage(
                      &dest_view,
                      pRegions[r].imageOffset,
                      pRegions[r].imageExtent);
+
+      anv_DestroyObject(vk_device, VK_OBJECT_TYPE_IMAGE, (VkImage) src_image);
    }
 
    meta_finish_blit(cmd_buffer, &saved_state);
@@ -1139,6 +1150,8 @@ void anv_CmdCopyImageToBuffer(
                      &dest_view,
                      (VkOffset3D) { 0, 0, 0 },
                      pRegions[r].imageExtent);
+
+      anv_DestroyObject(vk_device, VK_OBJECT_TYPE_IMAGE, (VkImage) dest_image);
    }
 
    meta_finish_blit(cmd_buffer, &saved_state);
@@ -1233,3 +1246,27 @@ anv_device_init_meta(struct anv_device *device)
       },
       &device->meta_state.shared.ds_state);
 }
+
+void
+anv_device_finish_meta(struct anv_device *device)
+{
+   /* Clear */
+   anv_DestroyObject((VkDevice) device, VK_OBJECT_TYPE_PIPELINE,
+                     device->meta_state.clear.pipeline);
+
+   /* Blit */
+   anv_DestroyObject((VkDevice) device, VK_OBJECT_TYPE_PIPELINE,
+                     device->meta_state.blit.pipeline);
+   anv_DestroyObject((VkDevice) device, VK_OBJECT_TYPE_PIPELINE_LAYOUT,
+                     device->meta_state.blit.pipeline_layout);
+   anv_DestroyObject((VkDevice) device, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT,
+                     device->meta_state.blit.ds_layout);
+
+   /* Shared */
+   anv_DestroyObject((VkDevice) device, VK_OBJECT_TYPE_DYNAMIC_RS_STATE,
+                     device->meta_state.shared.rs_state);
+   anv_DestroyObject((VkDevice) device, VK_OBJECT_TYPE_DYNAMIC_CB_STATE,
+                     device->meta_state.shared.cb_state);
+   anv_DestroyObject((VkDevice) device, VK_OBJECT_TYPE_DYNAMIC_DS_STATE,
+                     device->meta_state.shared.ds_state);
+}
index 05016d21792e94f4d8ac6cc0db1920a430b2ccad..873efaa48f511a9d9ed851910d830dab428bc684 100644 (file)
@@ -302,6 +302,7 @@ struct anv_meta_state {
 
    struct {
       VkPipeline                                pipeline;
+      VkPipelineLayout                          pipeline_layout;
       VkDescriptorSetLayout                     ds_layout;
    } blit;
 
@@ -832,6 +833,7 @@ struct anv_render_pass {
 };
 
 void anv_device_init_meta(struct anv_device *device);
+void anv_device_finish_meta(struct anv_device *device);
 
 void
 anv_cmd_buffer_clear(struct anv_cmd_buffer *cmd_buffer,