InstEmitMove.cs 3.7 KB

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