2019-10-13 08:02:07 +02: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
|
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
public static void MovR(EmitterContext context)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
InstMovR op = context.GetOp<InstMovR>();
|
|
|
|
|
|
|
|
context.Copy(GetDest(op.Dest), GetSrcReg(context, op.SrcA));
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
public static void MovI(EmitterContext context)
|
2019-11-19 14:45:46 +01:00
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
InstMovI op = context.GetOp<InstMovI>();
|
2019-11-19 14:45:46 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
context.Copy(GetDest(op.Dest), GetSrcImm(context, op.Imm20));
|
|
|
|
}
|
2019-11-19 14:45:46 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
public static void MovC(EmitterContext context)
|
|
|
|
{
|
|
|
|
InstMovC op = context.GetOp<InstMovC>();
|
2019-11-19 14:45:46 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
context.Copy(GetDest(op.Dest), GetSrcCbuf(context, op.CbufSlot, op.CbufOffset));
|
|
|
|
}
|
2019-11-19 14:45:46 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
public static void Mov32i(EmitterContext context)
|
|
|
|
{
|
|
|
|
InstMov32i op = context.GetOp<InstMov32i>();
|
2019-11-19 14:45:46 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
context.Copy(GetDest(op.Dest), GetSrcImm(context, op.Imm32));
|
|
|
|
}
|
2019-11-19 14:45:46 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
public static void R2pR(EmitterContext context)
|
|
|
|
{
|
|
|
|
InstR2pR op = context.GetOp<InstR2pR>();
|
|
|
|
|
|
|
|
Operand value = GetSrcReg(context, op.SrcA);
|
|
|
|
Operand mask = GetSrcReg(context, op.SrcB);
|
|
|
|
|
|
|
|
EmitR2p(context, value, mask, op.ByteSel, op.Ccpr);
|
2019-11-19 14:45:46 +01:00
|
|
|
}
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
public static void R2pI(EmitterContext context)
|
|
|
|
{
|
|
|
|
InstR2pI op = context.GetOp<InstR2pI>();
|
|
|
|
|
|
|
|
Operand value = GetSrcReg(context, op.SrcA);
|
|
|
|
Operand mask = GetSrcImm(context, Imm20ToSInt(op.Imm20));
|
|
|
|
|
|
|
|
EmitR2p(context, value, mask, op.ByteSel, op.Ccpr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void R2pC(EmitterContext context)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
InstR2pC op = context.GetOp<InstR2pC>();
|
|
|
|
|
|
|
|
Operand value = GetSrcReg(context, op.SrcA);
|
|
|
|
Operand mask = GetSrcCbuf(context, op.CbufSlot, op.CbufOffset);
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
EmitR2p(context, value, mask, op.ByteSel, op.Ccpr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void S2r(EmitterContext context)
|
|
|
|
{
|
|
|
|
InstS2r op = context.GetOp<InstS2r>();
|
2019-10-13 08:02:07 +02:00
|
|
|
|
|
|
|
Operand src;
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
switch (op.SReg)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
case SReg.LaneId:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.SubgroupLaneId);
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
2019-11-08 21:29:41 +01:00
|
|
|
|
2021-10-18 23:38:04 +02:00
|
|
|
case SReg.InvocationId:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.InvocationId);
|
2021-10-18 23:38:04 +02:00
|
|
|
break;
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
case SReg.YDirection:
|
|
|
|
src = ConstF(1); // TODO: Use value from Y direction GPU register.
|
|
|
|
break;
|
2019-10-31 04:29:22 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
case SReg.ThreadKill:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Config.Stage == ShaderStage.Fragment ? context.Load(StorageKind.Input, IoVariable.ThreadKill) : Const(0);
|
2021-04-02 12:50:35 +02:00
|
|
|
break;
|
|
|
|
|
2021-10-18 23:38:04 +02:00
|
|
|
case SReg.InvocationInfo:
|
|
|
|
if (context.Config.Stage != ShaderStage.Compute && context.Config.Stage != ShaderStage.Fragment)
|
|
|
|
{
|
2022-04-08 12:42:39 +02:00
|
|
|
// Note: Lowest 8-bits seems to contain some primitive index,
|
|
|
|
// but it seems to be NVIDIA implementation specific as it's only used
|
|
|
|
// to calculate ISBE offsets, so we can just keep it as zero.
|
2021-11-08 15:39:30 +01:00
|
|
|
|
2022-04-08 12:42:39 +02:00
|
|
|
if (context.Config.Stage == ShaderStage.TessellationControl ||
|
|
|
|
context.Config.Stage == ShaderStage.TessellationEvaluation)
|
2021-11-08 15:39:30 +01:00
|
|
|
{
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.ShiftLeft(context.Load(StorageKind.Input, IoVariable.PatchVertices), Const(16));
|
2021-11-08 15:39:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-08 12:42:39 +02:00
|
|
|
src = Const(context.Config.GpuAccessor.QueryPrimitiveTopology().ToInputVertices() << 16);
|
2021-11-08 15:39:30 +01:00
|
|
|
}
|
2021-10-18 23:38:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src = Const(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
case SReg.TId:
|
2023-04-26 00:51:07 +02:00
|
|
|
Operand tidX = context.Load(StorageKind.Input, IoVariable.ThreadId, null, Const(0));
|
|
|
|
Operand tidY = context.Load(StorageKind.Input, IoVariable.ThreadId, null, Const(1));
|
|
|
|
Operand tidZ = context.Load(StorageKind.Input, IoVariable.ThreadId, null, Const(2));
|
2019-10-26 19:50:52 +02:00
|
|
|
|
|
|
|
tidY = context.ShiftLeft(tidY, Const(16));
|
|
|
|
tidZ = context.ShiftLeft(tidZ, Const(26));
|
|
|
|
|
|
|
|
src = context.BitwiseOr(tidX, context.BitwiseOr(tidY, tidZ));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
2019-10-26 19:50:52 +02:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
case SReg.TIdX:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.ThreadId, null, Const(0));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
|
|
|
case SReg.TIdY:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.ThreadId, null, Const(1));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
|
|
|
case SReg.TIdZ:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.ThreadId, null, Const(2));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SReg.CtaIdX:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.CtaId, null, Const(0));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
|
|
|
case SReg.CtaIdY:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.CtaId, null, Const(1));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
|
|
|
case SReg.CtaIdZ:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.CtaId, null, Const(2));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SReg.EqMask:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.SubgroupEqMask, null, Const(0));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
|
|
|
case SReg.LtMask:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.SubgroupLtMask, null, Const(0));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
|
|
|
case SReg.LeMask:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.SubgroupLeMask, null, Const(0));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
|
|
|
case SReg.GtMask:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.SubgroupGtMask, null, Const(0));
|
2021-10-12 22:35:31 +02:00
|
|
|
break;
|
|
|
|
case SReg.GeMask:
|
2023-04-26 00:51:07 +02:00
|
|
|
src = context.Load(StorageKind.Input, IoVariable.SubgroupGeMask, null, Const(0));
|
2019-10-26 19:50:52 +02:00
|
|
|
break;
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
default:
|
|
|
|
src = Const(0);
|
|
|
|
break;
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
context.Copy(GetDest(op.Dest), src);
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
public static void SelR(EmitterContext context)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
InstSelR op = context.GetOp<InstSelR>();
|
|
|
|
|
|
|
|
Operand srcA = GetSrcReg(context, op.SrcA);
|
|
|
|
Operand srcB = GetSrcReg(context, op.SrcB);
|
|
|
|
Operand srcPred = GetPredicate(context, op.SrcPred, op.SrcPredInv);
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
EmitSel(context, srcA, srcB, srcPred, op.Dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void SelI(EmitterContext context)
|
|
|
|
{
|
|
|
|
InstSelI op = context.GetOp<InstSelI>();
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
Operand srcA = GetSrcReg(context, op.SrcA);
|
|
|
|
Operand srcB = GetSrcImm(context, Imm20ToSInt(op.Imm20));
|
|
|
|
Operand srcPred = GetPredicate(context, op.SrcPred, op.SrcPredInv);
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
EmitSel(context, srcA, srcB, srcPred, op.Dest);
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
2019-10-31 04:29:22 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
public static void SelC(EmitterContext context)
|
2019-10-31 04:29:22 +01:00
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
InstSelC op = context.GetOp<InstSelC>();
|
2019-10-31 04:29:22 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
Operand srcA = GetSrcReg(context, op.SrcA);
|
|
|
|
Operand srcB = GetSrcCbuf(context, op.CbufSlot, op.CbufOffset);
|
|
|
|
Operand srcPred = GetPredicate(context, op.SrcPred, op.SrcPredInv);
|
2019-10-31 04:29:22 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
EmitSel(context, srcA, srcB, srcPred, op.Dest);
|
|
|
|
}
|
2019-10-31 04:29:22 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
private static void EmitR2p(EmitterContext context, Operand value, Operand mask, ByteSel byteSel, bool ccpr)
|
|
|
|
{
|
|
|
|
Operand Test(Operand value, int bit)
|
|
|
|
{
|
|
|
|
return context.ICompareNotEqual(context.BitwiseAnd(value, Const(1 << bit)), Const(0));
|
|
|
|
}
|
2019-10-31 04:29:22 +01:00
|
|
|
|
2021-10-12 22:35:31 +02:00
|
|
|
if (ccpr)
|
|
|
|
{
|
|
|
|
// TODO: Support Register to condition code flags copy.
|
|
|
|
context.Config.GpuAccessor.Log("R2P.CC not implemented.");
|
|
|
|
}
|
|
|
|
else
|
2019-10-31 04:29:22 +01:00
|
|
|
{
|
2021-10-12 22:35:31 +02:00
|
|
|
int shift = (int)byteSel * 8;
|
|
|
|
|
|
|
|
for (int bit = 0; bit < RegisterConsts.PredsCount; bit++)
|
|
|
|
{
|
|
|
|
Operand pred = Register(bit, RegisterType.Predicate);
|
|
|
|
Operand res = context.ConditionalSelect(Test(mask, bit), Test(value, bit + shift), pred);
|
|
|
|
context.Copy(pred, res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void EmitSel(EmitterContext context, Operand srcA, Operand srcB, Operand srcPred, int rd)
|
|
|
|
{
|
|
|
|
Operand res = context.ConditionalSelect(srcPred, srcA, srcB);
|
|
|
|
|
|
|
|
context.Copy(GetDest(rd), res);
|
2019-10-31 04:29:22 +01:00
|
|
|
}
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
}
|