anv/blit2d: Enhance teardown and clean up init error paths
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 30 Mar 2016 20:47:41 +0000 (13:47 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 8 Apr 2016 22:57:45 +0000 (15:57 -0700)
Reviewed-by: Nanley Chery <nanley.g.chery@intel.com>
src/intel/vulkan/anv_meta_blit2d.c

index 7424a00b7f2d87b34902676e8e5160153c92c11e..3dc0c66d1cc853b35f2d10f4bd840d4af5bdf260 100644 (file)
@@ -461,18 +461,29 @@ build_nir_copy_fragment_shader(struct anv_device *device,
 void
 anv_device_finish_meta_blit2d_state(struct anv_device *device)
 {
-   anv_DestroyRenderPass(anv_device_to_handle(device),
-                         device->meta_state.blit2d.render_pass,
-                         &device->meta_state.alloc);
-   anv_DestroyPipeline(anv_device_to_handle(device),
-                       device->meta_state.blit2d.pipeline_2d_src,
-                       &device->meta_state.alloc);
-   anv_DestroyPipelineLayout(anv_device_to_handle(device),
-                             device->meta_state.blit2d.pipeline_layout,
-                             &device->meta_state.alloc);
-   anv_DestroyDescriptorSetLayout(anv_device_to_handle(device),
-                                  device->meta_state.blit2d.ds_layout,
-                                  &device->meta_state.alloc);
+   if (device->meta_state.blit2d.render_pass) {
+      anv_DestroyRenderPass(anv_device_to_handle(device),
+                            device->meta_state.blit2d.render_pass,
+                            &device->meta_state.alloc);
+   }
+
+   if (device->meta_state.blit2d.pipeline_2d_src) {
+      anv_DestroyPipeline(anv_device_to_handle(device),
+                          device->meta_state.blit2d.pipeline_2d_src,
+                          &device->meta_state.alloc);
+   }
+
+   if (device->meta_state.blit2d.pipeline_layout) {
+      anv_DestroyPipelineLayout(anv_device_to_handle(device),
+                                device->meta_state.blit2d.pipeline_layout,
+                                &device->meta_state.alloc);
+   }
+
+   if (device->meta_state.blit2d.ds_layout) {
+      anv_DestroyDescriptorSetLayout(anv_device_to_handle(device),
+                                     device->meta_state.blit2d.ds_layout,
+                                     &device->meta_state.alloc);
+   }
 }
 
 VkResult
@@ -480,6 +491,8 @@ anv_device_init_meta_blit2d_state(struct anv_device *device)
 {
    VkResult result;
 
+   zero(device->meta_state.blit2d);
+
    result = anv_CreateRenderPass(anv_device_to_handle(device),
       &(VkRenderPassCreateInfo) {
          .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
@@ -513,6 +526,33 @@ anv_device_init_meta_blit2d_state(struct anv_device *device)
    if (result != VK_SUCCESS)
       goto fail;
 
+   result = anv_CreateDescriptorSetLayout(anv_device_to_handle(device),
+      &(VkDescriptorSetLayoutCreateInfo) {
+         .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
+         .bindingCount = 1,
+         .pBindings = (VkDescriptorSetLayoutBinding[]) {
+            {
+               .binding = 0,
+               .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
+               .descriptorCount = 1,
+               .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
+               .pImmutableSamplers = NULL
+            },
+         }
+      }, &device->meta_state.alloc, &device->meta_state.blit2d.ds_layout);
+   if (result != VK_SUCCESS)
+      goto fail;
+
+   result = anv_CreatePipelineLayout(anv_device_to_handle(device),
+      &(VkPipelineLayoutCreateInfo) {
+         .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
+         .setLayoutCount = 1,
+         .pSetLayouts = &device->meta_state.blit2d.ds_layout,
+      },
+      &device->meta_state.alloc, &device->meta_state.blit2d.pipeline_layout);
+   if (result != VK_SUCCESS)
+      goto fail;
+
    /* We don't use a vertex shader for blitting, but instead build and pass
     * the VUEs directly to the rasterization backend.  However, we do need
     * to provide GLSL source for the vertex shader so that the compiler
@@ -567,36 +607,6 @@ anv_device_init_meta_blit2d_state(struct anv_device *device)
       }
    };
 
-   VkDescriptorSetLayoutCreateInfo ds_layout_info = {
-      .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
-      .bindingCount = 1,
-      .pBindings = (VkDescriptorSetLayoutBinding[]) {
-         {
-            .binding = 0,
-            .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
-            .descriptorCount = 1,
-            .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
-            .pImmutableSamplers = NULL
-         },
-      }
-   };
-   result = anv_CreateDescriptorSetLayout(anv_device_to_handle(device),
-                                          &ds_layout_info,
-                                          &device->meta_state.alloc,
-                                          &device->meta_state.blit2d.ds_layout);
-   if (result != VK_SUCCESS)
-      goto fail_render_pass;
-
-   result = anv_CreatePipelineLayout(anv_device_to_handle(device),
-      &(VkPipelineLayoutCreateInfo) {
-         .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
-         .setLayoutCount = 1,
-         .pSetLayouts = &device->meta_state.blit2d.ds_layout,
-      },
-      &device->meta_state.alloc, &device->meta_state.blit2d.pipeline_layout);
-   if (result != VK_SUCCESS)
-      goto fail_descriptor_set_layout;
-
    VkPipelineShaderStageCreateInfo pipeline_shader_stages[] = {
       {
          .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
@@ -687,29 +697,16 @@ anv_device_init_meta_blit2d_state(struct anv_device *device)
       VK_NULL_HANDLE,
       &vk_pipeline_info, &anv_pipeline_info,
       &device->meta_state.alloc, &device->meta_state.blit2d.pipeline_2d_src);
-   if (result != VK_SUCCESS)
-      goto fail_pipeline_layout;
 
    ralloc_free(vs.nir);
    ralloc_free(fs_2d.nir);
 
-   return VK_SUCCESS;
+   if (result != VK_SUCCESS)
+      goto fail;
 
- fail_pipeline_layout:
-   anv_DestroyPipelineLayout(anv_device_to_handle(device),
-                             device->meta_state.blit2d.pipeline_layout,
-                             &device->meta_state.alloc);
- fail_descriptor_set_layout:
-   anv_DestroyDescriptorSetLayout(anv_device_to_handle(device),
-                                  device->meta_state.blit2d.ds_layout,
-                                  &device->meta_state.alloc);
- fail_render_pass:
-   anv_DestroyRenderPass(anv_device_to_handle(device),
-                         device->meta_state.blit2d.render_pass,
-                         &device->meta_state.alloc);
+   return VK_SUCCESS;
 
-   ralloc_free(vs.nir);
-   ralloc_free(fs_2d.nir);
- fail:
+fail:
+   anv_device_finish_meta_blit2d_state(device);
    return result;
 }