OpCodeVideo.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 OpCodeVideo(InstEmitter emitter, ulong address, long opCode) : base(emitter, address, opCode)
  21. {
  22. Rd = new Register(opCode.Extract(0, 8), RegisterType.Gpr);
  23. Ra = new Register(opCode.Extract(8, 8), RegisterType.Gpr);
  24. Rb = new Register(opCode.Extract(20, 8), RegisterType.Gpr);
  25. Rc = new Register(opCode.Extract(39, 8), RegisterType.Gpr);
  26. RaSelection = opCode.Extract(36, 2);
  27. RbSelection = opCode.Extract(28, 2);
  28. RaType = opCode.Extract(37, 2) switch
  29. {
  30. 2 => VideoType.U16,
  31. 3 => VideoType.U32,
  32. _ => VideoType.U8
  33. };
  34. RbType = opCode.Extract(29, 2) switch
  35. {
  36. 2 => VideoType.U16,
  37. 3 => VideoType.U32,
  38. _ => VideoType.U8
  39. };
  40. if (opCode.Extract(48))
  41. {
  42. RaType |= VideoType.Signed;
  43. }
  44. if (!opCode.Extract(50))
  45. {
  46. // Immediate variant.
  47. Immediate = opCode.Extract(16, 20);
  48. RbType = opCode.Extract(49) ? VideoType.S16 : VideoType.U16;
  49. if (RbType == VideoType.S16)
  50. {
  51. Immediate = (Immediate << 12) >> 12;
  52. }
  53. }
  54. else if (opCode.Extract(49))
  55. {
  56. RbType |= VideoType.Signed;
  57. }
  58. if (RaType == VideoType.U16)
  59. {
  60. RaSelection &= 1;
  61. }
  62. else if (RaType == VideoType.U32)
  63. {
  64. RaSelection = 0;
  65. }
  66. if (RbType == VideoType.U16)
  67. {
  68. RbSelection &= 1;
  69. }
  70. else if (RbType == VideoType.U32)
  71. {
  72. RbSelection = 0;
  73. }
  74. SetCondCode = opCode.Extract(47);
  75. HasRb = opCode.Extract(50);
  76. PostOp = (VideoPostOp)opCode.Extract(51, 3);
  77. DstSigned = opCode.Extract(54);
  78. Saturate = opCode.Extract(55);
  79. }
  80. }
  81. }