ShaderDecoder.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. namespace Ryujinx.Graphics.Gal.Shader
  2. {
  3. static class ShaderDecoder
  4. {
  5. public static ShaderIrBlock DecodeBasicBlock(int[] Code, int Offset)
  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. return Block;
  32. }
  33. private static bool IsFlowChange(ShaderIrInst Inst)
  34. {
  35. return Inst == ShaderIrInst.Exit;
  36. }
  37. }
  38. }