2018-04-08 20:17:35 +01:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.Shader
|
|
|
|
{
|
|
|
|
static class ShaderOpCodeTable
|
|
|
|
{
|
|
|
|
private const int EncodingBits = 14;
|
|
|
|
|
2018-04-26 03:11:26 +01:00
|
|
|
private class ShaderDecodeEntry
|
|
|
|
{
|
|
|
|
public ShaderDecodeFunc Func;
|
|
|
|
|
|
|
|
public int XBits;
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public ShaderDecodeEntry(ShaderDecodeFunc func, int xBits)
|
2018-04-26 03:11:26 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
Func = func;
|
|
|
|
XBits = xBits;
|
2018-04-26 03:11:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private static ShaderDecodeEntry[] _opCodes;
|
2018-04-08 20:17:35 +01:00
|
|
|
|
|
|
|
static ShaderOpCodeTable()
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_opCodes = new ShaderDecodeEntry[1 << EncodingBits];
|
2018-04-08 20:17:35 +01:00
|
|
|
|
|
|
|
#region Instructions
|
2018-05-17 19:25:42 +01:00
|
|
|
Set("0100110000000x", ShaderDecode.Bfe_C);
|
|
|
|
Set("0011100x00000x", ShaderDecode.Bfe_I);
|
|
|
|
Set("0101110000000x", ShaderDecode.Bfe_R);
|
|
|
|
Set("111000100100xx", ShaderDecode.Bra);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("111000110000xx", ShaderDecode.Exit);
|
2018-04-10 20:50:32 +01:00
|
|
|
Set("0100110010101x", ShaderDecode.F2f_C);
|
|
|
|
Set("0011100x10101x", ShaderDecode.F2f_I);
|
|
|
|
Set("0101110010101x", ShaderDecode.F2f_R);
|
|
|
|
Set("0100110010110x", ShaderDecode.F2i_C);
|
|
|
|
Set("0011100x10110x", ShaderDecode.F2i_I);
|
|
|
|
Set("0101110010110x", ShaderDecode.F2i_R);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("0100110001011x", ShaderDecode.Fadd_C);
|
|
|
|
Set("0011100x01011x", ShaderDecode.Fadd_I);
|
2018-06-28 03:55:08 +01:00
|
|
|
Set("000010xxxxxxxx", ShaderDecode.Fadd_I32);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("0101110001011x", ShaderDecode.Fadd_R);
|
|
|
|
Set("010010011xxxxx", ShaderDecode.Ffma_CR);
|
2018-06-28 03:55:08 +01:00
|
|
|
Set("0011001x1xxxxx", ShaderDecode.Ffma_I);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("010100011xxxxx", ShaderDecode.Ffma_RC);
|
|
|
|
Set("010110011xxxxx", ShaderDecode.Ffma_RR);
|
|
|
|
Set("0100110001101x", ShaderDecode.Fmul_C);
|
|
|
|
Set("0011100x01101x", ShaderDecode.Fmul_I);
|
2018-06-28 03:55:08 +01:00
|
|
|
Set("00011110xxxxxx", ShaderDecode.Fmul_I32);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("0101110001101x", ShaderDecode.Fmul_R);
|
2018-05-17 19:25:42 +01:00
|
|
|
Set("0100110001100x", ShaderDecode.Fmnmx_C);
|
|
|
|
Set("0011100x01100x", ShaderDecode.Fmnmx_I);
|
|
|
|
Set("0101110001100x", ShaderDecode.Fmnmx_R);
|
2018-04-26 03:11:26 +01:00
|
|
|
Set("0100100xxxxxxx", ShaderDecode.Fset_C);
|
|
|
|
Set("0011000xxxxxxx", ShaderDecode.Fset_I);
|
|
|
|
Set("01011000xxxxxx", ShaderDecode.Fset_R);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("010010111011xx", ShaderDecode.Fsetp_C);
|
|
|
|
Set("0011011x1011xx", ShaderDecode.Fsetp_I);
|
|
|
|
Set("010110111011xx", ShaderDecode.Fsetp_R);
|
2019-01-31 12:43:24 +00:00
|
|
|
Set("0101110100010x", ShaderDecode.Hadd2_R);
|
|
|
|
Set("0101110100001x", ShaderDecode.Hmul2_R);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("0100110010111x", ShaderDecode.I2f_C);
|
|
|
|
Set("0011100x10111x", ShaderDecode.I2f_I);
|
|
|
|
Set("0101110010111x", ShaderDecode.I2f_R);
|
2018-04-26 03:11:26 +01:00
|
|
|
Set("0100110011100x", ShaderDecode.I2i_C);
|
|
|
|
Set("0011100x11100x", ShaderDecode.I2i_I);
|
|
|
|
Set("0101110011100x", ShaderDecode.I2i_R);
|
2018-07-17 20:50:00 +01:00
|
|
|
Set("0100110000010x", ShaderDecode.Iadd_C);
|
|
|
|
Set("0011100000010x", ShaderDecode.Iadd_I);
|
|
|
|
Set("0001110x0xxxxx", ShaderDecode.Iadd_I32);
|
|
|
|
Set("0101110000010x", ShaderDecode.Iadd_R);
|
|
|
|
Set("010011001100xx", ShaderDecode.Iadd3_C);
|
|
|
|
Set("001110001100xx", ShaderDecode.Iadd3_I);
|
|
|
|
Set("010111001100xx", ShaderDecode.Iadd3_R);
|
2018-05-30 00:37:10 +01:00
|
|
|
Set("0100110000100x", ShaderDecode.Imnmx_C);
|
|
|
|
Set("0011100x00100x", ShaderDecode.Imnmx_I);
|
|
|
|
Set("0101110000100x", ShaderDecode.Imnmx_R);
|
2018-07-19 06:33:27 +01:00
|
|
|
Set("1110111111010x", ShaderDecode.Isberd);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("11100000xxxxxx", ShaderDecode.Ipa);
|
2018-05-17 19:25:42 +01:00
|
|
|
Set("0100110000011x", ShaderDecode.Iscadd_C);
|
|
|
|
Set("0011100x00011x", ShaderDecode.Iscadd_I);
|
|
|
|
Set("0101110000011x", ShaderDecode.Iscadd_R);
|
2018-07-17 20:50:00 +01:00
|
|
|
Set("010010110101xx", ShaderDecode.Iset_C);
|
|
|
|
Set("001101100101xx", ShaderDecode.Iset_I);
|
|
|
|
Set("010110110101xx", ShaderDecode.Iset_R);
|
2018-04-10 20:50:32 +01:00
|
|
|
Set("010010110110xx", ShaderDecode.Isetp_C);
|
|
|
|
Set("0011011x0110xx", ShaderDecode.Isetp_I);
|
|
|
|
Set("010110110110xx", ShaderDecode.Isetp_R);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("111000110011xx", ShaderDecode.Kil);
|
|
|
|
Set("1110111111011x", ShaderDecode.Ld_A);
|
2018-05-17 19:25:42 +01:00
|
|
|
Set("1110111110010x", ShaderDecode.Ld_C);
|
2018-07-17 20:50:00 +01:00
|
|
|
Set("0100110001000x", ShaderDecode.Lop_C);
|
|
|
|
Set("0011100001000x", ShaderDecode.Lop_I);
|
2018-05-17 19:25:42 +01:00
|
|
|
Set("000001xxxxxxxx", ShaderDecode.Lop_I32);
|
2018-07-17 20:50:00 +01:00
|
|
|
Set("0101110001000x", ShaderDecode.Lop_R);
|
2018-04-10 20:50:32 +01:00
|
|
|
Set("0100110010011x", ShaderDecode.Mov_C);
|
|
|
|
Set("0011100x10011x", ShaderDecode.Mov_I);
|
2018-05-17 19:25:42 +01:00
|
|
|
Set("000000010000xx", ShaderDecode.Mov_I32);
|
2018-04-10 20:50:32 +01:00
|
|
|
Set("0101110010011x", ShaderDecode.Mov_R);
|
2018-07-19 06:33:27 +01:00
|
|
|
Set("1111000011001x", ShaderDecode.Mov_S);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("0101000010000x", ShaderDecode.Mufu);
|
2018-07-19 06:33:27 +01:00
|
|
|
Set("1111101111100x", ShaderDecode.Out_R);
|
2018-06-02 04:50:56 +01:00
|
|
|
Set("0101000010010x", ShaderDecode.Psetp);
|
|
|
|
Set("0100110010010x", ShaderDecode.Rro_C);
|
|
|
|
Set("0011100x10010x", ShaderDecode.Rro_I);
|
|
|
|
Set("0101110010010x", ShaderDecode.Rro_R);
|
2018-07-17 20:50:00 +01:00
|
|
|
Set("0100110010100x", ShaderDecode.Sel_C);
|
|
|
|
Set("0011100010100x", ShaderDecode.Sel_I);
|
|
|
|
Set("0101110010100x", ShaderDecode.Sel_R);
|
2018-05-17 19:25:42 +01:00
|
|
|
Set("0100110001001x", ShaderDecode.Shl_C);
|
|
|
|
Set("0011100x01001x", ShaderDecode.Shl_I);
|
|
|
|
Set("0101110001001x", ShaderDecode.Shl_R);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("0100110000101x", ShaderDecode.Shr_C);
|
|
|
|
Set("0011100x00101x", ShaderDecode.Shr_I);
|
|
|
|
Set("0101110000101x", ShaderDecode.Shr_R);
|
2018-09-19 21:11:05 +01:00
|
|
|
Set("111000101001xx", ShaderDecode.Ssy);
|
2018-04-08 20:17:35 +01:00
|
|
|
Set("1110111111110x", ShaderDecode.St_A);
|
2018-08-31 17:14:04 +01:00
|
|
|
Set("1111000011111x", ShaderDecode.Sync);
|
2018-06-02 04:50:56 +01:00
|
|
|
Set("110000xxxx111x", ShaderDecode.Tex);
|
2018-08-13 22:22:09 +01:00
|
|
|
Set("1101111010111x", ShaderDecode.Tex_B);
|
2018-04-10 20:50:32 +01:00
|
|
|
Set("1101111101001x", ShaderDecode.Texq);
|
2019-01-31 12:43:24 +00:00
|
|
|
Set("1101x00xxxxxxx", ShaderDecode.Texs);
|
2018-04-10 20:50:32 +01:00
|
|
|
Set("1101101xxxxxxx", ShaderDecode.Tlds);
|
2019-02-28 01:12:24 +00:00
|
|
|
Set("110010xxxx111x", ShaderDecode.Tld4);
|
2019-03-04 01:45:25 +00:00
|
|
|
Set("1101111100xxxx", ShaderDecode.Tld4S);
|
2018-07-19 06:33:27 +01:00
|
|
|
Set("01011111xxxxxx", ShaderDecode.Vmad);
|
2018-05-30 00:37:10 +01:00
|
|
|
Set("0100111xxxxxxx", ShaderDecode.Xmad_CR);
|
|
|
|
Set("0011011x00xxxx", ShaderDecode.Xmad_I);
|
|
|
|
Set("010100010xxxxx", ShaderDecode.Xmad_RC);
|
|
|
|
Set("0101101100xxxx", ShaderDecode.Xmad_RR);
|
2018-04-08 20:17:35 +01:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private static void Set(string encoding, ShaderDecodeFunc func)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (encoding.Length != EncodingBits)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
throw new ArgumentException(nameof(encoding));
|
2018-04-08 20:17:35 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int bit = encoding.Length - 1;
|
|
|
|
int value = 0;
|
|
|
|
int xMask = 0;
|
|
|
|
int xBits = 0;
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int[] xPos = new int[encoding.Length];
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int index = 0; index < encoding.Length; index++, bit--)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
char chr = encoding[index];
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (chr == '1')
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
value |= 1 << bit;
|
2018-04-08 20:17:35 +01:00
|
|
|
}
|
2019-03-04 01:45:25 +00:00
|
|
|
else if (chr == 'x')
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
xMask |= 1 << bit;
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
xPos[xBits++] = bit;
|
2018-04-08 20:17:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
xMask = ~xMask;
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderDecodeEntry entry = new ShaderDecodeEntry(func, xBits);
|
2018-04-26 03:11:26 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int index = 0; index < (1 << xBits); index++)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
value &= xMask;
|
2018-04-08 20:17:35 +01:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int x = 0; x < xBits; x++)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
value |= ((index >> x) & 1) << xPos[x];
|
2018-04-08 20:17:35 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (_opCodes[value] == null || _opCodes[value].XBits > xBits)
|
2018-04-26 03:11:26 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_opCodes[value] = entry;
|
2018-04-26 03:11:26 +01:00
|
|
|
}
|
2018-04-08 20:17:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static ShaderDecodeFunc GetDecoder(long opCode)
|
2018-04-08 20:17:35 +01:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
return _opCodes[(ulong)opCode >> (64 - EncodingBits)]?.Func;
|
2018-04-08 20:17:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|