diff options
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Memory')
-rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs | 43 | ||||
-rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs | 10 |
2 files changed, 53 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs index c57f1a6f..ae27c712 100644 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs @@ -256,6 +256,49 @@ namespace Ryujinx.Graphics.Gpu.Memory } /// <summary> + /// Writes data to GPU mapped memory, stopping at the first unmapped page at the memory region, if any. + /// </summary> + /// <param name="va">GPU virtual address to write the data into</param> + /// <param name="data">The data to be written</param> + public void WriteMapped(ulong va, ReadOnlySpan<byte> data) + { + if (IsContiguous(va, data.Length)) + { + Physical.Write(Translate(va), data); + } + else + { + int offset = 0, size; + + if ((va & PageMask) != 0) + { + ulong pa = Translate(va); + + size = Math.Min(data.Length, (int)PageSize - (int)(va & PageMask)); + + if (pa != PteUnmapped && Physical.IsMapped(pa)) + { + Physical.Write(pa, data.Slice(0, size)); + } + + offset += size; + } + + for (; offset < data.Length; offset += size) + { + ulong pa = Translate(va + (ulong)offset); + + size = Math.Min(data.Length - offset, (int)PageSize); + + if (pa != PteUnmapped && Physical.IsMapped(pa)) + { + Physical.Write(pa, data.Slice(offset, size)); + } + } + } + } + + /// <summary> /// Maps a given range of pages to the specified CPU virtual address. /// </summary> /// <remarks> diff --git a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs index bfd3c04f..57590fb3 100644 --- a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs +++ b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs @@ -341,6 +341,16 @@ namespace Ryujinx.Graphics.Gpu.Memory } /// <summary> + /// Checks if the page at a given address is mapped on CPU memory. + /// </summary> + /// <param name="address">CPU virtual address of the page to check</param> + /// <returns>True if mapped, false otherwise</returns> + public bool IsMapped(ulong address) + { + return _cpuMemory.IsMapped(address); + } + + /// <summary> /// Release our reference to the CPU memory manager. /// </summary> public void Dispose() |