vulkan/wsi: Add drm_modifier member to wsi_image
[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 uint64_t drm_modifier;
39 int num_planes;
40 uint32_t sizes[4];
41 uint32_t offsets[4];
42 uint32_t row_pitches[4];
43 int fds[4];
44 };
45
46 struct wsi_swapchain {
47 const struct wsi_device *wsi;
48
49 VkDevice device;
50 VkAllocationCallbacks alloc;
51 VkFence fences[3];
52 VkPresentModeKHR present_mode;
53 uint32_t image_count;
54
55 bool use_prime_blit;
56
57 /* Command pools, one per queue family */
58 VkCommandPool *cmd_pools;
59
60 VkResult (*destroy)(struct wsi_swapchain *swapchain,
61 const VkAllocationCallbacks *pAllocator);
62 struct wsi_image *(*get_wsi_image)(struct wsi_swapchain *swapchain,
63 uint32_t image_index);
64 VkResult (*acquire_next_image)(struct wsi_swapchain *swap_chain,
65 uint64_t timeout, VkSemaphore semaphore,
66 uint32_t *image_index);
67 VkResult (*queue_present)(struct wsi_swapchain *swap_chain,
68 uint32_t image_index,
69 const VkPresentRegionKHR *damage);
70 };
71
72 VkResult
73 wsi_swapchain_init(const struct wsi_device *wsi,
74 struct wsi_swapchain *chain,
75 VkDevice device,
76 const VkSwapchainCreateInfoKHR *pCreateInfo,
77 const VkAllocationCallbacks *pAllocator);
78
79 void wsi_swapchain_finish(struct wsi_swapchain *chain);
80
81 VkResult
82 wsi_create_native_image(const struct wsi_swapchain *chain,
83 const VkSwapchainCreateInfoKHR *pCreateInfo,
84 struct wsi_image *image);
85
86 VkResult
87 wsi_create_prime_image(const struct wsi_swapchain *chain,
88 const VkSwapchainCreateInfoKHR *pCreateInfo,
89 struct wsi_image *image);
90
91 void
92 wsi_destroy_image(const struct wsi_swapchain *chain,
93 struct wsi_image *image);
94
95
96 struct wsi_interface {
97 VkResult (*get_support)(VkIcdSurfaceBase *surface,
98 struct wsi_device *wsi_device,
99 const VkAllocationCallbacks *alloc,
100 uint32_t queueFamilyIndex,
101 int local_fd,
102 VkBool32* pSupported);
103 VkResult (*get_capabilities)(VkIcdSurfaceBase *surface,
104 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities);
105 VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface,
106 const void *info_next,
107 VkSurfaceCapabilities2KHR* pSurfaceCapabilities);
108 VkResult (*get_formats)(VkIcdSurfaceBase *surface,
109 struct wsi_device *wsi_device,
110 uint32_t* pSurfaceFormatCount,
111 VkSurfaceFormatKHR* pSurfaceFormats);
112 VkResult (*get_formats2)(VkIcdSurfaceBase *surface,
113 struct wsi_device *wsi_device,
114 const void *info_next,
115 uint32_t* pSurfaceFormatCount,
116 VkSurfaceFormat2KHR* pSurfaceFormats);
117 VkResult (*get_present_modes)(VkIcdSurfaceBase *surface,
118 uint32_t* pPresentModeCount,
119 VkPresentModeKHR* pPresentModes);
120 VkResult (*create_swapchain)(VkIcdSurfaceBase *surface,
121 VkDevice device,
122 struct wsi_device *wsi_device,
123 int local_fd,
124 const VkSwapchainCreateInfoKHR* pCreateInfo,
125 const VkAllocationCallbacks* pAllocator,
126 struct wsi_swapchain **swapchain);
127 };
128
129 VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device,
130 const VkAllocationCallbacks *alloc);
131 void wsi_x11_finish_wsi(struct wsi_device *wsi_device,
132 const VkAllocationCallbacks *alloc);
133 VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device,
134 const VkAllocationCallbacks *alloc,
135 VkPhysicalDevice physical_device);
136 void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
137 const VkAllocationCallbacks *alloc);
138
139
140 #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
141 \
142 static inline struct __wsi_type * \
143 __wsi_type ## _from_handle(__VkType _handle) \
144 { \
145 return (struct __wsi_type *)(uintptr_t) _handle; \
146 } \
147 \
148 static inline __VkType \
149 __wsi_type ## _to_handle(struct __wsi_type *_obj) \
150 { \
151 return (__VkType)(uintptr_t) _obj; \
152 }
153
154 #define WSI_FROM_HANDLE(__wsi_type, __name, __handle) \
155 struct __wsi_type *__name = __wsi_type ## _from_handle(__handle)
156
157 WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, VkSwapchainKHR)
158
159 #endif /* WSI_COMMON_PRIVATE_H */