VulkanRenderer: Fix VK_EXT_debug_utils with MoltenVK

This commit is contained in:
Jérôme Leclercq 2022-03-20 14:54:38 +01:00
parent 48b87cc99b
commit d86f61cd82
6 changed files with 42 additions and 33 deletions

View File

@ -58,6 +58,7 @@ namespace Nz
inline VmaAllocator GetMemoryAllocator() const; inline VmaAllocator GetMemoryAllocator() const;
inline VkPhysicalDevice GetPhysicalDevice() const; inline VkPhysicalDevice GetPhysicalDevice() const;
inline const Vk::PhysicalDevice& GetPhysicalDeviceInfo() const; inline const Vk::PhysicalDevice& GetPhysicalDeviceInfo() const;
inline PFN_vkVoidFunction GetProcAddr(const char* name, bool allowInstanceFallback);
QueueHandle GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex); QueueHandle GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex);
inline bool IsExtensionLoaded(const std::string& extensionName); inline bool IsExtensionLoaded(const std::string& extensionName);
@ -98,8 +99,6 @@ namespace Nz
void ResetPointers(); void ResetPointers();
void WaitAndDestroyDevice(); void WaitAndDestroyDevice();
inline PFN_vkVoidFunction GetProcAddr(const char* name);
struct InternalData; struct InternalData;
static constexpr std::size_t QueueCount = static_cast<std::size_t>(QueueType::Max) + 1; static constexpr std::size_t QueueCount = static_cast<std::size_t>(QueueType::Max) + 1;

View File

@ -57,6 +57,20 @@ namespace Nz::Vk
return *m_physicalDevice; return *m_physicalDevice;
} }
inline PFN_vkVoidFunction Device::GetProcAddr(const char* name, bool allowInstanceFallback)
{
PFN_vkVoidFunction func = m_instance.GetDeviceProcAddr(m_device, name);
if (!func)
{
if (allowInstanceFallback)
return m_instance.GetProcAddr(name);
NazaraError("Failed to get " + std::string(name) + " address");
}
return func;
}
inline bool Device::IsExtensionLoaded(const std::string& extensionName) inline bool Device::IsExtensionLoaded(const std::string& extensionName)
{ {
return m_loadedExtensions.count(extensionName) > 0; return m_loadedExtensions.count(extensionName) > 0;
@ -83,15 +97,6 @@ namespace Nz::Vk
{ {
return m_device; return m_device;
} }
inline PFN_vkVoidFunction Device::GetProcAddr(const char* name)
{
PFN_vkVoidFunction func = m_instance.GetDeviceProcAddr(m_device, name);
if (!func)
NazaraError("Failed to get " + std::string(name) + " address");
return func;
}
} }
#include <Nazara/VulkanRenderer/DebugOff.hpp> #include <Nazara/VulkanRenderer/DebugOff.hpp>

View File

@ -16,6 +16,10 @@
#define NAZARA_VULKANRENDERER_DEVICE_EXT_END() #define NAZARA_VULKANRENDERER_DEVICE_EXT_END()
#endif #endif
#ifndef NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION
#define NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION(func) NAZARA_VULKANRENDERER_DEVICE_FUNCTION(func)
#endif
#ifndef NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN #ifndef NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN
#define NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN(ext) #define NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN(ext)
#endif #endif
@ -168,19 +172,20 @@ NAZARA_VULKANRENDERER_DEVICE_EXT_BEGIN(VK_KHR_swapchain)
NAZARA_VULKANRENDERER_DEVICE_EXT_END() NAZARA_VULKANRENDERER_DEVICE_EXT_END()
NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN(VK_EXT_debug_utils) NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN(VK_EXT_debug_utils)
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBeginDebugUtilsLabelEXT) NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION(vkCmdBeginDebugUtilsLabelEXT)
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdEndDebugUtilsLabelEXT) NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION(vkCmdEndDebugUtilsLabelEXT)
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdInsertDebugUtilsLabelEXT) NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION(vkCmdInsertDebugUtilsLabelEXT)
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkQueueBeginDebugUtilsLabelEXT) NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION(vkQueueBeginDebugUtilsLabelEXT)
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkQueueEndDebugUtilsLabelEXT) NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION(vkQueueEndDebugUtilsLabelEXT)
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkQueueInsertDebugUtilsLabelEXT) NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION(vkQueueInsertDebugUtilsLabelEXT)
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkSetDebugUtilsObjectNameEXT) NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION(vkSetDebugUtilsObjectNameEXT)
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkSetDebugUtilsObjectTagEXT) NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION(vkSetDebugUtilsObjectTagEXT)
NAZARA_VULKANRENDERER_INSTANCE_EXT_END() NAZARA_VULKANRENDERER_INSTANCE_EXT_END()
#undef NAZARA_VULKANRENDERER_DEVICE_CORE_EXT_FUNCTION #undef NAZARA_VULKANRENDERER_DEVICE_CORE_EXT_FUNCTION
#undef NAZARA_VULKANRENDERER_DEVICE_EXT_BEGIN #undef NAZARA_VULKANRENDERER_DEVICE_EXT_BEGIN
#undef NAZARA_VULKANRENDERER_DEVICE_EXT_END #undef NAZARA_VULKANRENDERER_DEVICE_EXT_END
#undef NAZARA_VULKANRENDERER_DEVICE_FUNCTION #undef NAZARA_VULKANRENDERER_DEVICE_FUNCTION
#undef NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION
#undef NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN #undef NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN
#undef NAZARA_VULKANRENDERER_INSTANCE_EXT_END #undef NAZARA_VULKANRENDERER_INSTANCE_EXT_END

View File

@ -73,6 +73,7 @@ namespace Nz
inline VkPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device) const; inline VkPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device) const;
inline VkPhysicalDeviceProperties GetPhysicalDeviceProperties(VkPhysicalDevice device) const; inline VkPhysicalDeviceProperties GetPhysicalDeviceProperties(VkPhysicalDevice device) const;
bool GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector<VkQueueFamilyProperties>* queueFamilyProperties) const; bool GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector<VkQueueFamilyProperties>* queueFamilyProperties) const;
inline PFN_vkVoidFunction GetProcAddr(const char* name) const;
void InstallDebugMessageCallback(); void InstallDebugMessageCallback();
@ -95,8 +96,6 @@ namespace Nz
void DestroyInstance(); void DestroyInstance();
void ResetPointers(); void ResetPointers();
inline PFN_vkVoidFunction GetProcAddr(const char* name) const;
struct InternalData; struct InternalData;
std::unique_ptr<InternalData> m_internalData; std::unique_ptr<InternalData> m_internalData;

View File

@ -68,6 +68,15 @@ namespace Nz
return m_lastErrorCode; return m_lastErrorCode;
} }
inline PFN_vkVoidFunction Instance::GetProcAddr(const char* name) const
{
PFN_vkVoidFunction func = Loader::GetInstanceProcAddr(m_instance, name);
if (!func)
NazaraError("Failed to get " + std::string(name) + " address");
return func;
}
inline bool Instance::IsExtensionLoaded(const std::string& extensionName) const inline bool Instance::IsExtensionLoaded(const std::string& extensionName) const
{ {
return m_loadedExtensions.count(extensionName) > 0; return m_loadedExtensions.count(extensionName) > 0;
@ -131,15 +140,6 @@ namespace Nz
return properties; return properties;
} }
inline PFN_vkVoidFunction Instance::GetProcAddr(const char* name) const
{
PFN_vkVoidFunction func = Loader::GetInstanceProcAddr(m_instance, name);
if (!func)
NazaraError("Failed to get " + std::string(name) + " address");
return func;
}
} }
} }

View File

@ -88,16 +88,17 @@ namespace Nz
#define NAZARA_VULKANRENDERER_DEVICE_EXT_BEGIN(ext) if (IsExtensionLoaded(#ext)) { #define NAZARA_VULKANRENDERER_DEVICE_EXT_BEGIN(ext) if (IsExtensionLoaded(#ext)) {
#define NAZARA_VULKANRENDERER_DEVICE_EXT_END() } #define NAZARA_VULKANRENDERER_DEVICE_EXT_END() }
#define NAZARA_VULKANRENDERER_DEVICE_FUNCTION(func) func = reinterpret_cast<PFN_##func>(GetProcAddr(#func)); #define NAZARA_VULKANRENDERER_DEVICE_FUNCTION(func) func = reinterpret_cast<PFN_##func>(GetProcAddr(#func, false));
#define NAZARA_VULKANRENDERER_DEVICE_OR_INSTANCE_FUNCTION(func) func = reinterpret_cast<PFN_##func>(GetProcAddr(#func, true));
#define NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN(ext) if (m_instance.IsExtensionLoaded(#ext)) { #define NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN(ext) if (m_instance.IsExtensionLoaded(#ext)) {
#define NAZARA_VULKANRENDERER_INSTANCE_EXT_END() } #define NAZARA_VULKANRENDERER_INSTANCE_EXT_END() }
#define NAZARA_VULKANRENDERER_DEVICE_CORE_EXT_FUNCTION(func, coreVersion, suffix, extName) \ #define NAZARA_VULKANRENDERER_DEVICE_CORE_EXT_FUNCTION(func, coreVersion, suffix, extName) \
if (deviceVersion >= coreVersion) \ if (deviceVersion >= coreVersion) \
func = reinterpret_cast<PFN_##func>(GetProcAddr(#func)); \ func = reinterpret_cast<PFN_##func>(GetProcAddr(#func, false)); \
else if (IsExtensionLoaded("VK_" #suffix "_" #extName)) \ else if (IsExtensionLoaded("VK_" #suffix "_" #extName)) \
func = reinterpret_cast<PFN_##func##suffix>(GetProcAddr(#func #suffix)); func = reinterpret_cast<PFN_##func##suffix>(GetProcAddr(#func #suffix, false));
#include <Nazara/VulkanRenderer/Wrapper/DeviceFunctions.hpp> #include <Nazara/VulkanRenderer/Wrapper/DeviceFunctions.hpp>
} }