OpCodeVideo.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using Ryujinx.Graphics.Shader.Instructions;
  2. namespace Ryujinx.Graphics.Shader.Decoders
  3. {
  4. class OpCodeVideo : OpCode, IOpCodeRd, IOpCodeRa, IOpCodeRc
  5. {
  6. public Register Rd { get; }
  7. public Register Ra { get; }
  8. public Register Rb { get; }
  9. public Register Rc { get; }
  10. public int Immediate { get; }
  11. public int RaSelection { get; }
  12. public int RbSelection { get; }
  13. public bool SetCondCode { get; }
  14. public bool HasRb { get; }
  15. public VideoType RaType { get; }
  16. public VideoType RbType { get; }
  17. public VideoPostOp PostOp { get; }
  18. public bool DstSigned { get; }
  19. public bool Saturate { get; }
  20. public new static OpCode Create(InstEmitter emitter, ulong address, long opCode) => new OpCodeVideo(emitter, address, opCode);
  21. public OpCodeVideo(InstEmitter emitter, ulong address, long opCode) : base(emitter, address, opCode)
  22. {
  23. Rd = new Register(opCode.Extract(0, 8), RegisterType.Gpr);
  24. Ra = new Register(opCode.Extract(8, 8), RegisterType.Gpr);
  25. Rb = new Register(opCode.Extract(20, 8), RegisterType.Gpr);
  26. Rc = new Register(opCode.Extract(39, 8), RegisterType.Gpr);
  27. RaSelection = opCode.Extract(36, 2);
  28. RbSelection = opCode.Extract(28, 2);
  29. RaType = opCode.Extract(37, 2) switch
  30. {
  31. 2 => VideoType.U16,
  32. 3 => VideoType.U32,
  33. _ => VideoType.U8
  34. };
  35. RbType = opCode.Extract(29, 2) switch
  36. {
  37. 2 => VideoType.U16,
  38. 3 => VideoType.U32,
  39. _ => VideoType.U8
  40. };
  41. if (opCode.Extract(48))
  42. {
  43. RaType |= VideoType.Signed;
  44. }
  45. if (!opCode.Extract(50))
  46. {
  47. // Immediate variant.
  48. Immediate = opCode.Extract(16, 20);
  49. RbType = opCode.Extract(49) ? VideoType.S16 : VideoType.U16;
  50. if (RbType == VideoType.S16)
  51. {
  52. Immediate = (Immediate << 12) >> 12;
  53. }
  54. }
  55. else if (opCode.Extract(49))
  56. {
  57. RbType |= VideoType.Signed;
  58. }
  59. if (RaType == VideoType.U16)
  60. {
  61. RaSelection &= 1;
  62. }
  63. else if (RaType == VideoType.U32)
  64. {
  65. RaSelection = 0;
  66. }
  67. if (RbType == VideoType.U16)
  68. {
  69. RbSelection &= 1;
  70. }
  71. else if (RbType == VideoType.U32)
  72. {
  73. RbSelection = 0;
  74. }
  75. SetCondCode = opCode.Extract(47);
  76. HasRb = opCode.Extract(50);
  77. PostOp = (VideoPostOp)opCode.Extract(51, 3);
  78. DstSigned = opCode.Extract(54);
  79. Saturate = opCode.Extract(55);
  80. }
  81. }
  82. }