2018-04-08 21:17:35 +02:00
|
|
|
namespace Ryujinx.Graphics.Gal.Shader
|
|
|
|
{
|
|
|
|
static class ShaderDecodeHelper
|
|
|
|
{
|
2018-10-14 04:54:14 +02:00
|
|
|
private static readonly ShaderIrOperImmf ImmfZero = new ShaderIrOperImmf(0);
|
|
|
|
private static readonly ShaderIrOperImmf ImmfOne = new ShaderIrOperImmf(1);
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderIrNode GetAluFabsFneg(ShaderIrNode node, bool abs, bool neg)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return GetAluFneg(GetAluFabs(node, abs), neg);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderIrNode GetAluFabs(ShaderIrNode node, bool abs)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return abs ? new ShaderIrOp(ShaderIrInst.Fabs, node) : node;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderIrNode GetAluFneg(ShaderIrNode node, bool neg)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return neg ? new ShaderIrOp(ShaderIrInst.Fneg, node) : node;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderIrNode GetAluFsat(ShaderIrNode node, bool sat)
|
2018-10-14 04:54:14 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return sat ? new ShaderIrOp(ShaderIrInst.Fclamp, node, ImmfZero, ImmfOne) : node;
|
2018-10-14 04:54:14 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderIrNode GetAluIabsIneg(ShaderIrNode node, bool abs, bool neg)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return GetAluIneg(GetAluIabs(node, abs), neg);
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderIrNode GetAluIabs(ShaderIrNode node, bool abs)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return abs ? new ShaderIrOp(ShaderIrInst.Abs, node) : node;
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderIrNode GetAluIneg(ShaderIrNode node, bool neg)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return neg ? new ShaderIrOp(ShaderIrInst.Neg, node) : node;
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderIrNode GetAluNot(ShaderIrNode node, bool not)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return not ? new ShaderIrOp(ShaderIrInst.Not, node) : node;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderIrNode ExtendTo32(ShaderIrNode node, bool signed, int size)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int shift = 32 - size;
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrInst rightShift = signed
|
2018-05-17 20:25:42 +02:00
|
|
|
? ShaderIrInst.Asr
|
|
|
|
: ShaderIrInst.Lsr;
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
node = new ShaderIrOp(ShaderIrInst.Lsl, node, new ShaderIrOperImm(shift));
|
|
|
|
node = new ShaderIrOp(rightShift, node, new ShaderIrOperImm(shift));
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return node;
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderIrNode ExtendTo32(ShaderIrNode node, bool signed, ShaderIrNode size)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrOperImm wordSize = new ShaderIrOperImm(32);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrOp shift = new ShaderIrOp(ShaderIrInst.Sub, wordSize, size);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrInst rightShift = signed
|
2018-05-17 20:25:42 +02:00
|
|
|
? ShaderIrInst.Asr
|
|
|
|
: ShaderIrInst.Lsr;
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
node = new ShaderIrOp(ShaderIrInst.Lsl, node, shift);
|
|
|
|
node = new ShaderIrOp(rightShift, node, shift);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return node;
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|