2018-04-08 21:17:35 +02:00
|
|
|
namespace Ryujinx.Graphics.Gal.Shader
|
|
|
|
{
|
|
|
|
static class ShaderDecoder
|
|
|
|
{
|
2018-04-13 20:12:58 +02:00
|
|
|
public static ShaderIrBlock DecodeBasicBlock(int[] Code, int Offset)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
ShaderIrBlock Block = new ShaderIrBlock();
|
|
|
|
|
|
|
|
while (Offset + 2 <= Code.Length)
|
|
|
|
{
|
2018-04-10 21:50:32 +02:00
|
|
|
//Ignore scheduling instructions, which are
|
|
|
|
//written every 32 bytes.
|
|
|
|
if ((Offset & 7) == 0)
|
|
|
|
{
|
|
|
|
Offset += 2;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
uint Word0 = (uint)Code[Offset++];
|
|
|
|
uint Word1 = (uint)Code[Offset++];
|
|
|
|
|
|
|
|
long OpCode = Word0 | (long)Word1 << 32;
|
|
|
|
|
|
|
|
ShaderDecodeFunc Decode = ShaderOpCodeTable.GetDecoder(OpCode);
|
|
|
|
|
|
|
|
if (Decode == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Decode(Block, OpCode);
|
|
|
|
|
|
|
|
if (Block.GetLastNode() is ShaderIrOp Op && IsFlowChange(Op.Inst))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Block;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool IsFlowChange(ShaderIrInst Inst)
|
|
|
|
{
|
|
|
|
return Inst == ShaderIrInst.Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|