vulkan/wsi/headless: do not destroy images that are never created

Currently the image creation failure handling codepath of
wsi_headless_surface_create_swapchain() just calls
wsi_headless_swapchain_destroy() , which will try to destroy all
`image_count` of images. However, some of these images might never be
successfully created because of the failure, which leads to double-free.

Set image_count to the number of successfully created images before
calling wsi_headless_swapchin_destroy() to prevent over-destroying.

Fixes dEQP-VK.wsi.headless.swapchain.simulate_oom.* on lavapipe and pvr,
although some of the tests got QualityWarning saying "Creating swapchain
did not succeed, callback limit exceeded" on lavapipe (Pass on pvr).

Cc: mesa-stable
Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
Reviewed-by: Frank Binns <frank.binns@imgtec.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39039>
This commit is contained in:
Icenowy Zheng 2025-12-19 23:52:33 +08:00 committed by Marge Bot
parent bb17ad3f08
commit e8c81652c9

View file

@ -406,8 +406,11 @@ wsi_headless_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
for (uint32_t i = 0; i < chain->base.image_count; i++) {
result = wsi_create_image(&chain->base, &chain->base.image_info,
&chain->images[i].base);
if (result != VK_SUCCESS)
if (result != VK_SUCCESS) {
/* Record how many images need to be torn down */
chain->base.image_count = i;
goto fail;
}
chain->images[i].busy_on_host = false;
chain->images[i].busy_on_device = false;