From c4f56c570494a6186792439e3c0e74458cc82b5c Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 17 Jan 2021 15:44:34 -0300 Subject: Support for resources on non-contiguous GPU memory regions (#1905) * Support for resources on non-contiguous GPU memory regions * Implement MultiRange physical addresses, only used with a single range for now * Actually use non-contiguous ranges * GetPhysicalRegions fixes * Documentation and remove Address property from TextureInfo * Finish implementing GetWritableRegion * Fix typo --- Ryujinx.Memory/Range/MemoryRange.cs | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Ryujinx.Memory/Range/MemoryRange.cs (limited to 'Ryujinx.Memory/Range/MemoryRange.cs') diff --git a/Ryujinx.Memory/Range/MemoryRange.cs b/Ryujinx.Memory/Range/MemoryRange.cs new file mode 100644 index 00000000..ba12bae5 --- /dev/null +++ b/Ryujinx.Memory/Range/MemoryRange.cs @@ -0,0 +1,71 @@ +using System; + +namespace Ryujinx.Memory.Range +{ + /// + /// Range of memory composed of an address and size. + /// + public struct MemoryRange : IEquatable + { + /// + /// An empty memory range, with a null address and zero size. + /// + public static MemoryRange Empty => new MemoryRange(0UL, 0); + + /// + /// Start address of the range. + /// + public ulong Address { get; } + + /// + /// Size of the range in bytes. + /// + public ulong Size { get; } + + /// + /// Address where the range ends (exclusive). + /// + public ulong EndAddress => Address + Size; + + /// + /// Creates a new memory range with the specified address and size. + /// + /// Start address + /// Size in bytes + public MemoryRange(ulong address, ulong size) + { + Address = address; + Size = size; + } + + /// + /// Checks if the range overlaps with another. + /// + /// The other range to check for overlap + /// True if the ranges overlap, false otherwise + public bool OverlapsWith(MemoryRange other) + { + ulong thisAddress = Address; + ulong thisEndAddress = EndAddress; + ulong otherAddress = other.Address; + ulong otherEndAddress = other.EndAddress; + + return thisAddress < otherEndAddress && otherAddress < thisEndAddress; + } + + public override bool Equals(object obj) + { + return obj is MemoryRange other && Equals(other); + } + + public bool Equals(MemoryRange other) + { + return Address == other.Address && Size == other.Size; + } + + public override int GetHashCode() + { + return HashCode.Combine(Address, Size); + } + } +} -- cgit v1.2.3