1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "anv_private.h"
25 #include "wsi_common.h"
26 #include "vk_format_info.h"
27 #include "vk_util.h"
28
29 static PFN_vkVoidFunction
anv_wsi_proc_addr(VkPhysicalDevice physicalDevice,const char * pName)30 anv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
31 {
32 ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
33 return anv_lookup_entrypoint(&physical_device->info, pName);
34 }
35
36 VkResult
anv_init_wsi(struct anv_physical_device * physical_device)37 anv_init_wsi(struct anv_physical_device *physical_device)
38 {
39 return wsi_device_init(&physical_device->wsi_device,
40 anv_physical_device_to_handle(physical_device),
41 anv_wsi_proc_addr,
42 &physical_device->instance->alloc);
43 }
44
45 void
anv_finish_wsi(struct anv_physical_device * physical_device)46 anv_finish_wsi(struct anv_physical_device *physical_device)
47 {
48 wsi_device_finish(&physical_device->wsi_device,
49 &physical_device->instance->alloc);
50 }
51
anv_DestroySurfaceKHR(VkInstance _instance,VkSurfaceKHR _surface,const VkAllocationCallbacks * pAllocator)52 void anv_DestroySurfaceKHR(
53 VkInstance _instance,
54 VkSurfaceKHR _surface,
55 const VkAllocationCallbacks* pAllocator)
56 {
57 ANV_FROM_HANDLE(anv_instance, instance, _instance);
58 ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
59
60 if (!surface)
61 return;
62
63 vk_free2(&instance->alloc, pAllocator, surface);
64 }
65
anv_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,VkSurfaceKHR surface,VkBool32 * pSupported)66 VkResult anv_GetPhysicalDeviceSurfaceSupportKHR(
67 VkPhysicalDevice physicalDevice,
68 uint32_t queueFamilyIndex,
69 VkSurfaceKHR surface,
70 VkBool32* pSupported)
71 {
72 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
73
74 return wsi_common_get_surface_support(&device->wsi_device,
75 device->local_fd,
76 queueFamilyIndex,
77 surface,
78 &device->instance->alloc,
79 pSupported);
80 }
81
anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,VkSurfaceCapabilitiesKHR * pSurfaceCapabilities)82 VkResult anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
83 VkPhysicalDevice physicalDevice,
84 VkSurfaceKHR surface,
85 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
86 {
87 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
88
89 return wsi_common_get_surface_capabilities(&device->wsi_device,
90 surface,
91 pSurfaceCapabilities);
92 }
93
anv_GetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceSurfaceInfo2KHR * pSurfaceInfo,VkSurfaceCapabilities2KHR * pSurfaceCapabilities)94 VkResult anv_GetPhysicalDeviceSurfaceCapabilities2KHR(
95 VkPhysicalDevice physicalDevice,
96 const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
97 VkSurfaceCapabilities2KHR* pSurfaceCapabilities)
98 {
99 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
100
101 return wsi_common_get_surface_capabilities2(&device->wsi_device,
102 pSurfaceInfo,
103 pSurfaceCapabilities);
104 }
105
anv_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pSurfaceFormatCount,VkSurfaceFormatKHR * pSurfaceFormats)106 VkResult anv_GetPhysicalDeviceSurfaceFormatsKHR(
107 VkPhysicalDevice physicalDevice,
108 VkSurfaceKHR surface,
109 uint32_t* pSurfaceFormatCount,
110 VkSurfaceFormatKHR* pSurfaceFormats)
111 {
112 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
113
114 return wsi_common_get_surface_formats(&device->wsi_device, surface,
115 pSurfaceFormatCount, pSurfaceFormats);
116 }
117
anv_GetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceSurfaceInfo2KHR * pSurfaceInfo,uint32_t * pSurfaceFormatCount,VkSurfaceFormat2KHR * pSurfaceFormats)118 VkResult anv_GetPhysicalDeviceSurfaceFormats2KHR(
119 VkPhysicalDevice physicalDevice,
120 const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
121 uint32_t* pSurfaceFormatCount,
122 VkSurfaceFormat2KHR* pSurfaceFormats)
123 {
124 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
125
126 return wsi_common_get_surface_formats2(&device->wsi_device, pSurfaceInfo,
127 pSurfaceFormatCount, pSurfaceFormats);
128 }
129
anv_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pPresentModeCount,VkPresentModeKHR * pPresentModes)130 VkResult anv_GetPhysicalDeviceSurfacePresentModesKHR(
131 VkPhysicalDevice physicalDevice,
132 VkSurfaceKHR surface,
133 uint32_t* pPresentModeCount,
134 VkPresentModeKHR* pPresentModes)
135 {
136 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
137
138 return wsi_common_get_surface_present_modes(&device->wsi_device, surface,
139 pPresentModeCount,
140 pPresentModes);
141 }
142
anv_CreateSwapchainKHR(VkDevice _device,const VkSwapchainCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSwapchainKHR * pSwapchain)143 VkResult anv_CreateSwapchainKHR(
144 VkDevice _device,
145 const VkSwapchainCreateInfoKHR* pCreateInfo,
146 const VkAllocationCallbacks* pAllocator,
147 VkSwapchainKHR* pSwapchain)
148 {
149 ANV_FROM_HANDLE(anv_device, device, _device);
150 struct wsi_device *wsi_device = &device->instance->physicalDevice.wsi_device;
151 const VkAllocationCallbacks *alloc;
152
153 if (pAllocator)
154 alloc = pAllocator;
155 else
156 alloc = &device->alloc;
157
158 return wsi_common_create_swapchain(wsi_device, _device, device->fd,
159 pCreateInfo, alloc, pSwapchain);
160 }
161
anv_DestroySwapchainKHR(VkDevice _device,VkSwapchainKHR swapchain,const VkAllocationCallbacks * pAllocator)162 void anv_DestroySwapchainKHR(
163 VkDevice _device,
164 VkSwapchainKHR swapchain,
165 const VkAllocationCallbacks* pAllocator)
166 {
167 ANV_FROM_HANDLE(anv_device, device, _device);
168 const VkAllocationCallbacks *alloc;
169
170 if (pAllocator)
171 alloc = pAllocator;
172 else
173 alloc = &device->alloc;
174
175 wsi_common_destroy_swapchain(_device, swapchain, alloc);
176 }
177
anv_GetSwapchainImagesKHR(VkDevice device,VkSwapchainKHR swapchain,uint32_t * pSwapchainImageCount,VkImage * pSwapchainImages)178 VkResult anv_GetSwapchainImagesKHR(
179 VkDevice device,
180 VkSwapchainKHR swapchain,
181 uint32_t* pSwapchainImageCount,
182 VkImage* pSwapchainImages)
183 {
184 return wsi_common_get_images(swapchain,
185 pSwapchainImageCount,
186 pSwapchainImages);
187 }
188
anv_AcquireNextImageKHR(VkDevice _device,VkSwapchainKHR swapchain,uint64_t timeout,VkSemaphore semaphore,VkFence fence,uint32_t * pImageIndex)189 VkResult anv_AcquireNextImageKHR(
190 VkDevice _device,
191 VkSwapchainKHR swapchain,
192 uint64_t timeout,
193 VkSemaphore semaphore,
194 VkFence fence,
195 uint32_t* pImageIndex)
196 {
197 ANV_FROM_HANDLE(anv_device, device, _device);
198 struct anv_physical_device *pdevice = &device->instance->physicalDevice;
199
200 VkResult result = wsi_common_acquire_next_image(&pdevice->wsi_device,
201 _device,
202 swapchain,
203 timeout,
204 semaphore,
205 pImageIndex);
206
207 /* Thanks to implicit sync, the image is ready immediately. However, we
208 * should wait for the current GPU state to finish.
209 */
210 if (fence != VK_NULL_HANDLE)
211 anv_QueueSubmit(anv_queue_to_handle(&device->queue), 0, NULL, fence);
212
213 return result;
214 }
215
anv_QueuePresentKHR(VkQueue _queue,const VkPresentInfoKHR * pPresentInfo)216 VkResult anv_QueuePresentKHR(
217 VkQueue _queue,
218 const VkPresentInfoKHR* pPresentInfo)
219 {
220 ANV_FROM_HANDLE(anv_queue, queue, _queue);
221 struct anv_physical_device *pdevice =
222 &queue->device->instance->physicalDevice;
223
224 return wsi_common_queue_present(&pdevice->wsi_device,
225 anv_device_to_handle(queue->device),
226 _queue, 0,
227 pPresentInfo);
228 }
229