+ wsi_destroy_image(&chain->base, &image->base);
+}
+
+static void
+wsi_x11_get_dri3_modifiers(struct wsi_x11_connection *wsi_conn,
+ xcb_connection_t *conn, xcb_window_t window,
+ uint8_t depth, uint8_t bpp,
+ VkCompositeAlphaFlagsKHR vk_alpha,
+ uint64_t **modifiers_in, uint32_t *num_modifiers_in,
+ uint32_t *num_tranches_in,
+ const VkAllocationCallbacks *pAllocator)
+{
+ if (!wsi_conn->has_dri3_modifiers)
+ goto out;
+
+#ifdef HAVE_DRI3_MODIFIERS
+ xcb_generic_error_t *error = NULL;
+ xcb_dri3_get_supported_modifiers_cookie_t mod_cookie =
+ xcb_dri3_get_supported_modifiers(conn, window, depth, bpp);
+ xcb_dri3_get_supported_modifiers_reply_t *mod_reply =
+ xcb_dri3_get_supported_modifiers_reply(conn, mod_cookie, &error);
+ free(error);
+
+ if (!mod_reply || (mod_reply->num_window_modifiers == 0 &&
+ mod_reply->num_screen_modifiers == 0)) {
+ free(mod_reply);
+ goto out;
+ }
+
+ uint32_t n = 0;
+ uint32_t counts[2];
+ uint64_t *modifiers[2];
+
+ if (mod_reply->num_window_modifiers) {
+ counts[n] = mod_reply->num_window_modifiers;
+ modifiers[n] = vk_alloc(pAllocator,
+ counts[n] * sizeof(uint64_t),
+ 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (!modifiers[n]) {
+ free(mod_reply);
+ goto out;
+ }
+
+ memcpy(modifiers[n],
+ xcb_dri3_get_supported_modifiers_window_modifiers(mod_reply),
+ counts[n] * sizeof(uint64_t));
+ n++;
+ }
+
+ if (mod_reply->num_screen_modifiers) {
+ counts[n] = mod_reply->num_screen_modifiers;
+ modifiers[n] = vk_alloc(pAllocator,
+ counts[n] * sizeof(uint64_t),
+ 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (!modifiers[n]) {
+ if (n > 0)
+ vk_free(pAllocator, modifiers[0]);
+ free(mod_reply);
+ goto out;
+ }
+
+ memcpy(modifiers[n],
+ xcb_dri3_get_supported_modifiers_screen_modifiers(mod_reply),
+ counts[n] * sizeof(uint64_t));
+ n++;
+ }
+
+ for (int i = 0; i < n; i++) {
+ modifiers_in[i] = modifiers[i];
+ num_modifiers_in[i] = counts[i];