#include <stdint.h>
#include <stdbool.h>
-#include "util/vk_alloc.h"
+#include "vk_alloc.h"
#include <vulkan/vulkan.h>
#include <vulkan/vk_icd.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
+
+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;
+};
+
+struct wsi_image {
+ VkImage image;
+ VkDeviceMemory memory;
+ uint32_t size;
+ uint32_t offset;
+ uint32_t row_pitch;
+ int fd;
+};
+
struct wsi_device;
struct wsi_image_fns {
VkResult (*create_wsi_image)(VkDevice device_h,
const VkSwapchainCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
- VkImage *image_p,
- VkDeviceMemory *memory_p,
- uint32_t *size_p,
- uint32_t *offset_p,
- uint32_t *row_pitch_p,
- int *fd_p);
+ bool needs_linear_copy,
+ bool linear,
+ struct wsi_image *image_p);
void (*free_wsi_image)(VkDevice device,
const VkAllocationCallbacks *pAllocator,
- VkImage image_h,
- VkDeviceMemory memory_h);
+ struct wsi_image *image);
};
struct wsi_swapchain {
+ const struct wsi_device *wsi;
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);
uint64_t timeout, VkSemaphore semaphore,
uint32_t *image_index);
VkResult (*queue_present)(struct wsi_swapchain *swap_chain,
- uint32_t image_index);
+ uint32_t image_index,
+ const VkPresentRegionKHR *damage);
+ void (*get_image_and_linear)(struct wsi_swapchain *swapchain,
+ int imageIndex,
+ VkImage *image,
+ VkImage *linear_image);
};
struct wsi_interface {
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_capabilities2)(VkIcdSurfaceBase *surface,
+ const void *info_next,
+ VkSurfaceCapabilities2KHR* pSurfaceCapabilities);
VkResult (*get_formats)(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
uint32_t* pSurfaceFormatCount,
VkSurfaceFormatKHR* pSurfaceFormats);
+ VkResult (*get_formats2)(VkIcdSurfaceBase *surface,
+ struct wsi_device *wsi_device,
+ const void *info_next,
+ uint32_t* pSurfaceFormatCount,
+ VkSurfaceFormat2KHR* 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_interface * wsi[VK_ICD_WSI_PLATFORM_MAX];
};
+typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);
+
+void
+wsi_device_init(struct wsi_device *wsi,
+ VkPhysicalDevice pdevice,
+ WSI_FN_GetPhysicalDeviceProcAddr proc_addr);
+
+#define WSI_CB(cb) PFN_vk##cb cb
struct wsi_callbacks {
- void (*get_phys_device_format_properties)(VkPhysicalDevice physicalDevice,
- VkFormat format,
- VkFormatProperties *pFormatProperties);
+ WSI_CB(GetPhysicalDeviceFormatProperties);
};
+#undef WSI_CB
#define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
\
return (__VkType)(uintptr_t) _obj; \
}
-WSI_DEFINE_NONDISP_HANDLE_CASTS(_VkIcdSurfaceBase, VkSurfaceKHR)
WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, VkSwapchainKHR)
+#define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
+ \
+ static inline __VkIcdType * \
+ __VkIcdType ## _from_handle(__VkType _handle) \
+ { \
+ return (__VkIcdType *)(uintptr_t) _handle; \
+ } \
+ \
+ static inline __VkType \
+ __VkIcdType ## _to_handle(__VkIcdType *_obj) \
+ { \
+ return (__VkType)(uintptr_t) _obj; \
+ }
+
+#define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
+ __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
+
+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,