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_unchecked(pName
);
39 radv_init_wsi(struct radv_physical_device
*physical_device
)
41 return wsi_device_init(&physical_device
->wsi_device
,
42 radv_physical_device_to_handle(physical_device
),
44 &physical_device
->instance
->alloc
,
45 physical_device
->master_fd
);
49 radv_finish_wsi(struct radv_physical_device
*physical_device
)
51 wsi_device_finish(&physical_device
->wsi_device
,
52 &physical_device
->instance
->alloc
);
55 void radv_DestroySurfaceKHR(
57 VkSurfaceKHR _surface
,
58 const VkAllocationCallbacks
* pAllocator
)
60 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
61 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
63 vk_free2(&instance
->alloc
, pAllocator
, surface
);
66 VkResult
radv_GetPhysicalDeviceSurfaceSupportKHR(
67 VkPhysicalDevice physicalDevice
,
68 uint32_t queueFamilyIndex
,
72 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
74 return wsi_common_get_surface_support(&device
->wsi_device
,
80 VkResult
radv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
81 VkPhysicalDevice physicalDevice
,
83 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
85 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
87 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
89 pSurfaceCapabilities
);
92 VkResult
radv_GetPhysicalDeviceSurfaceCapabilities2KHR(
93 VkPhysicalDevice physicalDevice
,
94 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
95 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
97 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
99 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
101 pSurfaceCapabilities
);
104 VkResult
radv_GetPhysicalDeviceSurfaceCapabilities2EXT(
105 VkPhysicalDevice physicalDevice
,
106 VkSurfaceKHR surface
,
107 VkSurfaceCapabilities2EXT
* pSurfaceCapabilities
)
109 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
111 return wsi_common_get_surface_capabilities2ext(&device
->wsi_device
,
113 pSurfaceCapabilities
);
116 VkResult
radv_GetPhysicalDeviceSurfaceFormatsKHR(
117 VkPhysicalDevice physicalDevice
,
118 VkSurfaceKHR surface
,
119 uint32_t* pSurfaceFormatCount
,
120 VkSurfaceFormatKHR
* pSurfaceFormats
)
122 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
124 return wsi_common_get_surface_formats(&device
->wsi_device
,
130 VkResult
radv_GetPhysicalDeviceSurfaceFormats2KHR(
131 VkPhysicalDevice physicalDevice
,
132 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
133 uint32_t* pSurfaceFormatCount
,
134 VkSurfaceFormat2KHR
* pSurfaceFormats
)
136 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
138 return wsi_common_get_surface_formats2(&device
->wsi_device
,
144 VkResult
radv_GetPhysicalDeviceSurfacePresentModesKHR(
145 VkPhysicalDevice physicalDevice
,
146 VkSurfaceKHR surface
,
147 uint32_t* pPresentModeCount
,
148 VkPresentModeKHR
* pPresentModes
)
150 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
152 return wsi_common_get_surface_present_modes(&device
->wsi_device
,
158 VkResult
radv_CreateSwapchainKHR(
160 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
161 const VkAllocationCallbacks
* pAllocator
,
162 VkSwapchainKHR
* pSwapchain
)
164 RADV_FROM_HANDLE(radv_device
, device
, _device
);
165 const VkAllocationCallbacks
*alloc
;
169 alloc
= &device
->alloc
;
171 return wsi_common_create_swapchain(&device
->physical_device
->wsi_device
,
172 radv_device_to_handle(device
),
178 void radv_DestroySwapchainKHR(
180 VkSwapchainKHR swapchain
,
181 const VkAllocationCallbacks
* pAllocator
)
183 RADV_FROM_HANDLE(radv_device
, device
, _device
);
184 const VkAllocationCallbacks
*alloc
;
189 alloc
= &device
->alloc
;
191 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
194 VkResult
radv_GetSwapchainImagesKHR(
196 VkSwapchainKHR swapchain
,
197 uint32_t* pSwapchainImageCount
,
198 VkImage
* pSwapchainImages
)
200 return wsi_common_get_images(swapchain
,
201 pSwapchainImageCount
,
205 VkResult
radv_AcquireNextImageKHR(
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 radv_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
225 VkResult
radv_AcquireNextImage2KHR(
227 const VkAcquireNextImageInfoKHR
* pAcquireInfo
,
228 uint32_t* pImageIndex
)
230 RADV_FROM_HANDLE(radv_device
, device
, _device
);
231 struct radv_physical_device
*pdevice
= device
->physical_device
;
232 RADV_FROM_HANDLE(radv_fence
, fence
, pAcquireInfo
->fence
);
234 VkResult result
= wsi_common_acquire_next_image2(&pdevice
->wsi_device
,
239 if (fence
&& (result
== VK_SUCCESS
|| result
== VK_SUBOPTIMAL_KHR
)) {
240 fence
->submitted
= true;
241 fence
->signalled
= true;
242 if (fence
->temp_syncobj
) {
243 device
->ws
->signal_syncobj(device
->ws
, fence
->temp_syncobj
);
244 } else if (fence
->syncobj
) {
245 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
251 VkResult
radv_QueuePresentKHR(
253 const VkPresentInfoKHR
* pPresentInfo
)
255 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
256 return wsi_common_queue_present(&queue
->device
->physical_device
->wsi_device
,
257 radv_device_to_handle(queue
->device
),
259 queue
->queue_family_index
,
264 VkResult
radv_GetDeviceGroupPresentCapabilitiesKHR(
266 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
268 memset(pCapabilities
->presentMask
, 0,
269 sizeof(pCapabilities
->presentMask
));
270 pCapabilities
->presentMask
[0] = 0x1;
271 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
276 VkResult
radv_GetDeviceGroupSurfacePresentModesKHR(
278 VkSurfaceKHR surface
,
279 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
281 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
286 VkResult
radv_GetPhysicalDevicePresentRectanglesKHR(
287 VkPhysicalDevice physicalDevice
,
288 VkSurfaceKHR surface
,
289 uint32_t* pRectCount
,
292 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
294 return wsi_common_get_present_rectangles(&device
->wsi_device
,