vulkan/wsi: remove unused image_get_modifier
[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 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 if (result != VK_SUCCESS)
49 return result;
50
51 physical_device->wsi_device.supports_modifiers = true;
52
53 return VK_SUCCESS;
54 }
55
56 void
57 tu_wsi_finish(struct tu_physical_device *physical_device)
58 {
59 wsi_device_finish(&physical_device->wsi_device,
60 &physical_device->instance->alloc);
61 }
62
63 void
64 tu_DestroySurfaceKHR(VkInstance _instance,
65 VkSurfaceKHR _surface,
66 const VkAllocationCallbacks *pAllocator)
67 {
68 TU_FROM_HANDLE(tu_instance, instance, _instance);
69 ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
70
71 vk_free2(&instance->alloc, pAllocator, surface);
72 }
73
74 VkResult
75 tu_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
76 uint32_t queueFamilyIndex,
77 VkSurfaceKHR surface,
78 VkBool32 *pSupported)
79 {
80 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
81
82 return wsi_common_get_surface_support(
83 &device->wsi_device, queueFamilyIndex, surface, pSupported);
84 }
85
86 VkResult
87 tu_GetPhysicalDeviceSurfaceCapabilitiesKHR(
88 VkPhysicalDevice physicalDevice,
89 VkSurfaceKHR surface,
90 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)
91 {
92 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
93
94 return wsi_common_get_surface_capabilities(&device->wsi_device, surface,
95 pSurfaceCapabilities);
96 }
97
98 VkResult
99 tu_GetPhysicalDeviceSurfaceCapabilities2KHR(
100 VkPhysicalDevice physicalDevice,
101 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
102 VkSurfaceCapabilities2KHR *pSurfaceCapabilities)
103 {
104 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
105
106 return wsi_common_get_surface_capabilities2(
107 &device->wsi_device, pSurfaceInfo, pSurfaceCapabilities);
108 }
109
110 VkResult
111 tu_GetPhysicalDeviceSurfaceCapabilities2EXT(
112 VkPhysicalDevice physicalDevice,
113 VkSurfaceKHR surface,
114 VkSurfaceCapabilities2EXT *pSurfaceCapabilities)
115 {
116 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
117
118 return wsi_common_get_surface_capabilities2ext(
119 &device->wsi_device, surface, pSurfaceCapabilities);
120 }
121
122 VkResult
123 tu_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
124 VkSurfaceKHR surface,
125 uint32_t *pSurfaceFormatCount,
126 VkSurfaceFormatKHR *pSurfaceFormats)
127 {
128 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
129
130 return wsi_common_get_surface_formats(
131 &device->wsi_device, surface, pSurfaceFormatCount, pSurfaceFormats);
132 }
133
134 VkResult
135 tu_GetPhysicalDeviceSurfaceFormats2KHR(
136 VkPhysicalDevice physicalDevice,
137 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
138 uint32_t *pSurfaceFormatCount,
139 VkSurfaceFormat2KHR *pSurfaceFormats)
140 {
141 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
142
143 return wsi_common_get_surface_formats2(&device->wsi_device, pSurfaceInfo,
144 pSurfaceFormatCount,
145 pSurfaceFormats);
146 }
147
148 VkResult
149 tu_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
150 VkSurfaceKHR surface,
151 uint32_t *pPresentModeCount,
152 VkPresentModeKHR *pPresentModes)
153 {
154 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
155
156 return wsi_common_get_surface_present_modes(
157 &device->wsi_device, surface, pPresentModeCount, pPresentModes);
158 }
159
160 VkResult
161 tu_CreateSwapchainKHR(VkDevice _device,
162 const VkSwapchainCreateInfoKHR *pCreateInfo,
163 const VkAllocationCallbacks *pAllocator,
164 VkSwapchainKHR *pSwapchain)
165 {
166 TU_FROM_HANDLE(tu_device, device, _device);
167 const VkAllocationCallbacks *alloc;
168 if (pAllocator)
169 alloc = pAllocator;
170 else
171 alloc = &device->alloc;
172
173 return wsi_common_create_swapchain(&device->physical_device->wsi_device,
174 tu_device_to_handle(device),
175 pCreateInfo, alloc, pSwapchain);
176 }
177
178 void
179 tu_DestroySwapchainKHR(VkDevice _device,
180 VkSwapchainKHR swapchain,
181 const VkAllocationCallbacks *pAllocator)
182 {
183 TU_FROM_HANDLE(tu_device, device, _device);
184 const VkAllocationCallbacks *alloc;
185
186 if (pAllocator)
187 alloc = pAllocator;
188 else
189 alloc = &device->alloc;
190
191 wsi_common_destroy_swapchain(_device, swapchain, alloc);
192 }
193
194 VkResult
195 tu_GetSwapchainImagesKHR(VkDevice device,
196 VkSwapchainKHR swapchain,
197 uint32_t *pSwapchainImageCount,
198 VkImage *pSwapchainImages)
199 {
200 return wsi_common_get_images(swapchain, pSwapchainImageCount,
201 pSwapchainImages);
202 }
203
204 VkResult
205 tu_AcquireNextImageKHR(VkDevice device,
206 VkSwapchainKHR swapchain,
207 uint64_t timeout,
208 VkSemaphore semaphore,
209 VkFence fence,
210 uint32_t *pImageIndex)
211 {
212 VkAcquireNextImageInfoKHR acquire_info = {
213 .sType = VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR,
214 .swapchain = swapchain,
215 .timeout = timeout,
216 .semaphore = semaphore,
217 .fence = fence,
218 .deviceMask = 0,
219 };
220
221 return tu_AcquireNextImage2KHR(device, &acquire_info, pImageIndex);
222 }
223
224 VkResult
225 tu_AcquireNextImage2KHR(VkDevice _device,
226 const VkAcquireNextImageInfoKHR *pAcquireInfo,
227 uint32_t *pImageIndex)
228 {
229 TU_FROM_HANDLE(tu_device, device, _device);
230 struct tu_physical_device *pdevice = device->physical_device;
231
232 VkResult result = wsi_common_acquire_next_image2(
233 &pdevice->wsi_device, _device, pAcquireInfo, pImageIndex);
234
235 /* TODO signal fence and semaphore */
236
237 return result;
238 }
239
240 VkResult
241 tu_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)
242 {
243 TU_FROM_HANDLE(tu_queue, queue, _queue);
244 return wsi_common_queue_present(
245 &queue->device->physical_device->wsi_device,
246 tu_device_to_handle(queue->device), _queue, queue->queue_family_index,
247 pPresentInfo);
248 }
249
250 VkResult
251 tu_GetDeviceGroupPresentCapabilitiesKHR(
252 VkDevice device, VkDeviceGroupPresentCapabilitiesKHR *pCapabilities)
253 {
254 memset(pCapabilities->presentMask, 0, sizeof(pCapabilities->presentMask));
255 pCapabilities->presentMask[0] = 0x1;
256 pCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
257
258 return VK_SUCCESS;
259 }
260
261 VkResult
262 tu_GetDeviceGroupSurfacePresentModesKHR(
263 VkDevice device,
264 VkSurfaceKHR surface,
265 VkDeviceGroupPresentModeFlagsKHR *pModes)
266 {
267 *pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
268
269 return VK_SUCCESS;
270 }
271
272 VkResult
273 tu_GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice,
274 VkSurfaceKHR surface,
275 uint32_t *pRectCount,
276 VkRect2D *pRects)
277 {
278 TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
279
280 return wsi_common_get_present_rectangles(&device->wsi_device, surface,
281 pRectCount, pRects);
282 }