c5002ec8ecaab6d4b5ed6d77fa4e48db9e84b1b4
[mesa.git] / src / vulkan / wsi / wsi_common_private.h
1 /*
2 * Copyright © 2017 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23 #ifndef WSI_COMMON_PRIVATE_H
24 #define WSI_COMMON_PRIVATE_H
25
26 #include "wsi_common.h"
27
28 struct wsi_image {
29 VkImage image;
30 VkDeviceMemory memory;
31
32 struct {
33 VkBuffer buffer;
34 VkDeviceMemory memory;
35 VkCommandBuffer *blit_cmd_buffers;
36 } prime;
37
38 int num_planes;
39 uint32_t sizes[4];
40 uint32_t offsets[4];
41 uint32_t row_pitches[4];
42 int fds[4];
43 };
44
45 struct wsi_swapchain {
46 const struct wsi_device *wsi;
47
48 VkDevice device;
49 VkAllocationCallbacks alloc;
50 VkFence fences[3];
51 VkPresentModeKHR present_mode;
52 uint32_t image_count;
53
54 bool use_prime_blit;
55
56 /* Command pools, one per queue family */
57 VkCommandPool *cmd_pools;
58
59 VkResult (*destroy)(struct wsi_swapchain *swapchain,
60 const VkAllocationCallbacks *pAllocator);
61 struct wsi_image *(*get_wsi_image)(struct wsi_swapchain *swapchain,
62 uint32_t image_index);
63 VkResult (*acquire_next_image)(struct wsi_swapchain *swap_chain,
64 uint64_t timeout, VkSemaphore semaphore,
65 uint32_t *image_index);
66 VkResult (*queue_present)(struct wsi_swapchain *swap_chain,
67 uint32_t image_index,
68 const VkPresentRegionKHR *damage);
69 };
70
71 VkResult
72 wsi_swapchain_init(const struct wsi_device *wsi,
73 struct wsi_swapchain *chain,
74 VkDevice device,
75 const VkSwapchainCreateInfoKHR *pCreateInfo,
76 const VkAllocationCallbacks *pAllocator);
77
78 void wsi_swapchain_finish(struct wsi_swapchain *chain);
79
80 VkResult
81 wsi_create_native_image(const struct wsi_swapchain *chain,
82 const VkSwapchainCreateInfoKHR *pCreateInfo,
83 struct wsi_image *image);
84
85 VkResult
86 wsi_create_prime_image(const struct wsi_swapchain *chain,
87 const VkSwapchainCreateInfoKHR *pCreateInfo,
88 struct wsi_image *image);
89
90 void
91 wsi_destroy_image(const struct wsi_swapchain *chain,
92 struct wsi_image *image);
93
94
95 struct wsi_interface {
96 VkResult (*get_support)(VkIcdSurfaceBase *surface,
97 struct wsi_device *wsi_device,
98 const VkAllocationCallbacks *alloc,
99 uint32_t queueFamilyIndex,
100 int local_fd,
101 VkBool32* pSupported);
102 VkResult (*get_capabilities)(VkIcdSurfaceBase *surface,
103 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities);
104 VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface,
105 const void *info_next,
106 VkSurfaceCapabilities2KHR* pSurfaceCapabilities);
107 VkResult (*get_formats)(VkIcdSurfaceBase *surface,
108 struct wsi_device *wsi_device,
109 uint32_t* pSurfaceFormatCount,
110 VkSurfaceFormatKHR* pSurfaceFormats);
111 VkResult (*get_formats2)(VkIcdSurfaceBase *surface,
112 struct wsi_device *wsi_device,
113 const void *info_next,
114 uint32_t* pSurfaceFormatCount,
115 VkSurfaceFormat2KHR* pSurfaceFormats);
116 VkResult (*get_present_modes)(VkIcdSurfaceBase *surface,
117 uint32_t* pPresentModeCount,
118 VkPresentModeKHR* pPresentModes);
119 VkResult (*create_swapchain)(VkIcdSurfaceBase *surface,
120 VkDevice device,
121 struct wsi_device *wsi_device,
122 int local_fd,
123 const VkSwapchainCreateInfoKHR* pCreateInfo,
124 const VkAllocationCallbacks* pAllocator,
125 struct wsi_swapchain **swapchain);
126 };
127
128 VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device,
129 const VkAllocationCallbacks *alloc);
130 void wsi_x11_finish_wsi(struct wsi_device *wsi_device,
131 const VkAllocationCallbacks *alloc);
132 VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device,
133 const VkAllocationCallbacks *alloc,
134 VkPhysicalDevice physical_device);
135 void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
136 const VkAllocationCallbacks *alloc);
137
138
139 #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
140 \
141 static inline struct __wsi_type * \
142 __wsi_type ## _from_handle(__VkType _handle) \
143 { \
144 return (struct __wsi_type *)(uintptr_t) _handle; \
145 } \
146 \
147 static inline __VkType \
148 __wsi_type ## _to_handle(struct __wsi_type *_obj) \
149 { \
150 return (__VkType)(uintptr_t) _obj; \
151 }
152
153 #define WSI_FROM_HANDLE(__wsi_type, __name, __handle) \
154 struct __wsi_type *__name = __wsi_type ## _from_handle(__handle)
155
156 WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, VkSwapchainKHR)
157
158 #endif /* WSI_COMMON_PRIVATE_H */