diff --git a/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs b/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs index 99138f8434..c4570a5324 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs @@ -73,8 +73,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv (long inputDataPosition, long inputDataSize) = context.Request.GetBufferType0x21(0); (long outputDataPosition, long outputDataSize) = context.Request.GetBufferType0x22(0); - NvIoctl.Direction ioctlDirection = ioctlCommand.GetDirectionValue(); - uint ioctlSize = ioctlCommand.GetSizeValue(); + NvIoctl.Direction ioctlDirection = ioctlCommand.DirectionValue; + uint ioctlSize = ioctlCommand.Size; bool isRead = (ioctlDirection & NvIoctl.Direction.Read) != 0; bool isWrite = (ioctlDirection & NvIoctl.Direction.Write) != 0; @@ -261,7 +261,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv errorCode = ConvertInternalErrorCode(internalResult); - if (errorCode == NvResult.Success && (ioctlCommand.GetDirectionValue() & NvIoctl.Direction.Write) == NvIoctl.Direction.Write) + if (errorCode == NvResult.Success && (ioctlCommand.DirectionValue & NvIoctl.Direction.Write) != 0) { context.Memory.WriteBytes(context.Request.GetBufferType0x22(0).Position, arguments.ToArray()); } @@ -449,7 +449,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv errorCode = ConvertInternalErrorCode(internalResult); - if (errorCode == NvResult.Success && (ioctlCommand.GetDirectionValue() & NvIoctl.Direction.Write) != 0) + if (errorCode == NvResult.Success && (ioctlCommand.DirectionValue & NvIoctl.Direction.Write) != 0) { context.Memory.WriteBytes(context.Request.GetBufferType0x22(0).Position, arguments.ToArray()); } @@ -494,7 +494,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv errorCode = ConvertInternalErrorCode(internalResult); - if (errorCode == NvResult.Success && (ioctlCommand.GetDirectionValue() & NvIoctl.Direction.Write) != 0) + if (errorCode == NvResult.Success && (ioctlCommand.DirectionValue & NvIoctl.Direction.Write) != 0) { context.Memory.WriteBytes(context.Request.GetBufferType0x22(0).Position, arguments.ToArray()); context.Memory.WriteBytes(inlineOutBufferPosition, inlineOutBuffer.ToArray()); diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs index 012e32b33d..ed842483e8 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs @@ -50,8 +50,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices protected delegate NvInternalResult IoctlProcessor(ref T arguments); protected delegate NvInternalResult IoctlProcessorSpan(Span arguments); - protected delegate NvInternalResult IoctlProcessorInline(ref T arguments, ref Y inlineData); - protected delegate NvInternalResult IoctlProcessorInlineSpan(ref T arguments, Span inlineData); + protected delegate NvInternalResult IoctlProcessorInline(ref T arguments, ref T1 inlineData); + protected delegate NvInternalResult IoctlProcessorInlineSpan(ref T arguments, Span inlineData); protected static NvInternalResult CallIoctlMethod(IoctlProcessor callback, Span arguments) where T : struct { @@ -60,12 +60,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices return callback(ref MemoryMarshal.Cast(arguments)[0]); } - protected static NvInternalResult CallIoctlMethod(IoctlProcessorInline callback, Span arguments, Span inlineBuffer) where T : struct where Y : struct + protected static NvInternalResult CallIoctlMethod(IoctlProcessorInline callback, Span arguments, Span inlineBuffer) where T : struct where T1 : struct { Debug.Assert(arguments.Length == Unsafe.SizeOf()); - Debug.Assert(inlineBuffer.Length == Unsafe.SizeOf()); + Debug.Assert(inlineBuffer.Length == Unsafe.SizeOf()); - return callback(ref MemoryMarshal.Cast(arguments)[0], ref MemoryMarshal.Cast(inlineBuffer)[0]); + return callback(ref MemoryMarshal.Cast(arguments)[0], ref MemoryMarshal.Cast(inlineBuffer)[0]); } protected static NvInternalResult CallIoctlMethod(IoctlProcessorSpan callback, Span arguments) where T : struct @@ -73,11 +73,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices return callback(MemoryMarshal.Cast(arguments)); } - protected static NvInternalResult CallIoctlMethod(IoctlProcessorInlineSpan callback, Span arguments, Span inlineBuffer) where T : struct where Y : struct + protected static NvInternalResult CallIoctlMethod(IoctlProcessorInlineSpan callback, Span arguments, Span inlineBuffer) where T : struct where T1 : struct { Debug.Assert(arguments.Length == Unsafe.SizeOf()); - return callback(ref MemoryMarshal.Cast(arguments)[0], MemoryMarshal.Cast(inlineBuffer)); + return callback(ref MemoryMarshal.Cast(arguments)[0], MemoryMarshal.Cast(inlineBuffer)); } public abstract void Close(); diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs index 86aa591b90..41c0cc7507 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs @@ -24,9 +24,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu { NvInternalResult result = NvInternalResult.NotImplemented; - if (command.GetTypeValue() == NvIoctl.NvGpuAsMagic) + if (command.Type == NvIoctl.NvGpuAsMagic) { - switch (command.GetNumberValue()) + switch (command.Number) { case 0x01: result = CallIoctlMethod(BindChannel, arguments); @@ -62,9 +62,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu { NvInternalResult result = NvInternalResult.NotImplemented; - if (command.GetTypeValue() == NvIoctl.NvGpuAsMagic) + if (command.Type == NvIoctl.NvGpuAsMagic) { - switch (command.GetNumberValue()) + switch (command.Number) { case 0x08: // This is the same as the one in ioctl as inlineOutBuffer is empty. diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs index 4d9b4da330..c7a2190cd9 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs @@ -6,6 +6,7 @@ using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu; using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types; using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel @@ -31,9 +32,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel { NvInternalResult result = NvInternalResult.NotImplemented; - if (command.GetTypeValue() == NvIoctl.NvHostCustomMagic) + if (command.Type == NvIoctl.NvHostCustomMagic) { - switch (command.GetNumberValue()) + switch (command.Number) { case 0x01: result = Submit(arguments); @@ -55,9 +56,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel break; } } - else if (command.GetTypeValue() == NvIoctl.NvHostMagic) + else if (command.Type == NvIoctl.NvHostMagic) { - switch (command.GetNumberValue()) + switch (command.Number) { case 0x01: result = CallIoctlMethod(SetNvMapFd, arguments); @@ -91,9 +92,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel break; } } - else if (command.GetTypeValue() == NvIoctl.NvGpuMagic) + else if (command.Type == NvIoctl.NvGpuMagic) { - switch (command.GetNumberValue()) + switch (command.Number) { case 0x14: result = CallIoctlMethod(SetUserData, arguments); @@ -106,7 +107,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private NvInternalResult Submit(Span arguments) { - int headerSize = Marshal.SizeOf(); + int headerSize = Unsafe.SizeOf(); SubmitArguments submitHeader = MemoryMarshal.Cast(arguments)[0]; Span commandBufferEntries = MemoryMarshal.Cast(arguments.Slice(headerSize)).Slice(0, submitHeader.CmdBufsCount); NvGpuVmm vmm = NvHostAsGpuDeviceFile.GetAddressSpaceContext(_owner).Vmm; @@ -157,7 +158,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private NvInternalResult MapCommandBuffer(Span arguments) { - int headerSize = Marshal.SizeOf(); + int headerSize = Unsafe.SizeOf(); MapCommandBufferArguments commandBufferHeader = MemoryMarshal.Cast(arguments)[0]; Span commandBufferEntries = MemoryMarshal.Cast(arguments.Slice(headerSize)).Slice(0, commandBufferHeader.NumEntries); NvGpuVmm vmm = NvHostAsGpuDeviceFile.GetAddressSpaceContext(_owner).Vmm; @@ -189,7 +190,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private NvInternalResult UnmapCommandBuffer(Span arguments) { - int headerSize = Marshal.SizeOf(); + int headerSize = Unsafe.SizeOf(); MapCommandBufferArguments commandBufferHeader = MemoryMarshal.Cast(arguments)[0]; Span commandBufferEntries = MemoryMarshal.Cast(arguments.Slice(headerSize)).Slice(0, commandBufferHeader.NumEntries); NvGpuVmm vmm = NvHostAsGpuDeviceFile.GetAddressSpaceContext(_owner).Vmm; @@ -239,7 +240,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel private NvInternalResult SubmitGpfifo(Span arguments) { - int headerSize = Marshal.SizeOf(); + int headerSize = Unsafe.SizeOf(); SubmitGpfifoArguments gpfifoSubmissionHeader = MemoryMarshal.Cast(arguments)[0]; Span gpfifoEntries = MemoryMarshal.Cast(arguments.Slice(headerSize)).Slice(0, gpfifoSubmissionHeader.NumEntries); diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs index 8df115eb7e..01b206dca6 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs @@ -22,9 +22,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel { NvInternalResult result = NvInternalResult.NotImplemented; - if (command.GetTypeValue() == NvIoctl.NvHostMagic) + if (command.Type == NvIoctl.NvHostMagic) { - switch (command.GetNumberValue()) + switch (command.Number) { case 0x1b: result = CallIoctlMethod(SubmitGpfifoEx, arguments, inlineInBuffer); diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs index 062b057edc..b12c1d63b1 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/Types/MapCommandBufferArguments.cs @@ -14,7 +14,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel.Types { public int NumEntries; public int DataAddress; // Ignored by the driver. - [MarshalAs(UnmanagedType.I1)] public bool AttachHostChDas; public byte Padding1; public short Padding2; diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs index 54dab8583e..b0d4a5d4f3 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs @@ -40,9 +40,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl { NvInternalResult result = NvInternalResult.NotImplemented; - if (command.GetTypeValue() == NvIoctl.NvHostCustomMagic) + if (command.Type == NvIoctl.NvHostCustomMagic) { - switch (command.GetNumberValue()) + switch (command.Number) { case 0x14: result = CallIoctlMethod(SyncptRead, arguments); diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs index f55c9f90a5..b76f813d88 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs @@ -31,9 +31,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu { NvInternalResult result = NvInternalResult.NotImplemented; - if (command.GetTypeValue() == NvIoctl.NvGpuMagic) + if (command.Type == NvIoctl.NvGpuMagic) { - switch (command.GetNumberValue()) + switch (command.Number) { case 0x01: result = CallIoctlMethod(ZcullGetCtxSize, arguments); @@ -66,9 +66,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu { NvInternalResult result = NvInternalResult.NotImplemented; - if (command.GetTypeValue() == NvIoctl.NvGpuMagic) + if (command.Type == NvIoctl.NvGpuMagic) { - switch (command.GetNumberValue()) + switch (command.Number) { case 0x05: result = CallIoctlMethod(GetCharacteristics, arguments, inlineOutBuffer); diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs index fa341a0e38..4980f4bfca 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs @@ -24,9 +24,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap { NvInternalResult result = NvInternalResult.NotImplemented; - if (command.GetTypeValue() == NvIoctl.NvMapCustomMagic) + if (command.Type == NvIoctl.NvMapCustomMagic) { - switch (command.GetNumberValue()) + switch (command.Number) { case 0x01: result = CallIoctlMethod(Create, arguments); diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvIoctl.cs b/Ryujinx.HLE/HOS/Services/Nv/NvIoctl.cs index dd90b2ed04..0585869496 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/NvIoctl.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/NvIoctl.cs @@ -37,24 +37,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv public uint RawValue; - public uint GetNumberValue() - { - return (RawValue >> NumberShift) & NumberMask; - } - - public uint GetTypeValue() - { - return (RawValue >> TypeShift) & TypeMask; - } - - public uint GetSizeValue() - { - return (RawValue >> SizeShift) & SizeMask; - } - - public Direction GetDirectionValue() - { - return (Direction)((RawValue >> DirectionShift) & DirectionMask); - } + public uint Number => (RawValue >> NumberShift) & NumberMask; + public uint Type => (RawValue >> TypeShift) & TypeMask; + public uint Size => (RawValue >> SizeShift) & SizeMask; + public Direction DirectionValue => (Direction)((RawValue >> DirectionShift) & DirectionMask); } } diff --git a/Ryujinx.HLE/HOS/Services/Nv/Types/NvIoctlNotImplementedException.cs b/Ryujinx.HLE/HOS/Services/Nv/Types/NvIoctlNotImplementedException.cs index dcc28b1ceb..9404c18ce2 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/Types/NvIoctlNotImplementedException.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/Types/NvIoctlNotImplementedException.cs @@ -27,9 +27,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types get { return base.Message + - Environment.NewLine + - Environment.NewLine + - BuildMessage(); + Environment.NewLine + + Environment.NewLine + + BuildMessage(); } } @@ -41,10 +41,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types sb.AppendLine(); sb.AppendLine($"Ioctl (0x{Command.RawValue:x8})"); - sb.AppendLine($"\tNumber: 0x{Command.GetNumberValue():x8}"); - sb.AppendLine($"\tType: 0x{Command.GetTypeValue():x8}"); - sb.AppendLine($"\tSize: 0x{Command.GetSizeValue():x8}"); - sb.AppendLine($"\tDirection: {Command.GetDirectionValue()}"); + sb.AppendLine($"\tNumber: 0x{Command.Number:x8}"); + sb.AppendLine($"\tType: 0x{Command.Type:x8}"); + sb.AppendLine($"\tSize: 0x{Command.Size:x8}"); + sb.AppendLine($"\tDirection: {Command.DirectionValue}"); sb.AppendLine("Guest Stack Trace:"); sb.AppendLine(Context.Thread.GetGuestStackTrace()); diff --git a/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs b/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs index 76eeba0e43..30cab31e80 100644 --- a/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs +++ b/Ryujinx.HLE/HOS/Services/Nv/Types/NvQueryEventNotImplementedException.cs @@ -27,9 +27,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.Types get { return base.Message + - Environment.NewLine + - Environment.NewLine + - BuildMessage(); + Environment.NewLine + + Environment.NewLine + + BuildMessage(); } }