ShaderOpCodeTable.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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("0100110010101x", ShaderDecode.F2f_C);
  14. Set("0011100x10101x", ShaderDecode.F2f_I);
  15. Set("0101110010101x", ShaderDecode.F2f_R);
  16. Set("0100110010110x", ShaderDecode.F2i_C);
  17. Set("0011100x10110x", ShaderDecode.F2i_I);
  18. Set("0101110010110x", ShaderDecode.F2i_R);
  19. Set("0100110001011x", ShaderDecode.Fadd_C);
  20. Set("0011100x01011x", ShaderDecode.Fadd_I);
  21. Set("0101110001011x", ShaderDecode.Fadd_R);
  22. Set("010010011xxxxx", ShaderDecode.Ffma_CR);
  23. Set("001100101xxxxx", ShaderDecode.Ffma_I);
  24. Set("010100011xxxxx", ShaderDecode.Ffma_RC);
  25. Set("010110011xxxxx", ShaderDecode.Ffma_RR);
  26. Set("0100110001101x", ShaderDecode.Fmul_C);
  27. Set("0011100x01101x", ShaderDecode.Fmul_I);
  28. Set("0101110001101x", ShaderDecode.Fmul_R);
  29. Set("010010111011xx", ShaderDecode.Fsetp_C);
  30. Set("0011011x1011xx", ShaderDecode.Fsetp_I);
  31. Set("010110111011xx", ShaderDecode.Fsetp_R);
  32. Set("0100110010111x", ShaderDecode.I2f_C);
  33. Set("0011100x10111x", ShaderDecode.I2f_I);
  34. Set("0101110010111x", ShaderDecode.I2f_R);
  35. Set("11100000xxxxxx", ShaderDecode.Ipa);
  36. Set("010010110110xx", ShaderDecode.Isetp_C);
  37. Set("0011011x0110xx", ShaderDecode.Isetp_I);
  38. Set("010110110110xx", ShaderDecode.Isetp_R);
  39. Set("111000110011xx", ShaderDecode.Kil);
  40. Set("1110111111011x", ShaderDecode.Ld_A);
  41. Set("000001xxxxxxxx", ShaderDecode.Lop32i);
  42. Set("0100110010011x", ShaderDecode.Mov_C);
  43. Set("0011100x10011x", ShaderDecode.Mov_I);
  44. Set("0101110010011x", ShaderDecode.Mov_R);
  45. Set("000000010000xx", ShaderDecode.Mov32i);
  46. Set("0101000010000x", ShaderDecode.Mufu);
  47. Set("0100110000101x", ShaderDecode.Shr_C);
  48. Set("0011100x00101x", ShaderDecode.Shr_I);
  49. Set("0101110000101x", ShaderDecode.Shr_R);
  50. Set("1110111111110x", ShaderDecode.St_A);
  51. Set("1101111101001x", ShaderDecode.Texq);
  52. Set("1101100xxxxxxx", ShaderDecode.Texs);
  53. Set("1101101xxxxxxx", ShaderDecode.Tlds);
  54. #endregion
  55. }
  56. private static void Set(string Encoding, ShaderDecodeFunc Func)
  57. {
  58. if (Encoding.Length != EncodingBits)
  59. {
  60. throw new ArgumentException(nameof(Encoding));
  61. }
  62. int Bit = Encoding.Length - 1;
  63. int Value = 0;
  64. int XMask = 0;
  65. int XBits = 0;
  66. int[] XPos = new int[Encoding.Length];
  67. for (int Index = 0; Index < Encoding.Length; Index++, Bit--)
  68. {
  69. char Chr = Encoding[Index];
  70. if (Chr == '1')
  71. {
  72. Value |= 1 << Bit;
  73. }
  74. else if (Chr == 'x')
  75. {
  76. XMask |= 1 << Bit;
  77. XPos[XBits++] = Bit;
  78. }
  79. }
  80. XMask = ~XMask;
  81. for (int Index = 0; Index < (1 << XBits); Index++)
  82. {
  83. Value &= XMask;
  84. for (int X = 0; X < XBits; X++)
  85. {
  86. Value |= ((Index >> X) & 1) << XPos[X];
  87. }
  88. OpCodes[Value] = Func;
  89. }
  90. }
  91. public static ShaderDecodeFunc GetDecoder(long OpCode)
  92. {
  93. return OpCodes[(ulong)OpCode >> (64 - EncodingBits)];
  94. }
  95. }
  96. }