-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathicd_interface.cpp
171 lines (152 loc) · 6.63 KB
/
icd_interface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "precompiled.h"
#define ICD_FUNC(name) \
if(!strcmp(pName, #name)) \
return (PFN_vkVoidFunction)&name;
#define CHECK_INST_FUNCS() \
ICD_FUNC(vkEnumerateInstanceExtensionProperties); \
ICD_FUNC(vkEnumerateDeviceExtensionProperties); \
ICD_FUNC(vkGetDeviceProcAddr); \
ICD_FUNC(vkCreateInstance); \
ICD_FUNC(vkDestroyInstance); \
ICD_FUNC(vkEnumeratePhysicalDevices); \
ICD_FUNC(vkCreateDevice); \
ICD_FUNC(vkEnumerateInstanceVersion);
#define CHECK_PHYS_FUNCS() \
ICD_FUNC(vkGetPhysicalDeviceFeatures); \
ICD_FUNC(vkGetPhysicalDeviceProperties); \
ICD_FUNC(vkGetPhysicalDeviceQueueFamilyProperties); \
ICD_FUNC(vkGetPhysicalDeviceMemoryProperties); \
ICD_FUNC(vkGetPhysicalDeviceFormatProperties); \
ICD_FUNC(vkGetPhysicalDeviceSurfaceSupportKHR); \
ICD_FUNC(vkGetPhysicalDeviceSurfaceFormatsKHR); \
ICD_FUNC(vkGetPhysicalDeviceSurfaceCapabilitiesKHR); \
ICD_FUNC(vkGetPhysicalDeviceSurfacePresentModesKHR);
#define CHECK_DEV_FUNCS() \
ICD_FUNC(vkDestroyDevice); \
ICD_FUNC(vkGetDeviceQueue); \
ICD_FUNC(vkCreateFence); \
ICD_FUNC(vkDestroyFence); \
ICD_FUNC(vkCreateSemaphore); \
ICD_FUNC(vkDestroySemaphore); \
ICD_FUNC(vkCreateCommandPool); \
ICD_FUNC(vkDestroyCommandPool); \
ICD_FUNC(vkAllocateCommandBuffers); \
ICD_FUNC(vkFreeCommandBuffers); \
ICD_FUNC(vkBeginCommandBuffer); \
ICD_FUNC(vkEndCommandBuffer); \
ICD_FUNC(vkCreateSwapchainKHR); \
ICD_FUNC(vkDestroySwapchainKHR); \
ICD_FUNC(vkGetSwapchainImagesKHR); \
ICD_FUNC(vkAcquireNextImageKHR); \
ICD_FUNC(vkQueuePresentKHR); \
ICD_FUNC(vkCreateImageView); \
ICD_FUNC(vkDestroyImageView); \
ICD_FUNC(vkCreateImage); \
ICD_FUNC(vkDestroyImage); \
ICD_FUNC(vkCreateBuffer); \
ICD_FUNC(vkDestroyBuffer); \
ICD_FUNC(vkGetBufferMemoryRequirements); \
ICD_FUNC(vkGetImageMemoryRequirements); \
ICD_FUNC(vkBindBufferMemory); \
ICD_FUNC(vkBindImageMemory); \
ICD_FUNC(vkAllocateMemory); \
ICD_FUNC(vkFreeMemory); \
ICD_FUNC(vkMapMemory); \
ICD_FUNC(vkUnmapMemory); \
ICD_FUNC(vkFlushMappedMemoryRanges); \
ICD_FUNC(vkGetImageSubresourceLayout); \
ICD_FUNC(vkCreateSampler); \
ICD_FUNC(vkDestroySampler); \
ICD_FUNC(vkCreateDescriptorSetLayout); \
ICD_FUNC(vkDestroyDescriptorSetLayout); \
ICD_FUNC(vkCreatePipelineLayout); \
ICD_FUNC(vkDestroyPipelineLayout); \
ICD_FUNC(vkCreateFramebuffer); \
ICD_FUNC(vkDestroyFramebuffer); \
ICD_FUNC(vkCreateRenderPass); \
ICD_FUNC(vkDestroyRenderPass); \
ICD_FUNC(vkCreateShaderModule); \
ICD_FUNC(vkDestroyShaderModule); \
ICD_FUNC(vkCreatePipelineCache); \
ICD_FUNC(vkDestroyPipelineCache); \
ICD_FUNC(vkCreateGraphicsPipelines); \
ICD_FUNC(vkCreateComputePipelines); \
ICD_FUNC(vkDestroyPipeline); \
ICD_FUNC(vkCreateDescriptorPool); \
ICD_FUNC(vkDestroyDescriptorPool); \
ICD_FUNC(vkAllocateDescriptorSets); \
ICD_FUNC(vkFreeDescriptorSets); \
ICD_FUNC(vkUpdateDescriptorSets); \
ICD_FUNC(vkCmdPipelineBarrier); \
ICD_FUNC(vkCmdBeginRenderPass); \
ICD_FUNC(vkCmdEndRenderPass); \
ICD_FUNC(vkCmdBindIndexBuffer); \
ICD_FUNC(vkCmdBindVertexBuffers); \
ICD_FUNC(vkCmdBindPipeline); \
ICD_FUNC(vkCmdBindDescriptorSets); \
ICD_FUNC(vkCmdSetViewport); \
ICD_FUNC(vkCmdSetScissor); \
ICD_FUNC(vkCmdPushConstants); \
ICD_FUNC(vkCmdDraw); \
ICD_FUNC(vkCmdDrawIndexed); \
ICD_FUNC(vkCmdCopyBufferToImage); \
ICD_FUNC(vkCmdCopyBuffer); \
ICD_FUNC(vkQueueSubmit); \
ICD_FUNC(vkWaitForFences); \
ICD_FUNC(vkResetFences); \
ICD_FUNC(vkDeviceWaitIdle); \
ICD_FUNC(vkQueueWaitIdle);
VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t *pApiVersion)
{
if(pApiVersion)
{
*pApiVersion = VK_MAKE_VERSION(1, 0, 0);
return VK_SUCCESS;
}
return VK_ERROR_INITIALIZATION_FAILED;
}
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *pName)
{
CHECK_DEV_FUNCS();
// we want to return non-NULL for all entry points otherwise our ICD will be discarded. We've
// implemented all the functions needed for vkcube so if any other function gets called it will
// execute a string and we can see what function was missing.
return (PFN_vkVoidFunction)strdup(pName);
}
extern "C" {
#if defined(_WIN32)
#undef VKAPI_ATTR
#define VKAPI_ATTR __declspec(dllexport)
#endif
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance,
const char *pName)
{
CHECK_INST_FUNCS();
CHECK_PHYS_FUNCS();
CHECK_DEV_FUNCS();
if(!strcmp(pName, "vkCreateDebugReportCallbackEXT"))
return NULL;
if(!strcmp(pName, "vkCreateWin32SurfaceKHR"))
return NULL;
// we want to return non-NULL for all entry points otherwise our ICD will be discarded. We've
// implemented all the functions needed for vkcube so if any other function gets called it will
// execute a string and we can see what function was missing.
return (PFN_vkVoidFunction)strdup(pName);
}
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance instance,
const char *pName)
{
CHECK_PHYS_FUNCS();
// we want to return non-NULL for all entry points otherwise our ICD will be discarded. We've
// implemented all the functions needed for vkcube so if any other function gets called it will
// execute a string and we can see what function was missing.
return (PFN_vkVoidFunction)strdup(pName);
}
VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion)
{
if(!pSupportedVersion)
return VK_ERROR_INITIALIZATION_FAILED;
*pSupportedVersion = std::min<uint32_t>(CURRENT_LOADER_ICD_INTERFACE_VERSION, *pSupportedVersion);
return VK_SUCCESS;
}
}; // extern "C"