More flexible memory manager (#307)
* Keep track mapped buffers with fixed offsets * Started rewriting the memory manager * Initial support for MapPhysicalMemory and UnmapPhysicalMemory, other tweaks * MapPhysicalMemory/UnmapPhysicalMemory support, other tweaks * Rebased * Optimize the map/unmap physical memory svcs * Integrate shared font support * Fix address space reserve alignment * Some fixes related to gpu memory mapping * Some cleanup * Only try uploading const buffers that are really used * Check if memory region is contiguous * Rebased * Add missing count increment on IsRegionModified * Check for reads/writes outside of the address space, optimize translation with a tail call
This commit is contained in:
@@ -10,9 +10,9 @@ namespace Ryujinx.HLE.OsHle.Services.Hid
|
||||
|
||||
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private HSharedMem HidSharedMem;
|
||||
private KSharedMemory HidSharedMem;
|
||||
|
||||
public IAppletResource(HSharedMem HidSharedMem)
|
||||
public IAppletResource(KSharedMemory HidSharedMem)
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
|
||||
198
Ryujinx.HLE/OsHle/Services/Nv/NvGpuAS/NvGpuASCtx.cs
Normal file
198
Ryujinx.HLE/OsHle/Services/Nv/NvGpuAS/NvGpuASCtx.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
using ChocolArm64.Memory;
|
||||
using Ryujinx.HLE.Gpu.Memory;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS
|
||||
{
|
||||
class NvGpuASCtx
|
||||
{
|
||||
public NvGpuVmm Vmm { get; private set; }
|
||||
|
||||
private class Range
|
||||
{
|
||||
public ulong Start { get; private set; }
|
||||
public ulong End { get; private set; }
|
||||
|
||||
public Range(long Position, long Size)
|
||||
{
|
||||
Start = (ulong)Position;
|
||||
End = (ulong)Size + Start;
|
||||
}
|
||||
}
|
||||
|
||||
private class MappedMemory : Range
|
||||
{
|
||||
public long PhysicalAddress { get; private set; }
|
||||
public bool VaAllocated { get; private set; }
|
||||
|
||||
public MappedMemory(
|
||||
long Position,
|
||||
long Size,
|
||||
long PhysicalAddress,
|
||||
bool VaAllocated) : base(Position, Size)
|
||||
{
|
||||
this.PhysicalAddress = PhysicalAddress;
|
||||
this.VaAllocated = VaAllocated;
|
||||
}
|
||||
}
|
||||
|
||||
private SortedList<long, Range> Maps;
|
||||
private SortedList<long, Range> Reservations;
|
||||
|
||||
public NvGpuASCtx(ServiceCtx Context)
|
||||
{
|
||||
Vmm = new NvGpuVmm(Context.Memory);
|
||||
|
||||
Maps = new SortedList<long, Range>();
|
||||
Reservations = new SortedList<long, Range>();
|
||||
}
|
||||
|
||||
public bool ValidateFixedBuffer(long Position, long Size)
|
||||
{
|
||||
long MapEnd = Position + Size;
|
||||
|
||||
//Check if size is valid (0 is also not allowed).
|
||||
if ((ulong)MapEnd <= (ulong)Position)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check if address is page aligned.
|
||||
if ((Position & NvGpuVmm.PageMask) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check if region is reserved.
|
||||
if (BinarySearch(Reservations, Position) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check for overlap with already mapped buffers.
|
||||
Range Map = BinarySearchLt(Maps, MapEnd);
|
||||
|
||||
if (Map != null && Map.End > (ulong)Position)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddMap(
|
||||
long Position,
|
||||
long Size,
|
||||
long PhysicalAddress,
|
||||
bool VaAllocated)
|
||||
{
|
||||
Maps.Add(Position, new MappedMemory(Position, Size, PhysicalAddress, VaAllocated));
|
||||
}
|
||||
|
||||
public bool RemoveMap(long Position, out long Size)
|
||||
{
|
||||
Size = 0;
|
||||
|
||||
if (Maps.Remove(Position, out Range Value))
|
||||
{
|
||||
MappedMemory Map = (MappedMemory)Value;
|
||||
|
||||
if (Map.VaAllocated)
|
||||
{
|
||||
Size = (long)(Map.End - Map.Start);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetMapPhysicalAddress(long Position, out long PhysicalAddress)
|
||||
{
|
||||
Range Map = BinarySearch(Maps, Position);
|
||||
|
||||
if (Map != null)
|
||||
{
|
||||
PhysicalAddress = ((MappedMemory)Map).PhysicalAddress;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
PhysicalAddress = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void AddReservation(long Position, long Size)
|
||||
{
|
||||
Reservations.Add(Position, new Range(Position, Size));
|
||||
}
|
||||
|
||||
public bool RemoveReservation(long Position)
|
||||
{
|
||||
return Reservations.Remove(Position);
|
||||
}
|
||||
|
||||
private Range BinarySearch(SortedList<long, Range> Lst, long Position)
|
||||
{
|
||||
int Left = 0;
|
||||
int Right = Lst.Count - 1;
|
||||
|
||||
while (Left <= Right)
|
||||
{
|
||||
int Size = Right - Left;
|
||||
|
||||
int Middle = Left + (Size >> 1);
|
||||
|
||||
Range Rg = Lst.Values[Middle];
|
||||
|
||||
if ((ulong)Position >= Rg.Start && (ulong)Position < Rg.End)
|
||||
{
|
||||
return Rg;
|
||||
}
|
||||
|
||||
if ((ulong)Position < Rg.Start)
|
||||
{
|
||||
Right = Middle - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Left = Middle + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Range BinarySearchLt(SortedList<long, Range> Lst, long Position)
|
||||
{
|
||||
Range LtRg = null;
|
||||
|
||||
int Left = 0;
|
||||
int Right = Lst.Count - 1;
|
||||
|
||||
while (Left <= Right)
|
||||
{
|
||||
int Size = Right - Left;
|
||||
|
||||
int Middle = Left + (Size >> 1);
|
||||
|
||||
Range Rg = Lst.Values[Middle];
|
||||
|
||||
if ((ulong)Position < Rg.Start)
|
||||
{
|
||||
Right = Middle - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Left = Middle + 1;
|
||||
|
||||
LtRg = Rg;
|
||||
}
|
||||
}
|
||||
|
||||
return LtRg;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,13 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS
|
||||
{
|
||||
private const int FlagFixedOffset = 1;
|
||||
|
||||
private static ConcurrentDictionary<Process, NvGpuVmm> Vmms;
|
||||
private const int FlagRemapSubRange = 0x100;
|
||||
|
||||
private static ConcurrentDictionary<Process, NvGpuASCtx> ASCtxs;
|
||||
|
||||
static NvGpuASIoctl()
|
||||
{
|
||||
Vmms = new ConcurrentDictionary<Process, NvGpuVmm>();
|
||||
ASCtxs = new ConcurrentDictionary<Process, NvGpuASCtx>();
|
||||
}
|
||||
|
||||
public static int ProcessIoctl(ServiceCtx Context, int Cmd)
|
||||
@@ -29,7 +31,7 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS
|
||||
case 0x4106: return MapBufferEx (Context);
|
||||
case 0x4108: return GetVaRegions(Context);
|
||||
case 0x4109: return InitializeEx(Context);
|
||||
case 0x4114: return Remap (Context);
|
||||
case 0x4114: return Remap (Context, Cmd);
|
||||
}
|
||||
|
||||
throw new NotImplementedException(Cmd.ToString("x8"));
|
||||
@@ -52,29 +54,38 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS
|
||||
|
||||
NvGpuASAllocSpace Args = AMemoryHelper.Read<NvGpuASAllocSpace>(Context.Memory, InputPosition);
|
||||
|
||||
NvGpuVmm Vmm = GetVmm(Context);
|
||||
NvGpuASCtx ASCtx = GetASCtx(Context);
|
||||
|
||||
ulong Size = (ulong)Args.Pages *
|
||||
(ulong)Args.PageSize;
|
||||
|
||||
if ((Args.Flags & FlagFixedOffset) != 0)
|
||||
{
|
||||
Args.Offset = Vmm.Reserve(Args.Offset, (long)Size, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Args.Offset = Vmm.Reserve((long)Size, 1);
|
||||
}
|
||||
|
||||
int Result = NvResult.Success;
|
||||
|
||||
if (Args.Offset < 0)
|
||||
lock (ASCtx)
|
||||
{
|
||||
Args.Offset = 0;
|
||||
//Note: When the fixed offset flag is not set,
|
||||
//the Offset field holds the alignment size instead.
|
||||
if ((Args.Flags & FlagFixedOffset) != 0)
|
||||
{
|
||||
Args.Offset = ASCtx.Vmm.ReserveFixed(Args.Offset, (long)Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
Args.Offset = ASCtx.Vmm.Reserve((long)Size, Args.Offset);
|
||||
}
|
||||
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"No memory to allocate size {Size:x16}!");
|
||||
if (Args.Offset < 0)
|
||||
{
|
||||
Args.Offset = 0;
|
||||
|
||||
Result = NvResult.OutOfMemory;
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Failed to allocate size {Size:x16}!");
|
||||
|
||||
Result = NvResult.OutOfMemory;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASCtx.AddReservation(Args.Offset, (long)Size);
|
||||
}
|
||||
}
|
||||
|
||||
AMemoryHelper.Write(Context.Memory, OutputPosition, Args);
|
||||
@@ -89,14 +100,29 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS
|
||||
|
||||
NvGpuASAllocSpace Args = AMemoryHelper.Read<NvGpuASAllocSpace>(Context.Memory, InputPosition);
|
||||
|
||||
NvGpuVmm Vmm = GetVmm(Context);
|
||||
NvGpuASCtx ASCtx = GetASCtx(Context);
|
||||
|
||||
ulong Size = (ulong)Args.Pages *
|
||||
(ulong)Args.PageSize;
|
||||
int Result = NvResult.Success;
|
||||
|
||||
Vmm.Free(Args.Offset, (long)Size);
|
||||
lock (ASCtx)
|
||||
{
|
||||
ulong Size = (ulong)Args.Pages *
|
||||
(ulong)Args.PageSize;
|
||||
|
||||
return NvResult.Success;
|
||||
if (ASCtx.RemoveReservation(Args.Offset))
|
||||
{
|
||||
ASCtx.Vmm.Free(Args.Offset, (long)Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv,
|
||||
$"Failed to free offset 0x{Args.Offset:x16} size 0x{Size:x16}!");
|
||||
|
||||
Result = NvResult.InvalidInput;
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
private static int UnmapBuffer(ServiceCtx Context)
|
||||
@@ -106,11 +132,21 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS
|
||||
|
||||
NvGpuASUnmapBuffer Args = AMemoryHelper.Read<NvGpuASUnmapBuffer>(Context.Memory, InputPosition);
|
||||
|
||||
NvGpuVmm Vmm = GetVmm(Context);
|
||||
NvGpuASCtx ASCtx = GetASCtx(Context);
|
||||
|
||||
if (!Vmm.Unmap(Args.Offset))
|
||||
lock (ASCtx)
|
||||
{
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Invalid buffer offset {Args.Offset:x16}!");
|
||||
if (ASCtx.RemoveMap(Args.Offset, out long Size))
|
||||
{
|
||||
if (Size != 0)
|
||||
{
|
||||
ASCtx.Vmm.Free(Args.Offset, Size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Invalid buffer offset {Args.Offset:x16}!");
|
||||
}
|
||||
}
|
||||
|
||||
return NvResult.Success;
|
||||
@@ -118,12 +154,14 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS
|
||||
|
||||
private static int MapBufferEx(ServiceCtx Context)
|
||||
{
|
||||
const string MapErrorMsg = "Failed to map fixed buffer with offset 0x{0:x16} and size 0x{1:x16}!";
|
||||
|
||||
long InputPosition = Context.Request.GetBufferType0x21().Position;
|
||||
long OutputPosition = Context.Request.GetBufferType0x22().Position;
|
||||
|
||||
NvGpuASMapBufferEx Args = AMemoryHelper.Read<NvGpuASMapBufferEx>(Context.Memory, InputPosition);
|
||||
|
||||
NvGpuVmm Vmm = GetVmm(Context);
|
||||
NvGpuASCtx ASCtx = GetASCtx(Context);
|
||||
|
||||
NvMapHandle Map = NvMapIoctl.GetNvMapWithFb(Context, Args.NvMapHandle);
|
||||
|
||||
@@ -134,7 +172,39 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS
|
||||
return NvResult.InvalidInput;
|
||||
}
|
||||
|
||||
long PA = Map.Address + Args.BufferOffset;
|
||||
long PA;
|
||||
|
||||
if ((Args.Flags & FlagRemapSubRange) != 0)
|
||||
{
|
||||
lock (ASCtx)
|
||||
{
|
||||
if (ASCtx.TryGetMapPhysicalAddress(Args.Offset, out PA))
|
||||
{
|
||||
long VA = Args.Offset + Args.BufferOffset;
|
||||
|
||||
PA += Args.BufferOffset;
|
||||
|
||||
if (ASCtx.Vmm.Map(PA, VA, Args.MappingSize) < 0)
|
||||
{
|
||||
string Msg = string.Format(MapErrorMsg, VA, Args.MappingSize);
|
||||
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, Msg);
|
||||
|
||||
return NvResult.InvalidInput;
|
||||
}
|
||||
|
||||
return NvResult.Success;
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Address 0x{Args.Offset:x16} not mapped!");
|
||||
|
||||
return NvResult.InvalidInput;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PA = Map.Address + Args.BufferOffset;
|
||||
|
||||
long Size = Args.MappingSize;
|
||||
|
||||
@@ -145,40 +215,44 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS
|
||||
|
||||
int Result = NvResult.Success;
|
||||
|
||||
//Note: When the fixed offset flag is not set,
|
||||
//the Offset field holds the alignment size instead.
|
||||
if ((Args.Flags & FlagFixedOffset) != 0)
|
||||
lock (ASCtx)
|
||||
{
|
||||
long MapEnd = Args.Offset + Args.MappingSize;
|
||||
//Note: When the fixed offset flag is not set,
|
||||
//the Offset field holds the alignment size instead.
|
||||
bool VaAllocated = (Args.Flags & FlagFixedOffset) == 0;
|
||||
|
||||
if ((ulong)MapEnd <= (ulong)Args.Offset)
|
||||
if (!VaAllocated)
|
||||
{
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Offset 0x{Args.Offset:x16} and size 0x{Args.MappingSize:x16} results in a overflow!");
|
||||
if (ASCtx.ValidateFixedBuffer(Args.Offset, Size))
|
||||
{
|
||||
Args.Offset = ASCtx.Vmm.Map(PA, Args.Offset, Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
string Msg = string.Format(MapErrorMsg, Args.Offset, Size);
|
||||
|
||||
return NvResult.InvalidInput;
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, Msg);
|
||||
|
||||
Result = NvResult.InvalidInput;
|
||||
}
|
||||
}
|
||||
|
||||
if ((Args.Offset & NvGpuVmm.PageMask) != 0)
|
||||
else
|
||||
{
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Offset 0x{Args.Offset:x16} is not page aligned!");
|
||||
|
||||
return NvResult.InvalidInput;
|
||||
Args.Offset = ASCtx.Vmm.Map(PA, Size);
|
||||
}
|
||||
|
||||
Args.Offset = Vmm.Map(PA, Args.Offset, Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
Args.Offset = Vmm.Map(PA, Size);
|
||||
|
||||
if (Args.Offset < 0)
|
||||
{
|
||||
Args.Offset = 0;
|
||||
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"No memory to map size {Args.MappingSize:x16}!");
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Failed to map size 0x{Size:x16}!");
|
||||
|
||||
Result = NvResult.InvalidInput;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASCtx.AddMap(Args.Offset, Size, PA, VaAllocated);
|
||||
}
|
||||
}
|
||||
|
||||
AMemoryHelper.Write(Context.Memory, OutputPosition, Args);
|
||||
@@ -206,38 +280,50 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS
|
||||
return NvResult.Success;
|
||||
}
|
||||
|
||||
private static int Remap(ServiceCtx Context)
|
||||
private static int Remap(ServiceCtx Context, int Cmd)
|
||||
{
|
||||
int Count = ((Cmd >> 16) & 0xff) / 0x14;
|
||||
|
||||
long InputPosition = Context.Request.GetBufferType0x21().Position;
|
||||
|
||||
NvGpuASRemap Args = AMemoryHelper.Read<NvGpuASRemap>(Context.Memory, InputPosition);
|
||||
|
||||
NvGpuVmm Vmm = GetVmm(Context);
|
||||
|
||||
NvMapHandle Map = NvMapIoctl.GetNvMapWithFb(Context, Args.NvMapHandle);
|
||||
|
||||
if (Map == null)
|
||||
for (int Index = 0; Index < Count; Index++, InputPosition += 0x14)
|
||||
{
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Invalid NvMap handle 0x{Args.NvMapHandle:x8}!");
|
||||
NvGpuASRemap Args = AMemoryHelper.Read<NvGpuASRemap>(Context.Memory, InputPosition);
|
||||
|
||||
return NvResult.InvalidInput;
|
||||
NvGpuVmm Vmm = GetASCtx(Context).Vmm;
|
||||
|
||||
NvMapHandle Map = NvMapIoctl.GetNvMapWithFb(Context, Args.NvMapHandle);
|
||||
|
||||
if (Map == null)
|
||||
{
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv, $"Invalid NvMap handle 0x{Args.NvMapHandle:x8}!");
|
||||
|
||||
return NvResult.InvalidInput;
|
||||
}
|
||||
|
||||
long Result = Vmm.Map(Map.Address, (long)(uint)Args.Offset << 16,
|
||||
(long)(uint)Args.Pages << 16);
|
||||
|
||||
if (Result < 0)
|
||||
{
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceNv,
|
||||
$"Page 0x{Args.Offset:x16} size 0x{Args.Pages:x16} not allocated!");
|
||||
|
||||
return NvResult.InvalidInput;
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME: This is most likely wrong...
|
||||
Vmm.Map(Map.Address, (long)(uint)Args.Offset << 16,
|
||||
(long)(uint)Args.Pages << 16);
|
||||
|
||||
return NvResult.Success;
|
||||
}
|
||||
|
||||
public static NvGpuVmm GetVmm(ServiceCtx Context)
|
||||
public static NvGpuASCtx GetASCtx(ServiceCtx Context)
|
||||
{
|
||||
return Vmms.GetOrAdd(Context.Process, (Key) => new NvGpuVmm(Context.Memory));
|
||||
return ASCtxs.GetOrAdd(Context.Process, (Key) => new NvGpuASCtx(Context));
|
||||
}
|
||||
|
||||
public static void UnloadProcess(Process Process)
|
||||
{
|
||||
Vmms.TryRemove(Process, out _);
|
||||
ASCtxs.TryRemove(Process, out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvHostChannel
|
||||
|
||||
NvHostChannelSubmitGpfifo Args = AMemoryHelper.Read<NvHostChannelSubmitGpfifo>(Context.Memory, InputPosition);
|
||||
|
||||
NvGpuVmm Vmm = NvGpuASIoctl.GetVmm(Context);
|
||||
NvGpuVmm Vmm = NvGpuASIoctl.GetASCtx(Context).Vmm;;
|
||||
|
||||
for (int Index = 0; Index < Args.NumEntries; Index++)
|
||||
{
|
||||
@@ -162,7 +162,7 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvHostChannel
|
||||
|
||||
NvHostChannelSubmitGpfifo Args = AMemoryHelper.Read<NvHostChannelSubmitGpfifo>(Context.Memory, InputPosition);
|
||||
|
||||
NvGpuVmm Vmm = NvGpuASIoctl.GetVmm(Context);
|
||||
NvGpuVmm Vmm = NvGpuASIoctl.GetASCtx(Context).Vmm;;
|
||||
|
||||
for (int Index = 0; Index < Args.NumEntries; Index++)
|
||||
{
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvHostCtrl
|
||||
|
||||
Context.Ns.Log.PrintDebug(Logging.LogClass.ServiceNv, $"Got setting {Domain}!{Name}");
|
||||
}
|
||||
|
||||
|
||||
return NvResult.Success;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvMap
|
||||
{
|
||||
public int Handle;
|
||||
public int Padding;
|
||||
public long RefCount;
|
||||
public long Address;
|
||||
public int Size;
|
||||
public int Flags;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvMap
|
||||
|
||||
public long DecrementRefCount()
|
||||
{
|
||||
return Interlocked.Decrement(ref Dupes) + 1;
|
||||
return Interlocked.Decrement(ref Dupes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,8 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvMap
|
||||
{
|
||||
//When the address is zero, we need to allocate
|
||||
//our own backing memory for the NvMap.
|
||||
if (!Context.Ns.Os.Allocator.TryAllocate((uint)Size, out Address))
|
||||
//TODO: Is this allocation inside the transfer memory?
|
||||
if (!Context.Ns.Memory.Allocator.TryAllocate((uint)Size, out Address))
|
||||
{
|
||||
Result = NvResult.OutOfMemory;
|
||||
}
|
||||
@@ -163,23 +164,22 @@ namespace Ryujinx.HLE.OsHle.Services.Nv.NvMap
|
||||
return NvResult.InvalidInput;
|
||||
}
|
||||
|
||||
long OldRefCount = Map.DecrementRefCount();
|
||||
|
||||
if (OldRefCount <= 1)
|
||||
if (Map.DecrementRefCount() <= 0)
|
||||
{
|
||||
DeleteNvMap(Context, Args.Handle);
|
||||
|
||||
Context.Ns.Log.PrintInfo(LogClass.ServiceNv, $"Deleted map {Args.Handle}!");
|
||||
|
||||
Args.Flags = 0;
|
||||
Args.Address = Map.Address;
|
||||
Args.Flags = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Args.Flags = FlagNotFreedYet;
|
||||
Args.Address = 0;
|
||||
Args.Flags = FlagNotFreedYet;
|
||||
}
|
||||
|
||||
Args.RefCount = OldRefCount;
|
||||
Args.Size = Map.Size;
|
||||
Args.Size = Map.Size;
|
||||
|
||||
AMemoryHelper.Write(Context.Memory, OutputPosition, Args);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Ryujinx.HLE.Font;
|
||||
using Ryujinx.HLE.OsHle.Font;
|
||||
using Ryujinx.HLE.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace Ryujinx.HLE.OsHle.Services.Pl
|
||||
{
|
||||
SharedFontType FontType = (SharedFontType)Context.RequestData.ReadInt32();
|
||||
|
||||
Context.Ns.Font.Load(FontType);
|
||||
|
||||
//We don't need to do anything here because we do lazy initialization
|
||||
//on SharedFontManager (the font is loaded when necessary).
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,9 @@ namespace Ryujinx.HLE.OsHle.Services.Pl
|
||||
{
|
||||
SharedFontType FontType = (SharedFontType)Context.RequestData.ReadInt32();
|
||||
|
||||
Context.ResponseData.Write(Context.Ns.Font.GetLoadState(FontType));
|
||||
//1 (true) indicates that the font is already loaded.
|
||||
//All fonts are already loaded.
|
||||
Context.ResponseData.Write(1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -45,7 +47,7 @@ namespace Ryujinx.HLE.OsHle.Services.Pl
|
||||
{
|
||||
SharedFontType FontType = (SharedFontType)Context.RequestData.ReadInt32();
|
||||
|
||||
Context.ResponseData.Write(Context.Ns.Font.GetFontSize(FontType));
|
||||
Context.ResponseData.Write(Context.Ns.Os.Font.GetFontSize(FontType));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -54,13 +56,15 @@ namespace Ryujinx.HLE.OsHle.Services.Pl
|
||||
{
|
||||
SharedFontType FontType = (SharedFontType)Context.RequestData.ReadInt32();
|
||||
|
||||
Context.ResponseData.Write(Context.Ns.Font.GetSharedMemoryAddressOffset(FontType));
|
||||
Context.ResponseData.Write(Context.Ns.Os.Font.GetSharedMemoryAddressOffset(FontType));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetSharedMemoryNativeHandle(ServiceCtx Context)
|
||||
{
|
||||
Context.Ns.Os.Font.EnsureInitialized();
|
||||
|
||||
int Handle = Context.Process.HandleTable.OpenHandle(Context.Ns.Os.FontSharedMem);
|
||||
|
||||
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
|
||||
@@ -68,50 +72,54 @@ namespace Ryujinx.HLE.OsHle.Services.Pl
|
||||
return 0;
|
||||
}
|
||||
|
||||
private uint AddFontToOrderOfPriorityList(ServiceCtx Context, SharedFontType FontType, uint BufferPos, out uint LoadState)
|
||||
public long GetSharedFontInOrderOfPriority(ServiceCtx Context)
|
||||
{
|
||||
long TypesPosition = Context.Request.ReceiveBuff[0].Position;
|
||||
long TypesSize = Context.Request.ReceiveBuff[0].Size;
|
||||
long LanguageCode = Context.RequestData.ReadInt64();
|
||||
int LoadedCount = 0;
|
||||
|
||||
long OffsetsPosition = Context.Request.ReceiveBuff[1].Position;
|
||||
long OffsetsSize = Context.Request.ReceiveBuff[1].Size;
|
||||
for (SharedFontType Type = 0; Type < SharedFontType.Count; Type++)
|
||||
{
|
||||
int Offset = (int)Type * 4;
|
||||
|
||||
if (!AddFontToOrderOfPriorityList(Context, (SharedFontType)Type, Offset))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
LoadedCount++;
|
||||
}
|
||||
|
||||
Context.ResponseData.Write(LoadedCount);
|
||||
Context.ResponseData.Write((int)SharedFontType.Count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private bool AddFontToOrderOfPriorityList(ServiceCtx Context, SharedFontType FontType, int Offset)
|
||||
{
|
||||
long TypesPosition = Context.Request.ReceiveBuff[0].Position;
|
||||
long TypesSize = Context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
long OffsetsPosition = Context.Request.ReceiveBuff[1].Position;
|
||||
long OffsetsSize = Context.Request.ReceiveBuff[1].Size;
|
||||
|
||||
long FontSizeBufferPosition = Context.Request.ReceiveBuff[2].Position;
|
||||
long FontSizeBufferSize = Context.Request.ReceiveBuff[2].Size;
|
||||
|
||||
LoadState = Context.Ns.Font.GetLoadState(FontType);
|
||||
|
||||
if (BufferPos >= TypesSize || BufferPos >= OffsetsSize || BufferPos >= FontSizeBufferSize)
|
||||
if ((uint)Offset + 4 > (uint)TypesSize ||
|
||||
(uint)Offset + 4 > (uint)OffsetsSize ||
|
||||
(uint)Offset + 4 > (uint)FontSizeBufferSize)
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
Context.Memory.WriteUInt32(TypesPosition + BufferPos, (uint)FontType);
|
||||
Context.Memory.WriteUInt32(OffsetsPosition + BufferPos, Context.Ns.Font.GetSharedMemoryAddressOffset(FontType));
|
||||
Context.Memory.WriteUInt32(FontSizeBufferPosition + BufferPos, Context.Ns.Font.GetFontSize(FontType));
|
||||
Context.Memory.WriteInt32(TypesPosition + Offset, (int)FontType);
|
||||
|
||||
BufferPos += 4;
|
||||
Context.Memory.WriteInt32(OffsetsPosition + Offset, Context.Ns.Os.Font.GetSharedMemoryAddressOffset(FontType));
|
||||
|
||||
return BufferPos;
|
||||
}
|
||||
Context.Memory.WriteInt32(FontSizeBufferPosition + Offset, Context.Ns.Os.Font.GetFontSize(FontType));
|
||||
|
||||
public long GetSharedFontInOrderOfPriority(ServiceCtx Context)
|
||||
{
|
||||
ulong LanguageCode = Context.RequestData.ReadUInt64();
|
||||
uint LoadedCount = 0;
|
||||
uint BufferPos = 0;
|
||||
uint Loaded = 0;
|
||||
|
||||
for (int Type = 0; Type < Context.Ns.Font.Count; Type++)
|
||||
{
|
||||
BufferPos = AddFontToOrderOfPriorityList(Context, (SharedFontType)Type, BufferPos, out Loaded);
|
||||
LoadedCount += Loaded;
|
||||
}
|
||||
|
||||
Context.ResponseData.Write(LoadedCount);
|
||||
Context.ResponseData.Write(Context.Ns.Font.Count);
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ namespace Ryujinx.HLE.OsHle.Services.Android
|
||||
|
||||
int Slot = GetFreeSlotBlocking(Width, Height);
|
||||
|
||||
return MakeReplyParcel(Context, Slot, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
return MakeReplyParcel(Context, Slot, 1, 0x24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
private long GbpQueueBuffer(ServiceCtx Context, BinaryReader ParcelReader)
|
||||
|
||||
Reference in New Issue
Block a user