MacroHLETable.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Ryujinx.Common;
  2. using Ryujinx.Graphics.GAL;
  3. using System;
  4. using System.Runtime.InteropServices;
  5. namespace Ryujinx.Graphics.Gpu.Engine.MME
  6. {
  7. /// <summary>
  8. /// Table with information about High-level implementations of GPU Macro code.
  9. /// </summary>
  10. static class MacroHLETable
  11. {
  12. /// <summary>
  13. /// Macroo High-level implementation table entry.
  14. /// </summary>
  15. struct TableEntry
  16. {
  17. /// <summary>
  18. /// Name of the Macro function.
  19. /// </summary>
  20. public MacroHLEFunctionName Name { get; }
  21. /// <summary>
  22. /// Hash of the original binary Macro function code.
  23. /// </summary>
  24. public Hash128 Hash { get; }
  25. /// <summary>
  26. /// Size (in bytes) of the original binary Macro function code.
  27. /// </summary>
  28. public int Length { get; }
  29. /// <summary>
  30. /// Creates a new table entry.
  31. /// </summary>
  32. /// <param name="name">Name of the Macro function</param>
  33. /// <param name="hash">Hash of the original binary Macro function code</param>
  34. /// <param name="length">Size (in bytes) of the original binary Macro function code</param>
  35. public TableEntry(MacroHLEFunctionName name, Hash128 hash, int length)
  36. {
  37. Name = name;
  38. Hash = hash;
  39. Length = length;
  40. }
  41. }
  42. private static readonly TableEntry[] Table = new TableEntry[]
  43. {
  44. new TableEntry(MacroHLEFunctionName.MultiDrawElementsIndirectCount, new Hash128(0x890AF57ED3FB1C37, 0x35D0C95C61F5386F), 0x19C)
  45. };
  46. private static bool IsMacroHLESupported(Capabilities caps, MacroHLEFunctionName name)
  47. {
  48. if (name == MacroHLEFunctionName.MultiDrawElementsIndirectCount)
  49. {
  50. return caps.SupportsIndirectParameters;
  51. }
  52. return false;
  53. }
  54. /// <summary>
  55. /// Checks if there's a fast, High-level implementation of the specified Macro code available.
  56. /// </summary>
  57. /// <param name="code">Macro code to be checked</param>
  58. /// <param name="caps">Renderer capabilities to check for this macro HLE support</param>
  59. /// <param name="name">Name of the function if a implementation is available and supported, otherwise <see cref="MacroHLEFunctionName.None"/></param>
  60. /// <returns>True if there is a implementation available and supported, false otherwise</returns>
  61. public static bool TryGetMacroHLEFunction(ReadOnlySpan<int> code, Capabilities caps, out MacroHLEFunctionName name)
  62. {
  63. var mc = MemoryMarshal.Cast<int, byte>(code);
  64. for (int i = 0; i < Table.Length; i++)
  65. {
  66. ref var entry = ref Table[i];
  67. var hash = XXHash128.ComputeHash(mc.Slice(0, entry.Length));
  68. if (hash == entry.Hash)
  69. {
  70. name = entry.Name;
  71. return IsMacroHLESupported(caps, name);
  72. }
  73. }
  74. name = MacroHLEFunctionName.None;
  75. return false;
  76. }
  77. }
  78. }