Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 1 | /* IN DEVELOPMENT. DO NOT SHIP. */ |
| 2 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3 | #ifndef __VKWSIX11EXT_H__ |
| 4 | #define __VKWSIX11EXT_H__ |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 5 | |
| 6 | #include <xcb/xcb.h> |
| 7 | #include <xcb/randr.h> |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 8 | #include "vulkan.h" |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 9 | |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" |
| 12 | { |
| 13 | #endif // __cplusplus |
| 14 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 15 | typedef struct _VK_WSI_X11_CONNECTION_INFO { |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 16 | xcb_connection_t* pConnection; |
| 17 | xcb_window_t root; |
| 18 | xcb_randr_provider_t provider; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 19 | } VK_WSI_X11_CONNECTION_INFO; |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 20 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 21 | typedef struct _VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 22 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 23 | VK_FORMAT format; |
| 24 | VK_FLAGS usage; // VK_IMAGE_USAGE_FLAGS |
| 25 | VK_EXTENT2D extent; |
| 26 | VK_FLAGS flags; |
| 27 | } VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO; |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 28 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 29 | typedef struct _VK_WSI_X11_PRESENT_INFO |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 30 | { |
| 31 | /* which window to present to */ |
| 32 | xcb_window_t destWindow; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 33 | VK_IMAGE srcImage; |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * After the command buffers in the queue have been completed, if the MSC |
| 37 | * of \p crtc is less than or equal to \p target_msc, wait until it |
| 38 | * reaches \p target_msc. |
| 39 | * |
| 40 | * If the current MSC of \p crtc is greater than \p target_msc, adjust |
| 41 | * \p target_msc as following: |
| 42 | * |
| 43 | * if (divisor) { |
| 44 | * target_msc = crtc_msc - (crtc_msc % divisor) + remainder; |
| 45 | * if (target_msc < crtc_msc) |
| 46 | * target_msc += divisor; |
| 47 | * } else { |
| 48 | * target_msc = crtc_msc; |
| 49 | * } |
| 50 | * |
| 51 | * In other words, either set \p target_msc to an absolute value (require |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 52 | * vkWsiX11GetMSC(), potentially a round-trip to the server, to get the |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 53 | * current MSC first), or set \p target_msc to zero and set a "swap |
| 54 | * interval". |
Chia-I Wu | eecd408 | 2014-11-07 13:33:45 +0800 | [diff] [blame] | 55 | * |
| 56 | * \p crtc can be XCB_NONE. In that case, a suitable CRTC is picked based |
| 57 | * on \p destWindow. |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 58 | */ |
| 59 | xcb_randr_crtc_t crtc; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 60 | uint64_t target_msc; |
| 61 | uint64_t divisor; |
| 62 | uint64_t remainder; |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * After waiting for the current and target MSCs to match, the |
| 66 | * presentation is scheduled. When \p async is false, it will occur the |
| 67 | * next time current MSC is incremented. When \p async is true, it will |
| 68 | * occur as soon as possible. |
| 69 | */ |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 70 | bool32_t async; |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * When \p flip is false, the contents of \p srcImage are copied to |
| 74 | * \p destWindow when the presentation occurs. When \p flip is true, |
| 75 | * \p srcImage is made the front buffer of \p destWindow. |
| 76 | * |
| 77 | * An error may be returned if \p flip is true but \p destWindow can not |
| 78 | * be flipped to. |
| 79 | */ |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 80 | bool32_t flip; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 81 | } VK_WSI_X11_PRESENT_INFO; |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 82 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 83 | typedef VK_RESULT (VKAPI *vkWsiX11AssociateConnectionType)(VK_PHYSICAL_GPU gpu, const VK_WSI_X11_CONNECTION_INFO* pConnectionInfo); |
| 84 | typedef VK_RESULT (VKAPI *vkWsiX11GetMSCType)(VK_DEVICE device, xcb_window_t window, xcb_randr_crtc_t crtc, uint64_t* pMsc); |
| 85 | typedef VK_RESULT (VKAPI *vkWsiX11CreatePresentableImageType)(VK_DEVICE device, const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo, VK_IMAGE* pImage, VK_GPU_MEMORY* pMem); |
| 86 | typedef VK_RESULT (VKAPI *vkWsiX11QueuePresentType)(VK_QUEUE queue, const VK_WSI_X11_PRESENT_INFO* pPresentInfo, VK_FENCE fence); |
Jon Ashburn | 83f4a69 | 2014-12-02 08:59:56 -0700 | [diff] [blame] | 87 | |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 88 | /** |
| 89 | * Associate an X11 connection with a GPU. This should be done before device |
| 90 | * creation. If the device is already created, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 91 | * VK_ERROR_DEVICE_ALREADY_CREATED is returned. |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 92 | * |
| 93 | * Truth is, given a connection, we could find the associated GPU. But |
| 94 | * without having a GPU as the first parameter, the loader could not find the |
| 95 | * dispatch table. |
| 96 | * |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 97 | * This function is available when vkGetExtensionSupport says "VK_WSI_X11" |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 98 | * is supported. |
| 99 | */ |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 100 | VK_RESULT VKAPI vkWsiX11AssociateConnection( |
| 101 | VK_PHYSICAL_GPU gpu, |
| 102 | const VK_WSI_X11_CONNECTION_INFO* pConnectionInfo); |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Return the current MSC (Media Stream Counter, incremented for each vblank) |
Chia-I Wu | eecd408 | 2014-11-07 13:33:45 +0800 | [diff] [blame] | 106 | * of \p crtc. If crtc is \p XCB_NONE, a suitable CRTC is picked based on \p |
| 107 | * win. |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 108 | */ |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 109 | VK_RESULT VKAPI vkWsiX11GetMSC( |
| 110 | VK_DEVICE device, |
Chia-I Wu | eecd408 | 2014-11-07 13:33:45 +0800 | [diff] [blame] | 111 | xcb_window_t window, |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 112 | xcb_randr_crtc_t crtc, |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 113 | uint64_t* pMsc); |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 114 | |
| 115 | /** |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 116 | * Create an VK_IMAGE that can be presented. An VK_GPU_MEMORY is created |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 117 | * and bound automatically. The memory returned can only be used in |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 118 | * vkQueue[Add|Remove]MemReference. Destroying the memory or binding another memory to the |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 119 | * image is not allowed. |
| 120 | */ |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 121 | VK_RESULT VKAPI vkWsiX11CreatePresentableImage( |
| 122 | VK_DEVICE device, |
| 123 | const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo, |
| 124 | VK_IMAGE* pImage, |
| 125 | VK_GPU_MEMORY* pMem); |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 126 | |
| 127 | /** |
| 128 | * Present an image to an X11 window. The presentation always occurs after |
| 129 | * the command buffers in the queue have been completed, subject to other |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 130 | * parameters specified in VK_WSI_X11_PRESENT_INFO. |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 131 | * |
| 132 | * Fence is reached when the presentation occurs. |
| 133 | */ |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 134 | VK_RESULT VKAPI vkWsiX11QueuePresent( |
| 135 | VK_QUEUE queue, |
| 136 | const VK_WSI_X11_PRESENT_INFO* pPresentInfo, |
| 137 | VK_FENCE fence); |
Chia-I Wu | 9281c39 | 2014-09-23 10:37:08 +0800 | [diff] [blame] | 138 | |
| 139 | #ifdef __cplusplus |
| 140 | } // extern "C" |
| 141 | #endif // __cplusplus |
| 142 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 143 | #endif // __VKWSIX11EXT_H__ |