ShaderDecoder.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. namespace Ryujinx.Graphics.Gal.Shader
  2. {
  3. static class ShaderDecoder
  4. {
  5. public static ShaderIrBlock DecodeBasicBlock(int[] Code, int Offset, GalShaderType ShaderType)
  6. {
  7. ShaderIrBlock Block = new ShaderIrBlock();
  8. while (Offset + 2 <= Code.Length)
  9. {
  10. //Ignore scheduling instructions, which are
  11. //written every 32 bytes.
  12. if ((Offset & 7) == 0)
  13. {
  14. Offset += 2;
  15. continue;
  16. }
  17. uint Word0 = (uint)Code[Offset++];
  18. uint Word1 = (uint)Code[Offset++];
  19. long OpCode = Word0 | (long)Word1 << 32;
  20. ShaderDecodeFunc Decode = ShaderOpCodeTable.GetDecoder(OpCode);
  21. if (Decode == null)
  22. {
  23. continue;
  24. }
  25. Decode(Block, OpCode);
  26. if (Block.GetLastNode() is ShaderIrOp Op && IsFlowChange(Op.Inst))
  27. {
  28. break;
  29. }
  30. }
  31. Block.RunOptimizationPasses(ShaderType);
  32. return Block;
  33. }
  34. private static bool IsFlowChange(ShaderIrInst Inst)
  35. {
  36. return Inst == ShaderIrInst.Exit;
  37. }
  38. }
  39. }