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
,
62 if (result
!= VK_SUCCESS
)
65 physical_device
->wsi_device
.set_memory_ownership
= radv_wsi_set_memory_ownership
;
70 radv_finish_wsi(struct radv_physical_device
*physical_device
)
72 wsi_device_finish(&physical_device
->wsi_device
,
73 &physical_device
->instance
->alloc
);
76 void radv_DestroySurfaceKHR(
78 VkSurfaceKHR _surface
,
79 const VkAllocationCallbacks
* pAllocator
)
81 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
82 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
84 vk_free2(&instance
->alloc
, pAllocator
, surface
);
87 VkResult
radv_GetPhysicalDeviceSurfaceSupportKHR(
88 VkPhysicalDevice physicalDevice
,
89 uint32_t queueFamilyIndex
,
93 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
95 return wsi_common_get_surface_support(&device
->wsi_device
,
101 VkResult
radv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
102 VkPhysicalDevice physicalDevice
,
103 VkSurfaceKHR surface
,
104 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
106 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
108 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
110 pSurfaceCapabilities
);
113 VkResult
radv_GetPhysicalDeviceSurfaceCapabilities2KHR(
114 VkPhysicalDevice physicalDevice
,
115 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
116 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
118 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
120 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
122 pSurfaceCapabilities
);
125 VkResult
radv_GetPhysicalDeviceSurfaceCapabilities2EXT(
126 VkPhysicalDevice physicalDevice
,
127 VkSurfaceKHR surface
,
128 VkSurfaceCapabilities2EXT
* pSurfaceCapabilities
)
130 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
132 return wsi_common_get_surface_capabilities2ext(&device
->wsi_device
,
134 pSurfaceCapabilities
);
137 VkResult
radv_GetPhysicalDeviceSurfaceFormatsKHR(
138 VkPhysicalDevice physicalDevice
,
139 VkSurfaceKHR surface
,
140 uint32_t* pSurfaceFormatCount
,
141 VkSurfaceFormatKHR
* pSurfaceFormats
)
143 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
145 return wsi_common_get_surface_formats(&device
->wsi_device
,
151 VkResult
radv_GetPhysicalDeviceSurfaceFormats2KHR(
152 VkPhysicalDevice physicalDevice
,
153 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
154 uint32_t* pSurfaceFormatCount
,
155 VkSurfaceFormat2KHR
* pSurfaceFormats
)
157 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
159 return wsi_common_get_surface_formats2(&device
->wsi_device
,
165 VkResult
radv_GetPhysicalDeviceSurfacePresentModesKHR(
166 VkPhysicalDevice physicalDevice
,
167 VkSurfaceKHR surface
,
168 uint32_t* pPresentModeCount
,
169 VkPresentModeKHR
* pPresentModes
)
171 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
173 return wsi_common_get_surface_present_modes(&device
->wsi_device
,
179 VkResult
radv_CreateSwapchainKHR(
181 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
182 const VkAllocationCallbacks
* pAllocator
,
183 VkSwapchainKHR
* pSwapchain
)
185 RADV_FROM_HANDLE(radv_device
, device
, _device
);
186 const VkAllocationCallbacks
*alloc
;
190 alloc
= &device
->vk
.alloc
;
192 return wsi_common_create_swapchain(&device
->physical_device
->wsi_device
,
193 radv_device_to_handle(device
),
199 void radv_DestroySwapchainKHR(
201 VkSwapchainKHR swapchain
,
202 const VkAllocationCallbacks
* pAllocator
)
204 RADV_FROM_HANDLE(radv_device
, device
, _device
);
205 const VkAllocationCallbacks
*alloc
;
210 alloc
= &device
->vk
.alloc
;
212 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
215 VkResult
radv_GetSwapchainImagesKHR(
217 VkSwapchainKHR swapchain
,
218 uint32_t* pSwapchainImageCount
,
219 VkImage
* pSwapchainImages
)
221 return wsi_common_get_images(swapchain
,
222 pSwapchainImageCount
,
226 VkResult
radv_AcquireNextImageKHR(
228 VkSwapchainKHR swapchain
,
230 VkSemaphore semaphore
,
232 uint32_t* pImageIndex
)
234 VkAcquireNextImageInfoKHR acquire_info
= {
235 .sType
= VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
,
236 .swapchain
= swapchain
,
238 .semaphore
= semaphore
,
243 return radv_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
246 VkResult
radv_AcquireNextImage2KHR(
248 const VkAcquireNextImageInfoKHR
* pAcquireInfo
,
249 uint32_t* pImageIndex
)
251 RADV_FROM_HANDLE(radv_device
, device
, _device
);
252 struct radv_physical_device
*pdevice
= device
->physical_device
;
253 RADV_FROM_HANDLE(radv_fence
, fence
, pAcquireInfo
->fence
);
254 RADV_FROM_HANDLE(radv_semaphore
, semaphore
, pAcquireInfo
->semaphore
);
256 VkResult result
= wsi_common_acquire_next_image2(&pdevice
->wsi_device
,
261 if (result
== VK_SUCCESS
|| result
== VK_SUBOPTIMAL_KHR
) {
263 struct radv_fence_part
*part
=
264 fence
->temporary
.kind
!= RADV_FENCE_NONE
?
265 &fence
->temporary
: &fence
->permanent
;
267 switch (part
->kind
) {
268 case RADV_FENCE_NONE
:
270 case RADV_FENCE_WINSYS
:
271 device
->ws
->signal_fence(part
->fence
);
273 case RADV_FENCE_SYNCOBJ
:
274 device
->ws
->signal_syncobj(device
->ws
, part
->syncobj
, 0);
277 unreachable("Invalid WSI fence type");
281 struct radv_semaphore_part
*part
=
282 semaphore
->temporary
.kind
!= RADV_SEMAPHORE_NONE
?
283 &semaphore
->temporary
: &semaphore
->permanent
;
285 switch (part
->kind
) {
286 case RADV_SEMAPHORE_NONE
:
287 case RADV_SEMAPHORE_WINSYS
:
288 /* Do not need to do anything. */
290 case RADV_SEMAPHORE_TIMELINE
:
291 case RADV_SEMAPHORE_TIMELINE_SYNCOBJ
:
292 unreachable("WSI only allows binary semaphores.");
293 case RADV_SEMAPHORE_SYNCOBJ
:
294 device
->ws
->signal_syncobj(device
->ws
, part
->syncobj
, 0);
302 VkResult
radv_QueuePresentKHR(
304 const VkPresentInfoKHR
* pPresentInfo
)
306 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
307 return wsi_common_queue_present(&queue
->device
->physical_device
->wsi_device
,
308 radv_device_to_handle(queue
->device
),
310 queue
->queue_family_index
,
315 VkResult
radv_GetDeviceGroupPresentCapabilitiesKHR(
317 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
319 memset(pCapabilities
->presentMask
, 0,
320 sizeof(pCapabilities
->presentMask
));
321 pCapabilities
->presentMask
[0] = 0x1;
322 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
327 VkResult
radv_GetDeviceGroupSurfacePresentModesKHR(
329 VkSurfaceKHR surface
,
330 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
332 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
337 VkResult
radv_GetPhysicalDevicePresentRectanglesKHR(
338 VkPhysicalDevice physicalDevice
,
339 VkSurfaceKHR surface
,
340 uint32_t* pRectCount
,
343 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
345 return wsi_common_get_present_rectangles(&device
->wsi_device
,