NvGpuEngineP2mf.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Ryujinx.Graphics.Memory;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. namespace Ryujinx.Graphics
  5. {
  6. public class NvGpuEngineP2mf : INvGpuEngine
  7. {
  8. public int[] Registers { get; private set; }
  9. private NvGpu Gpu;
  10. private Dictionary<int, NvGpuMethod> Methods;
  11. private ReadOnlyCollection<int> DataBuffer;
  12. public NvGpuEngineP2mf(NvGpu Gpu)
  13. {
  14. this.Gpu = Gpu;
  15. Registers = new int[0x80];
  16. Methods = new Dictionary<int, NvGpuMethod>();
  17. void AddMethod(int Meth, int Count, int Stride, NvGpuMethod Method)
  18. {
  19. while (Count-- > 0)
  20. {
  21. Methods.Add(Meth, Method);
  22. Meth += Stride;
  23. }
  24. }
  25. AddMethod(0x6c, 1, 1, Execute);
  26. AddMethod(0x6d, 1, 1, PushData);
  27. }
  28. public void CallMethod(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
  29. {
  30. if (Methods.TryGetValue(PBEntry.Method, out NvGpuMethod Method))
  31. {
  32. Method(Vmm, PBEntry);
  33. }
  34. else
  35. {
  36. WriteRegister(PBEntry);
  37. }
  38. }
  39. private void Execute(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
  40. {
  41. //TODO: Some registers and copy modes are still not implemented.
  42. int Control = PBEntry.Arguments[0];
  43. long DstAddress = MakeInt64From2xInt32(NvGpuEngineP2mfReg.DstAddress);
  44. int LineLengthIn = ReadRegister(NvGpuEngineP2mfReg.LineLengthIn);
  45. DataBuffer = null;
  46. Gpu.Fifo.Step();
  47. for (int Offset = 0; Offset < LineLengthIn; Offset += 4)
  48. {
  49. Vmm.WriteInt32(DstAddress + Offset, DataBuffer[Offset >> 2]);
  50. }
  51. }
  52. private void PushData(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
  53. {
  54. DataBuffer = PBEntry.Arguments;
  55. }
  56. private long MakeInt64From2xInt32(NvGpuEngineP2mfReg Reg)
  57. {
  58. return
  59. (long)Registers[(int)Reg + 0] << 32 |
  60. (uint)Registers[(int)Reg + 1];
  61. }
  62. private void WriteRegister(NvGpuPBEntry PBEntry)
  63. {
  64. int ArgsCount = PBEntry.Arguments.Count;
  65. if (ArgsCount > 0)
  66. {
  67. Registers[PBEntry.Method] = PBEntry.Arguments[ArgsCount - 1];
  68. }
  69. }
  70. private int ReadRegister(NvGpuEngineP2mfReg Reg)
  71. {
  72. return Registers[(int)Reg];
  73. }
  74. private void WriteRegister(NvGpuEngineP2mfReg Reg, int Value)
  75. {
  76. Registers[(int)Reg] = Value;
  77. }
  78. }
  79. }