1b8e80941Smrg/* 2b8e80941Smrg * Copyright © 2015 Intel Corporation 3b8e80941Smrg * 4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 6b8e80941Smrg * to deal in the Software without restriction, including without limitation 7b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the 9b8e80941Smrg * Software is furnished to do so, subject to the following conditions: 10b8e80941Smrg * 11b8e80941Smrg * The above copyright notice and this permission notice (including the next 12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 13b8e80941Smrg * Software. 14b8e80941Smrg * 15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21b8e80941Smrg * IN THE SOFTWARE. 22b8e80941Smrg */ 23b8e80941Smrg#ifndef WSI_COMMON_H 24b8e80941Smrg#define WSI_COMMON_H 25b8e80941Smrg 26b8e80941Smrg#include <stdint.h> 27b8e80941Smrg#include <stdbool.h> 28b8e80941Smrg 29b8e80941Smrg#include "vk_alloc.h" 30b8e80941Smrg#include <vulkan/vulkan.h> 31b8e80941Smrg#include <vulkan/vk_icd.h> 32b8e80941Smrg 33b8e80941Smrg/* This is guaranteed to not collide with anything because it's in the 34b8e80941Smrg * VK_KHR_swapchain namespace but not actually used by the extension. 35b8e80941Smrg */ 36b8e80941Smrg#define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)1000001002 37b8e80941Smrg#define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)1000001003 38b8e80941Smrg#define VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA (VkStructureType)1000001004 39b8e80941Smrg#define VK_STRUCTURE_TYPE_WSI_SURFACE_SUPPORTED_COUNTERS_MESA (VkStructureType)1000001005 40b8e80941Smrg 41b8e80941Smrgstruct wsi_image_create_info { 42b8e80941Smrg VkStructureType sType; 43b8e80941Smrg const void *pNext; 44b8e80941Smrg bool scanout; 45b8e80941Smrg 46b8e80941Smrg uint32_t modifier_count; 47b8e80941Smrg const uint64_t *modifiers; 48b8e80941Smrg}; 49b8e80941Smrg 50b8e80941Smrgstruct wsi_memory_allocate_info { 51b8e80941Smrg VkStructureType sType; 52b8e80941Smrg const void *pNext; 53b8e80941Smrg bool implicit_sync; 54b8e80941Smrg}; 55b8e80941Smrg 56b8e80941Smrgstruct wsi_format_modifier_properties { 57b8e80941Smrg uint64_t modifier; 58b8e80941Smrg uint32_t modifier_plane_count; 59b8e80941Smrg}; 60b8e80941Smrg 61b8e80941Smrg/* Chain in for vkGetPhysicalDeviceFormatProperties2KHR */ 62b8e80941Smrgstruct wsi_format_modifier_properties_list { 63b8e80941Smrg VkStructureType sType; 64b8e80941Smrg const void *pNext; 65b8e80941Smrg 66b8e80941Smrg uint32_t modifier_count; 67b8e80941Smrg struct wsi_format_modifier_properties *modifier_properties; 68b8e80941Smrg}; 69b8e80941Smrg 70b8e80941Smrg/* To be chained into VkSurfaceCapabilities2KHR */ 71b8e80941Smrgstruct wsi_surface_supported_counters { 72b8e80941Smrg VkStructureType sType; 73b8e80941Smrg const void *pNext; 74b8e80941Smrg 75b8e80941Smrg VkSurfaceCounterFlagsEXT supported_surface_counters; 76b8e80941Smrg 77b8e80941Smrg}; 78b8e80941Smrg 79b8e80941Smrgstruct wsi_fence { 80b8e80941Smrg VkDevice device; 81b8e80941Smrg const struct wsi_device *wsi_device; 82b8e80941Smrg VkDisplayKHR display; 83b8e80941Smrg const VkAllocationCallbacks *alloc; 84b8e80941Smrg VkResult (*wait)(struct wsi_fence *fence, uint64_t abs_timeout); 85b8e80941Smrg void (*destroy)(struct wsi_fence *fence); 86b8e80941Smrg}; 87b8e80941Smrg 88b8e80941Smrgstruct wsi_interface; 89b8e80941Smrg 90b8e80941Smrgstruct driOptionCache; 91b8e80941Smrg 92b8e80941Smrg#define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1) 93b8e80941Smrg 94b8e80941Smrgstruct wsi_device { 95b8e80941Smrg /* Allocator for the instance */ 96b8e80941Smrg VkAllocationCallbacks instance_alloc; 97b8e80941Smrg 98b8e80941Smrg VkPhysicalDevice pdevice; 99b8e80941Smrg VkPhysicalDeviceMemoryProperties memory_props; 100b8e80941Smrg uint32_t queue_family_count; 101b8e80941Smrg 102b8e80941Smrg VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info; 103b8e80941Smrg 104b8e80941Smrg bool supports_modifiers; 105b8e80941Smrg uint32_t maxImageDimension2D; 106b8e80941Smrg VkPresentModeKHR override_present_mode; 107b8e80941Smrg 108b8e80941Smrg /* Whether to enable adaptive sync for a swapchain if implemented and 109b8e80941Smrg * available. Not all window systems might support this. */ 110b8e80941Smrg bool enable_adaptive_sync; 111b8e80941Smrg 112b8e80941Smrg struct { 113b8e80941Smrg /* Override the minimum number of images on the swapchain. 114b8e80941Smrg * 0 = no override */ 115b8e80941Smrg uint32_t override_minImageCount; 116b8e80941Smrg } x11; 117b8e80941Smrg 118b8e80941Smrg uint64_t (*image_get_modifier)(VkImage image); 119b8e80941Smrg 120b8e80941Smrg#define WSI_CB(cb) PFN_vk##cb cb 121b8e80941Smrg WSI_CB(AllocateMemory); 122b8e80941Smrg WSI_CB(AllocateCommandBuffers); 123b8e80941Smrg WSI_CB(BindBufferMemory); 124b8e80941Smrg WSI_CB(BindImageMemory); 125b8e80941Smrg WSI_CB(BeginCommandBuffer); 126b8e80941Smrg WSI_CB(CmdCopyImageToBuffer); 127b8e80941Smrg WSI_CB(CreateBuffer); 128b8e80941Smrg WSI_CB(CreateCommandPool); 129b8e80941Smrg WSI_CB(CreateFence); 130b8e80941Smrg WSI_CB(CreateImage); 131b8e80941Smrg WSI_CB(DestroyBuffer); 132b8e80941Smrg WSI_CB(DestroyCommandPool); 133b8e80941Smrg WSI_CB(DestroyFence); 134b8e80941Smrg WSI_CB(DestroyImage); 135b8e80941Smrg WSI_CB(EndCommandBuffer); 136b8e80941Smrg WSI_CB(FreeMemory); 137b8e80941Smrg WSI_CB(FreeCommandBuffers); 138b8e80941Smrg WSI_CB(GetBufferMemoryRequirements); 139b8e80941Smrg WSI_CB(GetImageMemoryRequirements); 140b8e80941Smrg WSI_CB(GetImageSubresourceLayout); 141b8e80941Smrg WSI_CB(GetMemoryFdKHR); 142b8e80941Smrg WSI_CB(GetPhysicalDeviceFormatProperties); 143b8e80941Smrg WSI_CB(GetPhysicalDeviceFormatProperties2KHR); 144b8e80941Smrg WSI_CB(ResetFences); 145b8e80941Smrg WSI_CB(QueueSubmit); 146b8e80941Smrg WSI_CB(WaitForFences); 147b8e80941Smrg#undef WSI_CB 148b8e80941Smrg 149b8e80941Smrg struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX]; 150b8e80941Smrg}; 151b8e80941Smrg 152b8e80941Smrgtypedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName); 153b8e80941Smrg 154b8e80941SmrgVkResult 155b8e80941Smrgwsi_device_init(struct wsi_device *wsi, 156b8e80941Smrg VkPhysicalDevice pdevice, 157b8e80941Smrg WSI_FN_GetPhysicalDeviceProcAddr proc_addr, 158b8e80941Smrg const VkAllocationCallbacks *alloc, 159b8e80941Smrg int display_fd, 160b8e80941Smrg const struct driOptionCache *dri_options); 161b8e80941Smrg 162b8e80941Smrgvoid 163b8e80941Smrgwsi_device_finish(struct wsi_device *wsi, 164b8e80941Smrg const VkAllocationCallbacks *alloc); 165b8e80941Smrg 166b8e80941Smrg#define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \ 167b8e80941Smrg \ 168b8e80941Smrg static inline __VkIcdType * \ 169b8e80941Smrg __VkIcdType ## _from_handle(__VkType _handle) \ 170b8e80941Smrg { \ 171b8e80941Smrg return (__VkIcdType *)(uintptr_t) _handle; \ 172b8e80941Smrg } \ 173b8e80941Smrg \ 174b8e80941Smrg static inline __VkType \ 175b8e80941Smrg __VkIcdType ## _to_handle(__VkIcdType *_obj) \ 176b8e80941Smrg { \ 177b8e80941Smrg return (__VkType)(uintptr_t) _obj; \ 178b8e80941Smrg } 179b8e80941Smrg 180b8e80941Smrg#define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \ 181b8e80941Smrg __VkIcdType *__name = __VkIcdType ## _from_handle(__handle) 182b8e80941Smrg 183b8e80941SmrgICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR) 184b8e80941Smrg 185b8e80941SmrgVkResult 186b8e80941Smrgwsi_common_get_surface_support(struct wsi_device *wsi_device, 187b8e80941Smrg uint32_t queueFamilyIndex, 188b8e80941Smrg VkSurfaceKHR surface, 189b8e80941Smrg VkBool32* pSupported); 190b8e80941Smrg 191b8e80941SmrgVkResult 192b8e80941Smrgwsi_common_get_surface_capabilities(struct wsi_device *wsi_device, 193b8e80941Smrg VkSurfaceKHR surface, 194b8e80941Smrg VkSurfaceCapabilitiesKHR *pSurfaceCapabilities); 195b8e80941Smrg 196b8e80941SmrgVkResult 197b8e80941Smrgwsi_common_get_surface_capabilities2(struct wsi_device *wsi_device, 198b8e80941Smrg const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, 199b8e80941Smrg VkSurfaceCapabilities2KHR *pSurfaceCapabilities); 200b8e80941Smrg 201b8e80941SmrgVkResult 202b8e80941Smrgwsi_common_get_surface_formats(struct wsi_device *wsi_device, 203b8e80941Smrg VkSurfaceKHR surface, 204b8e80941Smrg uint32_t *pSurfaceFormatCount, 205b8e80941Smrg VkSurfaceFormatKHR *pSurfaceFormats); 206b8e80941Smrg 207b8e80941SmrgVkResult 208b8e80941Smrgwsi_common_get_surface_formats2(struct wsi_device *wsi_device, 209b8e80941Smrg const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, 210b8e80941Smrg uint32_t *pSurfaceFormatCount, 211b8e80941Smrg VkSurfaceFormat2KHR *pSurfaceFormats); 212b8e80941Smrg 213b8e80941SmrgVkResult 214b8e80941Smrgwsi_common_get_surface_present_modes(struct wsi_device *wsi_device, 215b8e80941Smrg VkSurfaceKHR surface, 216b8e80941Smrg uint32_t *pPresentModeCount, 217b8e80941Smrg VkPresentModeKHR *pPresentModes); 218b8e80941Smrg 219b8e80941SmrgVkResult 220b8e80941Smrgwsi_common_get_present_rectangles(struct wsi_device *wsi, 221b8e80941Smrg VkSurfaceKHR surface, 222b8e80941Smrg uint32_t* pRectCount, 223b8e80941Smrg VkRect2D* pRects); 224b8e80941Smrg 225b8e80941SmrgVkResult 226b8e80941Smrgwsi_common_get_surface_capabilities2ext( 227b8e80941Smrg struct wsi_device *wsi_device, 228b8e80941Smrg VkSurfaceKHR surface, 229b8e80941Smrg VkSurfaceCapabilities2EXT *pSurfaceCapabilities); 230b8e80941Smrg 231b8e80941SmrgVkResult 232b8e80941Smrgwsi_common_get_images(VkSwapchainKHR _swapchain, 233b8e80941Smrg uint32_t *pSwapchainImageCount, 234b8e80941Smrg VkImage *pSwapchainImages); 235b8e80941Smrg 236b8e80941SmrgVkResult 237b8e80941Smrgwsi_common_acquire_next_image2(const struct wsi_device *wsi, 238b8e80941Smrg VkDevice device, 239b8e80941Smrg const VkAcquireNextImageInfoKHR *pAcquireInfo, 240b8e80941Smrg uint32_t *pImageIndex); 241b8e80941Smrg 242b8e80941SmrgVkResult 243b8e80941Smrgwsi_common_create_swapchain(struct wsi_device *wsi, 244b8e80941Smrg VkDevice device, 245b8e80941Smrg const VkSwapchainCreateInfoKHR *pCreateInfo, 246b8e80941Smrg const VkAllocationCallbacks *pAllocator, 247b8e80941Smrg VkSwapchainKHR *pSwapchain); 248b8e80941Smrgvoid 249b8e80941Smrgwsi_common_destroy_swapchain(VkDevice device, 250b8e80941Smrg VkSwapchainKHR swapchain, 251b8e80941Smrg const VkAllocationCallbacks *pAllocator); 252b8e80941Smrg 253b8e80941SmrgVkResult 254b8e80941Smrgwsi_common_queue_present(const struct wsi_device *wsi, 255b8e80941Smrg VkDevice device_h, 256b8e80941Smrg VkQueue queue_h, 257b8e80941Smrg int queue_family_index, 258b8e80941Smrg const VkPresentInfoKHR *pPresentInfo); 259b8e80941Smrg 260b8e80941Smrguint64_t 261b8e80941Smrgwsi_common_get_current_time(void); 262b8e80941Smrg 263b8e80941Smrg#endif 264