blob: f7046375b86f4262be9807e120a64d8a465e6835 [file] [log] [blame]
Chia-I Wu9281c392014-09-23 10:37:08 +08001/* IN DEVELOPMENT. DO NOT SHIP. */
2
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003#ifndef __VKWSIX11EXT_H__
4#define __VKWSIX11EXT_H__
Chia-I Wu9281c392014-09-23 10:37:08 +08005
6#include <xcb/xcb.h>
7#include <xcb/randr.h>
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06008#include "vulkan.h"
Chia-I Wu9281c392014-09-23 10:37:08 +08009
10#ifdef __cplusplus
11extern "C"
12{
13#endif // __cplusplus
14
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060015typedef struct _VK_WSI_X11_CONNECTION_INFO {
Chia-I Wu9281c392014-09-23 10:37:08 +080016 xcb_connection_t* pConnection;
17 xcb_window_t root;
18 xcb_randr_provider_t provider;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060019} VK_WSI_X11_CONNECTION_INFO;
Chia-I Wu9281c392014-09-23 10:37:08 +080020
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060021typedef struct _VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO
Chia-I Wu9281c392014-09-23 10:37:08 +080022{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060023 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 Wu9281c392014-09-23 10:37:08 +080028
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060029typedef struct _VK_WSI_X11_PRESENT_INFO
Chia-I Wu9281c392014-09-23 10:37:08 +080030{
31 /* which window to present to */
32 xcb_window_t destWindow;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060033 VK_IMAGE srcImage;
Chia-I Wu9281c392014-09-23 10:37:08 +080034
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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060052 * vkWsiX11GetMSC(), potentially a round-trip to the server, to get the
Chia-I Wu9281c392014-09-23 10:37:08 +080053 * current MSC first), or set \p target_msc to zero and set a "swap
54 * interval".
Chia-I Wueecd4082014-11-07 13:33:45 +080055 *
56 * \p crtc can be XCB_NONE. In that case, a suitable CRTC is picked based
57 * on \p destWindow.
Chia-I Wu9281c392014-09-23 10:37:08 +080058 */
59 xcb_randr_crtc_t crtc;
Mark Lobodzinski17caf572015-01-29 08:55:56 -060060 uint64_t target_msc;
61 uint64_t divisor;
62 uint64_t remainder;
Chia-I Wu9281c392014-09-23 10:37:08 +080063
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 Lobodzinski17caf572015-01-29 08:55:56 -060070 bool32_t async;
Chia-I Wu9281c392014-09-23 10:37:08 +080071
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 Lobodzinski17caf572015-01-29 08:55:56 -060080 bool32_t flip;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060081} VK_WSI_X11_PRESENT_INFO;
Chia-I Wu9281c392014-09-23 10:37:08 +080082
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060083typedef VK_RESULT (VKAPI *vkWsiX11AssociateConnectionType)(VK_PHYSICAL_GPU gpu, const VK_WSI_X11_CONNECTION_INFO* pConnectionInfo);
84typedef VK_RESULT (VKAPI *vkWsiX11GetMSCType)(VK_DEVICE device, xcb_window_t window, xcb_randr_crtc_t crtc, uint64_t* pMsc);
85typedef VK_RESULT (VKAPI *vkWsiX11CreatePresentableImageType)(VK_DEVICE device, const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo, VK_IMAGE* pImage, VK_GPU_MEMORY* pMem);
86typedef VK_RESULT (VKAPI *vkWsiX11QueuePresentType)(VK_QUEUE queue, const VK_WSI_X11_PRESENT_INFO* pPresentInfo, VK_FENCE fence);
Jon Ashburn83f4a692014-12-02 08:59:56 -070087
Chia-I Wu9281c392014-09-23 10:37:08 +080088/**
89 * Associate an X11 connection with a GPU. This should be done before device
90 * creation. If the device is already created,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060091 * VK_ERROR_DEVICE_ALREADY_CREATED is returned.
Chia-I Wu9281c392014-09-23 10:37:08 +080092 *
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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060097 * This function is available when vkGetExtensionSupport says "VK_WSI_X11"
Chia-I Wu9281c392014-09-23 10:37:08 +080098 * is supported.
99 */
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600100VK_RESULT VKAPI vkWsiX11AssociateConnection(
101 VK_PHYSICAL_GPU gpu,
102 const VK_WSI_X11_CONNECTION_INFO* pConnectionInfo);
Chia-I Wu9281c392014-09-23 10:37:08 +0800103
104/**
105 * Return the current MSC (Media Stream Counter, incremented for each vblank)
Chia-I Wueecd4082014-11-07 13:33:45 +0800106 * of \p crtc. If crtc is \p XCB_NONE, a suitable CRTC is picked based on \p
107 * win.
Chia-I Wu9281c392014-09-23 10:37:08 +0800108 */
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600109VK_RESULT VKAPI vkWsiX11GetMSC(
110 VK_DEVICE device,
Chia-I Wueecd4082014-11-07 13:33:45 +0800111 xcb_window_t window,
Chia-I Wu9281c392014-09-23 10:37:08 +0800112 xcb_randr_crtc_t crtc,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600113 uint64_t* pMsc);
Chia-I Wu9281c392014-09-23 10:37:08 +0800114
115/**
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600116 * Create an VK_IMAGE that can be presented. An VK_GPU_MEMORY is created
Chia-I Wu9281c392014-09-23 10:37:08 +0800117 * and bound automatically. The memory returned can only be used in
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600118 * vkQueue[Add|Remove]MemReference. Destroying the memory or binding another memory to the
Chia-I Wu9281c392014-09-23 10:37:08 +0800119 * image is not allowed.
120 */
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600121VK_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 Wu9281c392014-09-23 10:37:08 +0800126
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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600130 * parameters specified in VK_WSI_X11_PRESENT_INFO.
Chia-I Wu9281c392014-09-23 10:37:08 +0800131 *
132 * Fence is reached when the presentation occurs.
133 */
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600134VK_RESULT VKAPI vkWsiX11QueuePresent(
135 VK_QUEUE queue,
136 const VK_WSI_X11_PRESENT_INFO* pPresentInfo,
137 VK_FENCE fence);
Chia-I Wu9281c392014-09-23 10:37:08 +0800138
139#ifdef __cplusplus
140} // extern "C"
141#endif // __cplusplus
142
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600143#endif // __VKWSIX11EXT_H__