Lines Matching full:chain
773 * the combined status. The chain status will eventually be returned from
781 _x11_swapchain_result(struct x11_swapchain *chain, VkResult result, in _x11_swapchain_result() argument
785 if (chain->status < 0) in _x11_swapchain_result()
786 return chain->status; in _x11_swapchain_result()
788 /* If we have a new error, mark it as permanent on the chain and return. */ in _x11_swapchain_result()
794 chain->status = result; in _x11_swapchain_result()
807 if (chain->status != VK_SUBOPTIMAL_KHR) { in _x11_swapchain_result()
812 chain->status = result; in _x11_swapchain_result()
817 return chain->status; in _x11_swapchain_result()
819 #define x11_swapchain_result(chain, result) \ argument
820 _x11_swapchain_result(chain, result, __FILE__, __LINE__)
825 struct x11_swapchain *chain = (struct x11_swapchain *)wsi_chain; in x11_get_wsi_image() local
826 return &chain->images[image_index].base; in x11_get_wsi_image()
830 * Process an X11 Present event. Does not update chain->status.
833 x11_handle_dri3_present_event(struct x11_swapchain *chain, in x11_handle_dri3_present_event() argument
840 if (config->width != chain->extent.width || in x11_handle_dri3_present_event()
841 config->height != chain->extent.height) in x11_handle_dri3_present_event()
850 for (unsigned i = 0; i < chain->base.image_count; i++) { in x11_handle_dri3_present_event()
851 if (chain->images[i].pixmap == idle->pixmap) { in x11_handle_dri3_present_event()
852 chain->images[i].busy = false; in x11_handle_dri3_present_event()
853 chain->sent_image_count--; in x11_handle_dri3_present_event()
854 assert(chain->sent_image_count >= 0); in x11_handle_dri3_present_event()
855 if (chain->has_acquire_queue) in x11_handle_dri3_present_event()
856 wsi_queue_push(&chain->acquire_queue, i); in x11_handle_dri3_present_event()
867 chain->last_present_msc = complete->msc; in x11_handle_dri3_present_event()
876 chain->last_present_mode != XCB_PRESENT_COMPLETE_MODE_SUBOPTIMAL_COPY) in x11_handle_dri3_present_event()
885 chain->last_present_mode == XCB_PRESENT_COMPLETE_MODE_FLIP) in x11_handle_dri3_present_event()
888 chain->last_present_mode = complete->mode; in x11_handle_dri3_present_event()
910 x11_acquire_next_image_poll_x11(struct x11_swapchain *chain, in x11_acquire_next_image_poll_x11() argument
917 for (uint32_t i = 0; i < chain->base.image_count; i++) { in x11_acquire_next_image_poll_x11()
918 if (!chain->images[i].busy) { in x11_acquire_next_image_poll_x11()
920 xshmfence_await(chain->images[i].shm_fence); in x11_acquire_next_image_poll_x11()
922 chain->images[i].busy = true; in x11_acquire_next_image_poll_x11()
923 return x11_swapchain_result(chain, VK_SUCCESS); in x11_acquire_next_image_poll_x11()
927 xcb_flush(chain->conn); in x11_acquire_next_image_poll_x11()
930 event = xcb_wait_for_special_event(chain->conn, chain->special_event); in x11_acquire_next_image_poll_x11()
932 return x11_swapchain_result(chain, VK_ERROR_OUT_OF_DATE_KHR); in x11_acquire_next_image_poll_x11()
934 event = xcb_poll_for_special_event(chain->conn, chain->special_event); in x11_acquire_next_image_poll_x11()
938 return x11_swapchain_result(chain, VK_NOT_READY); in x11_acquire_next_image_poll_x11()
942 pfds.fd = xcb_get_file_descriptor(chain->conn); in x11_acquire_next_image_poll_x11()
946 return x11_swapchain_result(chain, VK_TIMEOUT); in x11_acquire_next_image_poll_x11()
948 return x11_swapchain_result(chain, VK_ERROR_OUT_OF_DATE_KHR); in x11_acquire_next_image_poll_x11()
965 VkResult result = x11_handle_dri3_present_event(chain, (void *)event); in x11_acquire_next_image_poll_x11()
968 return x11_swapchain_result(chain, result); in x11_acquire_next_image_poll_x11()
973 x11_acquire_next_image_from_queue(struct x11_swapchain *chain, in x11_acquire_next_image_from_queue() argument
976 assert(chain->has_acquire_queue); in x11_acquire_next_image_from_queue()
979 VkResult result = wsi_queue_pull(&chain->acquire_queue, in x11_acquire_next_image_from_queue()
982 /* On error, the thread has shut down, so safe to update chain->status. in x11_acquire_next_image_from_queue()
984 * chain->status so that is also safe. in x11_acquire_next_image_from_queue()
986 return x11_swapchain_result(chain, result); in x11_acquire_next_image_from_queue()
987 } else if (chain->status < 0) { in x11_acquire_next_image_from_queue()
988 return chain->status; in x11_acquire_next_image_from_queue()
991 assert(image_index < chain->base.image_count); in x11_acquire_next_image_from_queue()
992 xshmfence_await(chain->images[image_index].shm_fence); in x11_acquire_next_image_from_queue()
996 return chain->status; in x11_acquire_next_image_from_queue()
1000 x11_present_to_x11_dri3(struct x11_swapchain *chain, uint32_t image_index, in x11_present_to_x11_dri3() argument
1003 struct x11_image *image = &chain->images[image_index]; in x11_present_to_x11_dri3()
1005 assert(image_index < chain->base.image_count); in x11_present_to_x11_dri3()
1012 if (chain->base.present_mode == VK_PRESENT_MODE_IMMEDIATE_KHR || in x11_present_to_x11_dri3()
1013 chain->base.present_mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR) in x11_present_to_x11_dri3()
1017 if (chain->has_dri3_modifiers) in x11_present_to_x11_dri3()
1026 while ((event = xcb_poll_for_special_event(chain->conn, chain->special_event))) { in x11_present_to_x11_dri3()
1027 VkResult result = x11_handle_dri3_present_event(chain, (void *)event); in x11_present_to_x11_dri3()
1030 return x11_swapchain_result(chain, result); in x11_present_to_x11_dri3()
1031 x11_swapchain_result(chain, result); in x11_present_to_x11_dri3()
1036 ++chain->sent_image_count; in x11_present_to_x11_dri3()
1037 assert(chain->sent_image_count <= chain->base.image_count); in x11_present_to_x11_dri3()
1039 ++chain->send_sbc; in x11_present_to_x11_dri3()
1042 xcb_present_pixmap(chain->conn, in x11_present_to_x11_dri3()
1043 chain->window, in x11_present_to_x11_dri3()
1045 (uint32_t) chain->send_sbc, in x11_present_to_x11_dri3()
1057 xcb_discard_reply(chain->conn, cookie.sequence); in x11_present_to_x11_dri3()
1059 xcb_flush(chain->conn); in x11_present_to_x11_dri3()
1061 return x11_swapchain_result(chain, VK_SUCCESS); in x11_present_to_x11_dri3()
1065 x11_present_to_x11_sw(struct x11_swapchain *chain, uint32_t image_index, in x11_present_to_x11_sw() argument
1068 struct x11_image *image = &chain->images[image_index]; in x11_present_to_x11_sw()
1072 chain->base.wsi->MapMemory(chain->base.device, in x11_present_to_x11_sw()
1076 cookie = xcb_put_image(chain->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, in x11_present_to_x11_sw()
1077 chain->window, in x11_present_to_x11_sw()
1078 chain->gc, in x11_present_to_x11_sw()
1080 chain->extent.height, in x11_present_to_x11_sw()
1082 image->base.row_pitches[0] * chain->extent.height, in x11_present_to_x11_sw()
1085 chain->base.wsi->UnmapMemory(chain->base.device, image->base.memory); in x11_present_to_x11_sw()
1086 xcb_discard_reply(chain->conn, cookie.sequence); in x11_present_to_x11_sw()
1087 xcb_flush(chain->conn); in x11_present_to_x11_sw()
1088 return x11_swapchain_result(chain, VK_SUCCESS); in x11_present_to_x11_sw()
1091 x11_present_to_x11(struct x11_swapchain *chain, uint32_t image_index, in x11_present_to_x11() argument
1094 if (chain->base.wsi->sw) in x11_present_to_x11()
1095 return x11_present_to_x11_sw(chain, image_index, target_msc); in x11_present_to_x11()
1096 return x11_present_to_x11_dri3(chain, image_index, target_msc); in x11_present_to_x11()
1104 struct x11_swapchain *chain = (struct x11_swapchain *)anv_chain; in x11_acquire_next_image() local
1108 if (chain->status < 0) in x11_acquire_next_image()
1109 return chain->status; in x11_acquire_next_image()
1111 if (chain->base.wsi->sw) { in x11_acquire_next_image()
1115 if (chain->has_acquire_queue) { in x11_acquire_next_image()
1116 return x11_acquire_next_image_from_queue(chain, image_index, timeout); in x11_acquire_next_image()
1118 return x11_acquire_next_image_poll_x11(chain, image_index, timeout); in x11_acquire_next_image()
1127 struct x11_swapchain *chain = (struct x11_swapchain *)anv_chain; in x11_queue_present() local
1130 if (chain->status < 0) in x11_queue_present()
1131 return chain->status; in x11_queue_present()
1133 chain->images[image_index].busy = true; in x11_queue_present()
1134 if (chain->has_present_queue) { in x11_queue_present()
1135 wsi_queue_push(&chain->present_queue, image_index); in x11_queue_present()
1136 return chain->status; in x11_queue_present()
1138 return x11_present_to_x11(chain, image_index, 0); in x11_queue_present()
1145 struct x11_swapchain *chain = state; in x11_manage_fifo_queues() local
1148 assert(chain->has_present_queue); in x11_manage_fifo_queues()
1149 while (chain->status >= 0) { in x11_manage_fifo_queues()
1155 result = wsi_queue_pull(&chain->present_queue, &image_index, INT64_MAX); in x11_manage_fifo_queues()
1159 } else if (chain->status < 0) { in x11_manage_fifo_queues()
1166 if (chain->base.present_mode == VK_PRESENT_MODE_MAILBOX_KHR) { in x11_manage_fifo_queues()
1167 result = chain->base.wsi->WaitForFences(chain->base.device, 1, in x11_manage_fifo_queues()
1168 &chain->base.fences[image_index], in x11_manage_fifo_queues()
1177 if (chain->has_acquire_queue) in x11_manage_fifo_queues()
1178 target_msc = chain->last_present_msc + 1; in x11_manage_fifo_queues()
1180 result = x11_present_to_x11(chain, image_index, target_msc); in x11_manage_fifo_queues()
1184 if (chain->has_acquire_queue) { in x11_manage_fifo_queues()
1189 while (chain->last_present_msc < target_msc || in x11_manage_fifo_queues()
1190 chain->sent_image_count == chain->base.image_count) { in x11_manage_fifo_queues()
1192 xcb_wait_for_special_event(chain->conn, chain->special_event); in x11_manage_fifo_queues()
1198 result = x11_handle_dri3_present_event(chain, (void *)event); in x11_manage_fifo_queues()
1207 x11_swapchain_result(chain, result); in x11_manage_fifo_queues()
1208 if (chain->has_acquire_queue) in x11_manage_fifo_queues()
1209 wsi_queue_push(&chain->acquire_queue, UINT32_MAX); in x11_manage_fifo_queues()
1215 x11_image_init(VkDevice device_h, struct x11_swapchain *chain, in x11_image_init() argument
1226 if (chain->base.use_prime_blit) { in x11_image_init()
1228 result = wsi_create_prime_image(&chain->base, pCreateInfo, use_modifier, &image->base); in x11_image_init()
1230 result = wsi_create_native_image(&chain->base, pCreateInfo, in x11_image_init()
1237 if (chain->base.wsi->sw) { in x11_image_init()
1241 image->pixmap = xcb_generate_id(chain->conn); in x11_image_init()
1246 assert(chain->has_dri3_modifiers); in x11_image_init()
1249 xcb_dri3_pixmap_from_buffers_checked(chain->conn, in x11_image_init()
1251 chain->window, in x11_image_init()
1263 chain->depth, bpp, in x11_image_init()
1273 xcb_dri3_pixmap_from_buffer_checked(chain->conn, in x11_image_init()
1275 chain->window, in x11_image_init()
1280 chain->depth, bpp, in x11_image_init()
1284 xcb_discard_reply(chain->conn, cookie.sequence); in x11_image_init()
1298 image->sync_fence = xcb_generate_id(chain->conn); in x11_image_init()
1299 xcb_dri3_fence_from_fd(chain->conn, in x11_image_init()
1314 cookie = xcb_free_pixmap(chain->conn, image->pixmap); in x11_image_init()
1315 xcb_discard_reply(chain->conn, cookie.sequence); in x11_image_init()
1317 wsi_destroy_image(&chain->base, &image->base); in x11_image_init()
1323 x11_image_finish(struct x11_swapchain *chain, in x11_image_finish() argument
1329 if (!chain->base.wsi->sw) { in x11_image_finish()
1330 cookie = xcb_sync_destroy_fence(chain->conn, image->sync_fence); in x11_image_finish()
1331 xcb_discard_reply(chain->conn, cookie.sequence); in x11_image_finish()
1334 cookie = xcb_free_pixmap(chain->conn, image->pixmap); in x11_image_finish()
1335 xcb_discard_reply(chain->conn, cookie.sequence); in x11_image_finish()
1338 wsi_destroy_image(&chain->base, &image->base); in x11_image_finish()
1422 struct x11_swapchain *chain = (struct x11_swapchain *)anv_chain; in x11_swapchain_destroy() local
1425 if (chain->has_present_queue) { in x11_swapchain_destroy()
1426 chain->status = VK_ERROR_OUT_OF_DATE_KHR; in x11_swapchain_destroy()
1428 wsi_queue_push(&chain->present_queue, UINT32_MAX); in x11_swapchain_destroy()
1429 pthread_join(chain->queue_manager, NULL); in x11_swapchain_destroy()
1431 if (chain->has_acquire_queue) in x11_swapchain_destroy()
1432 wsi_queue_destroy(&chain->acquire_queue); in x11_swapchain_destroy()
1433 wsi_queue_destroy(&chain->present_queue); in x11_swapchain_destroy()
1436 for (uint32_t i = 0; i < chain->base.image_count; i++) in x11_swapchain_destroy()
1437 x11_image_finish(chain, pAllocator, &chain->images[i]); in x11_swapchain_destroy()
1439 xcb_unregister_for_special_event(chain->conn, chain->special_event); in x11_swapchain_destroy()
1440 cookie = xcb_present_select_input_checked(chain->conn, chain->event_id, in x11_swapchain_destroy()
1441 chain->window, in x11_swapchain_destroy()
1443 xcb_discard_reply(chain->conn, cookie.sequence); in x11_swapchain_destroy()
1445 wsi_swapchain_finish(&chain->base); in x11_swapchain_destroy()
1447 vk_free(pAllocator, chain); in x11_swapchain_destroy()
1487 struct x11_swapchain *chain; in x11_surface_create_swapchain() local
1517 size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]); in x11_surface_create_swapchain()
1518 chain = vk_alloc(pAllocator, size, 8, in x11_surface_create_swapchain()
1520 if (chain == NULL) in x11_surface_create_swapchain()
1523 result = wsi_swapchain_init(wsi_device, &chain->base, device, in x11_surface_create_swapchain()
1528 chain->base.destroy = x11_swapchain_destroy; in x11_surface_create_swapchain()
1529 chain->base.get_wsi_image = x11_get_wsi_image; in x11_surface_create_swapchain()
1530 chain->base.acquire_next_image = x11_acquire_next_image; in x11_surface_create_swapchain()
1531 chain->base.queue_present = x11_queue_present; in x11_surface_create_swapchain()
1532 chain->base.present_mode = present_mode; in x11_surface_create_swapchain()
1533 chain->base.image_count = num_images; in x11_surface_create_swapchain()
1534 chain->conn = conn; in x11_surface_create_swapchain()
1535 chain->window = window; in x11_surface_create_swapchain()
1536 chain->depth = bit_depth; in x11_surface_create_swapchain()
1537 chain->extent = pCreateInfo->imageExtent; in x11_surface_create_swapchain()
1538 chain->send_sbc = 0; in x11_surface_create_swapchain()
1539 chain->sent_image_count = 0; in x11_surface_create_swapchain()
1540 chain->last_present_msc = 0; in x11_surface_create_swapchain()
1541 chain->has_acquire_queue = false; in x11_surface_create_swapchain()
1542 chain->has_present_queue = false; in x11_surface_create_swapchain()
1543 chain->status = VK_SUCCESS; in x11_surface_create_swapchain()
1544 chain->has_dri3_modifiers = wsi_conn->has_dri3_modifiers; in x11_surface_create_swapchain()
1554 chain->last_present_mode = old_chain->last_present_mode; in x11_surface_create_swapchain()
1556 chain->last_present_mode = XCB_PRESENT_COMPLETE_MODE_COPY; in x11_surface_create_swapchain()
1560 chain->base.use_prime_blit = true; in x11_surface_create_swapchain()
1562 chain->event_id = xcb_generate_id(chain->conn); in x11_surface_create_swapchain()
1563 xcb_present_select_input(chain->conn, chain->event_id, chain->window, in x11_surface_create_swapchain()
1571 chain->special_event = in x11_surface_create_swapchain()
1572 xcb_register_for_special_xge(chain->conn, &xcb_present_id, in x11_surface_create_swapchain()
1573 chain->event_id, NULL); in x11_surface_create_swapchain()
1575 chain->gc = xcb_generate_id(chain->conn); in x11_surface_create_swapchain()
1576 if (!chain->gc) { in x11_surface_create_swapchain()
1582 cookie = xcb_create_gc(chain->conn, in x11_surface_create_swapchain()
1583 chain->gc, in x11_surface_create_swapchain()
1584 chain->window, in x11_surface_create_swapchain()
1587 xcb_discard_reply(chain->conn, cookie.sequence); in x11_surface_create_swapchain()
1593 wsi_x11_get_dri3_modifiers(wsi_conn, conn, window, chain->depth, 32, in x11_surface_create_swapchain()
1599 for (; image < chain->base.image_count; image++) { in x11_surface_create_swapchain()
1600 result = x11_image_init(device, chain, pCreateInfo, pAllocator, in x11_surface_create_swapchain()
1603 &chain->images[image]); in x11_surface_create_swapchain()
1608 if ((chain->base.present_mode == VK_PRESENT_MODE_FIFO_KHR || in x11_surface_create_swapchain()
1609 chain->base.present_mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR || in x11_surface_create_swapchain()
1610 chain->base.present_mode == VK_PRESENT_MODE_MAILBOX_KHR) && !chain->base.wsi->sw) { in x11_surface_create_swapchain()
1611 chain->has_present_queue = true; in x11_surface_create_swapchain()
1618 ret = wsi_queue_init(&chain->present_queue, chain->base.image_count + 1); in x11_surface_create_swapchain()
1623 if (chain->base.present_mode == VK_PRESENT_MODE_FIFO_KHR || in x11_surface_create_swapchain()
1624 chain->base.present_mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR) { in x11_surface_create_swapchain()
1625 chain->has_acquire_queue = true; in x11_surface_create_swapchain()
1627 ret = wsi_queue_init(&chain->acquire_queue, chain->base.image_count + 1); in x11_surface_create_swapchain()
1629 wsi_queue_destroy(&chain->present_queue); in x11_surface_create_swapchain()
1633 for (unsigned i = 0; i < chain->base.image_count; i++) in x11_surface_create_swapchain()
1634 wsi_queue_push(&chain->acquire_queue, i); in x11_surface_create_swapchain()
1637 ret = pthread_create(&chain->queue_manager, NULL, in x11_surface_create_swapchain()
1638 x11_manage_fifo_queues, chain); in x11_surface_create_swapchain()
1640 wsi_queue_destroy(&chain->present_queue); in x11_surface_create_swapchain()
1641 if (chain->has_acquire_queue) in x11_surface_create_swapchain()
1642 wsi_queue_destroy(&chain->acquire_queue); in x11_surface_create_swapchain()
1648 assert(chain->has_present_queue || !chain->has_acquire_queue); in x11_surface_create_swapchain()
1659 *swapchain_out = &chain->base; in x11_surface_create_swapchain()
1665 x11_image_finish(chain, pAllocator, &chain->images[j]); in x11_surface_create_swapchain()
1671 xcb_unregister_for_special_event(chain->conn, chain->special_event); in x11_surface_create_swapchain()
1673 wsi_swapchain_finish(&chain->base); in x11_surface_create_swapchain()
1676 vk_free(pAllocator, chain); in x11_surface_create_swapchain()