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