mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-10-01 12:30:00 +02:00
Remove long <-> ulong casts from Nvservices code (#1848)
* Remove long <-> ulong casts from Nvservices code * review: fix lint
This commit is contained in:
parent
532b8cad13
commit
b9fd7c8b23
12 changed files with 89 additions and 89 deletions
|
@ -97,12 +97,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
// the Offset field holds the alignment size instead.
|
||||
if ((arguments.Flags & AddressSpaceFlags.FixedOffset) != 0)
|
||||
{
|
||||
bool regionInUse = _memoryAllocator.IsRegionInUse((ulong)arguments.Offset, size, out ulong freeAddressStartPosition);
|
||||
bool regionInUse = _memoryAllocator.IsRegionInUse(arguments.Offset, size, out ulong freeAddressStartPosition);
|
||||
ulong address;
|
||||
|
||||
if (!regionInUse)
|
||||
{
|
||||
_memoryAllocator.AllocateRange((ulong)arguments.Offset, size, freeAddressStartPosition);
|
||||
_memoryAllocator.AllocateRange(arguments.Offset, size, freeAddressStartPosition);
|
||||
address = freeAddressStartPosition;
|
||||
}
|
||||
else
|
||||
|
@ -110,17 +110,17 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
address = NvMemoryAllocator.PteUnmapped;
|
||||
}
|
||||
|
||||
arguments.Offset = (long)address;
|
||||
arguments.Offset = address;
|
||||
}
|
||||
else
|
||||
{
|
||||
ulong address = _memoryAllocator.GetFreeAddress((ulong)size, out ulong freeAddressStartPosition, (ulong)arguments.Offset);
|
||||
ulong address = _memoryAllocator.GetFreeAddress(size, out ulong freeAddressStartPosition, arguments.Offset);
|
||||
if (address != NvMemoryAllocator.PteUnmapped)
|
||||
{
|
||||
_memoryAllocator.AllocateRange(address, (ulong)size, freeAddressStartPosition);
|
||||
_memoryAllocator.AllocateRange(address, size, freeAddressStartPosition);
|
||||
}
|
||||
|
||||
arguments.Offset = unchecked((long)address);
|
||||
arguments.Offset = address;
|
||||
}
|
||||
|
||||
if (arguments.Offset < 0)
|
||||
|
@ -133,7 +133,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
}
|
||||
else
|
||||
{
|
||||
addressSpaceContext.AddReservation(arguments.Offset, (long)size);
|
||||
addressSpaceContext.AddReservation(arguments.Offset, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,8 +152,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
|
||||
if (addressSpaceContext.RemoveReservation(arguments.Offset))
|
||||
{
|
||||
_memoryAllocator.DeallocateRange((ulong)arguments.Offset, size);
|
||||
addressSpaceContext.Gmm.Free((ulong)arguments.Offset, size);
|
||||
_memoryAllocator.DeallocateRange(arguments.Offset, size);
|
||||
addressSpaceContext.Gmm.Free(arguments.Offset, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -173,12 +173,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
|
||||
lock (addressSpaceContext)
|
||||
{
|
||||
if (addressSpaceContext.RemoveMap(arguments.Offset, out long size))
|
||||
if (addressSpaceContext.RemoveMap(arguments.Offset, out ulong size))
|
||||
{
|
||||
if (size != 0)
|
||||
{
|
||||
_memoryAllocator.DeallocateRange((ulong)arguments.Offset, (ulong)size);
|
||||
addressSpaceContext.Gmm.Free((ulong)arguments.Offset, (ulong)size);
|
||||
_memoryAllocator.DeallocateRange(arguments.Offset, size);
|
||||
addressSpaceContext.Gmm.Free(arguments.Offset, size);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -212,7 +212,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
pageSize = (ulong)map.Align;
|
||||
}
|
||||
|
||||
long physicalAddress;
|
||||
ulong physicalAddress;
|
||||
|
||||
if ((arguments.Flags & AddressSpaceFlags.RemapSubRange) != 0)
|
||||
{
|
||||
|
@ -220,10 +220,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
{
|
||||
if (addressSpaceContext.TryGetMapPhysicalAddress(arguments.Offset, out physicalAddress))
|
||||
{
|
||||
long virtualAddress = arguments.Offset + arguments.BufferOffset;
|
||||
ulong virtualAddress = arguments.Offset + arguments.BufferOffset;
|
||||
|
||||
physicalAddress += arguments.BufferOffset;
|
||||
addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)virtualAddress, (ulong)arguments.MappingSize);
|
||||
addressSpaceContext.Gmm.Map(physicalAddress, virtualAddress, arguments.MappingSize);
|
||||
|
||||
if (virtualAddress < 0)
|
||||
{
|
||||
|
@ -247,7 +247,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
|
||||
physicalAddress = map.Address + arguments.BufferOffset;
|
||||
|
||||
long size = arguments.MappingSize;
|
||||
ulong size = arguments.MappingSize;
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
|
@ -266,7 +266,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
{
|
||||
if (addressSpaceContext.ValidateFixedBuffer(arguments.Offset, size, pageSize))
|
||||
{
|
||||
addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)arguments.Offset, (ulong)size);
|
||||
addressSpaceContext.Gmm.Map(physicalAddress, arguments.Offset, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -279,14 +279,14 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
}
|
||||
else
|
||||
{
|
||||
ulong va = _memoryAllocator.GetFreeAddress((ulong)size, out ulong freeAddressStartPosition, (ulong) pageSize);
|
||||
ulong va = _memoryAllocator.GetFreeAddress(size, out ulong freeAddressStartPosition, pageSize);
|
||||
if (va != NvMemoryAllocator.PteUnmapped)
|
||||
{
|
||||
_memoryAllocator.AllocateRange(va, (ulong)size, freeAddressStartPosition);
|
||||
_memoryAllocator.AllocateRange(va, size, freeAddressStartPosition);
|
||||
}
|
||||
|
||||
addressSpaceContext.Gmm.Map((ulong)physicalAddress, va, (ulong)size);
|
||||
arguments.Offset = (long)va;
|
||||
addressSpaceContext.Gmm.Map(physicalAddress, va, size);
|
||||
arguments.Offset = va;
|
||||
}
|
||||
|
||||
if (arguments.Offset < 0)
|
||||
|
@ -335,11 +335,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
|||
return NvInternalResult.InvalidInput;
|
||||
}
|
||||
|
||||
long shiftedGpuOffset = (long)((ulong)arguments[index].GpuOffset << 16);
|
||||
ulong shiftedGpuOffset = ((ulong)arguments[index].GpuOffset << 16);
|
||||
|
||||
gmm.Map(
|
||||
((ulong)arguments[index].MapOffset << 16) + (ulong)map.Address,
|
||||
(ulong)shiftedGpuOffset,
|
||||
((ulong)arguments[index].MapOffset << 16) + map.Address,
|
||||
shiftedGpuOffset,
|
||||
(ulong)arguments[index].Pages << 16);
|
||||
|
||||
if (shiftedGpuOffset < 0)
|
||||
|
|
|
@ -12,22 +12,22 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
public ulong Start { get; private set; }
|
||||
public ulong End { get; private set; }
|
||||
|
||||
public Range(long position, long size)
|
||||
public Range(ulong position, ulong size)
|
||||
{
|
||||
Start = (ulong)position;
|
||||
End = (ulong)size + Start;
|
||||
Start = position;
|
||||
End = size + Start;
|
||||
}
|
||||
}
|
||||
|
||||
private class MappedMemory : Range
|
||||
{
|
||||
public long PhysicalAddress { get; private set; }
|
||||
public bool VaAllocated { get; private set; }
|
||||
public ulong PhysicalAddress { get; private set; }
|
||||
public bool VaAllocated { get; private set; }
|
||||
|
||||
public MappedMemory(
|
||||
long position,
|
||||
long size,
|
||||
long physicalAddress,
|
||||
ulong position,
|
||||
ulong size,
|
||||
ulong physicalAddress,
|
||||
bool vaAllocated) : base(position, size)
|
||||
{
|
||||
PhysicalAddress = physicalAddress;
|
||||
|
@ -35,8 +35,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
}
|
||||
}
|
||||
|
||||
private SortedList<long, Range> _maps;
|
||||
private SortedList<long, Range> _reservations;
|
||||
private SortedList<ulong, Range> _maps;
|
||||
private SortedList<ulong, Range> _reservations;
|
||||
|
||||
public MemoryManager Gmm { get; }
|
||||
|
||||
|
@ -44,22 +44,22 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
{
|
||||
Gmm = context.Device.Gpu.MemoryManager;
|
||||
|
||||
_maps = new SortedList<long, Range>();
|
||||
_reservations = new SortedList<long, Range>();
|
||||
_maps = new SortedList<ulong, Range>();
|
||||
_reservations = new SortedList<ulong, Range>();
|
||||
}
|
||||
|
||||
public bool ValidateFixedBuffer(long position, long size, ulong alignment)
|
||||
public bool ValidateFixedBuffer(ulong position, ulong size, ulong alignment)
|
||||
{
|
||||
long mapEnd = position + size;
|
||||
ulong mapEnd = position + size;
|
||||
|
||||
// Check if size is valid (0 is also not allowed).
|
||||
if ((ulong)mapEnd <= (ulong)position)
|
||||
if (mapEnd <= position)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if address is aligned.
|
||||
if ((position & (long)(alignment - 1)) != 0)
|
||||
if ((position & (alignment - 1)) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
// Check for overlap with already mapped buffers.
|
||||
Range map = BinarySearchLt(_maps, mapEnd);
|
||||
|
||||
if (map != null && map.End > (ulong)position)
|
||||
if (map != null && map.End > position)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -82,15 +82,15 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
}
|
||||
|
||||
public void AddMap(
|
||||
long position,
|
||||
long size,
|
||||
long physicalAddress,
|
||||
ulong position,
|
||||
ulong size,
|
||||
ulong physicalAddress,
|
||||
bool vaAllocated)
|
||||
{
|
||||
_maps.Add(position, new MappedMemory(position, size, physicalAddress, vaAllocated));
|
||||
}
|
||||
|
||||
public bool RemoveMap(long position, out long size)
|
||||
public bool RemoveMap(ulong position, out ulong size)
|
||||
{
|
||||
size = 0;
|
||||
|
||||
|
@ -100,7 +100,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
|
||||
if (map.VaAllocated)
|
||||
{
|
||||
size = (long)(map.End - map.Start);
|
||||
size = (map.End - map.Start);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -109,7 +109,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetMapPhysicalAddress(long position, out long physicalAddress)
|
||||
public bool TryGetMapPhysicalAddress(ulong position, out ulong physicalAddress)
|
||||
{
|
||||
Range map = BinarySearch(_maps, position);
|
||||
|
||||
|
@ -125,17 +125,17 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
return false;
|
||||
}
|
||||
|
||||
public void AddReservation(long position, long size)
|
||||
public void AddReservation(ulong position, ulong size)
|
||||
{
|
||||
_reservations.Add(position, new Range(position, size));
|
||||
}
|
||||
|
||||
public bool RemoveReservation(long position)
|
||||
public bool RemoveReservation(ulong position)
|
||||
{
|
||||
return _reservations.Remove(position);
|
||||
}
|
||||
|
||||
private Range BinarySearch(SortedList<long, Range> lst, long position)
|
||||
private Range BinarySearch(SortedList<ulong, Range> lst, ulong position)
|
||||
{
|
||||
int left = 0;
|
||||
int right = lst.Count - 1;
|
||||
|
@ -148,12 +148,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
|
||||
Range rg = lst.Values[middle];
|
||||
|
||||
if ((ulong)position >= rg.Start && (ulong)position < rg.End)
|
||||
if (position >= rg.Start && position < rg.End)
|
||||
{
|
||||
return rg;
|
||||
}
|
||||
|
||||
if ((ulong)position < rg.Start)
|
||||
if (position < rg.Start)
|
||||
{
|
||||
right = middle - 1;
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
return null;
|
||||
}
|
||||
|
||||
private Range BinarySearchLt(SortedList<long, Range> lst, long position)
|
||||
private Range BinarySearchLt(SortedList<ulong, Range> lst, ulong position)
|
||||
{
|
||||
Range ltRg = null;
|
||||
|
||||
|
@ -181,7 +181,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
|
||||
Range rg = lst.Values[middle];
|
||||
|
||||
if ((ulong)position < rg.Start)
|
||||
if (position < rg.Start)
|
||||
{
|
||||
right = middle - 1;
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
{
|
||||
left = middle + 1;
|
||||
|
||||
if ((ulong)position > rg.Start)
|
||||
if (position > rg.Start)
|
||||
{
|
||||
ltRg = rg;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
public uint PageSize;
|
||||
public AddressSpaceFlags Flags;
|
||||
public uint Padding;
|
||||
public long Offset;
|
||||
public ulong Offset;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct FreeSpaceArguments
|
||||
{
|
||||
public long Offset;
|
||||
public uint Pages;
|
||||
public uint PageSize;
|
||||
public ulong Offset;
|
||||
public uint Pages;
|
||||
public uint PageSize;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
|||
public int Kind;
|
||||
public int NvMapHandle;
|
||||
public int PageSize;
|
||||
public long BufferOffset;
|
||||
public long MappingSize;
|
||||
public long Offset;
|
||||
public ulong BufferOffset;
|
||||
public ulong MappingSize;
|
||||
public ulong Offset;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
struct UnmapBufferArguments
|
||||
{
|
||||
#pragma warning disable CS0649
|
||||
public long Offset;
|
||||
public ulong Offset;
|
||||
#pragma warning restore CS0649
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
|
|||
{
|
||||
NvMapHandle map = NvMapDeviceFile.GetMapFromHandle(Owner, commandBuffer.Mem);
|
||||
|
||||
var data = _memory.GetSpan((ulong)map.Address + commandBuffer.Offset, commandBuffer.WordsCount * 4);
|
||||
var data = _memory.GetSpan(map.Address + commandBuffer.Offset, commandBuffer.WordsCount * 4);
|
||||
|
||||
_device.Host1x.Submit(MemoryMarshal.Cast<byte, int>(data));
|
||||
}
|
||||
|
@ -253,12 +253,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
|
|||
if (va != NvMemoryAllocator.PteUnmapped && va <= uint.MaxValue && (va + (uint)map.Size) <= uint.MaxValue)
|
||||
{
|
||||
_memoryAllocator.AllocateRange(va, (uint)map.Size, freeAddressStartPosition);
|
||||
gmm.Map((ulong)map.Address, va, (uint)map.Size);
|
||||
map.DmaMapAddress = (long)va;
|
||||
gmm.Map(map.Address, va, (uint)map.Size);
|
||||
map.DmaMapAddress = va;
|
||||
}
|
||||
else
|
||||
{
|
||||
map.DmaMapAddress = unchecked((long)NvMemoryAllocator.PteUnmapped);
|
||||
map.DmaMapAddress = NvMemoryAllocator.PteUnmapped;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
|
|||
|
||||
int size = BitUtils.AlignUp(map.Size, (int)MemoryManager.PageSize);
|
||||
|
||||
long address = arguments.Address;
|
||||
ulong address = arguments.Address;
|
||||
|
||||
if (address == 0)
|
||||
{
|
||||
|
|
|
@ -5,11 +5,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
|
|||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct NvMapAlloc
|
||||
{
|
||||
public int Handle;
|
||||
public int HeapMask;
|
||||
public int Flags;
|
||||
public int Align;
|
||||
public long Kind;
|
||||
public long Address;
|
||||
public int Handle;
|
||||
public int HeapMask;
|
||||
public int Flags;
|
||||
public int Align;
|
||||
public long Kind;
|
||||
public ulong Address;
|
||||
}
|
||||
}
|
|
@ -5,10 +5,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
|
|||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct NvMapFree
|
||||
{
|
||||
public int Handle;
|
||||
public int Padding;
|
||||
public long Address;
|
||||
public int Size;
|
||||
public int Flags;
|
||||
public int Handle;
|
||||
public int Padding;
|
||||
public ulong Address;
|
||||
public int Size;
|
||||
public int Flags;
|
||||
}
|
||||
}
|
|
@ -5,15 +5,15 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
|
|||
class NvMapHandle
|
||||
{
|
||||
#pragma warning disable CS0649
|
||||
public int Handle;
|
||||
public int Id;
|
||||
public int Handle;
|
||||
public int Id;
|
||||
#pragma warning restore CS0649
|
||||
public int Size;
|
||||
public int Align;
|
||||
public int Kind;
|
||||
public long Address;
|
||||
public bool Allocated;
|
||||
public long DmaMapAddress;
|
||||
public int Size;
|
||||
public int Align;
|
||||
public int Kind;
|
||||
public ulong Address;
|
||||
public bool Allocated;
|
||||
public ulong DmaMapAddress;
|
||||
|
||||
private long _dupes;
|
||||
|
||||
|
|
|
@ -308,11 +308,11 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
|||
nvMapHandle = item.GraphicBuffer.Object.Buffer.NvMapId;
|
||||
}
|
||||
|
||||
int bufferOffset = item.GraphicBuffer.Object.Buffer.Surfaces[0].Offset;
|
||||
ulong bufferOffset = (ulong)item.GraphicBuffer.Object.Buffer.Surfaces[0].Offset;
|
||||
|
||||
NvMapHandle map = NvMapDeviceFile.GetMapFromHandle(layer.Owner, nvMapHandle);
|
||||
|
||||
ulong frameBufferAddress = (ulong)(map.Address + bufferOffset);
|
||||
ulong frameBufferAddress = map.Address + bufferOffset;
|
||||
|
||||
Format format = ConvertColorFormat(item.GraphicBuffer.Object.Buffer.Surfaces[0].ColorFormat);
|
||||
|
||||
|
|
Loading…
Reference in a new issue