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
,
78 &device
->instance
->alloc
,
82 VkResult
radv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
83 VkPhysicalDevice physicalDevice
,
85 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
87 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
89 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
91 pSurfaceCapabilities
);
94 VkResult
radv_GetPhysicalDeviceSurfaceCapabilities2KHR(
95 VkPhysicalDevice physicalDevice
,
96 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
97 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
)
99 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
101 return wsi_common_get_surface_capabilities2(&device
->wsi_device
,
103 pSurfaceCapabilities
);
106 VkResult
radv_GetPhysicalDeviceSurfaceCapabilities2EXT(
107 VkPhysicalDevice physicalDevice
,
108 VkSurfaceKHR surface
,
109 VkSurfaceCapabilities2EXT
* pSurfaceCapabilities
)
111 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
113 return wsi_common_get_surface_capabilities2ext(&device
->wsi_device
,
115 pSurfaceCapabilities
);
118 VkResult
radv_GetPhysicalDeviceSurfaceFormatsKHR(
119 VkPhysicalDevice physicalDevice
,
120 VkSurfaceKHR surface
,
121 uint32_t* pSurfaceFormatCount
,
122 VkSurfaceFormatKHR
* pSurfaceFormats
)
124 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
126 return wsi_common_get_surface_formats(&device
->wsi_device
,
132 VkResult
radv_GetPhysicalDeviceSurfaceFormats2KHR(
133 VkPhysicalDevice physicalDevice
,
134 const VkPhysicalDeviceSurfaceInfo2KHR
* pSurfaceInfo
,
135 uint32_t* pSurfaceFormatCount
,
136 VkSurfaceFormat2KHR
* pSurfaceFormats
)
138 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
140 return wsi_common_get_surface_formats2(&device
->wsi_device
,
146 VkResult
radv_GetPhysicalDeviceSurfacePresentModesKHR(
147 VkPhysicalDevice physicalDevice
,
148 VkSurfaceKHR surface
,
149 uint32_t* pPresentModeCount
,
150 VkPresentModeKHR
* pPresentModes
)
152 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
154 return wsi_common_get_surface_present_modes(&device
->wsi_device
,
160 VkResult
radv_CreateSwapchainKHR(
162 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
163 const VkAllocationCallbacks
* pAllocator
,
164 VkSwapchainKHR
* pSwapchain
)
166 RADV_FROM_HANDLE(radv_device
, device
, _device
);
167 const VkAllocationCallbacks
*alloc
;
171 alloc
= &device
->alloc
;
173 return wsi_common_create_swapchain(&device
->physical_device
->wsi_device
,
174 radv_device_to_handle(device
),
175 device
->physical_device
->local_fd
,
181 void radv_DestroySwapchainKHR(
183 VkSwapchainKHR swapchain
,
184 const VkAllocationCallbacks
* pAllocator
)
186 RADV_FROM_HANDLE(radv_device
, device
, _device
);
187 const VkAllocationCallbacks
*alloc
;
192 alloc
= &device
->alloc
;
194 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
197 VkResult
radv_GetSwapchainImagesKHR(
199 VkSwapchainKHR swapchain
,
200 uint32_t* pSwapchainImageCount
,
201 VkImage
* pSwapchainImages
)
203 return wsi_common_get_images(swapchain
,
204 pSwapchainImageCount
,
208 VkResult
radv_AcquireNextImageKHR(
210 VkSwapchainKHR swapchain
,
212 VkSemaphore semaphore
,
214 uint32_t* pImageIndex
)
216 RADV_FROM_HANDLE(radv_device
, device
, _device
);
217 struct radv_physical_device
*pdevice
= device
->physical_device
;
218 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
220 VkResult result
= wsi_common_acquire_next_image(&pdevice
->wsi_device
,
227 if (fence
&& (result
== VK_SUCCESS
|| result
== VK_SUBOPTIMAL_KHR
)) {
228 fence
->submitted
= true;
229 fence
->signalled
= true;
230 if (fence
->temp_syncobj
) {
231 device
->ws
->signal_syncobj(device
->ws
, fence
->temp_syncobj
);
232 } else if (fence
->syncobj
) {
233 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
239 VkResult
radv_QueuePresentKHR(
241 const VkPresentInfoKHR
* pPresentInfo
)
243 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
244 return wsi_common_queue_present(&queue
->device
->physical_device
->wsi_device
,
245 radv_device_to_handle(queue
->device
),
247 queue
->queue_family_index
,
252 VkResult
radv_GetDeviceGroupPresentCapabilitiesKHR(
254 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
256 memset(pCapabilities
->presentMask
, 0,
257 sizeof(pCapabilities
->presentMask
));
258 pCapabilities
->presentMask
[0] = 0x1;
259 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
264 VkResult
radv_GetDeviceGroupSurfacePresentModesKHR(
266 VkSurfaceKHR surface
,
267 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
269 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;