blob: c80c4c28dea0830436d514f68e2f83a1d0a87fea [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
Courtney Goeltzenleuchter7f5aafc2015-07-05 11:28:29 -060029#define _GNU_SOURCE
30#include <stdio.h>
31#include <stdlib.h>
Jon Ashburn07daee72015-05-21 18:13:33 -060032#include <string.h>
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060033#include "vk_loader_platform.h"
Jon Ashburn07daee72015-05-21 18:13:33 -060034#include "loader.h"
35#include "wsi_lunarg.h"
36
37/************ Trampoline entrypoints *******************/
38/* since one entrypoint is instance level will make available all entrypoints */
Jon Ashburn07daee72015-05-21 18:13:33 -060039
40VkResult wsi_lunarg_CreateSwapChainWSI(
41 VkDevice device,
42 const VkSwapChainCreateInfoWSI* pCreateInfo,
43 VkSwapChainWSI* pSwapChain)
44{
45 const VkLayerDispatchTable *disp;
46 VkResult res;
47
48 disp = loader_get_dispatch(device);
49
50 res = disp->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
51 if (res == VK_SUCCESS) {
52 loader_init_dispatch(*pSwapChain, disp);
53 }
54
55 return res;
56}
57
58VkResult wsi_lunarg_DestroySwapChainWSI(
59 VkSwapChainWSI swapChain)
60{
61 const VkLayerDispatchTable *disp;
62
63 disp = loader_get_dispatch(swapChain);
64
65 return disp->DestroySwapChainWSI(swapChain);
66}
67
68static VkResult wsi_lunarg_GetSwapChainInfoWSI(
69 VkSwapChainWSI swapChain,
70 VkSwapChainInfoTypeWSI infoType,
71 size_t* pDataSize,
72 void* pData)
73{
74 const VkLayerDispatchTable *disp;
75
76 disp = loader_get_dispatch(swapChain);
77
78 return disp->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
79}
80
81static VkResult wsi_lunarg_QueuePresentWSI(
82 VkQueue queue,
83 const VkPresentInfoWSI* pPresentInfo)
84{
85 const VkLayerDispatchTable *disp;
86
87 disp = loader_get_dispatch(queue);
88
89 return disp->QueuePresentWSI(queue, pPresentInfo);
90}
91
Jon Ashburn07daee72015-05-21 18:13:33 -060092
Jon Ashburn07daee72015-05-21 18:13:33 -060093
94void *wsi_lunarg_GetInstanceProcAddr(
95 VkInstance instance,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060096 const char* pName)
Jon Ashburn07daee72015-05-21 18:13:33 -060097{
98 if (instance == VK_NULL_HANDLE)
99 return NULL;
100
Jon Ashburn922c8f62015-06-18 09:05:37 -0600101 // TODO once WSI is pure device extension with no special trampoline code remove this function
Jon Ashburnb19ddbf2015-06-16 12:44:51 -0600102 /* since one of these entrypoints must be loader handled will report all */
Jon Ashburn07daee72015-05-21 18:13:33 -0600103 if (!strcmp(pName, "vkCreateSwapChainWSI"))
104 return (void*) wsi_lunarg_CreateSwapChainWSI;
105 if (!strcmp(pName, "vkDestroySwapChainWSI"))
106 return (void*) wsi_lunarg_DestroySwapChainWSI;
107 if (!strcmp(pName, "vkGetSwapChainInfoWSI"))
108 return (void*) wsi_lunarg_GetSwapChainInfoWSI;
109 if (!strcmp(pName, "vkQueuePresentWSI"))
110 return (void*) wsi_lunarg_QueuePresentWSI;
111
112 return NULL;
113}
114
115void *wsi_lunarg_GetDeviceProcAddr(
116 VkDevice device,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600117 const char* name)
Jon Ashburn07daee72015-05-21 18:13:33 -0600118{
119 if (device == VK_NULL_HANDLE)
120 return NULL;
121
Jon Ashburn922c8f62015-06-18 09:05:37 -0600122 // TODO make sure WSI is enabled, but eventually this function goes away
Jon Ashburn07daee72015-05-21 18:13:33 -0600123 /* only handle device entrypoints that are loader special cases */
124 if (!strcmp(name, "vkCreateSwapChainWSI"))
125 return (void*) wsi_lunarg_CreateSwapChainWSI;
126
127 return NULL;
128}