Path: blob/21.2-virgl/src/freedreno/vulkan/tu_wsi.c
4565 views
/*1* Copyright © 2016 Red Hat2* based on intel anv code:3* Copyright © 2015 Intel Corporation4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the "Software"),7* to deal in the Software without restriction, including without limitation8* the rights to use, copy, modify, merge, publish, distribute, sublicense,9* and/or sell copies of the Software, and to permit persons to whom the10* Software is furnished to do so, subject to the following conditions:11*12* The above copyright notice and this permission notice (including the next13* paragraph) shall be included in all copies or substantial portions of the14* Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL19* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING21* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER22* DEALINGS IN THE SOFTWARE.23*/2425#include "tu_private.h"2627#include "vk_util.h"28#include "wsi_common.h"29#include "drm-uapi/drm_fourcc.h"3031static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL32tu_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)33{34TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice);35return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName);36}3738VkResult39tu_wsi_init(struct tu_physical_device *physical_device)40{41VkResult result;4243result = wsi_device_init(&physical_device->wsi_device,44tu_physical_device_to_handle(physical_device),45tu_wsi_proc_addr,46&physical_device->instance->vk.alloc,47physical_device->master_fd, NULL,48false);49if (result != VK_SUCCESS)50return result;5152physical_device->wsi_device.supports_modifiers = true;5354return VK_SUCCESS;55}5657void58tu_wsi_finish(struct tu_physical_device *physical_device)59{60wsi_device_finish(&physical_device->wsi_device,61&physical_device->instance->vk.alloc);62}6364VKAPI_ATTR void VKAPI_CALL65tu_DestroySurfaceKHR(VkInstance _instance,66VkSurfaceKHR _surface,67const VkAllocationCallbacks *pAllocator)68{69TU_FROM_HANDLE(tu_instance, instance, _instance);70ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);7172vk_free2(&instance->vk.alloc, pAllocator, surface);73}7475VKAPI_ATTR VkResult VKAPI_CALL76tu_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,77uint32_t queueFamilyIndex,78VkSurfaceKHR surface,79VkBool32 *pSupported)80{81TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);8283return wsi_common_get_surface_support(84&device->wsi_device, queueFamilyIndex, surface, pSupported);85}8687VKAPI_ATTR VkResult VKAPI_CALL88tu_GetPhysicalDeviceSurfaceCapabilitiesKHR(89VkPhysicalDevice physicalDevice,90VkSurfaceKHR surface,91VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)92{93TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);9495return wsi_common_get_surface_capabilities(&device->wsi_device, surface,96pSurfaceCapabilities);97}9899VKAPI_ATTR VkResult VKAPI_CALL100tu_GetPhysicalDeviceSurfaceCapabilities2KHR(101VkPhysicalDevice physicalDevice,102const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,103VkSurfaceCapabilities2KHR *pSurfaceCapabilities)104{105TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);106107return wsi_common_get_surface_capabilities2(108&device->wsi_device, pSurfaceInfo, pSurfaceCapabilities);109}110111VKAPI_ATTR VkResult VKAPI_CALL112tu_GetPhysicalDeviceSurfaceCapabilities2EXT(113VkPhysicalDevice physicalDevice,114VkSurfaceKHR surface,115VkSurfaceCapabilities2EXT *pSurfaceCapabilities)116{117TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);118119return wsi_common_get_surface_capabilities2ext(120&device->wsi_device, surface, pSurfaceCapabilities);121}122123VKAPI_ATTR VkResult VKAPI_CALL124tu_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,125VkSurfaceKHR surface,126uint32_t *pSurfaceFormatCount,127VkSurfaceFormatKHR *pSurfaceFormats)128{129TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);130131return wsi_common_get_surface_formats(132&device->wsi_device, surface, pSurfaceFormatCount, pSurfaceFormats);133}134135VKAPI_ATTR VkResult VKAPI_CALL136tu_GetPhysicalDeviceSurfaceFormats2KHR(137VkPhysicalDevice physicalDevice,138const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,139uint32_t *pSurfaceFormatCount,140VkSurfaceFormat2KHR *pSurfaceFormats)141{142TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);143144return wsi_common_get_surface_formats2(&device->wsi_device, pSurfaceInfo,145pSurfaceFormatCount,146pSurfaceFormats);147}148149VKAPI_ATTR VkResult VKAPI_CALL150tu_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,151VkSurfaceKHR surface,152uint32_t *pPresentModeCount,153VkPresentModeKHR *pPresentModes)154{155TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);156157return wsi_common_get_surface_present_modes(158&device->wsi_device, surface, pPresentModeCount, pPresentModes);159}160161VKAPI_ATTR VkResult VKAPI_CALL162tu_CreateSwapchainKHR(VkDevice _device,163const VkSwapchainCreateInfoKHR *pCreateInfo,164const VkAllocationCallbacks *pAllocator,165VkSwapchainKHR *pSwapchain)166{167TU_FROM_HANDLE(tu_device, device, _device);168const VkAllocationCallbacks *alloc;169if (pAllocator)170alloc = pAllocator;171else172alloc = &device->vk.alloc;173174return wsi_common_create_swapchain(&device->physical_device->wsi_device,175tu_device_to_handle(device),176pCreateInfo, alloc, pSwapchain);177}178179VKAPI_ATTR void VKAPI_CALL180tu_DestroySwapchainKHR(VkDevice _device,181VkSwapchainKHR swapchain,182const VkAllocationCallbacks *pAllocator)183{184TU_FROM_HANDLE(tu_device, device, _device);185const VkAllocationCallbacks *alloc;186187if (pAllocator)188alloc = pAllocator;189else190alloc = &device->vk.alloc;191192wsi_common_destroy_swapchain(_device, swapchain, alloc);193}194195VKAPI_ATTR VkResult VKAPI_CALL196tu_GetSwapchainImagesKHR(VkDevice device,197VkSwapchainKHR swapchain,198uint32_t *pSwapchainImageCount,199VkImage *pSwapchainImages)200{201return wsi_common_get_images(swapchain, pSwapchainImageCount,202pSwapchainImages);203}204205VKAPI_ATTR VkResult VKAPI_CALL206tu_AcquireNextImageKHR(VkDevice device,207VkSwapchainKHR swapchain,208uint64_t timeout,209VkSemaphore semaphore,210VkFence fence,211uint32_t *pImageIndex)212{213VkAcquireNextImageInfoKHR acquire_info = {214.sType = VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR,215.swapchain = swapchain,216.timeout = timeout,217.semaphore = semaphore,218.fence = fence,219.deviceMask = 0,220};221222return tu_AcquireNextImage2KHR(device, &acquire_info, pImageIndex);223}224225VKAPI_ATTR VkResult VKAPI_CALL226tu_AcquireNextImage2KHR(VkDevice _device,227const VkAcquireNextImageInfoKHR *pAcquireInfo,228uint32_t *pImageIndex)229{230TU_FROM_HANDLE(tu_device, device, _device);231TU_FROM_HANDLE(tu_syncobj, fence, pAcquireInfo->fence);232TU_FROM_HANDLE(tu_syncobj, semaphore, pAcquireInfo->semaphore);233234struct tu_physical_device *pdevice = device->physical_device;235236VkResult result = wsi_common_acquire_next_image2(237&pdevice->wsi_device, _device, pAcquireInfo, pImageIndex);238239/* signal fence/semaphore - image is available immediately */240tu_signal_fences(device, fence, semaphore);241242return result;243}244245VKAPI_ATTR VkResult VKAPI_CALL246tu_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)247{248TU_FROM_HANDLE(tu_queue, queue, _queue);249return wsi_common_queue_present(250&queue->device->physical_device->wsi_device,251tu_device_to_handle(queue->device), _queue, queue->queue_family_index,252pPresentInfo);253}254255VKAPI_ATTR VkResult VKAPI_CALL256tu_GetDeviceGroupPresentCapabilitiesKHR(257VkDevice device, VkDeviceGroupPresentCapabilitiesKHR *pCapabilities)258{259memset(pCapabilities->presentMask, 0, sizeof(pCapabilities->presentMask));260pCapabilities->presentMask[0] = 0x1;261pCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;262263return VK_SUCCESS;264}265266VKAPI_ATTR VkResult VKAPI_CALL267tu_GetDeviceGroupSurfacePresentModesKHR(268VkDevice device,269VkSurfaceKHR surface,270VkDeviceGroupPresentModeFlagsKHR *pModes)271{272*pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;273274return VK_SUCCESS;275}276277VKAPI_ATTR VkResult VKAPI_CALL278tu_GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice,279VkSurfaceKHR surface,280uint32_t *pRectCount,281VkRect2D *pRects)282{283TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);284285return wsi_common_get_present_rectangles(&device->wsi_device, surface,286pRectCount, pRects);287}288289290