2019-02-28 01:12:24 +00:00
|
|
|
using Ryujinx.Graphics.Texture;
|
2018-05-17 19:25:42 +01:00
|
|
|
using System;
|
|
|
|
|
2018-04-08 20:17:35 +01:00
|
|
|
using static Ryujinx.Graphics.Gal.Shader.ShaderDecodeHelper;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.Shader
|
|
|
|
{
|
|
|
|
static partial class ShaderDecode
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
// ReSharper disable InconsistentNaming
|
2018-07-04 00:06:13 +01:00
|
|
|
private const int ____ = 0x0;
|
|
|
|
private const int R___ = 0x1;
|
|
|
|
private const int _G__ = 0x2;
|
|
|
|
private const int RG__ = 0x3;
|
|
|
|
private const int __B_ = 0x4;
|
|
|
|
private const int RGB_ = 0x7;
|
|
|
|
private const int ___A = 0x8;
|
|
|
|
private const int R__A = 0x9;
|
|
|
|
private const int _G_A = 0xa;
|
|
|
|
private const int RG_A = 0xb;
|
|
|
|
private const int __BA = 0xc;
|
|
|
|
private const int R_BA = 0xd;
|
|
|
|
private const int _GBA = 0xe;
|
|
|
|
private const int RGBA = 0xf;
|
2019-03-04 01:45:25 +00:00
|
|
|
// ReSharper restore InconsistentNaming
|
2018-07-04 00:06:13 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private static int[,] _maskLut = new int[,]
|
2018-07-04 00:06:13 +01:00
|
|
|
{
|
|
|
|
{ ____, ____, ____, ____, ____, ____, ____, ____ },
|
|
|
|
{ R___, _G__, __B_, ___A, RG__, R__A, _G_A, __BA },
|
2018-08-13 23:46:36 +01:00
|
|
|
{ R___, _G__, __B_, ___A, RG__, ____, ____, ____ },
|
2018-07-04 00:06:13 +01:00
|
|
|
{ RGB_, RG_A, R_BA, _GBA, RGBA, ____, ____, ____ }
|
|
|
|
};
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private static GalTextureTarget TexToTextureTarget(int texType, bool isArray)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (texType)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
case 0:
|
2019-03-04 01:45:25 +00:00
|
|
|
return isArray ? GalTextureTarget.OneDArray : GalTextureTarget.OneD;
|
2019-02-28 01:12:24 +00:00
|
|
|
case 2:
|
2019-03-04 01:45:25 +00:00
|
|
|
return isArray ? GalTextureTarget.TwoDArray : GalTextureTarget.TwoD;
|
2019-02-28 01:12:24 +00:00
|
|
|
case 4:
|
2019-03-04 01:45:25 +00:00
|
|
|
if (isArray)
|
|
|
|
throw new InvalidOperationException("ARRAY bit set on a TEX with 3D texture!");
|
2019-02-28 01:12:24 +00:00
|
|
|
return GalTextureTarget.ThreeD;
|
|
|
|
case 6:
|
2019-03-04 01:45:25 +00:00
|
|
|
return isArray ? GalTextureTarget.CubeArray : GalTextureTarget.CubeMap;
|
2019-02-28 01:12:24 +00:00
|
|
|
default:
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private static GalTextureTarget TexsToTextureTarget(int texType)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (texType)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return GalTextureTarget.OneD;
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
case 6:
|
|
|
|
case 8:
|
|
|
|
case 0xa:
|
|
|
|
case 0xc:
|
|
|
|
return GalTextureTarget.TwoD;
|
|
|
|
case 0xe:
|
|
|
|
case 0x10:
|
|
|
|
case 0x12:
|
|
|
|
return GalTextureTarget.TwoDArray;
|
|
|
|
case 0x14:
|
|
|
|
case 0x16:
|
|
|
|
return GalTextureTarget.ThreeD;
|
|
|
|
case 0x18:
|
|
|
|
case 0x1a:
|
|
|
|
return GalTextureTarget.CubeMap;
|
|
|
|
default:
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static GalTextureTarget TldsToTextureTarget(int texType)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (texType)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
return GalTextureTarget.OneD;
|
|
|
|
case 4:
|
|
|
|
case 8:
|
|
|
|
case 0xa:
|
|
|
|
case 0xc:
|
|
|
|
case 0x18:
|
|
|
|
return GalTextureTarget.TwoD;
|
|
|
|
case 0x10:
|
|
|
|
return GalTextureTarget.TwoDArray;
|
|
|
|
case 0xe:
|
|
|
|
return GalTextureTarget.ThreeD;
|
|
|
|
default:
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static void Ld_A(ShaderIrBlock block, long opCode, int position)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrNode[] opers = opCode.Abuf20();
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2018-07-19 06:33:27 +01:00
|
|
|
//Used by GS
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr vertex = opCode.Gpr39();
|
2018-07-19 06:33:27 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int index = 0;
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
foreach (ShaderIrNode operA in opers)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr operD = opCode.Gpr0();
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
operD.Index += index++;
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(operD, operA)));
|
2018-04-08 20:17:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static void Ld_C(ShaderIrBlock block, long opCode, int position)
|
2018-05-17 19:25:42 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
int cbufPos = opCode.Read(22, 0x3fff);
|
|
|
|
int cbufIndex = opCode.Read(36, 0x1f);
|
|
|
|
int type = opCode.Read(48, 7);
|
2018-05-17 19:25:42 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (type > 5)
|
2018-05-17 19:25:42 +01:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr temp = ShaderIrOperGpr.MakeTemporary();
|
2018-08-21 03:31:10 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
block.AddNode(new ShaderIrAsg(temp, opCode.Gpr8()));
|
2018-08-21 03:31:10 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int count = type == 5 ? 2 : 1;
|
2018-05-17 19:25:42 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int index = 0; index < count; index++)
|
2018-05-17 19:25:42 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperCbuf operA = new ShaderIrOperCbuf(cbufIndex, cbufPos, temp);
|
2018-08-21 03:31:10 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr operD = opCode.Gpr0();
|
2018-05-17 19:25:42 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
operA.Pos += index;
|
|
|
|
operD.Index += index;
|
2018-05-17 19:25:42 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!operD.IsValidRegister)
|
2018-08-21 03:31:10 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrNode node = operA;
|
2018-05-17 19:25:42 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (type < 4)
|
2018-05-17 19:25:42 +01:00
|
|
|
{
|
|
|
|
//This is a 8 or 16 bits type.
|
2019-03-04 01:45:25 +00:00
|
|
|
bool signed = (type & 1) != 0;
|
2018-05-17 19:25:42 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int size = 8 << (type >> 1);
|
2018-05-17 19:25:42 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
node = ExtendTo32(node, signed, size);
|
2018-05-17 19:25:42 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(operD, node)));
|
2018-05-17 19:25:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static void St_A(ShaderIrBlock block, long opCode, int position)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrNode[] opers = opCode.Abuf20();
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int index = 0;
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
foreach (ShaderIrNode operA in opers)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr operD = opCode.Gpr0();
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
operD.Index += index++;
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(operA, operD)));
|
2018-04-08 20:17:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static void Texq(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 20:50:32 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrNode operD = opCode.Gpr0();
|
|
|
|
ShaderIrNode operA = opCode.Gpr8();
|
2018-04-10 20:50:32 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderTexqInfo info = (ShaderTexqInfo)(opCode.Read(22, 0x1f));
|
2018-04-10 20:50:32 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrMetaTexq meta0 = new ShaderIrMetaTexq(info, 0);
|
|
|
|
ShaderIrMetaTexq meta1 = new ShaderIrMetaTexq(info, 1);
|
2018-04-10 20:50:32 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrNode operC = opCode.Imm13_36();
|
2018-04-10 20:50:32 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOp op0 = new ShaderIrOp(ShaderIrInst.Texq, operA, null, operC, meta0);
|
|
|
|
ShaderIrOp op1 = new ShaderIrOp(ShaderIrInst.Texq, operA, null, operC, meta1);
|
2018-04-10 20:50:32 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(operD, op0)));
|
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(operA, op1))); //Is this right?
|
2018-04-10 20:50:32 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static void Tex(ShaderIrBlock block, long opCode, int position)
|
2018-08-13 22:22:09 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
TextureInstructionSuffix suffix;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int rawSuffix = opCode.Read(0x34, 0x38);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (rawSuffix)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
case 0:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.None;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x8:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lz;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x10:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lb;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x18:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Ll;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x30:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lba;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x38:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lla;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-03-04 01:45:25 +00:00
|
|
|
throw new InvalidOperationException($"Invalid Suffix for TEX instruction {rawSuffix}");
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
bool isOffset = opCode.Read(0x36);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (isOffset)
|
|
|
|
suffix |= TextureInstructionSuffix.AOffI;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
EmitTex(block, opCode, suffix, gprHandle: false);
|
2018-08-13 22:22:09 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static void Tex_B(ShaderIrBlock block, long opCode, int position)
|
2018-08-13 22:22:09 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
TextureInstructionSuffix suffix;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int rawSuffix = opCode.Read(0x24, 0xe);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (rawSuffix)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
case 0:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.None;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x2:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lz;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x4:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lb;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x6:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Ll;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0xc:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lba;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0xe:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lla;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-03-04 01:45:25 +00:00
|
|
|
throw new InvalidOperationException($"Invalid Suffix for TEX.B instruction {rawSuffix}");
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
bool isOffset = opCode.Read(0x23);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (isOffset)
|
|
|
|
suffix |= TextureInstructionSuffix.AOffI;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
EmitTex(block, opCode, suffix, gprHandle: true);
|
2018-08-13 22:22:09 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private static void EmitTex(ShaderIrBlock block, long opCode, TextureInstructionSuffix textureInstructionSuffix, bool gprHandle)
|
2018-06-02 04:50:56 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
bool isArray = opCode.HasArray();
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
GalTextureTarget textureTarget = TexToTextureTarget(opCode.Read(28, 6), isArray);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
bool hasDepthCompare = opCode.Read(0x32);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (hasDepthCompare)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
textureInstructionSuffix |= TextureInstructionSuffix.Dc;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr[] coords = new ShaderIrOperGpr[ImageUtils.GetCoordsCountTextureTarget(textureTarget)];
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int indexExtraCoord = 0;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (isArray)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
indexExtraCoord++;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[coords.Length - 1] = opCode.Gpr8();
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int index = 0; index < coords.Length - indexExtraCoord; index++)
|
2018-06-02 04:50:56 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr coordReg = opCode.Gpr8();
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coordReg.Index += index;
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coordReg.Index += indexExtraCoord;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!coordReg.IsValidRegister)
|
2018-06-02 04:50:56 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
coordReg.Index = ShaderIrOperGpr.ZrIndex;
|
2018-06-02 04:50:56 +01:00
|
|
|
}
|
2019-01-31 12:43:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[index] = coordReg;
|
2018-06-02 04:50:56 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int chMask = opCode.Read(31, 0xf);
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr levelOfDetail = null;
|
|
|
|
ShaderIrOperGpr offset = null;
|
|
|
|
ShaderIrOperGpr depthCompare = null;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
|
|
|
// TODO: determine first argument when TEX.B is used
|
2019-03-04 01:45:25 +00:00
|
|
|
int operBIndex = gprHandle ? 1 : 0;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if ((textureInstructionSuffix & TextureInstructionSuffix.Ll) != 0 ||
|
|
|
|
(textureInstructionSuffix & TextureInstructionSuffix.Lb) != 0 ||
|
|
|
|
(textureInstructionSuffix & TextureInstructionSuffix.Lba) != 0 ||
|
|
|
|
(textureInstructionSuffix & TextureInstructionSuffix.Lla) != 0)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
levelOfDetail = opCode.Gpr20();
|
|
|
|
levelOfDetail.Index += operBIndex;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
operBIndex++;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if ((textureInstructionSuffix & TextureInstructionSuffix.AOffI) != 0)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
offset = opCode.Gpr20();
|
|
|
|
offset.Index += operBIndex;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
operBIndex++;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if ((textureInstructionSuffix & TextureInstructionSuffix.Dc) != 0)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
depthCompare = opCode.Gpr20();
|
|
|
|
depthCompare.Index += operBIndex;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
operBIndex++;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ???
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrNode operC = gprHandle
|
|
|
|
? (ShaderIrNode)opCode.Gpr20()
|
|
|
|
: (ShaderIrNode)opCode.Imm13_36();
|
2018-08-13 22:22:09 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrInst inst = gprHandle ? ShaderIrInst.Texb : ShaderIrInst.Texs;
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coords = CoordsRegistersToTempRegisters(block, coords);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int regInc = 0;
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int ch = 0; ch < 4; ch++)
|
2018-06-02 04:50:56 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!IsChannelUsed(chMask, ch))
|
2018-06-02 04:50:56 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr dst = opCode.Gpr0();
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
dst.Index += regInc++;
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!dst.IsValidRegister || dst.IsConst)
|
2018-06-02 04:50:56 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrMetaTex meta = new ShaderIrMetaTex(ch, textureTarget, textureInstructionSuffix, coords)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
LevelOfDetail = levelOfDetail,
|
|
|
|
Offset = offset,
|
|
|
|
DepthCompare = depthCompare
|
2019-02-28 01:12:24 +00:00
|
|
|
};
|
2019-01-31 12:43:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOp op = new ShaderIrOp(inst, coords[0], coords.Length > 1 ? coords[1] : null, operC, meta);
|
2019-01-31 12:43:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(dst, op)));
|
2018-06-02 04:50:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static void Texs(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 20:50:32 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
TextureInstructionSuffix suffix;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int rawSuffix = opCode.Read(0x34, 0x1e);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (rawSuffix)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 0x4:
|
|
|
|
case 0x10:
|
|
|
|
case 0x16:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lz;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x6:
|
|
|
|
case 0x1a:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Ll;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x8:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Dc;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x2:
|
|
|
|
case 0xe:
|
|
|
|
case 0x14:
|
|
|
|
case 0x18:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.None;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0xa:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Ll | TextureInstructionSuffix.Dc;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0xc:
|
|
|
|
case 0x12:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lz | TextureInstructionSuffix.Dc;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-03-04 01:45:25 +00:00
|
|
|
throw new InvalidOperationException($"Invalid Suffix for TEXS instruction {rawSuffix}");
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
GalTextureTarget textureTarget = TexsToTextureTarget(opCode.Read(52, 0x1e));
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
EmitTexs(block, opCode, ShaderIrInst.Texs, textureTarget, suffix);
|
2018-04-10 20:50:32 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static void Tlds(ShaderIrBlock block, long opCode, int position)
|
2018-04-10 20:50:32 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
TextureInstructionSuffix suffix;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int rawSuffix = opCode.Read(0x34, 0x1e);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (rawSuffix)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 0x4:
|
|
|
|
case 0x8:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lz | TextureInstructionSuffix.AOffI;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0xc:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lz | TextureInstructionSuffix.Mz;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0xe:
|
|
|
|
case 0x10:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Lz;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x2:
|
|
|
|
case 0xa:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Ll;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x18:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Ll | TextureInstructionSuffix.AOffI;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-03-04 01:45:25 +00:00
|
|
|
throw new InvalidOperationException($"Invalid Suffix for TLDS instruction {rawSuffix}");
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
GalTextureTarget textureTarget = TldsToTextureTarget(opCode.Read(52, 0x1e));
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
EmitTexs(block, opCode, ShaderIrInst.Txlf, textureTarget, suffix);
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static void Tld4(ShaderIrBlock block, long opCode, int position)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
TextureInstructionSuffix suffix;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int rawSuffix = opCode.Read(0x34, 0xc);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (rawSuffix)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
case 0:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.None;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x4:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.AOffI;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
case 0x8:
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix = TextureInstructionSuffix.Ptp;
|
2019-02-28 01:12:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-03-04 01:45:25 +00:00
|
|
|
throw new InvalidOperationException($"Invalid Suffix for TLD4 instruction {rawSuffix}");
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
bool isShadow = opCode.Read(0x32);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
bool isArray = opCode.HasArray();
|
|
|
|
int chMask = opCode.Read(31, 0xf);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
GalTextureTarget textureTarget = TexToTextureTarget(opCode.Read(28, 6), isArray);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (isShadow)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix |= TextureInstructionSuffix.Dc;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
EmitTld4(block, opCode, textureTarget, suffix, chMask, opCode.Read(0x38, 0x3), false);
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static void Tld4S(ShaderIrBlock block, long opCode, int position)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
TextureInstructionSuffix suffix = TextureInstructionSuffix.None;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
bool isOffset = opCode.Read(0x33);
|
|
|
|
bool isShadow = opCode.Read(0x32);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (isOffset)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix |= TextureInstructionSuffix.AOffI;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (isShadow)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
suffix |= TextureInstructionSuffix.Dc;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TLD4S seems to only support 2D textures with RGBA mask?
|
2019-03-04 01:45:25 +00:00
|
|
|
EmitTld4(block, opCode, GalTextureTarget.TwoD, suffix, RGBA, opCode.Read(0x34, 0x3), true);
|
2018-04-10 20:50:32 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private static void EmitTexs(ShaderIrBlock block,
|
|
|
|
long opCode,
|
|
|
|
ShaderIrInst inst,
|
|
|
|
GalTextureTarget textureTarget,
|
|
|
|
TextureInstructionSuffix textureInstructionSuffix)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (inst == ShaderIrInst.Txlf && textureTarget == GalTextureTarget.CubeArray)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException("TLDS instructions cannot use CUBE modifier!");
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
bool isArray = ImageUtils.IsArray(textureTarget);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr[] coords = new ShaderIrOperGpr[ImageUtils.GetCoordsCountTextureTarget(textureTarget)];
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr operA = opCode.Gpr8();
|
|
|
|
ShaderIrOperGpr operB = opCode.Gpr20();
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr suffixExtra = opCode.Gpr20();
|
|
|
|
suffixExtra.Index += 1;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int coordStartIndex = 0;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (isArray)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
coordStartIndex++;
|
|
|
|
coords[coords.Length - 1] = opCode.Gpr8();
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (coords.Length - coordStartIndex)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
case 1:
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[0] = opCode.Gpr8();
|
2019-02-28 01:12:24 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[0] = opCode.Gpr8();
|
|
|
|
coords[0].Index += coordStartIndex;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case 3:
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[0] = opCode.Gpr8();
|
|
|
|
coords[0].Index += coordStartIndex;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[1] = opCode.Gpr8();
|
|
|
|
coords[1].Index += 1 + coordStartIndex;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
2019-03-04 01:45:25 +00:00
|
|
|
throw new NotSupportedException($"{coords.Length - coordStartIndex} coords textures aren't supported in TEXS");
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int operBIndex = 0;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr levelOfDetail = null;
|
|
|
|
ShaderIrOperGpr offset = null;
|
|
|
|
ShaderIrOperGpr depthCompare = null;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
|
|
|
// OperB is always the last value
|
|
|
|
// Not applicable to 1d textures
|
2019-03-04 01:45:25 +00:00
|
|
|
if (coords.Length - coordStartIndex != 1)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[coords.Length - coordStartIndex - 1] = operB;
|
|
|
|
operBIndex++;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encoding of TEXS/TLDS is a bit special and change for 2d textures
|
|
|
|
// NOTE: OperA seems to hold at best two args.
|
|
|
|
// On 2D textures, if no suffix need an additional values, Y is stored in OperB, otherwise coords are in OperA and the additional values is in OperB.
|
2019-03-04 01:45:25 +00:00
|
|
|
if (textureInstructionSuffix != TextureInstructionSuffix.None && textureInstructionSuffix != TextureInstructionSuffix.Lz && textureTarget == GalTextureTarget.TwoD)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[coords.Length - coordStartIndex - 1] = opCode.Gpr8();
|
|
|
|
coords[coords.Length - coordStartIndex - 1].Index += coords.Length - coordStartIndex - 1;
|
|
|
|
operBIndex--;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Find what MZ does and what changes about the encoding (Maybe Multisample?)
|
2019-03-04 01:45:25 +00:00
|
|
|
if ((textureInstructionSuffix & TextureInstructionSuffix.Ll) != 0)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
levelOfDetail = opCode.Gpr20();
|
|
|
|
levelOfDetail.Index += operBIndex;
|
|
|
|
operBIndex++;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if ((textureInstructionSuffix & TextureInstructionSuffix.AOffI) != 0)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
offset = opCode.Gpr20();
|
|
|
|
offset.Index += operBIndex;
|
|
|
|
operBIndex++;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if ((textureInstructionSuffix & TextureInstructionSuffix.Dc) != 0)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
depthCompare = opCode.Gpr20();
|
|
|
|
depthCompare.Index += operBIndex;
|
|
|
|
operBIndex++;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int lutIndex;
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
lutIndex = !opCode.Gpr0().IsConst ? 1 : 0;
|
|
|
|
lutIndex |= !opCode.Gpr28().IsConst ? 2 : 0;
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (lutIndex == 0)
|
2018-08-13 23:46:36 +01:00
|
|
|
{
|
2019-01-31 12:43:24 +00:00
|
|
|
//Both destination registers are RZ, do nothing.
|
2018-08-13 23:46:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
bool fp16 = !opCode.Read(59);
|
2018-04-13 19:12:58 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int dstIncrement = 0;
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2018-08-13 23:46:36 +01:00
|
|
|
ShaderIrOperGpr GetDst()
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr dst;
|
2018-08-13 23:46:36 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (fp16)
|
2018-08-13 23:46:36 +01:00
|
|
|
{
|
2019-01-31 12:43:24 +00:00
|
|
|
//FP16 mode, two components are packed on the two
|
|
|
|
//halfs of a 32-bits register, as two half-float values.
|
2019-03-04 01:45:25 +00:00
|
|
|
int halfPart = dstIncrement & 1;
|
2019-01-31 12:43:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (lutIndex)
|
2019-01-31 12:43:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
case 1: dst = opCode.GprHalf0(halfPart); break;
|
|
|
|
case 2: dst = opCode.GprHalf28(halfPart); break;
|
|
|
|
case 3: dst = (dstIncrement >> 1) != 0
|
|
|
|
? opCode.GprHalf28(halfPart)
|
|
|
|
: opCode.GprHalf0(halfPart); break;
|
2019-01-31 12:43:24 +00:00
|
|
|
|
|
|
|
default: throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//32-bits mode, each component uses one register.
|
|
|
|
//Two components uses two consecutive registers.
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (lutIndex)
|
2019-01-31 12:43:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
case 1: dst = opCode.Gpr0(); break;
|
|
|
|
case 2: dst = opCode.Gpr28(); break;
|
|
|
|
case 3: dst = (dstIncrement >> 1) != 0
|
|
|
|
? opCode.Gpr28()
|
|
|
|
: opCode.Gpr0(); break;
|
2019-01-31 12:43:24 +00:00
|
|
|
|
|
|
|
default: throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
dst.Index += dstIncrement & 1;
|
2018-08-13 23:46:36 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
dstIncrement++;
|
2018-08-13 23:46:36 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
return dst;
|
2018-08-13 23:46:36 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int chMask = _maskLut[lutIndex, opCode.Read(50, 7)];
|
2019-01-31 12:43:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (chMask == 0)
|
2019-01-31 12:43:24 +00:00
|
|
|
{
|
|
|
|
//All channels are disabled, do nothing.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrNode operC = opCode.Imm13_36();
|
|
|
|
coords = CoordsRegistersToTempRegisters(block, coords);
|
2019-01-31 12:43:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int ch = 0; ch < 4; ch++)
|
2018-04-13 19:12:58 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!IsChannelUsed(chMask, ch))
|
2018-06-02 04:50:56 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrMetaTex meta = new ShaderIrMetaTex(ch, textureTarget, textureInstructionSuffix, coords)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
LevelOfDetail = levelOfDetail,
|
|
|
|
Offset = offset,
|
|
|
|
DepthCompare = depthCompare
|
2019-02-28 01:12:24 +00:00
|
|
|
};
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOp op = new ShaderIrOp(inst, operA, operB, operC, meta);
|
2018-04-13 19:12:58 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr dst = GetDst();
|
2018-04-13 19:12:58 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (dst.IsValidRegister && !dst.IsConst)
|
2018-04-30 18:32:54 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(dst, op)));
|
2018-04-30 18:32:54 +01:00
|
|
|
}
|
2018-04-13 19:12:58 +01:00
|
|
|
}
|
2018-04-08 20:17:35 +01:00
|
|
|
}
|
2018-06-02 04:50:56 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private static void EmitTld4(ShaderIrBlock block, long opCode, GalTextureTarget textureType, TextureInstructionSuffix textureInstructionSuffix, int chMask, int component, bool scalar)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr operA = opCode.Gpr8();
|
|
|
|
ShaderIrOperGpr operB = opCode.Gpr20();
|
|
|
|
ShaderIrOperImm operC = opCode.Imm13_36();
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr[] coords = new ShaderIrOperGpr[ImageUtils.GetCoordsCountTextureTarget(textureType)];
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr offset = null;
|
|
|
|
ShaderIrOperGpr depthCompare = null;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
bool isArray = ImageUtils.IsArray(textureType);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int operBIndex = 0;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (scalar)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
int coordStartIndex = 0;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (isArray)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
coordStartIndex++;
|
|
|
|
coords[coords.Length - 1] = operB;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (coords.Length - coordStartIndex)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
case 1:
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[0] = opCode.Gpr8();
|
2019-02-28 01:12:24 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[0] = opCode.Gpr8();
|
|
|
|
coords[0].Index += coordStartIndex;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case 3:
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[0] = opCode.Gpr8();
|
|
|
|
coords[0].Index += coordStartIndex;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[1] = opCode.Gpr8();
|
|
|
|
coords[1].Index += 1 + coordStartIndex;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
2019-03-04 01:45:25 +00:00
|
|
|
throw new NotSupportedException($"{coords.Length - coordStartIndex} coords textures aren't supported in TLD4S");
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (coords.Length - coordStartIndex != 1)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[coords.Length - coordStartIndex - 1] = operB;
|
|
|
|
operBIndex++;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (textureInstructionSuffix != TextureInstructionSuffix.None && textureType == GalTextureTarget.TwoD)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[coords.Length - coordStartIndex - 1] = opCode.Gpr8();
|
|
|
|
coords[coords.Length - coordStartIndex - 1].Index += coords.Length - coordStartIndex - 1;
|
|
|
|
operBIndex--;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
int indexExtraCoord = 0;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (isArray)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
indexExtraCoord++;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[coords.Length - 1] = opCode.Gpr8();
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int index = 0; index < coords.Length - indexExtraCoord; index++)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[index] = opCode.Gpr8();
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[index].Index += index;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[index].Index += indexExtraCoord;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (coords[index].Index > ShaderIrOperGpr.ZrIndex)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
coords[index].Index = ShaderIrOperGpr.ZrIndex;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if ((textureInstructionSuffix & TextureInstructionSuffix.AOffI) != 0)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
offset = opCode.Gpr20();
|
|
|
|
offset.Index += operBIndex;
|
|
|
|
operBIndex++;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if ((textureInstructionSuffix & TextureInstructionSuffix.Dc) != 0)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
depthCompare = opCode.Gpr20();
|
|
|
|
depthCompare.Index += operBIndex;
|
|
|
|
operBIndex++;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
coords = CoordsRegistersToTempRegisters(block, coords);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int regInc = 0;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int ch = 0; ch < 4; ch++)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!IsChannelUsed(chMask, ch))
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr dst = opCode.Gpr0();
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
dst.Index += regInc++;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!dst.IsValidRegister || dst.IsConst)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrMetaTex meta = new ShaderIrMetaTex(ch, textureType, textureInstructionSuffix, coords)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
Component = component,
|
|
|
|
Offset = offset,
|
|
|
|
DepthCompare = depthCompare
|
2019-02-28 01:12:24 +00:00
|
|
|
};
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOp op = new ShaderIrOp(ShaderIrInst.Tld4, operA, operB, operC, meta);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
block.AddNode(opCode.PredNode(new ShaderIrAsg(dst, op)));
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private static bool IsChannelUsed(int chMask, int ch)
|
2018-06-02 04:50:56 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
return (chMask & (1 << ch)) != 0;
|
2018-06-02 04:50:56 +01:00
|
|
|
}
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private static ShaderIrOperGpr[] CoordsRegistersToTempRegisters(ShaderIrBlock block, params ShaderIrOperGpr[] registers)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrOperGpr[] res = new ShaderIrOperGpr[registers.Length];
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int index = 0; index < res.Length; index++)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
res[index] = ShaderIrOperGpr.MakeTemporary(index);
|
|
|
|
block.AddNode(new ShaderIrAsg(res[index], registers[index]));
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
return res;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
2018-04-08 20:17:35 +01:00
|
|
|
}
|
|
|
|
}
|