From bcd5a9235c2aa21bcd091d3088d90a9e2f94b8dc Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 20 Nov 2018 15:50:41 +0100 Subject: [PATCH] [dxvk] Make use of VK_AMD_memory_overallocation_behavior Currently only supported on AMDVLK. Enforces memory limits on a driver level unless the corresponding dxvk.allowMemoryOvercommit option is enabled. --- src/dxvk/dxvk_adapter.cpp | 15 ++++++++++++++- src/dxvk/dxvk_extensions.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/dxvk/dxvk_adapter.cpp b/src/dxvk/dxvk_adapter.cpp index 9c166825..adea2900 100644 --- a/src/dxvk/dxvk_adapter.cpp +++ b/src/dxvk/dxvk_adapter.cpp @@ -212,7 +212,8 @@ namespace dxvk { Rc DxvkAdapter::createDevice(DxvkDeviceFeatures enabledFeatures) { DxvkDeviceExtensions devExtensions; - std::array devExtensionList = {{ + std::array devExtensionList = {{ + &devExtensions.amdMemoryOverallocationBehaviour, &devExtensions.extShaderViewportIndexLayer, &devExtensions.extTransformFeedback, &devExtensions.extVertexAttributeDivisor, @@ -254,6 +255,15 @@ namespace dxvk { enabledFeatures.extVertexAttributeDivisor.pNext = enabledFeatures.core.pNext; enabledFeatures.core.pNext = &enabledFeatures.extVertexAttributeDivisor; } + + // Report the desired overallocation behaviour to the driver + VkDeviceMemoryOverallocationCreateInfoAMD overallocInfo; + overallocInfo.sType = VK_STRUCTURE_TYPE_DEVICE_MEMORY_OVERALLOCATION_CREATE_INFO_AMD; + overallocInfo.pNext = nullptr; + overallocInfo.overallocationBehavior = VK_MEMORY_OVERALLOCATION_BEHAVIOR_DISALLOWED_AMD; + + if (m_instance->options().allowMemoryOvercommit) + overallocInfo.overallocationBehavior = VK_MEMORY_OVERALLOCATION_BEHAVIOR_ALLOWED_AMD; // Create one single queue for graphics and present float queuePriority = 1.0f; @@ -288,6 +298,9 @@ namespace dxvk { info.enabledExtensionCount = extensionNameList.count(); info.ppEnabledExtensionNames = extensionNameList.names(); info.pEnabledFeatures = &enabledFeatures.core.features; + + if (devExtensions.amdMemoryOverallocationBehaviour) + overallocInfo.pNext = std::exchange(info.pNext, &overallocInfo); VkDevice device = VK_NULL_HANDLE; diff --git a/src/dxvk/dxvk_extensions.h b/src/dxvk/dxvk_extensions.h index 12160b5c..401d42b1 100644 --- a/src/dxvk/dxvk_extensions.h +++ b/src/dxvk/dxvk_extensions.h @@ -257,6 +257,7 @@ namespace dxvk { * used by DXVK if supported by the implementation. */ struct DxvkDeviceExtensions { + DxvkExt amdMemoryOverallocationBehaviour= { VK_AMD_MEMORY_OVERALLOCATION_BEHAVIOR_EXTENSION_NAME, DxvkExtMode::Optional }; DxvkExt extShaderViewportIndexLayer = { VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME, DxvkExtMode::Optional }; DxvkExt extTransformFeedback = { VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME, DxvkExtMode::Optional }; DxvkExt extVertexAttributeDivisor = { VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME, DxvkExtMode::Optional };