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> |
| 26 | */ |
| 27 | |
| 28 | #include <sys/types.h> |
| 29 | #include <sys/stat.h> |
| 30 | #include <unistd.h> |
| 31 | #include <fcntl.h> |
| 32 | #include <xcb/xcb.h> |
| 33 | #include <xcb/dri3.h> |
| 34 | #include <xcb/present.h> |
| 35 | |
| 36 | #include "kmd/winsys.h" |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 37 | #include "kmd/libdrm/xf86drmMode.h" |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 38 | #include "dev.h" |
| 39 | #include "fence.h" |
| 40 | #include "gpu.h" |
| 41 | #include "img.h" |
| 42 | #include "mem.h" |
| 43 | #include "queue.h" |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 44 | #include "wsi.h" |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 45 | |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 46 | struct intel_x11_display { |
| 47 | struct intel_handle handle; |
| 48 | |
| 49 | int fd; |
| 50 | uint32_t connector_id; |
| 51 | |
| 52 | char name[32]; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 53 | VkExtent2D physical_dimension; |
| 54 | VkExtent2D physical_resolution; |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 55 | |
| 56 | drmModeModeInfoPtr modes; |
| 57 | uint32_t mode_count; |
| 58 | }; |
| 59 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 60 | struct intel_x11_swap_chain { |
| 61 | struct intel_handle handle; |
| 62 | |
| 63 | xcb_connection_t *c; |
| 64 | xcb_window_t window; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 65 | |
| 66 | xcb_present_event_t present_special_event_id; |
| 67 | xcb_special_event_t *present_special_event; |
| 68 | |
| 69 | struct { |
| 70 | uint32_t serial; |
| 71 | } local; |
| 72 | |
| 73 | struct { |
| 74 | uint32_t serial; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 75 | uint64_t msc; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 76 | } remote; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 77 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 78 | struct intel_x11_swap_chain *next; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | struct intel_wsi_x11 { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 82 | struct intel_handle handle; |
| 83 | |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 84 | xcb_connection_t *c; |
| 85 | xcb_window_t root; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 86 | int root_depth; |
| 87 | |
| 88 | int dri3_major, dri3_minor; |
| 89 | int present_major, present_minor; |
| 90 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 91 | struct intel_x11_swap_chain *swap_chains; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 92 | }; |
| 93 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 94 | struct intel_x11_img_data { |
| 95 | struct intel_mem *mem; |
| 96 | int prime_fd; |
| 97 | uint32_t pixmap; |
| 98 | }; |
| 99 | |
| 100 | struct intel_x11_fence_data { |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +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 | uint32_t serial; |
| 103 | }; |
| 104 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 105 | static bool x11_is_format_presentable(const struct intel_dev *dev, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 106 | VkFormat format) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 107 | { |
| 108 | /* this is what DDX expects */ |
| 109 | switch (format) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 110 | case VK_FORMAT_B5G6R5_UNORM: |
| 111 | case VK_FORMAT_B8G8R8A8_UNORM: |
| 112 | case VK_FORMAT_B8G8R8A8_SRGB: |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 113 | return true; |
| 114 | default: |
| 115 | return false; |
| 116 | } |
| 117 | } |
| 118 | |
Chia-I Wu | 030b2db | 2015-04-08 13:46:29 +0800 | [diff] [blame] | 119 | static int x11_export_prime_fd(struct intel_dev *dev, |
| 120 | struct intel_bo *bo, |
| 121 | const struct intel_layout *layout) |
| 122 | { |
| 123 | struct intel_winsys_handle export; |
| 124 | enum intel_tiling_mode tiling; |
| 125 | |
| 126 | export.type = INTEL_WINSYS_HANDLE_FD; |
| 127 | |
| 128 | switch (layout->tiling) { |
| 129 | case GEN6_TILING_X: |
| 130 | tiling = INTEL_TILING_X; |
| 131 | break; |
| 132 | case GEN6_TILING_Y: |
| 133 | tiling = INTEL_TILING_Y; |
| 134 | break; |
| 135 | default: |
| 136 | assert(layout->tiling == GEN6_TILING_NONE); |
| 137 | tiling = INTEL_TILING_NONE; |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | if (intel_bo_set_tiling(bo, tiling, layout->bo_stride)) |
| 142 | return -1; |
| 143 | |
| 144 | if (intel_winsys_export_handle(dev->winsys, bo, tiling, |
| 145 | layout->bo_stride, layout->bo_height, &export)) |
| 146 | return -1; |
| 147 | |
| 148 | return (int) export.handle; |
| 149 | } |
| 150 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 151 | /** |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 152 | * 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] | 153 | */ |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 154 | 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] | 155 | { |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 156 | struct stat fd_stat, gpu_stat; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 157 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 158 | if (fstat(fd, &fd_stat)) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 159 | return false; |
| 160 | |
| 161 | /* is it the primary node? */ |
| 162 | if (!stat(gpu->primary_node, &gpu_stat) && |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 163 | !memcmp(&fd_stat, &gpu_stat, sizeof(fd_stat))) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 164 | return true; |
| 165 | |
| 166 | /* is it the render node? */ |
| 167 | if (gpu->render_node && !stat(gpu->render_node, &gpu_stat) && |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 168 | !memcmp(&fd_stat, &gpu_stat, sizeof(fd_stat))) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 169 | return true; |
| 170 | |
| 171 | return false; |
| 172 | } |
| 173 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 174 | /* |
| 175 | * Return the depth of \p drawable. |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 176 | */ |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 177 | static int x11_get_drawable_depth(xcb_connection_t *c, |
| 178 | xcb_drawable_t drawable) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 179 | { |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 180 | xcb_get_geometry_cookie_t cookie; |
| 181 | xcb_get_geometry_reply_t *reply; |
| 182 | uint8_t depth; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 183 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 184 | cookie = xcb_get_geometry(c, drawable); |
| 185 | reply = xcb_get_geometry_reply(c, cookie, NULL); |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 186 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 187 | if (reply) { |
| 188 | depth = reply->depth; |
| 189 | free(reply); |
| 190 | } else { |
| 191 | depth = 0; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 192 | } |
| 193 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 194 | return depth; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 195 | } |
| 196 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 197 | /** |
| 198 | * Return true if DRI3 and Present are supported by the server. |
| 199 | */ |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 200 | 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] | 201 | { |
| 202 | const xcb_query_extension_reply_t *ext; |
| 203 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 204 | xcb_prefetch_extension_data(c, &xcb_dri3_id); |
| 205 | xcb_prefetch_extension_data(c, &xcb_present_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 206 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 207 | ext = xcb_get_extension_data(c, &xcb_dri3_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 208 | if (!ext || !ext->present) |
| 209 | return false; |
| 210 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 211 | ext = xcb_get_extension_data(c, &xcb_present_id); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 212 | if (!ext || !ext->present) |
| 213 | return false; |
| 214 | |
| 215 | return true; |
| 216 | } |
| 217 | |
| 218 | /** |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 219 | * Send a DRI3Open to get the server GPU fd. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 220 | */ |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 221 | static int x11_dri3_open(xcb_connection_t *c, |
| 222 | xcb_drawable_t drawable, |
| 223 | xcb_randr_provider_t provider) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 224 | { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 225 | xcb_dri3_open_cookie_t cookie; |
| 226 | xcb_dri3_open_reply_t *reply; |
| 227 | int fd; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 228 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 229 | cookie = xcb_dri3_open(c, drawable, provider); |
| 230 | reply = xcb_dri3_open_reply(c, cookie, NULL); |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 231 | if (!reply) |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 232 | return -1; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 233 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 234 | 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] | 235 | free(reply); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 236 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 237 | return fd; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /** |
Chia-I Wu | 030b2db | 2015-04-08 13:46:29 +0800 | [diff] [blame] | 241 | * Send a DRI3PixmapFromBuffer to create a pixmap from \p prime_fd. |
| 242 | */ |
| 243 | static xcb_pixmap_t x11_dri3_pixmap_from_buffer(xcb_connection_t *c, |
| 244 | xcb_drawable_t drawable, |
| 245 | uint8_t depth, int prime_fd, |
| 246 | const struct intel_layout *layout) |
| 247 | { |
| 248 | xcb_pixmap_t pixmap; |
| 249 | |
| 250 | pixmap = xcb_generate_id(c); |
| 251 | |
| 252 | xcb_dri3_pixmap_from_buffer(c, pixmap, drawable, |
| 253 | layout->bo_stride * layout->bo_height, |
| 254 | layout->width0, layout->height0, |
| 255 | layout->bo_stride, depth, |
| 256 | layout->block_size * 8, prime_fd); |
| 257 | |
| 258 | return pixmap; |
| 259 | } |
| 260 | |
| 261 | /** |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 262 | * Send DRI3QueryVersion and PresentQueryVersion to query extension versions. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 263 | */ |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 264 | static bool wsi_x11_dri3_and_present_query_version(struct intel_wsi_x11 *x11) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 265 | { |
| 266 | xcb_dri3_query_version_cookie_t dri3_cookie; |
| 267 | xcb_dri3_query_version_reply_t *dri3_reply; |
| 268 | xcb_present_query_version_cookie_t present_cookie; |
| 269 | xcb_present_query_version_reply_t *present_reply; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 270 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 271 | dri3_cookie = xcb_dri3_query_version(x11->c, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 272 | XCB_DRI3_MAJOR_VERSION, XCB_DRI3_MINOR_VERSION); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 273 | present_cookie = xcb_present_query_version(x11->c, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 274 | XCB_PRESENT_MAJOR_VERSION, XCB_PRESENT_MINOR_VERSION); |
| 275 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 276 | dri3_reply = xcb_dri3_query_version_reply(x11->c, dri3_cookie, NULL); |
| 277 | if (!dri3_reply) |
| 278 | return false; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 279 | |
| 280 | x11->dri3_major = dri3_reply->major_version; |
| 281 | x11->dri3_minor = dri3_reply->minor_version; |
| 282 | free(dri3_reply); |
| 283 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 284 | present_reply = xcb_present_query_version_reply(x11->c, present_cookie, NULL); |
| 285 | if (!present_reply) |
| 286 | return false; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 287 | |
| 288 | x11->present_major = present_reply->major_version; |
| 289 | x11->present_minor = present_reply->minor_version; |
| 290 | free(present_reply); |
| 291 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 292 | return true; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 296 | * Send a PresentSelectInput to select interested events. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 297 | */ |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 298 | static VkResult 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] | 299 | { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 300 | xcb_void_cookie_t cookie; |
| 301 | xcb_generic_error_t *error; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 302 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 303 | /* create the event queue */ |
| 304 | sc->present_special_event_id = xcb_generate_id(sc->c); |
| 305 | sc->present_special_event = xcb_register_for_special_xge(sc->c, |
| 306 | &xcb_present_id, sc->present_special_event_id, NULL); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 307 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 308 | cookie = xcb_present_select_input_checked(sc->c, |
| 309 | sc->present_special_event_id, sc->window, |
| 310 | XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 311 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 312 | error = xcb_request_check(sc->c, cookie); |
| 313 | if (error) { |
| 314 | free(error); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 315 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 316 | } |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 317 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 318 | return VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 319 | } |
| 320 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 321 | static VkResult wsi_x11_dri3_pixmap_from_buffer(struct intel_wsi_x11 *x11, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 322 | struct intel_dev *dev, |
| 323 | struct intel_img *img, |
| 324 | struct intel_mem *mem) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 325 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 326 | struct intel_x11_img_data *data = |
| 327 | (struct intel_x11_img_data *) img->wsi_data; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 328 | |
Chia-I Wu | 030b2db | 2015-04-08 13:46:29 +0800 | [diff] [blame] | 329 | data->prime_fd = x11_export_prime_fd(dev, mem->bo, &img->layout); |
| 330 | if (data->prime_fd < 0) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 331 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 332 | |
Chia-I Wu | 030b2db | 2015-04-08 13:46:29 +0800 | [diff] [blame] | 333 | data->pixmap = x11_dri3_pixmap_from_buffer(x11->c, x11->root, |
| 334 | x11->root_depth, data->prime_fd, &img->layout); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 335 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 336 | data->mem = mem; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 337 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 338 | return VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /** |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 342 | * Create a presentable image. |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 343 | */ |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 344 | static VkResult wsi_x11_img_create(struct intel_wsi_x11 *x11, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 345 | struct intel_dev *dev, |
| 346 | const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO *info, |
| 347 | struct intel_img **img_ret) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 348 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 349 | VkImageCreateInfo img_info; |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 350 | VkMemoryAllocInfo mem_info; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 351 | struct intel_img *img; |
| 352 | struct intel_mem *mem; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 353 | VkResult ret; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 354 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 355 | if (!x11_is_format_presentable(dev, info->format)) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 356 | intel_dev_log(dev, VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, |
| 357 | VK_NULL_HANDLE, 0, 0, "invalid presentable image format"); |
| 358 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 359 | } |
| 360 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 361 | /* create image */ |
| 362 | memset(&img_info, 0, sizeof(img_info)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 363 | img_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 364 | img_info.imageType = VK_IMAGE_TYPE_2D; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 365 | img_info.format = info->format; |
| 366 | img_info.extent.width = info->extent.width; |
| 367 | img_info.extent.height = info->extent.height; |
| 368 | img_info.extent.depth = 1; |
| 369 | img_info.mipLevels = 1; |
| 370 | img_info.arraySize = 1; |
| 371 | img_info.samples = 1; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 372 | img_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 373 | img_info.usage = info->usage; |
| 374 | img_info.flags = 0; |
| 375 | |
| 376 | ret = intel_img_create(dev, &img_info, true, &img); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 377 | if (ret != VK_SUCCESS) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 378 | return ret; |
| 379 | |
| 380 | /* allocate memory */ |
| 381 | memset(&mem_info, 0, sizeof(mem_info)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 382 | mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 383 | mem_info.allocationSize = img->total_size; |
| 384 | mem_info.memProps = 0; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 385 | mem_info.memPriority = VK_MEMORY_PRIORITY_HIGH; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 386 | |
| 387 | ret = intel_mem_alloc(dev, &mem_info, &mem); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 388 | if (ret != VK_SUCCESS) { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 389 | intel_img_destroy(img); |
| 390 | return ret; |
| 391 | } |
| 392 | |
| 393 | ret = wsi_x11_dri3_pixmap_from_buffer(x11, dev, img, mem); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 394 | if (ret != VK_SUCCESS) { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 395 | intel_mem_free(mem); |
| 396 | intel_img_destroy(img); |
| 397 | return ret; |
| 398 | } |
| 399 | |
| 400 | intel_obj_bind_mem(&img->obj, mem, 0); |
| 401 | |
| 402 | *img_ret = img; |
| 403 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 404 | return VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Send a PresentPixmap. |
| 409 | */ |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 410 | static VkResult x11_swap_chain_present_pixmap(struct intel_x11_swap_chain *sc, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 411 | const VK_WSI_X11_PRESENT_INFO *info) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 412 | { |
| 413 | struct intel_img *img = intel_img(info->srcImage); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 414 | struct intel_x11_img_data *data = |
| 415 | (struct intel_x11_img_data *) img->wsi_data; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 416 | uint32_t options = XCB_PRESENT_OPTION_NONE; |
| 417 | xcb_void_cookie_t cookie; |
| 418 | xcb_generic_error_t *err; |
| 419 | |
| 420 | if (info->async) |
| 421 | options |= XCB_PRESENT_OPTION_ASYNC; |
| 422 | if (!info->flip) |
| 423 | options |= XCB_PRESENT_OPTION_COPY; |
| 424 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 425 | cookie = xcb_present_pixmap(sc->c, |
| 426 | sc->window, |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 427 | data->pixmap, |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 428 | ++sc->local.serial, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 429 | 0, /* valid-area */ |
| 430 | 0, /* update-area */ |
| 431 | 0, /* x-off */ |
| 432 | 0, /* y-off */ |
| 433 | info->crtc, |
| 434 | 0, /* wait-fence */ |
| 435 | 0, /* idle-fence */ |
| 436 | options, |
| 437 | info->target_msc, |
| 438 | info->divisor, |
| 439 | info->remainder, |
| 440 | 0, NULL); |
| 441 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 442 | err = xcb_request_check(sc->c, cookie); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 443 | if (err) { |
| 444 | free(err); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 445 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 446 | } |
| 447 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 448 | return VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | /** |
| 452 | * Send a PresentNotifyMSC for the current MSC. |
| 453 | */ |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 454 | static void x11_swap_chain_present_notify_msc(struct intel_x11_swap_chain *sc) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 455 | { |
| 456 | /* cannot specify CRTC? */ |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 457 | xcb_present_notify_msc(sc->c, sc->window, ++sc->local.serial, 0, 0, 0); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 458 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 459 | xcb_flush(sc->c); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Handle a Present event. |
| 464 | */ |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 465 | static void x11_swap_chain_present_event(struct intel_x11_swap_chain *sc, |
| 466 | const xcb_present_generic_event_t *ev) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 467 | { |
| 468 | union { |
| 469 | const xcb_present_generic_event_t *ev; |
| 470 | const xcb_present_complete_notify_event_t *complete; |
| 471 | } u = { .ev = ev }; |
| 472 | |
| 473 | switch (u.ev->evtype) { |
| 474 | case XCB_PRESENT_COMPLETE_NOTIFY: |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 475 | sc->remote.serial = u.complete->serial; |
| 476 | sc->remote.msc = u.complete->msc; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 477 | break; |
| 478 | default: |
| 479 | break; |
| 480 | } |
| 481 | } |
| 482 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 483 | static VkResult x11_swap_chain_wait(struct intel_x11_swap_chain *sc, |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 484 | uint32_t serial, int64_t timeout) |
| 485 | { |
| 486 | const bool wait = (timeout != 0); |
| 487 | |
| 488 | while (sc->remote.serial < serial) { |
| 489 | xcb_present_generic_event_t *ev; |
| 490 | |
| 491 | if (wait) { |
| 492 | ev = (xcb_present_generic_event_t *) |
| 493 | xcb_wait_for_special_event(sc->c, sc->present_special_event); |
| 494 | if (!ev) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 495 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 496 | } else { |
| 497 | ev = (xcb_present_generic_event_t *) |
| 498 | xcb_poll_for_special_event(sc->c, sc->present_special_event); |
| 499 | if (!ev) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 500 | return VK_NOT_READY; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | x11_swap_chain_present_event(sc, ev); |
| 504 | |
| 505 | free(ev); |
| 506 | } |
| 507 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 508 | return VK_SUCCESS; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 509 | } |
| 510 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 511 | 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] | 512 | { |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 513 | if (sc->present_special_event) |
| 514 | xcb_unregister_for_special_event(sc->c, sc->present_special_event); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 515 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 516 | intel_free(sc, sc); |
| 517 | } |
| 518 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 519 | static void wsi_x11_destroy(struct intel_wsi_x11 *x11) |
| 520 | { |
| 521 | struct intel_x11_swap_chain *sc = x11->swap_chains; |
| 522 | |
| 523 | while (sc) { |
| 524 | struct intel_x11_swap_chain *next = sc->next; |
| 525 | x11_swap_chain_destroy(sc); |
| 526 | sc = next; |
| 527 | } |
| 528 | |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 529 | intel_free(x11, x11); |
| 530 | } |
| 531 | |
| 532 | static struct intel_wsi_x11 *wsi_x11_create(struct intel_gpu *gpu, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 533 | const VK_WSI_X11_CONNECTION_INFO *info) |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 534 | { |
| 535 | struct intel_wsi_x11 *x11; |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 536 | int depth, fd; |
| 537 | |
| 538 | if (!x11_is_dri3_and_present_supported(info->pConnection)) |
| 539 | return NULL; |
| 540 | |
| 541 | depth = x11_get_drawable_depth(info->pConnection, info->root); |
| 542 | if (!depth) |
| 543 | return NULL; |
| 544 | |
| 545 | fd = x11_dri3_open(info->pConnection, info->root, info->provider); |
| 546 | if (fd < 0 || !x11_gpu_match_fd(gpu, fd)) { |
| 547 | if (fd >= 0) |
| 548 | close(fd); |
| 549 | return NULL; |
| 550 | } |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 551 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 552 | x11 = intel_alloc(gpu, sizeof(*x11), 0, VK_SYSTEM_ALLOC_TYPE_API_OBJECT); |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 553 | if (!x11) |
| 554 | return NULL; |
| 555 | |
| 556 | memset(x11, 0, sizeof(*x11)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 557 | /* there is no VK_DBG_OBJECT_WSI_DISPLAY */ |
| 558 | intel_handle_init(&x11->handle, VK_DBG_OBJECT_UNKNOWN, gpu->handle.icd); |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 559 | |
| 560 | x11->c = info->pConnection; |
| 561 | x11->root = info->root; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 562 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 563 | x11->root_depth = depth; |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 564 | |
Chia-I Wu | fcbc525 | 2015-04-08 11:44:26 +0800 | [diff] [blame] | 565 | if (!wsi_x11_dri3_and_present_query_version(x11)) { |
Chia-I Wu | dbbe6ea | 2015-04-08 10:30:57 +0800 | [diff] [blame] | 566 | wsi_x11_destroy(x11); |
| 567 | return NULL; |
| 568 | } |
| 569 | |
| 570 | return x11; |
| 571 | } |
| 572 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 573 | static struct intel_x11_swap_chain *x11_swap_chain_create(struct intel_dev *dev, |
| 574 | xcb_window_t window) |
| 575 | { |
| 576 | struct intel_wsi_x11 *x11 = (struct intel_wsi_x11 *) dev->gpu->wsi_data; |
| 577 | struct intel_x11_swap_chain *sc; |
| 578 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 579 | 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] | 580 | if (!sc) |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 581 | return NULL; |
| 582 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 583 | memset(sc, 0, sizeof(*sc)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 584 | /* there is no VK_DBG_OBJECT_WSI_SWAP_CHAIN */ |
| 585 | intel_handle_init(&sc->handle, VK_DBG_OBJECT_UNKNOWN, |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 586 | dev->base.handle.icd); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 587 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 588 | sc->c = x11->c; |
| 589 | sc->window = window; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 590 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 591 | if (x11_swap_chain_present_select_input(sc) != VK_SUCCESS) { |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 592 | intel_free(dev, sc); |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 593 | return NULL; |
| 594 | } |
| 595 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 596 | return sc; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 597 | } |
| 598 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 599 | static struct intel_x11_swap_chain *x11_swap_chain_lookup(struct intel_dev *dev, |
| 600 | xcb_window_t window) |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 601 | { |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 602 | struct intel_wsi_x11 *x11 = (struct intel_wsi_x11 *) dev->gpu->wsi_data; |
| 603 | struct intel_x11_swap_chain *sc = x11->swap_chains; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 604 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 605 | while (sc) { |
| 606 | if (sc->window == window) |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 607 | break; |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 608 | sc = sc->next; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /* lookup failed */ |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 612 | if (!sc) { |
| 613 | sc = x11_swap_chain_create(dev, window); |
| 614 | if (sc) { |
| 615 | sc->next = x11->swap_chains; |
| 616 | x11->swap_chains = sc; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 620 | return sc; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 621 | } |
| 622 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 623 | static VkResult intel_wsi_gpu_init(struct intel_gpu *gpu, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 624 | const VK_WSI_X11_CONNECTION_INFO *info) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 625 | { |
| 626 | struct intel_wsi_x11 *x11; |
| 627 | |
| 628 | x11 = wsi_x11_create(gpu, info); |
| 629 | if (!x11) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 630 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 631 | |
| 632 | gpu->wsi_data = x11; |
| 633 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 634 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 635 | } |
| 636 | |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 637 | static void x11_display_init_modes(struct intel_x11_display *dpy, |
| 638 | const drmModeConnectorPtr conn) |
| 639 | { |
| 640 | int i; |
| 641 | |
| 642 | if (!conn->count_modes) |
| 643 | return; |
| 644 | |
| 645 | dpy->modes = intel_alloc(dpy, sizeof(dpy->modes[0]) * conn->count_modes, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 646 | 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 647 | if (!dpy->modes) |
| 648 | return; |
| 649 | |
| 650 | for (i = 0; i < conn->count_modes; i++) { |
| 651 | dpy->modes[i] = conn->modes[i]; |
| 652 | |
| 653 | if (dpy->physical_resolution.width < conn->modes[i].hdisplay && |
| 654 | dpy->physical_resolution.height < conn->modes[i].vdisplay) { |
| 655 | dpy->physical_resolution.width = conn->modes[i].hdisplay; |
| 656 | dpy->physical_resolution.height = conn->modes[i].vdisplay; |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | dpy->mode_count = conn->count_modes; |
| 661 | |
| 662 | dpy->physical_dimension.width = conn->mmWidth; |
| 663 | dpy->physical_dimension.height = conn->mmHeight; |
| 664 | } |
| 665 | |
| 666 | static void x11_display_init_name(struct intel_x11_display *dpy, |
| 667 | const drmModeConnectorPtr conn) |
| 668 | { |
| 669 | static const char *connector_names[] = { |
| 670 | [DRM_MODE_CONNECTOR_Unknown] = "Unknown", |
| 671 | [DRM_MODE_CONNECTOR_VGA] = "VGA", |
| 672 | [DRM_MODE_CONNECTOR_DVII] = "DVII", |
| 673 | [DRM_MODE_CONNECTOR_DVID] = "DVID", |
| 674 | [DRM_MODE_CONNECTOR_DVIA] = "DVIA", |
| 675 | [DRM_MODE_CONNECTOR_Composite] = "Composite", |
| 676 | [DRM_MODE_CONNECTOR_SVIDEO] = "SVIDEO", |
| 677 | [DRM_MODE_CONNECTOR_LVDS] = "LVDS", |
| 678 | [DRM_MODE_CONNECTOR_Component] = "COMPONENT", |
| 679 | [DRM_MODE_CONNECTOR_9PinDIN] = "9PinDIN", |
| 680 | [DRM_MODE_CONNECTOR_DisplayPort] = "DisplayPort", |
| 681 | [DRM_MODE_CONNECTOR_HDMIA] = "HDMIA", |
| 682 | [DRM_MODE_CONNECTOR_HDMIB] = "HDMIB", |
| 683 | [DRM_MODE_CONNECTOR_TV] = "TV", |
| 684 | [DRM_MODE_CONNECTOR_eDP] = "eDP", |
| 685 | [DRM_MODE_CONNECTOR_VIRTUAL] = "VIRTUAL", |
| 686 | [DRM_MODE_CONNECTOR_DSI] = "DSI", |
| 687 | }; |
| 688 | const char *name; |
| 689 | |
| 690 | name = (conn->connector_type < ARRAY_SIZE(connector_names)) ? |
| 691 | connector_names[conn->connector_type] : NULL; |
| 692 | if (!name) |
| 693 | name = connector_names[DRM_MODE_CONNECTOR_Unknown]; |
| 694 | |
| 695 | snprintf(dpy->name, sizeof(dpy->name), |
| 696 | "%s%d", name, conn->connector_type_id); |
| 697 | } |
| 698 | |
| 699 | static void x11_display_destroy(struct intel_x11_display *dpy) |
| 700 | { |
| 701 | intel_free(dpy, dpy->modes); |
| 702 | intel_free(dpy, dpy); |
| 703 | } |
| 704 | |
| 705 | static struct intel_x11_display *x11_display_create(struct intel_gpu *gpu, |
| 706 | int fd, |
| 707 | uint32_t connector_id) |
| 708 | { |
| 709 | struct intel_x11_display *dpy; |
| 710 | drmModeConnectorPtr conn; |
| 711 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 712 | dpy = intel_alloc(gpu, sizeof(*dpy), 0, VK_SYSTEM_ALLOC_TYPE_API_OBJECT); |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 713 | if (!dpy) |
| 714 | return NULL; |
| 715 | |
| 716 | memset(dpy, 0, sizeof(*dpy)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 717 | /* there is no VK_DBG_OBJECT_WSI_DISPLAY */ |
| 718 | intel_handle_init(&dpy->handle, VK_DBG_OBJECT_UNKNOWN, gpu->handle.icd); |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 719 | |
| 720 | dpy->fd = fd; |
| 721 | dpy->connector_id = connector_id; |
| 722 | |
| 723 | conn = drmModeGetConnector(fd, connector_id); |
| 724 | if (!conn) { |
| 725 | x11_display_destroy(dpy); |
| 726 | return NULL; |
| 727 | } |
| 728 | |
| 729 | x11_display_init_name(dpy, conn); |
| 730 | x11_display_init_modes(dpy, conn); |
| 731 | |
| 732 | drmModeFreeConnector(conn); |
| 733 | |
| 734 | return dpy; |
| 735 | } |
| 736 | |
| 737 | static void x11_display_scan(struct intel_gpu *gpu) |
| 738 | { |
| 739 | struct intel_x11_display **displays; |
| 740 | drmModeResPtr res; |
| 741 | int fd, i; |
| 742 | |
| 743 | fd = intel_gpu_get_primary_fd(gpu); |
| 744 | if (fd < 0) |
| 745 | return; |
| 746 | |
| 747 | res = drmModeGetResources(fd); |
| 748 | if (!res) |
| 749 | return; |
| 750 | |
| 751 | displays = intel_alloc(gpu, sizeof(*displays) * res->count_connectors, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 752 | 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 753 | if (!displays) { |
| 754 | drmModeFreeResources(res); |
| 755 | return; |
| 756 | } |
| 757 | |
| 758 | for (i = 0; i < res->count_connectors; i++) { |
| 759 | displays[i] = x11_display_create(gpu, fd, res->connectors[i]); |
| 760 | if (!displays[i]) |
| 761 | break; |
| 762 | } |
| 763 | |
| 764 | drmModeFreeResources(res); |
| 765 | |
| 766 | gpu->displays = (struct intel_wsi_display **) displays; |
| 767 | gpu->display_count = i; |
| 768 | } |
| 769 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 770 | VkResult intel_wsi_gpu_get_info(struct intel_gpu *gpu, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 771 | VkPhysicalDeviceInfoType type, |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 772 | size_t *size, void *data) |
| 773 | { |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 774 | if (false) |
| 775 | x11_display_scan(gpu); |
| 776 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 777 | return VK_ERROR_INVALID_VALUE; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | void intel_wsi_gpu_cleanup(struct intel_gpu *gpu) |
| 781 | { |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 782 | if (gpu->displays) { |
| 783 | uint32_t i; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 784 | |
Chia-I Wu | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 785 | for (i = 0; i < gpu->display_count; i++) { |
| 786 | struct intel_x11_display *dpy = |
| 787 | (struct intel_x11_display *) gpu->displays[i]; |
| 788 | x11_display_destroy(dpy); |
| 789 | } |
| 790 | intel_free(gpu, gpu->displays); |
| 791 | } |
| 792 | |
| 793 | if (gpu->wsi_data) { |
| 794 | struct intel_wsi_x11 *x11 = (struct intel_wsi_x11 *) gpu->wsi_data; |
| 795 | wsi_x11_destroy(x11); |
| 796 | } |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 797 | } |
| 798 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 799 | VkResult intel_wsi_img_init(struct intel_img *img) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 800 | { |
| 801 | struct intel_x11_img_data *data; |
| 802 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 803 | 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] | 804 | if (!data) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 805 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 806 | |
| 807 | memset(data, 0, sizeof(*data)); |
| 808 | |
| 809 | assert(!img->wsi_data); |
| 810 | img->wsi_data = data; |
| 811 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 812 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | void intel_wsi_img_cleanup(struct intel_img *img) |
| 816 | { |
| 817 | struct intel_x11_img_data *data = |
| 818 | (struct intel_x11_img_data *) img->wsi_data; |
| 819 | |
| 820 | if (data->mem) { |
| 821 | close(data->prime_fd); |
| 822 | intel_mem_free(data->mem); |
| 823 | } |
| 824 | |
| 825 | intel_free(img, img->wsi_data); |
| 826 | } |
| 827 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 828 | VkResult intel_wsi_fence_init(struct intel_fence *fence) |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 829 | { |
| 830 | struct intel_x11_fence_data *data; |
| 831 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 832 | 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] | 833 | if (!data) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 834 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 835 | |
| 836 | memset(data, 0, sizeof(*data)); |
| 837 | |
| 838 | assert(!fence->wsi_data); |
| 839 | fence->wsi_data = data; |
| 840 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 841 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | void intel_wsi_fence_cleanup(struct intel_fence *fence) |
| 845 | { |
| 846 | intel_free(fence, fence->wsi_data); |
| 847 | } |
| 848 | |
| 849 | void intel_wsi_fence_copy(struct intel_fence *fence, |
| 850 | const struct intel_fence *src) |
| 851 | { |
| 852 | memcpy(fence->wsi_data, src->wsi_data, |
| 853 | sizeof(struct intel_x11_fence_data)); |
| 854 | } |
| 855 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 856 | VkResult intel_wsi_fence_wait(struct intel_fence *fence, |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 857 | int64_t timeout_ns) |
| 858 | { |
| 859 | struct intel_x11_fence_data *data = |
| 860 | (struct intel_x11_fence_data *) fence->wsi_data; |
| 861 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 862 | if (!data->swap_chain) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 863 | return VK_SUCCESS; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 864 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 865 | 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] | 866 | } |
| 867 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 868 | ICD_EXPORT VkResult VKAPI vkWsiX11AssociateConnection( |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 869 | VkPhysicalDevice gpu_, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 870 | const VK_WSI_X11_CONNECTION_INFO* pConnectionInfo) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 871 | { |
| 872 | struct intel_gpu *gpu = intel_gpu(gpu_); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 873 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 874 | return intel_wsi_gpu_init(gpu, pConnectionInfo); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 875 | } |
| 876 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 877 | ICD_EXPORT VkResult VKAPI vkWsiX11GetMSC( |
| 878 | VkDevice device, |
Chia-I Wu | 6204f34 | 2014-11-07 13:33:45 +0800 | [diff] [blame] | 879 | xcb_window_t window, |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 880 | xcb_randr_crtc_t crtc, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 881 | uint64_t * pMsc) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 882 | { |
| 883 | struct intel_dev *dev = intel_dev(device); |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 884 | struct intel_x11_swap_chain *sc; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 885 | VkResult ret; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 886 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 887 | sc = x11_swap_chain_lookup(dev, window); |
| 888 | if (!sc) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 889 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 890 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 891 | x11_swap_chain_present_notify_msc(sc); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 892 | |
| 893 | /* wait for the event */ |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 894 | ret = x11_swap_chain_wait(sc, sc->local.serial, -1); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 895 | if (ret != VK_SUCCESS) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 896 | return ret; |
| 897 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 898 | *pMsc = sc->remote.msc; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 899 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 900 | return VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 901 | } |
| 902 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 903 | ICD_EXPORT VkResult VKAPI vkWsiX11CreatePresentableImage( |
| 904 | VkDevice device, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 905 | const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 906 | VkImage* pImage, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 907 | VkDeviceMemory* pMem) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 908 | { |
| 909 | struct intel_dev *dev = intel_dev(device); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 910 | struct intel_wsi_x11 *x11 = (struct intel_wsi_x11 *) dev->gpu->wsi_data; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 911 | struct intel_img *img; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 912 | VkResult ret; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 913 | |
| 914 | ret = wsi_x11_img_create(x11, dev, pCreateInfo, &img); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 915 | if (ret == VK_SUCCESS) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 916 | *pImage = (VkImage) img; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame^] | 917 | *pMem = (VkDeviceMemory) img->obj.mem; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | return ret; |
| 921 | } |
| 922 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 923 | ICD_EXPORT VkResult VKAPI vkWsiX11QueuePresent( |
| 924 | VkQueue queue_, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 925 | const VK_WSI_X11_PRESENT_INFO* pPresentInfo, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 926 | VkFence fence_) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 927 | { |
| 928 | struct intel_queue *queue = intel_queue(queue_); |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 929 | struct intel_dev *dev = queue->dev; |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 930 | struct intel_x11_fence_data *data = |
| 931 | (struct intel_x11_fence_data *) queue->fence->wsi_data; |
| 932 | struct intel_img *img = intel_img(pPresentInfo->srcImage); |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 933 | struct intel_x11_swap_chain *sc; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 934 | VkResult ret; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 935 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 936 | sc = x11_swap_chain_lookup(dev, pPresentInfo->destWindow); |
| 937 | if (!sc) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 938 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | 7fbe2ab | 2014-11-07 13:26:45 +0800 | [diff] [blame] | 939 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 940 | ret = x11_swap_chain_present_pixmap(sc, pPresentInfo); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 941 | if (ret != VK_SUCCESS) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 942 | return ret; |
| 943 | |
Chia-I Wu | 6532d1d | 2015-04-04 22:16:45 +0800 | [diff] [blame] | 944 | data->swap_chain = sc; |
| 945 | data->serial = sc->local.serial; |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 946 | intel_fence_set_seqno(queue->fence, img->obj.mem->bo); |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 947 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 948 | if (fence_ != VK_NULL_HANDLE) { |
Chia-I Wu | b56f5df | 2015-04-04 20:21:10 +0800 | [diff] [blame] | 949 | struct intel_fence *fence = intel_fence(fence_); |
| 950 | intel_fence_copy(fence, queue->fence); |
Chia-I Wu | bda4f62 | 2015-02-25 15:06:15 -0700 | [diff] [blame] | 951 | } |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 952 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 953 | return VK_SUCCESS; |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 954 | } |