InstEmitMove.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. OpCodeAlu op = (OpCodeAlu)context.CurrOp;
  13. context.Copy(GetDest(context), GetSrcB(context));
  14. }
  15. public static void S2r(EmitterContext context)
  16. {
  17. // TODO: Better impl.
  18. OpCodeAlu op = (OpCodeAlu)context.CurrOp;
  19. SystemRegister sysReg = (SystemRegister)op.RawOpCode.Extract(20, 8);
  20. Operand src;
  21. switch (sysReg)
  22. {
  23. case SystemRegister.LaneId: src = Attribute(AttributeConsts.LaneId); break;
  24. // TODO: Use value from Y direction GPU register.
  25. case SystemRegister.YDirection: src = ConstF(1); break;
  26. case SystemRegister.ThreadId:
  27. {
  28. Operand tidX = Attribute(AttributeConsts.ThreadIdX);
  29. Operand tidY = Attribute(AttributeConsts.ThreadIdY);
  30. Operand tidZ = Attribute(AttributeConsts.ThreadIdZ);
  31. tidY = context.ShiftLeft(tidY, Const(16));
  32. tidZ = context.ShiftLeft(tidZ, Const(26));
  33. src = context.BitwiseOr(tidX, context.BitwiseOr(tidY, tidZ));
  34. break;
  35. }
  36. case SystemRegister.ThreadIdX: src = Attribute(AttributeConsts.ThreadIdX); break;
  37. case SystemRegister.ThreadIdY: src = Attribute(AttributeConsts.ThreadIdY); break;
  38. case SystemRegister.ThreadIdZ: src = Attribute(AttributeConsts.ThreadIdZ); break;
  39. case SystemRegister.CtaIdX: src = Attribute(AttributeConsts.CtaIdX); break;
  40. case SystemRegister.CtaIdY: src = Attribute(AttributeConsts.CtaIdY); break;
  41. case SystemRegister.CtaIdZ: src = Attribute(AttributeConsts.CtaIdZ); break;
  42. case SystemRegister.EqMask: src = Attribute(AttributeConsts.EqMask); break;
  43. case SystemRegister.LtMask: src = Attribute(AttributeConsts.LtMask); break;
  44. case SystemRegister.LeMask: src = Attribute(AttributeConsts.LeMask); break;
  45. case SystemRegister.GtMask: src = Attribute(AttributeConsts.GtMask); break;
  46. case SystemRegister.GeMask: src = Attribute(AttributeConsts.GeMask); break;
  47. default: src = Const(0); break;
  48. }
  49. context.Copy(GetDest(context), src);
  50. }
  51. public static void Sel(EmitterContext context)
  52. {
  53. OpCodeAlu op = (OpCodeAlu)context.CurrOp;
  54. Operand pred = GetPredicate39(context);
  55. Operand srcA = GetSrcA(context);
  56. Operand srcB = GetSrcB(context);
  57. Operand res = context.ConditionalSelect(pred, srcA, srcB);
  58. context.Copy(GetDest(context), res);
  59. }
  60. public static void Shfl(EmitterContext context)
  61. {
  62. OpCodeShuffle op = (OpCodeShuffle)context.CurrOp;
  63. Operand pred = Register(op.Predicate48);
  64. Operand srcA = GetSrcA(context);
  65. Operand srcB = op.IsBImmediate ? Const(op.ImmediateB) : Register(op.Rb);
  66. Operand srcC = op.IsCImmediate ? Const(op.ImmediateC) : Register(op.Rc);
  67. Operand res = null;
  68. switch (op.ShuffleType)
  69. {
  70. case ShuffleType.Indexed:
  71. res = context.Shuffle(srcA, srcB, srcC);
  72. break;
  73. case ShuffleType.Up:
  74. res = context.ShuffleUp(srcA, srcB, srcC);
  75. break;
  76. case ShuffleType.Down:
  77. res = context.ShuffleDown(srcA, srcB, srcC);
  78. break;
  79. case ShuffleType.Butterfly:
  80. res = context.ShuffleXor(srcA, srcB, srcC);
  81. break;
  82. }
  83. context.Copy(GetDest(context), res);
  84. }
  85. }
  86. }