Vulkan/wsi: Implement VK_EXT_display_surface_counter
[mesa.git] / src / vulkan / wsi / wsi_common.h
1 /*
2 * Copyright © 2015 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_H
24 #define WSI_COMMON_H
25
26 #include <stdint.h>
27 #include <stdbool.h>
28
29 #include "vk_alloc.h"
30 #include <vulkan/vulkan.h>
31 #include <vulkan/vk_icd.h>
32
33 /* This is guaranteed to not collide with anything because it's in the
34 * VK_KHR_swapchain namespace but not actually used by the extension.
35 */
36 #define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)1000001002
37 #define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)1000001003
38 #define VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA (VkStructureType)1000001004
39 #define VK_STRUCTURE_TYPE_WSI_SURFACE_SUPPORTED_COUNTERS_MESA (VkStructureType)1000001005
40
41 struct wsi_image_create_info {
42 VkStructureType sType;
43 const void *pNext;
44 bool scanout;
45
46 uint32_t modifier_count;
47 const uint64_t *modifiers;
48 };
49
50 struct wsi_memory_allocate_info {
51 VkStructureType sType;
52 const void *pNext;
53 bool implicit_sync;
54 };
55
56 struct wsi_format_modifier_properties {
57 uint64_t modifier;
58 uint32_t modifier_plane_count;
59 };
60
61 /* Chain in for vkGetPhysicalDeviceFormatProperties2KHR */
62 struct wsi_format_modifier_properties_list {
63 VkStructureType sType;
64 const void *pNext;
65
66 uint32_t modifier_count;
67 struct wsi_format_modifier_properties *modifier_properties;
68 };
69
70 /* To be chained into VkSurfaceCapabilities2KHR */
71 struct wsi_surface_supported_counters {
72 VkStructureType sType;
73 const void *pNext;
74
75 VkSurfaceCounterFlagsEXT supported_surface_counters;
76 };
77
78 struct wsi_interface;
79
80 #define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
81
82 struct wsi_device {
83 VkPhysicalDevice pdevice;
84 VkPhysicalDeviceMemoryProperties memory_props;
85 uint32_t queue_family_count;
86
87 bool supports_modifiers;
88 uint64_t (*image_get_modifier)(VkImage image);
89
90 #define WSI_CB(cb) PFN_vk##cb cb
91 WSI_CB(AllocateMemory);
92 WSI_CB(AllocateCommandBuffers);
93 WSI_CB(BindBufferMemory);
94 WSI_CB(BindImageMemory);
95 WSI_CB(BeginCommandBuffer);
96 WSI_CB(CmdCopyImageToBuffer);
97 WSI_CB(CreateBuffer);
98 WSI_CB(CreateCommandPool);
99 WSI_CB(CreateFence);
100 WSI_CB(CreateImage);
101 WSI_CB(DestroyBuffer);
102 WSI_CB(DestroyCommandPool);
103 WSI_CB(DestroyFence);
104 WSI_CB(DestroyImage);
105 WSI_CB(EndCommandBuffer);
106 WSI_CB(FreeMemory);
107 WSI_CB(FreeCommandBuffers);
108 WSI_CB(GetBufferMemoryRequirements);
109 WSI_CB(GetImageMemoryRequirements);
110 WSI_CB(GetImageSubresourceLayout);
111 WSI_CB(GetMemoryFdKHR);
112 WSI_CB(GetPhysicalDeviceFormatProperties);
113 WSI_CB(GetPhysicalDeviceFormatProperties2KHR);
114 WSI_CB(ResetFences);
115 WSI_CB(QueueSubmit);
116 WSI_CB(WaitForFences);
117 #undef WSI_CB
118
119 struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX];
120 };
121
122 typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);
123
124 VkResult
125 wsi_device_init(struct wsi_device *wsi,
126 VkPhysicalDevice pdevice,
127 WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
128 const VkAllocationCallbacks *alloc,
129 int display_fd);
130
131 void
132 wsi_device_finish(struct wsi_device *wsi,
133 const VkAllocationCallbacks *alloc);
134
135 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
136 \
137 static inline __VkIcdType * \
138 __VkIcdType ## _from_handle(__VkType _handle) \
139 { \
140 return (__VkIcdType *)(uintptr_t) _handle; \
141 } \
142 \
143 static inline __VkType \
144 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
145 { \
146 return (__VkType)(uintptr_t) _obj; \
147 }
148
149 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
150 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
151
152 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
153
154 VkResult
155 wsi_common_get_surface_support(struct wsi_device *wsi_device,
156 int local_fd,
157 uint32_t queueFamilyIndex,
158 VkSurfaceKHR surface,
159 const VkAllocationCallbacks *alloc,
160 VkBool32* pSupported);
161
162 VkResult
163 wsi_common_get_surface_capabilities(struct wsi_device *wsi_device,
164 VkSurfaceKHR surface,
165 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities);
166
167 VkResult
168 wsi_common_get_surface_capabilities2(struct wsi_device *wsi_device,
169 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
170 VkSurfaceCapabilities2KHR *pSurfaceCapabilities);
171
172 VkResult
173 wsi_common_get_surface_formats(struct wsi_device *wsi_device,
174 VkSurfaceKHR surface,
175 uint32_t *pSurfaceFormatCount,
176 VkSurfaceFormatKHR *pSurfaceFormats);
177
178 VkResult
179 wsi_common_get_surface_formats2(struct wsi_device *wsi_device,
180 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
181 uint32_t *pSurfaceFormatCount,
182 VkSurfaceFormat2KHR *pSurfaceFormats);
183
184 VkResult
185 wsi_common_get_surface_present_modes(struct wsi_device *wsi_device,
186 VkSurfaceKHR surface,
187 uint32_t *pPresentModeCount,
188 VkPresentModeKHR *pPresentModes);
189
190 VkResult
191 wsi_common_get_surface_capabilities2ext(
192 struct wsi_device *wsi_device,
193 VkSurfaceKHR surface,
194 VkSurfaceCapabilities2EXT *pSurfaceCapabilities);
195
196 VkResult
197 wsi_common_get_images(VkSwapchainKHR _swapchain,
198 uint32_t *pSwapchainImageCount,
199 VkImage *pSwapchainImages);
200
201 VkResult
202 wsi_common_acquire_next_image(const struct wsi_device *wsi,
203 VkDevice device,
204 VkSwapchainKHR swapchain,
205 uint64_t timeout,
206 VkSemaphore semaphore,
207 uint32_t *pImageIndex);
208
209 VkResult
210 wsi_common_create_swapchain(struct wsi_device *wsi,
211 VkDevice device,
212 int fd,
213 const VkSwapchainCreateInfoKHR *pCreateInfo,
214 const VkAllocationCallbacks *pAllocator,
215 VkSwapchainKHR *pSwapchain);
216 void
217 wsi_common_destroy_swapchain(VkDevice device,
218 VkSwapchainKHR swapchain,
219 const VkAllocationCallbacks *pAllocator);
220
221 VkResult
222 wsi_common_queue_present(const struct wsi_device *wsi,
223 VkDevice device_h,
224 VkQueue queue_h,
225 int queue_family_index,
226 const VkPresentInfoKHR *pPresentInfo);
227
228 #endif