2 * Copyright © 2016 Red Hat
3 * based on intel anv code:
4 * Copyright © 2015 Intel Corporation
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:
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
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.
26 #include "tu_private.h"
29 #include "wsi_common.h"
30 #include "drm-uapi/drm_fourcc.h"
32 static VKAPI_PTR PFN_vkVoidFunction
33 tu_wsi_proc_addr(VkPhysicalDevice physicalDevice
, const char *pName
)
35 return tu_lookup_entrypoint_unchecked(pName
);
39 tu_wsi_init(struct tu_physical_device
*physical_device
)
43 result
= wsi_device_init(&physical_device
->wsi_device
,
44 tu_physical_device_to_handle(physical_device
),
46 &physical_device
->instance
->alloc
,
47 physical_device
->master_fd
, NULL
,
49 if (result
!= VK_SUCCESS
)
52 physical_device
->wsi_device
.supports_modifiers
= true;
58 tu_wsi_finish(struct tu_physical_device
*physical_device
)
60 wsi_device_finish(&physical_device
->wsi_device
,
61 &physical_device
->instance
->alloc
);
65 tu_DestroySurfaceKHR(VkInstance _instance
,
66 VkSurfaceKHR _surface
,
67 const VkAllocationCallbacks
*pAllocator
)
69 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
70 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
72 vk_free2(&instance
->alloc
, pAllocator
, surface
);
76 tu_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice
,
77 uint32_t queueFamilyIndex
,
81 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
83 return wsi_common_get_surface_support(
84 &device
->wsi_device
, queueFamilyIndex
, surface
, pSupported
);
88 tu_GetPhysicalDeviceSurfaceCapabilitiesKHR(
89 VkPhysicalDevice physicalDevice
,
91 VkSurfaceCapabilitiesKHR
*pSurfaceCapabilities
)
93 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
95 return wsi_common_get_surface_capabilities(&device
->wsi_device
, surface
,
96 pSurfaceCapabilities
);
100 tu_GetPhysicalDeviceSurfaceCapabilities2KHR(
101 VkPhysicalDevice physicalDevice
,
102 const VkPhysicalDeviceSurfaceInfo2KHR
*pSurfaceInfo
,
103 VkSurfaceCapabilities2KHR
*pSurfaceCapabilities
)
105 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
107 return wsi_common_get_surface_capabilities2(
108 &device
->wsi_device
, pSurfaceInfo
, pSurfaceCapabilities
);
112 tu_GetPhysicalDeviceSurfaceCapabilities2EXT(
113 VkPhysicalDevice physicalDevice
,
114 VkSurfaceKHR surface
,
115 VkSurfaceCapabilities2EXT
*pSurfaceCapabilities
)
117 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
119 return wsi_common_get_surface_capabilities2ext(
120 &device
->wsi_device
, surface
, pSurfaceCapabilities
);
124 tu_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice
,
125 VkSurfaceKHR surface
,
126 uint32_t *pSurfaceFormatCount
,
127 VkSurfaceFormatKHR
*pSurfaceFormats
)
129 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
131 return wsi_common_get_surface_formats(
132 &device
->wsi_device
, surface
, pSurfaceFormatCount
, pSurfaceFormats
);
136 tu_GetPhysicalDeviceSurfaceFormats2KHR(
137 VkPhysicalDevice physicalDevice
,
138 const VkPhysicalDeviceSurfaceInfo2KHR
*pSurfaceInfo
,
139 uint32_t *pSurfaceFormatCount
,
140 VkSurfaceFormat2KHR
*pSurfaceFormats
)
142 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
144 return wsi_common_get_surface_formats2(&device
->wsi_device
, pSurfaceInfo
,
150 tu_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice
,
151 VkSurfaceKHR surface
,
152 uint32_t *pPresentModeCount
,
153 VkPresentModeKHR
*pPresentModes
)
155 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
157 return wsi_common_get_surface_present_modes(
158 &device
->wsi_device
, surface
, pPresentModeCount
, pPresentModes
);
162 tu_CreateSwapchainKHR(VkDevice _device
,
163 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
164 const VkAllocationCallbacks
*pAllocator
,
165 VkSwapchainKHR
*pSwapchain
)
167 TU_FROM_HANDLE(tu_device
, device
, _device
);
168 const VkAllocationCallbacks
*alloc
;
172 alloc
= &device
->vk
.alloc
;
174 return wsi_common_create_swapchain(&device
->physical_device
->wsi_device
,
175 tu_device_to_handle(device
),
176 pCreateInfo
, alloc
, pSwapchain
);
180 tu_DestroySwapchainKHR(VkDevice _device
,
181 VkSwapchainKHR swapchain
,
182 const VkAllocationCallbacks
*pAllocator
)
184 TU_FROM_HANDLE(tu_device
, device
, _device
);
185 const VkAllocationCallbacks
*alloc
;
190 alloc
= &device
->vk
.alloc
;
192 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
196 tu_GetSwapchainImagesKHR(VkDevice device
,
197 VkSwapchainKHR swapchain
,
198 uint32_t *pSwapchainImageCount
,
199 VkImage
*pSwapchainImages
)
201 return wsi_common_get_images(swapchain
, pSwapchainImageCount
,
206 tu_AcquireNextImageKHR(VkDevice device
,
207 VkSwapchainKHR swapchain
,
209 VkSemaphore semaphore
,
211 uint32_t *pImageIndex
)
213 VkAcquireNextImageInfoKHR acquire_info
= {
214 .sType
= VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
,
215 .swapchain
= swapchain
,
217 .semaphore
= semaphore
,
222 return tu_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
226 tu_AcquireNextImage2KHR(VkDevice _device
,
227 const VkAcquireNextImageInfoKHR
*pAcquireInfo
,
228 uint32_t *pImageIndex
)
230 TU_FROM_HANDLE(tu_device
, device
, _device
);
231 struct tu_physical_device
*pdevice
= device
->physical_device
;
233 VkResult result
= wsi_common_acquire_next_image2(
234 &pdevice
->wsi_device
, _device
, pAcquireInfo
, pImageIndex
);
236 /* TODO signal fence and semaphore */
242 tu_QueuePresentKHR(VkQueue _queue
, const VkPresentInfoKHR
*pPresentInfo
)
244 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
245 return wsi_common_queue_present(
246 &queue
->device
->physical_device
->wsi_device
,
247 tu_device_to_handle(queue
->device
), _queue
, queue
->queue_family_index
,
252 tu_GetDeviceGroupPresentCapabilitiesKHR(
253 VkDevice device
, VkDeviceGroupPresentCapabilitiesKHR
*pCapabilities
)
255 memset(pCapabilities
->presentMask
, 0, sizeof(pCapabilities
->presentMask
));
256 pCapabilities
->presentMask
[0] = 0x1;
257 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
263 tu_GetDeviceGroupSurfacePresentModesKHR(
265 VkSurfaceKHR surface
,
266 VkDeviceGroupPresentModeFlagsKHR
*pModes
)
268 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
274 tu_GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice
,
275 VkSurfaceKHR surface
,
276 uint32_t *pRectCount
,
279 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
281 return wsi_common_get_present_rectangles(&device
->wsi_device
, surface
,