vulkan/wsi: Drop some unneeded cruft from the API
[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(pName);
36 }
37
38 VkResult
39 radv_init_wsi(struct radv_physical_device *physical_device)
40 {
41 VkResult result;
42
43 wsi_device_init(&physical_device->wsi_device,
44 radv_physical_device_to_handle(physical_device),
45 radv_wsi_proc_addr);
46
47 #ifdef VK_USE_PLATFORM_XCB_KHR
48 result = wsi_x11_init_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
49 if (result != VK_SUCCESS)
50 return result;
51 #endif
52
53 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
54 result = wsi_wl_init_wsi(&physical_device->wsi_device, &physical_device->instance->alloc,
55 radv_physical_device_to_handle(physical_device));
56 if (result != VK_SUCCESS) {
57 #ifdef VK_USE_PLATFORM_XCB_KHR
58 wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
59 #endif
60 return result;
61 }
62 #endif
63
64 return VK_SUCCESS;
65 }
66
67 void
68 radv_finish_wsi(struct radv_physical_device *physical_device)
69 {
70 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
71 wsi_wl_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
72 #endif
73 #ifdef VK_USE_PLATFORM_XCB_KHR
74 wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
75 #endif
76 }
77
78 void radv_DestroySurfaceKHR(
79 VkInstance _instance,
80 VkSurfaceKHR _surface,
81 const VkAllocationCallbacks* pAllocator)
82 {
83 RADV_FROM_HANDLE(radv_instance, instance, _instance);
84 ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
85
86 vk_free2(&instance->alloc, pAllocator, surface);
87 }
88
89 VkResult radv_GetPhysicalDeviceSurfaceSupportKHR(
90 VkPhysicalDevice physicalDevice,
91 uint32_t queueFamilyIndex,
92 VkSurfaceKHR surface,
93 VkBool32* pSupported)
94 {
95 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
96
97 return wsi_common_get_surface_support(&device->wsi_device,
98 device->local_fd,
99 queueFamilyIndex,
100 surface,
101 &device->instance->alloc,
102 pSupported);
103 }
104
105 VkResult radv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
106 VkPhysicalDevice physicalDevice,
107 VkSurfaceKHR surface,
108 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
109 {
110 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
111
112 return wsi_common_get_surface_capabilities(&device->wsi_device,
113 surface,
114 pSurfaceCapabilities);
115 }
116
117 VkResult radv_GetPhysicalDeviceSurfaceFormatsKHR(
118 VkPhysicalDevice physicalDevice,
119 VkSurfaceKHR surface,
120 uint32_t* pSurfaceFormatCount,
121 VkSurfaceFormatKHR* pSurfaceFormats)
122 {
123 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
124
125 return wsi_common_get_surface_formats(&device->wsi_device,
126 surface,
127 pSurfaceFormatCount,
128 pSurfaceFormats);
129 }
130
131 VkResult radv_GetPhysicalDeviceSurfacePresentModesKHR(
132 VkPhysicalDevice physicalDevice,
133 VkSurfaceKHR surface,
134 uint32_t* pPresentModeCount,
135 VkPresentModeKHR* pPresentModes)
136 {
137 RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
138
139 return wsi_common_get_surface_present_modes(&device->wsi_device,
140 surface,
141 pPresentModeCount,
142 pPresentModes);
143 }
144
145 VkResult radv_CreateSwapchainKHR(
146 VkDevice _device,
147 const VkSwapchainCreateInfoKHR* pCreateInfo,
148 const VkAllocationCallbacks* pAllocator,
149 VkSwapchainKHR* pSwapchain)
150 {
151 RADV_FROM_HANDLE(radv_device, device, _device);
152 const VkAllocationCallbacks *alloc;
153 if (pAllocator)
154 alloc = pAllocator;
155 else
156 alloc = &device->alloc;
157
158 return wsi_common_create_swapchain(&device->physical_device->wsi_device,
159 radv_device_to_handle(device),
160 device->physical_device->local_fd,
161 pCreateInfo,
162 alloc,
163 pSwapchain);
164 }
165
166 void radv_DestroySwapchainKHR(
167 VkDevice _device,
168 VkSwapchainKHR swapchain,
169 const VkAllocationCallbacks* pAllocator)
170 {
171 RADV_FROM_HANDLE(radv_device, device, _device);
172 const VkAllocationCallbacks *alloc;
173
174 if (pAllocator)
175 alloc = pAllocator;
176 else
177 alloc = &device->alloc;
178
179 wsi_common_destroy_swapchain(_device, swapchain, alloc);
180 }
181
182 VkResult radv_GetSwapchainImagesKHR(
183 VkDevice device,
184 VkSwapchainKHR swapchain,
185 uint32_t* pSwapchainImageCount,
186 VkImage* pSwapchainImages)
187 {
188 return wsi_common_get_images(swapchain,
189 pSwapchainImageCount,
190 pSwapchainImages);
191 }
192
193 VkResult radv_AcquireNextImageKHR(
194 VkDevice _device,
195 VkSwapchainKHR swapchain,
196 uint64_t timeout,
197 VkSemaphore semaphore,
198 VkFence _fence,
199 uint32_t* pImageIndex)
200 {
201 RADV_FROM_HANDLE(radv_device, device, _device);
202 struct radv_physical_device *pdevice = device->physical_device;
203 RADV_FROM_HANDLE(radv_fence, fence, _fence);
204
205 VkResult result = wsi_common_acquire_next_image(&pdevice->wsi_device,
206 _device,
207 swapchain,
208 timeout,
209 semaphore,
210 pImageIndex);
211
212 if (fence && (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR)) {
213 fence->submitted = true;
214 fence->signalled = true;
215 }
216 return result;
217 }
218
219 VkResult radv_QueuePresentKHR(
220 VkQueue _queue,
221 const VkPresentInfoKHR* pPresentInfo)
222 {
223 RADV_FROM_HANDLE(radv_queue, queue, _queue);
224 return wsi_common_queue_present(&queue->device->physical_device->wsi_device,
225 radv_device_to_handle(queue->device),
226 _queue,
227 queue->queue_family_index,
228 pPresentInfo);
229 }