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 = |
| 257 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 258 | |
| 259 | return VK_SUCCESS; |
| 260 | } |
| 261 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 262 | /** |
| 263 | * Return true if DRI3 and Present are supported by the server. |
| 264 | */ |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 265 | 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] | 266 | { |
| 267 | const xcb_query_extension_reply_t *ext; |
| 268 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 269 | xcb_prefetch_extension_data(c, &xcb_dri3_id); |
| 270 | xcb_prefetch_extension_data(c, &xcb_present_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 271 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 272 | ext = xcb_get_extension_data(c, &xcb_dri3_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 273 | if (!ext || !ext->present) |
| 274 | return false; |
| 275 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 276 | ext = xcb_get_extension_data(c, &xcb_present_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 277 | if (!ext || !ext->present) |
| 278 | return false; |
| 279 | |
| 280 | return true; |
| 281 | } |
| 282 | |
| 283 | /** |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 284 | * Send a DRI3Open to get the server GPU fd. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 285 | */ |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 286 | static int x11_dri3_open(xcb_connection_t *c, |
| 287 | xcb_drawable_t drawable, |
| 288 | xcb_randr_provider_t provider) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 289 | { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 290 | xcb_dri3_open_cookie_t cookie; |
| 291 | xcb_dri3_open_reply_t *reply; |
| 292 | int fd; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 293 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 294 | cookie = xcb_dri3_open(c, drawable, provider); |
| 295 | reply = xcb_dri3_open_reply(c, cookie, NULL); |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 296 | if (!reply) |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 297 | return -1; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 298 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 299 | 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] | 300 | free(reply); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 301 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 302 | return fd; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /** |
Chia-I Wu | 030b2db | 2015-04-08 13:46:29 +0800 | [diff] [blame] | 306 | * Send a DRI3PixmapFromBuffer to create a pixmap from \p prime_fd. |
| 307 | */ |
| 308 | static xcb_pixmap_t x11_dri3_pixmap_from_buffer(xcb_connection_t *c, |
| 309 | xcb_drawable_t drawable, |
| 310 | uint8_t depth, int prime_fd, |
| 311 | const struct intel_layout *layout) |
| 312 | { |
| 313 | xcb_pixmap_t pixmap; |
| 314 | |
| 315 | pixmap = xcb_generate_id(c); |
| 316 | |
| 317 | xcb_dri3_pixmap_from_buffer(c, pixmap, drawable, |
| 318 | layout->bo_stride * layout->bo_height, |
| 319 | layout->width0, layout->height0, |
| 320 | layout->bo_stride, depth, |
| 321 | layout->block_size * 8, prime_fd); |
| 322 | |
| 323 | return pixmap; |
| 324 | } |
| 325 | |
| 326 | /** |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 327 | * Send DRI3QueryVersion and PresentQueryVersion to query extension versions. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 328 | */ |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 329 | 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] | 330 | { |
| 331 | xcb_dri3_query_version_cookie_t dri3_cookie; |
| 332 | xcb_dri3_query_version_reply_t *dri3_reply; |
| 333 | xcb_present_query_version_cookie_t present_cookie; |
| 334 | xcb_present_query_version_reply_t *present_reply; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 335 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 336 | dri3_cookie = xcb_dri3_query_version(sc->c, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 337 | XCB_DRI3_MAJOR_VERSION, XCB_DRI3_MINOR_VERSION); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 338 | present_cookie = xcb_present_query_version(sc->c, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 339 | XCB_PRESENT_MAJOR_VERSION, XCB_PRESENT_MINOR_VERSION); |
| 340 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 341 | 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] | 342 | if (!dri3_reply) |
| 343 | return false; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 344 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 345 | sc->dri3_major = dri3_reply->major_version; |
| 346 | sc->dri3_minor = dri3_reply->minor_version; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 347 | free(dri3_reply); |
| 348 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 349 | 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] | 350 | if (!present_reply) |
| 351 | return false; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 352 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 353 | sc->present_major = present_reply->major_version; |
| 354 | sc->present_minor = present_reply->minor_version; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 355 | free(present_reply); |
| 356 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 357 | return true; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /** |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 361 | * Send a PresentSelectInput to select interested events. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 362 | */ |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 363 | 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] | 364 | { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 365 | xcb_void_cookie_t cookie; |
| 366 | xcb_generic_error_t *error; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 367 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 368 | /* create the event queue */ |
| 369 | sc->present_special_event_id = xcb_generate_id(sc->c); |
| 370 | sc->present_special_event = xcb_register_for_special_xge(sc->c, |
| 371 | &xcb_present_id, sc->present_special_event_id, NULL); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 372 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 373 | cookie = xcb_present_select_input_checked(sc->c, |
| 374 | sc->present_special_event_id, sc->window, |
| 375 | XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 376 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 377 | error = xcb_request_check(sc->c, cookie); |
| 378 | if (error) { |
| 379 | free(error); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 380 | return false; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 381 | } |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 382 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 383 | return true; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 384 | } |
| 385 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 386 | static struct intel_img *x11_swap_chain_create_persistent_image(struct intel_x11_swap_chain *sc, |
| 387 | struct intel_dev *dev, |
| 388 | const VkImageCreateInfo *img_info) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 389 | { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 390 | struct intel_img *img; |
| 391 | struct intel_mem *mem; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 392 | struct intel_x11_img_data *data; |
| 393 | VkMemoryAllocInfo mem_info; |
| 394 | int prime_fd; |
| 395 | xcb_pixmap_t pixmap; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 396 | VkResult ret; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 397 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 398 | ret = intel_img_create(dev, img_info, true, &img); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 399 | if (ret != VK_SUCCESS) |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 400 | return NULL; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 401 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 402 | memset(&mem_info, 0, sizeof(mem_info)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 403 | mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 404 | mem_info.allocationSize = img->total_size; |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 405 | mem_info.memoryTypeIndex = 0; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 406 | |
| 407 | ret = intel_mem_alloc(dev, &mem_info, &mem); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 408 | if (ret != VK_SUCCESS) { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 409 | intel_img_destroy(img); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 410 | return NULL; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 411 | } |
| 412 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 413 | prime_fd = x11_export_prime_fd(dev, mem->bo, &img->layout); |
| 414 | if (prime_fd < 0) { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 415 | intel_mem_free(mem); |
| 416 | intel_img_destroy(img); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 417 | return NULL; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 418 | } |
| 419 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 420 | pixmap = x11_dri3_pixmap_from_buffer(sc->c, sc->window, |
| 421 | x11_get_drawable_depth(sc->c, sc->window), |
| 422 | prime_fd, &img->layout); |
| 423 | |
| 424 | data = (struct intel_x11_img_data *) img->wsi_data; |
| 425 | data->swap_chain = sc; |
| 426 | data->mem = mem; |
| 427 | data->prime_fd = prime_fd; |
| 428 | data->pixmap = pixmap; |
| 429 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 430 | intel_obj_bind_mem(&img->obj, mem, 0); |
| 431 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 432 | return img; |
| 433 | } |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 434 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 435 | static bool x11_swap_chain_create_persistent_images(struct intel_x11_swap_chain *sc, |
| 436 | struct intel_dev *dev, |
| 437 | const VkSwapChainCreateInfoWSI *info) |
| 438 | { |
| 439 | struct intel_img **images; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 440 | intel_x11_swap_chain_image_state *image_state; |
| 441 | uint32_t *present_queue; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 442 | VkImageCreateInfo img_info; |
| 443 | uint32_t i; |
| 444 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 445 | images = intel_alloc(sc, sizeof(*images) * info->minImageCount, |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 446 | 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
| 447 | if (!images) |
| 448 | return false; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 449 | image_state = intel_alloc( |
| 450 | sc, sizeof(intel_x11_swap_chain_image_state) * info->minImageCount, |
| 451 | 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
| 452 | if (!image_state) { |
| 453 | for (i = 0; i < info->minImageCount; i++) { |
| 454 | intel_img_destroy(images[i]); |
| 455 | } |
| 456 | intel_free(sc, images); |
| 457 | return false; |
| 458 | } |
| 459 | present_queue = intel_alloc( |
| 460 | sc, sizeof(uint32_t) * info->minImageCount, |
| 461 | 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
| 462 | if (!present_queue) { |
| 463 | for (i = 0; i < info->minImageCount; i++) { |
| 464 | intel_img_destroy(images[i]); |
| 465 | } |
| 466 | intel_free(sc, images); |
| 467 | intel_free(sc, image_state); |
| 468 | return false; |
| 469 | } |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 470 | |
| 471 | memset(&img_info, 0, sizeof(img_info)); |
| 472 | img_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 473 | img_info.imageType = VK_IMAGE_TYPE_2D; |
| 474 | img_info.format = info->imageFormat; |
| 475 | img_info.extent.width = info->imageExtent.width; |
| 476 | img_info.extent.height = info->imageExtent.height; |
| 477 | img_info.extent.depth = 1; |
| 478 | img_info.mipLevels = 1; |
| 479 | img_info.arraySize = info->imageArraySize; |
| 480 | img_info.samples = 1; |
| 481 | img_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 482 | img_info.usage = info->imageUsageFlags; |
| 483 | img_info.flags = 0; |
| 484 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 485 | for (i = 0; i < info->minImageCount; i++) { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 486 | images[i] = x11_swap_chain_create_persistent_image(sc, |
| 487 | dev, &img_info); |
| 488 | if (!images[i]) |
| 489 | break; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 490 | image_state[i] = INTEL_SC_STATE_UNUSED; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 491 | } |
| 492 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 493 | if (i < info->minImageCount) { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 494 | uint32_t j; |
| 495 | for (j = 0; j < i; j++) |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 496 | intel_img_destroy(images[j]); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 497 | |
| 498 | intel_free(sc, images); |
| 499 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 500 | if (image_state) { |
| 501 | intel_free(sc, image_state); |
| 502 | } |
| 503 | |
| 504 | if (present_queue) { |
| 505 | intel_free(sc, present_queue); |
| 506 | } |
| 507 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 508 | return false; |
| 509 | } |
| 510 | |
| 511 | sc->persistent_images = images; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 512 | sc->persistent_image_count = info->minImageCount; |
| 513 | sc->image_state = image_state; |
| 514 | sc->present_queue = present_queue; |
| 515 | sc->present_queue_length = 0; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 516 | |
| 517 | return true; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /** |
| 521 | * Send a PresentPixmap. |
| 522 | */ |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 523 | 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] | 524 | struct intel_img *img) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 525 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 526 | struct intel_x11_img_data *data = |
| 527 | (struct intel_x11_img_data *) img->wsi_data; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 528 | uint32_t options = XCB_PRESENT_OPTION_NONE; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 529 | uint32_t target_msc, divisor, remainder; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 530 | xcb_void_cookie_t cookie; |
| 531 | xcb_generic_error_t *err; |
| 532 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 533 | target_msc = 0; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 534 | divisor = 1; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 535 | remainder = 0; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 536 | if (sc->present_mode == VK_PRESENT_MODE_IMMEDIATE_WSI) { |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 537 | options |= XCB_PRESENT_OPTION_ASYNC; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 538 | } |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 539 | |
| 540 | if (sc->force_copy) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 541 | options |= XCB_PRESENT_OPTION_COPY; |
| 542 | |
Chia-I Wu | f689c60 | 2015-04-28 10:55:52 +0800 | [diff] [blame] | 543 | cookie = xcb_present_pixmap_checked(sc->c, |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 544 | sc->window, |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 545 | data->pixmap, |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 546 | ++sc->local.serial, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 547 | 0, /* valid-area */ |
| 548 | 0, /* update-area */ |
| 549 | 0, /* x-off */ |
| 550 | 0, /* y-off */ |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 551 | 0, /* crtc */ |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 552 | 0, /* wait-fence */ |
| 553 | 0, /* idle-fence */ |
| 554 | options, |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 555 | target_msc, |
| 556 | divisor, |
| 557 | remainder, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 558 | 0, NULL); |
| 559 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 560 | err = xcb_request_check(sc->c, cookie); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 561 | if (err) { |
| 562 | free(err); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 563 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 564 | } |
| 565 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 566 | return VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /** |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 570 | * Handle a Present event. |
| 571 | */ |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 572 | static void x11_swap_chain_present_event(struct intel_x11_swap_chain *sc, |
| 573 | const xcb_present_generic_event_t *ev) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 574 | { |
| 575 | union { |
| 576 | const xcb_present_generic_event_t *ev; |
| 577 | const xcb_present_complete_notify_event_t *complete; |
| 578 | } u = { .ev = ev }; |
| 579 | |
| 580 | switch (u.ev->evtype) { |
| 581 | case XCB_PRESENT_COMPLETE_NOTIFY: |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 582 | sc->remote.serial = u.complete->serial; |
| 583 | sc->remote.msc = u.complete->msc; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 584 | assert(sc->present_queue_length > 0); |
| 585 | if (sc->image_state[sc->present_queue[0]] == INTEL_SC_STATE_DISPLAYED) { |
| 586 | // Remove the previously-displayed image from the present queue: |
| 587 | sc->image_state[sc->present_queue[0]] = INTEL_SC_STATE_UNUSED; |
| 588 | sc->present_queue_length--; |
| 589 | for (int j = 0; j < sc->present_queue_length; j++) { |
| 590 | sc->present_queue[j] = sc->present_queue[j+1]; |
| 591 | } |
| 592 | } |
| 593 | assert(sc->present_queue_length > 0); |
| 594 | assert(sc->image_state[sc->present_queue[0]] == INTEL_SC_STATE_QUEUED_FOR_PRESENT); |
| 595 | sc->image_state[sc->present_queue[0]] = INTEL_SC_STATE_DISPLAYED; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 596 | break; |
| 597 | default: |
| 598 | break; |
| 599 | } |
| 600 | } |
| 601 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 602 | 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] | 603 | uint32_t serial, int64_t timeout) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 604 | { |
| 605 | const bool wait = (timeout != 0); |
| 606 | |
| 607 | while (sc->remote.serial < serial) { |
| 608 | xcb_present_generic_event_t *ev; |
Mike Stroyan | 4a38716 | 2015-04-27 15:42:41 -0600 | [diff] [blame] | 609 | xcb_intern_atom_reply_t *reply; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 610 | |
| 611 | if (wait) { |
| 612 | ev = (xcb_present_generic_event_t *) |
| 613 | xcb_wait_for_special_event(sc->c, sc->present_special_event); |
Mike Stroyan | 4a38716 | 2015-04-27 15:42:41 -0600 | [diff] [blame] | 614 | /* use xcb_intern_atom_reply just to wake other threads waiting on sc->c */ |
| 615 | reply = xcb_intern_atom_reply(sc->c, xcb_intern_atom(sc->c, 1, 1, "a"), NULL); |
| 616 | if (reply) { |
| 617 | free(reply); |
| 618 | } |
| 619 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 620 | if (!ev) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 621 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 622 | } else { |
Mike Stroyan | 4a38716 | 2015-04-27 15:42:41 -0600 | [diff] [blame] | 623 | /* use xcb_intern_atom_reply just to check socket for special event */ |
| 624 | reply = xcb_intern_atom_reply(sc->c, xcb_intern_atom(sc->c, 1, 1, "a"), NULL); |
| 625 | if (reply) { |
| 626 | free(reply); |
| 627 | } |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 628 | ev = (xcb_present_generic_event_t *) |
| 629 | xcb_poll_for_special_event(sc->c, sc->present_special_event); |
| 630 | if (!ev) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 631 | return VK_NOT_READY; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | x11_swap_chain_present_event(sc, ev); |
| 635 | |
| 636 | free(ev); |
| 637 | } |
| 638 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 639 | return VK_SUCCESS; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 640 | } |
| 641 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 642 | 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] | 643 | { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 644 | if (sc->persistent_images) { |
| 645 | uint32_t i; |
| 646 | |
| 647 | for (i = 0; i < sc->persistent_image_count; i++) |
| 648 | intel_img_destroy(sc->persistent_images[i]); |
| 649 | intel_free(sc, sc->persistent_images); |
| 650 | } |
| 651 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 652 | if (sc->image_state) { |
| 653 | intel_free(sc, sc->image_state); |
| 654 | } |
| 655 | |
| 656 | if (sc->present_queue) { |
| 657 | intel_free(sc, sc->present_queue); |
| 658 | } |
| 659 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 660 | if (sc->present_special_event) |
| 661 | xcb_unregister_for_special_event(sc->c, sc->present_special_event); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 662 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 663 | intel_free(sc, sc); |
| 664 | } |
| 665 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 666 | static VkResult x11_swap_chain_create(struct intel_dev *dev, |
| 667 | const VkSwapChainCreateInfoWSI *info, |
| 668 | struct intel_x11_swap_chain **sc_ret) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 669 | { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 670 | const xcb_randr_provider_t provider = 0; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 671 | const VkSurfaceDescriptionWindowWSI* pSurfaceDescriptionWindow = |
| 672 | (VkSurfaceDescriptionWindowWSI*) info->pSurfaceDescription; |
| 673 | VkPlatformHandleXcbWSI *pPlatformHandleXcb = (VkPlatformHandleXcbWSI *) |
| 674 | pSurfaceDescriptionWindow->pPlatformHandle; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 675 | xcb_connection_t *c = (xcb_connection_t *) |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 676 | pPlatformHandleXcb->connection; |
| 677 | xcb_window_t window = *((xcb_window_t *) |
| 678 | pSurfaceDescriptionWindow->pPlatformWindow); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 679 | struct intel_x11_swap_chain *sc; |
| 680 | int fd; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 681 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 682 | if (!x11_is_format_presentable(dev, info->imageFormat)) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 683 | intel_dev_log(dev, VK_DBG_REPORT_ERROR_BIT, |
| 684 | VK_NULL_HANDLE, 0, 0, "invalid presentable image format"); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 685 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 686 | } |
| 687 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 688 | if (!x11_is_dri3_and_present_supported(c)) |
| 689 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 690 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 691 | fd = x11_dri3_open(c, window, provider); |
| 692 | if (fd < 0 || !x11_gpu_match_fd(dev->gpu, fd)) { |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 693 | if (fd >= 0) |
| 694 | close(fd); |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 695 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 696 | } |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 697 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 698 | close(fd); |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 699 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 700 | 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] | 701 | if (!sc) |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 702 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 703 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 704 | memset(sc, 0, sizeof(*sc)); |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 705 | 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] | 706 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 707 | sc->c = c; |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 708 | sc->window = window; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 709 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 710 | /* always copy unless flip bit is set */ |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 711 | sc->present_mode = info->presentMode; |
| 712 | sc->force_copy = true; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 713 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 714 | if (!x11_swap_chain_dri3_and_present_query_version(sc) || |
| 715 | !x11_swap_chain_present_select_input(sc) || |
| 716 | !x11_swap_chain_create_persistent_images(sc, dev, info)) { |
| 717 | x11_swap_chain_destroy(sc); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 718 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 719 | } |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 720 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 721 | *sc_ret = sc; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 722 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 723 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 724 | } |
| 725 | |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 726 | static void x11_display_destroy(struct intel_x11_display *dpy) |
| 727 | { |
| 728 | intel_free(dpy, dpy->modes); |
| 729 | intel_free(dpy, dpy); |
| 730 | } |
| 731 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 732 | void intel_wsi_gpu_cleanup(struct intel_gpu *gpu) |
| 733 | { |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 734 | if (gpu->displays) { |
| 735 | uint32_t i; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 736 | |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 737 | for (i = 0; i < gpu->display_count; i++) { |
| 738 | struct intel_x11_display *dpy = |
| 739 | (struct intel_x11_display *) gpu->displays[i]; |
| 740 | x11_display_destroy(dpy); |
| 741 | } |
| 742 | intel_free(gpu, gpu->displays); |
| 743 | } |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 744 | } |
| 745 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 746 | VkResult intel_wsi_img_init(struct intel_img *img) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 747 | { |
| 748 | struct intel_x11_img_data *data; |
| 749 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 750 | 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] | 751 | if (!data) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 752 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 753 | |
| 754 | memset(data, 0, sizeof(*data)); |
| 755 | |
| 756 | assert(!img->wsi_data); |
| 757 | img->wsi_data = data; |
| 758 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 759 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | void intel_wsi_img_cleanup(struct intel_img *img) |
| 763 | { |
| 764 | struct intel_x11_img_data *data = |
| 765 | (struct intel_x11_img_data *) img->wsi_data; |
| 766 | |
| 767 | if (data->mem) { |
| 768 | close(data->prime_fd); |
| 769 | intel_mem_free(data->mem); |
| 770 | } |
| 771 | |
| 772 | intel_free(img, img->wsi_data); |
| 773 | } |
| 774 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 775 | VkResult intel_wsi_fence_init(struct intel_fence *fence) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 776 | { |
| 777 | struct intel_x11_fence_data *data; |
| 778 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 779 | 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] | 780 | if (!data) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 781 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 782 | |
| 783 | memset(data, 0, sizeof(*data)); |
| 784 | |
| 785 | assert(!fence->wsi_data); |
| 786 | fence->wsi_data = data; |
| 787 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 788 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | void intel_wsi_fence_cleanup(struct intel_fence *fence) |
| 792 | { |
| 793 | intel_free(fence, fence->wsi_data); |
| 794 | } |
| 795 | |
| 796 | void intel_wsi_fence_copy(struct intel_fence *fence, |
| 797 | const struct intel_fence *src) |
| 798 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 799 | if (!fence->wsi_data) { |
| 800 | return; |
| 801 | } |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 802 | memcpy(fence->wsi_data, src->wsi_data, |
| 803 | sizeof(struct intel_x11_fence_data)); |
| 804 | } |
| 805 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 806 | VkResult intel_wsi_fence_wait(struct intel_fence *fence, |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 807 | int64_t timeout_ns) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 808 | { |
| 809 | struct intel_x11_fence_data *data = |
| 810 | (struct intel_x11_fence_data *) fence->wsi_data; |
| 811 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 812 | if (!data) |
| 813 | return VK_SUCCESS; |
| 814 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 815 | if (!data->swap_chain) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 816 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 817 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 818 | 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] | 819 | } |
| 820 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 821 | ICD_EXPORT VkResult VKAPI vkGetPhysicalDeviceSurfaceSupportWSI( |
| 822 | VkPhysicalDevice physicalDevice, |
| 823 | uint32_t queueNodeIndex, |
| 824 | const VkSurfaceDescriptionWSI* pSurfaceDescription, |
| 825 | VkBool32* pSupported) |
| 826 | { |
| 827 | VkResult ret = VK_SUCCESS; |
| 828 | const VkSurfaceDescriptionWindowWSI* pSurfaceDescriptionWindow = |
| 829 | (VkSurfaceDescriptionWindowWSI*) pSurfaceDescription; |
| 830 | |
| 831 | *pSupported = false; |
| 832 | |
| 833 | // TODO: Move this check to a validation layer (i.e. the driver should |
| 834 | // assume the correct data type, and not check): |
| 835 | if (pSurfaceDescriptionWindow->sType != VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI) { |
| 836 | return VK_ERROR_INVALID_VALUE; |
| 837 | } |
| 838 | |
| 839 | // TODO: NEED TO ALSO CHECK: |
| 840 | // - queueNodeIndex |
| 841 | // - pSurfaceDescriptionWindow->pPlatformHandle (can try to use it) |
| 842 | // - pSurfaceDescriptionWindow->pPlatformWindow (can try to use it) |
| 843 | if (pSurfaceDescriptionWindow->platform == VK_PLATFORM_XCB_WSI) { |
| 844 | *pSupported = true; |
| 845 | } |
| 846 | |
| 847 | return ret; |
| 848 | } |
| 849 | |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame^] | 850 | VkResult VKAPI vkGetSurfacePropertiesWSI( |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 851 | VkDevice device, |
| 852 | const VkSurfaceDescriptionWSI* pSurfaceDescription, |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame^] | 853 | VkSurfacePropertiesWSI* pSurfaceProperties) |
| 854 | { |
| 855 | // TODO: Move this check to a validation layer (i.e. the driver should |
| 856 | // assume the correct data type, and not check): |
| 857 | assert(pSurfaceProperties); |
| 858 | |
| 859 | return x11_get_surface_properties(pSurfaceDescription, pSurfaceProperties); |
| 860 | } |
| 861 | |
| 862 | VkResult VKAPI vkGetSurfaceFormatsWSI( |
| 863 | VkDevice device, |
| 864 | const VkSurfaceDescriptionWSI* pSurfaceDescription, |
| 865 | uint32_t* pCount, |
| 866 | VkSurfaceFormatWSI* pSurfaceFormats) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 867 | { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 868 | VkResult ret = VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 869 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 870 | // TODO: Move this check to a validation layer (i.e. the driver should |
| 871 | // assume the correct data type, and not check): |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame^] | 872 | if (!pCount) { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 873 | return VK_ERROR_INVALID_POINTER; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 874 | } |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 875 | |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame^] | 876 | *pCount = ARRAY_SIZE(x11_presentable_formats); |
| 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 | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame^] | 883 | } |
| 884 | |
| 885 | return ret; |
| 886 | } |
| 887 | |
| 888 | VkResult VKAPI vkGetSurfacePresentModesWSI( |
| 889 | VkDevice device, |
| 890 | const VkSurfaceDescriptionWSI* pSurfaceDescription, |
| 891 | uint32_t* pCount, |
| 892 | VkPresentModeWSI* pPresentModes) |
| 893 | { |
| 894 | VkResult ret = VK_SUCCESS; |
| 895 | |
| 896 | // TODO: Move this check to a validation layer (i.e. the driver should |
| 897 | // assume the correct data type, and not check): |
| 898 | if (!pCount) { |
| 899 | return VK_ERROR_INVALID_POINTER; |
| 900 | } |
| 901 | |
| 902 | *pCount = 2; |
| 903 | if (pPresentModes) { |
| 904 | pPresentModes[0] = VK_PRESENT_MODE_IMMEDIATE_WSI; |
| 905 | pPresentModes[1] = VK_PRESENT_MODE_FIFO_WSI; |
| 906 | // TODO: Consider adding VK_PRESENT_MODE_MAILBOX_WSI sometime |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | return ret; |
| 910 | } |
| 911 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 912 | ICD_EXPORT VkResult VKAPI vkCreateSwapChainWSI( |
| 913 | VkDevice device, |
| 914 | const VkSwapChainCreateInfoWSI* pCreateInfo, |
| 915 | VkSwapChainWSI* pSwapChain) |
| 916 | { |
| 917 | struct intel_dev *dev = intel_dev(device); |
| 918 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 919 | if (pCreateInfo->oldSwapChain.handle) { |
| 920 | // TODO: Eventually, do more than simply up-front destroy the |
| 921 | // oldSwapChain (but just do that for now): |
| 922 | struct intel_x11_swap_chain *sc = |
| 923 | x11_swap_chain(pCreateInfo->oldSwapChain); |
| 924 | |
| 925 | x11_swap_chain_destroy(sc); |
| 926 | } |
| 927 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 928 | return x11_swap_chain_create(dev, pCreateInfo, |
| 929 | (struct intel_x11_swap_chain **) pSwapChain); |
| 930 | } |
| 931 | |
| 932 | ICD_EXPORT VkResult VKAPI vkDestroySwapChainWSI( |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 933 | VkDevice device, |
| 934 | VkSwapChainWSI swapChain) |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 935 | { |
| 936 | struct intel_x11_swap_chain *sc = x11_swap_chain(swapChain); |
| 937 | |
| 938 | x11_swap_chain_destroy(sc); |
| 939 | |
| 940 | return VK_SUCCESS; |
| 941 | } |
| 942 | |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame^] | 943 | ICD_EXPORT VkResult VKAPI vkGetSwapChainImagesWSI( |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 944 | VkDevice device, |
| 945 | VkSwapChainWSI swapChain, |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame^] | 946 | uint32_t* pCount, |
| 947 | VkImage* pSwapChainImages) |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 948 | { |
| 949 | struct intel_x11_swap_chain *sc = x11_swap_chain(swapChain); |
| 950 | VkResult ret = VK_SUCCESS; |
| 951 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 952 | // TODO: Move this check to a validation layer (i.e. the driver should |
| 953 | // assume the correct data type, and not check): |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame^] | 954 | if (!pCount) { |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 955 | return VK_ERROR_INVALID_POINTER; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 956 | } |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 957 | |
Ian Elliott | ebda989 | 2015-08-06 17:35:06 -0600 | [diff] [blame^] | 958 | *pCount = sc->persistent_image_count; |
| 959 | if (pSwapChainImages) { |
| 960 | uint32_t i; |
| 961 | for (i = 0; i < sc->persistent_image_count; i++) { |
| 962 | pSwapChainImages[i].handle = (uint64_t) sc->persistent_images[i]; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 963 | } |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | return ret; |
| 967 | } |
| 968 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 969 | ICD_EXPORT VkResult VKAPI vkAcquireNextImageWSI( |
| 970 | VkDevice device, |
| 971 | VkSwapChainWSI swapChain, |
| 972 | uint64_t timeout, |
| 973 | VkSemaphore semaphore, |
| 974 | uint32_t* pImageIndex) |
| 975 | { |
| 976 | struct intel_x11_swap_chain *sc = x11_swap_chain(swapChain); |
| 977 | VkResult ret = VK_SUCCESS; |
| 978 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 979 | // Find an unused image to return: |
| 980 | for (int i = 0; i < sc->persistent_image_count; i++) { |
| 981 | if (sc->image_state[i] == INTEL_SC_STATE_UNUSED) { |
| 982 | sc->image_state[i] = INTEL_SC_STATE_APP_OWNED; |
| 983 | *pImageIndex = i; |
| 984 | return ret; |
| 985 | } |
| 986 | } |
| 987 | |
Mike Stroyan | f9f6dd7 | 2015-07-28 11:00:50 -0600 | [diff] [blame] | 988 | // If no image is ready, wait for a present to finish |
| 989 | ret = x11_swap_chain_wait(sc, sc->present_serial, timeout); |
| 990 | if (ret != VK_SUCCESS) { |
| 991 | return ret; |
| 992 | } |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 993 | |
Mike Stroyan | f9f6dd7 | 2015-07-28 11:00:50 -0600 | [diff] [blame] | 994 | // Find an unused image to return: |
| 995 | for (int i = 0; i < sc->persistent_image_count; i++) { |
| 996 | if (sc->image_state[i] == INTEL_SC_STATE_UNUSED) { |
| 997 | sc->image_state[i] = INTEL_SC_STATE_APP_OWNED; |
| 998 | *pImageIndex = i; |
| 999 | return ret; |
| 1000 | } |
| 1001 | } |
| 1002 | // NOTE: Should never get here, but in case we do, do something: |
| 1003 | assert(0); |
| 1004 | return VK_ERROR_UNKNOWN; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1008 | ICD_EXPORT VkResult VKAPI vkQueuePresentWSI( |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1009 | VkQueue queue_, |
| 1010 | VkPresentInfoWSI* pPresentInfo) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 1011 | { |
| 1012 | struct intel_queue *queue = intel_queue(queue_); |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1013 | uint32_t i; |
| 1014 | uint32_t num_swapchains = pPresentInfo->swapChainCount; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 1015 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1016 | for (i = 0; i < num_swapchains; i++) { |
| 1017 | struct intel_x11_swap_chain *sc = |
| 1018 | x11_swap_chain(pPresentInfo->swapChains[i]); |
| 1019 | struct intel_img *img = |
| 1020 | sc->persistent_images[pPresentInfo->imageIndices[i]]; |
| 1021 | struct intel_x11_fence_data *data = |
| 1022 | (struct intel_x11_fence_data *) queue->fence->wsi_data; |
| 1023 | VkResult ret; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 1024 | |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1025 | ret = x11_swap_chain_present_pixmap(sc, img); |
| 1026 | if (ret != VK_SUCCESS) { |
| 1027 | return ret; |
| 1028 | } |
| 1029 | |
| 1030 | // Record the state change for this image, and add this image to the |
| 1031 | // present queue for the swap chain: |
| 1032 | sc->image_state[pPresentInfo->imageIndices[i]] = |
| 1033 | INTEL_SC_STATE_QUEUED_FOR_PRESENT; |
| 1034 | sc->present_queue[sc->present_queue_length++] = |
| 1035 | pPresentInfo->imageIndices[i]; |
| 1036 | |
| 1037 | data->swap_chain = sc; |
| 1038 | data->serial = sc->local.serial; |
Mike Stroyan | f9f6dd7 | 2015-07-28 11:00:50 -0600 | [diff] [blame] | 1039 | sc->present_serial = sc->local.serial; |
Ian Elliott | 4f29936 | 2015-07-06 14:45:11 -0600 | [diff] [blame] | 1040 | intel_fence_set_seqno(queue->fence, img->obj.mem->bo); |
| 1041 | } |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 1042 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1043 | return VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 1044 | } |