diff --git a/Ryujinx.Common/StructIOExtension.cs b/Ryujinx.Common/StructIOExtension.cs new file mode 100644 index 0000000000..8671b1920b --- /dev/null +++ b/Ryujinx.Common/StructIOExtension.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; + +namespace Ryujinx.Common +{ + public static class StructIOExtension + { + public unsafe static T ReadStruct(this BinaryReader reader) where T : struct + { + int size = Marshal.SizeOf(); + + byte[] data = reader.ReadBytes(size); + + fixed (byte* ptr = data) + { + return Marshal.PtrToStructure((IntPtr)ptr); + } + } + + public unsafe static void WriteStruct(this BinaryWriter writer, T value) where T : struct + { + long size = Marshal.SizeOf(); + + byte[] data = new byte[size]; + + fixed (byte* ptr = data) + { + Marshal.StructureToPtr(value, (IntPtr)ptr, false); + } + + writer.Write(data); + } + } +} diff --git a/Ryujinx.HLE/HOS/Services/Vi/GbpBuffer.cs b/Ryujinx.HLE/HOS/Services/Vi/GbpBuffer.cs index 0731d84175..eb1adc7759 100644 --- a/Ryujinx.HLE/HOS/Services/Vi/GbpBuffer.cs +++ b/Ryujinx.HLE/HOS/Services/Vi/GbpBuffer.cs @@ -1,3 +1,4 @@ +using Ryujinx.Common; using System; using System.IO; using System.Runtime.InteropServices; @@ -141,7 +142,7 @@ namespace Ryujinx.HLE.HOS.Services.Android public GbpBuffer(BinaryReader reader) { - Header = NvFlinger.ReadStruct(reader); + Header = reader.ReadStruct(); // ignore fds // TODO: check if that is used in official implementation @@ -152,13 +153,13 @@ namespace Ryujinx.HLE.HOS.Services.Android throw new System.NotImplementedException($"Unexpected Graphic Buffer ints count (expected 0x51, found 0x{Header.IntsCount:x}"); } - Buffer = NvFlinger.ReadStruct(reader); + Buffer = reader.ReadStruct(); } public void Write(BinaryWriter writer) { - NvFlinger.WriteStruct(writer, Header); - NvFlinger.WriteStruct(writer, Buffer); + writer.WriteStruct(Header); + writer.WriteStruct(Buffer); } } } \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/Vi/NvFlinger.cs b/Ryujinx.HLE/HOS/Services/Vi/NvFlinger.cs index da4dabacf4..c677e7ac53 100644 --- a/Ryujinx.HLE/HOS/Services/Vi/NvFlinger.cs +++ b/Ryujinx.HLE/HOS/Services/Vi/NvFlinger.cs @@ -85,31 +85,31 @@ namespace Ryujinx.HLE.HOS.Services.Android private struct QueueBufferObject { [FieldOffset(0x0)] - public long Timestamp; + public long Timestamp; [FieldOffset(0x8)] - public int IsAutoTimestamp; + public int IsAutoTimestamp; [FieldOffset(0xC)] - public Rect Crop; + public Rect Crop; [FieldOffset(0x1C)] - public int ScalingMode; + public int ScalingMode; [FieldOffset(0x20)] public HalTransform Transform; [FieldOffset(0x24)] - public int StickyTransform; + public int StickyTransform; [FieldOffset(0x28)] - public int Unknown; + public int Unknown; [FieldOffset(0x2C)] - public int SwapInterval; + public int SwapInterval; [FieldOffset(0x30)] - public MultiFence Fence; + public MultiFence Fence; } private struct BufferEntry @@ -238,7 +238,7 @@ namespace Ryujinx.HLE.HOS.Services.Android parcelReader.BaseStream.Position = Position; _bufferQueue[slot].Transform = queueBufferObject.Transform; - _bufferQueue[slot].Crop = queueBufferObject.Crop; + _bufferQueue[slot].Crop = queueBufferObject.Crop; _bufferQueue[slot].State = BufferState.Queued; @@ -325,34 +325,6 @@ namespace Ryujinx.HLE.HOS.Services.Android } } - // FIXME: move this (extension?) - public unsafe static T ReadStruct(BinaryReader reader) where T : struct - { - int size = Marshal.SizeOf(); - - byte[] data = reader.ReadBytes(size); - - fixed (byte* ptr = data) - { - return Marshal.PtrToStructure((IntPtr)ptr); - } - } - - // FIXME: move this (extension?) - public unsafe static void WriteStruct(BinaryWriter writer, T value) where T : struct - { - long size = Marshal.SizeOf(); - - byte[] data = new byte[size]; - - fixed (byte* ptr = data) - { - Marshal.StructureToPtr(value, (IntPtr)ptr, false); - } - - writer.Write(data); - } - private long MakeReplyParcel(ServiceCtx context, params int[] ints) { using (MemoryStream ms = new MemoryStream()) @@ -429,7 +401,6 @@ namespace Ryujinx.HLE.HOS.Services.Android int right = crop.Right; int bottom = crop.Bottom; - NvGpuVmm vmm = NvGpuASIoctl.GetASCtx(context).Vmm; _renderer.QueueAction(() =>