Allow all methods to read from non-contiguous locations

This commit is contained in:
gdkchan 2018-11-22 00:57:31 -03:00
commit 964e0069fd
17 changed files with 288 additions and 181 deletions

View file

@ -1,13 +0,0 @@
using System;
namespace ChocolArm64.Exceptions
{
public class VmmAccessException : Exception
{
private const string ExMsg = "Memory region at 0x{0:X16} with size 0x{1:X16} is not contiguous!";
public VmmAccessException() { }
public VmmAccessException(long position, long size) : base(string.Format(ExMsg, position, size)) { }
}
}

View file

@ -26,22 +26,26 @@ namespace ChocolArm64.Memory
{ {
long size = Marshal.SizeOf<T>(); long size = Marshal.SizeOf<T>();
memory.EnsureRangeIsValid(position, size); byte[] data = memory.ReadBytes(position, size);
IntPtr ptr = (IntPtr)memory.Translate(position); fixed (byte* ptr = data)
{
return Marshal.PtrToStructure<T>(ptr); return Marshal.PtrToStructure<T>((IntPtr)ptr);
}
} }
public unsafe static void Write<T>(MemoryManager memory, long position, T value) where T : struct public unsafe static void Write<T>(MemoryManager memory, long position, T value) where T : struct
{ {
long size = Marshal.SizeOf<T>(); long size = Marshal.SizeOf<T>();
memory.EnsureRangeIsValid(position, size); byte[] data = new byte[size];
IntPtr ptr = (IntPtr)memory.TranslateWrite(position); fixed (byte* ptr = data)
{
Marshal.StructureToPtr<T>(value, (IntPtr)ptr, false);
}
Marshal.StructureToPtr<T>(value, ptr, false); memory.WriteBytes(position, data);
} }
public static string ReadAsciiString(MemoryManager memory, long position, long maxSize = -1) public static string ReadAsciiString(MemoryManager memory, long position, long maxSize = -1)

View file

@ -362,9 +362,36 @@ namespace ChocolArm64.Memory
public void ReadBytes(long position, byte[] data, int startIndex, int size) public void ReadBytes(long position, byte[] data, int startIndex, int size)
{ {
//Note: This will be moved later. //Note: This will be moved later.
EnsureRangeIsValid(position, (uint)size); long endAddr = position + size;
Marshal.Copy((IntPtr)Translate(position), data, startIndex, size); if ((ulong)size > int.MaxValue)
{
throw new ArgumentOutOfRangeException(nameof(size));
}
if ((ulong)endAddr < (ulong)position)
{
throw new ArgumentOutOfRangeException(nameof(position));
}
int offset = startIndex;
while ((ulong)position < (ulong)endAddr)
{
long pageLimit = (position + PageSize) & ~(long)PageMask;
if ((ulong)pageLimit > (ulong)endAddr)
{
pageLimit = endAddr;
}
int copySize = (int)(pageLimit - position);
Marshal.Copy((IntPtr)Translate(position), data, offset, copySize);
position += copySize;
offset += copySize;
}
} }
public void WriteSByte(long position, sbyte value) public void WriteSByte(long position, sbyte value)
@ -533,22 +560,48 @@ namespace ChocolArm64.Memory
public void WriteBytes(long position, byte[] data, int startIndex, int size) public void WriteBytes(long position, byte[] data, int startIndex, int size)
{ {
//Note: This will be moved later. //Note: This will be moved later.
//Using Translate instead of TranslateWrite is on purpose. long endAddr = position + size;
EnsureRangeIsValid(position, (uint)size);
Marshal.Copy(data, startIndex, (IntPtr)Translate(position), size); if ((ulong)endAddr < (ulong)position)
{
throw new ArgumentOutOfRangeException(nameof(position));
}
int offset = startIndex;
while ((ulong)position < (ulong)endAddr)
{
long pageLimit = (position + PageSize) & ~(long)PageMask;
if ((ulong)pageLimit > (ulong)endAddr)
{
pageLimit = endAddr;
}
int copySize = (int)(pageLimit - position);
Marshal.Copy(data, offset, (IntPtr)TranslateWrite(position), copySize);
position += copySize;
offset += copySize;
}
} }
public void CopyBytes(long src, long dst, long size) public void CopyBytes(long src, long dst, long size)
{ {
//Note: This will be moved later. //Note: This will be moved later.
EnsureRangeIsValid(src, size); if (IsContiguous(src, size) &&
EnsureRangeIsValid(dst, size); IsContiguous(dst, size))
{
byte* srcPtr = Translate(src);
byte* dstPtr = TranslateWrite(dst);
byte* srcPtr = Translate(src); Buffer.MemoryCopy(srcPtr, dstPtr, size, size);
byte* dstPtr = TranslateWrite(dst); }
else
Buffer.MemoryCopy(srcPtr, dstPtr, size, size); {
WriteBytes(dst, ReadBytes(src, size));
}
} }
public void Map(long va, long pa, long size) public void Map(long va, long pa, long size)
@ -797,14 +850,21 @@ Unmapped:
} }
} }
public IntPtr GetHostAddress(long position, long size) public bool TryGetHostAddress(long position, long size, out IntPtr ptr)
{ {
EnsureRangeIsValid(position, size); if (IsContiguous(position, size))
{
ptr = (IntPtr)Translate(position);
return (IntPtr)Translate(position); return true;
}
ptr = IntPtr.Zero;
return false;
} }
internal void EnsureRangeIsValid(long position, long size) private bool IsContiguous(long position, long size)
{ {
long endPos = position + size; long endPos = position + size;
@ -818,12 +878,14 @@ Unmapped:
if (pa != expectedPa) if (pa != expectedPa)
{ {
throw new VmmAccessException(position, size); return false;
} }
position += PageSize; position += PageSize;
expectedPa += PageSize; expectedPa += PageSize;
} }
return true;
} }
public bool IsValidPosition(long position) public bool IsValidPosition(long position)

View file

@ -1,5 +1,3 @@
using System;
namespace Ryujinx.Graphics.Gal namespace Ryujinx.Graphics.Gal
{ {
public struct GalVertexAttrib public struct GalVertexAttrib
@ -7,7 +5,7 @@ namespace Ryujinx.Graphics.Gal
public int Index { get; private set; } public int Index { get; private set; }
public bool IsConst { get; private set; } public bool IsConst { get; private set; }
public int Offset { get; private set; } public int Offset { get; private set; }
public IntPtr Pointer { get; private set; } public byte[] Data { get; private set; }
public GalVertexAttribSize Size { get; private set; } public GalVertexAttribSize Size { get; private set; }
public GalVertexAttribType Type { get; private set; } public GalVertexAttribType Type { get; private set; }
@ -18,14 +16,14 @@ namespace Ryujinx.Graphics.Gal
int Index, int Index,
bool IsConst, bool IsConst,
int Offset, int Offset,
IntPtr Pointer, byte[] Data,
GalVertexAttribSize Size, GalVertexAttribSize Size,
GalVertexAttribType Type, GalVertexAttribType Type,
bool IsBgra) bool IsBgra)
{ {
this.Index = Index; this.Index = Index;
this.IsConst = IsConst; this.IsConst = IsConst;
this.Pointer = Pointer; this.Data = Data;
this.Offset = Offset; this.Offset = Offset;
this.Size = Size; this.Size = Size;
this.Type = Type; this.Type = Type;

View file

@ -12,5 +12,6 @@ namespace Ryujinx.Graphics.Gal
bool IsCached(long Key, long Size); bool IsCached(long Key, long Size);
void SetData(long Key, long Size, IntPtr HostAddress); void SetData(long Key, long Size, IntPtr HostAddress);
void SetData(long Key, byte[] Data);
} }
} }

View file

@ -22,6 +22,7 @@ namespace Ryujinx.Graphics.Gal
bool IsIboCached(long Key, long DataSize); bool IsIboCached(long Key, long DataSize);
void CreateVbo(long Key, int DataSize, IntPtr HostAddress); void CreateVbo(long Key, int DataSize, IntPtr HostAddress);
void CreateVbo(long Key, byte[] Data);
void CreateIbo(long Key, int DataSize, IntPtr HostAddress); void CreateIbo(long Key, int DataSize, IntPtr HostAddress);
void CreateIbo(long Key, int DataSize, byte[] Buffer); void CreateIbo(long Key, int DataSize, byte[] Buffer);

View file

@ -44,6 +44,14 @@ namespace Ryujinx.Graphics.Gal.OpenGL
} }
} }
public void SetData(long Key, byte[] Data)
{
if (Cache.TryGetValue(Key, out OGLStreamBuffer Buffer))
{
Buffer.SetData(Data);
}
}
public bool TryGetUbo(long Key, out int UboHandle) public bool TryGetUbo(long Key, out int UboHandle)
{ {
if (Cache.TryGetValue(Key, out OGLStreamBuffer Buffer)) if (Cache.TryGetValue(Key, out OGLStreamBuffer Buffer))

View file

@ -600,122 +600,125 @@ namespace Ryujinx.Graphics.Gal.OpenGL
ThrowUnsupportedAttrib(Attrib); ThrowUnsupportedAttrib(Attrib);
} }
if (Attrib.Type == GalVertexAttribType.Unorm) fixed (byte* Ptr = Attrib.Data)
{ {
switch (Attrib.Size) if (Attrib.Type == GalVertexAttribType.Unorm)
{ {
case GalVertexAttribSize._8: switch (Attrib.Size)
case GalVertexAttribSize._8_8: {
case GalVertexAttribSize._8_8_8: case GalVertexAttribSize._8:
case GalVertexAttribSize._8_8_8_8: case GalVertexAttribSize._8_8:
GL.VertexAttrib4N((uint)Attrib.Index, (byte*)Attrib.Pointer); case GalVertexAttribSize._8_8_8:
break; case GalVertexAttribSize._8_8_8_8:
GL.VertexAttrib4N((uint)Attrib.Index, Ptr);
break;
case GalVertexAttribSize._16: case GalVertexAttribSize._16:
case GalVertexAttribSize._16_16: case GalVertexAttribSize._16_16:
case GalVertexAttribSize._16_16_16: case GalVertexAttribSize._16_16_16:
case GalVertexAttribSize._16_16_16_16: case GalVertexAttribSize._16_16_16_16:
GL.VertexAttrib4N((uint)Attrib.Index, (ushort*)Attrib.Pointer); GL.VertexAttrib4N((uint)Attrib.Index, (ushort*)Ptr);
break; break;
case GalVertexAttribSize._32: case GalVertexAttribSize._32:
case GalVertexAttribSize._32_32: case GalVertexAttribSize._32_32:
case GalVertexAttribSize._32_32_32: case GalVertexAttribSize._32_32_32:
case GalVertexAttribSize._32_32_32_32: case GalVertexAttribSize._32_32_32_32:
GL.VertexAttrib4N((uint)Attrib.Index, (uint*)Attrib.Pointer); GL.VertexAttrib4N((uint)Attrib.Index, (uint*)Ptr);
break; break;
}
} }
} else if (Attrib.Type == GalVertexAttribType.Snorm)
else if (Attrib.Type == GalVertexAttribType.Snorm)
{
switch (Attrib.Size)
{ {
case GalVertexAttribSize._8: switch (Attrib.Size)
case GalVertexAttribSize._8_8: {
case GalVertexAttribSize._8_8_8: case GalVertexAttribSize._8:
case GalVertexAttribSize._8_8_8_8: case GalVertexAttribSize._8_8:
GL.VertexAttrib4N((uint)Attrib.Index, (sbyte*)Attrib.Pointer); case GalVertexAttribSize._8_8_8:
break; case GalVertexAttribSize._8_8_8_8:
GL.VertexAttrib4N((uint)Attrib.Index, (sbyte*)Ptr);
break;
case GalVertexAttribSize._16: case GalVertexAttribSize._16:
case GalVertexAttribSize._16_16: case GalVertexAttribSize._16_16:
case GalVertexAttribSize._16_16_16: case GalVertexAttribSize._16_16_16:
case GalVertexAttribSize._16_16_16_16: case GalVertexAttribSize._16_16_16_16:
GL.VertexAttrib4N((uint)Attrib.Index, (short*)Attrib.Pointer); GL.VertexAttrib4N((uint)Attrib.Index, (short*)Ptr);
break; break;
case GalVertexAttribSize._32: case GalVertexAttribSize._32:
case GalVertexAttribSize._32_32: case GalVertexAttribSize._32_32:
case GalVertexAttribSize._32_32_32: case GalVertexAttribSize._32_32_32:
case GalVertexAttribSize._32_32_32_32: case GalVertexAttribSize._32_32_32_32:
GL.VertexAttrib4N((uint)Attrib.Index, (int*)Attrib.Pointer); GL.VertexAttrib4N((uint)Attrib.Index, (int*)Ptr);
break; break;
}
} }
} else if (Attrib.Type == GalVertexAttribType.Uint)
else if (Attrib.Type == GalVertexAttribType.Uint)
{
switch (Attrib.Size)
{ {
case GalVertexAttribSize._8: switch (Attrib.Size)
case GalVertexAttribSize._8_8: {
case GalVertexAttribSize._8_8_8: case GalVertexAttribSize._8:
case GalVertexAttribSize._8_8_8_8: case GalVertexAttribSize._8_8:
GL.VertexAttribI4((uint)Attrib.Index, (byte*)Attrib.Pointer); case GalVertexAttribSize._8_8_8:
break; case GalVertexAttribSize._8_8_8_8:
GL.VertexAttribI4((uint)Attrib.Index, Ptr);
break;
case GalVertexAttribSize._16: case GalVertexAttribSize._16:
case GalVertexAttribSize._16_16: case GalVertexAttribSize._16_16:
case GalVertexAttribSize._16_16_16: case GalVertexAttribSize._16_16_16:
case GalVertexAttribSize._16_16_16_16: case GalVertexAttribSize._16_16_16_16:
GL.VertexAttribI4((uint)Attrib.Index, (ushort*)Attrib.Pointer); GL.VertexAttribI4((uint)Attrib.Index, (ushort*)Ptr);
break; break;
case GalVertexAttribSize._32: case GalVertexAttribSize._32:
case GalVertexAttribSize._32_32: case GalVertexAttribSize._32_32:
case GalVertexAttribSize._32_32_32: case GalVertexAttribSize._32_32_32:
case GalVertexAttribSize._32_32_32_32: case GalVertexAttribSize._32_32_32_32:
GL.VertexAttribI4((uint)Attrib.Index, (uint*)Attrib.Pointer); GL.VertexAttribI4((uint)Attrib.Index, (uint*)Ptr);
break; break;
}
} }
} else if (Attrib.Type == GalVertexAttribType.Sint)
else if (Attrib.Type == GalVertexAttribType.Sint)
{
switch (Attrib.Size)
{ {
case GalVertexAttribSize._8: switch (Attrib.Size)
case GalVertexAttribSize._8_8: {
case GalVertexAttribSize._8_8_8: case GalVertexAttribSize._8:
case GalVertexAttribSize._8_8_8_8: case GalVertexAttribSize._8_8:
GL.VertexAttribI4((uint)Attrib.Index, (sbyte*)Attrib.Pointer); case GalVertexAttribSize._8_8_8:
break; case GalVertexAttribSize._8_8_8_8:
GL.VertexAttribI4((uint)Attrib.Index, (sbyte*)Ptr);
break;
case GalVertexAttribSize._16: case GalVertexAttribSize._16:
case GalVertexAttribSize._16_16: case GalVertexAttribSize._16_16:
case GalVertexAttribSize._16_16_16: case GalVertexAttribSize._16_16_16:
case GalVertexAttribSize._16_16_16_16: case GalVertexAttribSize._16_16_16_16:
GL.VertexAttribI4((uint)Attrib.Index, (short*)Attrib.Pointer); GL.VertexAttribI4((uint)Attrib.Index, (short*)Ptr);
break; break;
case GalVertexAttribSize._32: case GalVertexAttribSize._32:
case GalVertexAttribSize._32_32: case GalVertexAttribSize._32_32:
case GalVertexAttribSize._32_32_32: case GalVertexAttribSize._32_32_32:
case GalVertexAttribSize._32_32_32_32: case GalVertexAttribSize._32_32_32_32:
GL.VertexAttribI4((uint)Attrib.Index, (int*)Attrib.Pointer); GL.VertexAttribI4((uint)Attrib.Index, (int*)Ptr);
break; break;
}
} }
} else if (Attrib.Type == GalVertexAttribType.Float)
else if (Attrib.Type == GalVertexAttribType.Float)
{
switch (Attrib.Size)
{ {
case GalVertexAttribSize._32: switch (Attrib.Size)
case GalVertexAttribSize._32_32: {
case GalVertexAttribSize._32_32_32: case GalVertexAttribSize._32:
case GalVertexAttribSize._32_32_32_32: case GalVertexAttribSize._32_32:
GL.VertexAttrib4(Attrib.Index, (float*)Attrib.Pointer); case GalVertexAttribSize._32_32_32:
break; case GalVertexAttribSize._32_32_32_32:
GL.VertexAttrib4(Attrib.Index, (float*)Ptr);
break;
default: ThrowUnsupportedAttrib(Attrib); break; default: ThrowUnsupportedAttrib(Attrib); break;
}
} }
} }
} }

View file

@ -92,7 +92,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{ {
int Handle = GL.GenBuffer(); int Handle = GL.GenBuffer();
VboCache.AddOrUpdate(Key, Handle, (uint)DataSize); VboCache.AddOrUpdate(Key, Handle, DataSize);
IntPtr Length = new IntPtr(DataSize); IntPtr Length = new IntPtr(DataSize);
@ -100,6 +100,18 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.BufferData(BufferTarget.ArrayBuffer, Length, HostAddress, BufferUsageHint.StreamDraw); GL.BufferData(BufferTarget.ArrayBuffer, Length, HostAddress, BufferUsageHint.StreamDraw);
} }
public void CreateVbo(long Key, byte[] Data)
{
int Handle = GL.GenBuffer();
VboCache.AddOrUpdate(Key, Handle, Data.Length);
IntPtr Length = new IntPtr(Data.Length);
GL.BindBuffer(BufferTarget.ArrayBuffer, Handle);
GL.BufferData(BufferTarget.ArrayBuffer, Length, Data, BufferUsageHint.StreamDraw);
}
public void CreateIbo(long Key, int DataSize, IntPtr HostAddress) public void CreateIbo(long Key, int DataSize, IntPtr HostAddress)
{ {
int Handle = GL.GenBuffer(); int Handle = GL.GenBuffer();
@ -116,7 +128,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{ {
int Handle = GL.GenBuffer(); int Handle = GL.GenBuffer();
IboCache.AddOrUpdate(Key, Handle, (uint)DataSize); IboCache.AddOrUpdate(Key, Handle, DataSize);
IntPtr Length = new IntPtr(Buffer.Length); IntPtr Length = new IntPtr(Buffer.Length);

View file

@ -30,6 +30,13 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.BufferSubData(Target, IntPtr.Zero, (IntPtr)Size, HostAddress); GL.BufferSubData(Target, IntPtr.Zero, (IntPtr)Size, HostAddress);
} }
public void SetData(byte[] Data)
{
GL.BindBuffer(Target, Handle);
GL.BufferSubData(Target, IntPtr.Zero, (IntPtr)Data.Length, Data);
}
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);

View file

@ -243,9 +243,9 @@ namespace Ryujinx.Graphics.Memory
return Cache.IsRegionModified(Memory, BufferType, PA, Size); return Cache.IsRegionModified(Memory, BufferType, PA, Size);
} }
public IntPtr GetHostAddress(long Position, long Size) public bool TryGetHostAddress(long Position, long Size, out IntPtr Ptr)
{ {
return Memory.GetHostAddress(GetPhysicalAddress(Position), Size); return Memory.TryGetHostAddress(GetPhysicalAddress(Position), Size, out Ptr);
} }
public byte ReadByte(long Position) public byte ReadByte(long Position)

View file

@ -615,9 +615,14 @@ namespace Ryujinx.Graphics
if (Gpu.ResourceManager.MemoryRegionModified(Vmm, Key, Cb.Size, NvGpuBufferType.ConstBuffer)) if (Gpu.ResourceManager.MemoryRegionModified(Vmm, Key, Cb.Size, NvGpuBufferType.ConstBuffer))
{ {
IntPtr Source = Vmm.GetHostAddress(Cb.Position, Cb.Size); if (Vmm.TryGetHostAddress(Cb.Position, Cb.Size, out IntPtr CbPtr))
{
Gpu.Renderer.Buffer.SetData(Key, Cb.Size, Source); Gpu.Renderer.Buffer.SetData(Key, Cb.Size, CbPtr);
}
else
{
Gpu.Renderer.Buffer.SetData(Key, Vmm.ReadBytes(Cb.Position, Cb.Size));
}
} }
State.ConstBufferKeys[Stage][DeclInfo.Cbuf] = Key; State.ConstBufferKeys[Stage][DeclInfo.Cbuf] = Key;
@ -660,9 +665,14 @@ namespace Ryujinx.Graphics
{ {
if (!UsesLegacyQuads) if (!UsesLegacyQuads)
{ {
IntPtr DataAddress = Vmm.GetHostAddress(IbPosition, IbSize); if (Vmm.TryGetHostAddress(IbPosition, IbSize, out IntPtr IbPtr))
{
Gpu.Renderer.Rasterizer.CreateIbo(IboKey, IbSize, DataAddress); Gpu.Renderer.Rasterizer.CreateIbo(IboKey, IbSize, IbPtr);
}
else
{
Gpu.Renderer.Rasterizer.CreateIbo(IboKey, IbSize, Vmm.ReadBytes(IbPosition, IbSize));
}
} }
else else
{ {
@ -711,22 +721,22 @@ namespace Ryujinx.Graphics
Attribs[ArrayIndex] = new List<GalVertexAttrib>(); Attribs[ArrayIndex] = new List<GalVertexAttrib>();
} }
long VertexPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNAddress + ArrayIndex * 4); long VbPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNAddress + ArrayIndex * 4);
bool IsConst = ((Packed >> 6) & 1) != 0;
int Offset = (Packed >> 7) & 0x3fff; int Offset = (Packed >> 7) & 0x3fff;
GalVertexAttribSize Size = (GalVertexAttribSize)((Packed >> 21) & 0x3f);
GalVertexAttribType Type = (GalVertexAttribType)((Packed >> 27) & 0x7);
bool IsRgba = ((Packed >> 31) & 1) != 0;
//Note: 16 is the maximum size of an attribute, //Note: 16 is the maximum size of an attribute,
//having a component size of 32-bits with 4 elements (a vec4). //having a component size of 32-bits with 4 elements (a vec4).
IntPtr Pointer = Vmm.GetHostAddress(VertexPosition + Offset, 16); byte[] Data = Vmm.ReadBytes(VbPosition + Offset, 16);
Attribs[ArrayIndex].Add(new GalVertexAttrib( Attribs[ArrayIndex].Add(new GalVertexAttrib(Attr, IsConst, Offset, Data, Size, Type, IsRgba));
Attr,
((Packed >> 6) & 0x1) != 0,
Offset,
Pointer,
(GalVertexAttribSize)((Packed >> 21) & 0x3f),
(GalVertexAttribType)((Packed >> 27) & 0x7),
((Packed >> 31) & 0x1) != 0));
} }
State.VertexBindings = new GalVertexBinding[32]; State.VertexBindings = new GalVertexBinding[32];
@ -747,8 +757,8 @@ namespace Ryujinx.Graphics
continue; continue;
} }
long VertexPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNAddress + Index * 4); long VbPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNAddress + Index * 4);
long VertexEndPos = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNEndAddr + Index * 2); long VbEndPos = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNEndAddr + Index * 2);
int VertexDivisor = ReadRegister(NvGpuEngine3dReg.VertexArrayNDivisor + Index * 4); int VertexDivisor = ReadRegister(NvGpuEngine3dReg.VertexArrayNDivisor + Index * 4);
@ -758,26 +768,31 @@ namespace Ryujinx.Graphics
if (Instanced && VertexDivisor != 0) if (Instanced && VertexDivisor != 0)
{ {
VertexPosition += Stride * (CurrentInstance / VertexDivisor); VbPosition += Stride * (CurrentInstance / VertexDivisor);
} }
if (VertexPosition > VertexEndPos) if (VbPosition > VbEndPos)
{ {
//Instance is invalid, ignore the draw call //Instance is invalid, ignore the draw call
continue; continue;
} }
long VboKey = Vmm.GetPhysicalAddress(VertexPosition); long VboKey = Vmm.GetPhysicalAddress(VbPosition);
long VbSize = (VertexEndPos - VertexPosition) + 1; long VbSize = (VbEndPos - VbPosition) + 1;
bool VboCached = Gpu.Renderer.Rasterizer.IsVboCached(VboKey, VbSize); bool VboCached = Gpu.Renderer.Rasterizer.IsVboCached(VboKey, VbSize);
if (!VboCached || Gpu.ResourceManager.MemoryRegionModified(Vmm, VboKey, VbSize, NvGpuBufferType.Vertex)) if (!VboCached || Gpu.ResourceManager.MemoryRegionModified(Vmm, VboKey, VbSize, NvGpuBufferType.Vertex))
{ {
IntPtr DataAddress = Vmm.GetHostAddress(VertexPosition, VbSize); if (Vmm.TryGetHostAddress(VbPosition, VbSize, out IntPtr VbPtr))
{
Gpu.Renderer.Rasterizer.CreateVbo(VboKey, (int)VbSize, DataAddress); Gpu.Renderer.Rasterizer.CreateVbo(VboKey, (int)VbSize, VbPtr);
}
else
{
Gpu.Renderer.Rasterizer.CreateVbo(VboKey, Vmm.ReadBytes(VbPosition, VbSize));
}
} }
State.VertexBindings[Index].Enabled = true; State.VertexBindings[Index].Enabled = true;

View file

@ -62,6 +62,8 @@ namespace Ryujinx.HLE.HOS
internal LinkedList<KProcess> Processes; internal LinkedList<KProcess> Processes;
internal bool EnableVersionChecks { get; private set; }
internal AppletStateMgr AppletState { get; private set; } internal AppletStateMgr AppletState { get; private set; }
internal KSharedMemory HidSharedMem { get; private set; } internal KSharedMemory HidSharedMem { get; private set; }

View file

@ -1,6 +1,8 @@
using ChocolArm64; using ChocolArm64;
using ChocolArm64.Events;
using ChocolArm64.Memory; using ChocolArm64.Memory;
using Ryujinx.Common; using Ryujinx.Common;
using Ryujinx.Common.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -343,19 +345,22 @@ namespace Ryujinx.HLE.HOS.Kernel
uint RequiredKernelVersionMajor = (uint)Capabilities.KernelReleaseVersion >> 19; uint RequiredKernelVersionMajor = (uint)Capabilities.KernelReleaseVersion >> 19;
uint RequiredKernelVersionMinor = ((uint)Capabilities.KernelReleaseVersion >> 15) & 0xf; uint RequiredKernelVersionMinor = ((uint)Capabilities.KernelReleaseVersion >> 15) & 0xf;
if (RequiredKernelVersionMajor > KernelVersionMajor) if (System.EnableVersionChecks)
{ {
return KernelResult.InvalidCombination; if (RequiredKernelVersionMajor > KernelVersionMajor)
} {
return KernelResult.InvalidCombination;
}
if (RequiredKernelVersionMajor != KernelVersionMajor && RequiredKernelVersionMajor < 3) if (RequiredKernelVersionMajor != KernelVersionMajor && RequiredKernelVersionMajor < 3)
{ {
return KernelResult.InvalidCombination; return KernelResult.InvalidCombination;
} }
if (RequiredKernelVersionMinor > KernelVersionMinor) if (RequiredKernelVersionMinor > KernelVersionMinor)
{ {
return KernelResult.InvalidCombination; return KernelResult.InvalidCombination;
}
} }
KernelResult Result = AllocateThreadLocalStorage(out ulong UserExceptionContextAddress); KernelResult Result = AllocateThreadLocalStorage(out ulong UserExceptionContextAddress);
@ -985,9 +990,9 @@ namespace Ryujinx.HLE.HOS.Kernel
} }
} }
private void CpuTraceHandler(object sender, EventArgs e) private void CpuTraceHandler(object sender, CpuTraceEventArgs e)
{ {
System.Scheduler.GetCurrentThread().PrintGuestStackTrace(); Logger.PrintInfo(LogClass.Cpu, $"Executing at 0x{e.Position:X16}.");
} }
} }
} }

View file

@ -11,7 +11,7 @@ namespace Ryujinx.HLE.HOS.Kernel
{ {
ulong Size = ThreadState.X1; ulong Size = ThreadState.X1;
if ((Size & 0xFFFFFFFE001FFFFF) != 0) if ((Size & 0xfffffffe001fffff) != 0)
{ {
Logger.PrintWarning(LogClass.KernelSvc, $"Heap size 0x{Size:x16} is not aligned!"); Logger.PrintWarning(LogClass.KernelSvc, $"Heap size 0x{Size:x16} is not aligned!");

View file

@ -112,6 +112,8 @@ namespace Ryujinx.HLE.HOS
for (int Index = 0; Index < StaticObjects.Length; Index++) for (int Index = 0; Index < StaticObjects.Length; Index++)
{ {
Logger.PrintInfo(LogClass.Loader, $"Loading image {Index} at 0x{NsoBase[Index]:x16}...");
IExecutable StaticObject = StaticObjects[Index]; IExecutable StaticObject = StaticObjects[Index];
ulong TextStart = NsoBase[Index] + (ulong)StaticObject.TextOffset; ulong TextStart = NsoBase[Index] + (ulong)StaticObject.TextOffset;

View file

@ -204,7 +204,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldr
{ {
return MakeError(ErrorModule.Loader, LoaderErr.BadSize); return MakeError(ErrorModule.Loader, LoaderErr.BadSize);
} }
else if (BssSize != 0 && (BssAddress + BssSize) <= BssAddress) else if (BssSize != 0 && BssAddress + BssSize <= BssAddress)
{ {
return MakeError(ErrorModule.Loader, LoaderErr.BadSize); return MakeError(ErrorModule.Loader, LoaderErr.BadSize);
} }