ShaderDecoder.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. uint Word0 = (uint)Code[Offset++];
  11. uint Word1 = (uint)Code[Offset++];
  12. long OpCode = Word0 | (long)Word1 << 32;
  13. ShaderDecodeFunc Decode = ShaderOpCodeTable.GetDecoder(OpCode);
  14. if (Decode == null)
  15. {
  16. continue;
  17. }
  18. Decode(Block, OpCode);
  19. if (Block.GetLastNode() is ShaderIrOp Op && IsFlowChange(Op.Inst))
  20. {
  21. break;
  22. }
  23. }
  24. Block.RunOptimizationPasses(ShaderType);
  25. return Block;
  26. }
  27. private static bool IsFlowChange(ShaderIrInst Inst)
  28. {
  29. return Inst == ShaderIrInst.Exit;
  30. }
  31. }
  32. }