aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/Instructions/InstEmitMove.cs
blob: 5833d87984c280f434e1ff673125eee322b3297b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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)
        {
            OpCodeAlu op = (OpCodeAlu)context.CurrOp;

            context.Copy(GetDest(context), GetSrcB(context));
        }

        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)
            {
                case SystemRegister.LaneId: src = Attribute(AttributeConsts.LaneId); break;

                // TODO: Use value from Y direction GPU register.
                case SystemRegister.YDirection: src = ConstF(1); break;

                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;
                }

                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;
                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;

                default: src = Const(0); break;
            }

            context.Copy(GetDest(context), src);
        }

        public static void Sel(EmitterContext context)
        {
            OpCodeAlu op = (OpCodeAlu)context.CurrOp;

            Operand pred = GetPredicate39(context);

            Operand srcA = GetSrcA(context);
            Operand srcB = GetSrcB(context);

            Operand res = context.ConditionalSelect(pred, srcA, srcB);

            context.Copy(GetDest(context), res);
        }

        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);
        }
    }
}