summaryrefslogtreecommitdiffstats
path: root/source/render/render_vk_loader.h
blob: af5a8e34abf54f34b681da73727bc8098f1346aa (plain) (blame)
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
#ifndef RENDER_VK_LOADER_H
#define RENDER_VK_LOADER_H

// NOTE: vulkan is loaded at runtime, never linked. the binary then starts on any machine and can
// say "no vulkan driver" itself instead of the os refusing to launch it over a missing
// vulkan-1.dll / libvulkan.so.1. on macos MoltenVK is linked statically (VK_STATIC_MOLTENVK, the
// single executable) or found as a dylib (the loader from the vulkan sdk, or MoltenVK itself).
//
// every function the renderer calls is a global pointer with the real name, so render_vulkan.cpp
// reads exactly like it did with prototypes. the 1.3 entry points fall back to their KHR
// extension twins, MoltenVK and older drivers expose dynamic rendering / sync2 that way.

#define VK_GLOBAL_FUNCTIONS(X)                     \
	X(vkCreateInstance)                            \
	X(vkEnumerateInstanceLayerProperties)          \
	X(vkEnumerateInstanceExtensionProperties)

#define VK_INSTANCE_FUNCTIONS(X)                   \
	X(vkDestroyInstance)                           \
	X(vkEnumeratePhysicalDevices)                  \
	X(vkGetPhysicalDeviceProperties)               \
	X(vkGetPhysicalDeviceQueueFamilyProperties)    \
	X(vkGetPhysicalDeviceMemoryProperties)         \
	X(vkEnumerateDeviceExtensionProperties)        \
	X(vkCreateDevice)                              \
	X(vkGetDeviceProcAddr)                         \
	X(vkDestroySurfaceKHR)                         \
	X(vkGetPhysicalDeviceSurfaceSupportKHR)        \
	X(vkGetPhysicalDeviceSurfaceCapabilitiesKHR)   \
	X(vkGetPhysicalDeviceSurfaceFormatsKHR)        \
	X(vkGetPhysicalDeviceSurfacePresentModesKHR)

// NOTE: may be missing, depends on the platform and the driver
#define VK_INSTANCE_OPTIONAL_FUNCTIONS(X)          \
	X(vkCreateDebugUtilsMessengerEXT)              \
	X(vkDestroyDebugUtilsMessengerEXT)             \
	VK_SURFACE_FUNCTIONS(X)

#if PLATFORM_LINUX
#define VK_SURFACE_FUNCTIONS(X) X(vkCreateWaylandSurfaceKHR) X(vkCreateXlibSurfaceKHR)
#elif PLATFORM_WINDOWS
#define VK_SURFACE_FUNCTIONS(X) X(vkCreateWin32SurfaceKHR)
#elif PLATFORM_APPLE
#define VK_SURFACE_FUNCTIONS(X) X(vkCreateMetalSurfaceEXT)
#endif

#define VK_DEVICE_FUNCTIONS(X)                     \
	X(vkDestroyDevice)                             \
	X(vkGetDeviceQueue)                            \
	X(vkDeviceWaitIdle)                            \
	X(vkQueueWaitIdle)                             \
	X(vkCreateSwapchainKHR)                        \
	X(vkDestroySwapchainKHR)                       \
	X(vkGetSwapchainImagesKHR)                     \
	X(vkAcquireNextImageKHR)                       \
	X(vkQueuePresentKHR)                           \
	X(vkCreateBuffer)                              \
	X(vkDestroyBuffer)                             \
	X(vkCreateImage)                               \
	X(vkDestroyImage)                              \
	X(vkCreateImageView)                           \
	X(vkDestroyImageView)                          \
	X(vkCreateSampler)                             \
	X(vkDestroySampler)                            \
	X(vkAllocateMemory)                            \
	X(vkFreeMemory)                                \
	X(vkMapMemory)                                 \
	X(vkBindBufferMemory)                          \
	X(vkBindImageMemory)                           \
	X(vkGetBufferMemoryRequirements)               \
	X(vkGetImageMemoryRequirements)                \
	X(vkCreateCommandPool)                         \
	X(vkDestroyCommandPool)                        \
	X(vkAllocateCommandBuffers)                    \
	X(vkResetCommandBuffer)                        \
	X(vkBeginCommandBuffer)                        \
	X(vkEndCommandBuffer)                          \
	X(vkCreateFence)                               \
	X(vkDestroyFence)                              \
	X(vkWaitForFences)                             \
	X(vkResetFences)                               \
	X(vkCreateSemaphore)                           \
	X(vkDestroySemaphore)                          \
	X(vkCreateDescriptorSetLayout)                 \
	X(vkDestroyDescriptorSetLayout)                \
	X(vkCreateDescriptorPool)                      \
	X(vkDestroyDescriptorPool)                     \
	X(vkAllocateDescriptorSets)                    \
	X(vkUpdateDescriptorSets)                      \
	X(vkCreatePipelineLayout)                      \
	X(vkDestroyPipelineLayout)                     \
	X(vkCreateShaderModule)                        \
	X(vkDestroyShaderModule)                       \
	X(vkCreateGraphicsPipelines)                   \
	X(vkDestroyPipeline)                           \
	X(vkCmdBindPipeline)                           \
	X(vkCmdBindDescriptorSets)                     \
	X(vkCmdBindVertexBuffers)                      \
	X(vkCmdPushConstants)                          \
	X(vkCmdSetViewport)                            \
	X(vkCmdSetScissor)                             \
	X(vkCmdDraw)                                   \
	X(vkCmdCopyBufferToImage)                      \
	X(vkCmdCopyImageToBuffer)

// NOTE: core in 1.3, VK_KHR_dynamic_rendering / VK_KHR_synchronization2 before that
#define VK_DEVICE_KHR_FALLBACK_FUNCTIONS(X)        \
	X(vkCmdBeginRendering)                         \
	X(vkCmdEndRendering)                           \
	X(vkCmdPipelineBarrier2)                       \
	X(vkQueueSubmit2)

#define VK_DECLARE_FUNCTION(name) global_variable PFN_##name name;
VK_DECLARE_FUNCTION(vkGetInstanceProcAddr)
VK_GLOBAL_FUNCTIONS(VK_DECLARE_FUNCTION)
VK_INSTANCE_FUNCTIONS(VK_DECLARE_FUNCTION)
VK_INSTANCE_OPTIONAL_FUNCTIONS(VK_DECLARE_FUNCTION)
VK_DEVICE_FUNCTIONS(VK_DECLARE_FUNCTION)
VK_DEVICE_KHR_FALLBACK_FUNCTIONS(VK_DECLARE_FUNCTION)
#undef VK_DECLARE_FUNCTION

// NOTE: why vulkan couldn't start, for the error dialog. static storage, always terminated.
global_variable char vk_loader_error[512];

internal b32 vk_load_library(void);          // vkGetInstanceProcAddr + the global functions
internal b32 vk_load_instance(VkInstance instance);
internal b32 vk_load_device(VkDevice device);

#endif // RENDER_VK_LOADER_H