InstEmitMove.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.ThreadKill: src = context.Config.Stage == ShaderStage.Fragment
  52. ? Attribute(AttributeConsts.ThreadKill)
  53. : Const(0);
  54. break;
  55. case SystemRegister.ThreadId:
  56. {
  57. Operand tidX = Attribute(AttributeConsts.ThreadIdX);
  58. Operand tidY = Attribute(AttributeConsts.ThreadIdY);
  59. Operand tidZ = Attribute(AttributeConsts.ThreadIdZ);
  60. tidY = context.ShiftLeft(tidY, Const(16));
  61. tidZ = context.ShiftLeft(tidZ, Const(26));
  62. src = context.BitwiseOr(tidX, context.BitwiseOr(tidY, tidZ));
  63. break;
  64. }
  65. case SystemRegister.ThreadIdX: src = Attribute(AttributeConsts.ThreadIdX); break;
  66. case SystemRegister.ThreadIdY: src = Attribute(AttributeConsts.ThreadIdY); break;
  67. case SystemRegister.ThreadIdZ: src = Attribute(AttributeConsts.ThreadIdZ); break;
  68. case SystemRegister.CtaIdX: src = Attribute(AttributeConsts.CtaIdX); break;
  69. case SystemRegister.CtaIdY: src = Attribute(AttributeConsts.CtaIdY); break;
  70. case SystemRegister.CtaIdZ: src = Attribute(AttributeConsts.CtaIdZ); break;
  71. case SystemRegister.EqMask: src = Attribute(AttributeConsts.EqMask); break;
  72. case SystemRegister.LtMask: src = Attribute(AttributeConsts.LtMask); break;
  73. case SystemRegister.LeMask: src = Attribute(AttributeConsts.LeMask); break;
  74. case SystemRegister.GtMask: src = Attribute(AttributeConsts.GtMask); break;
  75. case SystemRegister.GeMask: src = Attribute(AttributeConsts.GeMask); break;
  76. default: src = Const(0); break;
  77. }
  78. context.Copy(GetDest(context), src);
  79. }
  80. public static void Sel(EmitterContext context)
  81. {
  82. Operand pred = GetPredicate39(context);
  83. Operand srcA = GetSrcA(context);
  84. Operand srcB = GetSrcB(context);
  85. Operand res = context.ConditionalSelect(pred, srcA, srcB);
  86. context.Copy(GetDest(context), res);
  87. }
  88. public static void Shfl(EmitterContext context)
  89. {
  90. OpCodeShuffle op = (OpCodeShuffle)context.CurrOp;
  91. Operand pred = Register(op.Predicate48);
  92. Operand srcA = GetSrcA(context);
  93. Operand srcB = op.IsBImmediate ? Const(op.ImmediateB) : Register(op.Rb);
  94. Operand srcC = op.IsCImmediate ? Const(op.ImmediateC) : Register(op.Rc);
  95. (Operand res, Operand valid) = op.ShuffleType switch
  96. {
  97. ShuffleType.Indexed => context.Shuffle(srcA, srcB, srcC),
  98. ShuffleType.Up => context.ShuffleUp(srcA, srcB, srcC),
  99. ShuffleType.Down => context.ShuffleDown(srcA, srcB, srcC),
  100. ShuffleType.Butterfly => context.ShuffleXor(srcA, srcB, srcC),
  101. _ => (null, null)
  102. };
  103. context.Copy(GetDest(context), res);
  104. context.Copy(pred, valid);
  105. }
  106. }
  107. }