From ec62551412b81b92bc216524519f28c372e225ec Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 24 Oct 2024 12:15:44 +0200 Subject: [PATCH] [dxvk] Add option to disable memory defragmentation --- dxvk.conf | 14 ++++++++++++++ src/dxvk/dxvk_memory.cpp | 16 +++++++++------- src/dxvk/dxvk_options.cpp | 1 + src/dxvk/dxvk_options.h | 19 +++++++++++-------- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/dxvk.conf b/dxvk.conf index 3416dd4dc..b1e9be58d 100644 --- a/dxvk.conf +++ b/dxvk.conf @@ -388,6 +388,20 @@ # dxvk.trackPipelineLifetime = Auto +# Controls memory defragmentation +# +# By default, DXVK will try to defragment video memory if there is a +# significant amount of memory wasted, or if the allocation budget of +# the application is exceeded. This option is provided solely for +# debug purposes. +# +# Supported values: +# - True: Enable defragmentation +# - False: Disable defragmentation + +# dxvk.enableMemoryDefrag = True + + # Sets enabled HUD elements # # Behaves like the DXVK_HUD environment variable if the diff --git a/src/dxvk/dxvk_memory.cpp b/src/dxvk/dxvk_memory.cpp index ab31f0fd3..4d31bbdf0 100644 --- a/src/dxvk/dxvk_memory.cpp +++ b/src/dxvk/dxvk_memory.cpp @@ -2283,13 +2283,15 @@ namespace dxvk { m_memTypes[i].sharedCache->cleanupUnusedFromLockedAllocator(currentTime); } - // Periodically defragment device-local memory types. We cannot - // do anything about mapped allocations since we rely on pointer - // stability there. - for (uint32_t i = 0; i < m_memTypeCount; i++) { - if (m_memTypes[i].properties.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) { - moveDefragChunk(m_memTypes[i]); - pickDefragChunk(m_memTypes[i]); + if (m_device->config().enableMemoryDefrag) { + // Periodically defragment device-local memory types. We cannot + // do anything about mapped allocations since we rely on pointer + // stability there. + for (uint32_t i = 0; i < m_memTypeCount; i++) { + if (m_memTypes[i].properties.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) { + moveDefragChunk(m_memTypes[i]); + pickDefragChunk(m_memTypes[i]); + } } } } diff --git a/src/dxvk/dxvk_options.cpp b/src/dxvk/dxvk_options.cpp index 75245ff34..b00eb3b60 100644 --- a/src/dxvk/dxvk_options.cpp +++ b/src/dxvk/dxvk_options.cpp @@ -5,6 +5,7 @@ namespace dxvk { DxvkOptions::DxvkOptions(const Config& config) { enableDebugUtils = config.getOption ("dxvk.enableDebugUtils", false); enableStateCache = config.getOption ("dxvk.enableStateCache", true); + enableMemoryDefrag = config.getOption ("dxvk.enableMemoryDefrag", true); numCompilerThreads = config.getOption ("dxvk.numCompilerThreads", 0); enableGraphicsPipelineLibrary = config.getOption("dxvk.enableGraphicsPipelineLibrary", Tristate::Auto); trackPipelineLifetime = config.getOption("dxvk.trackPipelineLifetime", Tristate::Auto); diff --git a/src/dxvk/dxvk_options.h b/src/dxvk/dxvk_options.h index eee3d9c88..ab77aa987 100644 --- a/src/dxvk/dxvk_options.h +++ b/src/dxvk/dxvk_options.h @@ -9,35 +9,38 @@ namespace dxvk { DxvkOptions(const Config& config); /// Enable debug utils - bool enableDebugUtils; + bool enableDebugUtils = false; /// Enable state cache - bool enableStateCache; + bool enableStateCache = true; + + /// Enable memory defragmentation + bool enableMemoryDefrag = true; /// Number of compiler threads /// when using the state cache - int32_t numCompilerThreads; + int32_t numCompilerThreads = 0; /// Enable graphics pipeline library - Tristate enableGraphicsPipelineLibrary; + Tristate enableGraphicsPipelineLibrary = Tristate::Auto; /// Enables pipeline lifetime tracking - Tristate trackPipelineLifetime; + Tristate trackPipelineLifetime = Tristate::Auto; /// Shader-related options - Tristate useRawSsbo; + Tristate useRawSsbo = Tristate::Auto; /// HUD elements std::string hud; /// Forces swap chain into MAILBOX (if true) /// or FIFO_RELAXED (if false) present mode - Tristate tearFree; + Tristate tearFree = Tristate::Auto; // Hides integrated GPUs if dedicated GPUs are // present. May be necessary for some games that // incorrectly assume monitor layouts. - bool hideIntegratedGraphics; + bool hideIntegratedGraphics = false; // Device name std::string deviceFilter;