3 #include <unordered_map> 9 #if defined(LUG_SYSTEM_WINDOWS) 10 #define VK_USE_PLATFORM_WIN32_KHR 11 #elif defined(LUG_SYSTEM_LINUX) 12 #define VK_USE_PLATFORM_XLIB_KHR 13 #elif defined(LUG_SYSTEM_ANDROID) 14 #define VK_USE_PLATFORM_ANDROID_KHR 17 #define VK_NO_PROTOTYPES 18 #ifndef WIN32_LEAN_AND_MEAN 19 #define WIN32_LEAN_AND_MEAN 22 #include <vulkan/vulkan.h> 24 #if defined(LUG_SYSTEM_LINUX) 29 #define LUG_EXPORTED_VULKAN_FUNCTIONS(macro) \ 30 macro(vkGetInstanceProcAddr) 32 #define LUG_CORE_VULKAN_FUNCTIONS(macro) \ 33 macro(vkEnumerateInstanceExtensionProperties) \ 34 macro(vkEnumerateInstanceLayerProperties) \ 35 macro(vkCreateInstance) 37 #if defined(LUG_SYSTEM_WINDOWS) 38 #define LUG_VK_KHR_PLATFORM_SURFACE_EXTENSION_NAME VK_KHR_WIN32_SURFACE_EXTENSION_NAME 39 #define LUG_INSTANCE_VULKAN_FUNCTIONS_PLATFORM(macro) \ 40 macro(vkCreateWin32SurfaceKHR) // VK_KHR_win32_surface 41 #elif defined(LUG_SYSTEM_LINUX) 42 #define LUG_VK_KHR_PLATFORM_SURFACE_EXTENSION_NAME VK_KHR_XLIB_SURFACE_EXTENSION_NAME 43 #define LUG_INSTANCE_VULKAN_FUNCTIONS_PLATFORM(macro) \ 44 macro(vkCreateXlibSurfaceKHR) // VK_KHR_xlib_surface 45 #elif defined(LUG_SYSTEM_ANDROID) 46 #define LUG_VK_KHR_PLATFORM_SURFACE_EXTENSION_NAME VK_KHR_ANDROID_SURFACE_EXTENSION_NAME 47 #define LUG_INSTANCE_VULKAN_FUNCTIONS_PLATFORM(macro) \ 48 macro(vkCreateAndroidSurfaceKHR) // VK_KHR_android_surface 52 #define LUG_INSTANCE_VULKAN_FUNCTIONS_KHR_SURFACE(macro) \ 53 macro(vkGetPhysicalDeviceSurfaceSupportKHR) \ 54 macro(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) \ 55 macro(vkGetPhysicalDeviceSurfaceFormatsKHR) \ 56 macro(vkGetPhysicalDeviceSurfacePresentModesKHR) \ 57 macro(vkDestroySurfaceKHR) 59 #define LUG_INSTANCE_VULKAN_FUNCTIONS(macro) \ 60 macro(vkEnumeratePhysicalDevices) \ 61 macro(vkGetPhysicalDeviceProperties) \ 62 macro(vkGetPhysicalDeviceFeatures) \ 63 macro(vkGetPhysicalDeviceQueueFamilyProperties) \ 64 macro(vkGetPhysicalDeviceFormatProperties) \ 65 macro(vkGetDeviceProcAddr) \ 66 macro(vkCreateDevice) \ 67 macro(vkDestroyInstance) \ 68 macro(vkEnumerateDeviceExtensionProperties) \ 69 macro(vkGetPhysicalDeviceMemoryProperties) \ 70 LUG_INSTANCE_VULKAN_FUNCTIONS_PLATFORM(macro) \ 71 LUG_INSTANCE_VULKAN_FUNCTIONS_KHR_SURFACE(macro) 73 #define LUG_DEVICE_VULKAN_FUNCTIONS_KHR_SWAPCHAIN(macro) \ 74 macro(vkCreateSwapchainKHR) \ 75 macro(vkGetSwapchainImagesKHR) \ 76 macro(vkAcquireNextImageKHR) \ 77 macro(vkQueuePresentKHR) \ 78 macro(vkDestroySwapchainKHR) \ 80 #define LUG_DEVICE_VULKAN_FUNCTIONS(macro) \ 81 macro(vkQueueWaitIdle) \ 82 macro(vkGetDeviceQueue) \ 83 macro(vkDeviceWaitIdle) \ 84 macro(vkDestroyDevice) \ 85 macro(vkCreateSemaphore) \ 86 macro(vkCreateCommandPool) \ 87 macro(vkAllocateCommandBuffers) \ 88 macro(vkBeginCommandBuffer) \ 89 macro(vkCmdPipelineBarrier) \ 90 macro(vkCmdClearColorImage) \ 91 macro(vkEndCommandBuffer) \ 92 macro(vkResetCommandBuffer) \ 93 macro(vkQueueSubmit) \ 94 macro(vkFreeCommandBuffers) \ 95 macro(vkResetCommandPool) \ 96 macro(vkDestroyCommandPool) \ 97 macro(vkDestroySemaphore) \ 98 macro(vkCreateImageView) \ 99 macro(vkCreateRenderPass) \ 100 macro(vkCreateFramebuffer) \ 101 macro(vkCreateShaderModule) \ 102 macro(vkCreatePipelineLayout) \ 103 macro(vkCreateGraphicsPipelines) \ 104 macro(vkCmdBeginRenderPass) \ 105 macro(vkCmdBindPipeline) \ 107 macro(vkCmdDrawIndexed) \ 108 macro(vkCmdEndRenderPass) \ 109 macro(vkDestroyShaderModule) \ 110 macro(vkDestroyPipelineLayout) \ 111 macro(vkDestroyPipeline) \ 112 macro(vkDestroyRenderPass) \ 113 macro(vkDestroyFramebuffer) \ 114 macro(vkDestroyImageView) \ 115 macro(vkCreateFence) \ 116 macro(vkCreateBuffer) \ 117 macro(vkGetBufferMemoryRequirements) \ 118 macro(vkAllocateMemory) \ 119 macro(vkBindBufferMemory) \ 121 macro(vkFlushMappedMemoryRanges) \ 122 macro(vkUnmapMemory) \ 123 macro(vkCmdSetViewport) \ 124 macro(vkCmdSetScissor) \ 125 macro(vkCmdSetBlendConstants) \ 126 macro(vkCmdBindVertexBuffers) \ 127 macro(vkCmdBindIndexBuffer) \ 128 macro(vkWaitForFences) \ 129 macro(vkResetFences) \ 130 macro(vkGetFenceStatus) \ 131 macro(vkFreeMemory) \ 132 macro(vkDestroyBuffer) \ 133 macro(vkDestroyFence) \ 134 macro(vkCmdCopyBuffer) \ 135 macro(vkCreateImage) \ 136 macro(vkGetImageMemoryRequirements) \ 137 macro(vkBindImageMemory) \ 138 macro(vkCreateSampler) \ 139 macro(vkCmdCopyImage) \ 140 macro(vkCmdCopyBufferToImage) \ 141 macro(vkCreateDescriptorSetLayout) \ 142 macro(vkCreateDescriptorPool) \ 143 macro(vkAllocateDescriptorSets) \ 144 macro(vkUpdateDescriptorSets) \ 145 macro(vkFreeDescriptorSets) \ 146 macro(vkCmdUpdateBuffer) \ 147 macro(vkCmdBindDescriptorSets) \ 148 macro(vkDestroyDescriptorPool) \ 149 macro(vkDestroyDescriptorSetLayout) \ 150 macro(vkDestroySampler) \ 151 macro(vkDestroyImage) \ 152 macro(vkCmdPushConstants) \ 153 LUG_DEVICE_VULKAN_FUNCTIONS_KHR_SWAPCHAIN(macro) 157 #define LUG_DEFINE_DECLARATION_VULKAN_FUNCTIONS(name) extern PFN_##name LUG_GRAPHICS_API name; 162 #undef LUG_DEFINE_DECLARATION__VULKAN_FUNCTIONS 174 bool containsExtension(
const char* extensionName)
const;
175 bool containsLayer(
const char* layerName)
const;
199 bool containsExtension(
const char* extensionName)
const;
200 bool containsQueueFlags(VkQueueFlags queueFlags, int8_t& idx)
const;
210 inline std::ostream&
operator<<(std::ostream& ss, VkResult result) {
216 ss <<
"A fence or query has not yet completed";
219 ss <<
"A wait operation has not completed in the specified time";
222 ss <<
"An event is signaled";
225 ss <<
"An event is unsignaled";
228 ss <<
"A return array was too small for the result";
230 case VK_ERROR_OUT_OF_HOST_MEMORY:
231 ss <<
"A host memory allocation has failed";
233 case VK_ERROR_OUT_OF_DEVICE_MEMORY:
234 ss <<
"A device memory allocation has failed";
236 case VK_ERROR_INITIALIZATION_FAILED:
237 ss <<
"Initialization of an object could not be completed for implementation-specific reasons";
239 case VK_ERROR_DEVICE_LOST:
240 ss <<
"The logical or physical device has been lost";
242 case VK_ERROR_MEMORY_MAP_FAILED:
243 ss <<
"Mapping of a memory object has failed";
245 case VK_ERROR_LAYER_NOT_PRESENT:
246 ss <<
"A requested layer is not present or could not be loaded";
248 case VK_ERROR_EXTENSION_NOT_PRESENT:
249 ss <<
"A requested extension is not supported";
251 case VK_ERROR_FEATURE_NOT_PRESENT:
252 ss <<
"A requested feature is not supported";
254 case VK_ERROR_INCOMPATIBLE_DRIVER:
255 ss <<
"The requested version of Vulkan is not supported by the driver or is otherwise incompatible";
257 case VK_ERROR_TOO_MANY_OBJECTS:
258 ss <<
"Too many objects of the type have already been created";
260 case VK_ERROR_FORMAT_NOT_SUPPORTED:
261 ss <<
"A requested format is not supported on this device";
263 case VK_ERROR_SURFACE_LOST_KHR:
264 ss <<
"A surface is no longer available";
266 case VK_SUBOPTIMAL_KHR:
267 ss <<
"A swapchain no longer matches the surface properties exactly, but can still be used";
269 case VK_ERROR_OUT_OF_DATE_KHR:
270 ss <<
"A surface has changed in such a way that it is no longer compatible with the swapchain";
272 case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
273 ss <<
"The display used by a swapchain does not use the same presentable image layout";
275 case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
276 ss <<
"The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API";
278 case VK_ERROR_VALIDATION_FAILED_EXT:
279 ss <<
"A validation layer found an error";
282 ss <<
"ERROR: UNKNOWN VULKAN ERROR";
VkPhysicalDeviceMemoryProperties memoryProperties
std::vector< VkQueueFamilyProperties > queueFamilies
VkSurfaceCapabilitiesKHR capabilities
VkPhysicalDeviceFeatures features
std::vector< VkExtensionProperties > extensions
std::vector< VkPresentModeKHR > presentModes
std::vector< VkSurfaceFormatKHR > formats
#define LUG_DEFINE_DECLARATION_VULKAN_FUNCTIONS(name)
LUG_DEVICE_VULKAN_FUNCTIONS(LUG_DEFINE_DECLARATION_VULKAN_FUNCTIONS)
std::vector< VkExtensionProperties > extensions
LUG_CORE_VULKAN_FUNCTIONS(LUG_DEFINE_DECLARATION_VULKAN_FUNCTIONS)
std::unordered_map< VkFormat, VkFormatProperties > formatProperties
std::ostream & operator<<(std::ostream &ss, VkResult result)
LUG_INSTANCE_VULKAN_FUNCTIONS(LUG_DEFINE_DECLARATION_VULKAN_FUNCTIONS)
VkPhysicalDeviceProperties properties
std::vector< VkLayerProperties > layers
LUG_EXPORTED_VULKAN_FUNCTIONS(LUG_DEFINE_DECLARATION_VULKAN_FUNCTIONS)