aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2022-03-20 13:55:07 -0300
committerGitHub <noreply@github.com>2022-03-20 13:55:07 -0300
commit79408b68c3e72c26d42f858089d97d77d58b44d9 (patch)
tree9aaa12a877030dc17b4333eefe886be7fb8eb820 /Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
parentd461d4f68bf64f008336845ae8a25af4f69ec9ed (diff)
De-tile GOB when DMA copying from block linear to pitch kind memory regions (#3207)1.1.80
* De-tile GOB when DMA copying from block linear to pitch kind memory regions * XML docs + nits * Remove using * No flush for regular buffer copies * Add back ulong casts, fix regression due to oversight
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs')
-rw-r--r--Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs65
1 files changed, 60 insertions, 5 deletions
diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
index 977fbdf9..c57f1a6f 100644
--- a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
+++ b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
@@ -264,7 +264,8 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <param name="pa">CPU virtual address to map into</param>
/// <param name="va">GPU virtual address to be mapped</param>
/// <param name="size">Size in bytes of the mapping</param>
- public void Map(ulong pa, ulong va, ulong size)
+ /// <param name="kind">Kind of the resource located at the mapping</param>
+ public void Map(ulong pa, ulong va, ulong size, PteKind kind)
{
lock (_pageTable)
{
@@ -272,7 +273,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
for (ulong offset = 0; offset < size; offset += PageSize)
{
- SetPte(va + offset, pa + offset);
+ SetPte(va + offset, PackPte(pa + offset, kind));
}
}
}
@@ -462,14 +463,37 @@ namespace Ryujinx.Graphics.Gpu.Memory
return PteUnmapped;
}
- ulong baseAddress = GetPte(va);
+ ulong pte = GetPte(va);
- if (baseAddress == PteUnmapped)
+ if (pte == PteUnmapped)
{
return PteUnmapped;
}
- return baseAddress + (va & PageMask);
+ return UnpackPaFromPte(pte) + (va & PageMask);
+ }
+
+ /// <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>
+ /// <param name="va">GPU virtual address</param>
+ /// <returns>Kind of the memory page</returns>
+ public PteKind GetKind(ulong va)
+ {
+ if (!ValidateAddress(va))
+ {
+ return PteKind.Invalid;
+ }
+
+ ulong pte = GetPte(va);
+
+ if (pte == PteUnmapped)
+ {
+ return PteKind.Invalid;
+ }
+
+ return UnpackKindFromPte(pte);
}
/// <summary>
@@ -512,5 +536,36 @@ namespace Ryujinx.Graphics.Gpu.Memory
_pageTable[l0][l1] = pte;
}
+
+ /// <summary>
+ /// Creates a page table entry from a physical address and kind.
+ /// </summary>
+ /// <param name="pa">Physical address</param>
+ /// <param name="kind">Kind</param>
+ /// <returns>Page table entry</returns>
+ private static ulong PackPte(ulong pa, PteKind kind)
+ {
+ return pa | ((ulong)kind << 56);
+ }
+
+ /// <summary>
+ /// Unpacks kind from a page table entry.
+ /// </summary>
+ /// <param name="pte">Page table entry</param>
+ /// <returns>Kind</returns>
+ private static PteKind UnpackKindFromPte(ulong pte)
+ {
+ return (PteKind)(pte >> 56);
+ }
+
+ /// <summary>
+ /// Unpacks physical address from a page table entry.
+ /// </summary>
+ /// <param name="pte">Page table entry</param>
+ /// <returns>Physical address</returns>
+ private static ulong UnpackPaFromPte(ulong pte)
+ {
+ return pte & 0xffffffffffffffUL;
+ }
}
} \ No newline at end of file