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