InstEmitMove.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 MovR(EmitterContext context)
  11. {
  12. InstMovR op = context.GetOp<InstMovR>();
  13. context.Copy(GetDest(op.Dest), GetSrcReg(context, op.SrcA));
  14. }
  15. public static void MovI(EmitterContext context)
  16. {
  17. InstMovI op = context.GetOp<InstMovI>();
  18. context.Copy(GetDest(op.Dest), GetSrcImm(context, op.Imm20));
  19. }
  20. public static void MovC(EmitterContext context)
  21. {
  22. InstMovC op = context.GetOp<InstMovC>();
  23. context.Copy(GetDest(op.Dest), GetSrcCbuf(context, op.CbufSlot, op.CbufOffset));
  24. }
  25. public static void Mov32i(EmitterContext context)
  26. {
  27. InstMov32i op = context.GetOp<InstMov32i>();
  28. context.Copy(GetDest(op.Dest), GetSrcImm(context, op.Imm32));
  29. }
  30. public static void R2pR(EmitterContext context)
  31. {
  32. InstR2pR op = context.GetOp<InstR2pR>();
  33. Operand value = GetSrcReg(context, op.SrcA);
  34. Operand mask = GetSrcReg(context, op.SrcB);
  35. EmitR2p(context, value, mask, op.ByteSel, op.Ccpr);
  36. }
  37. public static void R2pI(EmitterContext context)
  38. {
  39. InstR2pI op = context.GetOp<InstR2pI>();
  40. Operand value = GetSrcReg(context, op.SrcA);
  41. Operand mask = GetSrcImm(context, Imm20ToSInt(op.Imm20));
  42. EmitR2p(context, value, mask, op.ByteSel, op.Ccpr);
  43. }
  44. public static void R2pC(EmitterContext context)
  45. {
  46. InstR2pC op = context.GetOp<InstR2pC>();
  47. Operand value = GetSrcReg(context, op.SrcA);
  48. Operand mask = GetSrcCbuf(context, op.CbufSlot, op.CbufOffset);
  49. EmitR2p(context, value, mask, op.ByteSel, op.Ccpr);
  50. }
  51. public static void S2r(EmitterContext context)
  52. {
  53. InstS2r op = context.GetOp<InstS2r>();
  54. Operand src;
  55. switch (op.SReg)
  56. {
  57. case SReg.LaneId:
  58. src = Attribute(AttributeConsts.LaneId);
  59. break;
  60. case SReg.YDirection:
  61. src = ConstF(1); // TODO: Use value from Y direction GPU register.
  62. break;
  63. case SReg.ThreadKill:
  64. src = context.Config.Stage == ShaderStage.Fragment ? Attribute(AttributeConsts.ThreadKill) : Const(0);
  65. break;
  66. case SReg.TId:
  67. Operand tidX = Attribute(AttributeConsts.ThreadIdX);
  68. Operand tidY = Attribute(AttributeConsts.ThreadIdY);
  69. Operand tidZ = Attribute(AttributeConsts.ThreadIdZ);
  70. tidY = context.ShiftLeft(tidY, Const(16));
  71. tidZ = context.ShiftLeft(tidZ, Const(26));
  72. src = context.BitwiseOr(tidX, context.BitwiseOr(tidY, tidZ));
  73. break;
  74. case SReg.TIdX:
  75. src = Attribute(AttributeConsts.ThreadIdX);
  76. break;
  77. case SReg.TIdY:
  78. src = Attribute(AttributeConsts.ThreadIdY);
  79. break;
  80. case SReg.TIdZ:
  81. src = Attribute(AttributeConsts.ThreadIdZ);
  82. break;
  83. case SReg.CtaIdX:
  84. src = Attribute(AttributeConsts.CtaIdX);
  85. break;
  86. case SReg.CtaIdY:
  87. src = Attribute(AttributeConsts.CtaIdY);
  88. break;
  89. case SReg.CtaIdZ:
  90. src = Attribute(AttributeConsts.CtaIdZ);
  91. break;
  92. case SReg.EqMask:
  93. src = Attribute(AttributeConsts.EqMask);
  94. break;
  95. case SReg.LtMask:
  96. src = Attribute(AttributeConsts.LtMask);
  97. break;
  98. case SReg.LeMask:
  99. src = Attribute(AttributeConsts.LeMask);
  100. break;
  101. case SReg.GtMask:
  102. src = Attribute(AttributeConsts.GtMask);
  103. break;
  104. case SReg.GeMask:
  105. src = Attribute(AttributeConsts.GeMask);
  106. break;
  107. default:
  108. src = Const(0);
  109. break;
  110. }
  111. context.Copy(GetDest(op.Dest), src);
  112. }
  113. public static void SelR(EmitterContext context)
  114. {
  115. InstSelR op = context.GetOp<InstSelR>();
  116. Operand srcA = GetSrcReg(context, op.SrcA);
  117. Operand srcB = GetSrcReg(context, op.SrcB);
  118. Operand srcPred = GetPredicate(context, op.SrcPred, op.SrcPredInv);
  119. EmitSel(context, srcA, srcB, srcPred, op.Dest);
  120. }
  121. public static void SelI(EmitterContext context)
  122. {
  123. InstSelI op = context.GetOp<InstSelI>();
  124. Operand srcA = GetSrcReg(context, op.SrcA);
  125. Operand srcB = GetSrcImm(context, Imm20ToSInt(op.Imm20));
  126. Operand srcPred = GetPredicate(context, op.SrcPred, op.SrcPredInv);
  127. EmitSel(context, srcA, srcB, srcPred, op.Dest);
  128. }
  129. public static void SelC(EmitterContext context)
  130. {
  131. InstSelC op = context.GetOp<InstSelC>();
  132. Operand srcA = GetSrcReg(context, op.SrcA);
  133. Operand srcB = GetSrcCbuf(context, op.CbufSlot, op.CbufOffset);
  134. Operand srcPred = GetPredicate(context, op.SrcPred, op.SrcPredInv);
  135. EmitSel(context, srcA, srcB, srcPred, op.Dest);
  136. }
  137. private static void EmitR2p(EmitterContext context, Operand value, Operand mask, ByteSel byteSel, bool ccpr)
  138. {
  139. Operand Test(Operand value, int bit)
  140. {
  141. return context.ICompareNotEqual(context.BitwiseAnd(value, Const(1 << bit)), Const(0));
  142. }
  143. if (ccpr)
  144. {
  145. // TODO: Support Register to condition code flags copy.
  146. context.Config.GpuAccessor.Log("R2P.CC not implemented.");
  147. }
  148. else
  149. {
  150. int shift = (int)byteSel * 8;
  151. for (int bit = 0; bit < RegisterConsts.PredsCount; bit++)
  152. {
  153. Operand pred = Register(bit, RegisterType.Predicate);
  154. Operand res = context.ConditionalSelect(Test(mask, bit), Test(value, bit + shift), pred);
  155. context.Copy(pred, res);
  156. }
  157. }
  158. }
  159. private static void EmitSel(EmitterContext context, Operand srcA, Operand srcB, Operand srcPred, int rd)
  160. {
  161. Operand res = context.ConditionalSelect(srcPred, srcA, srcB);
  162. context.Copy(GetDest(rd), res);
  163. }
  164. }
  165. }