diff --git a/Ryujinx.Graphics/Graphics3d/INvGpuEngine.cs b/Ryujinx.Graphics/Graphics3d/INvGpuEngine.cs index c2474a1718..aa0db6826f 100644 --- a/Ryujinx.Graphics/Graphics3d/INvGpuEngine.cs +++ b/Ryujinx.Graphics/Graphics3d/INvGpuEngine.cs @@ -6,6 +6,6 @@ namespace Ryujinx.Graphics.Graphics3d { int[] Registers { get; } - void CallMethod(NvGpuVmm Vmm, GpuMethodCall MethCall); + void CallMethod(NvGpuVmm vmm, GpuMethodCall methCall); } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/MacroInterpreter.cs b/Ryujinx.Graphics/Graphics3d/MacroInterpreter.cs index a124aca484..845762133c 100644 --- a/Ryujinx.Graphics/Graphics3d/MacroInterpreter.cs +++ b/Ryujinx.Graphics/Graphics3d/MacroInterpreter.cs @@ -42,78 +42,78 @@ namespace Ryujinx.Graphics.Graphics3d BitwiseNotAnd = 12 } - private NvGpuFifo PFifo; - private INvGpuEngine Engine; + private NvGpuFifo _pFifo; + private INvGpuEngine _engine; public Queue Fifo { get; private set; } - private int[] Gprs; + private int[] _gprs; - private int MethAddr; - private int MethIncr; + private int _methAddr; + private int _methIncr; - private bool Carry; + private bool _carry; - private int OpCode; + private int _opCode; - private int PipeOp; + private int _pipeOp; - private int Pc; + private int _pc; - public MacroInterpreter(NvGpuFifo PFifo, INvGpuEngine Engine) + public MacroInterpreter(NvGpuFifo pFifo, INvGpuEngine engine) { - this.PFifo = PFifo; - this.Engine = Engine; + _pFifo = pFifo; + _engine = engine; Fifo = new Queue(); - Gprs = new int[8]; + _gprs = new int[8]; } - public void Execute(NvGpuVmm Vmm, int[] Mme, int Position, int Param) + public void Execute(NvGpuVmm vmm, int[] mme, int position, int param) { Reset(); - Gprs[1] = Param; + _gprs[1] = param; - Pc = Position; + _pc = position; - FetchOpCode(Mme); + FetchOpCode(mme); - while (Step(Vmm, Mme)); + while (Step(vmm, mme)); //Due to the delay slot, we still need to execute //one more instruction before we actually exit. - Step(Vmm, Mme); + Step(vmm, mme); } private void Reset() { - for (int Index = 0; Index < Gprs.Length; Index++) + for (int index = 0; index < _gprs.Length; index++) { - Gprs[Index] = 0; + _gprs[index] = 0; } - MethAddr = 0; - MethIncr = 0; + _methAddr = 0; + _methIncr = 0; - Carry = false; + _carry = false; } - private bool Step(NvGpuVmm Vmm, int[] Mme) + private bool Step(NvGpuVmm vmm, int[] mme) { - int BaseAddr = Pc - 1; + int baseAddr = _pc - 1; - FetchOpCode(Mme); + FetchOpCode(mme); - if ((OpCode & 7) < 7) + if ((_opCode & 7) < 7) { //Operation produces a value. - AssignmentOperation AsgOp = (AssignmentOperation)((OpCode >> 4) & 7); + AssignmentOperation asgOp = (AssignmentOperation)((_opCode >> 4) & 7); - int Result = GetAluResult(); + int result = GetAluResult(); - switch (AsgOp) + switch (asgOp) { //Fetch parameter and ignore result. case AssignmentOperation.IgnoreAndFetch: @@ -126,7 +126,7 @@ namespace Ryujinx.Graphics.Graphics3d //Move result. case AssignmentOperation.Move: { - SetDstGpr(Result); + SetDstGpr(result); break; } @@ -134,9 +134,9 @@ namespace Ryujinx.Graphics.Graphics3d //Move result and use as Method Address. case AssignmentOperation.MoveAndSetMaddr: { - SetDstGpr(Result); + SetDstGpr(result); - SetMethAddr(Result); + SetMethAddr(result); break; } @@ -146,7 +146,7 @@ namespace Ryujinx.Graphics.Graphics3d { SetDstGpr(FetchParam()); - Send(Vmm, Result); + Send(vmm, result); break; } @@ -154,9 +154,9 @@ namespace Ryujinx.Graphics.Graphics3d //Move and send result. case AssignmentOperation.MoveAndSend: { - SetDstGpr(Result); + SetDstGpr(result); - Send(Vmm, Result); + Send(vmm, result); break; } @@ -166,7 +166,7 @@ namespace Ryujinx.Graphics.Graphics3d { SetDstGpr(FetchParam()); - SetMethAddr(Result); + SetMethAddr(result); break; } @@ -174,11 +174,11 @@ namespace Ryujinx.Graphics.Graphics3d //Move result and use as Method Address, then fetch and send paramter. case AssignmentOperation.MoveAndSetMaddrThenFetchAndSend: { - SetDstGpr(Result); + SetDstGpr(result); - SetMethAddr(Result); + SetMethAddr(result); - Send(Vmm, FetchParam()); + Send(vmm, FetchParam()); break; } @@ -186,11 +186,11 @@ namespace Ryujinx.Graphics.Graphics3d //Move result and use as Method Address, then send bits 17:12 of result. case AssignmentOperation.MoveAndSetMaddrThenSendHigh: { - SetDstGpr(Result); + SetDstGpr(result); - SetMethAddr(Result); + SetMethAddr(result); - Send(Vmm, (Result >> 12) & 0x3f); + Send(vmm, (result >> 12) & 0x3f); break; } @@ -199,50 +199,50 @@ namespace Ryujinx.Graphics.Graphics3d else { //Branch. - bool OnNotZero = ((OpCode >> 4) & 1) != 0; + bool onNotZero = ((_opCode >> 4) & 1) != 0; - bool Taken = OnNotZero + bool taken = onNotZero ? GetGprA() != 0 : GetGprA() == 0; - if (Taken) + if (taken) { - Pc = BaseAddr + GetImm(); + _pc = baseAddr + GetImm(); - bool NoDelays = (OpCode & 0x20) != 0; + bool noDelays = (_opCode & 0x20) != 0; - if (NoDelays) + if (noDelays) { - FetchOpCode(Mme); + FetchOpCode(mme); } return true; } } - bool Exit = (OpCode & 0x80) != 0; + bool exit = (_opCode & 0x80) != 0; - return !Exit; + return !exit; } - private void FetchOpCode(int[] Mme) + private void FetchOpCode(int[] mme) { - OpCode = PipeOp; + _opCode = _pipeOp; - PipeOp = Mme[Pc++]; + _pipeOp = mme[_pc++]; } private int GetAluResult() { - AluOperation Op = (AluOperation)(OpCode & 7); + AluOperation op = (AluOperation)(_opCode & 7); - switch (Op) + switch (op) { case AluOperation.AluReg: { - AluRegOperation AluOp = (AluRegOperation)((OpCode >> 17) & 0x1f); + AluRegOperation aluOp = (AluRegOperation)((_opCode >> 17) & 0x1f); - return GetAluResult(AluOp, GetGprA(), GetGprB()); + return GetAluResult(aluOp, GetGprA(), GetGprB()); } case AluOperation.AddImmediate: @@ -254,40 +254,40 @@ namespace Ryujinx.Graphics.Graphics3d case AluOperation.BitfieldExtractLslImm: case AluOperation.BitfieldExtractLslReg: { - int BfSrcBit = (OpCode >> 17) & 0x1f; - int BfSize = (OpCode >> 22) & 0x1f; - int BfDstBit = (OpCode >> 27) & 0x1f; + int bfSrcBit = (_opCode >> 17) & 0x1f; + int bfSize = (_opCode >> 22) & 0x1f; + int bfDstBit = (_opCode >> 27) & 0x1f; - int BfMask = (1 << BfSize) - 1; + int bfMask = (1 << bfSize) - 1; - int Dst = GetGprA(); - int Src = GetGprB(); + int dst = GetGprA(); + int src = GetGprB(); - switch (Op) + switch (op) { case AluOperation.BitfieldReplace: { - Src = (int)((uint)Src >> BfSrcBit) & BfMask; + src = (int)((uint)src >> bfSrcBit) & bfMask; - Dst &= ~(BfMask << BfDstBit); + dst &= ~(bfMask << bfDstBit); - Dst |= Src << BfDstBit; + dst |= src << bfDstBit; - return Dst; + return dst; } case AluOperation.BitfieldExtractLslImm: { - Src = (int)((uint)Src >> Dst) & BfMask; + src = (int)((uint)src >> dst) & bfMask; - return Src << BfDstBit; + return src << bfDstBit; } case AluOperation.BitfieldExtractLslReg: { - Src = (int)((uint)Src >> BfSrcBit) & BfMask; + src = (int)((uint)src >> bfSrcBit) & bfMask; - return Src << Dst; + return src << dst; } } @@ -300,117 +300,117 @@ namespace Ryujinx.Graphics.Graphics3d } } - throw new ArgumentException(nameof(OpCode)); + throw new ArgumentException(nameof(_opCode)); } - private int GetAluResult(AluRegOperation AluOp, int A, int B) + private int GetAluResult(AluRegOperation aluOp, int a, int b) { - switch (AluOp) + switch (aluOp) { case AluRegOperation.Add: { - ulong Result = (ulong)A + (ulong)B; + ulong result = (ulong)a + (ulong)b; - Carry = Result > 0xffffffff; + _carry = result > 0xffffffff; - return (int)Result; + return (int)result; } case AluRegOperation.AddWithCarry: { - ulong Result = (ulong)A + (ulong)B + (Carry ? 1UL : 0UL); + ulong result = (ulong)a + (ulong)b + (_carry ? 1UL : 0UL); - Carry = Result > 0xffffffff; + _carry = result > 0xffffffff; - return (int)Result; + return (int)result; } case AluRegOperation.Subtract: { - ulong Result = (ulong)A - (ulong)B; + ulong result = (ulong)a - (ulong)b; - Carry = Result < 0x100000000; + _carry = result < 0x100000000; - return (int)Result; + return (int)result; } case AluRegOperation.SubtractWithBorrow: { - ulong Result = (ulong)A - (ulong)B - (Carry ? 0UL : 1UL); + ulong result = (ulong)a - (ulong)b - (_carry ? 0UL : 1UL); - Carry = Result < 0x100000000; + _carry = result < 0x100000000; - return (int)Result; + return (int)result; } - case AluRegOperation.BitwiseExclusiveOr: return A ^ B; - case AluRegOperation.BitwiseOr: return A | B; - case AluRegOperation.BitwiseAnd: return A & B; - case AluRegOperation.BitwiseAndNot: return A & ~B; - case AluRegOperation.BitwiseNotAnd: return ~(A & B); + case AluRegOperation.BitwiseExclusiveOr: return a ^ b; + case AluRegOperation.BitwiseOr: return a | b; + case AluRegOperation.BitwiseAnd: return a & b; + case AluRegOperation.BitwiseAndNot: return a & ~b; + case AluRegOperation.BitwiseNotAnd: return ~(a & b); } - throw new ArgumentOutOfRangeException(nameof(AluOp)); + throw new ArgumentOutOfRangeException(nameof(aluOp)); } private int GetImm() { //Note: The immediate is signed, the sign-extension is intended here. - return OpCode >> 14; + return _opCode >> 14; } - private void SetMethAddr(int Value) + private void SetMethAddr(int value) { - MethAddr = (Value >> 0) & 0xfff; - MethIncr = (Value >> 12) & 0x3f; + _methAddr = (value >> 0) & 0xfff; + _methIncr = (value >> 12) & 0x3f; } - private void SetDstGpr(int Value) + private void SetDstGpr(int value) { - Gprs[(OpCode >> 8) & 7] = Value; + _gprs[(_opCode >> 8) & 7] = value; } private int GetGprA() { - return GetGprValue((OpCode >> 11) & 7); + return GetGprValue((_opCode >> 11) & 7); } private int GetGprB() { - return GetGprValue((OpCode >> 14) & 7); + return GetGprValue((_opCode >> 14) & 7); } - private int GetGprValue(int Index) + private int GetGprValue(int index) { - return Index != 0 ? Gprs[Index] : 0; + return index != 0 ? _gprs[index] : 0; } private int FetchParam() { - int Value; + int value; - if (!Fifo.TryDequeue(out Value)) + if (!Fifo.TryDequeue(out value)) { Logger.PrintWarning(LogClass.Gpu, "Macro attempted to fetch an inexistent argument."); return 0; } - return Value; + return value; } - private int Read(int Reg) + private int Read(int reg) { - return Engine.Registers[Reg]; + return _engine.Registers[reg]; } - private void Send(NvGpuVmm Vmm, int Value) + private void Send(NvGpuVmm vmm, int value) { - GpuMethodCall MethCall = new GpuMethodCall(MethAddr, Value); + GpuMethodCall methCall = new GpuMethodCall(_methAddr, value); - Engine.CallMethod(Vmm, MethCall); + _engine.CallMethod(vmm, methCall); - MethAddr += MethIncr; + _methAddr += _methIncr; } } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngine.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngine.cs index 20c36fda33..31d99b4f4b 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngine.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngine.cs @@ -2,8 +2,8 @@ namespace Ryujinx.Graphics.Graphics3d { enum NvGpuEngine { - _2d = 0x902d, - _3d = 0xb197, + _2D = 0x902d, + _3D = 0xb197, Compute = 0xb1c0, P2mf = 0xa140, M2mf = 0xb0b5 diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngine2d.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngine2d.cs index 3295f6da05..5eeaae50ef 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngine2d.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngine2d.cs @@ -5,7 +5,7 @@ using Ryujinx.Graphics.Texture; namespace Ryujinx.Graphics.Graphics3d { - class NvGpuEngine2d : INvGpuEngine + class NvGpuEngine2D : INvGpuEngine { private enum CopyOperation { @@ -20,187 +20,187 @@ namespace Ryujinx.Graphics.Graphics3d public int[] Registers { get; private set; } - private NvGpu Gpu; + private NvGpu _gpu; - public NvGpuEngine2d(NvGpu Gpu) + public NvGpuEngine2D(NvGpu gpu) { - this.Gpu = Gpu; + _gpu = gpu; Registers = new int[0x238]; } - public void CallMethod(NvGpuVmm Vmm, GpuMethodCall MethCall) + public void CallMethod(NvGpuVmm vmm, GpuMethodCall methCall) { - WriteRegister(MethCall); + WriteRegister(methCall); - if ((NvGpuEngine2dReg)MethCall.Method == NvGpuEngine2dReg.BlitSrcYInt) + if ((NvGpuEngine2DReg)methCall.Method == NvGpuEngine2DReg.BlitSrcYInt) { - TextureCopy(Vmm); + TextureCopy(vmm); } } - private void TextureCopy(NvGpuVmm Vmm) + private void TextureCopy(NvGpuVmm vmm) { - CopyOperation Operation = (CopyOperation)ReadRegister(NvGpuEngine2dReg.CopyOperation); + CopyOperation operation = (CopyOperation)ReadRegister(NvGpuEngine2DReg.CopyOperation); - int DstFormat = ReadRegister(NvGpuEngine2dReg.DstFormat); - bool DstLinear = ReadRegister(NvGpuEngine2dReg.DstLinear) != 0; - int DstWidth = ReadRegister(NvGpuEngine2dReg.DstWidth); - int DstHeight = ReadRegister(NvGpuEngine2dReg.DstHeight); - int DstDepth = ReadRegister(NvGpuEngine2dReg.DstDepth); - int DstLayer = ReadRegister(NvGpuEngine2dReg.DstLayer); - int DstPitch = ReadRegister(NvGpuEngine2dReg.DstPitch); - int DstBlkDim = ReadRegister(NvGpuEngine2dReg.DstBlockDimensions); + int dstFormat = ReadRegister(NvGpuEngine2DReg.DstFormat); + bool dstLinear = ReadRegister(NvGpuEngine2DReg.DstLinear) != 0; + int dstWidth = ReadRegister(NvGpuEngine2DReg.DstWidth); + int dstHeight = ReadRegister(NvGpuEngine2DReg.DstHeight); + int dstDepth = ReadRegister(NvGpuEngine2DReg.DstDepth); + int dstLayer = ReadRegister(NvGpuEngine2DReg.DstLayer); + int dstPitch = ReadRegister(NvGpuEngine2DReg.DstPitch); + int dstBlkDim = ReadRegister(NvGpuEngine2DReg.DstBlockDimensions); - int SrcFormat = ReadRegister(NvGpuEngine2dReg.SrcFormat); - bool SrcLinear = ReadRegister(NvGpuEngine2dReg.SrcLinear) != 0; - int SrcWidth = ReadRegister(NvGpuEngine2dReg.SrcWidth); - int SrcHeight = ReadRegister(NvGpuEngine2dReg.SrcHeight); - int SrcDepth = ReadRegister(NvGpuEngine2dReg.SrcDepth); - int SrcLayer = ReadRegister(NvGpuEngine2dReg.SrcLayer); - int SrcPitch = ReadRegister(NvGpuEngine2dReg.SrcPitch); - int SrcBlkDim = ReadRegister(NvGpuEngine2dReg.SrcBlockDimensions); + int srcFormat = ReadRegister(NvGpuEngine2DReg.SrcFormat); + bool srcLinear = ReadRegister(NvGpuEngine2DReg.SrcLinear) != 0; + int srcWidth = ReadRegister(NvGpuEngine2DReg.SrcWidth); + int srcHeight = ReadRegister(NvGpuEngine2DReg.SrcHeight); + int srcDepth = ReadRegister(NvGpuEngine2DReg.SrcDepth); + int srcLayer = ReadRegister(NvGpuEngine2DReg.SrcLayer); + int srcPitch = ReadRegister(NvGpuEngine2DReg.SrcPitch); + int srcBlkDim = ReadRegister(NvGpuEngine2DReg.SrcBlockDimensions); - int DstBlitX = ReadRegister(NvGpuEngine2dReg.BlitDstX); - int DstBlitY = ReadRegister(NvGpuEngine2dReg.BlitDstY); - int DstBlitW = ReadRegister(NvGpuEngine2dReg.BlitDstW); - int DstBlitH = ReadRegister(NvGpuEngine2dReg.BlitDstH); + int dstBlitX = ReadRegister(NvGpuEngine2DReg.BlitDstX); + int dstBlitY = ReadRegister(NvGpuEngine2DReg.BlitDstY); + int dstBlitW = ReadRegister(NvGpuEngine2DReg.BlitDstW); + int dstBlitH = ReadRegister(NvGpuEngine2DReg.BlitDstH); - long BlitDuDx = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitDuDxFract); - long BlitDvDy = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitDvDyFract); + long blitDuDx = ReadRegisterFixed1_31_32(NvGpuEngine2DReg.BlitDuDxFract); + long blitDvDy = ReadRegisterFixed1_31_32(NvGpuEngine2DReg.BlitDvDyFract); - long SrcBlitX = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitSrcXFract); - long SrcBlitY = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitSrcYFract); + long srcBlitX = ReadRegisterFixed1_31_32(NvGpuEngine2DReg.BlitSrcXFract); + long srcBlitY = ReadRegisterFixed1_31_32(NvGpuEngine2DReg.BlitSrcYFract); - GalImageFormat SrcImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)SrcFormat); - GalImageFormat DstImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)DstFormat); + GalImageFormat srcImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)srcFormat); + GalImageFormat dstImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)dstFormat); - GalMemoryLayout SrcLayout = GetLayout(SrcLinear); - GalMemoryLayout DstLayout = GetLayout(DstLinear); + GalMemoryLayout srcLayout = GetLayout(srcLinear); + GalMemoryLayout dstLayout = GetLayout(dstLinear); - int SrcBlockHeight = 1 << ((SrcBlkDim >> 4) & 0xf); - int DstBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf); + int srcBlockHeight = 1 << ((srcBlkDim >> 4) & 0xf); + int dstBlockHeight = 1 << ((dstBlkDim >> 4) & 0xf); - long SrcAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress); - long DstAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.DstAddress); + long srcAddress = MakeInt64From2xInt32(NvGpuEngine2DReg.SrcAddress); + long dstAddress = MakeInt64From2xInt32(NvGpuEngine2DReg.DstAddress); - long SrcKey = Vmm.GetPhysicalAddress(SrcAddress); - long DstKey = Vmm.GetPhysicalAddress(DstAddress); + long srcKey = vmm.GetPhysicalAddress(srcAddress); + long dstKey = vmm.GetPhysicalAddress(dstAddress); - bool IsSrcLayered = false; - bool IsDstLayered = false; + bool isSrcLayered = false; + bool isDstLayered = false; - GalTextureTarget SrcTarget = GalTextureTarget.TwoD; + GalTextureTarget srcTarget = GalTextureTarget.TwoD; - if (SrcDepth != 0) + if (srcDepth != 0) { - SrcTarget = GalTextureTarget.TwoDArray; - SrcDepth++; - IsSrcLayered = true; + srcTarget = GalTextureTarget.TwoDArray; + srcDepth++; + isSrcLayered = true; } else { - SrcDepth = 1; + srcDepth = 1; } - GalTextureTarget DstTarget = GalTextureTarget.TwoD; + GalTextureTarget dstTarget = GalTextureTarget.TwoD; - if (DstDepth != 0) + if (dstDepth != 0) { - DstTarget = GalTextureTarget.TwoDArray; - DstDepth++; - IsDstLayered = true; + dstTarget = GalTextureTarget.TwoDArray; + dstDepth++; + isDstLayered = true; } else { - DstDepth = 1; + dstDepth = 1; } - GalImage SrcTexture = new GalImage( - SrcWidth, - SrcHeight, - 1, SrcDepth, 1, - SrcBlockHeight, 1, - SrcLayout, - SrcImgFormat, - SrcTarget); + GalImage srcTexture = new GalImage( + srcWidth, + srcHeight, + 1, srcDepth, 1, + srcBlockHeight, 1, + srcLayout, + srcImgFormat, + srcTarget); - GalImage DstTexture = new GalImage( - DstWidth, - DstHeight, - 1, DstDepth, 1, - DstBlockHeight, 1, - DstLayout, - DstImgFormat, - DstTarget); + GalImage dstTexture = new GalImage( + dstWidth, + dstHeight, + 1, dstDepth, 1, + dstBlockHeight, 1, + dstLayout, + dstImgFormat, + dstTarget); - SrcTexture.Pitch = SrcPitch; - DstTexture.Pitch = DstPitch; + srcTexture.Pitch = srcPitch; + dstTexture.Pitch = dstPitch; - long GetLayerOffset(GalImage Image, int Layer) + long GetLayerOffset(GalImage image, int layer) { - int TargetMipLevel = Image.MaxMipmapLevel <= 1 ? 1 : Image.MaxMipmapLevel - 1; - return ImageUtils.GetLayerOffset(Image, TargetMipLevel) * Layer; + int targetMipLevel = image.MaxMipmapLevel <= 1 ? 1 : image.MaxMipmapLevel - 1; + return ImageUtils.GetLayerOffset(image, targetMipLevel) * layer; } - int SrcLayerIndex = -1; + int srcLayerIndex = -1; - if (IsSrcLayered && Gpu.ResourceManager.TryGetTextureLayer(SrcKey, out SrcLayerIndex) && SrcLayerIndex != 0) + if (isSrcLayered && _gpu.ResourceManager.TryGetTextureLayer(srcKey, out srcLayerIndex) && srcLayerIndex != 0) { - SrcKey = SrcKey - GetLayerOffset(SrcTexture, SrcLayerIndex); + srcKey = srcKey - GetLayerOffset(srcTexture, srcLayerIndex); } - int DstLayerIndex = -1; + int dstLayerIndex = -1; - if (IsDstLayered && Gpu.ResourceManager.TryGetTextureLayer(DstKey, out DstLayerIndex) && DstLayerIndex != 0) + if (isDstLayered && _gpu.ResourceManager.TryGetTextureLayer(dstKey, out dstLayerIndex) && dstLayerIndex != 0) { - DstKey = DstKey - GetLayerOffset(DstTexture, DstLayerIndex); + dstKey = dstKey - GetLayerOffset(dstTexture, dstLayerIndex); } - Gpu.ResourceManager.SendTexture(Vmm, SrcKey, SrcTexture); - Gpu.ResourceManager.SendTexture(Vmm, DstKey, DstTexture); + _gpu.ResourceManager.SendTexture(vmm, srcKey, srcTexture); + _gpu.ResourceManager.SendTexture(vmm, dstKey, dstTexture); - if (IsSrcLayered && SrcLayerIndex == -1) + if (isSrcLayered && srcLayerIndex == -1) { - for (int Layer = 0; Layer < SrcTexture.LayerCount; Layer++) + for (int layer = 0; layer < srcTexture.LayerCount; layer++) { - Gpu.ResourceManager.SetTextureArrayLayer(SrcKey + GetLayerOffset(SrcTexture, Layer), Layer); + _gpu.ResourceManager.SetTextureArrayLayer(srcKey + GetLayerOffset(srcTexture, layer), layer); } - SrcLayerIndex = 0; + srcLayerIndex = 0; } - if (IsDstLayered && DstLayerIndex == -1) + if (isDstLayered && dstLayerIndex == -1) { - for (int Layer = 0; Layer < DstTexture.LayerCount; Layer++) + for (int layer = 0; layer < dstTexture.LayerCount; layer++) { - Gpu.ResourceManager.SetTextureArrayLayer(DstKey + GetLayerOffset(DstTexture, Layer), Layer); + _gpu.ResourceManager.SetTextureArrayLayer(dstKey + GetLayerOffset(dstTexture, layer), layer); } - DstLayerIndex = 0; + dstLayerIndex = 0; } - int SrcBlitX1 = (int)(SrcBlitX >> 32); - int SrcBlitY1 = (int)(SrcBlitY >> 32); + int srcBlitX1 = (int)(srcBlitX >> 32); + int srcBlitY1 = (int)(srcBlitY >> 32); - int SrcBlitX2 = (int)(SrcBlitX + DstBlitW * BlitDuDx >> 32); - int SrcBlitY2 = (int)(SrcBlitY + DstBlitH * BlitDvDy >> 32); + int srcBlitX2 = (int)(srcBlitX + dstBlitW * blitDuDx >> 32); + int srcBlitY2 = (int)(srcBlitY + dstBlitH * blitDvDy >> 32); - Gpu.Renderer.RenderTarget.Copy( - SrcTexture, - DstTexture, - SrcKey, - DstKey, - SrcLayerIndex, - DstLayerIndex, - SrcBlitX1, - SrcBlitY1, - SrcBlitX2, - SrcBlitY2, - DstBlitX, - DstBlitY, - DstBlitX + DstBlitW, - DstBlitY + DstBlitH); + _gpu.Renderer.RenderTarget.Copy( + srcTexture, + dstTexture, + srcKey, + dstKey, + srcLayerIndex, + dstLayerIndex, + srcBlitX1, + srcBlitY1, + srcBlitX2, + srcBlitY2, + dstBlitX, + dstBlitY, + dstBlitX + dstBlitW, + dstBlitY + dstBlitH); //Do a guest side copy aswell. This is necessary when //the texture is modified by the guest, however it doesn't @@ -209,19 +209,19 @@ namespace Ryujinx.Graphics.Graphics3d // FIXME: SUPPORT MULTILAYER CORRECTLY HERE (this will cause weird stuffs on the first layer) ImageUtils.CopyTexture( - Vmm, - SrcTexture, - DstTexture, - SrcAddress, - DstAddress, - SrcBlitX1, - SrcBlitY1, - DstBlitX, - DstBlitY, - DstBlitW, - DstBlitH); + vmm, + srcTexture, + dstTexture, + srcAddress, + dstAddress, + srcBlitX1, + srcBlitY1, + dstBlitX, + dstBlitY, + dstBlitW, + dstBlitH); - Vmm.IsRegionModified(DstKey, ImageUtils.GetSize(DstTexture), NvGpuBufferType.Texture); + vmm.IsRegionModified(dstKey, ImageUtils.GetSize(dstTexture), NvGpuBufferType.Texture); } private static GalMemoryLayout GetLayout(bool Linear) @@ -231,29 +231,29 @@ namespace Ryujinx.Graphics.Graphics3d : GalMemoryLayout.BlockLinear; } - private long MakeInt64From2xInt32(NvGpuEngine2dReg Reg) + private long MakeInt64From2xInt32(NvGpuEngine2DReg reg) { return - (long)Registers[(int)Reg + 0] << 32 | - (uint)Registers[(int)Reg + 1]; + (long)Registers[(int)reg + 0] << 32 | + (uint)Registers[(int)reg + 1]; } - private void WriteRegister(GpuMethodCall MethCall) + private void WriteRegister(GpuMethodCall methCall) { - Registers[MethCall.Method] = MethCall.Argument; + Registers[methCall.Method] = methCall.Argument; } - private long ReadRegisterFixed1_31_32(NvGpuEngine2dReg Reg) + private long ReadRegisterFixed1_31_32(NvGpuEngine2DReg reg) { - long Low = (uint)ReadRegister(Reg + 0); - long High = (uint)ReadRegister(Reg + 1); + long low = (uint)ReadRegister(reg + 0); + long high = (uint)ReadRegister(reg + 1); - return Low | (High << 32); + return low | (high << 32); } - private int ReadRegister(NvGpuEngine2dReg Reg) + private int ReadRegister(NvGpuEngine2DReg reg) { - return Registers[(int)Reg]; + return Registers[(int)reg]; } } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngine2dReg.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngine2dReg.cs index 7747b5a3ab..8e787c4203 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngine2dReg.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngine2dReg.cs @@ -1,6 +1,6 @@ namespace Ryujinx.Graphics.Graphics3d { - enum NvGpuEngine2dReg + enum NvGpuEngine2DReg { DstFormat = 0x80, DstLinear = 0x81, diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngine3d.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngine3d.cs index 162ff42dbc..781da3797f 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngine3d.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngine3d.cs @@ -8,13 +8,13 @@ using System.Collections.Generic; namespace Ryujinx.Graphics.Graphics3d { - class NvGpuEngine3d : INvGpuEngine + class NvGpuEngine3D : INvGpuEngine { public int[] Registers { get; private set; } - private NvGpu Gpu; + private NvGpu _gpu; - private Dictionary Methods; + private Dictionary _methods; private struct ConstBuffer { @@ -23,28 +23,28 @@ namespace Ryujinx.Graphics.Graphics3d public int Size; } - private ConstBuffer[][] ConstBuffers; + private ConstBuffer[][] _constBuffers; // Height kept for flipping y axis - private int ViewportHeight = 0; + private int _viewportHeight = 0; - private int CurrentInstance = 0; + private int _currentInstance = 0; - public NvGpuEngine3d(NvGpu Gpu) + public NvGpuEngine3D(NvGpu gpu) { - this.Gpu = Gpu; + _gpu = gpu; Registers = new int[0xe00]; - Methods = new Dictionary(); + _methods = new Dictionary(); - void AddMethod(int Meth, int Count, int Stride, NvGpuMethod Method) + void AddMethod(int meth, int count, int stride, NvGpuMethod method) { - while (Count-- > 0) + while (count-- > 0) { - Methods.Add(Meth, Method); + _methods.Add(meth, method); - Meth += Stride; + meth += stride; } } @@ -54,240 +54,240 @@ namespace Ryujinx.Graphics.Graphics3d AddMethod(0x8e4, 16, 1, CbData); AddMethod(0x904, 5, 8, CbBind); - ConstBuffers = new ConstBuffer[6][]; + _constBuffers = new ConstBuffer[6][]; - for (int Index = 0; Index < ConstBuffers.Length; Index++) + for (int index = 0; index < _constBuffers.Length; index++) { - ConstBuffers[Index] = new ConstBuffer[18]; + _constBuffers[index] = new ConstBuffer[18]; } //Ensure that all components are enabled by default. //FIXME: Is this correct? - WriteRegister(NvGpuEngine3dReg.ColorMaskN, 0x1111); + WriteRegister(NvGpuEngine3DReg.ColorMaskN, 0x1111); - WriteRegister(NvGpuEngine3dReg.FrameBufferSrgb, 1); + WriteRegister(NvGpuEngine3DReg.FrameBufferSrgb, 1); - WriteRegister(NvGpuEngine3dReg.FrontFace, (int)GalFrontFace.Cw); + WriteRegister(NvGpuEngine3DReg.FrontFace, (int)GalFrontFace.Cw); - for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++) + for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++) { - WriteRegister(NvGpuEngine3dReg.IBlendNEquationRgb + Index * 8, (int)GalBlendEquation.FuncAdd); - WriteRegister(NvGpuEngine3dReg.IBlendNFuncSrcRgb + Index * 8, (int)GalBlendFactor.One); - WriteRegister(NvGpuEngine3dReg.IBlendNFuncDstRgb + Index * 8, (int)GalBlendFactor.Zero); - WriteRegister(NvGpuEngine3dReg.IBlendNEquationAlpha + Index * 8, (int)GalBlendEquation.FuncAdd); - WriteRegister(NvGpuEngine3dReg.IBlendNFuncSrcAlpha + Index * 8, (int)GalBlendFactor.One); - WriteRegister(NvGpuEngine3dReg.IBlendNFuncDstAlpha + Index * 8, (int)GalBlendFactor.Zero); + WriteRegister(NvGpuEngine3DReg.IBlendNEquationRgb + index * 8, (int)GalBlendEquation.FuncAdd); + WriteRegister(NvGpuEngine3DReg.IBlendNFuncSrcRgb + index * 8, (int)GalBlendFactor.One); + WriteRegister(NvGpuEngine3DReg.IBlendNFuncDstRgb + index * 8, (int)GalBlendFactor.Zero); + WriteRegister(NvGpuEngine3DReg.IBlendNEquationAlpha + index * 8, (int)GalBlendEquation.FuncAdd); + WriteRegister(NvGpuEngine3DReg.IBlendNFuncSrcAlpha + index * 8, (int)GalBlendFactor.One); + WriteRegister(NvGpuEngine3DReg.IBlendNFuncDstAlpha + index * 8, (int)GalBlendFactor.Zero); } } - public void CallMethod(NvGpuVmm Vmm, GpuMethodCall MethCall) + public void CallMethod(NvGpuVmm vmm, GpuMethodCall methCall) { - if (Methods.TryGetValue(MethCall.Method, out NvGpuMethod Method)) + if (_methods.TryGetValue(methCall.Method, out NvGpuMethod method)) { - Method(Vmm, MethCall); + method(vmm, methCall); } else { - WriteRegister(MethCall); + WriteRegister(methCall); } } - private void VertexEndGl(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void VertexEndGl(NvGpuVmm vmm, GpuMethodCall methCall) { LockCaches(); - GalPipelineState State = new GalPipelineState(); + GalPipelineState state = new GalPipelineState(); - SetFrameBuffer(State); - SetFrontFace(State); - SetCullFace(State); - SetDepth(State); - SetStencil(State); - SetScissor(State); - SetBlending(State); - SetColorMask(State); - SetPrimitiveRestart(State); + SetFrameBuffer(state); + SetFrontFace(state); + SetCullFace(state); + SetDepth(state); + SetStencil(state); + SetScissor(state); + SetBlending(state); + SetColorMask(state); + SetPrimitiveRestart(state); - for (int FbIndex = 0; FbIndex < 8; FbIndex++) + for (int fbIndex = 0; fbIndex < 8; fbIndex++) { - SetFrameBuffer(Vmm, FbIndex); + SetFrameBuffer(vmm, fbIndex); } - SetZeta(Vmm); + SetZeta(vmm); SetRenderTargets(); - long[] Keys = UploadShaders(Vmm); + long[] keys = UploadShaders(vmm); - Gpu.Renderer.Shader.BindProgram(); + _gpu.Renderer.Shader.BindProgram(); - UploadTextures(Vmm, State, Keys); - UploadConstBuffers(Vmm, State, Keys); - UploadVertexArrays(Vmm, State); + UploadTextures(vmm, state, keys); + UploadConstBuffers(vmm, state, keys); + UploadVertexArrays(vmm, state); - DispatchRender(Vmm, State); + DispatchRender(vmm, state); UnlockCaches(); } private void LockCaches() { - Gpu.Renderer.Buffer.LockCache(); - Gpu.Renderer.Rasterizer.LockCaches(); - Gpu.Renderer.Texture.LockCache(); + _gpu.Renderer.Buffer.LockCache(); + _gpu.Renderer.Rasterizer.LockCaches(); + _gpu.Renderer.Texture.LockCache(); } private void UnlockCaches() { - Gpu.Renderer.Buffer.UnlockCache(); - Gpu.Renderer.Rasterizer.UnlockCaches(); - Gpu.Renderer.Texture.UnlockCache(); + _gpu.Renderer.Buffer.UnlockCache(); + _gpu.Renderer.Rasterizer.UnlockCaches(); + _gpu.Renderer.Texture.UnlockCache(); } - private void ClearBuffers(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void ClearBuffers(NvGpuVmm vmm, GpuMethodCall methCall) { - int Attachment = (MethCall.Argument >> 6) & 0xf; + int attachment = (methCall.Argument >> 6) & 0xf; - GalClearBufferFlags Flags = (GalClearBufferFlags)(MethCall.Argument & 0x3f); + GalClearBufferFlags flags = (GalClearBufferFlags)(methCall.Argument & 0x3f); - float Red = ReadRegisterFloat(NvGpuEngine3dReg.ClearNColor + 0); - float Green = ReadRegisterFloat(NvGpuEngine3dReg.ClearNColor + 1); - float Blue = ReadRegisterFloat(NvGpuEngine3dReg.ClearNColor + 2); - float Alpha = ReadRegisterFloat(NvGpuEngine3dReg.ClearNColor + 3); + float red = ReadRegisterFloat(NvGpuEngine3DReg.ClearNColor + 0); + float green = ReadRegisterFloat(NvGpuEngine3DReg.ClearNColor + 1); + float blue = ReadRegisterFloat(NvGpuEngine3DReg.ClearNColor + 2); + float alpha = ReadRegisterFloat(NvGpuEngine3DReg.ClearNColor + 3); - float Depth = ReadRegisterFloat(NvGpuEngine3dReg.ClearDepth); + float depth = ReadRegisterFloat(NvGpuEngine3DReg.ClearDepth); - int Stencil = ReadRegister(NvGpuEngine3dReg.ClearStencil); + int stencil = ReadRegister(NvGpuEngine3DReg.ClearStencil); - SetFrameBuffer(Vmm, Attachment); + SetFrameBuffer(vmm, attachment); - SetZeta(Vmm); + SetZeta(vmm); SetRenderTargets(); - Gpu.Renderer.RenderTarget.Bind(); + _gpu.Renderer.RenderTarget.Bind(); - Gpu.Renderer.Rasterizer.ClearBuffers(Flags, Attachment, Red, Green, Blue, Alpha, Depth, Stencil); + _gpu.Renderer.Rasterizer.ClearBuffers(flags, attachment, red, green, blue, alpha, depth, stencil); - Gpu.Renderer.Pipeline.ResetDepthMask(); - Gpu.Renderer.Pipeline.ResetColorMask(Attachment); + _gpu.Renderer.Pipeline.ResetDepthMask(); + _gpu.Renderer.Pipeline.ResetColorMask(attachment); } - private void SetFrameBuffer(NvGpuVmm Vmm, int FbIndex) + private void SetFrameBuffer(NvGpuVmm vmm, int fbIndex) { - long VA = MakeInt64From2xInt32(NvGpuEngine3dReg.FrameBufferNAddress + FbIndex * 0x10); + long va = MakeInt64From2xInt32(NvGpuEngine3DReg.FrameBufferNAddress + fbIndex * 0x10); - int SurfFormat = ReadRegister(NvGpuEngine3dReg.FrameBufferNFormat + FbIndex * 0x10); + int surfFormat = ReadRegister(NvGpuEngine3DReg.FrameBufferNFormat + fbIndex * 0x10); - if (VA == 0 || SurfFormat == 0) + if (va == 0 || surfFormat == 0) { - Gpu.Renderer.RenderTarget.UnbindColor(FbIndex); + _gpu.Renderer.RenderTarget.UnbindColor(fbIndex); return; } - long Key = Vmm.GetPhysicalAddress(VA); + long key = vmm.GetPhysicalAddress(va); - int Width = ReadRegister(NvGpuEngine3dReg.FrameBufferNWidth + FbIndex * 0x10); - int Height = ReadRegister(NvGpuEngine3dReg.FrameBufferNHeight + FbIndex * 0x10); + int width = ReadRegister(NvGpuEngine3DReg.FrameBufferNWidth + fbIndex * 0x10); + int height = ReadRegister(NvGpuEngine3DReg.FrameBufferNHeight + fbIndex * 0x10); - int ArrayMode = ReadRegister(NvGpuEngine3dReg.FrameBufferNArrayMode + FbIndex * 0x10); - int LayerCount = ArrayMode & 0xFFFF; - int LayerStride = ReadRegister(NvGpuEngine3dReg.FrameBufferNLayerStride + FbIndex * 0x10); - int BaseLayer = ReadRegister(NvGpuEngine3dReg.FrameBufferNBaseLayer + FbIndex * 0x10); - int BlockDim = ReadRegister(NvGpuEngine3dReg.FrameBufferNBlockDim + FbIndex * 0x10); + int arrayMode = ReadRegister(NvGpuEngine3DReg.FrameBufferNArrayMode + fbIndex * 0x10); + int layerCount = arrayMode & 0xFFFF; + int layerStride = ReadRegister(NvGpuEngine3DReg.FrameBufferNLayerStride + fbIndex * 0x10); + int baseLayer = ReadRegister(NvGpuEngine3DReg.FrameBufferNBaseLayer + fbIndex * 0x10); + int blockDim = ReadRegister(NvGpuEngine3DReg.FrameBufferNBlockDim + fbIndex * 0x10); - int GobBlockHeight = 1 << ((BlockDim >> 4) & 7); + int gobBlockHeight = 1 << ((blockDim >> 4) & 7); - GalMemoryLayout Layout = (GalMemoryLayout)((BlockDim >> 12) & 1); + GalMemoryLayout layout = (GalMemoryLayout)((blockDim >> 12) & 1); - float TX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateX + FbIndex * 8); - float TY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateY + FbIndex * 8); + float tx = ReadRegisterFloat(NvGpuEngine3DReg.ViewportNTranslateX + fbIndex * 8); + float ty = ReadRegisterFloat(NvGpuEngine3DReg.ViewportNTranslateY + fbIndex * 8); - float SX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleX + FbIndex * 8); - float SY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleY + FbIndex * 8); + float sx = ReadRegisterFloat(NvGpuEngine3DReg.ViewportNScaleX + fbIndex * 8); + float sy = ReadRegisterFloat(NvGpuEngine3DReg.ViewportNScaleY + fbIndex * 8); - int VpX = (int)MathF.Max(0, TX - MathF.Abs(SX)); - int VpY = (int)MathF.Max(0, TY - MathF.Abs(SY)); + int vpX = (int)MathF.Max(0, tx - MathF.Abs(sx)); + int vpY = (int)MathF.Max(0, ty - MathF.Abs(sy)); - int VpW = (int)(TX + MathF.Abs(SX)) - VpX; - int VpH = (int)(TY + MathF.Abs(SY)) - VpY; + int vpW = (int)(tx + MathF.Abs(sx)) - vpX; + int vpH = (int)(ty + MathF.Abs(sy)) - vpY; - GalImageFormat Format = ImageUtils.ConvertSurface((GalSurfaceFormat)SurfFormat); + GalImageFormat format = ImageUtils.ConvertSurface((GalSurfaceFormat)surfFormat); - GalImage Image = new GalImage(Width, Height, 1, 1, 1, GobBlockHeight, 1, Layout, Format, GalTextureTarget.TwoD); + GalImage image = new GalImage(width, height, 1, 1, 1, gobBlockHeight, 1, layout, format, GalTextureTarget.TwoD); - Gpu.ResourceManager.SendColorBuffer(Vmm, Key, FbIndex, Image); + _gpu.ResourceManager.SendColorBuffer(vmm, key, fbIndex, image); - ViewportHeight = VpH; + _viewportHeight = vpH; - Gpu.Renderer.RenderTarget.SetViewport(FbIndex, VpX, VpY, VpW, VpH); + _gpu.Renderer.RenderTarget.SetViewport(fbIndex, vpX, vpY, vpW, vpH); } - private void SetFrameBuffer(GalPipelineState State) + private void SetFrameBuffer(GalPipelineState state) { - State.FramebufferSrgb = ReadRegisterBool(NvGpuEngine3dReg.FrameBufferSrgb); + state.FramebufferSrgb = ReadRegisterBool(NvGpuEngine3DReg.FrameBufferSrgb); - State.FlipX = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleX); - State.FlipY = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleY); + state.FlipX = GetFlipSign(NvGpuEngine3DReg.ViewportNScaleX); + state.FlipY = GetFlipSign(NvGpuEngine3DReg.ViewportNScaleY); - int ScreenYControl = ReadRegister(NvGpuEngine3dReg.ScreenYControl); + int screenYControl = ReadRegister(NvGpuEngine3DReg.ScreenYControl); - bool NegateY = (ScreenYControl & 1) != 0; + bool negateY = (screenYControl & 1) != 0; - if (NegateY) + if (negateY) { - State.FlipY = -State.FlipY; + state.FlipY = -state.FlipY; } } - private void SetZeta(NvGpuVmm Vmm) + private void SetZeta(NvGpuVmm vmm) { - long VA = MakeInt64From2xInt32(NvGpuEngine3dReg.ZetaAddress); + long va = MakeInt64From2xInt32(NvGpuEngine3DReg.ZetaAddress); - int ZetaFormat = ReadRegister(NvGpuEngine3dReg.ZetaFormat); + int zetaFormat = ReadRegister(NvGpuEngine3DReg.ZetaFormat); - int BlockDim = ReadRegister(NvGpuEngine3dReg.ZetaBlockDimensions); + int blockDim = ReadRegister(NvGpuEngine3DReg.ZetaBlockDimensions); - int GobBlockHeight = 1 << ((BlockDim >> 4) & 7); + int gobBlockHeight = 1 << ((blockDim >> 4) & 7); - GalMemoryLayout Layout = (GalMemoryLayout)((BlockDim >> 12) & 1); //? + GalMemoryLayout layout = (GalMemoryLayout)((blockDim >> 12) & 1); //? - bool ZetaEnable = ReadRegisterBool(NvGpuEngine3dReg.ZetaEnable); + bool zetaEnable = ReadRegisterBool(NvGpuEngine3DReg.ZetaEnable); - if (VA == 0 || ZetaFormat == 0 || !ZetaEnable) + if (va == 0 || zetaFormat == 0 || !zetaEnable) { - Gpu.Renderer.RenderTarget.UnbindZeta(); + _gpu.Renderer.RenderTarget.UnbindZeta(); return; } - long Key = Vmm.GetPhysicalAddress(VA); + long key = vmm.GetPhysicalAddress(va); - int Width = ReadRegister(NvGpuEngine3dReg.ZetaHoriz); - int Height = ReadRegister(NvGpuEngine3dReg.ZetaVert); + int width = ReadRegister(NvGpuEngine3DReg.ZetaHoriz); + int height = ReadRegister(NvGpuEngine3DReg.ZetaVert); - GalImageFormat Format = ImageUtils.ConvertZeta((GalZetaFormat)ZetaFormat); + GalImageFormat format = ImageUtils.ConvertZeta((GalZetaFormat)zetaFormat); // TODO: Support non 2D? - GalImage Image = new GalImage(Width, Height, 1, 1, 1, GobBlockHeight, 1, Layout, Format, GalTextureTarget.TwoD); + GalImage image = new GalImage(width, height, 1, 1, 1, gobBlockHeight, 1, layout, format, GalTextureTarget.TwoD); - Gpu.ResourceManager.SendZetaBuffer(Vmm, Key, Image); + _gpu.ResourceManager.SendZetaBuffer(vmm, key, image); } - private long[] UploadShaders(NvGpuVmm Vmm) + private long[] UploadShaders(NvGpuVmm vmm) { - long[] Keys = new long[5]; + long[] keys = new long[5]; - long BasePosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress); + long basePosition = MakeInt64From2xInt32(NvGpuEngine3DReg.ShaderAddress); - int Index = 1; + int index = 1; - int VpAControl = ReadRegister(NvGpuEngine3dReg.ShaderNControl); + int vpAControl = ReadRegister(NvGpuEngine3DReg.ShaderNControl); - bool VpAEnable = (VpAControl & 1) != 0; + bool vpAEnable = (vpAControl & 1) != 0; - if (VpAEnable) + if (vpAEnable) { //Note: The maxwell supports 2 vertex programs, usually //only VP B is used, but in some cases VP A is also used. @@ -295,51 +295,51 @@ namespace Ryujinx.Graphics.Graphics3d //shader stage. //The graphics abstraction layer has a special overload for this //case, which should merge the two shaders into one vertex shader. - int VpAOffset = ReadRegister(NvGpuEngine3dReg.ShaderNOffset); - int VpBOffset = ReadRegister(NvGpuEngine3dReg.ShaderNOffset + 0x10); + int vpAOffset = ReadRegister(NvGpuEngine3DReg.ShaderNOffset); + int vpBOffset = ReadRegister(NvGpuEngine3DReg.ShaderNOffset + 0x10); - long VpAPos = BasePosition + (uint)VpAOffset; - long VpBPos = BasePosition + (uint)VpBOffset; + long vpAPos = basePosition + (uint)vpAOffset; + long vpBPos = basePosition + (uint)vpBOffset; - Keys[(int)GalShaderType.Vertex] = VpBPos; + keys[(int)GalShaderType.Vertex] = vpBPos; - Gpu.Renderer.Shader.Create(Vmm, VpAPos, VpBPos, GalShaderType.Vertex); - Gpu.Renderer.Shader.Bind(VpBPos); + _gpu.Renderer.Shader.Create(vmm, vpAPos, vpBPos, GalShaderType.Vertex); + _gpu.Renderer.Shader.Bind(vpBPos); - Index = 2; + index = 2; } - for (; Index < 6; Index++) + for (; index < 6; index++) { - GalShaderType Type = GetTypeFromProgram(Index); + GalShaderType type = GetTypeFromProgram(index); - int Control = ReadRegister(NvGpuEngine3dReg.ShaderNControl + Index * 0x10); - int Offset = ReadRegister(NvGpuEngine3dReg.ShaderNOffset + Index * 0x10); + int control = ReadRegister(NvGpuEngine3DReg.ShaderNControl + index * 0x10); + int offset = ReadRegister(NvGpuEngine3DReg.ShaderNOffset + index * 0x10); //Note: Vertex Program (B) is always enabled. - bool Enable = (Control & 1) != 0 || Index == 1; + bool enable = (control & 1) != 0 || index == 1; - if (!Enable) + if (!enable) { - Gpu.Renderer.Shader.Unbind(Type); + _gpu.Renderer.Shader.Unbind(type); continue; } - long Key = BasePosition + (uint)Offset; + long key = basePosition + (uint)offset; - Keys[(int)Type] = Key; + keys[(int)type] = key; - Gpu.Renderer.Shader.Create(Vmm, Key, Type); - Gpu.Renderer.Shader.Bind(Key); + _gpu.Renderer.Shader.Create(vmm, key, type); + _gpu.Renderer.Shader.Bind(key); } - return Keys; + return keys; } - private static GalShaderType GetTypeFromProgram(int Program) + private static GalShaderType GetTypeFromProgram(int program) { - switch (Program) + switch (program) { case 0: case 1: return GalShaderType.Vertex; @@ -349,193 +349,193 @@ namespace Ryujinx.Graphics.Graphics3d case 5: return GalShaderType.Fragment; } - throw new ArgumentOutOfRangeException(nameof(Program)); + throw new ArgumentOutOfRangeException(nameof(program)); } - private void SetFrontFace(GalPipelineState State) + private void SetFrontFace(GalPipelineState state) { - float SignX = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleX); - float SignY = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleY); + float signX = GetFlipSign(NvGpuEngine3DReg.ViewportNScaleX); + float signY = GetFlipSign(NvGpuEngine3DReg.ViewportNScaleY); - GalFrontFace FrontFace = (GalFrontFace)ReadRegister(NvGpuEngine3dReg.FrontFace); + GalFrontFace frontFace = (GalFrontFace)ReadRegister(NvGpuEngine3DReg.FrontFace); //Flipping breaks facing. Flipping front facing too fixes it - if (SignX != SignY) + if (signX != signY) { - switch (FrontFace) + switch (frontFace) { - case GalFrontFace.Cw: FrontFace = GalFrontFace.Ccw; break; - case GalFrontFace.Ccw: FrontFace = GalFrontFace.Cw; break; + case GalFrontFace.Cw: frontFace = GalFrontFace.Ccw; break; + case GalFrontFace.Ccw: frontFace = GalFrontFace.Cw; break; } } - State.FrontFace = FrontFace; + state.FrontFace = frontFace; } - private void SetCullFace(GalPipelineState State) + private void SetCullFace(GalPipelineState state) { - State.CullFaceEnabled = ReadRegisterBool(NvGpuEngine3dReg.CullFaceEnable); + state.CullFaceEnabled = ReadRegisterBool(NvGpuEngine3DReg.CullFaceEnable); - if (State.CullFaceEnabled) + if (state.CullFaceEnabled) { - State.CullFace = (GalCullFace)ReadRegister(NvGpuEngine3dReg.CullFace); + state.CullFace = (GalCullFace)ReadRegister(NvGpuEngine3DReg.CullFace); } } - private void SetDepth(GalPipelineState State) + private void SetDepth(GalPipelineState state) { - State.DepthTestEnabled = ReadRegisterBool(NvGpuEngine3dReg.DepthTestEnable); + state.DepthTestEnabled = ReadRegisterBool(NvGpuEngine3DReg.DepthTestEnable); - State.DepthWriteEnabled = ReadRegisterBool(NvGpuEngine3dReg.DepthWriteEnable); + state.DepthWriteEnabled = ReadRegisterBool(NvGpuEngine3DReg.DepthWriteEnable); - if (State.DepthTestEnabled) + if (state.DepthTestEnabled) { - State.DepthFunc = (GalComparisonOp)ReadRegister(NvGpuEngine3dReg.DepthTestFunction); + state.DepthFunc = (GalComparisonOp)ReadRegister(NvGpuEngine3DReg.DepthTestFunction); } - State.DepthRangeNear = ReadRegisterFloat(NvGpuEngine3dReg.DepthRangeNNear); - State.DepthRangeFar = ReadRegisterFloat(NvGpuEngine3dReg.DepthRangeNFar); + state.DepthRangeNear = ReadRegisterFloat(NvGpuEngine3DReg.DepthRangeNNear); + state.DepthRangeFar = ReadRegisterFloat(NvGpuEngine3DReg.DepthRangeNFar); } - private void SetStencil(GalPipelineState State) + private void SetStencil(GalPipelineState state) { - State.StencilTestEnabled = ReadRegisterBool(NvGpuEngine3dReg.StencilEnable); + state.StencilTestEnabled = ReadRegisterBool(NvGpuEngine3DReg.StencilEnable); - if (State.StencilTestEnabled) + if (state.StencilTestEnabled) { - State.StencilBackFuncFunc = (GalComparisonOp)ReadRegister(NvGpuEngine3dReg.StencilBackFuncFunc); - State.StencilBackFuncRef = ReadRegister(NvGpuEngine3dReg.StencilBackFuncRef); - State.StencilBackFuncMask = (uint)ReadRegister(NvGpuEngine3dReg.StencilBackFuncMask); - State.StencilBackOpFail = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilBackOpFail); - State.StencilBackOpZFail = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilBackOpZFail); - State.StencilBackOpZPass = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilBackOpZPass); - State.StencilBackMask = (uint)ReadRegister(NvGpuEngine3dReg.StencilBackMask); + state.StencilBackFuncFunc = (GalComparisonOp)ReadRegister(NvGpuEngine3DReg.StencilBackFuncFunc); + state.StencilBackFuncRef = ReadRegister(NvGpuEngine3DReg.StencilBackFuncRef); + state.StencilBackFuncMask = (uint)ReadRegister(NvGpuEngine3DReg.StencilBackFuncMask); + state.StencilBackOpFail = (GalStencilOp)ReadRegister(NvGpuEngine3DReg.StencilBackOpFail); + state.StencilBackOpZFail = (GalStencilOp)ReadRegister(NvGpuEngine3DReg.StencilBackOpZFail); + state.StencilBackOpZPass = (GalStencilOp)ReadRegister(NvGpuEngine3DReg.StencilBackOpZPass); + state.StencilBackMask = (uint)ReadRegister(NvGpuEngine3DReg.StencilBackMask); - State.StencilFrontFuncFunc = (GalComparisonOp)ReadRegister(NvGpuEngine3dReg.StencilFrontFuncFunc); - State.StencilFrontFuncRef = ReadRegister(NvGpuEngine3dReg.StencilFrontFuncRef); - State.StencilFrontFuncMask = (uint)ReadRegister(NvGpuEngine3dReg.StencilFrontFuncMask); - State.StencilFrontOpFail = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilFrontOpFail); - State.StencilFrontOpZFail = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilFrontOpZFail); - State.StencilFrontOpZPass = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilFrontOpZPass); - State.StencilFrontMask = (uint)ReadRegister(NvGpuEngine3dReg.StencilFrontMask); + state.StencilFrontFuncFunc = (GalComparisonOp)ReadRegister(NvGpuEngine3DReg.StencilFrontFuncFunc); + state.StencilFrontFuncRef = ReadRegister(NvGpuEngine3DReg.StencilFrontFuncRef); + state.StencilFrontFuncMask = (uint)ReadRegister(NvGpuEngine3DReg.StencilFrontFuncMask); + state.StencilFrontOpFail = (GalStencilOp)ReadRegister(NvGpuEngine3DReg.StencilFrontOpFail); + state.StencilFrontOpZFail = (GalStencilOp)ReadRegister(NvGpuEngine3DReg.StencilFrontOpZFail); + state.StencilFrontOpZPass = (GalStencilOp)ReadRegister(NvGpuEngine3DReg.StencilFrontOpZPass); + state.StencilFrontMask = (uint)ReadRegister(NvGpuEngine3DReg.StencilFrontMask); } } - private void SetScissor(GalPipelineState State) + private void SetScissor(GalPipelineState state) { // FIXME: Stubbed, only the first scissor test is valid without a geometry shader loaded. At time of writing geometry shaders are also stubbed. // Once geometry shaders are fixed it should be equal to GalPipelineState.RenderTargetCount when shader loaded, otherwise equal to 1 - State.ScissorTestCount = 1; + state.ScissorTestCount = 1; - for (int Index = 0; Index < State.ScissorTestCount; Index++) + for (int index = 0; index < state.ScissorTestCount; index++) { - State.ScissorTestEnabled[Index] = ReadRegisterBool(NvGpuEngine3dReg.ScissorEnable + Index * 4); + state.ScissorTestEnabled[index] = ReadRegisterBool(NvGpuEngine3DReg.ScissorEnable + index * 4); - if (State.ScissorTestEnabled[Index]) + if (state.ScissorTestEnabled[index]) { - uint ScissorHorizontal = (uint)ReadRegister(NvGpuEngine3dReg.ScissorHorizontal + Index * 4); - uint ScissorVertical = (uint)ReadRegister(NvGpuEngine3dReg.ScissorVertical + Index * 4); + uint scissorHorizontal = (uint)ReadRegister(NvGpuEngine3DReg.ScissorHorizontal + index * 4); + uint scissorVertical = (uint)ReadRegister(NvGpuEngine3DReg.ScissorVertical + index * 4); - State.ScissorTestX[Index] = (int)((ScissorHorizontal & 0xFFFF) * State.FlipX); // X, lower 16 bits - State.ScissorTestWidth[Index] = (int)((ScissorHorizontal >> 16) * State.FlipX) - State.ScissorTestX[Index]; // Width, right side is upper 16 bits + state.ScissorTestX[index] = (int)((scissorHorizontal & 0xFFFF) * state.FlipX); // X, lower 16 bits + state.ScissorTestWidth[index] = (int)((scissorHorizontal >> 16) * state.FlipX) - state.ScissorTestX[index]; // Width, right side is upper 16 bits - State.ScissorTestY[Index] = (int)((ScissorVertical & 0xFFFF)); // Y, lower 16 bits - State.ScissorTestHeight[Index] = (int)((ScissorVertical >> 16)) - State.ScissorTestY[Index]; // Height, top side is upper 16 bits + state.ScissorTestY[index] = (int)((scissorVertical & 0xFFFF)); // Y, lower 16 bits + state.ScissorTestHeight[index] = (int)((scissorVertical >> 16)) - state.ScissorTestY[index]; // Height, top side is upper 16 bits // Y coordinates may have to be flipped - if ((int)State.FlipY == -1) + if ((int)state.FlipY == -1) { - State.ScissorTestY[Index] = ViewportHeight - State.ScissorTestY[Index] - State.ScissorTestHeight[Index]; + state.ScissorTestY[index] = _viewportHeight - state.ScissorTestY[index] - state.ScissorTestHeight[index]; // Handle negative viewpont coordinate - if (State.ScissorTestY[Index] < 0) + if (state.ScissorTestY[index] < 0) { - State.ScissorTestY[Index] = 0; + state.ScissorTestY[index] = 0; } } } } } - private void SetBlending(GalPipelineState State) + private void SetBlending(GalPipelineState state) { - bool BlendIndependent = ReadRegisterBool(NvGpuEngine3dReg.BlendIndependent); + bool blendIndependent = ReadRegisterBool(NvGpuEngine3DReg.BlendIndependent); - State.BlendIndependent = BlendIndependent; + state.BlendIndependent = blendIndependent; - for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++) + for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++) { - if (BlendIndependent) + if (blendIndependent) { - State.Blends[Index].Enabled = ReadRegisterBool(NvGpuEngine3dReg.IBlendNEnable + Index); + state.Blends[index].Enabled = ReadRegisterBool(NvGpuEngine3DReg.IBlendNEnable + index); - if (State.Blends[Index].Enabled) + if (state.Blends[index].Enabled) { - State.Blends[Index].SeparateAlpha = ReadRegisterBool(NvGpuEngine3dReg.IBlendNSeparateAlpha + Index * 8); + state.Blends[index].SeparateAlpha = ReadRegisterBool(NvGpuEngine3DReg.IBlendNSeparateAlpha + index * 8); - State.Blends[Index].EquationRgb = ReadBlendEquation(NvGpuEngine3dReg.IBlendNEquationRgb + Index * 8); - State.Blends[Index].FuncSrcRgb = ReadBlendFactor (NvGpuEngine3dReg.IBlendNFuncSrcRgb + Index * 8); - State.Blends[Index].FuncDstRgb = ReadBlendFactor (NvGpuEngine3dReg.IBlendNFuncDstRgb + Index * 8); - State.Blends[Index].EquationAlpha = ReadBlendEquation(NvGpuEngine3dReg.IBlendNEquationAlpha + Index * 8); - State.Blends[Index].FuncSrcAlpha = ReadBlendFactor (NvGpuEngine3dReg.IBlendNFuncSrcAlpha + Index * 8); - State.Blends[Index].FuncDstAlpha = ReadBlendFactor (NvGpuEngine3dReg.IBlendNFuncDstAlpha + Index * 8); + state.Blends[index].EquationRgb = ReadBlendEquation(NvGpuEngine3DReg.IBlendNEquationRgb + index * 8); + state.Blends[index].FuncSrcRgb = ReadBlendFactor (NvGpuEngine3DReg.IBlendNFuncSrcRgb + index * 8); + state.Blends[index].FuncDstRgb = ReadBlendFactor (NvGpuEngine3DReg.IBlendNFuncDstRgb + index * 8); + state.Blends[index].EquationAlpha = ReadBlendEquation(NvGpuEngine3DReg.IBlendNEquationAlpha + index * 8); + state.Blends[index].FuncSrcAlpha = ReadBlendFactor (NvGpuEngine3DReg.IBlendNFuncSrcAlpha + index * 8); + state.Blends[index].FuncDstAlpha = ReadBlendFactor (NvGpuEngine3DReg.IBlendNFuncDstAlpha + index * 8); } } else { //It seems that even when independent blend is disabled, the first IBlend enable //register is still set to indicate whenever blend is enabled or not (?). - State.Blends[Index].Enabled = ReadRegisterBool(NvGpuEngine3dReg.IBlendNEnable); + state.Blends[index].Enabled = ReadRegisterBool(NvGpuEngine3DReg.IBlendNEnable); - if (State.Blends[Index].Enabled) + if (state.Blends[index].Enabled) { - State.Blends[Index].SeparateAlpha = ReadRegisterBool(NvGpuEngine3dReg.BlendSeparateAlpha); + state.Blends[index].SeparateAlpha = ReadRegisterBool(NvGpuEngine3DReg.BlendSeparateAlpha); - State.Blends[Index].EquationRgb = ReadBlendEquation(NvGpuEngine3dReg.BlendEquationRgb); - State.Blends[Index].FuncSrcRgb = ReadBlendFactor (NvGpuEngine3dReg.BlendFuncSrcRgb); - State.Blends[Index].FuncDstRgb = ReadBlendFactor (NvGpuEngine3dReg.BlendFuncDstRgb); - State.Blends[Index].EquationAlpha = ReadBlendEquation(NvGpuEngine3dReg.BlendEquationAlpha); - State.Blends[Index].FuncSrcAlpha = ReadBlendFactor (NvGpuEngine3dReg.BlendFuncSrcAlpha); - State.Blends[Index].FuncDstAlpha = ReadBlendFactor (NvGpuEngine3dReg.BlendFuncDstAlpha); + state.Blends[index].EquationRgb = ReadBlendEquation(NvGpuEngine3DReg.BlendEquationRgb); + state.Blends[index].FuncSrcRgb = ReadBlendFactor (NvGpuEngine3DReg.BlendFuncSrcRgb); + state.Blends[index].FuncDstRgb = ReadBlendFactor (NvGpuEngine3DReg.BlendFuncDstRgb); + state.Blends[index].EquationAlpha = ReadBlendEquation(NvGpuEngine3DReg.BlendEquationAlpha); + state.Blends[index].FuncSrcAlpha = ReadBlendFactor (NvGpuEngine3DReg.BlendFuncSrcAlpha); + state.Blends[index].FuncDstAlpha = ReadBlendFactor (NvGpuEngine3DReg.BlendFuncDstAlpha); } } } } - private GalBlendEquation ReadBlendEquation(NvGpuEngine3dReg Register) + private GalBlendEquation ReadBlendEquation(NvGpuEngine3DReg register) { - return (GalBlendEquation)ReadRegister(Register); + return (GalBlendEquation)ReadRegister(register); } - private GalBlendFactor ReadBlendFactor(NvGpuEngine3dReg Register) + private GalBlendFactor ReadBlendFactor(NvGpuEngine3DReg register) { - return (GalBlendFactor)ReadRegister(Register); + return (GalBlendFactor)ReadRegister(register); } - private void SetColorMask(GalPipelineState State) + private void SetColorMask(GalPipelineState state) { - bool ColorMaskCommon = ReadRegisterBool(NvGpuEngine3dReg.ColorMaskCommon); + bool colorMaskCommon = ReadRegisterBool(NvGpuEngine3DReg.ColorMaskCommon); - State.ColorMaskCommon = ColorMaskCommon; + state.ColorMaskCommon = colorMaskCommon; - for (int Index = 0; Index < GalPipelineState.RenderTargetsCount; Index++) + for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++) { - int ColorMask = ReadRegister(NvGpuEngine3dReg.ColorMaskN + (ColorMaskCommon ? 0 : Index)); + int colorMask = ReadRegister(NvGpuEngine3DReg.ColorMaskN + (colorMaskCommon ? 0 : index)); - State.ColorMasks[Index].Red = ((ColorMask >> 0) & 0xf) != 0; - State.ColorMasks[Index].Green = ((ColorMask >> 4) & 0xf) != 0; - State.ColorMasks[Index].Blue = ((ColorMask >> 8) & 0xf) != 0; - State.ColorMasks[Index].Alpha = ((ColorMask >> 12) & 0xf) != 0; + state.ColorMasks[index].Red = ((colorMask >> 0) & 0xf) != 0; + state.ColorMasks[index].Green = ((colorMask >> 4) & 0xf) != 0; + state.ColorMasks[index].Blue = ((colorMask >> 8) & 0xf) != 0; + state.ColorMasks[index].Alpha = ((colorMask >> 12) & 0xf) != 0; } } - private void SetPrimitiveRestart(GalPipelineState State) + private void SetPrimitiveRestart(GalPipelineState state) { - State.PrimitiveRestartEnabled = ReadRegisterBool(NvGpuEngine3dReg.PrimRestartEnable); + state.PrimitiveRestartEnabled = ReadRegisterBool(NvGpuEngine3DReg.PrimRestartEnable); - if (State.PrimitiveRestartEnabled) + if (state.PrimitiveRestartEnabled) { - State.PrimitiveRestartIndex = (uint)ReadRegister(NvGpuEngine3dReg.PrimRestartIndex); + state.PrimitiveRestartIndex = (uint)ReadRegister(NvGpuEngine3DReg.PrimRestartIndex); } } @@ -544,462 +544,462 @@ namespace Ryujinx.Graphics.Graphics3d //Commercial games do not seem to //bool SeparateFragData = ReadRegisterBool(NvGpuEngine3dReg.RTSeparateFragData); - uint Control = (uint)(ReadRegister(NvGpuEngine3dReg.RTControl)); + uint control = (uint)(ReadRegister(NvGpuEngine3DReg.RtControl)); - uint Count = Control & 0xf; + uint count = control & 0xf; - if (Count > 0) + if (count > 0) { - int[] Map = new int[Count]; + int[] map = new int[count]; - for (int Index = 0; Index < Count; Index++) + for (int index = 0; index < count; index++) { - int Shift = 4 + Index * 3; + int shift = 4 + index * 3; - Map[Index] = (int)((Control >> Shift) & 7); + map[index] = (int)((control >> shift) & 7); } - Gpu.Renderer.RenderTarget.SetMap(Map); + _gpu.Renderer.RenderTarget.SetMap(map); } else { - Gpu.Renderer.RenderTarget.SetMap(null); + _gpu.Renderer.RenderTarget.SetMap(null); } } - private void UploadTextures(NvGpuVmm Vmm, GalPipelineState State, long[] Keys) + private void UploadTextures(NvGpuVmm vmm, GalPipelineState state, long[] keys) { - long BaseShPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress); + long baseShPosition = MakeInt64From2xInt32(NvGpuEngine3DReg.ShaderAddress); - int TextureCbIndex = ReadRegister(NvGpuEngine3dReg.TextureCbIndex); + int textureCbIndex = ReadRegister(NvGpuEngine3DReg.TextureCbIndex); - List<(long, GalImage, GalTextureSampler)> UnboundTextures = new List<(long, GalImage, GalTextureSampler)>(); + List<(long, GalImage, GalTextureSampler)> unboundTextures = new List<(long, GalImage, GalTextureSampler)>(); - for (int Index = 0; Index < Keys.Length; Index++) + for (int index = 0; index < keys.Length; index++) { - foreach (ShaderDeclInfo DeclInfo in Gpu.Renderer.Shader.GetTextureUsage(Keys[Index])) + foreach (ShaderDeclInfo declInfo in _gpu.Renderer.Shader.GetTextureUsage(keys[index])) { - long Position; + long position; - if (DeclInfo.IsCb) + if (declInfo.IsCb) { - Position = ConstBuffers[Index][DeclInfo.Cbuf].Position; + position = _constBuffers[index][declInfo.Cbuf].Position; } else { - Position = ConstBuffers[Index][TextureCbIndex].Position; + position = _constBuffers[index][textureCbIndex].Position; } - int TextureHandle = Vmm.ReadInt32(Position + DeclInfo.Index * 4); + int textureHandle = vmm.ReadInt32(position + declInfo.Index * 4); - UnboundTextures.Add(UploadTexture(Vmm, TextureHandle)); + unboundTextures.Add(UploadTexture(vmm, textureHandle)); } } - for (int Index = 0; Index < UnboundTextures.Count; Index++) + for (int index = 0; index < unboundTextures.Count; index++) { - (long Key, GalImage Image, GalTextureSampler Sampler) = UnboundTextures[Index]; + (long key, GalImage image, GalTextureSampler sampler) = unboundTextures[index]; - if (Key == 0) + if (key == 0) { continue; } - Gpu.Renderer.Texture.Bind(Key, Index, Image); - Gpu.Renderer.Texture.SetSampler(Image, Sampler); + _gpu.Renderer.Texture.Bind(key, index, image); + _gpu.Renderer.Texture.SetSampler(image, sampler); } } - private (long, GalImage, GalTextureSampler) UploadTexture(NvGpuVmm Vmm, int TextureHandle) + private (long, GalImage, GalTextureSampler) UploadTexture(NvGpuVmm vmm, int textureHandle) { - if (TextureHandle == 0) + if (textureHandle == 0) { //FIXME: Some games like puyo puyo will use handles with the value 0. //This is a bug, most likely caused by sync issues. return (0, default(GalImage), default(GalTextureSampler)); } - bool LinkedTsc = ReadRegisterBool(NvGpuEngine3dReg.LinkedTsc); + bool linkedTsc = ReadRegisterBool(NvGpuEngine3DReg.LinkedTsc); - int TicIndex = (TextureHandle >> 0) & 0xfffff; + int ticIndex = (textureHandle >> 0) & 0xfffff; - int TscIndex = LinkedTsc ? TicIndex : (TextureHandle >> 20) & 0xfff; + int tscIndex = linkedTsc ? ticIndex : (textureHandle >> 20) & 0xfff; - long TicPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.TexHeaderPoolOffset); - long TscPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.TexSamplerPoolOffset); + long ticPosition = MakeInt64From2xInt32(NvGpuEngine3DReg.TexHeaderPoolOffset); + long tscPosition = MakeInt64From2xInt32(NvGpuEngine3DReg.TexSamplerPoolOffset); - TicPosition += TicIndex * 0x20; - TscPosition += TscIndex * 0x20; + ticPosition += ticIndex * 0x20; + tscPosition += tscIndex * 0x20; - GalImage Image = TextureFactory.MakeTexture(Vmm, TicPosition); + GalImage image = TextureFactory.MakeTexture(vmm, ticPosition); - GalTextureSampler Sampler = TextureFactory.MakeSampler(Gpu, Vmm, TscPosition); + GalTextureSampler sampler = TextureFactory.MakeSampler(_gpu, vmm, tscPosition); - long Key = Vmm.ReadInt64(TicPosition + 4) & 0xffffffffffff; + long key = vmm.ReadInt64(ticPosition + 4) & 0xffffffffffff; - if (Image.Layout == GalMemoryLayout.BlockLinear) + if (image.Layout == GalMemoryLayout.BlockLinear) { - Key &= ~0x1ffL; + key &= ~0x1ffL; } - else if (Image.Layout == GalMemoryLayout.Pitch) + else if (image.Layout == GalMemoryLayout.Pitch) { - Key &= ~0x1fL; + key &= ~0x1fL; } - Key = Vmm.GetPhysicalAddress(Key); + key = vmm.GetPhysicalAddress(key); - if (Key == -1) + if (key == -1) { //FIXME: Shouldn't ignore invalid addresses. return (0, default(GalImage), default(GalTextureSampler)); } - Gpu.ResourceManager.SendTexture(Vmm, Key, Image); + _gpu.ResourceManager.SendTexture(vmm, key, image); - return (Key, Image, Sampler); + return (Key: key, Image: image, Sampler: sampler); } - private void UploadConstBuffers(NvGpuVmm Vmm, GalPipelineState State, long[] Keys) + private void UploadConstBuffers(NvGpuVmm vmm, GalPipelineState state, long[] keys) { - for (int Stage = 0; Stage < Keys.Length; Stage++) + for (int stage = 0; stage < keys.Length; stage++) { - foreach (ShaderDeclInfo DeclInfo in Gpu.Renderer.Shader.GetConstBufferUsage(Keys[Stage])) + foreach (ShaderDeclInfo declInfo in _gpu.Renderer.Shader.GetConstBufferUsage(keys[stage])) { - ConstBuffer Cb = ConstBuffers[Stage][DeclInfo.Cbuf]; + ConstBuffer cb = _constBuffers[stage][declInfo.Cbuf]; - if (!Cb.Enabled) + if (!cb.Enabled) { continue; } - long Key = Vmm.GetPhysicalAddress(Cb.Position); + long key = vmm.GetPhysicalAddress(cb.Position); - if (Gpu.ResourceManager.MemoryRegionModified(Vmm, Key, Cb.Size, NvGpuBufferType.ConstBuffer)) + if (_gpu.ResourceManager.MemoryRegionModified(vmm, key, cb.Size, NvGpuBufferType.ConstBuffer)) { - if (Vmm.TryGetHostAddress(Cb.Position, Cb.Size, out IntPtr CbPtr)) + if (vmm.TryGetHostAddress(cb.Position, cb.Size, out IntPtr cbPtr)) { - Gpu.Renderer.Buffer.SetData(Key, Cb.Size, CbPtr); + _gpu.Renderer.Buffer.SetData(key, cb.Size, cbPtr); } else { - Gpu.Renderer.Buffer.SetData(Key, Vmm.ReadBytes(Cb.Position, Cb.Size)); + _gpu.Renderer.Buffer.SetData(key, vmm.ReadBytes(cb.Position, cb.Size)); } } - State.ConstBufferKeys[Stage][DeclInfo.Cbuf] = Key; + state.ConstBufferKeys[stage][declInfo.Cbuf] = key; } } } - private void UploadVertexArrays(NvGpuVmm Vmm, GalPipelineState State) + private void UploadVertexArrays(NvGpuVmm vmm, GalPipelineState state) { - long IbPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.IndexArrayAddress); + long ibPosition = MakeInt64From2xInt32(NvGpuEngine3DReg.IndexArrayAddress); - long IboKey = Vmm.GetPhysicalAddress(IbPosition); + long iboKey = vmm.GetPhysicalAddress(ibPosition); - int IndexEntryFmt = ReadRegister(NvGpuEngine3dReg.IndexArrayFormat); - int IndexCount = ReadRegister(NvGpuEngine3dReg.IndexBatchCount); - int PrimCtrl = ReadRegister(NvGpuEngine3dReg.VertexBeginGl); + int indexEntryFmt = ReadRegister(NvGpuEngine3DReg.IndexArrayFormat); + int indexCount = ReadRegister(NvGpuEngine3DReg.IndexBatchCount); + int primCtrl = ReadRegister(NvGpuEngine3DReg.VertexBeginGl); - GalPrimitiveType PrimType = (GalPrimitiveType)(PrimCtrl & 0xffff); + GalPrimitiveType primType = (GalPrimitiveType)(primCtrl & 0xffff); - GalIndexFormat IndexFormat = (GalIndexFormat)IndexEntryFmt; + GalIndexFormat indexFormat = (GalIndexFormat)indexEntryFmt; - int IndexEntrySize = 1 << IndexEntryFmt; + int indexEntrySize = 1 << indexEntryFmt; - if (IndexEntrySize > 4) + if (indexEntrySize > 4) { - throw new InvalidOperationException("Invalid index entry size \"" + IndexEntrySize + "\"!"); + throw new InvalidOperationException("Invalid index entry size \"" + indexEntrySize + "\"!"); } - if (IndexCount != 0) + if (indexCount != 0) { - int IbSize = IndexCount * IndexEntrySize; + int ibSize = indexCount * indexEntrySize; - bool IboCached = Gpu.Renderer.Rasterizer.IsIboCached(IboKey, (uint)IbSize); + bool iboCached = _gpu.Renderer.Rasterizer.IsIboCached(iboKey, (uint)ibSize); - bool UsesLegacyQuads = - PrimType == GalPrimitiveType.Quads || - PrimType == GalPrimitiveType.QuadStrip; + bool usesLegacyQuads = + primType == GalPrimitiveType.Quads || + primType == GalPrimitiveType.QuadStrip; - if (!IboCached || Gpu.ResourceManager.MemoryRegionModified(Vmm, IboKey, (uint)IbSize, NvGpuBufferType.Index)) + if (!iboCached || _gpu.ResourceManager.MemoryRegionModified(vmm, iboKey, (uint)ibSize, NvGpuBufferType.Index)) { - if (!UsesLegacyQuads) + if (!usesLegacyQuads) { - if (Vmm.TryGetHostAddress(IbPosition, IbSize, out IntPtr IbPtr)) + if (vmm.TryGetHostAddress(ibPosition, ibSize, out IntPtr ibPtr)) { - Gpu.Renderer.Rasterizer.CreateIbo(IboKey, IbSize, IbPtr); + _gpu.Renderer.Rasterizer.CreateIbo(iboKey, ibSize, ibPtr); } else { - Gpu.Renderer.Rasterizer.CreateIbo(IboKey, IbSize, Vmm.ReadBytes(IbPosition, IbSize)); + _gpu.Renderer.Rasterizer.CreateIbo(iboKey, ibSize, vmm.ReadBytes(ibPosition, ibSize)); } } else { - byte[] Buffer = Vmm.ReadBytes(IbPosition, IbSize); + byte[] buffer = vmm.ReadBytes(ibPosition, ibSize); - if (PrimType == GalPrimitiveType.Quads) + if (primType == GalPrimitiveType.Quads) { - Buffer = QuadHelper.ConvertQuadsToTris(Buffer, IndexEntrySize, IndexCount); + buffer = QuadHelper.ConvertQuadsToTris(buffer, indexEntrySize, indexCount); } else /* if (PrimType == GalPrimitiveType.QuadStrip) */ { - Buffer = QuadHelper.ConvertQuadStripToTris(Buffer, IndexEntrySize, IndexCount); + buffer = QuadHelper.ConvertQuadStripToTris(buffer, indexEntrySize, indexCount); } - Gpu.Renderer.Rasterizer.CreateIbo(IboKey, IbSize, Buffer); + _gpu.Renderer.Rasterizer.CreateIbo(iboKey, ibSize, buffer); } } - if (!UsesLegacyQuads) + if (!usesLegacyQuads) { - Gpu.Renderer.Rasterizer.SetIndexArray(IbSize, IndexFormat); + _gpu.Renderer.Rasterizer.SetIndexArray(ibSize, indexFormat); } else { - if (PrimType == GalPrimitiveType.Quads) + if (primType == GalPrimitiveType.Quads) { - Gpu.Renderer.Rasterizer.SetIndexArray(QuadHelper.ConvertSizeQuadsToTris(IbSize), IndexFormat); + _gpu.Renderer.Rasterizer.SetIndexArray(QuadHelper.ConvertSizeQuadsToTris(ibSize), indexFormat); } else /* if (PrimType == GalPrimitiveType.QuadStrip) */ { - Gpu.Renderer.Rasterizer.SetIndexArray(QuadHelper.ConvertSizeQuadStripToTris(IbSize), IndexFormat); + _gpu.Renderer.Rasterizer.SetIndexArray(QuadHelper.ConvertSizeQuadStripToTris(ibSize), indexFormat); } } } - List[] Attribs = new List[32]; + List[] attribs = new List[32]; - for (int Attr = 0; Attr < 16; Attr++) + for (int attr = 0; attr < 16; attr++) { - int Packed = ReadRegister(NvGpuEngine3dReg.VertexAttribNFormat + Attr); + int packed = ReadRegister(NvGpuEngine3DReg.VertexAttribNFormat + attr); - int ArrayIndex = Packed & 0x1f; + int arrayIndex = packed & 0x1f; - if (Attribs[ArrayIndex] == null) + if (attribs[arrayIndex] == null) { - Attribs[ArrayIndex] = new List(); + attribs[arrayIndex] = new List(); } - long VbPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNAddress + ArrayIndex * 4); + long vbPosition = MakeInt64From2xInt32(NvGpuEngine3DReg.VertexArrayNAddress + arrayIndex * 4); - if (VbPosition == 0) + if (vbPosition == 0) { continue; } - bool IsConst = ((Packed >> 6) & 1) != 0; + 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); + GalVertexAttribSize size = (GalVertexAttribSize)((packed >> 21) & 0x3f); + GalVertexAttribType type = (GalVertexAttribType)((packed >> 27) & 0x7); - bool IsRgba = ((Packed >> 31) & 1) != 0; + bool isRgba = ((packed >> 31) & 1) != 0; // Check vertex array is enabled to avoid out of bounds exception when reading bytes - bool Enable = (ReadRegister(NvGpuEngine3dReg.VertexArrayNControl + ArrayIndex * 4) & 0x1000) != 0; + bool enable = (ReadRegister(NvGpuEngine3DReg.VertexArrayNControl + arrayIndex * 4) & 0x1000) != 0; //Note: 16 is the maximum size of an attribute, //having a component size of 32-bits with 4 elements (a vec4). - if (Enable) + if (enable) { - byte[] Data = Vmm.ReadBytes(VbPosition + Offset, 16); + byte[] data = vmm.ReadBytes(vbPosition + offset, 16); - Attribs[ArrayIndex].Add(new GalVertexAttrib(Attr, IsConst, Offset, Data, Size, Type, IsRgba)); + attribs[arrayIndex].Add(new GalVertexAttrib(attr, isConst, offset, data, size, type, isRgba)); } } - State.VertexBindings = new GalVertexBinding[32]; + state.VertexBindings = new GalVertexBinding[32]; - for (int Index = 0; Index < 32; Index++) + for (int index = 0; index < 32; index++) { - if (Attribs[Index] == null) + if (attribs[index] == null) { continue; } - int Control = ReadRegister(NvGpuEngine3dReg.VertexArrayNControl + Index * 4); + int control = ReadRegister(NvGpuEngine3DReg.VertexArrayNControl + index * 4); - bool Enable = (Control & 0x1000) != 0; + bool enable = (control & 0x1000) != 0; - if (!Enable) + if (!enable) { continue; } - long VbPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNAddress + Index * 4); - long VbEndPos = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNEndAddr + Index * 2); + long vbPosition = MakeInt64From2xInt32(NvGpuEngine3DReg.VertexArrayNAddress + index * 4); + long vbEndPos = MakeInt64From2xInt32(NvGpuEngine3DReg.VertexArrayNEndAddr + index * 2); - int VertexDivisor = ReadRegister(NvGpuEngine3dReg.VertexArrayNDivisor + Index * 4); + int vertexDivisor = ReadRegister(NvGpuEngine3DReg.VertexArrayNDivisor + index * 4); - bool Instanced = ReadRegisterBool(NvGpuEngine3dReg.VertexArrayNInstance + Index); + bool instanced = ReadRegisterBool(NvGpuEngine3DReg.VertexArrayNInstance + index); - int Stride = Control & 0xfff; + int stride = control & 0xfff; - if (Instanced && VertexDivisor != 0) + if (instanced && vertexDivisor != 0) { - VbPosition += Stride * (CurrentInstance / VertexDivisor); + vbPosition += stride * (_currentInstance / vertexDivisor); } - if (VbPosition > VbEndPos) + if (vbPosition > vbEndPos) { //Instance is invalid, ignore the draw call continue; } - long VboKey = Vmm.GetPhysicalAddress(VbPosition); + long vboKey = vmm.GetPhysicalAddress(vbPosition); - long VbSize = (VbEndPos - VbPosition) + 1; - int ModifiedVbSize = (int)VbSize; + long vbSize = (vbEndPos - vbPosition) + 1; + int modifiedVbSize = (int)vbSize; // If quads convert size to triangle length - if (Stride == 0) + if (stride == 0) { - if (PrimType == GalPrimitiveType.Quads) + if (primType == GalPrimitiveType.Quads) { - ModifiedVbSize = QuadHelper.ConvertSizeQuadsToTris(ModifiedVbSize); + modifiedVbSize = QuadHelper.ConvertSizeQuadsToTris(modifiedVbSize); } - else if (PrimType == GalPrimitiveType.QuadStrip) + else if (primType == GalPrimitiveType.QuadStrip) { - ModifiedVbSize = QuadHelper.ConvertSizeQuadStripToTris(ModifiedVbSize); + modifiedVbSize = QuadHelper.ConvertSizeQuadStripToTris(modifiedVbSize); } } - bool VboCached = Gpu.Renderer.Rasterizer.IsVboCached(VboKey, ModifiedVbSize); + bool vboCached = _gpu.Renderer.Rasterizer.IsVboCached(vboKey, modifiedVbSize); - if (!VboCached || Gpu.ResourceManager.MemoryRegionModified(Vmm, VboKey, VbSize, NvGpuBufferType.Vertex)) + if (!vboCached || _gpu.ResourceManager.MemoryRegionModified(vmm, vboKey, vbSize, NvGpuBufferType.Vertex)) { - if ((PrimType == GalPrimitiveType.Quads | PrimType == GalPrimitiveType.QuadStrip) && Stride != 0) + if ((primType == GalPrimitiveType.Quads | primType == GalPrimitiveType.QuadStrip) && stride != 0) { // Convert quad buffer to triangles - byte[] data = Vmm.ReadBytes(VbPosition, VbSize); + byte[] data = vmm.ReadBytes(vbPosition, vbSize); - if (PrimType == GalPrimitiveType.Quads) + if (primType == GalPrimitiveType.Quads) { - data = QuadHelper.ConvertQuadsToTris(data, Stride, (int)(VbSize / Stride)); + data = QuadHelper.ConvertQuadsToTris(data, stride, (int)(vbSize / stride)); } else { - data = QuadHelper.ConvertQuadStripToTris(data, Stride, (int)(VbSize / Stride)); + data = QuadHelper.ConvertQuadStripToTris(data, stride, (int)(vbSize / stride)); } - Gpu.Renderer.Rasterizer.CreateVbo(VboKey, data); + _gpu.Renderer.Rasterizer.CreateVbo(vboKey, data); } - else if (Vmm.TryGetHostAddress(VbPosition, VbSize, out IntPtr VbPtr)) + else if (vmm.TryGetHostAddress(vbPosition, vbSize, out IntPtr vbPtr)) { - Gpu.Renderer.Rasterizer.CreateVbo(VboKey, (int)VbSize, VbPtr); + _gpu.Renderer.Rasterizer.CreateVbo(vboKey, (int)vbSize, vbPtr); } else { - Gpu.Renderer.Rasterizer.CreateVbo(VboKey, Vmm.ReadBytes(VbPosition, VbSize)); + _gpu.Renderer.Rasterizer.CreateVbo(vboKey, vmm.ReadBytes(vbPosition, vbSize)); } } - State.VertexBindings[Index].Enabled = true; - State.VertexBindings[Index].Stride = Stride; - State.VertexBindings[Index].VboKey = VboKey; - State.VertexBindings[Index].Instanced = Instanced; - State.VertexBindings[Index].Divisor = VertexDivisor; - State.VertexBindings[Index].Attribs = Attribs[Index].ToArray(); + state.VertexBindings[index].Enabled = true; + state.VertexBindings[index].Stride = stride; + state.VertexBindings[index].VboKey = vboKey; + state.VertexBindings[index].Instanced = instanced; + state.VertexBindings[index].Divisor = vertexDivisor; + state.VertexBindings[index].Attribs = attribs[index].ToArray(); } } - private void DispatchRender(NvGpuVmm Vmm, GalPipelineState State) + private void DispatchRender(NvGpuVmm vmm, GalPipelineState state) { - int IndexCount = ReadRegister(NvGpuEngine3dReg.IndexBatchCount); - int PrimCtrl = ReadRegister(NvGpuEngine3dReg.VertexBeginGl); + int indexCount = ReadRegister(NvGpuEngine3DReg.IndexBatchCount); + int primCtrl = ReadRegister(NvGpuEngine3DReg.VertexBeginGl); - GalPrimitiveType PrimType = (GalPrimitiveType)(PrimCtrl & 0xffff); + GalPrimitiveType primType = (GalPrimitiveType)(primCtrl & 0xffff); - bool InstanceNext = ((PrimCtrl >> 26) & 1) != 0; - bool InstanceCont = ((PrimCtrl >> 27) & 1) != 0; + bool instanceNext = ((primCtrl >> 26) & 1) != 0; + bool instanceCont = ((primCtrl >> 27) & 1) != 0; - if (InstanceNext && InstanceCont) + if (instanceNext && instanceCont) { throw new InvalidOperationException("GPU tried to increase and reset instance count at the same time"); } - if (InstanceNext) + if (instanceNext) { - CurrentInstance++; + _currentInstance++; } - else if (!InstanceCont) + else if (!instanceCont) { - CurrentInstance = 0; + _currentInstance = 0; } - State.Instance = CurrentInstance; + state.Instance = _currentInstance; - Gpu.Renderer.Pipeline.Bind(State); + _gpu.Renderer.Pipeline.Bind(state); - Gpu.Renderer.RenderTarget.Bind(); + _gpu.Renderer.RenderTarget.Bind(); - if (IndexCount != 0) + if (indexCount != 0) { - int IndexEntryFmt = ReadRegister(NvGpuEngine3dReg.IndexArrayFormat); - int IndexFirst = ReadRegister(NvGpuEngine3dReg.IndexBatchFirst); - int VertexBase = ReadRegister(NvGpuEngine3dReg.VertexArrayElemBase); + int indexEntryFmt = ReadRegister(NvGpuEngine3DReg.IndexArrayFormat); + int indexFirst = ReadRegister(NvGpuEngine3DReg.IndexBatchFirst); + int vertexBase = ReadRegister(NvGpuEngine3DReg.VertexArrayElemBase); - long IndexPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.IndexArrayAddress); + long indexPosition = MakeInt64From2xInt32(NvGpuEngine3DReg.IndexArrayAddress); - long IboKey = Vmm.GetPhysicalAddress(IndexPosition); + long iboKey = vmm.GetPhysicalAddress(indexPosition); //Quad primitive types were deprecated on OpenGL 3.x, //they are converted to a triangles index buffer on IB creation, //so we should use the triangles type here too. - if (PrimType == GalPrimitiveType.Quads || PrimType == GalPrimitiveType.QuadStrip) + if (primType == GalPrimitiveType.Quads || primType == GalPrimitiveType.QuadStrip) { //Note: We assume that index first points to the first //vertex of a quad, if it points to the middle of a //quad (First % 4 != 0 for Quads) then it will not work properly. - if (PrimType == GalPrimitiveType.Quads) + if (primType == GalPrimitiveType.Quads) { - IndexFirst = QuadHelper.ConvertSizeQuadsToTris(IndexFirst); + indexFirst = QuadHelper.ConvertSizeQuadsToTris(indexFirst); } else // QuadStrip { - IndexFirst = QuadHelper.ConvertSizeQuadStripToTris(IndexFirst); + indexFirst = QuadHelper.ConvertSizeQuadStripToTris(indexFirst); } - PrimType = GalPrimitiveType.Triangles; + primType = GalPrimitiveType.Triangles; } - Gpu.Renderer.Rasterizer.DrawElements(IboKey, IndexFirst, VertexBase, PrimType); + _gpu.Renderer.Rasterizer.DrawElements(iboKey, indexFirst, vertexBase, primType); } else { - int VertexFirst = ReadRegister(NvGpuEngine3dReg.VertexArrayFirst); - int VertexCount = ReadRegister(NvGpuEngine3dReg.VertexArrayCount); + int vertexFirst = ReadRegister(NvGpuEngine3DReg.VertexArrayFirst); + int vertexCount = ReadRegister(NvGpuEngine3DReg.VertexArrayCount); //Quad primitive types were deprecated on OpenGL 3.x, //they are converted to a triangles index buffer on IB creation, //so we should use the triangles type here too. - if (PrimType == GalPrimitiveType.Quads || PrimType == GalPrimitiveType.QuadStrip) + if (primType == GalPrimitiveType.Quads || primType == GalPrimitiveType.QuadStrip) { //Note: We assume that index first points to the first //vertex of a quad, if it points to the middle of a //quad (First % 4 != 0 for Quads) then it will not work properly. - if (PrimType == GalPrimitiveType.Quads) + if (primType == GalPrimitiveType.Quads) { - VertexFirst = QuadHelper.ConvertSizeQuadsToTris(VertexFirst); + vertexFirst = QuadHelper.ConvertSizeQuadsToTris(vertexFirst); } else // QuadStrip { - VertexFirst = QuadHelper.ConvertSizeQuadStripToTris(VertexFirst); + vertexFirst = QuadHelper.ConvertSizeQuadStripToTris(vertexFirst); } - PrimType = GalPrimitiveType.Triangles; - VertexCount = QuadHelper.ConvertSizeQuadsToTris(VertexCount); + primType = GalPrimitiveType.Triangles; + vertexCount = QuadHelper.ConvertSizeQuadsToTris(vertexCount); } - Gpu.Renderer.Rasterizer.DrawArrays(VertexFirst, VertexCount, PrimType); + _gpu.Renderer.Rasterizer.DrawArrays(vertexFirst, vertexCount, primType); } //Is the GPU really clearing those registers after draw? - WriteRegister(NvGpuEngine3dReg.IndexBatchFirst, 0); - WriteRegister(NvGpuEngine3dReg.IndexBatchCount, 0); + WriteRegister(NvGpuEngine3DReg.IndexBatchFirst, 0); + WriteRegister(NvGpuEngine3DReg.IndexBatchCount, 0); } private enum QueryMode @@ -1009,115 +1009,115 @@ namespace Ryujinx.Graphics.Graphics3d WriteCounterAndTimestamp } - private void QueryControl(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void QueryControl(NvGpuVmm vmm, GpuMethodCall methCall) { - WriteRegister(MethCall); + WriteRegister(methCall); - long Position = MakeInt64From2xInt32(NvGpuEngine3dReg.QueryAddress); + long position = MakeInt64From2xInt32(NvGpuEngine3DReg.QueryAddress); - int Seq = Registers[(int)NvGpuEngine3dReg.QuerySequence]; - int Ctrl = Registers[(int)NvGpuEngine3dReg.QueryControl]; + int seq = Registers[(int)NvGpuEngine3DReg.QuerySequence]; + int ctrl = Registers[(int)NvGpuEngine3DReg.QueryControl]; - QueryMode Mode = (QueryMode)(Ctrl & 3); + QueryMode mode = (QueryMode)(ctrl & 3); - switch (Mode) + switch (mode) { - case QueryMode.WriteSeq: Vmm.WriteInt32(Position, Seq); break; + case QueryMode.WriteSeq: vmm.WriteInt32(position, seq); break; case QueryMode.WriteCounterAndTimestamp: { //TODO: Implement counters. - long Counter = 1; + long counter = 1; - long Timestamp = PerformanceCounter.ElapsedMilliseconds; + long timestamp = PerformanceCounter.ElapsedMilliseconds; - Vmm.WriteInt64(Position + 0, Counter); - Vmm.WriteInt64(Position + 8, Timestamp); + vmm.WriteInt64(position + 0, counter); + vmm.WriteInt64(position + 8, timestamp); break; } } } - private void CbData(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void CbData(NvGpuVmm vmm, GpuMethodCall methCall) { - long Position = MakeInt64From2xInt32(NvGpuEngine3dReg.ConstBufferAddress); + long position = MakeInt64From2xInt32(NvGpuEngine3DReg.ConstBufferAddress); - int Offset = ReadRegister(NvGpuEngine3dReg.ConstBufferOffset); + int offset = ReadRegister(NvGpuEngine3DReg.ConstBufferOffset); - Vmm.WriteInt32(Position + Offset, MethCall.Argument); + vmm.WriteInt32(position + offset, methCall.Argument); - WriteRegister(NvGpuEngine3dReg.ConstBufferOffset, Offset + 4); + WriteRegister(NvGpuEngine3DReg.ConstBufferOffset, offset + 4); - Gpu.ResourceManager.ClearPbCache(NvGpuBufferType.ConstBuffer); + _gpu.ResourceManager.ClearPbCache(NvGpuBufferType.ConstBuffer); } - private void CbBind(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void CbBind(NvGpuVmm vmm, GpuMethodCall methCall) { - int Stage = (MethCall.Method - 0x904) >> 3; + int stage = (methCall.Method - 0x904) >> 3; - int Index = MethCall.Argument; + int index = methCall.Argument; - bool Enabled = (Index & 1) != 0; + bool enabled = (index & 1) != 0; - Index = (Index >> 4) & 0x1f; + index = (index >> 4) & 0x1f; - long Position = MakeInt64From2xInt32(NvGpuEngine3dReg.ConstBufferAddress); + long position = MakeInt64From2xInt32(NvGpuEngine3DReg.ConstBufferAddress); - long CbKey = Vmm.GetPhysicalAddress(Position); + long cbKey = vmm.GetPhysicalAddress(position); - int Size = ReadRegister(NvGpuEngine3dReg.ConstBufferSize); + int size = ReadRegister(NvGpuEngine3DReg.ConstBufferSize); - if (!Gpu.Renderer.Buffer.IsCached(CbKey, Size)) + if (!_gpu.Renderer.Buffer.IsCached(cbKey, size)) { - Gpu.Renderer.Buffer.Create(CbKey, Size); + _gpu.Renderer.Buffer.Create(cbKey, size); } - ConstBuffer Cb = ConstBuffers[Stage][Index]; + ConstBuffer cb = _constBuffers[stage][index]; - if (Cb.Position != Position || Cb.Enabled != Enabled || Cb.Size != Size) + if (cb.Position != position || cb.Enabled != enabled || cb.Size != size) { - ConstBuffers[Stage][Index].Position = Position; - ConstBuffers[Stage][Index].Enabled = Enabled; - ConstBuffers[Stage][Index].Size = Size; + _constBuffers[stage][index].Position = position; + _constBuffers[stage][index].Enabled = enabled; + _constBuffers[stage][index].Size = size; } } - private float GetFlipSign(NvGpuEngine3dReg Reg) + private float GetFlipSign(NvGpuEngine3DReg reg) { - return MathF.Sign(ReadRegisterFloat(Reg)); + return MathF.Sign(ReadRegisterFloat(reg)); } - private long MakeInt64From2xInt32(NvGpuEngine3dReg Reg) + private long MakeInt64From2xInt32(NvGpuEngine3DReg reg) { return - (long)Registers[(int)Reg + 0] << 32 | - (uint)Registers[(int)Reg + 1]; + (long)Registers[(int)reg + 0] << 32 | + (uint)Registers[(int)reg + 1]; } - private void WriteRegister(GpuMethodCall MethCall) + private void WriteRegister(GpuMethodCall methCall) { - Registers[MethCall.Method] = MethCall.Argument; + Registers[methCall.Method] = methCall.Argument; } - private int ReadRegister(NvGpuEngine3dReg Reg) + private int ReadRegister(NvGpuEngine3DReg reg) { - return Registers[(int)Reg]; + return Registers[(int)reg]; } - private float ReadRegisterFloat(NvGpuEngine3dReg Reg) + private float ReadRegisterFloat(NvGpuEngine3DReg reg) { - return BitConverter.Int32BitsToSingle(ReadRegister(Reg)); + return BitConverter.Int32BitsToSingle(ReadRegister(reg)); } - private bool ReadRegisterBool(NvGpuEngine3dReg Reg) + private bool ReadRegisterBool(NvGpuEngine3DReg reg) { - return (ReadRegister(Reg) & 1) != 0; + return (ReadRegister(reg) & 1) != 0; } - private void WriteRegister(NvGpuEngine3dReg Reg, int Value) + private void WriteRegister(NvGpuEngine3DReg reg, int value) { - Registers[(int)Reg] = Value; + Registers[(int)reg] = value; } } } diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngine3dReg.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngine3dReg.cs index 9134646403..0336c80ced 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngine3dReg.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngine3dReg.cs @@ -1,6 +1,6 @@ namespace Ryujinx.Graphics.Graphics3d { - enum NvGpuEngine3dReg + enum NvGpuEngine3DReg { FrameBufferNAddress = 0x200, FrameBufferNWidth = 0x202, @@ -32,13 +32,13 @@ namespace Ryujinx.Graphics.Graphics3d StencilBackMask = 0x3d6, StencilBackFuncMask = 0x3d7, ColorMaskCommon = 0x3e4, - RTSeparateFragData = 0x3eb, + RtSeparateFragData = 0x3eb, ZetaAddress = 0x3f8, ZetaFormat = 0x3fa, ZetaBlockDimensions = 0x3fb, ZetaLayerStride = 0x3fc, VertexAttribNFormat = 0x458, - RTControl = 0x487, + RtControl = 0x487, ZetaHoriz = 0x48a, ZetaVert = 0x48b, ZetaArrayMode = 0x48c, diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mf.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mf.cs index 2f1df3d377..c1cfc96766 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mf.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mf.cs @@ -9,188 +9,188 @@ namespace Ryujinx.Graphics.Graphics3d { public int[] Registers { get; private set; } - private NvGpu Gpu; + private NvGpu _gpu; - private Dictionary Methods; + private Dictionary _methods; - public NvGpuEngineM2mf(NvGpu Gpu) + public NvGpuEngineM2mf(NvGpu gpu) { - this.Gpu = Gpu; + _gpu = gpu; Registers = new int[0x1d6]; - Methods = new Dictionary(); + _methods = new Dictionary(); - void AddMethod(int Meth, int Count, int Stride, NvGpuMethod Method) + void AddMethod(int meth, int count, int stride, NvGpuMethod method) { - while (Count-- > 0) + while (count-- > 0) { - Methods.Add(Meth, Method); + _methods.Add(meth, method); - Meth += Stride; + meth += stride; } } AddMethod(0xc0, 1, 1, Execute); } - public void CallMethod(NvGpuVmm Vmm, GpuMethodCall MethCall) + public void CallMethod(NvGpuVmm vmm, GpuMethodCall methCall) { - if (Methods.TryGetValue(MethCall.Method, out NvGpuMethod Method)) + if (_methods.TryGetValue(methCall.Method, out NvGpuMethod method)) { - Method(Vmm, MethCall); + method(vmm, methCall); } else { - WriteRegister(MethCall); + WriteRegister(methCall); } } - private void Execute(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void Execute(NvGpuVmm vmm, GpuMethodCall methCall) { //TODO: Some registers and copy modes are still not implemented. - int Control = MethCall.Argument; + int control = methCall.Argument; - bool SrcLinear = ((Control >> 7) & 1) != 0; - bool DstLinear = ((Control >> 8) & 1) != 0; - bool Copy2d = ((Control >> 9) & 1) != 0; + bool srcLinear = ((control >> 7) & 1) != 0; + bool dstLinear = ((control >> 8) & 1) != 0; + bool copy2D = ((control >> 9) & 1) != 0; - long SrcAddress = MakeInt64From2xInt32(NvGpuEngineM2mfReg.SrcAddress); - long DstAddress = MakeInt64From2xInt32(NvGpuEngineM2mfReg.DstAddress); + long srcAddress = MakeInt64From2xInt32(NvGpuEngineM2mfReg.SrcAddress); + long dstAddress = MakeInt64From2xInt32(NvGpuEngineM2mfReg.DstAddress); - int SrcPitch = ReadRegister(NvGpuEngineM2mfReg.SrcPitch); - int DstPitch = ReadRegister(NvGpuEngineM2mfReg.DstPitch); + int srcPitch = ReadRegister(NvGpuEngineM2mfReg.SrcPitch); + int dstPitch = ReadRegister(NvGpuEngineM2mfReg.DstPitch); - int XCount = ReadRegister(NvGpuEngineM2mfReg.XCount); - int YCount = ReadRegister(NvGpuEngineM2mfReg.YCount); + int xCount = ReadRegister(NvGpuEngineM2mfReg.XCount); + int yCount = ReadRegister(NvGpuEngineM2mfReg.YCount); - int Swizzle = ReadRegister(NvGpuEngineM2mfReg.Swizzle); + int swizzle = ReadRegister(NvGpuEngineM2mfReg.Swizzle); - int DstBlkDim = ReadRegister(NvGpuEngineM2mfReg.DstBlkDim); - int DstSizeX = ReadRegister(NvGpuEngineM2mfReg.DstSizeX); - int DstSizeY = ReadRegister(NvGpuEngineM2mfReg.DstSizeY); - int DstSizeZ = ReadRegister(NvGpuEngineM2mfReg.DstSizeZ); - int DstPosXY = ReadRegister(NvGpuEngineM2mfReg.DstPosXY); - int DstPosZ = ReadRegister(NvGpuEngineM2mfReg.DstPosZ); + int dstBlkDim = ReadRegister(NvGpuEngineM2mfReg.DstBlkDim); + int dstSizeX = ReadRegister(NvGpuEngineM2mfReg.DstSizeX); + int dstSizeY = ReadRegister(NvGpuEngineM2mfReg.DstSizeY); + int dstSizeZ = ReadRegister(NvGpuEngineM2mfReg.DstSizeZ); + int dstPosXy = ReadRegister(NvGpuEngineM2mfReg.DstPosXy); + int dstPosZ = ReadRegister(NvGpuEngineM2mfReg.DstPosZ); - int SrcBlkDim = ReadRegister(NvGpuEngineM2mfReg.SrcBlkDim); - int SrcSizeX = ReadRegister(NvGpuEngineM2mfReg.SrcSizeX); - int SrcSizeY = ReadRegister(NvGpuEngineM2mfReg.SrcSizeY); - int SrcSizeZ = ReadRegister(NvGpuEngineM2mfReg.SrcSizeZ); - int SrcPosXY = ReadRegister(NvGpuEngineM2mfReg.SrcPosXY); - int SrcPosZ = ReadRegister(NvGpuEngineM2mfReg.SrcPosZ); + int srcBlkDim = ReadRegister(NvGpuEngineM2mfReg.SrcBlkDim); + int srcSizeX = ReadRegister(NvGpuEngineM2mfReg.SrcSizeX); + int srcSizeY = ReadRegister(NvGpuEngineM2mfReg.SrcSizeY); + int srcSizeZ = ReadRegister(NvGpuEngineM2mfReg.SrcSizeZ); + int srcPosXy = ReadRegister(NvGpuEngineM2mfReg.SrcPosXy); + int srcPosZ = ReadRegister(NvGpuEngineM2mfReg.SrcPosZ); - int SrcCpp = ((Swizzle >> 20) & 7) + 1; - int DstCpp = ((Swizzle >> 24) & 7) + 1; + int srcCpp = ((swizzle >> 20) & 7) + 1; + int dstCpp = ((swizzle >> 24) & 7) + 1; - int DstPosX = (DstPosXY >> 0) & 0xffff; - int DstPosY = (DstPosXY >> 16) & 0xffff; + int dstPosX = (dstPosXy >> 0) & 0xffff; + int dstPosY = (dstPosXy >> 16) & 0xffff; - int SrcPosX = (SrcPosXY >> 0) & 0xffff; - int SrcPosY = (SrcPosXY >> 16) & 0xffff; + int srcPosX = (srcPosXy >> 0) & 0xffff; + int srcPosY = (srcPosXy >> 16) & 0xffff; - int SrcBlockHeight = 1 << ((SrcBlkDim >> 4) & 0xf); - int DstBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf); + int srcBlockHeight = 1 << ((srcBlkDim >> 4) & 0xf); + int dstBlockHeight = 1 << ((dstBlkDim >> 4) & 0xf); - long SrcPA = Vmm.GetPhysicalAddress(SrcAddress); - long DstPA = Vmm.GetPhysicalAddress(DstAddress); + long srcPa = vmm.GetPhysicalAddress(srcAddress); + long dstPa = vmm.GetPhysicalAddress(dstAddress); - if (Copy2d) + if (copy2D) { - if (SrcLinear) + if (srcLinear) { - SrcPosX = SrcPosY = SrcPosZ = 0; + srcPosX = srcPosY = srcPosZ = 0; } - if (DstLinear) + if (dstLinear) { - DstPosX = DstPosY = DstPosZ = 0; + dstPosX = dstPosY = dstPosZ = 0; } - if (SrcLinear && DstLinear) + if (srcLinear && dstLinear) { - for (int Y = 0; Y < YCount; Y++) + for (int y = 0; y < yCount; y++) { - int SrcOffset = (SrcPosY + Y) * SrcPitch + SrcPosX * SrcCpp; - int DstOffset = (DstPosY + Y) * DstPitch + DstPosX * DstCpp; + int srcOffset = (srcPosY + y) * srcPitch + srcPosX * srcCpp; + int dstOffset = (dstPosY + y) * dstPitch + dstPosX * dstCpp; - long Src = SrcPA + (uint)SrcOffset; - long Dst = DstPA + (uint)DstOffset; + long src = srcPa + (uint)srcOffset; + long dst = dstPa + (uint)dstOffset; - Vmm.Memory.CopyBytes(Src, Dst, XCount * SrcCpp); + vmm.Memory.CopyBytes(src, dst, xCount * srcCpp); } } else { - ISwizzle SrcSwizzle; + ISwizzle srcSwizzle; - if (SrcLinear) + if (srcLinear) { - SrcSwizzle = new LinearSwizzle(SrcPitch, SrcCpp, SrcSizeX, SrcSizeY); + srcSwizzle = new LinearSwizzle(srcPitch, srcCpp, srcSizeX, srcSizeY); } else { - SrcSwizzle = new BlockLinearSwizzle( - SrcSizeX, - SrcSizeY, 1, - SrcBlockHeight, 1, - SrcCpp); + srcSwizzle = new BlockLinearSwizzle( + srcSizeX, + srcSizeY, 1, + srcBlockHeight, 1, + srcCpp); } - ISwizzle DstSwizzle; + ISwizzle dstSwizzle; - if (DstLinear) + if (dstLinear) { - DstSwizzle = new LinearSwizzle(DstPitch, DstCpp, SrcSizeX, SrcSizeY); + dstSwizzle = new LinearSwizzle(dstPitch, dstCpp, srcSizeX, srcSizeY); } else { - DstSwizzle = new BlockLinearSwizzle( - DstSizeX, - DstSizeY, 1, - DstBlockHeight, 1, - DstCpp); + dstSwizzle = new BlockLinearSwizzle( + dstSizeX, + dstSizeY, 1, + dstBlockHeight, 1, + dstCpp); } - for (int Y = 0; Y < YCount; Y++) - for (int X = 0; X < XCount; X++) + for (int y = 0; y < yCount; y++) + for (int x = 0; x < xCount; x++) { - int SrcOffset = SrcSwizzle.GetSwizzleOffset(SrcPosX + X, SrcPosY + Y, 0); - int DstOffset = DstSwizzle.GetSwizzleOffset(DstPosX + X, DstPosY + Y, 0); + int srcOffset = srcSwizzle.GetSwizzleOffset(srcPosX + x, srcPosY + y, 0); + int dstOffset = dstSwizzle.GetSwizzleOffset(dstPosX + x, dstPosY + y, 0); - long Src = SrcPA + (uint)SrcOffset; - long Dst = DstPA + (uint)DstOffset; + long src = srcPa + (uint)srcOffset; + long dst = dstPa + (uint)dstOffset; - Vmm.Memory.CopyBytes(Src, Dst, SrcCpp); + vmm.Memory.CopyBytes(src, dst, srcCpp); } } } else { - Vmm.Memory.CopyBytes(SrcPA, DstPA, XCount); + vmm.Memory.CopyBytes(srcPa, dstPa, xCount); } } - private long MakeInt64From2xInt32(NvGpuEngineM2mfReg Reg) + private long MakeInt64From2xInt32(NvGpuEngineM2mfReg reg) { return - (long)Registers[(int)Reg + 0] << 32 | - (uint)Registers[(int)Reg + 1]; + (long)Registers[(int)reg + 0] << 32 | + (uint)Registers[(int)reg + 1]; } - private void WriteRegister(GpuMethodCall MethCall) + private void WriteRegister(GpuMethodCall methCall) { - Registers[MethCall.Method] = MethCall.Argument; + Registers[methCall.Method] = methCall.Argument; } - private int ReadRegister(NvGpuEngineM2mfReg Reg) + private int ReadRegister(NvGpuEngineM2mfReg reg) { - return Registers[(int)Reg]; + return Registers[(int)reg]; } - private void WriteRegister(NvGpuEngineM2mfReg Reg, int Value) + private void WriteRegister(NvGpuEngineM2mfReg reg, int value) { - Registers[(int)Reg] = Value; + Registers[(int)reg] = value; } } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mfReg.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mfReg.cs index 4bef8d9ed2..a46c6ed916 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mfReg.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mfReg.cs @@ -14,12 +14,12 @@ namespace Ryujinx.Graphics.Graphics3d DstSizeY = 0x1c5, DstSizeZ = 0x1c6, DstPosZ = 0x1c7, - DstPosXY = 0x1c8, + DstPosXy = 0x1c8, SrcBlkDim = 0x1ca, SrcSizeX = 0x1cb, SrcSizeY = 0x1cc, SrcSizeZ = 0x1cd, SrcPosZ = 0x1ce, - SrcPosXY = 0x1cf + SrcPosXy = 0x1cf } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngineP2mf.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngineP2mf.cs index 62872ba15c..988a14c577 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngineP2mf.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngineP2mf.cs @@ -9,41 +9,41 @@ namespace Ryujinx.Graphics.Graphics3d { public int[] Registers { get; private set; } - private NvGpu Gpu; + private NvGpu _gpu; - private Dictionary Methods; + private Dictionary _methods; - private int CopyStartX; - private int CopyStartY; + private int _copyStartX; + private int _copyStartY; - private int CopyWidth; - private int CopyHeight; - private int CopyGobBlockHeight; + private int _copyWidth; + private int _copyHeight; + private int _copyGobBlockHeight; - private long CopyAddress; + private long _copyAddress; - private int CopyOffset; - private int CopySize; + private int _copyOffset; + private int _copySize; - private bool CopyLinear; + private bool _copyLinear; - private byte[] Buffer; + private byte[] _buffer; - public NvGpuEngineP2mf(NvGpu Gpu) + public NvGpuEngineP2mf(NvGpu gpu) { - this.Gpu = Gpu; + _gpu = gpu; Registers = new int[0x80]; - Methods = new Dictionary(); + _methods = new Dictionary(); - void AddMethod(int Meth, int Count, int Stride, NvGpuMethod Method) + void AddMethod(int meth, int count, int stride, NvGpuMethod method) { - while (Count-- > 0) + while (count-- > 0) { - Methods.Add(Meth, Method); + _methods.Add(meth, method); - Meth += Stride; + meth += stride; } } @@ -51,115 +51,115 @@ namespace Ryujinx.Graphics.Graphics3d AddMethod(0x6d, 1, 1, PushData); } - public void CallMethod(NvGpuVmm Vmm, GpuMethodCall MethCall) + public void CallMethod(NvGpuVmm vmm, GpuMethodCall methCall) { - if (Methods.TryGetValue(MethCall.Method, out NvGpuMethod Method)) + if (_methods.TryGetValue(methCall.Method, out NvGpuMethod method)) { - Method(Vmm, MethCall); + method(vmm, methCall); } else { - WriteRegister(MethCall); + WriteRegister(methCall); } } - private void Execute(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void Execute(NvGpuVmm vmm, GpuMethodCall methCall) { //TODO: Some registers and copy modes are still not implemented. - int Control = MethCall.Argument; + int control = methCall.Argument; - long DstAddress = MakeInt64From2xInt32(NvGpuEngineP2mfReg.DstAddress); + long dstAddress = MakeInt64From2xInt32(NvGpuEngineP2mfReg.DstAddress); - int DstPitch = ReadRegister(NvGpuEngineP2mfReg.DstPitch); - int DstBlkDim = ReadRegister(NvGpuEngineP2mfReg.DstBlockDim); + int dstPitch = ReadRegister(NvGpuEngineP2mfReg.DstPitch); + int dstBlkDim = ReadRegister(NvGpuEngineP2mfReg.DstBlockDim); - int DstX = ReadRegister(NvGpuEngineP2mfReg.DstX); - int DstY = ReadRegister(NvGpuEngineP2mfReg.DstY); + int dstX = ReadRegister(NvGpuEngineP2mfReg.DstX); + int dstY = ReadRegister(NvGpuEngineP2mfReg.DstY); - int DstWidth = ReadRegister(NvGpuEngineP2mfReg.DstWidth); - int DstHeight = ReadRegister(NvGpuEngineP2mfReg.DstHeight); + int dstWidth = ReadRegister(NvGpuEngineP2mfReg.DstWidth); + int dstHeight = ReadRegister(NvGpuEngineP2mfReg.DstHeight); - int LineLengthIn = ReadRegister(NvGpuEngineP2mfReg.LineLengthIn); - int LineCount = ReadRegister(NvGpuEngineP2mfReg.LineCount); + int lineLengthIn = ReadRegister(NvGpuEngineP2mfReg.LineLengthIn); + int lineCount = ReadRegister(NvGpuEngineP2mfReg.LineCount); - CopyLinear = (Control & 1) != 0; + _copyLinear = (control & 1) != 0; - CopyGobBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf); + _copyGobBlockHeight = 1 << ((dstBlkDim >> 4) & 0xf); - CopyStartX = DstX; - CopyStartY = DstY; + _copyStartX = dstX; + _copyStartY = dstY; - CopyWidth = DstWidth; - CopyHeight = DstHeight; + _copyWidth = dstWidth; + _copyHeight = dstHeight; - CopyAddress = DstAddress; + _copyAddress = dstAddress; - CopyOffset = 0; - CopySize = LineLengthIn * LineCount; + _copyOffset = 0; + _copySize = lineLengthIn * lineCount; - Buffer = new byte[CopySize]; + _buffer = new byte[_copySize]; } - private void PushData(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void PushData(NvGpuVmm vmm, GpuMethodCall methCall) { - if (Buffer == null) + if (_buffer == null) { return; } - for (int Shift = 0; Shift < 32 && CopyOffset < CopySize; Shift += 8, CopyOffset++) + for (int shift = 0; shift < 32 && _copyOffset < _copySize; shift += 8, _copyOffset++) { - Buffer[CopyOffset] = (byte)(MethCall.Argument >> Shift); + _buffer[_copyOffset] = (byte)(methCall.Argument >> shift); } - if (MethCall.IsLastCall) + if (methCall.IsLastCall) { - if (CopyLinear) + if (_copyLinear) { - Vmm.WriteBytes(CopyAddress, Buffer); + vmm.WriteBytes(_copyAddress, _buffer); } else { - BlockLinearSwizzle Swizzle = new BlockLinearSwizzle( - CopyWidth, - CopyHeight, 1, - CopyGobBlockHeight, 1, 1); + BlockLinearSwizzle swizzle = new BlockLinearSwizzle( + _copyWidth, + _copyHeight, 1, + _copyGobBlockHeight, 1, 1); - int SrcOffset = 0; + int srcOffset = 0; - for (int Y = CopyStartY; Y < CopyHeight && SrcOffset < CopySize; Y++) - for (int X = CopyStartX; X < CopyWidth && SrcOffset < CopySize; X++) + for (int y = _copyStartY; y < _copyHeight && srcOffset < _copySize; y++) + for (int x = _copyStartX; x < _copyWidth && srcOffset < _copySize; x++) { - int DstOffset = Swizzle.GetSwizzleOffset(X, Y, 0); + int dstOffset = swizzle.GetSwizzleOffset(x, y, 0); - Vmm.WriteByte(CopyAddress + DstOffset, Buffer[SrcOffset++]); + vmm.WriteByte(_copyAddress + dstOffset, _buffer[srcOffset++]); } } - Buffer = null; + _buffer = null; } } - private long MakeInt64From2xInt32(NvGpuEngineP2mfReg Reg) + private long MakeInt64From2xInt32(NvGpuEngineP2mfReg reg) { return - (long)Registers[(int)Reg + 0] << 32 | - (uint)Registers[(int)Reg + 1]; + (long)Registers[(int)reg + 0] << 32 | + (uint)Registers[(int)reg + 1]; } - private void WriteRegister(GpuMethodCall MethCall) + private void WriteRegister(GpuMethodCall methCall) { - Registers[MethCall.Method] = MethCall.Argument; + Registers[methCall.Method] = methCall.Argument; } - private int ReadRegister(NvGpuEngineP2mfReg Reg) + private int ReadRegister(NvGpuEngineP2mfReg reg) { - return Registers[(int)Reg]; + return Registers[(int)reg]; } - private void WriteRegister(NvGpuEngineP2mfReg Reg, int Value) + private void WriteRegister(NvGpuEngineP2mfReg reg, int value) { - Registers[(int)Reg] = Value; + Registers[(int)reg] = value; } } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuFifo.cs b/Ryujinx.Graphics/Graphics3d/NvGpuFifo.cs index f834ade78d..1bda3fe2a4 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuFifo.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuFifo.cs @@ -11,166 +11,166 @@ namespace Ryujinx.Graphics.Graphics3d //a guess here and use 256kb as the size. Increase if needed. private const int MmeWords = 256 * 256; - private NvGpu Gpu; + private NvGpu _gpu; - private NvGpuEngine[] SubChannels; + private NvGpuEngine[] _subChannels; private struct CachedMacro { public int Position { get; private set; } - private bool ExecutionPending; - private int Argument; + private bool _executionPending; + private int _argument; - private MacroInterpreter Interpreter; + private MacroInterpreter _interpreter; - public CachedMacro(NvGpuFifo PFifo, INvGpuEngine Engine, int Position) + public CachedMacro(NvGpuFifo pFifo, INvGpuEngine engine, int position) { - this.Position = Position; + Position = position; - ExecutionPending = false; - Argument = 0; + _executionPending = false; + _argument = 0; - Interpreter = new MacroInterpreter(PFifo, Engine); + _interpreter = new MacroInterpreter(pFifo, engine); } - public void StartExecution(int Argument) + public void StartExecution(int argument) { - this.Argument = Argument; + _argument = argument; - ExecutionPending = true; + _executionPending = true; } - public void Execute(NvGpuVmm Vmm, int[] Mme) + public void Execute(NvGpuVmm vmm, int[] mme) { - if (ExecutionPending) + if (_executionPending) { - ExecutionPending = false; + _executionPending = false; - Interpreter?.Execute(Vmm, Mme, Position, Argument); + _interpreter?.Execute(vmm, mme, Position, _argument); } } - public void PushArgument(int Argument) + public void PushArgument(int argument) { - Interpreter?.Fifo.Enqueue(Argument); + _interpreter?.Fifo.Enqueue(argument); } } - private int CurrMacroPosition; - private int CurrMacroBindIndex; + private int _currMacroPosition; + private int _currMacroBindIndex; - private CachedMacro[] Macros; + private CachedMacro[] _macros; - private int[] Mme; + private int[] _mme; - public NvGpuFifo(NvGpu Gpu) + public NvGpuFifo(NvGpu gpu) { - this.Gpu = Gpu; + _gpu = gpu; - SubChannels = new NvGpuEngine[8]; + _subChannels = new NvGpuEngine[8]; - Macros = new CachedMacro[MacrosCount]; + _macros = new CachedMacro[MacrosCount]; - Mme = new int[MmeWords]; + _mme = new int[MmeWords]; } - public void CallMethod(NvGpuVmm Vmm, GpuMethodCall MethCall) + public void CallMethod(NvGpuVmm vmm, GpuMethodCall methCall) { - if ((NvGpuFifoMeth)MethCall.Method == NvGpuFifoMeth.BindChannel) + if ((NvGpuFifoMeth)methCall.Method == NvGpuFifoMeth.BindChannel) { - NvGpuEngine Engine = (NvGpuEngine)MethCall.Argument; + NvGpuEngine engine = (NvGpuEngine)methCall.Argument; - SubChannels[MethCall.SubChannel] = Engine; + _subChannels[methCall.SubChannel] = engine; } else { - switch (SubChannels[MethCall.SubChannel]) + switch (_subChannels[methCall.SubChannel]) { - case NvGpuEngine._2d: Call2dMethod (Vmm, MethCall); break; - case NvGpuEngine._3d: Call3dMethod (Vmm, MethCall); break; - case NvGpuEngine.P2mf: CallP2mfMethod(Vmm, MethCall); break; - case NvGpuEngine.M2mf: CallM2mfMethod(Vmm, MethCall); break; + case NvGpuEngine._2D: Call2DMethod (vmm, methCall); break; + case NvGpuEngine._3D: Call3DMethod (vmm, methCall); break; + case NvGpuEngine.P2mf: CallP2mfMethod(vmm, methCall); break; + case NvGpuEngine.M2mf: CallM2mfMethod(vmm, methCall); break; } } } - private void Call2dMethod(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void Call2DMethod(NvGpuVmm vmm, GpuMethodCall methCall) { - Gpu.Engine2d.CallMethod(Vmm, MethCall); + _gpu.Engine2d.CallMethod(vmm, methCall); } - private void Call3dMethod(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void Call3DMethod(NvGpuVmm vmm, GpuMethodCall methCall) { - if (MethCall.Method < 0x80) + if (methCall.Method < 0x80) { - switch ((NvGpuFifoMeth)MethCall.Method) + switch ((NvGpuFifoMeth)methCall.Method) { case NvGpuFifoMeth.SetMacroUploadAddress: { - CurrMacroPosition = MethCall.Argument; + _currMacroPosition = methCall.Argument; break; } case NvGpuFifoMeth.SendMacroCodeData: { - Mme[CurrMacroPosition++] = MethCall.Argument; + _mme[_currMacroPosition++] = methCall.Argument; break; } case NvGpuFifoMeth.SetMacroBindingIndex: { - CurrMacroBindIndex = MethCall.Argument; + _currMacroBindIndex = methCall.Argument; break; } case NvGpuFifoMeth.BindMacro: { - int Position = MethCall.Argument; + int position = methCall.Argument; - Macros[CurrMacroBindIndex] = new CachedMacro(this, Gpu.Engine3d, Position); + _macros[_currMacroBindIndex] = new CachedMacro(this, _gpu.Engine3d, position); break; } - default: CallP2mfMethod(Vmm, MethCall); break; + default: CallP2mfMethod(vmm, methCall); break; } } - else if (MethCall.Method < 0xe00) + else if (methCall.Method < 0xe00) { - Gpu.Engine3d.CallMethod(Vmm, MethCall); + _gpu.Engine3d.CallMethod(vmm, methCall); } else { - int MacroIndex = (MethCall.Method >> 1) & MacroIndexMask; + int macroIndex = (methCall.Method >> 1) & MacroIndexMask; - if ((MethCall.Method & 1) != 0) + if ((methCall.Method & 1) != 0) { - Macros[MacroIndex].PushArgument(MethCall.Argument); + _macros[macroIndex].PushArgument(methCall.Argument); } else { - Macros[MacroIndex].StartExecution(MethCall.Argument); + _macros[macroIndex].StartExecution(methCall.Argument); } - if (MethCall.IsLastCall) + if (methCall.IsLastCall) { - Macros[MacroIndex].Execute(Vmm, Mme); + _macros[macroIndex].Execute(vmm, _mme); } } } - private void CallP2mfMethod(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void CallP2mfMethod(NvGpuVmm vmm, GpuMethodCall methCall) { - Gpu.EngineP2mf.CallMethod(Vmm, MethCall); + _gpu.EngineP2mf.CallMethod(vmm, methCall); } - private void CallM2mfMethod(NvGpuVmm Vmm, GpuMethodCall MethCall) + private void CallM2mfMethod(NvGpuVmm vmm, GpuMethodCall methCall) { - Gpu.EngineM2mf.CallMethod(Vmm, MethCall); + _gpu.EngineM2mf.CallMethod(vmm, methCall); } } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuMethod.cs b/Ryujinx.Graphics/Graphics3d/NvGpuMethod.cs index 8730d1448c..23185c81fc 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuMethod.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuMethod.cs @@ -2,5 +2,5 @@ using Ryujinx.Graphics.Memory; namespace Ryujinx.Graphics.Graphics3d { - delegate void NvGpuMethod(NvGpuVmm Vmm, GpuMethodCall MethCall); + delegate void NvGpuMethod(NvGpuVmm vmm, GpuMethodCall methCall); } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/Texture/BlockLinearSwizzle.cs b/Ryujinx.Graphics/Graphics3d/Texture/BlockLinearSwizzle.cs index 789e29c1a3..682f7d671d 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/BlockLinearSwizzle.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/BlockLinearSwizzle.cs @@ -111,8 +111,8 @@ namespace Ryujinx.Graphics.Texture public GobBlockSizes(int gobBlockHeight, int gobBlockDepth) { - this.Height = gobBlockHeight; - this.Depth = gobBlockDepth; + Height = gobBlockHeight; + Depth = gobBlockDepth; } } @@ -144,8 +144,8 @@ namespace Ryujinx.Graphics.Texture public RobAndSliceSizes(int robSize, int sliceSize) { - this.RobSize = robSize; - this.SliceSize = sliceSize; + RobSize = robSize; + SliceSize = sliceSize; } } diff --git a/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs b/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs index 84b979e7ca..31b0bae8df 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs @@ -31,11 +31,11 @@ namespace Ryujinx.Graphics.Texture public ImageDescriptor(int bytesPerPixel, int blockWidth, int blockHeight, int blockDepth, TargetBuffer target) { - this.BytesPerPixel = bytesPerPixel; - this.BlockWidth = blockWidth; - this.BlockHeight = blockHeight; - this.BlockDepth = blockDepth; - this.Target = target; + BytesPerPixel = bytesPerPixel; + BlockWidth = blockWidth; + BlockHeight = blockHeight; + BlockDepth = blockDepth; + Target = target; } } @@ -257,7 +257,7 @@ namespace Ryujinx.Graphics.Texture byte[] data = new byte[dataLayerSize * image.LayerCount]; int targetMipLevel = image.MaxMipmapLevel <= 1 ? 1 : image.MaxMipmapLevel - 1; - int layerOffset = ImageUtils.GetLayerOffset(image, targetMipLevel); + int layerOffset = GetLayerOffset(image, targetMipLevel); for (int layer = 0; layer < image.LayerCount; layer++) { @@ -288,7 +288,7 @@ namespace Ryujinx.Graphics.Texture ImageDescriptor desc = GetImageDescriptor(image.Format); - (int width, int height, int depth) = ImageUtils.GetImageSizeInBlocks(image); + (int width, int height, int depth) = GetImageSizeInBlocks(image); int bytesPerPixel = desc.BytesPerPixel; diff --git a/Ryujinx.Graphics/Graphics3d/Texture/LinearSwizzle.cs b/Ryujinx.Graphics/Graphics3d/Texture/LinearSwizzle.cs index 7ce0d399aa..837583f964 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/LinearSwizzle.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/LinearSwizzle.cs @@ -11,8 +11,8 @@ namespace Ryujinx.Graphics.Texture public LinearSwizzle(int pitch, int bpp, int width, int height) { - this._pitch = pitch; - this._bpp = bpp; + _pitch = pitch; + _bpp = bpp; _sliceSize = width * height * bpp; } diff --git a/Ryujinx.Graphics/NvGpu.cs b/Ryujinx.Graphics/NvGpu.cs index 3fd91f74a5..015b69fdbc 100644 --- a/Ryujinx.Graphics/NvGpu.cs +++ b/Ryujinx.Graphics/NvGpu.cs @@ -15,8 +15,8 @@ namespace Ryujinx.Graphics public DmaPusher Pusher { get; private set; } internal NvGpuFifo Fifo { get; private set; } - internal NvGpuEngine2d Engine2d { get; private set; } - internal NvGpuEngine3d Engine3d { get; private set; } + internal NvGpuEngine2D Engine2d { get; private set; } + internal NvGpuEngine3D Engine3d { get; private set; } internal NvGpuEngineM2mf EngineM2mf { get; private set; } internal NvGpuEngineP2mf EngineP2mf { get; private set; } @@ -33,8 +33,8 @@ namespace Ryujinx.Graphics Pusher = new DmaPusher(this); Fifo = new NvGpuFifo(this); - Engine2d = new NvGpuEngine2d(this); - Engine3d = new NvGpuEngine3d(this); + Engine2d = new NvGpuEngine2D(this); + Engine3d = new NvGpuEngine3D(this); EngineM2mf = new NvGpuEngineM2mf(this); EngineP2mf = new NvGpuEngineP2mf(this);