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_init_wsi(struct radv_physical_device
*physical_device
)
43 wsi_device_init(&physical_device
->wsi_device
,
44 radv_physical_device_to_handle(physical_device
),
47 #ifdef VK_USE_PLATFORM_XCB_KHR
48 result
= wsi_x11_init_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
49 if (result
!= VK_SUCCESS
)
53 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
54 result
= wsi_wl_init_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
,
55 radv_physical_device_to_handle(physical_device
));
56 if (result
!= VK_SUCCESS
) {
57 #ifdef VK_USE_PLATFORM_XCB_KHR
58 wsi_x11_finish_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
68 radv_finish_wsi(struct radv_physical_device
*physical_device
)
70 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
71 wsi_wl_finish_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
73 #ifdef VK_USE_PLATFORM_XCB_KHR
74 wsi_x11_finish_wsi(&physical_device
->wsi_device
, &physical_device
->instance
->alloc
);
78 void radv_DestroySurfaceKHR(
80 VkSurfaceKHR _surface
,
81 const VkAllocationCallbacks
* pAllocator
)
83 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
84 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
86 vk_free2(&instance
->alloc
, pAllocator
, surface
);
89 VkResult
radv_GetPhysicalDeviceSurfaceSupportKHR(
90 VkPhysicalDevice physicalDevice
,
91 uint32_t queueFamilyIndex
,
95 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
97 return wsi_common_get_surface_support(&device
->wsi_device
,
101 &device
->instance
->alloc
,
105 VkResult
radv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
106 VkPhysicalDevice physicalDevice
,
107 VkSurfaceKHR surface
,
108 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
110 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
112 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
114 pSurfaceCapabilities
);
117 VkResult
radv_GetPhysicalDeviceSurfaceFormatsKHR(
118 VkPhysicalDevice physicalDevice
,
119 VkSurfaceKHR surface
,
120 uint32_t* pSurfaceFormatCount
,
121 VkSurfaceFormatKHR
* pSurfaceFormats
)
123 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
125 return wsi_common_get_surface_formats(&device
->wsi_device
,
131 VkResult
radv_GetPhysicalDeviceSurfacePresentModesKHR(
132 VkPhysicalDevice physicalDevice
,
133 VkSurfaceKHR surface
,
134 uint32_t* pPresentModeCount
,
135 VkPresentModeKHR
* pPresentModes
)
137 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
139 return wsi_common_get_surface_present_modes(&device
->wsi_device
,
145 VkResult
radv_CreateSwapchainKHR(
147 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
148 const VkAllocationCallbacks
* pAllocator
,
149 VkSwapchainKHR
* pSwapchain
)
151 RADV_FROM_HANDLE(radv_device
, device
, _device
);
152 const VkAllocationCallbacks
*alloc
;
156 alloc
= &device
->alloc
;
158 return wsi_common_create_swapchain(&device
->physical_device
->wsi_device
,
159 radv_device_to_handle(device
),
160 device
->physical_device
->local_fd
,
166 void radv_DestroySwapchainKHR(
168 VkSwapchainKHR swapchain
,
169 const VkAllocationCallbacks
* pAllocator
)
171 RADV_FROM_HANDLE(radv_device
, device
, _device
);
172 const VkAllocationCallbacks
*alloc
;
177 alloc
= &device
->alloc
;
179 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
182 VkResult
radv_GetSwapchainImagesKHR(
184 VkSwapchainKHR swapchain
,
185 uint32_t* pSwapchainImageCount
,
186 VkImage
* pSwapchainImages
)
188 return wsi_common_get_images(swapchain
,
189 pSwapchainImageCount
,
193 VkResult
radv_AcquireNextImageKHR(
195 VkSwapchainKHR swapchain
,
197 VkSemaphore semaphore
,
199 uint32_t* pImageIndex
)
201 RADV_FROM_HANDLE(radv_device
, device
, _device
);
202 struct radv_physical_device
*pdevice
= device
->physical_device
;
203 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
205 VkResult result
= wsi_common_acquire_next_image(&pdevice
->wsi_device
,
212 if (fence
&& (result
== VK_SUCCESS
|| result
== VK_SUBOPTIMAL_KHR
)) {
213 fence
->submitted
= true;
214 fence
->signalled
= true;
219 VkResult
radv_QueuePresentKHR(
221 const VkPresentInfoKHR
* pPresentInfo
)
223 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
224 return wsi_common_queue_present(&queue
->device
->physical_device
->wsi_device
,
225 radv_device_to_handle(queue
->device
),
227 queue
->queue_family_index
,