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 PFN_vkVoidFunction
33 tu_wsi_proc_addr(VkPhysicalDevice physicalDevice
, const char *pName
)
35 return tu_lookup_entrypoint_unchecked(pName
);
39 tu_wsi_image_get_modifier(VkImage _image
)
41 TU_FROM_HANDLE(tu_image
, image
, _image
);
43 if (!image
->layout
.tile_mode
)
44 return DRM_FORMAT_MOD_LINEAR
;
46 if (image
->layout
.ubwc_size
)
47 return DRM_FORMAT_MOD_QCOM_COMPRESSED
;
49 /* TODO invent a modifier for tiled but not UBWC buffers: */
50 return DRM_FORMAT_MOD_INVALID
;
54 tu_wsi_init(struct tu_physical_device
*physical_device
)
58 result
= wsi_device_init(&physical_device
->wsi_device
,
59 tu_physical_device_to_handle(physical_device
),
61 &physical_device
->instance
->alloc
,
62 physical_device
->master_fd
, NULL
);
63 if (result
!= VK_SUCCESS
)
66 physical_device
->wsi_device
.supports_modifiers
= true;
67 physical_device
->wsi_device
.image_get_modifier
= tu_wsi_image_get_modifier
;
73 tu_wsi_finish(struct tu_physical_device
*physical_device
)
75 wsi_device_finish(&physical_device
->wsi_device
,
76 &physical_device
->instance
->alloc
);
80 tu_DestroySurfaceKHR(VkInstance _instance
,
81 VkSurfaceKHR _surface
,
82 const VkAllocationCallbacks
*pAllocator
)
84 TU_FROM_HANDLE(tu_instance
, instance
, _instance
);
85 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
87 vk_free2(&instance
->alloc
, pAllocator
, surface
);
91 tu_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice
,
92 uint32_t queueFamilyIndex
,
96 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
98 return wsi_common_get_surface_support(
99 &device
->wsi_device
, queueFamilyIndex
, surface
, pSupported
);
103 tu_GetPhysicalDeviceSurfaceCapabilitiesKHR(
104 VkPhysicalDevice physicalDevice
,
105 VkSurfaceKHR surface
,
106 VkSurfaceCapabilitiesKHR
*pSurfaceCapabilities
)
108 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
110 return wsi_common_get_surface_capabilities(&device
->wsi_device
, surface
,
111 pSurfaceCapabilities
);
115 tu_GetPhysicalDeviceSurfaceCapabilities2KHR(
116 VkPhysicalDevice physicalDevice
,
117 const VkPhysicalDeviceSurfaceInfo2KHR
*pSurfaceInfo
,
118 VkSurfaceCapabilities2KHR
*pSurfaceCapabilities
)
120 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
122 return wsi_common_get_surface_capabilities2(
123 &device
->wsi_device
, pSurfaceInfo
, pSurfaceCapabilities
);
127 tu_GetPhysicalDeviceSurfaceCapabilities2EXT(
128 VkPhysicalDevice physicalDevice
,
129 VkSurfaceKHR surface
,
130 VkSurfaceCapabilities2EXT
*pSurfaceCapabilities
)
132 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
134 return wsi_common_get_surface_capabilities2ext(
135 &device
->wsi_device
, surface
, pSurfaceCapabilities
);
139 tu_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice
,
140 VkSurfaceKHR surface
,
141 uint32_t *pSurfaceFormatCount
,
142 VkSurfaceFormatKHR
*pSurfaceFormats
)
144 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
146 return wsi_common_get_surface_formats(
147 &device
->wsi_device
, surface
, pSurfaceFormatCount
, pSurfaceFormats
);
151 tu_GetPhysicalDeviceSurfaceFormats2KHR(
152 VkPhysicalDevice physicalDevice
,
153 const VkPhysicalDeviceSurfaceInfo2KHR
*pSurfaceInfo
,
154 uint32_t *pSurfaceFormatCount
,
155 VkSurfaceFormat2KHR
*pSurfaceFormats
)
157 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
159 return wsi_common_get_surface_formats2(&device
->wsi_device
, pSurfaceInfo
,
165 tu_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice
,
166 VkSurfaceKHR surface
,
167 uint32_t *pPresentModeCount
,
168 VkPresentModeKHR
*pPresentModes
)
170 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
172 return wsi_common_get_surface_present_modes(
173 &device
->wsi_device
, surface
, pPresentModeCount
, pPresentModes
);
177 tu_CreateSwapchainKHR(VkDevice _device
,
178 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
179 const VkAllocationCallbacks
*pAllocator
,
180 VkSwapchainKHR
*pSwapchain
)
182 TU_FROM_HANDLE(tu_device
, device
, _device
);
183 const VkAllocationCallbacks
*alloc
;
187 alloc
= &device
->alloc
;
189 return wsi_common_create_swapchain(&device
->physical_device
->wsi_device
,
190 tu_device_to_handle(device
),
191 pCreateInfo
, alloc
, pSwapchain
);
195 tu_DestroySwapchainKHR(VkDevice _device
,
196 VkSwapchainKHR swapchain
,
197 const VkAllocationCallbacks
*pAllocator
)
199 TU_FROM_HANDLE(tu_device
, device
, _device
);
200 const VkAllocationCallbacks
*alloc
;
205 alloc
= &device
->alloc
;
207 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
211 tu_GetSwapchainImagesKHR(VkDevice device
,
212 VkSwapchainKHR swapchain
,
213 uint32_t *pSwapchainImageCount
,
214 VkImage
*pSwapchainImages
)
216 return wsi_common_get_images(swapchain
, pSwapchainImageCount
,
221 tu_AcquireNextImageKHR(VkDevice device
,
222 VkSwapchainKHR swapchain
,
224 VkSemaphore semaphore
,
226 uint32_t *pImageIndex
)
228 VkAcquireNextImageInfoKHR acquire_info
= {
229 .sType
= VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
,
230 .swapchain
= swapchain
,
232 .semaphore
= semaphore
,
237 return tu_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
241 tu_AcquireNextImage2KHR(VkDevice _device
,
242 const VkAcquireNextImageInfoKHR
*pAcquireInfo
,
243 uint32_t *pImageIndex
)
245 TU_FROM_HANDLE(tu_device
, device
, _device
);
246 struct tu_physical_device
*pdevice
= device
->physical_device
;
248 VkResult result
= wsi_common_acquire_next_image2(
249 &pdevice
->wsi_device
, _device
, pAcquireInfo
, pImageIndex
);
251 /* TODO signal fence and semaphore */
257 tu_QueuePresentKHR(VkQueue _queue
, const VkPresentInfoKHR
*pPresentInfo
)
259 TU_FROM_HANDLE(tu_queue
, queue
, _queue
);
260 return wsi_common_queue_present(
261 &queue
->device
->physical_device
->wsi_device
,
262 tu_device_to_handle(queue
->device
), _queue
, queue
->queue_family_index
,
267 tu_GetDeviceGroupPresentCapabilitiesKHR(
268 VkDevice device
, VkDeviceGroupPresentCapabilitiesKHR
*pCapabilities
)
270 memset(pCapabilities
->presentMask
, 0, sizeof(pCapabilities
->presentMask
));
271 pCapabilities
->presentMask
[0] = 0x1;
272 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
278 tu_GetDeviceGroupSurfacePresentModesKHR(
280 VkSurfaceKHR surface
,
281 VkDeviceGroupPresentModeFlagsKHR
*pModes
)
283 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
289 tu_GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice
,
290 VkSurfaceKHR surface
,
291 uint32_t *pRectCount
,
294 TU_FROM_HANDLE(tu_physical_device
, device
, physicalDevice
);
296 return wsi_common_get_present_rectangles(&device
->wsi_device
, surface
,