VideoImageComposer.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using Ryujinx.Graphics.Memory;
  2. namespace Ryujinx.Graphics.Vic
  3. {
  4. class VideoImageComposer
  5. {
  6. private NvGpu Gpu;
  7. private long ConfigStructAddress;
  8. private long OutputSurfaceLumaAddress;
  9. private long OutputSurfaceChromaUAddress;
  10. private long OutputSurfaceChromaVAddress;
  11. public VideoImageComposer(NvGpu Gpu)
  12. {
  13. this.Gpu = Gpu;
  14. }
  15. public void Process(NvGpuVmm Vmm, int MethodOffset, int[] Arguments)
  16. {
  17. VideoImageComposerMeth Method = (VideoImageComposerMeth)MethodOffset;
  18. switch (Method)
  19. {
  20. case VideoImageComposerMeth.Execute:
  21. Execute(Vmm, Arguments);
  22. break;
  23. case VideoImageComposerMeth.SetConfigStructOffset:
  24. SetConfigStructOffset(Vmm, Arguments);
  25. break;
  26. case VideoImageComposerMeth.SetOutputSurfaceLumaOffset:
  27. SetOutputSurfaceLumaOffset(Vmm, Arguments);
  28. break;
  29. case VideoImageComposerMeth.SetOutputSurfaceChromaUOffset:
  30. SetOutputSurfaceChromaUOffset(Vmm, Arguments);
  31. break;
  32. case VideoImageComposerMeth.SetOutputSurfaceChromaVOffset:
  33. SetOutputSurfaceChromaVOffset(Vmm, Arguments);
  34. break;
  35. }
  36. }
  37. private void Execute(NvGpuVmm Vmm, int[] Arguments)
  38. {
  39. StructUnpacker Unpacker = new StructUnpacker(Vmm, ConfigStructAddress + 0x20);
  40. SurfacePixelFormat PixelFormat = (SurfacePixelFormat)Unpacker.Read(7);
  41. int ChromaLocHoriz = Unpacker.Read(2);
  42. int ChromaLocVert = Unpacker.Read(2);
  43. int BlockLinearKind = Unpacker.Read(4);
  44. int BlockLinearHeightLog2 = Unpacker.Read(4);
  45. int Reserved0 = Unpacker.Read(3);
  46. int Reserved1 = Unpacker.Read(10);
  47. int SurfaceWidthMinus1 = Unpacker.Read(14);
  48. int SurfaceHeightMinus1 = Unpacker.Read(14);
  49. int GobBlockHeight = 1 << BlockLinearHeightLog2;
  50. int SurfaceWidth = SurfaceWidthMinus1 + 1;
  51. int SurfaceHeight = SurfaceHeightMinus1 + 1;
  52. SurfaceOutputConfig OutputConfig = new SurfaceOutputConfig(
  53. PixelFormat,
  54. SurfaceWidth,
  55. SurfaceHeight,
  56. GobBlockHeight,
  57. OutputSurfaceLumaAddress,
  58. OutputSurfaceChromaUAddress,
  59. OutputSurfaceChromaVAddress);
  60. Gpu.VideoDecoder.CopyPlanes(Vmm, OutputConfig);
  61. }
  62. private void SetConfigStructOffset(NvGpuVmm Vmm, int[] Arguments)
  63. {
  64. ConfigStructAddress = GetAddress(Arguments);
  65. }
  66. private void SetOutputSurfaceLumaOffset(NvGpuVmm Vmm, int[] Arguments)
  67. {
  68. OutputSurfaceLumaAddress = GetAddress(Arguments);
  69. }
  70. private void SetOutputSurfaceChromaUOffset(NvGpuVmm Vmm, int[] Arguments)
  71. {
  72. OutputSurfaceChromaUAddress = GetAddress(Arguments);
  73. }
  74. private void SetOutputSurfaceChromaVOffset(NvGpuVmm Vmm, int[] Arguments)
  75. {
  76. OutputSurfaceChromaVAddress = GetAddress(Arguments);
  77. }
  78. private static long GetAddress(int[] Arguments)
  79. {
  80. return (long)(uint)Arguments[0] << 8;
  81. }
  82. }
  83. }