2018-04-08 21:17:35 +02:00
|
|
|
using System;
|
|
|
|
|
|
|
|
using static Ryujinx.Graphics.Gal.Shader.ShaderDecodeHelper;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.Shader
|
|
|
|
{
|
|
|
|
static partial class ShaderDecode
|
|
|
|
{
|
|
|
|
private enum IntType
|
|
|
|
{
|
|
|
|
U8 = 0,
|
|
|
|
U16 = 1,
|
|
|
|
U32 = 2,
|
|
|
|
U64 = 3,
|
|
|
|
S8 = 4,
|
|
|
|
S16 = 5,
|
|
|
|
S32 = 6,
|
|
|
|
S64 = 7
|
|
|
|
}
|
|
|
|
|
|
|
|
private enum FloatType
|
|
|
|
{
|
|
|
|
F16 = 1,
|
|
|
|
F32 = 2,
|
|
|
|
F64 = 3
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void F2f_C(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitF2F(block, opCode, ShaderOper.Cr);
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void F2f_I(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitF2F(block, opCode, ShaderOper.Immf);
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void F2f_R(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitF2F(block, opCode, ShaderOper.Rr);
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void F2i_C(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitF2I(block, opCode, ShaderOper.Cr);
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void F2i_I(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitF2I(block, opCode, ShaderOper.Immf);
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void F2i_R(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitF2I(block, opCode, ShaderOper.Rr);
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void I2f_C(ShaderIrBlock block, long opCode, int position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitI2F(block, opCode, ShaderOper.Cr);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void I2f_I(ShaderIrBlock block, long opCode, int position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitI2F(block, opCode, ShaderOper.Imm);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void I2f_R(ShaderIrBlock block, long opCode, int position)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitI2F(block, opCode, ShaderOper.Rr);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void I2i_C(ShaderIrBlock block, long opCode, int position)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitI2I(block, opCode, ShaderOper.Cr);
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void I2i_I(ShaderIrBlock block, long opCode, int position)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitI2I(block, opCode, ShaderOper.Imm);
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void I2i_R(ShaderIrBlock block, long opCode, int position)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitI2I(block, opCode, ShaderOper.Rr);
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void Isberd(ShaderIrBlock block, long opCode, int position)
|
2018-07-19 07:33:27 +02:00
|
|
|
{
|
|
|
|
//This instruction seems to be used to translate from an address to a vertex index in a GS
|
|
|
|
//Stub it as such
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(new ShaderIrCmnt("Stubbed."));
|
2018-07-19 07:33:27 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), opCode.Gpr8())));
|
2018-07-19 07:33:27 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void Mov_C(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrOperCbuf cbuf = opCode.Cbuf34();
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), cbuf)));
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void Mov_I(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrOperImm imm = opCode.Imm19_20();
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), imm)));
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void Mov_I32(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrOperImm imm = opCode.Imm32_20();
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), imm)));
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void Mov_R(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrOperGpr gpr = opCode.Gpr20();
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), gpr)));
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void Sel_C(ShaderIrBlock block, long opCode, int position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitSel(block, opCode, ShaderOper.Cr);
|
2018-07-17 21:50:00 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void Sel_I(ShaderIrBlock block, long opCode, int position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitSel(block, opCode, ShaderOper.Imm);
|
2018-07-17 21:50:00 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void Sel_R(ShaderIrBlock block, long opCode, int position)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
EmitSel(block, opCode, ShaderOper.Rr);
|
2018-07-17 21:50:00 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static void Mov_S(ShaderIrBlock block, long opCode, int position)
|
2018-07-19 07:33:27 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(new ShaderIrCmnt("Stubbed."));
|
2018-07-19 07:33:27 +02:00
|
|
|
|
|
|
|
//Zero is used as a special number to get a valid "0 * 0 + VertexIndex" in a GS
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrNode source = new ShaderIrOperImm(0);
|
2018-07-19 07:33:27 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), source)));
|
2018-07-19 07:33:27 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private static void EmitF2F(ShaderIrBlock block, long opCode, ShaderOper oper)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
bool negA = opCode.Read(45);
|
|
|
|
bool absA = opCode.Read(49);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrNode operA;
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (oper)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
case ShaderOper.Cr: operA = opCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Immf: operA = opCode.Immf19_20(); break;
|
|
|
|
case ShaderOper.Rr: operA = opCode.Gpr20(); break;
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
default: throw new ArgumentException(nameof(oper));
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = GetAluFabsFneg(operA, absA, negA);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrInst roundInst = GetRoundInst(opCode);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (roundInst != ShaderIrInst.Invalid)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = new ShaderIrOp(roundInst, operA);
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), operA)));
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private static void EmitF2I(ShaderIrBlock block, long opCode, ShaderOper oper)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
IntType type = GetIntType(opCode);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (type == IntType.U64 ||
|
|
|
|
type == IntType.S64)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
|
|
|
//TODO: 64-bits support.
|
|
|
|
//Note: GLSL doesn't support 64-bits integers.
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool negA = opCode.Read(45);
|
|
|
|
bool absA = opCode.Read(49);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrNode operA;
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (oper)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
case ShaderOper.Cr: operA = opCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Immf: operA = opCode.Immf19_20(); break;
|
|
|
|
case ShaderOper.Rr: operA = opCode.Gpr20(); break;
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
default: throw new ArgumentException(nameof(oper));
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = GetAluFabsFneg(operA, absA, negA);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrInst roundInst = GetRoundInst(opCode);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (roundInst != ShaderIrInst.Invalid)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = new ShaderIrOp(roundInst, operA);
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool signed = type >= IntType.S8;
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int size = 8 << ((int)type & 3);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (size < 32)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
uint mask = uint.MaxValue >> (32 - size);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
float cMin = 0;
|
|
|
|
float cMax = mask;
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (signed)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
uint halfMask = mask >> 1;
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
cMin -= halfMask + 1;
|
|
|
|
cMax = halfMask;
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrOperImmf min = new ShaderIrOperImmf(cMin);
|
|
|
|
ShaderIrOperImmf max = new ShaderIrOperImmf(cMax);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = new ShaderIrOp(ShaderIrInst.Fclamp, operA, min, max);
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrInst inst = signed
|
2018-04-10 21:50:32 +02:00
|
|
|
? ShaderIrInst.Ftos
|
|
|
|
: ShaderIrInst.Ftou;
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrNode op = new ShaderIrOp(inst, operA);
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), op)));
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private static void EmitI2F(ShaderIrBlock block, long opCode, ShaderOper oper)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
IntType type = GetIntType(opCode);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (type == IntType.U64 ||
|
|
|
|
type == IntType.S64)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
//TODO: 64-bits support.
|
|
|
|
//Note: GLSL doesn't support 64-bits integers.
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int sel = opCode.Read(41, 3);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool negA = opCode.Read(45);
|
|
|
|
bool absA = opCode.Read(49);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrNode operA;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (oper)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
case ShaderOper.Cr: operA = opCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: operA = opCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.Rr: operA = opCode.Gpr20(); break;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
default: throw new ArgumentException(nameof(oper));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = GetAluIabsIneg(operA, absA, negA);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool signed = type >= IntType.S8;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int shift = sel * 8;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int size = 8 << ((int)type & 3);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (shift != 0)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = new ShaderIrOp(ShaderIrInst.Asr, operA, new ShaderIrOperImm(shift));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (size < 32)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = ExtendTo32(operA, signed, size);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrInst inst = signed
|
2018-04-08 21:17:35 +02:00
|
|
|
? ShaderIrInst.Stof
|
|
|
|
: ShaderIrInst.Utof;
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrNode op = new ShaderIrOp(inst, operA);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), op)));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private static void EmitI2I(ShaderIrBlock block, long opCode, ShaderOper oper)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
IntType type = GetIntType(opCode);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (type == IntType.U64 ||
|
|
|
|
type == IntType.S64)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
|
|
|
//TODO: 64-bits support.
|
|
|
|
//Note: GLSL doesn't support 64-bits integers.
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int sel = opCode.Read(41, 3);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool negA = opCode.Read(45);
|
|
|
|
bool absA = opCode.Read(49);
|
|
|
|
bool satA = opCode.Read(50);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrNode operA;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (oper)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
case ShaderOper.Cr: operA = opCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Immf: operA = opCode.Immf19_20(); break;
|
|
|
|
case ShaderOper.Rr: operA = opCode.Gpr20(); break;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
default: throw new ArgumentException(nameof(oper));
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = GetAluIabsIneg(operA, absA, negA);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool signed = type >= IntType.S8;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int shift = sel * 8;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int size = 8 << ((int)type & 3);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (shift != 0)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = new ShaderIrOp(ShaderIrInst.Asr, operA, new ShaderIrOperImm(shift));
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (size < 32)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
uint mask = uint.MaxValue >> (32 - size);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (satA)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
uint cMin = 0;
|
|
|
|
uint cMax = mask;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (signed)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
uint halfMask = mask >> 1;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
cMin -= halfMask + 1;
|
|
|
|
cMax = halfMask;
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrOperImm min = new ShaderIrOperImm((int)cMin);
|
|
|
|
ShaderIrOperImm max = new ShaderIrOperImm((int)cMax);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = new ShaderIrOp(signed
|
2018-04-26 04:11:26 +02:00
|
|
|
? ShaderIrInst.Clamps
|
2019-03-04 02:45:25 +01:00
|
|
|
: ShaderIrInst.Clampu, operA, min, max);
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
operA = ExtendTo32(operA, signed, size);
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), operA)));
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private static void EmitSel(ShaderIrBlock block, long opCode, ShaderOper oper)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrOperGpr dst = opCode.Gpr0();
|
|
|
|
ShaderIrNode pred = opCode.Pred39N();
|
2018-07-17 21:50:00 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ShaderIrNode resultA = opCode.Gpr8();
|
|
|
|
ShaderIrNode resultB;
|
2018-07-17 21:50:00 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (oper)
|
2018-07-17 21:50:00 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
case ShaderOper.Cr: resultB = opCode.Cbuf34(); break;
|
|
|
|
case ShaderOper.Imm: resultB = opCode.Imm19_20(); break;
|
|
|
|
case ShaderOper.Rr: resultB = opCode.Gpr20(); break;
|
2018-07-17 21:50:00 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
default: throw new ArgumentException(nameof(oper));
|
2018-07-17 21:50:00 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrCond(pred, new ShaderIrAsg(dst, resultA), false)));
|
2018-07-17 21:50:00 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrCond(pred, new ShaderIrAsg(dst, resultB), true)));
|
2018-07-17 21:50:00 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private static IntType GetIntType(long opCode)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
bool signed = opCode.Read(13);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
IntType type = (IntType)(opCode.Read(10, 3));
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (signed)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
type += (int)IntType.S8;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return type;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private static FloatType GetFloatType(long opCode)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return (FloatType)(opCode.Read(8, 3));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
2018-04-10 21:50:32 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private static ShaderIrInst GetRoundInst(long opCode)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (opCode.Read(39, 3))
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
|
|
|
case 1: return ShaderIrInst.Floor;
|
|
|
|
case 2: return ShaderIrInst.Ceil;
|
|
|
|
case 3: return ShaderIrInst.Trunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ShaderIrInst.Invalid;
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|