blob: ad7aa22c748268a9df2a483523b22c595b561854 [file] [log] [blame]
Jon Ashburn07daee72015-05-21 18:13:33 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2015 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Jon Ashburn <jon@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
27 */
28
29#include <string.h>
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060030#include "vk_loader_platform.h"
Jon Ashburn07daee72015-05-21 18:13:33 -060031#include "loader.h"
32#include "wsi_lunarg.h"
33
34/************ Trampoline entrypoints *******************/
35/* since one entrypoint is instance level will make available all entrypoints */
Jon Ashburn07daee72015-05-21 18:13:33 -060036
37VkResult wsi_lunarg_CreateSwapChainWSI(
38 VkDevice device,
39 const VkSwapChainCreateInfoWSI* pCreateInfo,
40 VkSwapChainWSI* pSwapChain)
41{
42 const VkLayerDispatchTable *disp;
43 VkResult res;
44
45 disp = loader_get_dispatch(device);
46
47 res = disp->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
48 if (res == VK_SUCCESS) {
49 loader_init_dispatch(*pSwapChain, disp);
50 }
51
52 return res;
53}
54
55VkResult wsi_lunarg_DestroySwapChainWSI(
56 VkSwapChainWSI swapChain)
57{
58 const VkLayerDispatchTable *disp;
59
60 disp = loader_get_dispatch(swapChain);
61
62 return disp->DestroySwapChainWSI(swapChain);
63}
64
65static VkResult wsi_lunarg_GetSwapChainInfoWSI(
66 VkSwapChainWSI swapChain,
67 VkSwapChainInfoTypeWSI infoType,
68 size_t* pDataSize,
69 void* pData)
70{
71 const VkLayerDispatchTable *disp;
72
73 disp = loader_get_dispatch(swapChain);
74
75 return disp->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
76}
77
78static VkResult wsi_lunarg_QueuePresentWSI(
79 VkQueue queue,
80 const VkPresentInfoWSI* pPresentInfo)
81{
82 const VkLayerDispatchTable *disp;
83
84 disp = loader_get_dispatch(queue);
85
86 return disp->QueuePresentWSI(queue, pPresentInfo);
87}
88
Jon Ashburn07daee72015-05-21 18:13:33 -060089
Jon Ashburn07daee72015-05-21 18:13:33 -060090
91void *wsi_lunarg_GetInstanceProcAddr(
92 VkInstance instance,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060093 const char* pName)
Jon Ashburn07daee72015-05-21 18:13:33 -060094{
95 if (instance == VK_NULL_HANDLE)
96 return NULL;
97
Jon Ashburn922c8f62015-06-18 09:05:37 -060098 // TODO once WSI is pure device extension with no special trampoline code remove this function
Jon Ashburnb19ddbf2015-06-16 12:44:51 -060099 /* since one of these entrypoints must be loader handled will report all */
Jon Ashburn07daee72015-05-21 18:13:33 -0600100 if (!strcmp(pName, "vkCreateSwapChainWSI"))
101 return (void*) wsi_lunarg_CreateSwapChainWSI;
102 if (!strcmp(pName, "vkDestroySwapChainWSI"))
103 return (void*) wsi_lunarg_DestroySwapChainWSI;
104 if (!strcmp(pName, "vkGetSwapChainInfoWSI"))
105 return (void*) wsi_lunarg_GetSwapChainInfoWSI;
106 if (!strcmp(pName, "vkQueuePresentWSI"))
107 return (void*) wsi_lunarg_QueuePresentWSI;
108
109 return NULL;
110}
111
112void *wsi_lunarg_GetDeviceProcAddr(
113 VkDevice device,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600114 const char* name)
Jon Ashburn07daee72015-05-21 18:13:33 -0600115{
116 if (device == VK_NULL_HANDLE)
117 return NULL;
118
Jon Ashburn922c8f62015-06-18 09:05:37 -0600119 // TODO make sure WSI is enabled, but eventually this function goes away
Jon Ashburn07daee72015-05-21 18:13:33 -0600120 /* only handle device entrypoints that are loader special cases */
121 if (!strcmp(name, "vkCreateSwapChainWSI"))
122 return (void*) wsi_lunarg_CreateSwapChainWSI;
123
124 return NULL;
125}