Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 26 | * Ian Elliott <ian@lunarg.com> |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <sys/types.h> |
| 30 | #include <sys/stat.h> |
| 31 | #include <unistd.h> |
| 32 | #include <fcntl.h> |
| 33 | #include <xcb/xcb.h> |
| 34 | #include <xcb/dri3.h> |
| 35 | #include <xcb/present.h> |
| 36 | |
| 37 | #include "kmd/winsys.h" |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 38 | #include "kmd/libdrm/xf86drmMode.h" |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 39 | #include "dev.h" |
| 40 | #include "fence.h" |
| 41 | #include "gpu.h" |
| 42 | #include "img.h" |
| 43 | #include "mem.h" |
| 44 | #include "queue.h" |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 45 | #include "wsi.h" |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 46 | |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 47 | struct intel_x11_display { |
| 48 | struct intel_handle handle; |
| 49 | |
| 50 | int fd; |
| 51 | uint32_t connector_id; |
| 52 | |
| 53 | char name[32]; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 54 | VkExtent2D physical_dimension; |
| 55 | VkExtent2D physical_resolution; |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 56 | |
| 57 | drmModeModeInfoPtr modes; |
| 58 | uint32_t mode_count; |
| 59 | }; |
| 60 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 61 | typedef enum intel_x11_swap_chain_image_state_ |
| 62 | { |
| 63 | INTEL_SC_STATE_UNUSED = 0, |
| 64 | INTEL_SC_STATE_APP_OWNED = 1, |
| 65 | INTEL_SC_STATE_QUEUED_FOR_PRESENT = 2, |
| 66 | INTEL_SC_STATE_DISPLAYED = 3, |
| 67 | } intel_x11_swap_chain_image_state; |
| 68 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 69 | struct intel_x11_swap_chain { |
| 70 | struct intel_handle handle; |
| 71 | |
| 72 | xcb_connection_t *c; |
| 73 | xcb_window_t window; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 74 | bool force_copy; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 75 | VkPresentModeWSI present_mode; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 76 | |
| 77 | int dri3_major, dri3_minor; |
| 78 | int present_major, present_minor; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 79 | |
| 80 | xcb_present_event_t present_special_event_id; |
| 81 | xcb_special_event_t *present_special_event; |
| 82 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 83 | struct intel_img **persistent_images; |
| 84 | uint32_t persistent_image_count; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 85 | intel_x11_swap_chain_image_state *image_state; |
| 86 | uint32_t *present_queue; |
| 87 | uint32_t present_queue_length; |
Mike Stroyan | f9f6dd7 | 2015-07-28 11:00:50 -0600 | [diff] [blame] | 88 | uint32_t present_serial; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 89 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 90 | struct { |
| 91 | uint32_t serial; |
| 92 | } local; |
| 93 | |
| 94 | struct { |
| 95 | uint32_t serial; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 96 | uint64_t msc; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 97 | } remote; |
| 98 | }; |
| 99 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 100 | struct intel_x11_img_data { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 101 | struct intel_x11_swap_chain *swap_chain; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 102 | struct intel_mem *mem; |
| 103 | int prime_fd; |
| 104 | uint32_t pixmap; |
| 105 | }; |
| 106 | |
| 107 | struct intel_x11_fence_data { |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 108 | struct intel_x11_swap_chain *swap_chain; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 109 | uint32_t serial; |
| 110 | }; |
| 111 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 112 | /* these are what DDX expects */ |
| 113 | static const VkFormat x11_presentable_formats[] = { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 114 | VK_FORMAT_B8G8R8A8_UNORM, |
| 115 | VK_FORMAT_B8G8R8A8_SRGB, |
Ian Elliott | 32536f9 | 2015-04-21 16:41:02 -0600 | [diff] [blame] | 116 | VK_FORMAT_B5G6R5_UNORM, |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 117 | }; |
| 118 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 119 | static inline struct intel_x11_swap_chain *x11_swap_chain(VkSwapChainWSI sc) |
| 120 | { |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 121 | return (struct intel_x11_swap_chain *) sc.handle; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 122 | } |
| 123 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 124 | static bool x11_is_format_presentable(const struct intel_dev *dev, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 125 | VkFormat format) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 126 | { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 127 | uint32_t i; |
| 128 | |
| 129 | for (i = 0; i < ARRAY_SIZE(x11_presentable_formats); i++) { |
| 130 | if (x11_presentable_formats[i] == format) |
| 131 | return true; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 132 | } |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 133 | |
| 134 | return false; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 135 | } |
| 136 | |
Chia-I Wu | 030b2db | 2015-04-08 13:46:29 +0800 | [diff] [blame] | 137 | static int x11_export_prime_fd(struct intel_dev *dev, |
| 138 | struct intel_bo *bo, |
| 139 | const struct intel_layout *layout) |
| 140 | { |
| 141 | struct intel_winsys_handle export; |
| 142 | enum intel_tiling_mode tiling; |
| 143 | |
| 144 | export.type = INTEL_WINSYS_HANDLE_FD; |
| 145 | |
| 146 | switch (layout->tiling) { |
| 147 | case GEN6_TILING_X: |
| 148 | tiling = INTEL_TILING_X; |
| 149 | break; |
| 150 | case GEN6_TILING_Y: |
| 151 | tiling = INTEL_TILING_Y; |
| 152 | break; |
| 153 | default: |
| 154 | assert(layout->tiling == GEN6_TILING_NONE); |
| 155 | tiling = INTEL_TILING_NONE; |
| 156 | break; |
| 157 | } |
| 158 | |
| 159 | if (intel_bo_set_tiling(bo, tiling, layout->bo_stride)) |
| 160 | return -1; |
| 161 | |
| 162 | if (intel_winsys_export_handle(dev->winsys, bo, tiling, |
| 163 | layout->bo_stride, layout->bo_height, &export)) |
| 164 | return -1; |
| 165 | |
| 166 | return (int) export.handle; |
| 167 | } |
| 168 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 169 | /** |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 170 | * Return true if fd points to the primary or render node of the GPU. |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 171 | */ |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 172 | static bool x11_gpu_match_fd(const struct intel_gpu *gpu, int fd) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 173 | { |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 174 | struct stat fd_stat, gpu_stat; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 175 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 176 | if (fstat(fd, &fd_stat)) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 177 | return false; |
| 178 | |
| 179 | /* is it the primary node? */ |
| 180 | if (!stat(gpu->primary_node, &gpu_stat) && |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 181 | !memcmp(&fd_stat, &gpu_stat, sizeof(fd_stat))) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 182 | return true; |
| 183 | |
| 184 | /* is it the render node? */ |
| 185 | if (gpu->render_node && !stat(gpu->render_node, &gpu_stat) && |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 186 | !memcmp(&fd_stat, &gpu_stat, sizeof(fd_stat))) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 187 | return true; |
| 188 | |
| 189 | return false; |
| 190 | } |
| 191 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 192 | /* |
| 193 | * Return the depth of \p drawable. |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 194 | */ |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 195 | static int x11_get_drawable_depth(xcb_connection_t *c, |
| 196 | xcb_drawable_t drawable) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 197 | { |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 198 | xcb_get_geometry_cookie_t cookie; |
| 199 | xcb_get_geometry_reply_t *reply; |
| 200 | uint8_t depth; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 201 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 202 | cookie = xcb_get_geometry(c, drawable); |
| 203 | reply = xcb_get_geometry_reply(c, cookie, NULL); |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 204 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 205 | if (reply) { |
| 206 | depth = reply->depth; |
| 207 | free(reply); |
| 208 | } else { |
| 209 | depth = 0; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 210 | } |
| 211 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 212 | return depth; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 213 | } |
| 214 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 215 | static VkResult x11_get_surface_properties( |
| 216 | const VkSurfaceDescriptionWSI *pSurfaceDescription, |
| 217 | VkSurfacePropertiesWSI *pSurfaceProperties) |
| 218 | { |
| 219 | const VkSurfaceDescriptionWindowWSI* pSurfaceDescriptionWindow = |
| 220 | (VkSurfaceDescriptionWindowWSI*) pSurfaceDescription; |
| 221 | VkPlatformHandleXcbWSI *pPlatformHandleXcb = (VkPlatformHandleXcbWSI *) |
| 222 | pSurfaceDescriptionWindow->pPlatformHandle; |
| 223 | xcb_connection_t *c = (xcb_connection_t *) |
| 224 | pPlatformHandleXcb->connection; |
| 225 | xcb_window_t window = *((xcb_window_t *) |
| 226 | pSurfaceDescriptionWindow->pPlatformWindow); |
| 227 | xcb_get_geometry_cookie_t cookie; |
| 228 | xcb_get_geometry_reply_t *reply; |
| 229 | |
| 230 | cookie = xcb_get_geometry(c, window); |
| 231 | reply = xcb_get_geometry_reply(c, cookie, NULL); |
| 232 | |
| 233 | if (reply) { |
| 234 | pSurfaceProperties->currentExtent.width = reply->width; |
| 235 | pSurfaceProperties->currentExtent.height = reply->height; |
| 236 | free(reply); |
| 237 | } else { |
| 238 | pSurfaceProperties->currentExtent.width = 0; |
| 239 | pSurfaceProperties->currentExtent.height = 0; |
| 240 | } |
| 241 | |
| 242 | pSurfaceProperties->minImageCount = 2; |
| 243 | pSurfaceProperties->maxImageCount = 0; |
| 244 | |
| 245 | pSurfaceProperties->minImageExtent.width = |
| 246 | pSurfaceProperties->currentExtent.width; |
| 247 | pSurfaceProperties->minImageExtent.height = |
| 248 | pSurfaceProperties->currentExtent.height; |
| 249 | pSurfaceProperties->maxImageExtent.width = |
| 250 | pSurfaceProperties->currentExtent.width; |
| 251 | pSurfaceProperties->maxImageExtent.height = |
| 252 | pSurfaceProperties->currentExtent.height; |
| 253 | pSurfaceProperties->supportedTransforms = VK_SURFACE_TRANSFORM_NONE_BIT_WSI; |
| 254 | pSurfaceProperties->currentTransform = VK_SURFACE_TRANSFORM_NONE_WSI; |
| 255 | pSurfaceProperties->maxImageArraySize = 0; |
| 256 | pSurfaceProperties->supportedUsageFlags = |
Cody Northrop | 3440c2d | 2015-08-28 16:40:45 -0600 | [diff] [blame^] | 257 | VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 258 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 259 | |
| 260 | return VK_SUCCESS; |
| 261 | } |
| 262 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 263 | /** |
| 264 | * Return true if DRI3 and Present are supported by the server. |
| 265 | */ |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 266 | static bool x11_is_dri3_and_present_supported(xcb_connection_t *c) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 267 | { |
| 268 | const xcb_query_extension_reply_t *ext; |
| 269 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 270 | xcb_prefetch_extension_data(c, &xcb_dri3_id); |
| 271 | xcb_prefetch_extension_data(c, &xcb_present_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 272 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 273 | ext = xcb_get_extension_data(c, &xcb_dri3_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 274 | if (!ext || !ext->present) |
| 275 | return false; |
| 276 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 277 | ext = xcb_get_extension_data(c, &xcb_present_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 278 | if (!ext || !ext->present) |
| 279 | return false; |
| 280 | |
| 281 | return true; |
| 282 | } |
| 283 | |
| 284 | /** |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 285 | * Send a DRI3Open to get the server GPU fd. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 286 | */ |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 287 | static int x11_dri3_open(xcb_connection_t *c, |
| 288 | xcb_drawable_t drawable, |
| 289 | xcb_randr_provider_t provider) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 290 | { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 291 | xcb_dri3_open_cookie_t cookie; |
| 292 | xcb_dri3_open_reply_t *reply; |
| 293 | int fd; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 294 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 295 | cookie = xcb_dri3_open(c, drawable, provider); |
| 296 | reply = xcb_dri3_open_reply(c, cookie, NULL); |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 297 | if (!reply) |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 298 | return -1; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 299 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 300 | fd = (reply->nfd == 1) ? xcb_dri3_open_reply_fds(c, reply)[0] : -1; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 301 | free(reply); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 302 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 303 | return fd; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /** |
Chia-I Wu | 030b2db | 2015-04-08 13:46:29 +0800 | [diff] [blame] | 307 | * Send a DRI3PixmapFromBuffer to create a pixmap from \p prime_fd. |
| 308 | */ |
| 309 | static xcb_pixmap_t x11_dri3_pixmap_from_buffer(xcb_connection_t *c, |
| 310 | xcb_drawable_t drawable, |
| 311 | uint8_t depth, int prime_fd, |
| 312 | const struct intel_layout *layout) |
| 313 | { |
| 314 | xcb_pixmap_t pixmap; |
| 315 | |
| 316 | pixmap = xcb_generate_id(c); |
| 317 | |
| 318 | xcb_dri3_pixmap_from_buffer(c, pixmap, drawable, |
| 319 | layout->bo_stride * layout->bo_height, |
| 320 | layout->width0, layout->height0, |
| 321 | layout->bo_stride, depth, |
| 322 | layout->block_size * 8, prime_fd); |
| 323 | |
| 324 | return pixmap; |
| 325 | } |
| 326 | |
| 327 | /** |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 328 | * Send DRI3QueryVersion and PresentQueryVersion to query extension versions. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 329 | */ |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 330 | static bool x11_swap_chain_dri3_and_present_query_version(struct intel_x11_swap_chain *sc) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 331 | { |
| 332 | xcb_dri3_query_version_cookie_t dri3_cookie; |
| 333 | xcb_dri3_query_version_reply_t *dri3_reply; |
| 334 | xcb_present_query_version_cookie_t present_cookie; |
| 335 | xcb_present_query_version_reply_t *present_reply; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 336 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 337 | dri3_cookie = xcb_dri3_query_version(sc->c, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 338 | XCB_DRI3_MAJOR_VERSION, XCB_DRI3_MINOR_VERSION); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 339 | present_cookie = xcb_present_query_version(sc->c, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 340 | XCB_PRESENT_MAJOR_VERSION, XCB_PRESENT_MINOR_VERSION); |
| 341 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 342 | dri3_reply = xcb_dri3_query_version_reply(sc->c, dri3_cookie, NULL); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 343 | if (!dri3_reply) |
| 344 | return false; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 345 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 346 | sc->dri3_major = dri3_reply->major_version; |
| 347 | sc->dri3_minor = dri3_reply->minor_version; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 348 | free(dri3_reply); |
| 349 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 350 | present_reply = xcb_present_query_version_reply(sc->c, present_cookie, NULL); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 351 | if (!present_reply) |
| 352 | return false; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 353 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 354 | sc->present_major = present_reply->major_version; |
| 355 | sc->present_minor = present_reply->minor_version; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 356 | free(present_reply); |
| 357 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 358 | return true; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | /** |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 362 | * Send a PresentSelectInput to select interested events. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 363 | */ |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 364 | static bool x11_swap_chain_present_select_input(struct intel_x11_swap_chain *sc) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 365 | { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 366 | xcb_void_cookie_t cookie; |
| 367 | xcb_generic_error_t *error; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 368 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 369 | /* create the event queue */ |
| 370 | sc->present_special_event_id = xcb_generate_id(sc->c); |
| 371 | sc->present_special_event = xcb_register_for_special_xge(sc->c, |
| 372 | &xcb_present_id, sc->present_special_event_id, NULL); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 373 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 374 | cookie = xcb_present_select_input_checked(sc->c, |
| 375 | sc->present_special_event_id, sc->window, |
| 376 | XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 377 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 378 | error = xcb_request_check(sc->c, cookie); |
| 379 | if (error) { |
| 380 | free(error); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 381 | return false; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 382 | } |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 383 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 384 | return true; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 385 | } |
| 386 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 387 | static struct intel_img *x11_swap_chain_create_persistent_image(struct intel_x11_swap_chain *sc, |
| 388 | struct intel_dev *dev, |
| 389 | const VkImageCreateInfo *img_info) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 390 | { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 391 | struct intel_img *img; |
| 392 | struct intel_mem *mem; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 393 | struct intel_x11_img_data *data; |
| 394 | VkMemoryAllocInfo mem_info; |
| 395 | int prime_fd; |
| 396 | xcb_pixmap_t pixmap; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 397 | VkResult ret; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 398 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 399 | ret = intel_img_create(dev, img_info, true, &img); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 400 | if (ret != VK_SUCCESS) |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 401 | return NULL; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 402 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 403 | memset(&mem_info, 0, sizeof(mem_info)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 404 | mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 405 | mem_info.allocationSize = img->total_size; |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 406 | mem_info.memoryTypeIndex = 0; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 407 | |
| 408 | ret = intel_mem_alloc(dev, &mem_info, &mem); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 409 | if (ret != VK_SUCCESS) { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 410 | intel_img_destroy(img); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 411 | return NULL; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 412 | } |
| 413 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 414 | prime_fd = x11_export_prime_fd(dev, mem->bo, &img->layout); |
| 415 | if (prime_fd < 0) { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 416 | intel_mem_free(mem); |
| 417 | intel_img_destroy(img); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 418 | return NULL; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 419 | } |
| 420 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 421 | pixmap = x11_dri3_pixmap_from_buffer(sc->c, sc->window, |
| 422 | x11_get_drawable_depth(sc->c, sc->window), |
| 423 | prime_fd, &img->layout); |
| 424 | |
| 425 | data = (struct intel_x11_img_data *) img->wsi_data; |
| 426 | data->swap_chain = sc; |
| 427 | data->mem = mem; |
| 428 | data->prime_fd = prime_fd; |
| 429 | data->pixmap = pixmap; |
| 430 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 431 | intel_obj_bind_mem(&img->obj, mem, 0); |
| 432 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 433 | return img; |
| 434 | } |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 435 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 436 | static bool x11_swap_chain_create_persistent_images(struct intel_x11_swap_chain *sc, |
| 437 | struct intel_dev *dev, |
| 438 | const VkSwapChainCreateInfoWSI *info) |
| 439 | { |
| 440 | struct intel_img **images; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 441 | intel_x11_swap_chain_image_state *image_state; |
| 442 | uint32_t *present_queue; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 443 | VkImageCreateInfo img_info; |
| 444 | uint32_t i; |
| 445 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 446 | images = intel_alloc(sc, sizeof(*images) * info->minImageCount, |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 447 | 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
| 448 | if (!images) |
| 449 | return false; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 450 | image_state = intel_alloc( |
| 451 | sc, sizeof(intel_x11_swap_chain_image_state) * info->minImageCount, |
| 452 | 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
| 453 | if (!image_state) { |
| 454 | for (i = 0; i < info->minImageCount; i++) { |
| 455 | intel_img_destroy(images[i]); |
| 456 | } |
| 457 | intel_free(sc, images); |
| 458 | return false; |
| 459 | } |
| 460 | present_queue = intel_alloc( |
| 461 | sc, sizeof(uint32_t) * info->minImageCount, |
| 462 | 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
| 463 | if (!present_queue) { |
| 464 | for (i = 0; i < info->minImageCount; i++) { |
| 465 | intel_img_destroy(images[i]); |
| 466 | } |
| 467 | intel_free(sc, images); |
| 468 | intel_free(sc, image_state); |
| 469 | return false; |
| 470 | } |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 471 | |
| 472 | memset(&img_info, 0, sizeof(img_info)); |
| 473 | img_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 474 | img_info.imageType = VK_IMAGE_TYPE_2D; |
| 475 | img_info.format = info->imageFormat; |
| 476 | img_info.extent.width = info->imageExtent.width; |
| 477 | img_info.extent.height = info->imageExtent.height; |
| 478 | img_info.extent.depth = 1; |
| 479 | img_info.mipLevels = 1; |
| 480 | img_info.arraySize = info->imageArraySize; |
| 481 | img_info.samples = 1; |
| 482 | img_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 483 | img_info.usage = info->imageUsageFlags; |
| 484 | img_info.flags = 0; |
| 485 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 486 | for (i = 0; i < info->minImageCount; i++) { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 487 | images[i] = x11_swap_chain_create_persistent_image(sc, |
| 488 | dev, &img_info); |
| 489 | if (!images[i]) |
| 490 | break; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 491 | image_state[i] = INTEL_SC_STATE_UNUSED; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 492 | } |
| 493 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 494 | if (i < info->minImageCount) { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 495 | uint32_t j; |
| 496 | for (j = 0; j < i; j++) |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 497 | intel_img_destroy(images[j]); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 498 | |
| 499 | intel_free(sc, images); |
| 500 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 501 | if (image_state) { |
| 502 | intel_free(sc, image_state); |
| 503 | } |
| 504 | |
| 505 | if (present_queue) { |
| 506 | intel_free(sc, present_queue); |
| 507 | } |
| 508 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 509 | return false; |
| 510 | } |
| 511 | |
| 512 | sc->persistent_images = images; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 513 | sc->persistent_image_count = info->minImageCount; |
| 514 | sc->image_state = image_state; |
| 515 | sc->present_queue = present_queue; |
| 516 | sc->present_queue_length = 0; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 517 | |
| 518 | return true; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /** |
| 522 | * Send a PresentPixmap. |
| 523 | */ |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 524 | static VkResult x11_swap_chain_present_pixmap(struct intel_x11_swap_chain *sc, |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 525 | struct intel_img *img) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 526 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 527 | struct intel_x11_img_data *data = |
| 528 | (struct intel_x11_img_data *) img->wsi_data; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 529 | uint32_t options = XCB_PRESENT_OPTION_NONE; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 530 | uint32_t target_msc, divisor, remainder; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 531 | xcb_void_cookie_t cookie; |
| 532 | xcb_generic_error_t *err; |
| 533 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 534 | target_msc = 0; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 535 | divisor = 1; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 536 | remainder = 0; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 537 | if (sc->present_mode == VK_PRESENT_MODE_IMMEDIATE_WSI) { |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 538 | options |= XCB_PRESENT_OPTION_ASYNC; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 539 | } |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 540 | |
| 541 | if (sc->force_copy) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 542 | options |= XCB_PRESENT_OPTION_COPY; |
| 543 | |
Chia-I Wu | f689c60 | 2015-04-28 10:55:52 +0800 | [diff] [blame] | 544 | cookie = xcb_present_pixmap_checked(sc->c, |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 545 | sc->window, |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 546 | data->pixmap, |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 547 | ++sc->local.serial, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 548 | 0, /* valid-area */ |
| 549 | 0, /* update-area */ |
| 550 | 0, /* x-off */ |
| 551 | 0, /* y-off */ |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 552 | 0, /* crtc */ |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 553 | 0, /* wait-fence */ |
| 554 | 0, /* idle-fence */ |
| 555 | options, |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 556 | target_msc, |
| 557 | divisor, |
| 558 | remainder, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 559 | 0, NULL); |
| 560 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 561 | err = xcb_request_check(sc->c, cookie); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 562 | if (err) { |
| 563 | free(err); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 564 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 565 | } |
| 566 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 567 | return VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /** |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 571 | * Handle a Present event. |
| 572 | */ |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 573 | static void x11_swap_chain_present_event(struct intel_x11_swap_chain *sc, |
| 574 | const xcb_present_generic_event_t *ev) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 575 | { |
| 576 | union { |
| 577 | const xcb_present_generic_event_t *ev; |
| 578 | const xcb_present_complete_notify_event_t *complete; |
| 579 | } u = { .ev = ev }; |
| 580 | |
| 581 | switch (u.ev->evtype) { |
| 582 | case XCB_PRESENT_COMPLETE_NOTIFY: |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 583 | sc->remote.serial = u.complete->serial; |
| 584 | sc->remote.msc = u.complete->msc; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 585 | assert(sc->present_queue_length > 0); |
| 586 | if (sc->image_state[sc->present_queue[0]] == INTEL_SC_STATE_DISPLAYED) { |
| 587 | // Remove the previously-displayed image from the present queue: |
| 588 | sc->image_state[sc->present_queue[0]] = INTEL_SC_STATE_UNUSED; |
| 589 | sc->present_queue_length--; |
| 590 | for (int j = 0; j < sc->present_queue_length; j++) { |
| 591 | sc->present_queue[j] = sc->present_queue[j+1]; |
| 592 | } |
| 593 | } |
| 594 | assert(sc->present_queue_length > 0); |
| 595 | assert(sc->image_state[sc->present_queue[0]] == INTEL_SC_STATE_QUEUED_FOR_PRESENT); |
| 596 | sc->image_state[sc->present_queue[0]] = INTEL_SC_STATE_DISPLAYED; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 597 | break; |
| 598 | default: |
| 599 | break; |
| 600 | } |
| 601 | } |
| 602 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 603 | static VkResult x11_swap_chain_wait(struct intel_x11_swap_chain *sc, |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 604 | uint32_t serial, int64_t timeout) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 605 | { |
| 606 | const bool wait = (timeout != 0); |
| 607 | |
| 608 | while (sc->remote.serial < serial) { |
| 609 | xcb_present_generic_event_t *ev; |
Mike Stroyan | 4a38716 | 2015-04-27 15:42:41 -0600 | [diff] [blame] | 610 | xcb_intern_atom_reply_t *reply; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 611 | |
| 612 | if (wait) { |
| 613 | ev = (xcb_present_generic_event_t *) |
| 614 | xcb_wait_for_special_event(sc->c, sc->present_special_event); |
Mike Stroyan | 4a38716 | 2015-04-27 15:42:41 -0600 | [diff] [blame] | 615 | /* use xcb_intern_atom_reply just to wake other threads waiting on sc->c */ |
| 616 | reply = xcb_intern_atom_reply(sc->c, xcb_intern_atom(sc->c, 1, 1, "a"), NULL); |
| 617 | if (reply) { |
| 618 | free(reply); |
| 619 | } |
| 620 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 621 | if (!ev) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 622 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 623 | } else { |
Mike Stroyan | 4a38716 | 2015-04-27 15:42:41 -0600 | [diff] [blame] | 624 | /* use xcb_intern_atom_reply just to check socket for special event */ |
| 625 | reply = xcb_intern_atom_reply(sc->c, xcb_intern_atom(sc->c, 1, 1, "a"), NULL); |
| 626 | if (reply) { |
| 627 | free(reply); |
| 628 | } |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 629 | ev = (xcb_present_generic_event_t *) |
| 630 | xcb_poll_for_special_event(sc->c, sc->present_special_event); |
| 631 | if (!ev) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 632 | return VK_NOT_READY; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | x11_swap_chain_present_event(sc, ev); |
| 636 | |
| 637 | free(ev); |
| 638 | } |
| 639 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 640 | return VK_SUCCESS; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 641 | } |
| 642 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 643 | static void x11_swap_chain_destroy(struct intel_x11_swap_chain *sc) |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 644 | { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 645 | if (sc->persistent_images) { |
| 646 | uint32_t i; |
| 647 | |
| 648 | for (i = 0; i < sc->persistent_image_count; i++) |
| 649 | intel_img_destroy(sc->persistent_images[i]); |
| 650 | intel_free(sc, sc->persistent_images); |
| 651 | } |
| 652 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 653 | if (sc->image_state) { |
| 654 | intel_free(sc, sc->image_state); |
| 655 | } |
| 656 | |
| 657 | if (sc->present_queue) { |
| 658 | intel_free(sc, sc->present_queue); |
| 659 | } |
| 660 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 661 | if (sc->present_special_event) |
| 662 | xcb_unregister_for_special_event(sc->c, sc->present_special_event); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 663 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 664 | intel_free(sc, sc); |
| 665 | } |
| 666 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 667 | static VkResult x11_swap_chain_create(struct intel_dev *dev, |
| 668 | const VkSwapChainCreateInfoWSI *info, |
| 669 | struct intel_x11_swap_chain **sc_ret) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 670 | { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 671 | const xcb_randr_provider_t provider = 0; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 672 | const VkSurfaceDescriptionWindowWSI* pSurfaceDescriptionWindow = |
| 673 | (VkSurfaceDescriptionWindowWSI*) info->pSurfaceDescription; |
| 674 | VkPlatformHandleXcbWSI *pPlatformHandleXcb = (VkPlatformHandleXcbWSI *) |
| 675 | pSurfaceDescriptionWindow->pPlatformHandle; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 676 | xcb_connection_t *c = (xcb_connection_t *) |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 677 | pPlatformHandleXcb->connection; |
| 678 | xcb_window_t window = *((xcb_window_t *) |
| 679 | pSurfaceDescriptionWindow->pPlatformWindow); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 680 | struct intel_x11_swap_chain *sc; |
| 681 | int fd; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 682 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 683 | if (!x11_is_format_presentable(dev, info->imageFormat)) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 684 | intel_dev_log(dev, VK_DBG_REPORT_ERROR_BIT, |
| 685 | VK_NULL_HANDLE, 0, 0, "invalid presentable image format"); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 686 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 687 | } |
| 688 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 689 | if (!x11_is_dri3_and_present_supported(c)) |
| 690 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 691 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 692 | fd = x11_dri3_open(c, window, provider); |
| 693 | if (fd < 0 || !x11_gpu_match_fd(dev->gpu, fd)) { |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 694 | if (fd >= 0) |
| 695 | close(fd); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 696 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 697 | } |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 698 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 699 | close(fd); |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 700 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 701 | sc = intel_alloc(dev, sizeof(*sc), 0, VK_SYSTEM_ALLOC_TYPE_API_OBJECT); |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 702 | if (!sc) |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 703 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 704 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 705 | memset(sc, 0, sizeof(*sc)); |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 706 | intel_handle_init(&sc->handle, VK_OBJECT_TYPE_SWAP_CHAIN_WSI, dev->base.handle.instance); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 707 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 708 | sc->c = c; |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 709 | sc->window = window; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 710 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 711 | /* always copy unless flip bit is set */ |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 712 | sc->present_mode = info->presentMode; |
| 713 | sc->force_copy = true; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 714 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 715 | if (!x11_swap_chain_dri3_and_present_query_version(sc) || |
| 716 | !x11_swap_chain_present_select_input(sc) || |
| 717 | !x11_swap_chain_create_persistent_images(sc, dev, info)) { |
| 718 | x11_swap_chain_destroy(sc); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 719 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 720 | } |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 721 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 722 | *sc_ret = sc; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 723 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 724 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 725 | } |
| 726 | |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 727 | static void x11_display_destroy(struct intel_x11_display *dpy) |
| 728 | { |
| 729 | intel_free(dpy, dpy->modes); |
| 730 | intel_free(dpy, dpy); |
| 731 | } |
| 732 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 733 | void intel_wsi_gpu_cleanup(struct intel_gpu *gpu) |
| 734 | { |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 735 | if (gpu->displays) { |
| 736 | uint32_t i; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 737 | |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 738 | for (i = 0; i < gpu->display_count; i++) { |
| 739 | struct intel_x11_display *dpy = |
| 740 | (struct intel_x11_display *) gpu->displays[i]; |
| 741 | x11_display_destroy(dpy); |
| 742 | } |
| 743 | intel_free(gpu, gpu->displays); |
| 744 | } |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 745 | } |
| 746 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 747 | VkResult intel_wsi_img_init(struct intel_img *img) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 748 | { |
| 749 | struct intel_x11_img_data *data; |
| 750 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 751 | data = intel_alloc(img, sizeof(*data), 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 752 | if (!data) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 753 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 754 | |
| 755 | memset(data, 0, sizeof(*data)); |
| 756 | |
| 757 | assert(!img->wsi_data); |
| 758 | img->wsi_data = data; |
| 759 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 760 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | void intel_wsi_img_cleanup(struct intel_img *img) |
| 764 | { |
| 765 | struct intel_x11_img_data *data = |
| 766 | (struct intel_x11_img_data *) img->wsi_data; |
| 767 | |
| 768 | if (data->mem) { |
| 769 | close(data->prime_fd); |
| 770 | intel_mem_free(data->mem); |
| 771 | } |
| 772 | |
| 773 | intel_free(img, img->wsi_data); |
| 774 | } |
| 775 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 776 | VkResult intel_wsi_fence_init(struct intel_fence *fence) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 777 | { |
| 778 | struct intel_x11_fence_data *data; |
| 779 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 780 | data = intel_alloc(fence, sizeof(*data), 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 781 | if (!data) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 782 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 783 | |
| 784 | memset(data, 0, sizeof(*data)); |
| 785 | |
| 786 | assert(!fence->wsi_data); |
| 787 | fence->wsi_data = data; |
| 788 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 789 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | void intel_wsi_fence_cleanup(struct intel_fence *fence) |
| 793 | { |
| 794 | intel_free(fence, fence->wsi_data); |
| 795 | } |
| 796 | |
| 797 | void intel_wsi_fence_copy(struct intel_fence *fence, |
| 798 | const struct intel_fence *src) |
| 799 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 800 | if (!fence->wsi_data) { |
| 801 | return; |
| 802 | } |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 803 | memcpy(fence->wsi_data, src->wsi_data, |
| 804 | sizeof(struct intel_x11_fence_data)); |
| 805 | } |
| 806 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 807 | VkResult intel_wsi_fence_wait(struct intel_fence *fence, |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 808 | int64_t timeout_ns) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 809 | { |
| 810 | struct intel_x11_fence_data *data = |
| 811 | (struct intel_x11_fence_data *) fence->wsi_data; |
| 812 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 813 | if (!data) |
| 814 | return VK_SUCCESS; |
| 815 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 816 | if (!data->swap_chain) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 817 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 818 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 819 | return x11_swap_chain_wait(data->swap_chain, data->serial, timeout_ns); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 820 | } |
| 821 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 822 | ICD_EXPORT VkResult VKAPI vkGetPhysicalDeviceSurfaceSupportWSI( |
| 823 | VkPhysicalDevice physicalDevice, |
| 824 | uint32_t queueNodeIndex, |
| 825 | const VkSurfaceDescriptionWSI* pSurfaceDescription, |
| 826 | VkBool32* pSupported) |
| 827 | { |
| 828 | VkResult ret = VK_SUCCESS; |
| 829 | const VkSurfaceDescriptionWindowWSI* pSurfaceDescriptionWindow = |
| 830 | (VkSurfaceDescriptionWindowWSI*) pSurfaceDescription; |
| 831 | |
| 832 | *pSupported = false; |
| 833 | |
| 834 | // TODO: Move this check to a validation layer (i.e. the driver should |
| 835 | // assume the correct data type, and not check): |
| 836 | if (pSurfaceDescriptionWindow->sType != VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI) { |
| 837 | return VK_ERROR_INVALID_VALUE; |
| 838 | } |
| 839 | |
| 840 | // TODO: NEED TO ALSO CHECK: |
| 841 | // - queueNodeIndex |
| 842 | // - pSurfaceDescriptionWindow->pPlatformHandle (can try to use it) |
| 843 | // - pSurfaceDescriptionWindow->pPlatformWindow (can try to use it) |
| 844 | if (pSurfaceDescriptionWindow->platform == VK_PLATFORM_XCB_WSI) { |
| 845 | *pSupported = true; |
| 846 | } |
| 847 | |
| 848 | return ret; |
| 849 | } |
| 850 | |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 851 | VkResult VKAPI vkGetSurfacePropertiesWSI( |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 852 | VkDevice device, |
| 853 | const VkSurfaceDescriptionWSI* pSurfaceDescription, |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 854 | VkSurfacePropertiesWSI* pSurfaceProperties) |
| 855 | { |
| 856 | // TODO: Move this check to a validation layer (i.e. the driver should |
| 857 | // assume the correct data type, and not check): |
| 858 | assert(pSurfaceProperties); |
| 859 | |
| 860 | return x11_get_surface_properties(pSurfaceDescription, pSurfaceProperties); |
| 861 | } |
| 862 | |
| 863 | VkResult VKAPI vkGetSurfaceFormatsWSI( |
| 864 | VkDevice device, |
| 865 | const VkSurfaceDescriptionWSI* pSurfaceDescription, |
| 866 | uint32_t* pCount, |
| 867 | VkSurfaceFormatWSI* pSurfaceFormats) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 868 | { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 869 | VkResult ret = VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 870 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 871 | // TODO: Move this check to a validation layer (i.e. the driver should |
| 872 | // assume the correct data type, and not check): |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 873 | if (!pCount) { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 874 | return VK_ERROR_INVALID_POINTER; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 875 | } |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 876 | |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 877 | if (pSurfaceFormats) { |
| 878 | uint32_t i; |
| 879 | for (i = 0; i < *pCount; i++) { |
| 880 | pSurfaceFormats[i].format = x11_presentable_formats[i]; |
| 881 | pSurfaceFormats[i].colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_WSI; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 882 | } |
Ian Elliott | e1ea671 | 2015-08-19 16:49:46 -0600 | [diff] [blame] | 883 | } else { |
| 884 | *pCount = ARRAY_SIZE(x11_presentable_formats); |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | return ret; |
| 888 | } |
| 889 | |
| 890 | VkResult VKAPI vkGetSurfacePresentModesWSI( |
| 891 | VkDevice device, |
| 892 | const VkSurfaceDescriptionWSI* pSurfaceDescription, |
| 893 | uint32_t* pCount, |
| 894 | VkPresentModeWSI* pPresentModes) |
| 895 | { |
| 896 | VkResult ret = VK_SUCCESS; |
| 897 | |
| 898 | // TODO: Move this check to a validation layer (i.e. the driver should |
| 899 | // assume the correct data type, and not check): |
| 900 | if (!pCount) { |
| 901 | return VK_ERROR_INVALID_POINTER; |
| 902 | } |
| 903 | |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 904 | if (pPresentModes) { |
| 905 | pPresentModes[0] = VK_PRESENT_MODE_IMMEDIATE_WSI; |
| 906 | pPresentModes[1] = VK_PRESENT_MODE_FIFO_WSI; |
| 907 | // TODO: Consider adding VK_PRESENT_MODE_MAILBOX_WSI sometime |
Ian Elliott | e1ea671 | 2015-08-19 16:49:46 -0600 | [diff] [blame] | 908 | } else { |
| 909 | *pCount = 2; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | return ret; |
| 913 | } |
| 914 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 915 | ICD_EXPORT VkResult VKAPI vkCreateSwapChainWSI( |
| 916 | VkDevice device, |
| 917 | const VkSwapChainCreateInfoWSI* pCreateInfo, |
| 918 | VkSwapChainWSI* pSwapChain) |
| 919 | { |
| 920 | struct intel_dev *dev = intel_dev(device); |
| 921 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 922 | if (pCreateInfo->oldSwapChain.handle) { |
| 923 | // TODO: Eventually, do more than simply up-front destroy the |
| 924 | // oldSwapChain (but just do that for now): |
| 925 | struct intel_x11_swap_chain *sc = |
| 926 | x11_swap_chain(pCreateInfo->oldSwapChain); |
| 927 | |
| 928 | x11_swap_chain_destroy(sc); |
| 929 | } |
| 930 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 931 | return x11_swap_chain_create(dev, pCreateInfo, |
| 932 | (struct intel_x11_swap_chain **) pSwapChain); |
| 933 | } |
| 934 | |
| 935 | ICD_EXPORT VkResult VKAPI vkDestroySwapChainWSI( |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 936 | VkDevice device, |
| 937 | VkSwapChainWSI swapChain) |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 938 | { |
| 939 | struct intel_x11_swap_chain *sc = x11_swap_chain(swapChain); |
| 940 | |
| 941 | x11_swap_chain_destroy(sc); |
| 942 | |
| 943 | return VK_SUCCESS; |
| 944 | } |
| 945 | |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 946 | ICD_EXPORT VkResult VKAPI vkGetSwapChainImagesWSI( |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 947 | VkDevice device, |
| 948 | VkSwapChainWSI swapChain, |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 949 | uint32_t* pCount, |
| 950 | VkImage* pSwapChainImages) |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 951 | { |
| 952 | struct intel_x11_swap_chain *sc = x11_swap_chain(swapChain); |
| 953 | VkResult ret = VK_SUCCESS; |
| 954 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 955 | // TODO: Move this check to a validation layer (i.e. the driver should |
| 956 | // assume the correct data type, and not check): |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 957 | if (!pCount) { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 958 | return VK_ERROR_INVALID_POINTER; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 959 | } |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 960 | |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 961 | if (pSwapChainImages) { |
| 962 | uint32_t i; |
Ian Elliott | e1ea671 | 2015-08-19 16:49:46 -0600 | [diff] [blame] | 963 | for (i = 0; i < *pCount; i++) { |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame] | 964 | pSwapChainImages[i].handle = (uint64_t) sc->persistent_images[i]; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 965 | } |
Ian Elliott | e1ea671 | 2015-08-19 16:49:46 -0600 | [diff] [blame] | 966 | } else { |
| 967 | *pCount = sc->persistent_image_count; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | return ret; |
| 971 | } |
| 972 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 973 | ICD_EXPORT VkResult VKAPI vkAcquireNextImageWSI( |
| 974 | VkDevice device, |
| 975 | VkSwapChainWSI swapChain, |
| 976 | uint64_t timeout, |
| 977 | VkSemaphore semaphore, |
| 978 | uint32_t* pImageIndex) |
| 979 | { |
| 980 | struct intel_x11_swap_chain *sc = x11_swap_chain(swapChain); |
| 981 | VkResult ret = VK_SUCCESS; |
| 982 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 983 | // Find an unused image to return: |
| 984 | for (int i = 0; i < sc->persistent_image_count; i++) { |
| 985 | if (sc->image_state[i] == INTEL_SC_STATE_UNUSED) { |
| 986 | sc->image_state[i] = INTEL_SC_STATE_APP_OWNED; |
| 987 | *pImageIndex = i; |
| 988 | return ret; |
| 989 | } |
| 990 | } |
| 991 | |
Mike Stroyan | f9f6dd7 | 2015-07-28 11:00:50 -0600 | [diff] [blame] | 992 | // If no image is ready, wait for a present to finish |
| 993 | ret = x11_swap_chain_wait(sc, sc->present_serial, timeout); |
| 994 | if (ret != VK_SUCCESS) { |
| 995 | return ret; |
| 996 | } |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 997 | |
Mike Stroyan | f9f6dd7 | 2015-07-28 11:00:50 -0600 | [diff] [blame] | 998 | // Find an unused image to return: |
| 999 | for (int i = 0; i < sc->persistent_image_count; i++) { |
| 1000 | if (sc->image_state[i] == INTEL_SC_STATE_UNUSED) { |
| 1001 | sc->image_state[i] = INTEL_SC_STATE_APP_OWNED; |
| 1002 | *pImageIndex = i; |
| 1003 | return ret; |
| 1004 | } |
| 1005 | } |
| 1006 | // NOTE: Should never get here, but in case we do, do something: |
| 1007 | assert(0); |
| 1008 | return VK_ERROR_UNKNOWN; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1012 | ICD_EXPORT VkResult VKAPI vkQueuePresentWSI( |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1013 | VkQueue queue_, |
| 1014 | VkPresentInfoWSI* pPresentInfo) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 1015 | { |
| 1016 | struct intel_queue *queue = intel_queue(queue_); |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1017 | uint32_t i; |
| 1018 | uint32_t num_swapchains = pPresentInfo->swapChainCount; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 1019 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1020 | for (i = 0; i < num_swapchains; i++) { |
| 1021 | struct intel_x11_swap_chain *sc = |
| 1022 | x11_swap_chain(pPresentInfo->swapChains[i]); |
| 1023 | struct intel_img *img = |
| 1024 | sc->persistent_images[pPresentInfo->imageIndices[i]]; |
| 1025 | struct intel_x11_fence_data *data = |
| 1026 | (struct intel_x11_fence_data *) queue->fence->wsi_data; |
| 1027 | VkResult ret; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 1028 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1029 | ret = x11_swap_chain_present_pixmap(sc, img); |
| 1030 | if (ret != VK_SUCCESS) { |
| 1031 | return ret; |
| 1032 | } |
| 1033 | |
| 1034 | // Record the state change for this image, and add this image to the |
| 1035 | // present queue for the swap chain: |
| 1036 | sc->image_state[pPresentInfo->imageIndices[i]] = |
| 1037 | INTEL_SC_STATE_QUEUED_FOR_PRESENT; |
| 1038 | sc->present_queue[sc->present_queue_length++] = |
| 1039 | pPresentInfo->imageIndices[i]; |
| 1040 | |
| 1041 | data->swap_chain = sc; |
| 1042 | data->serial = sc->local.serial; |
Mike Stroyan | f9f6dd7 | 2015-07-28 11:00:50 -0600 | [diff] [blame] | 1043 | sc->present_serial = sc->local.serial; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1044 | intel_fence_set_seqno(queue->fence, img->obj.mem->bo); |
| 1045 | } |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 1046 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1047 | return VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 1048 | } |