ShaderOpCodeTable.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. namespace Ryujinx.Graphics.Gal.Shader
  3. {
  4. static class ShaderOpCodeTable
  5. {
  6. private const int EncodingBits = 14;
  7. private static ShaderDecodeFunc[] OpCodes;
  8. static ShaderOpCodeTable()
  9. {
  10. OpCodes = new ShaderDecodeFunc[1 << EncodingBits];
  11. #region Instructions
  12. Set("111000110000xx", ShaderDecode.Exit);
  13. Set("0100110001011x", ShaderDecode.Fadd_C);
  14. Set("0011100x01011x", ShaderDecode.Fadd_I);
  15. Set("0101110001011x", ShaderDecode.Fadd_R);
  16. Set("010010011xxxxx", ShaderDecode.Ffma_CR);
  17. Set("001100101xxxxx", ShaderDecode.Ffma_I);
  18. Set("010100011xxxxx", ShaderDecode.Ffma_RC);
  19. Set("010110011xxxxx", ShaderDecode.Ffma_RR);
  20. Set("0100110001101x", ShaderDecode.Fmul_C);
  21. Set("0011100x01101x", ShaderDecode.Fmul_I);
  22. Set("0101110001101x", ShaderDecode.Fmul_R);
  23. Set("010010111011xx", ShaderDecode.Fsetp_C);
  24. Set("0011011x1011xx", ShaderDecode.Fsetp_I);
  25. Set("010110111011xx", ShaderDecode.Fsetp_R);
  26. Set("0100110010111x", ShaderDecode.I2f_C);
  27. Set("0011100x10111x", ShaderDecode.I2f_I);
  28. Set("0101110010111x", ShaderDecode.I2f_R);
  29. Set("11100000xxxxxx", ShaderDecode.Ipa);
  30. Set("111000110011xx", ShaderDecode.Kil);
  31. Set("1110111111011x", ShaderDecode.Ld_A);
  32. Set("000001xxxxxxxx", ShaderDecode.Lop32i);
  33. Set("000000010000xx", ShaderDecode.Mov32i);
  34. Set("0101000010000x", ShaderDecode.Mufu);
  35. Set("0100110000101x", ShaderDecode.Shr_C);
  36. Set("0011100x00101x", ShaderDecode.Shr_I);
  37. Set("0101110000101x", ShaderDecode.Shr_R);
  38. Set("1110111111110x", ShaderDecode.St_A);
  39. Set("1101100xxxxxxx", ShaderDecode.Texs);
  40. #endregion
  41. }
  42. private static void Set(string Encoding, ShaderDecodeFunc Func)
  43. {
  44. if (Encoding.Length != EncodingBits)
  45. {
  46. throw new ArgumentException(nameof(Encoding));
  47. }
  48. int Bit = Encoding.Length - 1;
  49. int Value = 0;
  50. int XMask = 0;
  51. int XBits = 0;
  52. int[] XPos = new int[Encoding.Length];
  53. for (int Index = 0; Index < Encoding.Length; Index++, Bit--)
  54. {
  55. char Chr = Encoding[Index];
  56. if (Chr == '1')
  57. {
  58. Value |= 1 << Bit;
  59. }
  60. else if (Chr == 'x')
  61. {
  62. XMask |= 1 << Bit;
  63. XPos[XBits++] = Bit;
  64. }
  65. }
  66. XMask = ~XMask;
  67. for (int Index = 0; Index < (1 << XBits); Index++)
  68. {
  69. Value &= XMask;
  70. for (int X = 0; X < XBits; X++)
  71. {
  72. Value |= ((Index >> X) & 1) << XPos[X];
  73. }
  74. OpCodes[Value] = Func;
  75. }
  76. }
  77. public static ShaderDecodeFunc GetDecoder(long OpCode)
  78. {
  79. return OpCodes[(ulong)OpCode >> (64 - EncodingBits)];
  80. }
  81. }
  82. }