Path: blob/21.2-virgl/src/panfrost/vulkan/panvk_wsi.c
4560 views
/*1* Copyright © 2021 Collabora Ltd.2*3* Derived from tu_wsi.c:4* Copyright © 2016 Red Hat5* Copyright © 2015 Intel Corporation6*7* Permission is hereby granted, free of charge, to any person obtaining a8* copy of this software and associated documentation files (the "Software"),9* to deal in the Software without restriction, including without limitation10* the rights to use, copy, modify, merge, publish, distribute, sublicense,11* and/or sell copies of the Software, and to permit persons to whom the12* Software is furnished to do so, subject to the following conditions:13*14* The above copyright notice and this permission notice (including the next15* paragraph) shall be included in all copies or substantial portions of the16* Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR19* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,20* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL21* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER22* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING23* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER24* DEALINGS IN THE SOFTWARE.25*/2627#include "panvk_private.h"2829#include "vk_util.h"30#include "wsi_common.h"3132static VKAPI_PTR PFN_vkVoidFunction33panvk_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)34{35VK_FROM_HANDLE(panvk_physical_device, pdevice, physicalDevice);36return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName);37}3839VkResult40panvk_wsi_init(struct panvk_physical_device *physical_device)41{42VkResult result;4344result = wsi_device_init(&physical_device->wsi_device,45panvk_physical_device_to_handle(physical_device),46panvk_wsi_proc_addr,47&physical_device->instance->vk.alloc,48physical_device->master_fd, NULL,49false);50if (result != VK_SUCCESS)51return result;5253physical_device->wsi_device.supports_modifiers = false;5455return VK_SUCCESS;56}5758void59panvk_wsi_finish(struct panvk_physical_device *physical_device)60{61wsi_device_finish(&physical_device->wsi_device,62&physical_device->instance->vk.alloc);63}6465void66panvk_DestroySurfaceKHR(VkInstance _instance,67VkSurfaceKHR _surface,68const VkAllocationCallbacks *pAllocator)69{70VK_FROM_HANDLE(panvk_instance, instance, _instance);71ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);7273vk_free2(&instance->vk.alloc, pAllocator, surface);74}7576VkResult77panvk_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,78uint32_t queueFamilyIndex,79VkSurfaceKHR surface,80VkBool32 *pSupported)81{82VK_FROM_HANDLE(panvk_physical_device, device, physicalDevice);8384return wsi_common_get_surface_support(85&device->wsi_device, queueFamilyIndex, surface, pSupported);86}8788VkResult89panvk_GetPhysicalDeviceSurfaceCapabilitiesKHR(90VkPhysicalDevice physicalDevice,91VkSurfaceKHR surface,92VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)93{94VK_FROM_HANDLE(panvk_physical_device, device, physicalDevice);9596return wsi_common_get_surface_capabilities(&device->wsi_device, surface,97pSurfaceCapabilities);98}99100VkResult101panvk_GetPhysicalDeviceSurfaceCapabilities2KHR(102VkPhysicalDevice physicalDevice,103const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,104VkSurfaceCapabilities2KHR *pSurfaceCapabilities)105{106VK_FROM_HANDLE(panvk_physical_device, device, physicalDevice);107108return wsi_common_get_surface_capabilities2(109&device->wsi_device, pSurfaceInfo, pSurfaceCapabilities);110}111112VkResult113panvk_GetPhysicalDeviceSurfaceCapabilities2EXT(114VkPhysicalDevice physicalDevice,115VkSurfaceKHR surface,116VkSurfaceCapabilities2EXT *pSurfaceCapabilities)117{118VK_FROM_HANDLE(panvk_physical_device, device, physicalDevice);119120return wsi_common_get_surface_capabilities2ext(121&device->wsi_device, surface, pSurfaceCapabilities);122}123124VkResult125panvk_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,126VkSurfaceKHR surface,127uint32_t *pSurfaceFormatCount,128VkSurfaceFormatKHR *pSurfaceFormats)129{130VK_FROM_HANDLE(panvk_physical_device, device, physicalDevice);131132return wsi_common_get_surface_formats(133&device->wsi_device, surface, pSurfaceFormatCount, pSurfaceFormats);134}135136VkResult137panvk_GetPhysicalDeviceSurfaceFormats2KHR(138VkPhysicalDevice physicalDevice,139const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,140uint32_t *pSurfaceFormatCount,141VkSurfaceFormat2KHR *pSurfaceFormats)142{143VK_FROM_HANDLE(panvk_physical_device, device, physicalDevice);144145return wsi_common_get_surface_formats2(&device->wsi_device, pSurfaceInfo,146pSurfaceFormatCount,147pSurfaceFormats);148}149150VkResult151panvk_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,152VkSurfaceKHR surface,153uint32_t *pPresentModeCount,154VkPresentModeKHR *pPresentModes)155{156VK_FROM_HANDLE(panvk_physical_device, device, physicalDevice);157158return wsi_common_get_surface_present_modes(159&device->wsi_device, surface, pPresentModeCount, pPresentModes);160}161162VkResult163panvk_CreateSwapchainKHR(VkDevice _device,164const VkSwapchainCreateInfoKHR *pCreateInfo,165const VkAllocationCallbacks *pAllocator,166VkSwapchainKHR *pSwapchain)167{168VK_FROM_HANDLE(panvk_device, device, _device);169170const VkAllocationCallbacks *alloc;171if (pAllocator)172alloc = pAllocator;173else174alloc = &device->vk.alloc;175176return wsi_common_create_swapchain(&device->physical_device->wsi_device,177panvk_device_to_handle(device),178pCreateInfo, alloc, pSwapchain);179}180181void182panvk_DestroySwapchainKHR(VkDevice _device,183VkSwapchainKHR swapchain,184const VkAllocationCallbacks *pAllocator)185{186VK_FROM_HANDLE(panvk_device, device, _device);187const VkAllocationCallbacks *alloc;188189if (pAllocator)190alloc = pAllocator;191else192alloc = &device->vk.alloc;193194wsi_common_destroy_swapchain(_device, swapchain, alloc);195}196197VkResult198panvk_GetSwapchainImagesKHR(VkDevice device,199VkSwapchainKHR swapchain,200uint32_t *pSwapchainImageCount,201VkImage *pSwapchainImages)202{203return wsi_common_get_images(swapchain, pSwapchainImageCount,204pSwapchainImages);205}206207VkResult208panvk_AcquireNextImageKHR(VkDevice device,209VkSwapchainKHR swapchain,210uint64_t timeout,211VkSemaphore semaphore,212VkFence fence,213uint32_t *pImageIndex)214{215VkAcquireNextImageInfoKHR acquire_info = {216.sType = VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR,217.swapchain = swapchain,218.timeout = timeout,219.semaphore = semaphore,220.fence = fence,221.deviceMask = 0,222};223224return panvk_AcquireNextImage2KHR(device, &acquire_info, pImageIndex);225}226227VkResult228panvk_AcquireNextImage2KHR(VkDevice _device,229const VkAcquireNextImageInfoKHR *pAcquireInfo,230uint32_t *pImageIndex)231{232VK_FROM_HANDLE(panvk_device, device, _device);233VK_FROM_HANDLE(panvk_fence, fence, pAcquireInfo->fence);234VK_FROM_HANDLE(panvk_semaphore, sem, pAcquireInfo->semaphore);235struct panvk_physical_device *pdevice = device->physical_device;236237VkResult result =238wsi_common_acquire_next_image2(&pdevice->wsi_device, _device,239pAcquireInfo, pImageIndex);240241/* signal fence/semaphore - image is available immediately */242if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) {243panvk_signal_syncobjs(device, fence ? &fence->syncobj : NULL,244sem ? &sem->syncobj : NULL);245}246247return result;248}249250VkResult251panvk_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)252{253VK_FROM_HANDLE(panvk_queue, queue, _queue);254return wsi_common_queue_present(255&queue->device->physical_device->wsi_device,256panvk_device_to_handle(queue->device), _queue, queue->queue_family_index,257pPresentInfo);258}259260VkResult261panvk_GetDeviceGroupPresentCapabilitiesKHR(262VkDevice device, VkDeviceGroupPresentCapabilitiesKHR *pCapabilities)263{264memset(pCapabilities->presentMask, 0, sizeof(pCapabilities->presentMask));265pCapabilities->presentMask[0] = 0x1;266pCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;267268return VK_SUCCESS;269}270271VkResult272panvk_GetDeviceGroupSurfacePresentModesKHR(273VkDevice device,274VkSurfaceKHR surface,275VkDeviceGroupPresentModeFlagsKHR *pModes)276{277*pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;278279return VK_SUCCESS;280}281282VkResult283panvk_GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice,284VkSurfaceKHR surface,285uint32_t *pRectCount,286VkRect2D *pRects)287{288VK_FROM_HANDLE(panvk_physical_device, device, physicalDevice);289290return wsi_common_get_present_rectangles(&device->wsi_device, surface,291pRectCount, pRects);292}293294295