From: Jason Ekstrand Date: Wed, 30 Mar 2016 20:47:41 +0000 (-0700) Subject: anv/blit2d: Enhance teardown and clean up init error paths X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=00e70868ee81f964bbdb33b40938eec7e4bef1f3;p=mesa.git anv/blit2d: Enhance teardown and clean up init error paths Reviewed-by: Nanley Chery --- diff --git a/src/intel/vulkan/anv_meta_blit2d.c b/src/intel/vulkan/anv_meta_blit2d.c index 7424a00b7f2..3dc0c66d1cc 100644 --- a/src/intel/vulkan/anv_meta_blit2d.c +++ b/src/intel/vulkan/anv_meta_blit2d.c @@ -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; }