aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs')
-rw-r--r--src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
index 0d4a41f0..c7a138c9 100644
--- a/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
+++ b/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
@@ -638,6 +638,33 @@ namespace Ryujinx.Graphics.Gpu.Memory
}
/// <summary>
+ /// Translates a GPU virtual address and returns the number of bytes that are mapped after it.
+ /// </summary>
+ /// <param name="va">GPU virtual address to be translated</param>
+ /// <param name="maxSize">Maximum size in bytes to scan</param>
+ /// <returns>Number of bytes, 0 if unmapped</returns>
+ public ulong GetMappedSize(ulong va, ulong maxSize)
+ {
+ if (!ValidateAddress(va))
+ {
+ return 0;
+ }
+
+ ulong startVa = va;
+ ulong endVa = va + maxSize;
+
+ ulong pte = GetPte(va);
+
+ while (pte != PteUnmapped && va < endVa)
+ {
+ va += PageSize - (va & PageMask);
+ pte = GetPte(va);
+ }
+
+ return Math.Min(maxSize, va - startVa);
+ }
+
+ /// <summary>
/// Gets the kind of a given memory page.
/// This might indicate the type of resource that can be allocated on the page, and also texture tiling.
/// </summary>