From edf5e2c14ed49f9fbd3cece1eafeb726a0ad267a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 14 Apr 2022 20:28:41 +1000 Subject: [PATCH] Vulkan/Context: Use static loading for vk_mem_alloc In doing so, we simplify things a bit, as we can assume Vulkan 1.1 support. It needed it before anyway, and would crash on Vulkan 1.0 drivers. --- common/Vulkan/Context.cpp | 64 ++++++++++++++++------------------- common/Vulkan/EntryPoints.h | 21 ++++++++++-- common/Vulkan/EntryPoints.inl | 13 +++++-- common/Vulkan/Loader.cpp | 4 +++ common/Vulkan/Loader.h | 3 ++ 5 files changed, 66 insertions(+), 39 deletions(-) diff --git a/common/Vulkan/Context.cpp b/common/Vulkan/Context.cpp index 08a033fc57..d269cbcca2 100644 --- a/common/Vulkan/Context.cpp +++ b/common/Vulkan/Context.cpp @@ -76,7 +76,7 @@ namespace Vulkan app_info.applicationVersion = VK_MAKE_VERSION(1, 7, 0); app_info.pEngineName = "PCSX2"; app_info.engineVersion = VK_MAKE_VERSION(1, 7, 0); - app_info.apiVersion = VK_MAKE_VERSION(1, 1, 0); + app_info.apiVersion = VK_API_VERSION_1_1; VkInstanceCreateInfo instance_create_info = {}; instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; @@ -641,43 +641,37 @@ namespace Vulkan void Context::ProcessDeviceExtensions() { // advanced feature checks - if (vkGetPhysicalDeviceFeatures2) + VkPhysicalDeviceFeatures2 features2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; + VkPhysicalDeviceProvokingVertexFeaturesEXT provoking_vertex_features = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT}; + VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesARM rasterization_order_access_feature = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_ARM}; + + // add in optional feature structs + if (m_optional_extensions.vk_ext_provoking_vertex) + Util::AddPointerToChain(&features2, &provoking_vertex_features); + if (m_optional_extensions.vk_arm_rasterization_order_attachment_access) + Util::AddPointerToChain(&features2, &rasterization_order_access_feature); + + // query + vkGetPhysicalDeviceFeatures2(m_physical_device, &features2); + + // confirm we actually support it + m_optional_extensions.vk_ext_provoking_vertex &= (provoking_vertex_features.provokingVertexLast == VK_TRUE); + m_optional_extensions.vk_arm_rasterization_order_attachment_access &= (rasterization_order_access_feature.rasterizationOrderColorAttachmentAccess == VK_TRUE); + + VkPhysicalDeviceProperties2 properties2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2}; + void** pNext = &properties2.pNext; + + if (m_optional_extensions.vk_khr_driver_properties) { - VkPhysicalDeviceFeatures2 features2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; - VkPhysicalDeviceProvokingVertexFeaturesEXT provoking_vertex_features = { - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT}; - VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesARM rasterization_order_access_feature = { - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_ARM}; - - // add in optional feature structs - if (m_optional_extensions.vk_ext_provoking_vertex) - Util::AddPointerToChain(&features2, &provoking_vertex_features); - if (m_optional_extensions.vk_arm_rasterization_order_attachment_access) - Util::AddPointerToChain(&features2, &rasterization_order_access_feature); - - // query - vkGetPhysicalDeviceFeatures2(m_physical_device, &features2); - - // confirm we actually support it - m_optional_extensions.vk_ext_provoking_vertex &= (provoking_vertex_features.provokingVertexLast == VK_TRUE); - m_optional_extensions.vk_arm_rasterization_order_attachment_access &= (rasterization_order_access_feature.rasterizationOrderColorAttachmentAccess == VK_TRUE); + m_device_driver_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES; + *pNext = &m_device_driver_properties; + pNext = &m_device_driver_properties.pNext; } - if (vkGetPhysicalDeviceProperties2) - { - VkPhysicalDeviceProperties2 properties2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2}; - void** pNext = &properties2.pNext; - - if (m_optional_extensions.vk_khr_driver_properties) - { - m_device_driver_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES; - *pNext = &m_device_driver_properties; - pNext = &m_device_driver_properties.pNext; - } - - // query - vkGetPhysicalDeviceProperties2(m_physical_device, &properties2); - } + // query + vkGetPhysicalDeviceProperties2(m_physical_device, &properties2); Console.WriteLn("VK_EXT_provoking_vertex is %s", m_optional_extensions.vk_ext_provoking_vertex ? "supported" : "NOT supported"); diff --git a/common/Vulkan/EntryPoints.h b/common/Vulkan/EntryPoints.h index 4be8ed877c..5bdc665068 100644 --- a/common/Vulkan/EntryPoints.h +++ b/common/Vulkan/EntryPoints.h @@ -15,6 +15,10 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + // We abuse the preprocessor here to only need to specify function names once. // Function names are prefixed so to not conflict with system symbols at runtime. #define VULKAN_MODULE_ENTRY_POINT(name, required) extern PFN_##name pcsx2_##name; @@ -27,6 +31,10 @@ #undef VULKAN_INSTANCE_ENTRY_POINT #undef VULKAN_MODULE_ENTRY_POINT +#ifdef __cplusplus +} +#endif + #define vkCreateInstance pcsx2_vkCreateInstance #define vkGetInstanceProcAddr pcsx2_vkGetInstanceProcAddr #define vkEnumerateInstanceExtensionProperties pcsx2_vkEnumerateInstanceExtensionProperties @@ -42,7 +50,6 @@ #define vkGetPhysicalDeviceProperties pcsx2_vkGetPhysicalDeviceProperties #define vkGetPhysicalDeviceQueueFamilyProperties pcsx2_vkGetPhysicalDeviceQueueFamilyProperties #define vkGetPhysicalDeviceMemoryProperties pcsx2_vkGetPhysicalDeviceMemoryProperties -#define vkGetPhysicalDeviceFeatures2 pcsx2_vkGetPhysicalDeviceFeatures2 #define vkCreateDevice pcsx2_vkCreateDevice #define vkEnumerateDeviceExtensionProperties pcsx2_vkEnumerateDeviceExtensionProperties #define vkEnumerateDeviceLayerProperties pcsx2_vkEnumerateDeviceLayerProperties @@ -74,7 +81,6 @@ #define vkSetDebugUtilsObjectTagEXT pcsx2_vkSetDebugUtilsObjectTagEXT #define vkSubmitDebugUtilsMessageEXT pcsx2_vkSubmitDebugUtilsMessageEXT -#define vkGetPhysicalDeviceProperties2 pcsx2_vkGetPhysicalDeviceProperties2 #define vkGetPhysicalDeviceSurfaceCapabilities2KHR pcsx2_vkGetPhysicalDeviceSurfaceCapabilities2KHR #define vkGetPhysicalDeviceDisplayPropertiesKHR pcsx2_vkGetPhysicalDeviceDisplayPropertiesKHR #define vkGetPhysicalDeviceDisplayPlanePropertiesKHR pcsx2_vkGetPhysicalDeviceDisplayPlanePropertiesKHR @@ -84,6 +90,11 @@ #define vkGetDisplayPlaneCapabilitiesKHR pcsx2_vkGetDisplayPlaneCapabilitiesKHR #define vkCreateDisplayPlaneSurfaceKHR pcsx2_vkCreateDisplayPlaneSurfaceKHR +// Vulkan 1.1 functions. +#define vkGetPhysicalDeviceFeatures2 pcsx2_vkGetPhysicalDeviceFeatures2 +#define vkGetPhysicalDeviceProperties2 pcsx2_vkGetPhysicalDeviceProperties2 +#define vkGetPhysicalDeviceMemoryProperties2 pcsx2_vkGetPhysicalDeviceMemoryProperties2 + #define vkDestroyDevice pcsx2_vkDestroyDevice #define vkGetDeviceQueue pcsx2_vkGetDeviceQueue #define vkQueueSubmit pcsx2_vkQueueSubmit @@ -210,6 +221,12 @@ #define vkAcquireNextImageKHR pcsx2_vkAcquireNextImageKHR #define vkQueuePresentKHR pcsx2_vkQueuePresentKHR +// Vulkan 1.1 functions. +#define vkGetBufferMemoryRequirements2 pcsx2_vkGetBufferMemoryRequirements2 +#define vkGetImageMemoryRequirements2 pcsx2_vkGetImageMemoryRequirements2 +#define vkBindBufferMemory2 pcsx2_vkBindBufferMemory2 +#define vkBindImageMemory2 pcsx2_vkBindImageMemory2 + #ifdef SUPPORTS_VULKAN_EXCLUSIVE_FULLSCREEN #define vkAcquireFullScreenExclusiveModeEXT pcsx2_vkAcquireFullScreenExclusiveModeEXT #define vkReleaseFullScreenExclusiveModeEXT pcsx2_vkReleaseFullScreenExclusiveModeEXT diff --git a/common/Vulkan/EntryPoints.inl b/common/Vulkan/EntryPoints.inl index 0ee6dfa86e..4e659ae7e9 100644 --- a/common/Vulkan/EntryPoints.inl +++ b/common/Vulkan/EntryPoints.inl @@ -40,7 +40,6 @@ VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceImageFormatProperties, true) VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceProperties, true) VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceQueueFamilyProperties, true) VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceMemoryProperties, true) -VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceFeatures2, false) VULKAN_INSTANCE_ENTRY_POINT(vkCreateDevice, true) VULKAN_INSTANCE_ENTRY_POINT(vkEnumerateDeviceExtensionProperties, true) VULKAN_INSTANCE_ENTRY_POINT(vkEnumerateDeviceLayerProperties, true) @@ -90,7 +89,6 @@ VULKAN_INSTANCE_ENTRY_POINT(vkSetDebugUtilsObjectNameEXT, false) VULKAN_INSTANCE_ENTRY_POINT(vkSetDebugUtilsObjectTagEXT, false) VULKAN_INSTANCE_ENTRY_POINT(vkSubmitDebugUtilsMessageEXT, false) -VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceProperties2, false) VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceSurfaceCapabilities2KHR, false) VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceDisplayPropertiesKHR, false) @@ -101,6 +99,11 @@ VULKAN_INSTANCE_ENTRY_POINT(vkCreateDisplayModeKHR, false) VULKAN_INSTANCE_ENTRY_POINT(vkGetDisplayPlaneCapabilitiesKHR, false) VULKAN_INSTANCE_ENTRY_POINT(vkCreateDisplayPlaneSurfaceKHR, false) +// Vulkan 1.1 functions. +VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceFeatures2, true) +VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceProperties2, true) +VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceMemoryProperties2, true) + #endif // VULKAN_INSTANCE_ENTRY_POINT #ifdef VULKAN_DEVICE_ENTRY_POINT @@ -231,6 +234,12 @@ VULKAN_DEVICE_ENTRY_POINT(vkGetSwapchainImagesKHR, false) VULKAN_DEVICE_ENTRY_POINT(vkAcquireNextImageKHR, false) VULKAN_DEVICE_ENTRY_POINT(vkQueuePresentKHR, false) +// Vulkan 1.1 functions. +VULKAN_DEVICE_ENTRY_POINT(vkGetBufferMemoryRequirements2, true) +VULKAN_DEVICE_ENTRY_POINT(vkGetImageMemoryRequirements2, true) +VULKAN_DEVICE_ENTRY_POINT(vkBindBufferMemory2, true) +VULKAN_DEVICE_ENTRY_POINT(vkBindImageMemory2, true) + #ifdef SUPPORTS_VULKAN_EXCLUSIVE_FULLSCREEN VULKAN_DEVICE_ENTRY_POINT(vkAcquireFullScreenExclusiveModeEXT, false) VULKAN_DEVICE_ENTRY_POINT(vkReleaseFullScreenExclusiveModeEXT, false) diff --git a/common/Vulkan/Loader.cpp b/common/Vulkan/Loader.cpp index 91930f628a..f52d32f9ed 100644 --- a/common/Vulkan/Loader.cpp +++ b/common/Vulkan/Loader.cpp @@ -30,6 +30,8 @@ #include #endif +extern "C" { + #define VULKAN_MODULE_ENTRY_POINT(name, required) PFN_##name pcsx2_##name; #define VULKAN_INSTANCE_ENTRY_POINT(name, required) PFN_##name pcsx2_##name; #define VULKAN_DEVICE_ENTRY_POINT(name, required) PFN_##name pcsx2_##name; @@ -38,6 +40,8 @@ #undef VULKAN_INSTANCE_ENTRY_POINT #undef VULKAN_MODULE_ENTRY_POINT +} + namespace Vulkan { void ResetVulkanLibraryFunctionPointers() diff --git a/common/Vulkan/Loader.h b/common/Vulkan/Loader.h index 9e65277ac9..c767dc0348 100644 --- a/common/Vulkan/Loader.h +++ b/common/Vulkan/Loader.h @@ -101,6 +101,9 @@ #pragma clang diagnostic ignored "-Wnullability-completeness" #endif +#define VMA_STATIC_VULKAN_FUNCTIONS 1 +#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0 +#define VMA_STATS_STRING_ENABLED 0 #include "vk_mem_alloc.h" #ifdef __clang__