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. _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. }