2019-10-13 02:02:07 -04:00
|
|
|
using Ryujinx.Graphics.Shader.Decoders;
|
|
|
|
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
|
|
|
using Ryujinx.Graphics.Shader.Translation;
|
|
|
|
|
|
|
|
using static Ryujinx.Graphics.Shader.Instructions.InstEmitHelper;
|
|
|
|
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Shader.Instructions
|
|
|
|
{
|
|
|
|
static partial class InstEmit
|
|
|
|
{
|
|
|
|
public static void Mov(EmitterContext context)
|
|
|
|
{
|
|
|
|
context.Copy(GetDest(context), GetSrcB(context));
|
|
|
|
}
|
|
|
|
|
2019-11-19 08:45:46 -05:00
|
|
|
public static void R2p(EmitterContext context)
|
|
|
|
{
|
|
|
|
OpCodeAlu op = (OpCodeAlu)context.CurrOp;
|
|
|
|
|
|
|
|
bool isCC = op.RawOpCode.Extract(40);
|
|
|
|
int shift = op.RawOpCode.Extract(41, 2) * 8;
|
|
|
|
|
|
|
|
Operand value = GetSrcA(context);
|
|
|
|
Operand mask = GetSrcB(context);
|
|
|
|
|
|
|
|
Operand Test(Operand value, int bit)
|
|
|
|
{
|
|
|
|
return context.ICompareNotEqual(context.BitwiseAnd(value, Const(1 << bit)), Const(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isCC)
|
|
|
|
{
|
2020-01-01 10:39:09 -05:00
|
|
|
// TODO: Support Register to condition code flags copy.
|
|
|
|
context.Config.PrintLog("R2P.CC not implemented.");
|
2019-11-19 08:45:46 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int bit = 0; bit < 7; bit++)
|
|
|
|
{
|
|
|
|
Operand pred = Register(bit, RegisterType.Predicate);
|
|
|
|
|
|
|
|
Operand res = context.ConditionalSelect(Test(mask, bit), Test(value, bit + shift), pred);
|
|
|
|
|
|
|
|
context.Copy(pred, res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
public static void S2r(EmitterContext context)
|
|
|
|
{
|
|
|
|
// TODO: Better impl.
|
|
|
|
OpCodeAlu op = (OpCodeAlu)context.CurrOp;
|
|
|
|
|
|
|
|
SystemRegister sysReg = (SystemRegister)op.RawOpCode.Extract(20, 8);
|
|
|
|
|
|
|
|
Operand src;
|
|
|
|
|
|
|
|
switch (sysReg)
|
|
|
|
{
|
2019-11-08 15:29:41 -05:00
|
|
|
case SystemRegister.LaneId: src = Attribute(AttributeConsts.LaneId); break;
|
|
|
|
|
2019-10-30 23:29:22 -04:00
|
|
|
// TODO: Use value from Y direction GPU register.
|
|
|
|
case SystemRegister.YDirection: src = ConstF(1); break;
|
|
|
|
|
2019-10-26 13:50:52 -04:00
|
|
|
case SystemRegister.ThreadId:
|
|
|
|
{
|
|
|
|
Operand tidX = Attribute(AttributeConsts.ThreadIdX);
|
|
|
|
Operand tidY = Attribute(AttributeConsts.ThreadIdY);
|
|
|
|
Operand tidZ = Attribute(AttributeConsts.ThreadIdZ);
|
|
|
|
|
|
|
|
tidY = context.ShiftLeft(tidY, Const(16));
|
|
|
|
tidZ = context.ShiftLeft(tidZ, Const(26));
|
|
|
|
|
|
|
|
src = context.BitwiseOr(tidX, context.BitwiseOr(tidY, tidZ));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
case SystemRegister.ThreadIdX: src = Attribute(AttributeConsts.ThreadIdX); break;
|
|
|
|
case SystemRegister.ThreadIdY: src = Attribute(AttributeConsts.ThreadIdY); break;
|
|
|
|
case SystemRegister.ThreadIdZ: src = Attribute(AttributeConsts.ThreadIdZ); break;
|
|
|
|
case SystemRegister.CtaIdX: src = Attribute(AttributeConsts.CtaIdX); break;
|
|
|
|
case SystemRegister.CtaIdY: src = Attribute(AttributeConsts.CtaIdY); break;
|
|
|
|
case SystemRegister.CtaIdZ: src = Attribute(AttributeConsts.CtaIdZ); break;
|
2019-11-08 15:29:41 -05:00
|
|
|
case SystemRegister.EqMask: src = Attribute(AttributeConsts.EqMask); break;
|
|
|
|
case SystemRegister.LtMask: src = Attribute(AttributeConsts.LtMask); break;
|
|
|
|
case SystemRegister.LeMask: src = Attribute(AttributeConsts.LeMask); break;
|
|
|
|
case SystemRegister.GtMask: src = Attribute(AttributeConsts.GtMask); break;
|
|
|
|
case SystemRegister.GeMask: src = Attribute(AttributeConsts.GeMask); break;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
default: src = Const(0); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.Copy(GetDest(context), src);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Sel(EmitterContext context)
|
|
|
|
{
|
|
|
|
Operand pred = GetPredicate39(context);
|
|
|
|
|
|
|
|
Operand srcA = GetSrcA(context);
|
|
|
|
Operand srcB = GetSrcB(context);
|
|
|
|
|
|
|
|
Operand res = context.ConditionalSelect(pred, srcA, srcB);
|
|
|
|
|
|
|
|
context.Copy(GetDest(context), res);
|
|
|
|
}
|
2019-10-30 23:29:22 -04:00
|
|
|
|
|
|
|
public static void Shfl(EmitterContext context)
|
|
|
|
{
|
|
|
|
OpCodeShuffle op = (OpCodeShuffle)context.CurrOp;
|
|
|
|
|
|
|
|
Operand pred = Register(op.Predicate48);
|
|
|
|
|
|
|
|
Operand srcA = GetSrcA(context);
|
|
|
|
|
|
|
|
Operand srcB = op.IsBImmediate ? Const(op.ImmediateB) : Register(op.Rb);
|
|
|
|
Operand srcC = op.IsCImmediate ? Const(op.ImmediateC) : Register(op.Rc);
|
|
|
|
|
|
|
|
Operand res = null;
|
|
|
|
|
|
|
|
switch (op.ShuffleType)
|
|
|
|
{
|
|
|
|
case ShuffleType.Indexed:
|
|
|
|
res = context.Shuffle(srcA, srcB, srcC);
|
|
|
|
break;
|
|
|
|
case ShuffleType.Up:
|
|
|
|
res = context.ShuffleUp(srcA, srcB, srcC);
|
|
|
|
break;
|
|
|
|
case ShuffleType.Down:
|
|
|
|
res = context.ShuffleDown(srcA, srcB, srcC);
|
|
|
|
break;
|
|
|
|
case ShuffleType.Butterfly:
|
|
|
|
res = context.ShuffleXor(srcA, srcB, srcC);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.Copy(GetDest(context), res);
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
}
|
|
|
|
}
|