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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
using System;
namespace Ryujinx.Graphics.Gal.Shader
{
static partial class ShaderDecode
{
private static int Read(this long OpCode, int Position, int Mask)
{
return (int)(OpCode >> Position) & Mask;
}
private static bool Read(this long OpCode, int Position)
{
return ((OpCode >> Position) & 1) != 0;
}
private static int Branch(this long OpCode)
{
return ((int)(OpCode >> 20) << 8) >> 8;
}
private static ShaderIrOperAbuf[] Abuf20(this long OpCode)
{
int Abuf = OpCode.Read(20, 0x3ff);
int Size = OpCode.Read(47, 3);
ShaderIrOperGpr Vertex = OpCode.Gpr39();
ShaderIrOperAbuf[] Opers = new ShaderIrOperAbuf[Size + 1];
for (int Index = 0; Index <= Size; Index++)
{
Opers[Index] = new ShaderIrOperAbuf(Abuf + Index * 4, Vertex);
}
return Opers;
}
private static ShaderIrOperAbuf Abuf28(this long OpCode)
{
int Abuf = OpCode.Read(28, 0x3ff);
return new ShaderIrOperAbuf(Abuf, OpCode.Gpr39());
}
private static ShaderIrOperCbuf Cbuf34(this long OpCode)
{
return new ShaderIrOperCbuf(
OpCode.Read(34, 0x1f),
OpCode.Read(20, 0x3fff));
}
private static ShaderIrOperGpr Gpr8(this long OpCode)
{
return new ShaderIrOperGpr(OpCode.Read(8, 0xff));
}
private static ShaderIrOperGpr Gpr20(this long OpCode)
{
return new ShaderIrOperGpr(OpCode.Read(20, 0xff));
}
private static ShaderIrOperGpr Gpr39(this long OpCode)
{
return new ShaderIrOperGpr(OpCode.Read(39, 0xff));
}
private static ShaderIrOperGpr Gpr0(this long OpCode)
{
return new ShaderIrOperGpr(OpCode.Read(0, 0xff));
}
private static ShaderIrOperGpr Gpr28(this long OpCode)
{
return new ShaderIrOperGpr(OpCode.Read(28, 0xff));
}
private static ShaderIrOperImm Imm5_39(this long OpCode)
{
return new ShaderIrOperImm(OpCode.Read(39, 0x1f));
}
private static ShaderIrOperImm Imm13_36(this long OpCode)
{
return new ShaderIrOperImm(OpCode.Read(36, 0x1fff));
}
private static ShaderIrOperImm Imm32_20(this long OpCode)
{
return new ShaderIrOperImm((int)(OpCode >> 20));
}
private static ShaderIrOperImmf Immf32_20(this long OpCode)
{
return new ShaderIrOperImmf(BitConverter.Int32BitsToSingle((int)(OpCode >> 20)));
}
private static ShaderIrOperImm Imm19_20(this long OpCode)
{
int Value = OpCode.Read(20, 0x7ffff);
bool Neg = OpCode.Read(56);
if (Neg)
{
Value = -Value;
}
return new ShaderIrOperImm(Value);
}
private static ShaderIrOperImmf Immf19_20(this long OpCode)
{
uint Imm = (uint)(OpCode >> 20) & 0x7ffff;
bool Neg = OpCode.Read(56);
Imm <<= 12;
if (Neg)
{
Imm |= 0x80000000;
}
float Value = BitConverter.Int32BitsToSingle((int)Imm);
return new ShaderIrOperImmf(Value);
}
private static ShaderIrOperPred Pred0(this long OpCode)
{
return new ShaderIrOperPred(OpCode.Read(0, 7));
}
private static ShaderIrOperPred Pred3(this long OpCode)
{
return new ShaderIrOperPred(OpCode.Read(3, 7));
}
private static ShaderIrOperPred Pred12(this long OpCode)
{
return new ShaderIrOperPred(OpCode.Read(12, 7));
}
private static ShaderIrOperPred Pred29(this long OpCode)
{
return new ShaderIrOperPred(OpCode.Read(29, 7));
}
private static ShaderIrNode Pred39N(this long OpCode)
{
ShaderIrNode Node = OpCode.Pred39();
if (OpCode.Read(42))
{
Node = new ShaderIrOp(ShaderIrInst.Bnot, Node);
}
return Node;
}
private static ShaderIrOperPred Pred39(this long OpCode)
{
return new ShaderIrOperPred(OpCode.Read(39, 7));
}
private static ShaderIrOperPred Pred48(this long OpCode)
{
return new ShaderIrOperPred(OpCode.Read(48, 7));
}
private static ShaderIrInst Cmp(this long OpCode)
{
switch (OpCode.Read(49, 7))
{
case 1: return ShaderIrInst.Clt;
case 2: return ShaderIrInst.Ceq;
case 3: return ShaderIrInst.Cle;
case 4: return ShaderIrInst.Cgt;
case 5: return ShaderIrInst.Cne;
case 6: return ShaderIrInst.Cge;
}
throw new ArgumentException(nameof(OpCode));
}
private static ShaderIrInst CmpF(this long OpCode)
{
switch (OpCode.Read(48, 0xf))
{
case 0x1: return ShaderIrInst.Fclt;
case 0x2: return ShaderIrInst.Fceq;
case 0x3: return ShaderIrInst.Fcle;
case 0x4: return ShaderIrInst.Fcgt;
case 0x5: return ShaderIrInst.Fcne;
case 0x6: return ShaderIrInst.Fcge;
case 0x7: return ShaderIrInst.Fcnum;
case 0x8: return ShaderIrInst.Fcnan;
case 0x9: return ShaderIrInst.Fcltu;
case 0xa: return ShaderIrInst.Fcequ;
case 0xb: return ShaderIrInst.Fcleu;
case 0xc: return ShaderIrInst.Fcgtu;
case 0xd: return ShaderIrInst.Fcneu;
case 0xe: return ShaderIrInst.Fcgeu;
}
throw new ArgumentException(nameof(OpCode));
}
private static ShaderIrInst BLop45(this long OpCode)
{
switch (OpCode.Read(45, 3))
{
case 0: return ShaderIrInst.Band;
case 1: return ShaderIrInst.Bor;
case 2: return ShaderIrInst.Bxor;
}
throw new ArgumentException(nameof(OpCode));
}
private static ShaderIrInst BLop24(this long OpCode)
{
switch (OpCode.Read(24, 3))
{
case 0: return ShaderIrInst.Band;
case 1: return ShaderIrInst.Bor;
case 2: return ShaderIrInst.Bxor;
}
throw new ArgumentException(nameof(OpCode));
}
private static ShaderIrNode PredNode(this long OpCode, ShaderIrNode Node)
{
ShaderIrOperPred Pred = OpCode.PredNode();
if (Pred.Index != ShaderIrOperPred.UnusedIndex)
{
bool Inv = OpCode.Read(19);
Node = new ShaderIrCond(Pred, Node, Inv);
}
return Node;
}
private static ShaderIrOperPred PredNode(this long OpCode)
{
int Pred = OpCode.Read(16, 0xf);
if (Pred != 0xf)
{
Pred &= 7;
}
return new ShaderIrOperPred(Pred);
}
}
}
|