Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / freedreno / vulkan / tu_wsi.c
1 /*
2 * Copyright © 2016 Red Hat
3 * based on intel anv code:
4 * Copyright © 2015 Intel Corporation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "tu_private.h"
27
28 #include "vk_util.h"
29 #include "wsi_common.h"
30 #include "drm-uapi/drm_fourcc.h"
31
32 static VKAPI_PTR PFN_vkVoidFunction
33 tu_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
34 {
35 return tu_lookup_entrypoint_unchecked(pName);
36 }
37
38 VkResult
39 tu_wsi_init(struct tu_physical_device *physical_device)
40 {
41 VkResult result;
42
43 result = wsi_device_init(&physical_device->wsi_device,
44 tu_physical_device_to_handle(physical_device),
45 tu_wsi_proc_addr,
46 &physical_device->instance->alloc,
47 physical_device->master_fd, NULL,
48 false);
49 if (result != VK_SUCCESS)
50 return result;
51
52 physical_device->wsi_device.supports_modifiers = true;
53
54 return VK_SUCCESS;
55 }
56
57 void
58 tu_wsi_finish(struct tu_physical_device *physical_device)
59 {
60 wsi_device_finish(&physical_device->wsi_device,
61 &physical_device->instance->alloc);
62 }
63
64 void
65 tu_DestroySurfaceKHR(VkInstance _instance,
66 VkSurfaceKHR _surface,
67 const VkAllocationCallbacks *pAllocator)
68 {
69 TU_FROM_HANDLE(tu_instance, instance, _instance);
70 ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
71
72 vk_free2(&instance->alloc, pAllocator, surface);
73 }
74
75 VkResult
76 tu_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
77 uint32_t queueFamilyIndex,
78 VkSurfaceKHR surface,
79 VkBool32 *pSupported)
80 {
81 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
82
83 return wsi_common_get_surface_support(
84 &device->wsi_device, queueFamilyIndex, surface, pSupported);
85 }
86
87 VkResult
88 tu_GetPhysicalDeviceSurfaceCapabilitiesKHR(
89 VkPhysicalDevice physicalDevice,
90 VkSurfaceKHR surface,
91 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)
92 {
93 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
94
95 return wsi_common_get_surface_capabilities(&device->wsi_device, surface,
96 pSurfaceCapabilities);
97 }
98
99 VkResult
100 tu_GetPhysicalDeviceSurfaceCapabilities2KHR(
101 VkPhysicalDevice physicalDevice,
102 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
103 VkSurfaceCapabilities2KHR *pSurfaceCapabilities)
104 {
105 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
106
107 return wsi_common_get_surface_capabilities2(
108 &device->wsi_device, pSurfaceInfo, pSurfaceCapabilities);
109 }
110
111 VkResult
112 tu_GetPhysicalDeviceSurfaceCapabilities2EXT(
113 VkPhysicalDevice physicalDevice,
114 VkSurfaceKHR surface,
115 VkSurfaceCapabilities2EXT *pSurfaceCapabilities)
116 {
117 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
118
119 return wsi_common_get_surface_capabilities2ext(
120 &device->wsi_device, surface, pSurfaceCapabilities);
121 }
122
123 VkResult
124 tu_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
125 VkSurfaceKHR surface,
126 uint32_t *pSurfaceFormatCount,
127 VkSurfaceFormatKHR *pSurfaceFormats)
128 {
129 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
130
131 return wsi_common_get_surface_formats(
132 &device->wsi_device, surface, pSurfaceFormatCount, pSurfaceFormats);
133 }
134
135 VkResult
136 tu_GetPhysicalDeviceSurfaceFormats2KHR(
137 VkPhysicalDevice physicalDevice,
138 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
139 uint32_t *pSurfaceFormatCount,
140 VkSurfaceFormat2KHR *pSurfaceFormats)
141 {
142 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
143
144 return wsi_common_get_surface_formats2(&device->wsi_device, pSurfaceInfo,
145 pSurfaceFormatCount,
146 pSurfaceFormats);
147 }
148
149 VkResult
150 tu_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
151 VkSurfaceKHR surface,
152 uint32_t *pPresentModeCount,
153 VkPresentModeKHR *pPresentModes)
154 {
155 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
156
157 return wsi_common_get_surface_present_modes(
158 &device->wsi_device, surface, pPresentModeCount, pPresentModes);
159 }
160
161 VkResult
162 tu_CreateSwapchainKHR(VkDevice _device,
163 const VkSwapchainCreateInfoKHR *pCreateInfo,
164 const VkAllocationCallbacks *pAllocator,
165 VkSwapchainKHR *pSwapchain)
166 {
167 TU_FROM_HANDLE(tu_device, device, _device);
168 const VkAllocationCallbacks *alloc;
169 if (pAllocator)
170 alloc = pAllocator;
171 else
172 alloc = &device->vk.alloc;
173
174 return wsi_common_create_swapchain(&device->physical_device->wsi_device,
175 tu_device_to_handle(device),
176 pCreateInfo, alloc, pSwapchain);
177 }
178
179 void
180 tu_DestroySwapchainKHR(VkDevice _device,
181 VkSwapchainKHR swapchain,
182 const VkAllocationCallbacks *pAllocator)
183 {
184 TU_FROM_HANDLE(tu_device, device, _device);
185 const VkAllocationCallbacks *alloc;
186
187 if (pAllocator)
188 alloc = pAllocator;
189 else
190 alloc = &device->vk.alloc;
191
192 wsi_common_destroy_swapchain(_device, swapchain, alloc);
193 }
194
195 VkResult
196 tu_GetSwapchainImagesKHR(VkDevice device,
197 VkSwapchainKHR swapchain,
198 uint32_t *pSwapchainImageCount,
199 VkImage *pSwapchainImages)
200 {
201 return wsi_common_get_images(swapchain, pSwapchainImageCount,
202 pSwapchainImages);
203 }
204
205 VkResult
206 tu_AcquireNextImageKHR(VkDevice device,
207 VkSwapchainKHR swapchain,
208 uint64_t timeout,
209 VkSemaphore semaphore,
210 VkFence fence,
211 uint32_t *pImageIndex)
212 {
213 VkAcquireNextImageInfoKHR acquire_info = {
214 .sType = VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR,
215 .swapchain = swapchain,
216 .timeout = timeout,
217 .semaphore = semaphore,
218 .fence = fence,
219 .deviceMask = 0,
220 };
221
222 return tu_AcquireNextImage2KHR(device, &acquire_info, pImageIndex);
223 }
224
225 VkResult
226 tu_AcquireNextImage2KHR(VkDevice _device,
227 const VkAcquireNextImageInfoKHR *pAcquireInfo,
228 uint32_t *pImageIndex)
229 {
230 TU_FROM_HANDLE(tu_device, device, _device);
231 struct tu_physical_device *pdevice = device->physical_device;
232
233 VkResult result = wsi_common_acquire_next_image2(
234 &pdevice->wsi_device, _device, pAcquireInfo, pImageIndex);
235
236 /* TODO signal fence and semaphore */
237
238 return result;
239 }
240
241 VkResult
242 tu_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)
243 {
244 TU_FROM_HANDLE(tu_queue, queue, _queue);
245 return wsi_common_queue_present(
246 &queue->device->physical_device->wsi_device,
247 tu_device_to_handle(queue->device), _queue, queue->queue_family_index,
248 pPresentInfo);
249 }
250
251 VkResult
252 tu_GetDeviceGroupPresentCapabilitiesKHR(
253 VkDevice device, VkDeviceGroupPresentCapabilitiesKHR *pCapabilities)
254 {
255 memset(pCapabilities->presentMask, 0, sizeof(pCapabilities->presentMask));
256 pCapabilities->presentMask[0] = 0x1;
257 pCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
258
259 return VK_SUCCESS;
260 }
261
262 VkResult
263 tu_GetDeviceGroupSurfacePresentModesKHR(
264 VkDevice device,
265 VkSurfaceKHR surface,
266 VkDeviceGroupPresentModeFlagsKHR *pModes)
267 {
268 *pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
269
270 return VK_SUCCESS;
271 }
272
273 VkResult
274 tu_GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice,
275 VkSurfaceKHR surface,
276 uint32_t *pRectCount,
277 VkRect2D *pRects)
278 {
279 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
280
281 return wsi_common_get_present_rectangles(&device->wsi_device, surface,
282 pRectCount, pRects);
283 }