1b8e80941Smrg/* 2b8e80941Smrg * Copyright © 2017 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_PRIVATE_H 24b8e80941Smrg#define WSI_COMMON_PRIVATE_H 25b8e80941Smrg 26b8e80941Smrg#include "wsi_common.h" 27b8e80941Smrg 28b8e80941Smrgstruct wsi_image { 29b8e80941Smrg VkImage image; 30b8e80941Smrg VkDeviceMemory memory; 31b8e80941Smrg 32b8e80941Smrg struct { 33b8e80941Smrg VkBuffer buffer; 34b8e80941Smrg VkDeviceMemory memory; 35b8e80941Smrg VkCommandBuffer *blit_cmd_buffers; 36b8e80941Smrg } prime; 37b8e80941Smrg 38b8e80941Smrg uint64_t drm_modifier; 39b8e80941Smrg int num_planes; 40b8e80941Smrg uint32_t sizes[4]; 41b8e80941Smrg uint32_t offsets[4]; 42b8e80941Smrg uint32_t row_pitches[4]; 43b8e80941Smrg int fds[4]; 44b8e80941Smrg}; 45b8e80941Smrg 46b8e80941Smrgstruct wsi_swapchain { 47b8e80941Smrg const struct wsi_device *wsi; 48b8e80941Smrg 49b8e80941Smrg VkDevice device; 50b8e80941Smrg VkAllocationCallbacks alloc; 51b8e80941Smrg VkFence fences[3]; 52b8e80941Smrg VkPresentModeKHR present_mode; 53b8e80941Smrg uint32_t image_count; 54b8e80941Smrg 55b8e80941Smrg bool use_prime_blit; 56b8e80941Smrg 57b8e80941Smrg /* Command pools, one per queue family */ 58b8e80941Smrg VkCommandPool *cmd_pools; 59b8e80941Smrg 60b8e80941Smrg VkResult (*destroy)(struct wsi_swapchain *swapchain, 61b8e80941Smrg const VkAllocationCallbacks *pAllocator); 62b8e80941Smrg struct wsi_image *(*get_wsi_image)(struct wsi_swapchain *swapchain, 63b8e80941Smrg uint32_t image_index); 64b8e80941Smrg VkResult (*acquire_next_image)(struct wsi_swapchain *swap_chain, 65b8e80941Smrg const VkAcquireNextImageInfoKHR *info, 66b8e80941Smrg uint32_t *image_index); 67b8e80941Smrg VkResult (*queue_present)(struct wsi_swapchain *swap_chain, 68b8e80941Smrg uint32_t image_index, 69b8e80941Smrg const VkPresentRegionKHR *damage); 70b8e80941Smrg}; 71b8e80941Smrg 72b8e80941Smrgbool 73b8e80941Smrgwsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd); 74b8e80941Smrg 75b8e80941SmrgVkResult 76b8e80941Smrgwsi_swapchain_init(const struct wsi_device *wsi, 77b8e80941Smrg struct wsi_swapchain *chain, 78b8e80941Smrg VkDevice device, 79b8e80941Smrg const VkSwapchainCreateInfoKHR *pCreateInfo, 80b8e80941Smrg const VkAllocationCallbacks *pAllocator); 81b8e80941Smrg 82b8e80941Smrgenum VkPresentModeKHR 83b8e80941Smrgwsi_swapchain_get_present_mode(struct wsi_device *wsi, 84b8e80941Smrg const VkSwapchainCreateInfoKHR *pCreateInfo); 85b8e80941Smrg 86b8e80941Smrgvoid wsi_swapchain_finish(struct wsi_swapchain *chain); 87b8e80941Smrg 88b8e80941SmrgVkResult 89b8e80941Smrgwsi_create_native_image(const struct wsi_swapchain *chain, 90b8e80941Smrg const VkSwapchainCreateInfoKHR *pCreateInfo, 91b8e80941Smrg uint32_t num_modifier_lists, 92b8e80941Smrg const uint32_t *num_modifiers, 93b8e80941Smrg const uint64_t *const *modifiers, 94b8e80941Smrg struct wsi_image *image); 95b8e80941Smrg 96b8e80941SmrgVkResult 97b8e80941Smrgwsi_create_prime_image(const struct wsi_swapchain *chain, 98b8e80941Smrg const VkSwapchainCreateInfoKHR *pCreateInfo, 99b8e80941Smrg bool use_modifier, 100b8e80941Smrg struct wsi_image *image); 101b8e80941Smrg 102b8e80941Smrgvoid 103b8e80941Smrgwsi_destroy_image(const struct wsi_swapchain *chain, 104b8e80941Smrg struct wsi_image *image); 105b8e80941Smrg 106b8e80941Smrg 107b8e80941Smrgstruct wsi_interface { 108b8e80941Smrg VkResult (*get_support)(VkIcdSurfaceBase *surface, 109b8e80941Smrg struct wsi_device *wsi_device, 110b8e80941Smrg uint32_t queueFamilyIndex, 111b8e80941Smrg VkBool32* pSupported); 112b8e80941Smrg VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface, 113b8e80941Smrg struct wsi_device *wsi_device, 114b8e80941Smrg const void *info_next, 115b8e80941Smrg VkSurfaceCapabilities2KHR* pSurfaceCapabilities); 116b8e80941Smrg VkResult (*get_formats)(VkIcdSurfaceBase *surface, 117b8e80941Smrg struct wsi_device *wsi_device, 118b8e80941Smrg uint32_t* pSurfaceFormatCount, 119b8e80941Smrg VkSurfaceFormatKHR* pSurfaceFormats); 120b8e80941Smrg VkResult (*get_formats2)(VkIcdSurfaceBase *surface, 121b8e80941Smrg struct wsi_device *wsi_device, 122b8e80941Smrg const void *info_next, 123b8e80941Smrg uint32_t* pSurfaceFormatCount, 124b8e80941Smrg VkSurfaceFormat2KHR* pSurfaceFormats); 125b8e80941Smrg VkResult (*get_present_modes)(VkIcdSurfaceBase *surface, 126b8e80941Smrg uint32_t* pPresentModeCount, 127b8e80941Smrg VkPresentModeKHR* pPresentModes); 128b8e80941Smrg VkResult (*get_present_rectangles)(VkIcdSurfaceBase *surface, 129b8e80941Smrg struct wsi_device *wsi_device, 130b8e80941Smrg uint32_t* pRectCount, 131b8e80941Smrg VkRect2D* pRects); 132b8e80941Smrg VkResult (*create_swapchain)(VkIcdSurfaceBase *surface, 133b8e80941Smrg VkDevice device, 134b8e80941Smrg struct wsi_device *wsi_device, 135b8e80941Smrg const VkSwapchainCreateInfoKHR* pCreateInfo, 136b8e80941Smrg const VkAllocationCallbacks* pAllocator, 137b8e80941Smrg struct wsi_swapchain **swapchain); 138b8e80941Smrg}; 139b8e80941Smrg 140b8e80941SmrgVkResult wsi_x11_init_wsi(struct wsi_device *wsi_device, 141b8e80941Smrg const VkAllocationCallbacks *alloc, 142b8e80941Smrg const struct driOptionCache *dri_options); 143b8e80941Smrgvoid wsi_x11_finish_wsi(struct wsi_device *wsi_device, 144b8e80941Smrg const VkAllocationCallbacks *alloc); 145b8e80941SmrgVkResult wsi_wl_init_wsi(struct wsi_device *wsi_device, 146b8e80941Smrg const VkAllocationCallbacks *alloc, 147b8e80941Smrg VkPhysicalDevice physical_device); 148b8e80941Smrgvoid wsi_wl_finish_wsi(struct wsi_device *wsi_device, 149b8e80941Smrg const VkAllocationCallbacks *alloc); 150b8e80941Smrg 151b8e80941Smrg 152b8e80941SmrgVkResult 153b8e80941Smrgwsi_display_init_wsi(struct wsi_device *wsi_device, 154b8e80941Smrg const VkAllocationCallbacks *alloc, 155b8e80941Smrg int display_fd); 156b8e80941Smrg 157b8e80941Smrgvoid 158b8e80941Smrgwsi_display_finish_wsi(struct wsi_device *wsi_device, 159b8e80941Smrg const VkAllocationCallbacks *alloc); 160b8e80941Smrg 161b8e80941Smrg#define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \ 162b8e80941Smrg \ 163b8e80941Smrg static inline struct __wsi_type * \ 164b8e80941Smrg __wsi_type ## _from_handle(__VkType _handle) \ 165b8e80941Smrg { \ 166b8e80941Smrg return (struct __wsi_type *)(uintptr_t) _handle; \ 167b8e80941Smrg } \ 168b8e80941Smrg \ 169b8e80941Smrg static inline __VkType \ 170b8e80941Smrg __wsi_type ## _to_handle(struct __wsi_type *_obj) \ 171b8e80941Smrg { \ 172b8e80941Smrg return (__VkType)(uintptr_t) _obj; \ 173b8e80941Smrg } 174b8e80941Smrg 175b8e80941Smrg#define WSI_FROM_HANDLE(__wsi_type, __name, __handle) \ 176b8e80941Smrg struct __wsi_type *__name = __wsi_type ## _from_handle(__handle) 177b8e80941Smrg 178b8e80941SmrgWSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, VkSwapchainKHR) 179b8e80941Smrg 180b8e80941Smrg#endif /* WSI_COMMON_PRIVATE_H */ 181