CdmaProcessor.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Ryujinx.Graphics.Memory;
  2. using System.Collections.Generic;
  3. namespace Ryujinx.Graphics
  4. {
  5. public class CdmaProcessor
  6. {
  7. private const int MethSetMethod = 0x10;
  8. private const int MethSetData = 0x11;
  9. private NvGpu Gpu;
  10. public CdmaProcessor(NvGpu Gpu)
  11. {
  12. this.Gpu = Gpu;
  13. }
  14. public void PushCommands(NvGpuVmm Vmm, int[] CmdBuffer)
  15. {
  16. List<ChCommand> Commands = new List<ChCommand>();
  17. ChClassId CurrentClass = 0;
  18. for (int Index = 0; Index < CmdBuffer.Length; Index++)
  19. {
  20. int Cmd = CmdBuffer[Index];
  21. int Value = (Cmd >> 0) & 0xffff;
  22. int MethodOffset = (Cmd >> 16) & 0xfff;
  23. ChSubmissionMode SubmissionMode = (ChSubmissionMode)((Cmd >> 28) & 0xf);
  24. switch (SubmissionMode)
  25. {
  26. case ChSubmissionMode.SetClass: CurrentClass = (ChClassId)(Value >> 6); break;
  27. case ChSubmissionMode.Incrementing:
  28. {
  29. int Count = Value;
  30. for (int ArgIdx = 0; ArgIdx < Count; ArgIdx++)
  31. {
  32. int Argument = CmdBuffer[++Index];
  33. Commands.Add(new ChCommand(CurrentClass, MethodOffset + ArgIdx, Argument));
  34. }
  35. break;
  36. }
  37. case ChSubmissionMode.NonIncrementing:
  38. {
  39. int Count = Value;
  40. int[] Arguments = new int[Count];
  41. for (int ArgIdx = 0; ArgIdx < Count; ArgIdx++)
  42. {
  43. Arguments[ArgIdx] = CmdBuffer[++Index];
  44. }
  45. Commands.Add(new ChCommand(CurrentClass, MethodOffset, Arguments));
  46. break;
  47. }
  48. }
  49. }
  50. ProcessCommands(Vmm, Commands.ToArray());
  51. }
  52. private void ProcessCommands(NvGpuVmm Vmm, ChCommand[] Commands)
  53. {
  54. int MethodOffset = 0;
  55. foreach (ChCommand Command in Commands)
  56. {
  57. switch (Command.MethodOffset)
  58. {
  59. case MethSetMethod: MethodOffset = Command.Arguments[0]; break;
  60. case MethSetData:
  61. {
  62. if (Command.ClassId == ChClassId.NvDec)
  63. {
  64. Gpu.VideoDecoder.Process(Vmm, MethodOffset, Command.Arguments);
  65. }
  66. else if (Command.ClassId == ChClassId.GraphicsVic)
  67. {
  68. Gpu.VideoImageComposer.Process(Vmm, MethodOffset, Command.Arguments);
  69. }
  70. break;
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }