2 * Copyright © 2015 Intel Corporation
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:
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
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
29 #include "util/vk_alloc.h"
30 #include <vulkan/vulkan.h>
31 #include <vulkan/vk_icd.h>
33 struct anv_wsi_device
;
34 struct anv_wsi_image_fns
{
35 VkResult (*create_wsi_image
)(VkDevice device_h
,
36 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
37 const VkAllocationCallbacks
*pAllocator
,
39 VkDeviceMemory
*memory_p
,
42 uint32_t *row_pitch_p
,
44 void (*free_wsi_image
)(VkDevice device
,
45 const VkAllocationCallbacks
*pAllocator
,
47 VkDeviceMemory memory_h
);
50 struct anv_swapchain
{
53 VkAllocationCallbacks alloc
;
54 const struct anv_wsi_image_fns
*image_fns
;
57 VkResult (*destroy
)(struct anv_swapchain
*swapchain
,
58 const VkAllocationCallbacks
*pAllocator
);
59 VkResult (*get_images
)(struct anv_swapchain
*swapchain
,
60 uint32_t *pCount
, VkImage
*pSwapchainImages
);
61 VkResult (*acquire_next_image
)(struct anv_swapchain
*swap_chain
,
62 uint64_t timeout
, VkSemaphore semaphore
,
63 uint32_t *image_index
);
64 VkResult (*queue_present
)(struct anv_swapchain
*swap_chain
,
65 uint32_t image_index
);
68 struct anv_wsi_interface
{
69 VkResult (*get_support
)(VkIcdSurfaceBase
*surface
,
70 struct anv_wsi_device
*wsi_device
,
71 const VkAllocationCallbacks
*alloc
,
72 uint32_t queueFamilyIndex
,
73 VkBool32
* pSupported
);
74 VkResult (*get_capabilities
)(VkIcdSurfaceBase
*surface
,
75 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
);
76 VkResult (*get_formats
)(VkIcdSurfaceBase
*surface
,
77 struct anv_wsi_device
*wsi_device
,
78 uint32_t* pSurfaceFormatCount
,
79 VkSurfaceFormatKHR
* pSurfaceFormats
);
80 VkResult (*get_present_modes
)(VkIcdSurfaceBase
*surface
,
81 uint32_t* pPresentModeCount
,
82 VkPresentModeKHR
* pPresentModes
);
83 VkResult (*create_swapchain
)(VkIcdSurfaceBase
*surface
,
85 struct anv_wsi_device
*wsi_device
,
86 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
87 const VkAllocationCallbacks
* pAllocator
,
88 const struct anv_wsi_image_fns
*image_fns
,
89 struct anv_swapchain
**swapchain
);
92 #define VK_ICD_WSI_PLATFORM_MAX 5
94 struct anv_wsi_device
{
95 struct anv_wsi_interface
* wsi
[VK_ICD_WSI_PLATFORM_MAX
];
98 struct anv_wsi_callbacks
{
99 void (*get_phys_device_format_properties
)(VkPhysicalDevice physicalDevice
,
101 VkFormatProperties
*pFormatProperties
);
104 #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
106 static inline struct __wsi_type * \
107 __wsi_type ## _from_handle(__VkType _handle) \
109 return (struct __wsi_type *)(uintptr_t) _handle; \
112 static inline __VkType \
113 __wsi_type ## _to_handle(struct __wsi_type *_obj) \
115 return (__VkType)(uintptr_t) _obj; \
118 WSI_DEFINE_NONDISP_HANDLE_CASTS(_VkIcdSurfaceBase
, VkSurfaceKHR
)
119 WSI_DEFINE_NONDISP_HANDLE_CASTS(anv_swapchain
, VkSwapchainKHR
)
120 VkResult
anv_x11_init_wsi(struct anv_wsi_device
*wsi_device
,
121 const VkAllocationCallbacks
*alloc
);
122 void anv_x11_finish_wsi(struct anv_wsi_device
*wsi_device
,
123 const VkAllocationCallbacks
*alloc
);
124 VkResult
anv_wl_init_wsi(struct anv_wsi_device
*wsi_device
,
125 const VkAllocationCallbacks
*alloc
,
126 VkPhysicalDevice physical_device
,
127 const struct anv_wsi_callbacks
*cbs
);
128 void anv_wl_finish_wsi(struct anv_wsi_device
*wsi_device
,
129 const VkAllocationCallbacks
*alloc
);