ShaderOpCodeTable.cs 3.9 KB

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