Update Vulkan backend
This commit is contained in:
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
||||
@@ -575,25 +575,15 @@ void GPUDeviceVulkan::GetDeviceExtensionsAndLayers(VkPhysicalDevice gpu, Array<c
|
||||
void GPUDeviceVulkan::ParseOptionalDeviceExtensions(const Array<const char*>& deviceExtensions)
|
||||
{
|
||||
Platform::MemoryClear(&OptionalDeviceExtensions, sizeof(OptionalDeviceExtensions));
|
||||
|
||||
const auto HasExtension = [&deviceExtensions](const char* name) -> bool
|
||||
{
|
||||
const Function<bool(const char* const&)> 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
|
||||
}
|
||||
|
||||
|
||||
@@ -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<const char*>& extensions, const char* name) -> bool
|
||||
{
|
||||
const Function<bool(const char* const&)> 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<const char* const*>(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;
|
||||
|
||||
@@ -400,8 +400,6 @@ public:
|
||||
uint32 HasKHRMaintenance1 : 1;
|
||||
uint32 HasKHRMaintenance2 : 1;
|
||||
uint32 HasMirrorClampToEdge : 1;
|
||||
uint32 HasKHRExternalMemoryCapabilities : 1;
|
||||
uint32 HasKHRGetPhysicalDeviceProperties2 : 1;
|
||||
uint32 HasEXTValidationCache : 1;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <vulkan/vulkan.h>
|
||||
#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"
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
#if GRAPHICS_API_VULKAN && PLATFORM_LINUX
|
||||
|
||||
#define VULKAN_HAS_PHYSICAL_DEVICE_PROPERTIES2 1
|
||||
|
||||
/// <summary>
|
||||
/// The implementation for the Vulkan API support for Linux platform.
|
||||
/// </summary>
|
||||
|
||||
@@ -277,4 +277,15 @@ void RenderToolsVulkan::LogVkResult(VkResult result)
|
||||
LogVkResult(result, "", 0);
|
||||
}
|
||||
|
||||
bool RenderToolsVulkan::HasExtension(const Array<const char*>& 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
|
||||
|
||||
@@ -307,6 +307,8 @@ public:
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool HasExtension(const Array<const char*, HeapAllocation>& extensions, const char* name);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user