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 "libresoc_private.h"
27 //#include "libresoc_meta.h"
28 #include "wsi_common.h"
30 #include "util/macros.h"
32 static PFN_vkVoidFunction
33 libresoc_wsi_proc_addr(VkPhysicalDevice physicalDevice
, const char *pName
)
35 return libresoc_lookup_entrypoint(pName
);
39 libresoc_wsi_set_memory_ownership(VkDevice _device
,
43 //TODO: enable when required
44 //LIBRESOC_FROM_HANDLE(libresoc_device, device, _device);
45 //LIBRESOC_FROM_HANDLE(libresoc_device_memory, mem, _mem);
48 // libresoc_bo_list_add(device, mem->bo);
50 // libresoc_bo_list_remove(device, mem->bo);
54 libresoc_init_wsi(struct libresoc_physical_device
*physical_device
)
58 VkResult result
= wsi_device_init(&physical_device
->wsi_device
,
59 libresoc_physical_device_to_handle(physical_device
),
60 libresoc_wsi_proc_addr
,
61 &physical_device
->instance
->alloc
,
62 physical_device
->master_fd
,
63 &physical_device
->instance
->dri_options
,
64 true); //TODO: for now this is sw_device
65 if (result
!= VK_SUCCESS
)
68 physical_device
->wsi_device
.set_memory_ownership
= libresoc_wsi_set_memory_ownership
;
73 libresoc_finish_wsi(struct libresoc_physical_device
*physical_device
)
75 wsi_device_finish(&physical_device
->wsi_device
,
76 &physical_device
->instance
->alloc
);
79 void libresoc_DestroySurfaceKHR(
81 VkSurfaceKHR _surface
,
82 const VkAllocationCallbacks
* pAllocator
)
84 LIBRESOC_FROM_HANDLE(libresoc_instance
, instance
, _instance
);
85 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, _surface
);
87 vk_free2(&instance
->alloc
, pAllocator
, surface
);
90 VkResult
libresoc_GetPhysicalDeviceSurfaceSupportKHR(
91 VkPhysicalDevice physicalDevice
,
92 uint32_t queueFamilyIndex
,
96 LIBRESOC_FROM_HANDLE(libresoc_physical_device
, device
, physicalDevice
);
98 return wsi_common_get_surface_support(&device
->wsi_device
,
104 VkResult
libresoc_GetPhysicalDeviceSurfaceCapabilitiesKHR(
105 VkPhysicalDevice physicalDevice
,
106 VkSurfaceKHR surface
,
107 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
)
109 LIBRESOC_FROM_HANDLE(libresoc_physical_device
, device
, physicalDevice
);
111 return wsi_common_get_surface_capabilities(&device
->wsi_device
,
113 pSurfaceCapabilities
);
116 // VkResult libresoc_GetPhysicalDeviceSurfaceCapabilities2KHR(
117 // VkPhysicalDevice physicalDevice,
118 // const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
119 // VkSurfaceCapabilities2KHR* pSurfaceCapabilities)
121 // LIBRESOC_FROM_HANDLE(libresoc_physical_device, device, physicalDevice);
123 // return wsi_common_get_surface_capabilities2(&device->wsi_device,
125 // pSurfaceCapabilities);
128 // VkResult libresoc_GetPhysicalDeviceSurfaceCapabilities2EXT(
129 // VkPhysicalDevice physicalDevice,
130 // VkSurfaceKHR surface,
131 // VkSurfaceCapabilities2EXT* pSurfaceCapabilities)
133 // LIBRESOC_FROM_HANDLE(libresoc_physical_device, device, physicalDevice);
135 // return wsi_common_get_surface_capabilities2ext(&device->wsi_device,
137 // pSurfaceCapabilities);
140 VkResult
libresoc_GetPhysicalDeviceSurfaceFormatsKHR(
141 VkPhysicalDevice physicalDevice
,
142 VkSurfaceKHR surface
,
143 uint32_t* pSurfaceFormatCount
,
144 VkSurfaceFormatKHR
* pSurfaceFormats
)
146 LIBRESOC_FROM_HANDLE(libresoc_physical_device
, device
, physicalDevice
);
148 return wsi_common_get_surface_formats(&device
->wsi_device
,
154 // VkResult libresoc_GetPhysicalDeviceSurfaceFormats2KHR(
155 // VkPhysicalDevice physicalDevice,
156 // const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
157 // uint32_t* pSurfaceFormatCount,
158 // VkSurfaceFormat2KHR* pSurfaceFormats)
160 // LIBRESOC_FROM_HANDLE(libresoc_physical_device, device, physicalDevice);
162 // return wsi_common_get_surface_formats2(&device->wsi_device,
164 // pSurfaceFormatCount,
168 VkResult
libresoc_GetPhysicalDeviceSurfacePresentModesKHR(
169 VkPhysicalDevice physicalDevice
,
170 VkSurfaceKHR surface
,
171 uint32_t* pPresentModeCount
,
172 VkPresentModeKHR
* pPresentModes
)
174 LIBRESOC_FROM_HANDLE(libresoc_physical_device
, device
, physicalDevice
);
176 return wsi_common_get_surface_present_modes(&device
->wsi_device
,
182 VkResult
libresoc_CreateSwapchainKHR(
184 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
185 const VkAllocationCallbacks
* pAllocator
,
186 VkSwapchainKHR
* pSwapchain
)
188 LIBRESOC_FROM_HANDLE(libresoc_device
, device
, _device
);
189 const VkAllocationCallbacks
*alloc
;
193 alloc
= &device
->vk
.alloc
;
195 return wsi_common_create_swapchain(&device
->physical_device
->wsi_device
,
196 libresoc_device_to_handle(device
),
202 void libresoc_DestroySwapchainKHR(
204 VkSwapchainKHR swapchain
,
205 const VkAllocationCallbacks
* pAllocator
)
207 LIBRESOC_FROM_HANDLE(libresoc_device
, device
, _device
);
208 const VkAllocationCallbacks
*alloc
;
213 alloc
= &device
->vk
.alloc
;
215 wsi_common_destroy_swapchain(_device
, swapchain
, alloc
);
218 VkResult
libresoc_GetSwapchainImagesKHR(
220 VkSwapchainKHR swapchain
,
221 uint32_t* pSwapchainImageCount
,
222 VkImage
* pSwapchainImages
)
224 return wsi_common_get_images(swapchain
,
225 pSwapchainImageCount
,
229 VkResult
libresoc_AcquireNextImageKHR(
231 VkSwapchainKHR swapchain
,
233 VkSemaphore semaphore
,
235 uint32_t* pImageIndex
)
237 VkAcquireNextImageInfoKHR acquire_info
= {
238 .sType
= VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR
,
239 .swapchain
= swapchain
,
241 .semaphore
= semaphore
,
246 return libresoc_AcquireNextImage2KHR(device
, &acquire_info
, pImageIndex
);
249 VkResult
libresoc_AcquireNextImage2KHR(
251 const VkAcquireNextImageInfoKHR
* pAcquireInfo
,
252 uint32_t* pImageIndex
)
254 LIBRESOC_FROM_HANDLE(libresoc_device
, device
, _device
);
255 struct libresoc_physical_device
*pdevice
= device
->physical_device
;
256 //LIBRESOC_FROM_HANDLE(libresoc_fence, fence, pAcquireInfo->fence);
257 //LIBRESOC_FROM_HANDLE(libresoc_semaphore, semaphore, pAcquireInfo->semaphore);
259 VkResult result
= wsi_common_acquire_next_image2(&pdevice
->wsi_device
,
263 //TODO: enable if required
264 // if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) {
266 // struct libresoc_fence_part *part =
267 // fence->temporary.kind != LIBRESOC_FENCE_NONE ?
268 // &fence->temporary : &fence->permanent;
270 // switch (part->kind) {
271 // case LIBRESOC_FENCE_NONE:
273 // case LIBRESOC_FENCE_WINSYS:
274 // device->ws->signal_fence(part->fence);
276 // case LIBRESOC_FENCE_SYNCOBJ:
277 // device->ws->signal_syncobj(device->ws, part->syncobj, 0);
280 // unreachable("Invalid WSI fence type");
284 // struct libresoc_semaphore_part *part =
285 // semaphore->temporary.kind != LIBRESOC_SEMAPHORE_NONE ?
286 // &semaphore->temporary : &semaphore->permanent;
288 // switch (part->kind) {
289 // case LIBRESOC_SEMAPHORE_NONE:
290 // case LIBRESOC_SEMAPHORE_WINSYS:
291 // /* Do not need to do anything. */
293 // case LIBRESOC_SEMAPHORE_TIMELINE:
294 // case LIBRESOC_SEMAPHORE_TIMELINE_SYNCOBJ:
295 // unreachable("WSI only allows binary semaphores.");
296 // case LIBRESOC_SEMAPHORE_SYNCOBJ:
297 // device->ws->signal_syncobj(device->ws, part->syncobj, 0);
305 VkResult
libresoc_QueuePresentKHR(
307 const VkPresentInfoKHR
* pPresentInfo
)
309 LIBRESOC_FROM_HANDLE(libresoc_queue
, queue
, _queue
);
310 return wsi_common_queue_present(&queue
->device
->physical_device
->wsi_device
,
311 libresoc_device_to_handle(queue
->device
),
313 queue
->queue_family_index
,
318 VkResult
libresoc_GetDeviceGroupPresentCapabilitiesKHR(
320 VkDeviceGroupPresentCapabilitiesKHR
* pCapabilities
)
322 memset(pCapabilities
->presentMask
, 0,
323 sizeof(pCapabilities
->presentMask
));
324 pCapabilities
->presentMask
[0] = 0x1;
325 pCapabilities
->modes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
330 VkResult
libresoc_GetDeviceGroupSurfacePresentModesKHR(
332 VkSurfaceKHR surface
,
333 VkDeviceGroupPresentModeFlagsKHR
* pModes
)
335 *pModes
= VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR
;
340 VkResult
libresoc_GetPhysicalDevicePresentRectanglesKHR(
341 VkPhysicalDevice physicalDevice
,
342 VkSurfaceKHR surface
,
343 uint32_t* pRectCount
,
346 LIBRESOC_FROM_HANDLE(libresoc_physical_device
, device
, physicalDevice
);
348 return wsi_common_get_present_rectangles(&device
->wsi_device
,