vulkan/wsi: Add callback to set ownership of buffer.
[mesa.git] / src / vulkan / wsi / wsi_common.h
index 6cf729ba025f4072b3584b44ea50e390291aaaf8..99ccdf84cde30e09989dc5de89da7aa810d9a13d 100644 (file)
  */
 #define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)1000001002
 #define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)1000001003
-#define VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA (VkStructureType)1000001004
+#define VK_STRUCTURE_TYPE_WSI_SURFACE_SUPPORTED_COUNTERS_MESA (VkStructureType)1000001005
+#define VK_STRUCTURE_TYPE_WSI_MEMORY_SIGNAL_SUBMIT_INFO_MESA (VkStructureType)1000001006
 
 struct wsi_image_create_info {
     VkStructureType sType;
     const void *pNext;
     bool scanout;
-
-    uint32_t modifier_count;
-    const uint64_t *modifiers;
 };
 
 struct wsi_memory_allocate_info {
@@ -52,31 +50,98 @@ struct wsi_memory_allocate_info {
     bool implicit_sync;
 };
 
-struct wsi_format_modifier_properties {
-   uint64_t modifier;
-   uint32_t modifier_plane_count;
-};
-
-/* Chain in for vkGetPhysicalDeviceFormatProperties2KHR */
-struct wsi_format_modifier_properties_list {
+/* To be chained into VkSurfaceCapabilities2KHR */
+struct wsi_surface_supported_counters {
    VkStructureType sType;
    const void *pNext;
 
-   uint32_t modifier_count;
-   struct wsi_format_modifier_properties *modifier_properties;
+   VkSurfaceCounterFlagsEXT supported_surface_counters;
+
+};
+
+/* To be chained into VkSubmitInfo */
+struct wsi_memory_signal_submit_info {
+    VkStructureType sType;
+    const void *pNext;
+    VkDeviceMemory memory;
+};
+
+struct wsi_fence {
+   VkDevice                     device;
+   const struct wsi_device      *wsi_device;
+   VkDisplayKHR                 display;
+   const VkAllocationCallbacks  *alloc;
+   VkResult                     (*wait)(struct wsi_fence *fence, uint64_t abs_timeout);
+   void                         (*destroy)(struct wsi_fence *fence);
 };
 
 struct wsi_interface;
 
-#define VK_ICD_WSI_PLATFORM_MAX 5
+struct driOptionCache;
+
+#define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
 
 struct wsi_device {
+   /* Allocator for the instance */
+   VkAllocationCallbacks instance_alloc;
+
    VkPhysicalDevice pdevice;
    VkPhysicalDeviceMemoryProperties memory_props;
    uint32_t queue_family_count;
 
+   VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info;
+
    bool supports_modifiers;
-   uint64_t (*image_get_modifier)(VkImage image);
+   uint32_t maxImageDimension2D;
+   VkPresentModeKHR override_present_mode;
+   bool force_bgra8_unorm_first;
+
+   /* Whether to enable adaptive sync for a swapchain if implemented and
+    * available. Not all window systems might support this. */
+   bool enable_adaptive_sync;
+
+   struct {
+      /* Override the minimum number of images on the swapchain.
+       * 0 = no override */
+      uint32_t override_minImageCount;
+
+      /* Forces strict number of image on the swapchain using application
+       * provided VkSwapchainCreateInfoKH::RminImageCount.
+       */
+      bool strict_imageCount;
+   } x11;
+
+   /* Signals the semaphore such that any wait on the semaphore will wait on
+    * any reads or writes on the give memory object.  This is used to
+    * implement the semaphore signal operation in vkAcquireNextImage.
+    */
+   void (*signal_semaphore_for_memory)(VkDevice device,
+                                       VkSemaphore semaphore,
+                                       VkDeviceMemory memory);
+
+   /* Signals the fence such that any wait on the fence will wait on any reads
+    * or writes on the give memory object.  This is used to implement the
+    * semaphore signal operation in vkAcquireNextImage.
+    */
+   void (*signal_fence_for_memory)(VkDevice device,
+                                   VkFence fence,
+                                   VkDeviceMemory memory);
+
+   /*
+    * This sets the ownership for a WSI memory object:
+    *
+    * The ownership is true if and only if the application is allowed to submit
+    * command buffers that reference the buffer.
+    *
+    * This can be used to prune BO lists without too many adverse affects on
+    * implicit sync.
+    *
+    * Side note: care needs to be taken for internally delayed submissions wrt
+    * timeline semaphores.
+    */
+   void (*set_memory_ownership)(VkDevice device,
+                                VkDeviceMemory memory,
+                                VkBool32 ownership);
 
 #define WSI_CB(cb) PFN_vk##cb cb
    WSI_CB(AllocateMemory);
@@ -97,11 +162,13 @@ struct wsi_device {
    WSI_CB(FreeMemory);
    WSI_CB(FreeCommandBuffers);
    WSI_CB(GetBufferMemoryRequirements);
+   WSI_CB(GetImageDrmFormatModifierPropertiesEXT);
    WSI_CB(GetImageMemoryRequirements);
    WSI_CB(GetImageSubresourceLayout);
    WSI_CB(GetMemoryFdKHR);
    WSI_CB(GetPhysicalDeviceFormatProperties);
    WSI_CB(GetPhysicalDeviceFormatProperties2KHR);
+   WSI_CB(GetPhysicalDeviceImageFormatProperties2);
    WSI_CB(ResetFences);
    WSI_CB(QueueSubmit);
    WSI_CB(WaitForFences);
@@ -116,7 +183,9 @@ VkResult
 wsi_device_init(struct wsi_device *wsi,
                 VkPhysicalDevice pdevice,
                 WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
-                const VkAllocationCallbacks *alloc);
+                const VkAllocationCallbacks *alloc,
+                int display_fd,
+                const struct driOptionCache *dri_options);
 
 void
 wsi_device_finish(struct wsi_device *wsi,
@@ -143,10 +212,8 @@ ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
 
 VkResult
 wsi_common_get_surface_support(struct wsi_device *wsi_device,
-                               int local_fd,
                                uint32_t queueFamilyIndex,
                                VkSurfaceKHR surface,
-                               const VkAllocationCallbacks *alloc,
                                VkBool32* pSupported);
 
 VkResult
@@ -177,23 +244,32 @@ wsi_common_get_surface_present_modes(struct wsi_device *wsi_device,
                                      uint32_t *pPresentModeCount,
                                      VkPresentModeKHR *pPresentModes);
 
+VkResult
+wsi_common_get_present_rectangles(struct wsi_device *wsi,
+                                  VkSurfaceKHR surface,
+                                  uint32_t* pRectCount,
+                                  VkRect2D* pRects);
+
+VkResult
+wsi_common_get_surface_capabilities2ext(
+   struct wsi_device *wsi_device,
+   VkSurfaceKHR surface,
+   VkSurfaceCapabilities2EXT *pSurfaceCapabilities);
+
 VkResult
 wsi_common_get_images(VkSwapchainKHR _swapchain,
                       uint32_t *pSwapchainImageCount,
                       VkImage *pSwapchainImages);
 
 VkResult
-wsi_common_acquire_next_image(const struct wsi_device *wsi,
-                              VkDevice device,
-                              VkSwapchainKHR swapchain,
-                              uint64_t timeout,
-                              VkSemaphore semaphore,
-                              uint32_t *pImageIndex);
+wsi_common_acquire_next_image2(const struct wsi_device *wsi,
+                               VkDevice device,
+                               const VkAcquireNextImageInfoKHR *pAcquireInfo,
+                               uint32_t *pImageIndex);
 
 VkResult
 wsi_common_create_swapchain(struct wsi_device *wsi,
                             VkDevice device,
-                            int fd,
                             const VkSwapchainCreateInfoKHR *pCreateInfo,
                             const VkAllocationCallbacks *pAllocator,
                             VkSwapchainKHR *pSwapchain);
@@ -209,4 +285,7 @@ wsi_common_queue_present(const struct wsi_device *wsi,
                          int queue_family_index,
                          const VkPresentInfoKHR *pPresentInfo);
 
+uint64_t
+wsi_common_get_current_time(void);
+
 #endif