aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Vulkan/MemoryAllocator.cs
diff options
context:
space:
mode:
authorMary <mary@mary.zone>2023-02-15 07:50:26 +0100
committerGitHub <noreply@github.com>2023-02-15 07:50:26 +0100
commit32450d45de7889318e0f289fc52b3fffc62edf60 (patch)
tree2fc838e1ff71e1bbaede63484958b35a859f491c /Ryujinx.Graphics.Vulkan/MemoryAllocator.cs
parented7a0474c6b126d885e6689abc46264100ec8de0 (diff)
vulkan: Clean up MemoryAllocator (#4418)
This started as an attempt to remove vkGetPhysicalDeviceMemoryProperties in FindSuitableMemoryTypeIndex (As this could have some overhead and shouldn't change at runtime) and turned in a little bigger cleanup.
Diffstat (limited to 'Ryujinx.Graphics.Vulkan/MemoryAllocator.cs')
-rw-r--r--Ryujinx.Graphics.Vulkan/MemoryAllocator.cs26
1 files changed, 12 insertions, 14 deletions
diff --git a/Ryujinx.Graphics.Vulkan/MemoryAllocator.cs b/Ryujinx.Graphics.Vulkan/MemoryAllocator.cs
index 83c0a324..e4dcd916 100644
--- a/Ryujinx.Graphics.Vulkan/MemoryAllocator.cs
+++ b/Ryujinx.Graphics.Vulkan/MemoryAllocator.cs
@@ -9,34 +9,36 @@ namespace Ryujinx.Graphics.Vulkan
private ulong MaxDeviceMemoryUsageEstimate = 16UL * 1024 * 1024 * 1024;
private readonly Vk _api;
+ private readonly PhysicalDevice _physicalDevice;
private readonly Device _device;
private readonly List<MemoryAllocatorBlockList> _blockLists;
+ private readonly int _blockAlignment;
+ private readonly PhysicalDeviceMemoryProperties _physicalDeviceMemoryProperties;
- private int _blockAlignment;
-
- public MemoryAllocator(Vk api, Device device, uint maxMemoryAllocationCount)
+ public MemoryAllocator(Vk api, PhysicalDevice physicalDevice, Device device, uint maxMemoryAllocationCount)
{
_api = api;
+ _physicalDevice = physicalDevice;
_device = device;
_blockLists = new List<MemoryAllocatorBlockList>();
_blockAlignment = (int)Math.Min(int.MaxValue, MaxDeviceMemoryUsageEstimate / (ulong)maxMemoryAllocationCount);
+
+ _api.GetPhysicalDeviceMemoryProperties(_physicalDevice, out _physicalDeviceMemoryProperties);
}
public MemoryAllocation AllocateDeviceMemory(
- PhysicalDevice physicalDevice,
MemoryRequirements requirements,
MemoryPropertyFlags flags = 0)
{
- return AllocateDeviceMemory(physicalDevice, requirements, flags, flags);
+ return AllocateDeviceMemory(requirements, flags, flags);
}
public MemoryAllocation AllocateDeviceMemory(
- PhysicalDevice physicalDevice,
MemoryRequirements requirements,
MemoryPropertyFlags flags,
MemoryPropertyFlags alternativeFlags)
{
- int memoryTypeIndex = FindSuitableMemoryTypeIndex(_api, physicalDevice, requirements.MemoryTypeBits, flags, alternativeFlags);
+ int memoryTypeIndex = FindSuitableMemoryTypeIndex(requirements.MemoryTypeBits, flags, alternativeFlags);
if (memoryTypeIndex < 0)
{
return default;
@@ -65,20 +67,16 @@ namespace Ryujinx.Graphics.Vulkan
return newBl.Allocate(size, alignment, map);
}
- private static int FindSuitableMemoryTypeIndex(
- Vk api,
- PhysicalDevice physicalDevice,
+ private int FindSuitableMemoryTypeIndex(
uint memoryTypeBits,
MemoryPropertyFlags flags,
MemoryPropertyFlags alternativeFlags)
{
int bestCandidateIndex = -1;
- api.GetPhysicalDeviceMemoryProperties(physicalDevice, out var properties);
-
- for (int i = 0; i < properties.MemoryTypeCount; i++)
+ for (int i = 0; i < _physicalDeviceMemoryProperties.MemoryTypeCount; i++)
{
- var type = properties.MemoryTypes[i];
+ var type = _physicalDeviceMemoryProperties.MemoryTypes[i];
if ((memoryTypeBits & (1 << i)) != 0)
{