android: radv: add libmesa_git_sha1 static dependency
[mesa.git] / src / amd / vulkan / radv_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 DEALINGS
23 * IN THE SOFTWARE.
24 */
25
26 #include "radv_private.h"
27 #include "radv_meta.h"
28 #include "wsi_common.h"
29 #include "vk_util.h"
30 #include "util/macros.h"
31
32 static PFN_vkVoidFunction
33 radv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
34 {
35 return radv_lookup_entrypoint_unchecked(pName);
36 }
37
38 VkResult
39 radv_init_wsi(struct radv_physical_device *physical_device)
40 {
41 return wsi_device_init(&physical_device->wsi_device,
42 radv_physical_device_to_handle(physical_device),
43 radv_wsi_proc_addr,
44 &physical_device->instance->alloc,
45 physical_device->master_fd);
46 }
47
48 void
49 radv_finish_wsi(struct radv_physical_device *physical_device)
50 {
51 wsi_device_finish(&physical_device->wsi_device,
52 &physical_device->instance->alloc);
53 }
54
55 void radv_DestroySurfaceKHR(
56 VkInstance _instance,
57 VkSurfaceKHR _surface,
58 const VkAllocationCallbacks* pAllocator)
59 {
60 RADV_FROM_HANDLE(radv_instance, instance, _instance);
61 ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
62
63 vk_free2(&instance->alloc, pAllocator, surface);
64 }
65
66 VkResult radv_GetPhysicalDeviceSurfaceSupportKHR(
67 VkPhysicalDevice physicalDevice,
68 uint32_t queueFamilyIndex,
69 VkSurfaceKHR surface,
70 VkBool32* pSupported)
71 {
72 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
73
74 return wsi_common_get_surface_support(&device->wsi_device,
75 queueFamilyIndex,
76 surface,
77 pSupported);
78 }
79
80 VkResult radv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
81 VkPhysicalDevice physicalDevice,
82 VkSurfaceKHR surface,
83 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
84 {
85 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
86
87 return wsi_common_get_surface_capabilities(&device->wsi_device,
88 surface,
89 pSurfaceCapabilities);
90 }
91
92 VkResult radv_GetPhysicalDeviceSurfaceCapabilities2KHR(
93 VkPhysicalDevice physicalDevice,
94 const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
95 VkSurfaceCapabilities2KHR* pSurfaceCapabilities)
96 {
97 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
98
99 return wsi_common_get_surface_capabilities2(&device->wsi_device,
100 pSurfaceInfo,
101 pSurfaceCapabilities);
102 }
103
104 VkResult radv_GetPhysicalDeviceSurfaceCapabilities2EXT(
105 VkPhysicalDevice physicalDevice,
106 VkSurfaceKHR surface,
107 VkSurfaceCapabilities2EXT* pSurfaceCapabilities)
108 {
109 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
110
111 return wsi_common_get_surface_capabilities2ext(&device->wsi_device,
112 surface,
113 pSurfaceCapabilities);
114 }
115
116 VkResult radv_GetPhysicalDeviceSurfaceFormatsKHR(
117 VkPhysicalDevice physicalDevice,
118 VkSurfaceKHR surface,
119 uint32_t* pSurfaceFormatCount,
120 VkSurfaceFormatKHR* pSurfaceFormats)
121 {
122 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
123
124 return wsi_common_get_surface_formats(&device->wsi_device,
125 surface,
126 pSurfaceFormatCount,
127 pSurfaceFormats);
128 }
129
130 VkResult radv_GetPhysicalDeviceSurfaceFormats2KHR(
131 VkPhysicalDevice physicalDevice,
132 const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
133 uint32_t* pSurfaceFormatCount,
134 VkSurfaceFormat2KHR* pSurfaceFormats)
135 {
136 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
137
138 return wsi_common_get_surface_formats2(&device->wsi_device,
139 pSurfaceInfo,
140 pSurfaceFormatCount,
141 pSurfaceFormats);
142 }
143
144 VkResult radv_GetPhysicalDeviceSurfacePresentModesKHR(
145 VkPhysicalDevice physicalDevice,
146 VkSurfaceKHR surface,
147 uint32_t* pPresentModeCount,
148 VkPresentModeKHR* pPresentModes)
149 {
150 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
151
152 return wsi_common_get_surface_present_modes(&device->wsi_device,
153 surface,
154 pPresentModeCount,
155 pPresentModes);
156 }
157
158 VkResult radv_CreateSwapchainKHR(
159 VkDevice _device,
160 const VkSwapchainCreateInfoKHR* pCreateInfo,
161 const VkAllocationCallbacks* pAllocator,
162 VkSwapchainKHR* pSwapchain)
163 {
164 RADV_FROM_HANDLE(radv_device, device, _device);
165 const VkAllocationCallbacks *alloc;
166 if (pAllocator)
167 alloc = pAllocator;
168 else
169 alloc = &device->alloc;
170
171 return wsi_common_create_swapchain(&device->physical_device->wsi_device,
172 radv_device_to_handle(device),
173 pCreateInfo,
174 alloc,
175 pSwapchain);
176 }
177
178 void radv_DestroySwapchainKHR(
179 VkDevice _device,
180 VkSwapchainKHR swapchain,
181 const VkAllocationCallbacks* pAllocator)
182 {
183 RADV_FROM_HANDLE(radv_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 radv_GetSwapchainImagesKHR(
195 VkDevice device,
196 VkSwapchainKHR swapchain,
197 uint32_t* pSwapchainImageCount,
198 VkImage* pSwapchainImages)
199 {
200 return wsi_common_get_images(swapchain,
201 pSwapchainImageCount,
202 pSwapchainImages);
203 }
204
205 VkResult radv_AcquireNextImageKHR(
206 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 radv_AcquireNextImage2KHR(device, &acquire_info, pImageIndex);
223 }
224
225 VkResult radv_AcquireNextImage2KHR(
226 VkDevice _device,
227 const VkAcquireNextImageInfoKHR* pAcquireInfo,
228 uint32_t* pImageIndex)
229 {
230 RADV_FROM_HANDLE(radv_device, device, _device);
231 struct radv_physical_device *pdevice = device->physical_device;
232 RADV_FROM_HANDLE(radv_fence, fence, pAcquireInfo->fence);
233
234 VkResult result = wsi_common_acquire_next_image2(&pdevice->wsi_device,
235 _device,
236 pAcquireInfo,
237 pImageIndex);
238
239 if (fence && (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR)) {
240 fence->submitted = true;
241 fence->signalled = true;
242 if (fence->temp_syncobj) {
243 device->ws->signal_syncobj(device->ws, fence->temp_syncobj);
244 } else if (fence->syncobj) {
245 device->ws->signal_syncobj(device->ws, fence->syncobj);
246 }
247 }
248 return result;
249 }
250
251 VkResult radv_QueuePresentKHR(
252 VkQueue _queue,
253 const VkPresentInfoKHR* pPresentInfo)
254 {
255 RADV_FROM_HANDLE(radv_queue, queue, _queue);
256 return wsi_common_queue_present(&queue->device->physical_device->wsi_device,
257 radv_device_to_handle(queue->device),
258 _queue,
259 queue->queue_family_index,
260 pPresentInfo);
261 }
262
263
264 VkResult radv_GetDeviceGroupPresentCapabilitiesKHR(
265 VkDevice device,
266 VkDeviceGroupPresentCapabilitiesKHR* pCapabilities)
267 {
268 memset(pCapabilities->presentMask, 0,
269 sizeof(pCapabilities->presentMask));
270 pCapabilities->presentMask[0] = 0x1;
271 pCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
272
273 return VK_SUCCESS;
274 }
275
276 VkResult radv_GetDeviceGroupSurfacePresentModesKHR(
277 VkDevice device,
278 VkSurfaceKHR surface,
279 VkDeviceGroupPresentModeFlagsKHR* pModes)
280 {
281 *pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
282
283 return VK_SUCCESS;
284 }
285
286 VkResult radv_GetPhysicalDevicePresentRectanglesKHR(
287 VkPhysicalDevice physicalDevice,
288 VkSurfaceKHR surface,
289 uint32_t* pRectCount,
290 VkRect2D* pRects)
291 {
292 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
293
294 return wsi_common_get_present_rectangles(&device->wsi_device,
295 surface,
296 pRectCount, pRects);
297 }