#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