Fix same textures with unmapped start being considered different (#7141)

* Fix same textures with unmapped start being considered different

* Consolidate IsInvalid check

* InvalidAddress const

* Fix typo

Co-authored-by: riperiperi <rhy3756547@hotmail.com>

---------

Co-authored-by: riperiperi <rhy3756547@hotmail.com>
This commit is contained in:
gdkchan 2024-08-05 11:00:41 -03:00 committed by GitHub
parent e85ee673b1
commit 4a4b11871e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 16 deletions

View file

@ -4,6 +4,22 @@ namespace Ryujinx.Memory.Range
{ {
MultiRange Range { get; } MultiRange Range { get; }
ulong BaseAddress => Range.GetSubRange(0).Address; ulong BaseAddress
{
get
{
for (int index = 0; index < Range.Count; index++)
{
MemoryRange subRange = Range.GetSubRange(index);
if (!MemoryRange.IsInvalid(ref subRange))
{
return subRange.Address;
}
}
return MemoryRange.InvalidAddress;
}
}
} }
} }

View file

@ -5,6 +5,11 @@ namespace Ryujinx.Memory.Range
/// </summary> /// </summary>
public readonly record struct MemoryRange public readonly record struct MemoryRange
{ {
/// <summary>
/// Special address value used to indicate than an address is invalid.
/// </summary>
internal const ulong InvalidAddress = ulong.MaxValue;
/// <summary> /// <summary>
/// An empty memory range, with a null address and zero size. /// An empty memory range, with a null address and zero size.
/// </summary> /// </summary>
@ -58,13 +63,24 @@ namespace Ryujinx.Memory.Range
return thisAddress < otherEndAddress && otherAddress < thisEndAddress; return thisAddress < otherEndAddress && otherAddress < thisEndAddress;
} }
/// <summary>
/// Checks if a given sub-range of memory is invalid.
/// Those are used to represent unmapped memory regions (holes in the region mapping).
/// </summary>
/// <param name="subRange">Memory range to check</param>
/// <returns>True if the memory range is considered invalid, false otherwise</returns>
internal static bool IsInvalid(ref MemoryRange subRange)
{
return subRange.Address == InvalidAddress;
}
/// <summary> /// <summary>
/// Returns a string summary of the memory range. /// Returns a string summary of the memory range.
/// </summary> /// </summary>
/// <returns>A string summary of the memory range</returns> /// <returns>A string summary of the memory range</returns>
public override string ToString() public override string ToString()
{ {
if (Address == ulong.MaxValue) if (Address == InvalidAddress)
{ {
return $"[Unmapped 0x{Size:X}]"; return $"[Unmapped 0x{Size:X}]";
} }

View file

@ -30,7 +30,7 @@ namespace Ryujinx.Memory.Range
{ {
var subrange = range.GetSubRange(i); var subrange = range.GetSubRange(i);
if (IsInvalid(ref subrange)) if (MemoryRange.IsInvalid(ref subrange))
{ {
continue; continue;
} }
@ -56,7 +56,7 @@ namespace Ryujinx.Memory.Range
{ {
var subrange = range.GetSubRange(i); var subrange = range.GetSubRange(i);
if (IsInvalid(ref subrange)) if (MemoryRange.IsInvalid(ref subrange))
{ {
continue; continue;
} }
@ -99,7 +99,7 @@ namespace Ryujinx.Memory.Range
{ {
var subrange = range.GetSubRange(i); var subrange = range.GetSubRange(i);
if (IsInvalid(ref subrange)) if (MemoryRange.IsInvalid(ref subrange))
{ {
continue; continue;
} }
@ -142,17 +142,6 @@ namespace Ryujinx.Memory.Range
return overlapCount; return overlapCount;
} }
/// <summary>
/// Checks if a given sub-range of memory is invalid.
/// Those are used to represent unmapped memory regions (holes in the region mapping).
/// </summary>
/// <param name="subRange">Memory range to checl</param>
/// <returns>True if the memory range is considered invalid, false otherwise</returns>
private static bool IsInvalid(ref MemoryRange subRange)
{
return subRange.Address == ulong.MaxValue;
}
/// <summary> /// <summary>
/// Gets all items on the list starting at the specified memory address. /// Gets all items on the list starting at the specified memory address.
/// </summary> /// </summary>