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 DEALINGS
26 #include "radv_private.h"
27 #include "radv_meta.h"
28 #include "wsi_common.h"
30 #include "util/macros.h"
32 static PFN_vkVoidFunction
33 radv_wsi_proc_addr(VkPhysicalDevice physicalDevice
, const char *pName
)
35 return radv_lookup_entrypoint(pName
);
39 radv_wsi_set_memory_ownership(VkDevice _device
,
43 RADV_FROM_HANDLE(radv_device
, device
, _device
);
44 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
47 radv_bo_list_add(device
, mem
->bo
);
49 radv_bo_list_remove(device
, mem
->bo
);
53 radv_init_wsi(struct radv_physical_device
*physical_device
)
55 VkResult result
= wsi_device_init(&physical_device
->wsi_device
,
56 radv_physical_device_to_handle(physical_device
),
58 &physical_device
->instance
->alloc
,
59 physical_device
->master_fd
,
60 &physical_device
->instance
->dri_options
);
61 if (result
!= VK_SUCCESS
)
64 physical_device
->wsi_device
.set_memory_ownership
= radv_wsi_set_memory_ownership
;
69 radv_finish_wsi(struct radv_physical_device
*physical_device
)
71 wsi_device_finish(&physical_device
->wsi_device
,
72 &physical_device
->instance
->alloc
);
75 void radv_DestroySurfaceKHR(
77 VkSurfaceKHR _surface
,
78 const VkAllocationCallbacks
* pAllocator
)
80 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
81 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
83 vk_free2(&instance
->alloc
, pAllocator
, surface
);
86 VkResult
radv_GetPhysicalDeviceSurfaceSupportKHR(
87 VkPhysicalDevice physicalDevice
,
88 uint32_t queueFamilyIndex
,
92 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
94 return wsi_common_get_surface_support(&device
->wsi_device
,
100 VkResult
radv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
101 VkPhysicalDevice physicalDevice
,
102 VkSurfaceKHR surface
,
103 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
105 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
107 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
109 pSurfaceCapabilities
);
112 VkResult
radv_GetPhysicalDeviceSurfaceCapabilities2KHR(
113 VkPhysicalDevice physicalDevice
,
114 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
115 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
117 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
119 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
121 pSurfaceCapabilities
);
124 VkResult
radv_GetPhysicalDeviceSurfaceCapabilities2EXT(
125 VkPhysicalDevice physicalDevice
,
126 VkSurfaceKHR surface
,
127 VkSurfaceCapabilities2EXT
* pSurfaceCapabilities
)
129 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
131 return wsi_common_get_surface_capabilities2ext(&device
->wsi_device
,
133 pSurfaceCapabilities
);
136 VkResult
radv_GetPhysicalDeviceSurfaceFormatsKHR(
137 VkPhysicalDevice physicalDevice
,
138 VkSurfaceKHR surface
,
139 uint32_t* pSurfaceFormatCount
,
140 VkSurfaceFormatKHR
* pSurfaceFormats
)
142 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
144 return wsi_common_get_surface_formats(&device
->wsi_device
,
150 VkResult
radv_GetPhysicalDeviceSurfaceFormats2KHR(
151 VkPhysicalDevice physicalDevice
,
152 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
153 uint32_t* pSurfaceFormatCount
,
154 VkSurfaceFormat2KHR
* pSurfaceFormats
)
156 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
158 return wsi_common_get_surface_formats2(&device
->wsi_device
,
164 VkResult
radv_GetPhysicalDeviceSurfacePresentModesKHR(
165 VkPhysicalDevice physicalDevice
,
166 VkSurfaceKHR surface
,
167 uint32_t* pPresentModeCount
,
168 VkPresentModeKHR
* pPresentModes
)
170 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
172 return wsi_common_get_surface_present_modes(&device
->wsi_device
,
178 VkResult
radv_CreateSwapchainKHR(
180 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
181 const VkAllocationCallbacks
* pAllocator
,
182 VkSwapchainKHR
* pSwapchain
)
184 RADV_FROM_HANDLE(radv_device
, device
, _device
);
185 const VkAllocationCallbacks
*alloc
;
189 alloc
= &device
->vk
.alloc
;
191 return wsi_common_create_swapchain(&device
->physical_device
->wsi_device
,
192 radv_device_to_handle(device
),
198 void radv_DestroySwapchainKHR(
200 VkSwapchainKHR swapchain
,
201 const VkAllocationCallbacks
* pAllocator
)
203 RADV_FROM_HANDLE(radv_device
, device
, _device
);
204 const VkAllocationCallbacks
*alloc
;
209 alloc
= &device
->vk
.alloc
;
211 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
214 VkResult
radv_GetSwapchainImagesKHR(
216 VkSwapchainKHR swapchain
,
217 uint32_t* pSwapchainImageCount
,
218 VkImage
* pSwapchainImages
)
220 return wsi_common_get_images(swapchain
,
221 pSwapchainImageCount
,
225 VkResult
radv_AcquireNextImageKHR(
227 VkSwapchainKHR swapchain
,
229 VkSemaphore semaphore
,
231 uint32_t* pImageIndex
)
233 VkAcquireNextImageInfoKHR acquire_info
= {
234 .sType
= VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
,
235 .swapchain
= swapchain
,
237 .semaphore
= semaphore
,
242 return radv_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
245 VkResult
radv_AcquireNextImage2KHR(
247 const VkAcquireNextImageInfoKHR
* pAcquireInfo
,
248 uint32_t* pImageIndex
)
250 RADV_FROM_HANDLE(radv_device
, device
, _device
);
251 struct radv_physical_device
*pdevice
= device
->physical_device
;
252 RADV_FROM_HANDLE(radv_fence
, fence
, pAcquireInfo
->fence
);
253 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pAcquireInfo
->semaphore
);
255 VkResult result
= wsi_common_acquire_next_image2(&pdevice
->wsi_device
,
260 if (result
== VK_SUCCESS
|| result
== VK_SUBOPTIMAL_KHR
) {
263 device
->ws
->signal_fence(fence
->fence
);
264 if (fence
->temp_syncobj
) {
265 device
->ws
->signal_syncobj(device
->ws
, fence
->temp_syncobj
);
266 } else if (fence
->syncobj
) {
267 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
271 struct radv_semaphore_part
*part
=
272 semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
?
273 &semaphore
->temporary
: &semaphore
->permanent
;
275 switch (part
->kind
) {
276 case RADV_SEMAPHORE_NONE
:
277 case RADV_SEMAPHORE_WINSYS
:
278 /* Do not need to do anything. */
280 case RADV_SEMAPHORE_TIMELINE
:
281 unreachable("WSI only allows binary semaphores.");
282 case RADV_SEMAPHORE_SYNCOBJ
:
283 device
->ws
->signal_syncobj(device
->ws
, part
->syncobj
);
291 VkResult
radv_QueuePresentKHR(
293 const VkPresentInfoKHR
* pPresentInfo
)
295 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
296 return wsi_common_queue_present(&queue
->device
->physical_device
->wsi_device
,
297 radv_device_to_handle(queue
->device
),
299 queue
->queue_family_index
,
304 VkResult
radv_GetDeviceGroupPresentCapabilitiesKHR(
306 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
308 memset(pCapabilities
->presentMask
, 0,
309 sizeof(pCapabilities
->presentMask
));
310 pCapabilities
->presentMask
[0] = 0x1;
311 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
316 VkResult
radv_GetDeviceGroupSurfacePresentModesKHR(
318 VkSurfaceKHR surface
,
319 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
321 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
326 VkResult
radv_GetPhysicalDevicePresentRectanglesKHR(
327 VkPhysicalDevice physicalDevice
,
328 VkSurfaceKHR surface
,
329 uint32_t* pRectCount
,
332 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
334 return wsi_common_get_present_rectangles(&device
->wsi_device
,