1 /* 2 * Copyright © 2017 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 #ifndef WSI_COMMON_PRIVATE_H 24 #define WSI_COMMON_PRIVATE_H 25 26 #include "wsi_common.h" 27 #include "vulkan/util/vk_object.h" 28 29 struct wsi_image { 30 VkImage image; 31 VkDeviceMemory memory; 32 33 struct { 34 VkBuffer buffer; 35 VkDeviceMemory memory; 36 VkCommandBuffer *blit_cmd_buffers; 37 } prime; 38 39 uint64_t drm_modifier; 40 int num_planes; 41 uint32_t sizes[4]; 42 uint32_t offsets[4]; 43 uint32_t row_pitches[4]; 44 int fds[4]; 45 }; 46 47 struct wsi_swapchain { 48 struct vk_object_base base; 49 50 const struct wsi_device *wsi; 51 52 VkDevice device; 53 VkAllocationCallbacks alloc; 54 VkFence* fences; 55 VkPresentModeKHR present_mode; 56 uint32_t image_count; 57 58 bool use_prime_blit; 59 60 /* Command pools, one per queue family */ 61 VkCommandPool *cmd_pools; 62 63 VkResult (*destroy)(struct wsi_swapchain *swapchain, 64 const VkAllocationCallbacks *pAllocator); 65 struct wsi_image *(*get_wsi_image)(struct wsi_swapchain *swapchain, 66 uint32_t image_index); 67 VkResult (*acquire_next_image)(struct wsi_swapchain *swap_chain, 68 const VkAcquireNextImageInfoKHR *info, 69 uint32_t *image_index); 70 VkResult (*queue_present)(struct wsi_swapchain *swap_chain, 71 uint32_t image_index, 72 const VkPresentRegionKHR *damage); 73 }; 74 75 bool 76 wsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd); 77 78 VkResult 79 wsi_swapchain_init(const struct wsi_device *wsi, 80 struct wsi_swapchain *chain, 81 VkDevice device, 82 const VkSwapchainCreateInfoKHR *pCreateInfo, 83 const VkAllocationCallbacks *pAllocator); 84 85 enum VkPresentModeKHR 86 wsi_swapchain_get_present_mode(struct wsi_device *wsi, 87 const VkSwapchainCreateInfoKHR *pCreateInfo); 88 89 void wsi_swapchain_finish(struct wsi_swapchain *chain); 90 91 VkResult 92 wsi_create_native_image(const struct wsi_swapchain *chain, 93 const VkSwapchainCreateInfoKHR *pCreateInfo, 94 uint32_t num_modifier_lists, 95 const uint32_t *num_modifiers, 96 const uint64_t *const *modifiers, 97 uint8_t *(alloc_shm)(struct wsi_image *image, unsigned size), 98 struct wsi_image *image); 99 100 VkResult 101 wsi_create_prime_image(const struct wsi_swapchain *chain, 102 const VkSwapchainCreateInfoKHR *pCreateInfo, 103 bool use_modifier, 104 struct wsi_image *image); 105 106 void 107 wsi_destroy_image(const struct wsi_swapchain *chain, 108 struct wsi_image *image); 109 110 111 struct wsi_interface { 112 VkResult (*get_support)(VkIcdSurfaceBase *surface, 113 struct wsi_device *wsi_device, 114 uint32_t queueFamilyIndex, 115 VkBool32* pSupported); 116 VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface, 117 struct wsi_device *wsi_device, 118 const void *info_next, 119 VkSurfaceCapabilities2KHR* pSurfaceCapabilities); 120 VkResult (*get_formats)(VkIcdSurfaceBase *surface, 121 struct wsi_device *wsi_device, 122 uint32_t* pSurfaceFormatCount, 123 VkSurfaceFormatKHR* pSurfaceFormats); 124 VkResult (*get_formats2)(VkIcdSurfaceBase *surface, 125 struct wsi_device *wsi_device, 126 const void *info_next, 127 uint32_t* pSurfaceFormatCount, 128 VkSurfaceFormat2KHR* pSurfaceFormats); 129 VkResult (*get_present_modes)(VkIcdSurfaceBase *surface, 130 uint32_t* pPresentModeCount, 131 VkPresentModeKHR* pPresentModes); 132 VkResult (*get_present_rectangles)(VkIcdSurfaceBase *surface, 133 struct wsi_device *wsi_device, 134 uint32_t* pRectCount, 135 VkRect2D* pRects); 136 VkResult (*create_swapchain)(VkIcdSurfaceBase *surface, 137 VkDevice device, 138 struct wsi_device *wsi_device, 139 const VkSwapchainCreateInfoKHR* pCreateInfo, 140 const VkAllocationCallbacks* pAllocator, 141 struct wsi_swapchain **swapchain); 142 }; 143 144 VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device, 145 const VkAllocationCallbacks *alloc, 146 const struct driOptionCache *dri_options); 147 void wsi_x11_finish_wsi(struct wsi_device *wsi_device, 148 const VkAllocationCallbacks *alloc); 149 VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device, 150 const VkAllocationCallbacks *alloc, 151 VkPhysicalDevice physical_device); 152 void wsi_wl_finish_wsi(struct wsi_device *wsi_device, 153 const VkAllocationCallbacks *alloc); 154 VkResult wsi_win32_init_wsi(struct wsi_device *wsi_device, 155 const VkAllocationCallbacks *alloc, 156 VkPhysicalDevice physical_device); 157 void wsi_win32_finish_wsi(struct wsi_device *wsi_device, 158 const VkAllocationCallbacks *alloc); 159 160 161 VkResult 162 wsi_display_init_wsi(struct wsi_device *wsi_device, 163 const VkAllocationCallbacks *alloc, 164 int display_fd); 165 166 void 167 wsi_display_finish_wsi(struct wsi_device *wsi_device, 168 const VkAllocationCallbacks *alloc); 169 170 VK_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, base, VkSwapchainKHR, 171 VK_OBJECT_TYPE_SWAPCHAIN_KHR) 172 173 #endif /* WSI_COMMON_PRIVATE_H */ 174