wsi/x11: Do not use allocation callbacks on a thread.

This is banned by spec.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Cc: mesa-stable
(cherry picked from commit 81526187a8)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32730>
This commit is contained in:
Hans-Kristian Arntzen 2024-12-05 16:29:08 +01:00 committed by Dylan Baker
parent 7c44f03d7f
commit ee0d63011c
2 changed files with 14 additions and 3 deletions

View file

@ -324,7 +324,7 @@
"description": "wsi/x11: Do not use allocation callbacks on a thread.",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -240,6 +240,10 @@ wsi_x11_connection_create(struct wsi_device *wsi_dev,
bool has_dri3_v1_4 = false;
bool has_present_v1_4 = false;
/* wsi_x11_get_connection may be called from a thread, but we will never end up here on a worker thread,
* since the connection will always be in the hash-map,
* so we will not violate Vulkan's rule on allocation callbacks w.r.t.
* when it is allowed to call the allocation callbacks. */
struct wsi_x11_connection *wsi_conn =
vk_alloc(&wsi_dev->instance_alloc, sizeof(*wsi_conn), 8,
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
@ -2370,10 +2374,17 @@ wsi_x11_swapchain_query_dri3_modifiers_changed(struct x11_swapchain *chain)
.explicit_sync = chain->base.image_info.explicit_sync,
};
/* This is called from a thread, so we must not use an allocation callback from user.
* From spec:
* An implementation must only make calls into an application-provided allocator
* during the execution of an API command.
* An implementation must only make calls into an application-provided allocator
* from the same thread that called the provoking API command. */
wsi_x11_get_dri3_modifiers(wsi_conn, chain->conn, chain->window, bit_depth, 32,
modifiers, num_modifiers,
&drm_image_params.num_modifier_lists,
&wsi_device->instance_alloc);
vk_default_allocator());
drm_image_params.num_modifiers = num_modifiers;
drm_image_params.modifiers = (const uint64_t **)modifiers;
@ -2382,7 +2393,7 @@ wsi_x11_swapchain_query_dri3_modifiers_changed(struct x11_swapchain *chain)
wsi_x11_recompute_dri3_modifier_hash(&hash, &drm_image_params);
for (int i = 0; i < ARRAY_SIZE(modifiers); i++)
vk_free(&wsi_device->instance_alloc, modifiers[i]);
vk_free(vk_default_allocator(), modifiers[i]);
return memcmp(hash, chain->dri3_modifier_hash, sizeof(hash)) != 0;
}