Path: blob/21.2-virgl/src/gallium/frontends/lavapipe/lvp_wsi.c
4565 views
/*1* Copyright © 2015 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "lvp_wsi.h"2425static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL26lvp_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)27{28LVP_FROM_HANDLE(lvp_physical_device, pdevice, physicalDevice);29PFN_vkVoidFunction func;3031func = vk_instance_dispatch_table_get(&pdevice->vk.instance->dispatch_table, pName);32if (func != NULL)33return func;3435func = vk_physical_device_dispatch_table_get(&pdevice->vk.dispatch_table, pName);36if (func != NULL)37return func;3839return vk_device_dispatch_table_get(&vk_device_trampolines, pName);40}4142VkResult43lvp_init_wsi(struct lvp_physical_device *physical_device)44{45return wsi_device_init(&physical_device->wsi_device,46lvp_physical_device_to_handle(physical_device),47lvp_wsi_proc_addr,48&physical_device->vk.instance->alloc,49-1, NULL, true);50}5152void53lvp_finish_wsi(struct lvp_physical_device *physical_device)54{55wsi_device_finish(&physical_device->wsi_device,56&physical_device->vk.instance->alloc);57}5859VKAPI_ATTR void VKAPI_CALL lvp_DestroySurfaceKHR(60VkInstance _instance,61VkSurfaceKHR _surface,62const VkAllocationCallbacks* pAllocator)63{64LVP_FROM_HANDLE(lvp_instance, instance, _instance);65ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);6667vk_free2(&instance->vk.alloc, pAllocator, surface);68}6970VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceSupportKHR(71VkPhysicalDevice physicalDevice,72uint32_t queueFamilyIndex,73VkSurfaceKHR surface,74VkBool32* pSupported)75{76LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);7778return wsi_common_get_surface_support(&device->wsi_device,79queueFamilyIndex,80surface,81pSupported);82}8384VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceCapabilitiesKHR(85VkPhysicalDevice physicalDevice,86VkSurfaceKHR surface,87VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)88{89LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);9091return wsi_common_get_surface_capabilities(&device->wsi_device,92surface,93pSurfaceCapabilities);94}9596VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceCapabilities2KHR(97VkPhysicalDevice physicalDevice,98const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,99VkSurfaceCapabilities2KHR* pSurfaceCapabilities)100{101LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);102103return wsi_common_get_surface_capabilities2(&device->wsi_device,104pSurfaceInfo,105pSurfaceCapabilities);106}107108VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceCapabilities2EXT(109VkPhysicalDevice physicalDevice,110VkSurfaceKHR surface,111VkSurfaceCapabilities2EXT* pSurfaceCapabilities)112{113LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);114115return wsi_common_get_surface_capabilities2ext(&device->wsi_device,116surface,117pSurfaceCapabilities);118}119120VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceFormatsKHR(121VkPhysicalDevice physicalDevice,122VkSurfaceKHR surface,123uint32_t* pSurfaceFormatCount,124VkSurfaceFormatKHR* pSurfaceFormats)125{126LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);127return wsi_common_get_surface_formats(&device->wsi_device,128surface,129pSurfaceFormatCount,130pSurfaceFormats);131}132133VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceFormats2KHR(134VkPhysicalDevice physicalDevice,135const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,136uint32_t* pSurfaceFormatCount,137VkSurfaceFormat2KHR* pSurfaceFormats)138{139LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);140141return wsi_common_get_surface_formats2(&device->wsi_device, pSurfaceInfo,142pSurfaceFormatCount, pSurfaceFormats);143}144145VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfacePresentModesKHR(146VkPhysicalDevice physicalDevice,147VkSurfaceKHR surface,148uint32_t* pPresentModeCount,149VkPresentModeKHR* pPresentModes)150{151LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);152153return wsi_common_get_surface_present_modes(&device->wsi_device,154surface,155pPresentModeCount,156pPresentModes);157}158159VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateSwapchainKHR(160VkDevice _device,161const VkSwapchainCreateInfoKHR* pCreateInfo,162const VkAllocationCallbacks* pAllocator,163VkSwapchainKHR* pSwapchain)164{165LVP_FROM_HANDLE(lvp_device, device, _device);166const VkAllocationCallbacks *alloc;167if (pAllocator)168alloc = pAllocator;169else170alloc = &device->vk.alloc;171172return wsi_common_create_swapchain(&device->physical_device->wsi_device,173lvp_device_to_handle(device),174pCreateInfo,175alloc,176pSwapchain);177}178179VKAPI_ATTR void VKAPI_CALL lvp_DestroySwapchainKHR(180VkDevice _device,181VkSwapchainKHR swapchain,182const VkAllocationCallbacks* pAllocator)183{184LVP_FROM_HANDLE(lvp_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_CALL lvp_GetSwapchainImagesKHR(196VkDevice device,197VkSwapchainKHR swapchain,198uint32_t* pSwapchainImageCount,199VkImage* pSwapchainImages)200{201return wsi_common_get_images(swapchain,202pSwapchainImageCount,203pSwapchainImages);204}205206VKAPI_ATTR VkResult VKAPI_CALL lvp_AcquireNextImageKHR(207VkDevice device,208VkSwapchainKHR swapchain,209uint64_t timeout,210VkSemaphore semaphore,211VkFence fence,212uint32_t* pImageIndex)213{214VkAcquireNextImageInfoKHR acquire_info = {215.sType = VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR,216.swapchain = swapchain,217.timeout = timeout,218.semaphore = semaphore,219.fence = fence,220.deviceMask = 0,221};222223return lvp_AcquireNextImage2KHR(device, &acquire_info, pImageIndex);224}225226VKAPI_ATTR VkResult VKAPI_CALL lvp_AcquireNextImage2KHR(227VkDevice _device,228const VkAcquireNextImageInfoKHR* pAcquireInfo,229uint32_t* pImageIndex)230{231LVP_FROM_HANDLE(lvp_device, device, _device);232struct lvp_physical_device *pdevice = device->physical_device;233234VkResult result = wsi_common_acquire_next_image2(&pdevice->wsi_device,235_device,236pAcquireInfo,237pImageIndex);238239LVP_FROM_HANDLE(lvp_fence, fence, pAcquireInfo->fence);240241if (fence && (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR)) {242fence->signaled = true;243}244return result;245}246247VKAPI_ATTR VkResult VKAPI_CALL lvp_QueuePresentKHR(248VkQueue _queue,249const VkPresentInfoKHR* pPresentInfo)250{251LVP_FROM_HANDLE(lvp_queue, queue, _queue);252return wsi_common_queue_present(&queue->device->physical_device->wsi_device,253lvp_device_to_handle(queue->device),254_queue, 0,255pPresentInfo);256}257258259VKAPI_ATTR VkResult VKAPI_CALL lvp_GetDeviceGroupPresentCapabilitiesKHR(260VkDevice device,261VkDeviceGroupPresentCapabilitiesKHR* pCapabilities)262{263memset(pCapabilities->presentMask, 0,264sizeof(pCapabilities->presentMask));265pCapabilities->presentMask[0] = 0x1;266pCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;267268return VK_SUCCESS;269}270271VKAPI_ATTR VkResult VKAPI_CALL lvp_GetDeviceGroupSurfacePresentModesKHR(272VkDevice device,273VkSurfaceKHR surface,274VkDeviceGroupPresentModeFlagsKHR* pModes)275{276*pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;277278return VK_SUCCESS;279}280281VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDevicePresentRectanglesKHR(282VkPhysicalDevice physicalDevice,283VkSurfaceKHR surface,284uint32_t* pRectCount,285VkRect2D* pRects)286{287LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);288289return wsi_common_get_present_rectangles(&device->wsi_device,290surface,291pRectCount, pRects);292}293294295