InstEmitMove.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using Ryujinx.Graphics.Shader.Decoders;
  2. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  3. using Ryujinx.Graphics.Shader.Translation;
  4. using static Ryujinx.Graphics.Shader.Instructions.InstEmitHelper;
  5. using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
  6. namespace Ryujinx.Graphics.Shader.Instructions
  7. {
  8. static partial class InstEmit
  9. {
  10. public static void Mov(EmitterContext context)
  11. {
  12. context.Copy(GetDest(context), GetSrcB(context));
  13. }
  14. public static void R2p(EmitterContext context)
  15. {
  16. OpCodeAlu op = (OpCodeAlu)context.CurrOp;
  17. bool isCC = op.RawOpCode.Extract(40);
  18. int shift = op.RawOpCode.Extract(41, 2) * 8;
  19. Operand value = GetSrcA(context);
  20. Operand mask = GetSrcB(context);
  21. Operand Test(Operand value, int bit)
  22. {
  23. return context.ICompareNotEqual(context.BitwiseAnd(value, Const(1 << bit)), Const(0));
  24. }
  25. if (isCC)
  26. {
  27. // TODO: Support Register to condition code flags copy.
  28. context.Config.GpuAccessor.Log("R2P.CC not implemented.");
  29. }
  30. else
  31. {
  32. for (int bit = 0; bit < 7; bit++)
  33. {
  34. Operand pred = Register(bit, RegisterType.Predicate);
  35. Operand res = context.ConditionalSelect(Test(mask, bit), Test(value, bit + shift), pred);
  36. context.Copy(pred, res);
  37. }
  38. }
  39. }
  40. public static void S2r(EmitterContext context)
  41. {
  42. // TODO: Better impl.
  43. OpCodeAlu op = (OpCodeAlu)context.CurrOp;
  44. SystemRegister sysReg = (SystemRegister)op.RawOpCode.Extract(20, 8);
  45. Operand src;
  46. switch (sysReg)
  47. {
  48. case SystemRegister.LaneId: src = Attribute(AttributeConsts.LaneId); break;
  49. // TODO: Use value from Y direction GPU register.
  50. case SystemRegister.YDirection: src = ConstF(1); break;
  51. case SystemRegister.ThreadId:
  52. {
  53. Operand tidX = Attribute(AttributeConsts.ThreadIdX);
  54. Operand tidY = Attribute(AttributeConsts.ThreadIdY);
  55. Operand tidZ = Attribute(AttributeConsts.ThreadIdZ);
  56. tidY = context.ShiftLeft(tidY, Const(16));
  57. tidZ = context.ShiftLeft(tidZ, Const(26));
  58. src = context.BitwiseOr(tidX, context.BitwiseOr(tidY, tidZ));
  59. break;
  60. }
  61. case SystemRegister.ThreadIdX: src = Attribute(AttributeConsts.ThreadIdX); break;
  62. case SystemRegister.ThreadIdY: src = Attribute(AttributeConsts.ThreadIdY); break;
  63. case SystemRegister.ThreadIdZ: src = Attribute(AttributeConsts.ThreadIdZ); break;
  64. case SystemRegister.CtaIdX: src = Attribute(AttributeConsts.CtaIdX); break;
  65. case SystemRegister.CtaIdY: src = Attribute(AttributeConsts.CtaIdY); break;
  66. case SystemRegister.CtaIdZ: src = Attribute(AttributeConsts.CtaIdZ); break;
  67. case SystemRegister.EqMask: src = Attribute(AttributeConsts.EqMask); break;
  68. case SystemRegister.LtMask: src = Attribute(AttributeConsts.LtMask); break;
  69. case SystemRegister.LeMask: src = Attribute(AttributeConsts.LeMask); break;
  70. case SystemRegister.GtMask: src = Attribute(AttributeConsts.GtMask); break;
  71. case SystemRegister.GeMask: src = Attribute(AttributeConsts.GeMask); break;
  72. default: src = Const(0); break;
  73. }
  74. context.Copy(GetDest(context), src);
  75. }
  76. public static void Sel(EmitterContext context)
  77. {
  78. Operand pred = GetPredicate39(context);
  79. Operand srcA = GetSrcA(context);
  80. Operand srcB = GetSrcB(context);
  81. Operand res = context.ConditionalSelect(pred, srcA, srcB);
  82. context.Copy(GetDest(context), res);
  83. }
  84. public static void Shfl(EmitterContext context)
  85. {
  86. OpCodeShuffle op = (OpCodeShuffle)context.CurrOp;
  87. Operand pred = Register(op.Predicate48);
  88. Operand srcA = GetSrcA(context);
  89. Operand srcB = op.IsBImmediate ? Const(op.ImmediateB) : Register(op.Rb);
  90. Operand srcC = op.IsCImmediate ? Const(op.ImmediateC) : Register(op.Rc);
  91. (Operand res, Operand valid) = op.ShuffleType switch
  92. {
  93. ShuffleType.Indexed => context.Shuffle(srcA, srcB, srcC),
  94. ShuffleType.Up => context.ShuffleUp(srcA, srcB, srcC),
  95. ShuffleType.Down => context.ShuffleDown(srcA, srcB, srcC),
  96. ShuffleType.Butterfly => context.ShuffleXor(srcA, srcB, srcC),
  97. _ => (null, null)
  98. };
  99. context.Copy(GetDest(context), res);
  100. context.Copy(pred, valid);
  101. }
  102. }
  103. }