Path: blob/21.2-virgl/src/vulkan/wsi/wsi_common.h
7237 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*/22#ifndef WSI_COMMON_H23#define WSI_COMMON_H2425#include <stdint.h>26#include <stdbool.h>2728#include "vk_alloc.h"29#include <vulkan/vulkan.h>30#include <vulkan/vk_icd.h>3132/* This is guaranteed to not collide with anything because it's in the33* VK_KHR_swapchain namespace but not actually used by the extension.34*/35#define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)100000100236#define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)100000100337#define VK_STRUCTURE_TYPE_WSI_SURFACE_SUPPORTED_COUNTERS_MESA (VkStructureType)100000100538#define VK_STRUCTURE_TYPE_WSI_MEMORY_SIGNAL_SUBMIT_INFO_MESA (VkStructureType)10000010063940/* This is always chained to VkImageCreateInfo when a wsi image is created.41* It indicates that the image can be transitioned to/from42* VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.43*/44struct wsi_image_create_info {45VkStructureType sType;46const void *pNext;47bool scanout;4849/* If set, the buffer is the prime blit destination and the image is the50* source.51*/52VkBuffer prime_blit_buffer;53};5455struct wsi_memory_allocate_info {56VkStructureType sType;57const void *pNext;58bool implicit_sync;59};6061/* To be chained into VkSurfaceCapabilities2KHR */62struct wsi_surface_supported_counters {63VkStructureType sType;64const void *pNext;6566VkSurfaceCounterFlagsEXT supported_surface_counters;6768};6970/* To be chained into VkSubmitInfo */71struct wsi_memory_signal_submit_info {72VkStructureType sType;73const void *pNext;74VkDeviceMemory memory;75};7677struct wsi_fence {78VkDevice device;79const struct wsi_device *wsi_device;80VkDisplayKHR display;81const VkAllocationCallbacks *alloc;82VkResult (*wait)(struct wsi_fence *fence, uint64_t abs_timeout);83void (*destroy)(struct wsi_fence *fence);84};8586struct wsi_interface;8788struct driOptionCache;8990#define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)9192struct wsi_device {93/* Allocator for the instance */94VkAllocationCallbacks instance_alloc;9596VkPhysicalDevice pdevice;97VkPhysicalDeviceMemoryProperties memory_props;98uint32_t queue_family_count;99100VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info;101102bool supports_modifiers;103uint32_t maxImageDimension2D;104VkPresentModeKHR override_present_mode;105bool force_bgra8_unorm_first;106107/* Whether to enable adaptive sync for a swapchain if implemented and108* available. Not all window systems might support this. */109bool enable_adaptive_sync;110111struct {112/* Override the minimum number of images on the swapchain.113* 0 = no override */114uint32_t override_minImageCount;115116/* Forces strict number of image on the swapchain using application117* provided VkSwapchainCreateInfoKH::RminImageCount.118*/119bool strict_imageCount;120121/* Ensures to create at least the number of image specified by the122* driver in VkSurfaceCapabilitiesKHR::minImageCount.123*/124bool ensure_minImageCount;125} x11;126127bool sw;128129/* Signals the semaphore such that any wait on the semaphore will wait on130* any reads or writes on the give memory object. This is used to131* implement the semaphore signal operation in vkAcquireNextImage.132*/133void (*signal_semaphore_for_memory)(VkDevice device,134VkSemaphore semaphore,135VkDeviceMemory memory);136137/* Signals the fence such that any wait on the fence will wait on any reads138* or writes on the give memory object. This is used to implement the139* semaphore signal operation in vkAcquireNextImage.140*/141void (*signal_fence_for_memory)(VkDevice device,142VkFence fence,143VkDeviceMemory memory);144145/*146* This sets the ownership for a WSI memory object:147*148* The ownership is true if and only if the application is allowed to submit149* command buffers that reference the buffer.150*151* This can be used to prune BO lists without too many adverse affects on152* implicit sync.153*154* Side note: care needs to be taken for internally delayed submissions wrt155* timeline semaphores.156*/157void (*set_memory_ownership)(VkDevice device,158VkDeviceMemory memory,159VkBool32 ownership);160161/*162* If this is set, the WSI device will call it to let the driver backend163* decide if it can present images directly on the given device fd.164*/165bool (*can_present_on_device)(VkPhysicalDevice pdevice, int fd);166167#define WSI_CB(cb) PFN_vk##cb cb168WSI_CB(AllocateMemory);169WSI_CB(AllocateCommandBuffers);170WSI_CB(BindBufferMemory);171WSI_CB(BindImageMemory);172WSI_CB(BeginCommandBuffer);173WSI_CB(CmdCopyImageToBuffer);174WSI_CB(CreateBuffer);175WSI_CB(CreateCommandPool);176WSI_CB(CreateFence);177WSI_CB(CreateImage);178WSI_CB(DestroyBuffer);179WSI_CB(DestroyCommandPool);180WSI_CB(DestroyFence);181WSI_CB(DestroyImage);182WSI_CB(EndCommandBuffer);183WSI_CB(FreeMemory);184WSI_CB(FreeCommandBuffers);185WSI_CB(GetBufferMemoryRequirements);186WSI_CB(GetImageDrmFormatModifierPropertiesEXT);187WSI_CB(GetImageMemoryRequirements);188WSI_CB(GetImageSubresourceLayout);189WSI_CB(GetMemoryFdKHR);190WSI_CB(GetPhysicalDeviceFormatProperties);191WSI_CB(GetPhysicalDeviceFormatProperties2KHR);192WSI_CB(GetPhysicalDeviceImageFormatProperties2);193WSI_CB(ResetFences);194WSI_CB(QueueSubmit);195WSI_CB(WaitForFences);196WSI_CB(MapMemory);197WSI_CB(UnmapMemory);198#undef WSI_CB199200struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX];201};202203typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);204205VkResult206wsi_device_init(struct wsi_device *wsi,207VkPhysicalDevice pdevice,208WSI_FN_GetPhysicalDeviceProcAddr proc_addr,209const VkAllocationCallbacks *alloc,210int display_fd,211const struct driOptionCache *dri_options,212bool sw_device);213214void215wsi_device_finish(struct wsi_device *wsi,216const VkAllocationCallbacks *alloc);217218#define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \219\220static inline __VkIcdType * \221__VkIcdType ## _from_handle(__VkType _handle) \222{ \223return (__VkIcdType *)(uintptr_t) _handle; \224} \225\226static inline __VkType \227__VkIcdType ## _to_handle(__VkIcdType *_obj) \228{ \229return (__VkType)(uintptr_t) _obj; \230}231232#define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \233__VkIcdType *__name = __VkIcdType ## _from_handle(__handle)234235ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)236237VkResult238wsi_common_get_surface_support(struct wsi_device *wsi_device,239uint32_t queueFamilyIndex,240VkSurfaceKHR surface,241VkBool32* pSupported);242243VkResult244wsi_common_get_surface_capabilities(struct wsi_device *wsi_device,245VkSurfaceKHR surface,246VkSurfaceCapabilitiesKHR *pSurfaceCapabilities);247248VkResult249wsi_common_get_surface_capabilities2(struct wsi_device *wsi_device,250const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,251VkSurfaceCapabilities2KHR *pSurfaceCapabilities);252253VkResult254wsi_common_get_surface_formats(struct wsi_device *wsi_device,255VkSurfaceKHR surface,256uint32_t *pSurfaceFormatCount,257VkSurfaceFormatKHR *pSurfaceFormats);258259VkResult260wsi_common_get_surface_formats2(struct wsi_device *wsi_device,261const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,262uint32_t *pSurfaceFormatCount,263VkSurfaceFormat2KHR *pSurfaceFormats);264265VkResult266wsi_common_get_surface_present_modes(struct wsi_device *wsi_device,267VkSurfaceKHR surface,268uint32_t *pPresentModeCount,269VkPresentModeKHR *pPresentModes);270271VkResult272wsi_common_get_present_rectangles(struct wsi_device *wsi,273VkSurfaceKHR surface,274uint32_t* pRectCount,275VkRect2D* pRects);276277VkResult278wsi_common_get_surface_capabilities2ext(279struct wsi_device *wsi_device,280VkSurfaceKHR surface,281VkSurfaceCapabilities2EXT *pSurfaceCapabilities);282283VkResult284wsi_common_get_images(VkSwapchainKHR _swapchain,285uint32_t *pSwapchainImageCount,286VkImage *pSwapchainImages);287288VkResult289wsi_common_acquire_next_image2(const struct wsi_device *wsi,290VkDevice device,291const VkAcquireNextImageInfoKHR *pAcquireInfo,292uint32_t *pImageIndex);293294VkResult295wsi_common_create_swapchain(struct wsi_device *wsi,296VkDevice device,297const VkSwapchainCreateInfoKHR *pCreateInfo,298const VkAllocationCallbacks *pAllocator,299VkSwapchainKHR *pSwapchain);300void301wsi_common_destroy_swapchain(VkDevice device,302VkSwapchainKHR swapchain,303const VkAllocationCallbacks *pAllocator);304305VkResult306wsi_common_queue_present(const struct wsi_device *wsi,307VkDevice device_h,308VkQueue queue_h,309int queue_family_index,310const VkPresentInfoKHR *pPresentInfo);311312uint64_t313wsi_common_get_current_time(void);314315#endif316317318