v3dv: ref pipeline layout earlier during pipeline init
authorIago Toral Quiroga <itoral@igalia.com>
Tue, 6 Sep 2022 05:55:22 +0000 (07:55 +0200)
committerMarge Bot <emma+marge@anholt.net>
Tue, 6 Sep 2022 09:58:15 +0000 (09:58 +0000)
If we fail to init the pipeline the callee will then destroy it
and if we had assigned the layout to the pipeline it will try to
unref it, so make sure we ref it right after assigning it.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7206
Fixes: dEQP-VK.api.object_management.alloc_callback_fail_multiple.graphics_pipeline
Fixes: 14dab6b10c ('v3dv: ref/unref pipeline layout objects')
Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18426>

src/broadcom/vulkan/v3dv_pipeline.c

index 763c97d..08bf637 100644 (file)
@@ -2928,6 +2928,7 @@ pipeline_init(struct v3dv_pipeline *pipeline,
 
    V3DV_FROM_HANDLE(v3dv_pipeline_layout, layout, pCreateInfo->layout);
    pipeline->layout = layout;
+   v3dv_pipeline_layout_ref(pipeline->layout);
 
    V3DV_FROM_HANDLE(v3dv_render_pass, render_pass, pCreateInfo->renderPass);
    assert(pCreateInfo->subpass < render_pass->subpass_count);
@@ -3026,8 +3027,6 @@ pipeline_init(struct v3dv_pipeline *pipeline,
    /* This must be done after the pipeline has been compiled */
    pipeline_set_ez_state(pipeline, ds_info);
 
-   v3dv_pipeline_layout_ref(pipeline->layout);
-
    return result;
 }
 
@@ -3267,13 +3266,12 @@ compute_pipeline_init(struct v3dv_pipeline *pipeline,
 
    pipeline->device = device;
    pipeline->layout = layout;
+   v3dv_pipeline_layout_ref(pipeline->layout);
 
    VkResult result = pipeline_compile_compute(pipeline, cache, info, alloc);
    if (result != VK_SUCCESS)
       return result;
 
-   v3dv_pipeline_layout_ref(pipeline->layout);
-
    return result;
 }