2018-04-08 15:17:35 -04:00
|
|
|
namespace Ryujinx.Graphics.Gal.Shader
|
|
|
|
{
|
|
|
|
static class ShaderDecoder
|
|
|
|
{
|
2018-05-17 14:25:42 -04:00
|
|
|
private const bool AddDbgComments = true;
|
|
|
|
|
2018-04-13 14:12:58 -04:00
|
|
|
public static ShaderIrBlock DecodeBasicBlock(int[] Code, int Offset)
|
2018-04-08 15:17:35 -04:00
|
|
|
{
|
|
|
|
ShaderIrBlock Block = new ShaderIrBlock();
|
|
|
|
|
|
|
|
while (Offset + 2 <= Code.Length)
|
|
|
|
{
|
2018-05-17 14:25:42 -04:00
|
|
|
int InstPos = Offset * 4;
|
|
|
|
|
|
|
|
Block.Position = InstPos;
|
|
|
|
|
|
|
|
Block.MarkLabel(InstPos);
|
|
|
|
|
|
|
|
//Ignore scheduling instructions, which are written every 32 bytes.
|
2018-04-10 15:50:32 -04:00
|
|
|
if ((Offset & 7) == 0)
|
|
|
|
{
|
|
|
|
Offset += 2;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-04-08 15:17:35 -04:00
|
|
|
uint Word0 = (uint)Code[Offset++];
|
|
|
|
uint Word1 = (uint)Code[Offset++];
|
|
|
|
|
|
|
|
long OpCode = Word0 | (long)Word1 << 32;
|
|
|
|
|
|
|
|
ShaderDecodeFunc Decode = ShaderOpCodeTable.GetDecoder(OpCode);
|
|
|
|
|
2018-05-17 14:25:42 -04:00
|
|
|
if (AddDbgComments)
|
|
|
|
{
|
|
|
|
string DbgOpCode = $"0x{InstPos:x8}: 0x{OpCode:x16} ";
|
|
|
|
|
|
|
|
Block.AddNode(new ShaderIrCmnt(DbgOpCode + (Decode?.Method.Name ?? "???")));
|
|
|
|
}
|
|
|
|
|
2018-04-08 15:17:35 -04:00
|
|
|
if (Decode == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Decode(Block, OpCode);
|
|
|
|
|
2018-05-17 14:25:42 -04:00
|
|
|
if (Block.GetLastNode() is ShaderIrOp Op && Op.Inst == ShaderIrInst.Exit)
|
2018-04-08 15:17:35 -04:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Block;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool IsFlowChange(ShaderIrInst Inst)
|
|
|
|
{
|
|
|
|
return Inst == ShaderIrInst.Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|