From 0d8bd2653b9aef374fc139eefc4e4ebd36e09c83 Mon Sep 17 00:00:00 2001 From: KeatonTheBot Date: Wed, 1 Apr 2026 09:10:46 -0500 Subject: [PATCH] Vulkan: Enable VK_EXT_memory_priority for Pageable Memory to work properly --- .../HostMemoryAllocator.cs | 9 +++- .../VulkanInitialization.cs | 48 +++++++++++++++---- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs b/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs index 056102dd6..69bf69919 100644 --- a/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs +++ b/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs @@ -108,12 +108,19 @@ namespace Ryujinx.Graphics.Vulkan PHostPointer = (void*)pageAlignedPointer, }; + MemoryPriorityAllocateInfoEXT priorityInfo = new() + { + SType = StructureType.MemoryPriorityAllocateInfoExt, + Priority = 0.0f, + PNext = &importInfo, + }; + var memoryAllocateInfo = new MemoryAllocateInfo { SType = StructureType.MemoryAllocateInfo, AllocationSize = pageAlignedSize, MemoryTypeIndex = (uint)memoryTypeIndex, - PNext = &importInfo, + PNext = &priorityInfo, }; Result result = _api.AllocateMemory(_device, in memoryAllocateInfo, null, out var deviceMemory); diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanInitialization.cs b/src/Ryujinx.Graphics.Vulkan/VulkanInitialization.cs index 679083843..6878befdd 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanInitialization.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanInitialization.cs @@ -46,7 +46,8 @@ namespace Ryujinx.Graphics.Vulkan "VK_KHR_8bit_storage", "VK_KHR_maintenance2", "VK_EXT_attachment_feedback_loop_layout", - "VK_EXT_attachment_feedback_loop_dynamic_state" + "VK_EXT_attachment_feedback_loop_dynamic_state", + "VK_EXT_memory_priority" ]; private static readonly string[] _requiredExtensions = @@ -466,7 +467,21 @@ namespace Ryujinx.Graphics.Vulkan PNext = features2.PNext, }; - features2.PNext = &supportedPageableDeviceLocalMemoryFeatures; + if (physicalDevice.IsDeviceExtensionPresent(ExtPageableDeviceLocalMemory.ExtensionName)) + { + features2.PNext = &supportedPageableDeviceLocalMemoryFeatures; + } + + PhysicalDeviceMemoryPriorityFeaturesEXT supportedDeviceMemoryPriorityFeatures = new() + { + SType = StructureType.PhysicalDeviceMemoryPriorityFeaturesExt, + PNext = features2.PNext, + }; + + if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_memory_priority")) + { + features2.PNext = &supportedDeviceMemoryPriorityFeatures; + } PhysicalDeviceVulkan12Features supportedPhysicalDeviceVulkan12Features = new() { @@ -640,14 +655,31 @@ namespace Ryujinx.Graphics.Vulkan pExtendedFeatures = &featuresDynamicAttachmentFeedbackLoop; } - PhysicalDevicePageableDeviceLocalMemoryFeaturesEXT featuresPageableDeviceLocalMemory = new() + if (physicalDevice.IsDeviceExtensionPresent(ExtPageableDeviceLocalMemory.ExtensionName) && + supportedPageableDeviceLocalMemoryFeatures.PageableDeviceLocalMemory) { - SType = StructureType.PhysicalDevicePageableDeviceLocalMemoryFeaturesExt, - PNext = pExtendedFeatures, - PageableDeviceLocalMemory = supportedPageableDeviceLocalMemoryFeatures.PageableDeviceLocalMemory, - }; + PhysicalDevicePageableDeviceLocalMemoryFeaturesEXT featuresPageableDeviceLocalMemory = new() + { + SType = StructureType.PhysicalDevicePageableDeviceLocalMemoryFeaturesExt, + PNext = pExtendedFeatures, + PageableDeviceLocalMemory = true, + }; - pExtendedFeatures = &featuresPageableDeviceLocalMemory; + pExtendedFeatures = &featuresPageableDeviceLocalMemory; + } + + if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_memory_priority") && + supportedDeviceMemoryPriorityFeatures.MemoryPriority) + { + PhysicalDeviceMemoryPriorityFeaturesEXT featuresDeviceMemoryPriority = new() + { + SType = StructureType.PhysicalDeviceMemoryPriorityFeaturesExt, + PNext = pExtendedFeatures, + MemoryPriority = true, + }; + + pExtendedFeatures = &featuresDeviceMemoryPriority; + } var enabledExtensions = _requiredExtensions.Union(_desirableExtensions.Intersect(physicalDevice.DeviceExtensions)).ToArray();