1 /*
2 * Copyright © 2015 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
24 #include "lvp_wsi.h"
25
26 static PFN_vkVoidFunction
lvp_wsi_proc_addr(VkPhysicalDevice physicalDevice,const char * pName)27 lvp_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
28 {
29 return lvp_lookup_entrypoint(pName);
30 }
31
32 VkResult
lvp_init_wsi(struct lvp_physical_device * physical_device)33 lvp_init_wsi(struct lvp_physical_device *physical_device)
34 {
35 return wsi_device_init(&physical_device->wsi_device,
36 lvp_physical_device_to_handle(physical_device),
37 lvp_wsi_proc_addr,
38 &physical_device->instance->alloc,
39 -1, NULL, true);
40 }
41
42 void
lvp_finish_wsi(struct lvp_physical_device * physical_device)43 lvp_finish_wsi(struct lvp_physical_device *physical_device)
44 {
45 wsi_device_finish(&physical_device->wsi_device,
46 &physical_device->instance->alloc);
47 }
48
lvp_DestroySurfaceKHR(VkInstance _instance,VkSurfaceKHR _surface,const VkAllocationCallbacks * pAllocator)49 void lvp_DestroySurfaceKHR(
50 VkInstance _instance,
51 VkSurfaceKHR _surface,
52 const VkAllocationCallbacks* pAllocator)
53 {
54 LVP_FROM_HANDLE(lvp_instance, instance, _instance);
55 ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
56
57 vk_free2(&instance->alloc, pAllocator, surface);
58 }
59
lvp_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,VkSurfaceKHR surface,VkBool32 * pSupported)60 VkResult lvp_GetPhysicalDeviceSurfaceSupportKHR(
61 VkPhysicalDevice physicalDevice,
62 uint32_t queueFamilyIndex,
63 VkSurfaceKHR surface,
64 VkBool32* pSupported)
65 {
66 LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
67
68 return wsi_common_get_surface_support(&device->wsi_device,
69 queueFamilyIndex,
70 surface,
71 pSupported);
72 }
73
lvp_GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,VkSurfaceCapabilitiesKHR * pSurfaceCapabilities)74 VkResult lvp_GetPhysicalDeviceSurfaceCapabilitiesKHR(
75 VkPhysicalDevice physicalDevice,
76 VkSurfaceKHR surface,
77 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
78 {
79 LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
80
81 return wsi_common_get_surface_capabilities(&device->wsi_device,
82 surface,
83 pSurfaceCapabilities);
84 }
85
lvp_GetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceSurfaceInfo2KHR * pSurfaceInfo,VkSurfaceCapabilities2KHR * pSurfaceCapabilities)86 VkResult lvp_GetPhysicalDeviceSurfaceCapabilities2KHR(
87 VkPhysicalDevice physicalDevice,
88 const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
89 VkSurfaceCapabilities2KHR* pSurfaceCapabilities)
90 {
91 LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
92
93 return wsi_common_get_surface_capabilities2(&device->wsi_device,
94 pSurfaceInfo,
95 pSurfaceCapabilities);
96 }
97
lvp_GetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,VkSurfaceCapabilities2EXT * pSurfaceCapabilities)98 VkResult lvp_GetPhysicalDeviceSurfaceCapabilities2EXT(
99 VkPhysicalDevice physicalDevice,
100 VkSurfaceKHR surface,
101 VkSurfaceCapabilities2EXT* pSurfaceCapabilities)
102 {
103 LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
104
105 return wsi_common_get_surface_capabilities2ext(&device->wsi_device,
106 surface,
107 pSurfaceCapabilities);
108 }
109
lvp_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pSurfaceFormatCount,VkSurfaceFormatKHR * pSurfaceFormats)110 VkResult lvp_GetPhysicalDeviceSurfaceFormatsKHR(
111 VkPhysicalDevice physicalDevice,
112 VkSurfaceKHR surface,
113 uint32_t* pSurfaceFormatCount,
114 VkSurfaceFormatKHR* pSurfaceFormats)
115 {
116 LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
117 return wsi_common_get_surface_formats(&device->wsi_device,
118 surface,
119 pSurfaceFormatCount,
120 pSurfaceFormats);
121 }
122
lvp_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pPresentModeCount,VkPresentModeKHR * pPresentModes)123 VkResult lvp_GetPhysicalDeviceSurfacePresentModesKHR(
124 VkPhysicalDevice physicalDevice,
125 VkSurfaceKHR surface,
126 uint32_t* pPresentModeCount,
127 VkPresentModeKHR* pPresentModes)
128 {
129 LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
130
131 return wsi_common_get_surface_present_modes(&device->wsi_device,
132 surface,
133 pPresentModeCount,
134 pPresentModes);
135 }
136
lvp_CreateSwapchainKHR(VkDevice _device,const VkSwapchainCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSwapchainKHR * pSwapchain)137 VkResult lvp_CreateSwapchainKHR(
138 VkDevice _device,
139 const VkSwapchainCreateInfoKHR* pCreateInfo,
140 const VkAllocationCallbacks* pAllocator,
141 VkSwapchainKHR* pSwapchain)
142 {
143 LVP_FROM_HANDLE(lvp_device, device, _device);
144 const VkAllocationCallbacks *alloc;
145 if (pAllocator)
146 alloc = pAllocator;
147 else
148 alloc = &device->vk.alloc;
149
150 return wsi_common_create_swapchain(&device->physical_device->wsi_device,
151 lvp_device_to_handle(device),
152 pCreateInfo,
153 alloc,
154 pSwapchain);
155 }
156
lvp_DestroySwapchainKHR(VkDevice _device,VkSwapchainKHR swapchain,const VkAllocationCallbacks * pAllocator)157 void lvp_DestroySwapchainKHR(
158 VkDevice _device,
159 VkSwapchainKHR swapchain,
160 const VkAllocationCallbacks* pAllocator)
161 {
162 LVP_FROM_HANDLE(lvp_device, device, _device);
163 const VkAllocationCallbacks *alloc;
164
165 if (pAllocator)
166 alloc = pAllocator;
167 else
168 alloc = &device->vk.alloc;
169
170 wsi_common_destroy_swapchain(_device, swapchain, alloc);
171 }
172
lvp_GetSwapchainImagesKHR(VkDevice device,VkSwapchainKHR swapchain,uint32_t * pSwapchainImageCount,VkImage * pSwapchainImages)173 VkResult lvp_GetSwapchainImagesKHR(
174 VkDevice device,
175 VkSwapchainKHR swapchain,
176 uint32_t* pSwapchainImageCount,
177 VkImage* pSwapchainImages)
178 {
179 return wsi_common_get_images(swapchain,
180 pSwapchainImageCount,
181 pSwapchainImages);
182 }
183
lvp_AcquireNextImageKHR(VkDevice device,VkSwapchainKHR swapchain,uint64_t timeout,VkSemaphore semaphore,VkFence fence,uint32_t * pImageIndex)184 VkResult lvp_AcquireNextImageKHR(
185 VkDevice device,
186 VkSwapchainKHR swapchain,
187 uint64_t timeout,
188 VkSemaphore semaphore,
189 VkFence fence,
190 uint32_t* pImageIndex)
191 {
192 VkAcquireNextImageInfoKHR acquire_info = {
193 .sType = VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR,
194 .swapchain = swapchain,
195 .timeout = timeout,
196 .semaphore = semaphore,
197 .fence = fence,
198 .deviceMask = 0,
199 };
200
201 return lvp_AcquireNextImage2KHR(device, &acquire_info, pImageIndex);
202 }
203
lvp_AcquireNextImage2KHR(VkDevice _device,const VkAcquireNextImageInfoKHR * pAcquireInfo,uint32_t * pImageIndex)204 VkResult lvp_AcquireNextImage2KHR(
205 VkDevice _device,
206 const VkAcquireNextImageInfoKHR* pAcquireInfo,
207 uint32_t* pImageIndex)
208 {
209 LVP_FROM_HANDLE(lvp_device, device, _device);
210 struct lvp_physical_device *pdevice = device->physical_device;
211
212 VkResult result = wsi_common_acquire_next_image2(&pdevice->wsi_device,
213 _device,
214 pAcquireInfo,
215 pImageIndex);
216
217 LVP_FROM_HANDLE(lvp_fence, fence, pAcquireInfo->fence);
218
219 if (fence && (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR)) {
220 fence->signaled = true;
221 }
222 return result;
223 }
224
lvp_QueuePresentKHR(VkQueue _queue,const VkPresentInfoKHR * pPresentInfo)225 VkResult lvp_QueuePresentKHR(
226 VkQueue _queue,
227 const VkPresentInfoKHR* pPresentInfo)
228 {
229 LVP_FROM_HANDLE(lvp_queue, queue, _queue);
230 return wsi_common_queue_present(&queue->device->physical_device->wsi_device,
231 lvp_device_to_handle(queue->device),
232 _queue, 0,
233 pPresentInfo);
234 }
235
236
lvp_GetDeviceGroupPresentCapabilitiesKHR(VkDevice device,VkDeviceGroupPresentCapabilitiesKHR * pCapabilities)237 VkResult lvp_GetDeviceGroupPresentCapabilitiesKHR(
238 VkDevice device,
239 VkDeviceGroupPresentCapabilitiesKHR* pCapabilities)
240 {
241 memset(pCapabilities->presentMask, 0,
242 sizeof(pCapabilities->presentMask));
243 pCapabilities->presentMask[0] = 0x1;
244 pCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
245
246 return VK_SUCCESS;
247 }
248
lvp_GetDeviceGroupSurfacePresentModesKHR(VkDevice device,VkSurfaceKHR surface,VkDeviceGroupPresentModeFlagsKHR * pModes)249 VkResult lvp_GetDeviceGroupSurfacePresentModesKHR(
250 VkDevice device,
251 VkSurfaceKHR surface,
252 VkDeviceGroupPresentModeFlagsKHR* pModes)
253 {
254 *pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
255
256 return VK_SUCCESS;
257 }
258
lvp_GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pRectCount,VkRect2D * pRects)259 VkResult lvp_GetPhysicalDevicePresentRectanglesKHR(
260 VkPhysicalDevice physicalDevice,
261 VkSurfaceKHR surface,
262 uint32_t* pRectCount,
263 VkRect2D* pRects)
264 {
265 LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
266
267 return wsi_common_get_present_rectangles(&device->wsi_device,
268 surface,
269 pRectCount, pRects);
270 }
271