vulkan/wsi: remove unused image_get_modifier
[mesa.git] / src / vulkan / wsi / wsi_common.h
index 8227c1e4e914015a3b95105f780b4702d409562c..92121be8bda1fa55c1d7edc1a63c76662f56c91f 100644 (file)
 #include <stdint.h>
 #include <stdbool.h>
 
-#include "util/vk_alloc.h"
+#include "vk_alloc.h"
 #include <vulkan/vulkan.h>
 #include <vulkan/vk_icd.h>
 
-struct wsi_device;
-struct wsi_image_fns {
-   VkResult (*create_wsi_image)(VkDevice device_h,
-                                const VkSwapchainCreateInfoKHR *pCreateInfo,
-                                const VkAllocationCallbacks *pAllocator,
-                                bool needs_linear_copy,
-                                bool linear,
-                                VkImage *image_p,
-                                VkDeviceMemory *memory_p,
-                                uint32_t *size_p,
-                                uint32_t *offset_p,
-                                uint32_t *row_pitch_p,
-                                int *fd_p);
-   void (*free_wsi_image)(VkDevice device,
-                          const VkAllocationCallbacks *pAllocator,
-                          VkImage image_h,
-                          VkDeviceMemory memory_h);
+/* This is guaranteed to not collide with anything because it's in the
+ * VK_KHR_swapchain namespace but not actually used by the extension.
+ */
+#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_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;
+};
+
+struct wsi_memory_allocate_info {
+    VkStructureType sType;
+    const void *pNext;
+    bool implicit_sync;
+};
+
+/* To be chained into VkSurfaceCapabilities2KHR */
+struct wsi_surface_supported_counters {
+   VkStructureType sType;
+   const void *pNext;
+
+   VkSurfaceCounterFlagsEXT supported_surface_counters;
+
 };
 
-struct wsi_swapchain {
-
-   VkDevice device;
-   VkAllocationCallbacks alloc;
-   const struct wsi_image_fns *image_fns;
-   VkFence fences[3];
-   VkCommandBuffer *cmd_buffers;
-   VkCommandPool cmd_pools[3];
-   VkPresentModeKHR present_mode;
-   uint32_t image_count;
-   bool needs_linear_copy;
-
-   VkResult (*destroy)(struct wsi_swapchain *swapchain,
-                       const VkAllocationCallbacks *pAllocator);
-   VkResult (*get_images)(struct wsi_swapchain *swapchain,
-                          uint32_t *pCount, VkImage *pSwapchainImages);
-   VkResult (*acquire_next_image)(struct wsi_swapchain *swap_chain,
-                                  uint64_t timeout, VkSemaphore semaphore,
-                                  uint32_t *image_index);
-   VkResult (*queue_present)(struct wsi_swapchain *swap_chain,
-                             uint32_t image_index);
-   void (*get_image_and_linear)(struct wsi_swapchain *swapchain,
-                                int imageIndex,
-                                VkImage *image,
-                                VkImage *linear_image);
+/* To be chained into VkSubmitInfo */
+struct wsi_memory_signal_submit_info {
+    VkStructureType sType;
+    const void *pNext;
+    VkDeviceMemory memory;
 };
 
-struct wsi_interface {
-   VkResult (*get_support)(VkIcdSurfaceBase *surface,
-                           struct wsi_device *wsi_device,
-                           const VkAllocationCallbacks *alloc,
-                           uint32_t queueFamilyIndex,
-                           int local_fd,
-                           bool can_handle_different_gpu,
-                           VkBool32* pSupported);
-   VkResult (*get_capabilities)(VkIcdSurfaceBase *surface,
-                                VkSurfaceCapabilitiesKHR* pSurfaceCapabilities);
-   VkResult (*get_formats)(VkIcdSurfaceBase *surface,
-                           struct wsi_device *wsi_device,
-                           uint32_t* pSurfaceFormatCount,
-                           VkSurfaceFormatKHR* pSurfaceFormats);
-   VkResult (*get_present_modes)(VkIcdSurfaceBase *surface,
-                                 uint32_t* pPresentModeCount,
-                                 VkPresentModeKHR* pPresentModes);
-   VkResult (*create_swapchain)(VkIcdSurfaceBase *surface,
-                                VkDevice device,
-                                struct wsi_device *wsi_device,
-                                int local_fd,
-                                const VkSwapchainCreateInfoKHR* pCreateInfo,
-                                const VkAllocationCallbacks* pAllocator,
-                                const struct wsi_image_fns *image_fns,
-                                struct wsi_swapchain **swapchain);
+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);
 };
 
-#define VK_ICD_WSI_PLATFORM_MAX 5
+struct wsi_interface;
+
+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;
+   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);
+
+#define WSI_CB(cb) PFN_vk##cb cb
+   WSI_CB(AllocateMemory);
+   WSI_CB(AllocateCommandBuffers);
+   WSI_CB(BindBufferMemory);
+   WSI_CB(BindImageMemory);
+   WSI_CB(BeginCommandBuffer);
+   WSI_CB(CmdCopyImageToBuffer);
+   WSI_CB(CreateBuffer);
+   WSI_CB(CreateCommandPool);
+   WSI_CB(CreateFence);
+   WSI_CB(CreateImage);
+   WSI_CB(DestroyBuffer);
+   WSI_CB(DestroyCommandPool);
+   WSI_CB(DestroyFence);
+   WSI_CB(DestroyImage);
+   WSI_CB(EndCommandBuffer);
+   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);
+#undef WSI_CB
+
     struct wsi_interface *                  wsi[VK_ICD_WSI_PLATFORM_MAX];
 };
 
-struct wsi_callbacks {
-   void (*get_phys_device_format_properties)(VkPhysicalDevice physicalDevice,
-                                             VkFormat format,
-                                             VkFormatProperties *pFormatProperties);
-};
+typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);
 
-#define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType)              \
-                                                                           \
-   static inline struct __wsi_type *                                       \
-   __wsi_type ## _from_handle(__VkType _handle)                            \
-   {                                                                       \
-      return (struct __wsi_type *)(uintptr_t) _handle;                     \
-   }                                                                       \
-                                                                           \
-   static inline __VkType                                                  \
-   __wsi_type ## _to_handle(struct __wsi_type *_obj)                       \
-   {                                                                       \
-      return (__VkType)(uintptr_t) _obj;                                   \
-   }
+VkResult
+wsi_device_init(struct wsi_device *wsi,
+                VkPhysicalDevice pdevice,
+                WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
+                const VkAllocationCallbacks *alloc,
+                int display_fd,
+                const struct driOptionCache *dri_options);
 
-WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, VkSwapchainKHR)
+void
+wsi_device_finish(struct wsi_device *wsi,
+                  const VkAllocationCallbacks *alloc);
 
 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType)             \
                                                                            \
@@ -150,16 +194,82 @@ WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, VkSwapchainKHR)
 
 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
 
-VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device,
-                          const VkAllocationCallbacks *alloc);
-void wsi_x11_finish_wsi(struct wsi_device *wsi_device,
-                        const VkAllocationCallbacks *alloc);
-VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device,
-                         const VkAllocationCallbacks *alloc,
-                         VkPhysicalDevice physical_device,
-                         const struct wsi_callbacks *cbs);
-void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
-                       const VkAllocationCallbacks *alloc);
+VkResult
+wsi_common_get_surface_support(struct wsi_device *wsi_device,
+                               uint32_t queueFamilyIndex,
+                               VkSurfaceKHR surface,
+                               VkBool32* pSupported);
+
+VkResult
+wsi_common_get_surface_capabilities(struct wsi_device *wsi_device,
+                                    VkSurfaceKHR surface,
+                                    VkSurfaceCapabilitiesKHR *pSurfaceCapabilities);
+
+VkResult
+wsi_common_get_surface_capabilities2(struct wsi_device *wsi_device,
+                                     const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
+                                     VkSurfaceCapabilities2KHR *pSurfaceCapabilities);
+
+VkResult
+wsi_common_get_surface_formats(struct wsi_device *wsi_device,
+                               VkSurfaceKHR surface,
+                               uint32_t *pSurfaceFormatCount,
+                               VkSurfaceFormatKHR *pSurfaceFormats);
+
+VkResult
+wsi_common_get_surface_formats2(struct wsi_device *wsi_device,
+                                const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
+                                uint32_t *pSurfaceFormatCount,
+                                VkSurfaceFormat2KHR *pSurfaceFormats);
+
+VkResult
+wsi_common_get_surface_present_modes(struct wsi_device *wsi_device,
+                                     VkSurfaceKHR surface,
+                                     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_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,
+                            const VkSwapchainCreateInfoKHR *pCreateInfo,
+                            const VkAllocationCallbacks *pAllocator,
+                            VkSwapchainKHR *pSwapchain);
+void
+wsi_common_destroy_swapchain(VkDevice device,
+                             VkSwapchainKHR swapchain,
+                             const VkAllocationCallbacks *pAllocator);
+
+VkResult
+wsi_common_queue_present(const struct wsi_device *wsi,
+                         VkDevice device_h,
+                         VkQueue queue_h,
+                         int queue_family_index,
+                         const VkPresentInfoKHR *pPresentInfo);
 
+uint64_t
+wsi_common_get_current_time(void);
 
 #endif