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