diff --git a/Source/Engine/GraphicsDevice/Vulkan/Config.h b/Source/Engine/GraphicsDevice/Vulkan/Config.h index ade8d96be..71245070b 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/Config.h +++ b/Source/Engine/GraphicsDevice/Vulkan/Config.h @@ -18,7 +18,7 @@ #ifndef VULKAN_BACK_BUFFERS_COUNT #define VULKAN_BACK_BUFFERS_COUNT 2 #endif -#define VULKAN_BACK_BUFFERS_COUNT_MAX 16 +#define VULKAN_BACK_BUFFERS_COUNT_MAX 4 /// /// Default amount of frames to wait until resource delete. @@ -34,8 +34,5 @@ #ifndef VULKAN_USE_QUERIES #define VULKAN_USE_QUERIES 1 #endif -#ifndef VULKAN_HAS_PHYSICAL_DEVICE_PROPERTIES2 -#define VULKAN_HAS_PHYSICAL_DEVICE_PROPERTIES2 0 -#endif #endif diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp index a69187f6f..9cd6f6b47 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.Layers.cpp @@ -575,25 +575,15 @@ void GPUDeviceVulkan::GetDeviceExtensionsAndLayers(VkPhysicalDevice gpu, Array& deviceExtensions) { Platform::MemoryClear(&OptionalDeviceExtensions, sizeof(OptionalDeviceExtensions)); - - const auto HasExtension = [&deviceExtensions](const char* name) -> bool - { - const Function CheckCallback = [&name](const char* const& extension) -> bool - { - return StringUtils::Compare(extension, name) == 0; - }; - return ArrayExtensions::Any(deviceExtensions, CheckCallback); - }; - #if VK_KHR_maintenance1 - OptionalDeviceExtensions.HasKHRMaintenance1 = HasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME); + OptionalDeviceExtensions.HasKHRMaintenance1 = RenderToolsVulkan::HasExtension(deviceExtensions, VK_KHR_MAINTENANCE1_EXTENSION_NAME); #endif #if VK_KHR_maintenance2 - OptionalDeviceExtensions.HasKHRMaintenance2 = HasExtension(VK_KHR_MAINTENANCE2_EXTENSION_NAME); + OptionalDeviceExtensions.HasKHRMaintenance2 = RenderToolsVulkan::HasExtension(deviceExtensions, VK_KHR_MAINTENANCE2_EXTENSION_NAME); #endif - OptionalDeviceExtensions.HasMirrorClampToEdge = HasExtension(VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME); + OptionalDeviceExtensions.HasMirrorClampToEdge = RenderToolsVulkan::HasExtension(deviceExtensions, VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME); #if VK_EXT_validation_cache - OptionalDeviceExtensions.HasEXTValidationCache = HasExtension(VK_EXT_VALIDATION_CACHE_EXTENSION_NAME); + OptionalDeviceExtensions.HasEXTValidationCache = RenderToolsVulkan::HasExtension(deviceExtensions, VK_EXT_VALIDATION_CACHE_EXTENSION_NAME); #endif } diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp index a6a412ce2..826efbd6c 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp @@ -998,11 +998,10 @@ void StagingManagerVulkan::ProcessPendingFree() } // Free staging buffers that has not been used for a few frames - const uint64 SafeFramesCount = 30; for (int32 i = _freeBuffers.Count() - 1; i >= 0; i--) { - auto& e = _freeBuffers[i]; - if (e.FrameNumber + SafeFramesCount < Engine::FrameCount) + auto& e = _freeBuffers.Get()[i]; + if (e.FrameNumber + VULKAN_RESOURCE_DELETE_SAFE_FRAMES_COUNT < Engine::FrameCount) { auto buffer = e.Buffer; @@ -1027,7 +1026,7 @@ void StagingManagerVulkan::Dispose() { ScopeLock lock(_locker); -#if !BUILD_RELEASE +#if BUILD_DEBUG LOG(Info, "Vulkan staging buffers peek memory usage: {0}, allocs: {1}, frees: {2}", Utilities::BytesToText(_allBuffersPeekSize), Utilities::BytesToText(_allBuffersAllocSize), Utilities::BytesToText(_allBuffersFreeSize)); #endif @@ -1078,7 +1077,7 @@ GPUDevice* GPUDeviceVulkan::Create() #endif // Engine registration - const StringAsANSI<256> appName(*Globals::ProductName); + const StringAsANSI<> appName(*Globals::ProductName); VkApplicationInfo appInfo; RenderToolsVulkan::ZeroStruct(appInfo, VK_STRUCTURE_TYPE_APPLICATION_INFO); appInfo.pApplicationName = appName.Get(); @@ -1093,24 +1092,13 @@ GPUDevice* GPUDeviceVulkan::Create() instInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; #endif instInfo.pApplicationInfo = &appInfo; - GetInstanceLayersAndExtensions(InstanceExtensions, InstanceLayers, SupportsDebugUtilsExt); - - const auto hasExtension = [](const Array& extensions, const char* name) -> bool - { - const Function callback = [&name](const char* const& extension) -> bool - { - return extension && StringUtils::Compare(extension, name) == 0; - }; - return ArrayExtensions::Any(extensions, callback); - }; - instInfo.enabledExtensionCount = InstanceExtensions.Count(); instInfo.ppEnabledExtensionNames = instInfo.enabledExtensionCount > 0 ? static_cast(InstanceExtensions.Get()) : nullptr; instInfo.enabledLayerCount = InstanceLayers.Count(); instInfo.ppEnabledLayerNames = instInfo.enabledLayerCount > 0 ? InstanceLayers.Get() : nullptr; #if VULKAN_USE_DEBUG_LAYER - SupportsDebugCallbackExt = !SupportsDebugUtilsExt && hasExtension(InstanceExtensions, VK_EXT_DEBUG_REPORT_EXTENSION_NAME); + SupportsDebugCallbackExt = !SupportsDebugUtilsExt && RenderToolsVulkan::HasExtension(InstanceExtensions, VK_EXT_DEBUG_REPORT_EXTENSION_NAME); #endif // Create Vulkan instance @@ -1658,9 +1646,7 @@ bool GPUDeviceVulkan::Init() queue.pQueuePriorities = currentPriority; const VkQueueFamilyProperties& properties = QueueFamilyProps[queue.queueFamilyIndex]; for (int32 queueIndex = 0; queueIndex < (int32)properties.queueCount; queueIndex++) - { *currentPriority++ = 1.0f; - } } deviceInfo.queueCreateInfoCount = queueFamilyInfos.Count(); deviceInfo.pQueueCreateInfos = queueFamilyInfos.Get(); @@ -1847,12 +1833,17 @@ bool GPUDeviceVulkan::Init() INIT_FUNC(vkDestroyImage); INIT_FUNC(vkCmdCopyBuffer); #if VMA_DEDICATED_ALLOCATION +#if PLATFORM_SWITCH + vulkanFunctions.vkGetBufferMemoryRequirements2KHR = vkGetBufferMemoryRequirements2; + vulkanFunctions.vkGetImageMemoryRequirements2KHR = vkGetImageMemoryRequirements2; +#else INIT_FUNC(vkGetBufferMemoryRequirements2KHR); INIT_FUNC(vkGetImageMemoryRequirements2KHR); #endif +#endif #undef INIT_FUNC VmaAllocatorCreateInfo allocatorInfo = {}; - allocatorInfo.vulkanApiVersion = VK_API_VERSION_1_0; + allocatorInfo.vulkanApiVersion = VULKAN_API_VERSION; allocatorInfo.physicalDevice = gpu; allocatorInfo.instance = Instance; allocatorInfo.device = Device; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h index ceed84dc2..b177ecf2b 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h @@ -400,8 +400,6 @@ public: uint32 HasKHRMaintenance1 : 1; uint32 HasKHRMaintenance2 : 1; uint32 HasMirrorClampToEdge : 1; - uint32 HasKHRExternalMemoryCapabilities : 1; - uint32 HasKHRGetPhysicalDeviceProperties2 : 1; uint32 HasEXTValidationCache : 1; }; diff --git a/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h b/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h index 4e2694aab..882e1ba0e 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h +++ b/Source/Engine/GraphicsDevice/Vulkan/IncludeVulkanHeaders.h @@ -14,7 +14,6 @@ #include #undef VK_EXT_debug_utils #undef VK_EXT_validation_cache -#define VMA_DEDICATED_ALLOCATION 0 #pragma clang diagnostic ignored "-Wpointer-bool-conversion" #pragma clang diagnostic ignored "-Wtautological-pointer-compare" diff --git a/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.h b/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.h index 6da593da4..9a564237c 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.h +++ b/Source/Engine/GraphicsDevice/Vulkan/Linux/LinuxVulkanPlatform.h @@ -6,8 +6,6 @@ #if GRAPHICS_API_VULKAN && PLATFORM_LINUX -#define VULKAN_HAS_PHYSICAL_DEVICE_PROPERTIES2 1 - /// /// The implementation for the Vulkan API support for Linux platform. /// diff --git a/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp index be801869b..185c3632c 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp @@ -277,4 +277,15 @@ void RenderToolsVulkan::LogVkResult(VkResult result) LogVkResult(result, "", 0); } +bool RenderToolsVulkan::HasExtension(const Array& extensions, const char* name) +{ + for (int32 i = 0; i < extensions.Count(); i++) + { + const char* extension = extensions[i]; + if (extension && StringUtils::Compare(extension, name) == 0) + return true; + } + return false; +} + #endif diff --git a/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.h index d97f24340..bdb4ca654 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.h @@ -307,6 +307,8 @@ public: } return result; } + + static bool HasExtension(const Array& extensions, const char* name); }; #endif diff --git a/Source/Engine/GraphicsDevice/Vulkan/Win32/Win32VulkanPlatform.h b/Source/Engine/GraphicsDevice/Vulkan/Win32/Win32VulkanPlatform.h index 34bcfaff1..f194a8300 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/Win32/Win32VulkanPlatform.h +++ b/Source/Engine/GraphicsDevice/Vulkan/Win32/Win32VulkanPlatform.h @@ -8,7 +8,6 @@ #define VULKAN_USE_PLATFORM_WIN32_KHR 1 #define VULKAN_USE_PLATFORM_WIN32_KHX 1 -#define VULKAN_HAS_PHYSICAL_DEVICE_PROPERTIES2 1 #define VULKAN_USE_CREATE_WIN32_SURFACE 1 ///