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