2 * Copyright © 2017 Intel Corporation
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:
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
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
23 #ifndef WSI_COMMON_PRIVATE_H
24 #define WSI_COMMON_PRIVATE_H
26 #include "wsi_common.h"
27 #include "util/perf/cpu_trace.h"
28 #include "vulkan/runtime/vk_object.h"
29 #include "vulkan/runtime/vk_sync.h"
34 #define WSI_DEBUG_BUFFER (1ull << 0)
35 #define WSI_DEBUG_SW (1ull << 1)
36 #define WSI_DEBUG_NOSHM (1ull << 2)
37 #define WSI_DEBUG_LINEAR (1ull << 3)
39 extern uint64_t WSI_DEBUG;
46 struct wsi_base_image_params {
47 enum wsi_image_type image_type;
50 struct wsi_cpu_image_params {
51 struct wsi_base_image_params base;
53 uint8_t *(*alloc_shm)(struct wsi_image *image, unsigned size);
56 struct wsi_drm_image_params {
57 struct wsi_base_image_params base;
61 uint32_t num_modifier_lists;
62 const uint32_t *num_modifiers;
63 const uint64_t *const *modifiers;
66 typedef uint32_t (*wsi_memory_type_select_cb)(const struct wsi_device *wsi,
69 struct wsi_image_info {
70 VkImageCreateInfo create;
71 struct wsi_image_create_info wsi;
72 VkExternalMemoryImageCreateInfo ext_mem;
73 VkImageFormatListCreateInfo format_list;
74 VkImageDrmFormatModifierListCreateInfoEXT drm_mod_list;
76 bool prime_use_linear_modifier;
78 /* Not really part of VkImageCreateInfo but needed to figure out the
79 * number of planes we need to bind.
81 uint32_t modifier_prop_count;
82 struct VkDrmFormatModifierPropertiesEXT *modifier_props;
84 /* For buffer blit images, the linear stride in bytes */
85 uint32_t linear_stride;
87 /* For buffer blit images, the size of the buffer in bytes */
90 wsi_memory_type_select_cb select_image_memory_type;
91 wsi_memory_type_select_cb select_blit_dst_memory_type;
93 uint8_t *(*alloc_shm)(struct wsi_image *image, unsigned size);
95 VkResult (*create_mem)(const struct wsi_swapchain *chain,
96 const struct wsi_image_info *info,
97 struct wsi_image *image);
99 VkResult (*finish_create)(const struct wsi_swapchain *chain,
100 const struct wsi_image_info *info,
101 struct wsi_image *image);
104 enum wsi_swapchain_blit_type {
105 WSI_SWAPCHAIN_NO_BLIT,
106 WSI_SWAPCHAIN_BUFFER_BLIT,
107 WSI_SWAPCHAIN_IMAGE_BLIT,
112 VkDeviceMemory memory;
117 VkDeviceMemory memory;
118 VkCommandBuffer *cmd_buffers;
122 uint64_t drm_modifier;
127 uint32_t row_pitches[4];
134 struct wsi_swapchain {
135 struct vk_object_base base;
137 const struct wsi_device *wsi;
140 VkAllocationCallbacks alloc;
142 VkPresentModeKHR present_mode;
143 VkSemaphore present_id_timeline;
145 int signal_dma_buf_from_semaphore;
146 VkSemaphore dma_buf_semaphore;
148 struct wsi_image_info image_info;
149 uint32_t image_count;
152 enum wsi_swapchain_blit_type type;
153 VkSemaphore *semaphores;
155 /* If the driver wants to use a special queue to execute the buffer blit,
156 * it'll implement the wsi_device::get_blit_queue callback.
157 * The created queue will be stored here and will be used to execute the
158 * buffer blit instead of using the present queue.
163 /* Command pools, one per queue family */
164 VkCommandPool *cmd_pools;
166 VkResult (*destroy)(struct wsi_swapchain *swapchain,
167 const VkAllocationCallbacks *pAllocator);
168 struct wsi_image *(*get_wsi_image)(struct wsi_swapchain *swapchain,
169 uint32_t image_index);
170 VkResult (*acquire_next_image)(struct wsi_swapchain *swap_chain,
171 const VkAcquireNextImageInfoKHR *info,
172 uint32_t *image_index);
173 VkResult (*queue_present)(struct wsi_swapchain *swap_chain,
174 uint32_t image_index,
176 const VkPresentRegionKHR *damage);
177 VkResult (*wait_for_present)(struct wsi_swapchain *swap_chain,
183 wsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd);
186 wsi_wl_surface_destroy(VkIcdSurfaceBase *icd_surface, VkInstance _instance,
187 const VkAllocationCallbacks *pAllocator);
190 wsi_swapchain_init(const struct wsi_device *wsi,
191 struct wsi_swapchain *chain,
193 const VkSwapchainCreateInfoKHR *pCreateInfo,
194 const struct wsi_base_image_params *image_params,
195 const VkAllocationCallbacks *pAllocator);
197 enum VkPresentModeKHR
198 wsi_swapchain_get_present_mode(struct wsi_device *wsi,
199 const VkSwapchainCreateInfoKHR *pCreateInfo);
201 void wsi_swapchain_finish(struct wsi_swapchain *chain);
204 wsi_select_memory_type(const struct wsi_device *wsi,
205 VkMemoryPropertyFlags req_flags,
206 VkMemoryPropertyFlags deny_flags,
209 wsi_select_device_memory_type(const struct wsi_device *wsi,
213 wsi_drm_image_needs_buffer_blit(const struct wsi_device *wsi,
214 const struct wsi_drm_image_params *params);
217 wsi_drm_configure_image(const struct wsi_swapchain *chain,
218 const VkSwapchainCreateInfoKHR *pCreateInfo,
219 const struct wsi_drm_image_params *params,
220 struct wsi_image_info *info);
223 wsi_cpu_image_needs_buffer_blit(const struct wsi_device *wsi,
224 const struct wsi_cpu_image_params *params);
227 wsi_configure_cpu_image(const struct wsi_swapchain *chain,
228 const VkSwapchainCreateInfoKHR *pCreateInfo,
229 const struct wsi_cpu_image_params *params,
230 struct wsi_image_info *info);
233 wsi_create_buffer_blit_context(const struct wsi_swapchain *chain,
234 const struct wsi_image_info *info,
235 struct wsi_image *image,
236 VkExternalMemoryHandleTypeFlags handle_types,
240 wsi_finish_create_blit_context(const struct wsi_swapchain *chain,
241 const struct wsi_image_info *info,
242 struct wsi_image *image);
245 wsi_configure_buffer_image(UNUSED const struct wsi_swapchain *chain,
246 const VkSwapchainCreateInfoKHR *pCreateInfo,
247 uint32_t stride_align, uint32_t size_align,
248 struct wsi_image_info *info);
251 wsi_configure_image_blit_image(UNUSED const struct wsi_swapchain *chain,
252 struct wsi_image_info *info);
255 wsi_configure_image(const struct wsi_swapchain *chain,
256 const VkSwapchainCreateInfoKHR *pCreateInfo,
257 VkExternalMemoryHandleTypeFlags handle_types,
258 struct wsi_image_info *info);
260 wsi_destroy_image_info(const struct wsi_swapchain *chain,
261 struct wsi_image_info *info);
263 wsi_create_image(const struct wsi_swapchain *chain,
264 const struct wsi_image_info *info,
265 struct wsi_image *image);
267 wsi_image_init(struct wsi_image *image);
270 wsi_destroy_image(const struct wsi_swapchain *chain,
271 struct wsi_image *image);
274 wsi_swapchain_wait_for_present_semaphore(const struct wsi_swapchain *chain,
275 uint64_t present_id, uint64_t timeout);
279 wsi_prepare_signal_dma_buf_from_semaphore(struct wsi_swapchain *chain,
280 const struct wsi_image *image);
282 wsi_signal_dma_buf_from_semaphore(const struct wsi_swapchain *chain,
283 const struct wsi_image *image);
285 wsi_create_sync_for_dma_buf_wait(const struct wsi_swapchain *chain,
286 const struct wsi_image *image,
287 enum vk_sync_features sync_features,
288 struct vk_sync **sync_out);
291 struct wsi_interface {
292 VkResult (*get_support)(VkIcdSurfaceBase *surface,
293 struct wsi_device *wsi_device,
294 uint32_t queueFamilyIndex,
295 VkBool32* pSupported);
296 VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface,
297 struct wsi_device *wsi_device,
298 const void *info_next,
299 VkSurfaceCapabilities2KHR* pSurfaceCapabilities);
300 VkResult (*get_formats)(VkIcdSurfaceBase *surface,
301 struct wsi_device *wsi_device,
302 uint32_t* pSurfaceFormatCount,
303 VkSurfaceFormatKHR* pSurfaceFormats);
304 VkResult (*get_formats2)(VkIcdSurfaceBase *surface,
305 struct wsi_device *wsi_device,
306 const void *info_next,
307 uint32_t* pSurfaceFormatCount,
308 VkSurfaceFormat2KHR* pSurfaceFormats);
309 VkResult (*get_present_modes)(VkIcdSurfaceBase *surface,
310 uint32_t* pPresentModeCount,
311 VkPresentModeKHR* pPresentModes);
312 VkResult (*get_present_rectangles)(VkIcdSurfaceBase *surface,
313 struct wsi_device *wsi_device,
314 uint32_t* pRectCount,
316 VkResult (*create_swapchain)(VkIcdSurfaceBase *surface,
318 struct wsi_device *wsi_device,
319 const VkSwapchainCreateInfoKHR* pCreateInfo,
320 const VkAllocationCallbacks* pAllocator,
321 struct wsi_swapchain **swapchain);
324 VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device,
325 const VkAllocationCallbacks *alloc,
326 const struct driOptionCache *dri_options);
327 void wsi_x11_finish_wsi(struct wsi_device *wsi_device,
328 const VkAllocationCallbacks *alloc);
329 VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device,
330 const VkAllocationCallbacks *alloc,
331 VkPhysicalDevice physical_device);
332 void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
333 const VkAllocationCallbacks *alloc);
334 VkResult wsi_win32_init_wsi(struct wsi_device *wsi_device,
335 const VkAllocationCallbacks *alloc,
336 VkPhysicalDevice physical_device);
337 void wsi_win32_finish_wsi(struct wsi_device *wsi_device,
338 const VkAllocationCallbacks *alloc);
342 wsi_display_init_wsi(struct wsi_device *wsi_device,
343 const VkAllocationCallbacks *alloc,
347 wsi_display_finish_wsi(struct wsi_device *wsi_device,
348 const VkAllocationCallbacks *alloc);
351 wsi_display_setup_syncobj_fd(struct wsi_device *wsi_device,
354 VK_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, base, VkSwapchainKHR,
355 VK_OBJECT_TYPE_SWAPCHAIN_KHR)
357 #if defined(HAVE_PTHREAD) && !defined(_WIN32)
359 wsi_init_pthread_cond_monotonic(pthread_cond_t *cond);
362 #endif /* WSI_COMMON_PRIVATE_H */