PerformanceManager.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Ryujinx.Audio.Renderer.Common;
  2. using Ryujinx.Audio.Renderer.Parameter;
  3. using System;
  4. namespace Ryujinx.Audio.Renderer.Server.Performance
  5. {
  6. public abstract class PerformanceManager
  7. {
  8. /// <summary>
  9. /// Get the required size for a single performance frame.
  10. /// </summary>
  11. /// <param name="parameter">The audio renderer configuration.</param>
  12. /// <param name="behaviourContext">The behaviour context.</param>
  13. /// <returns>The required size for a single performance frame.</returns>
  14. public static ulong GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref AudioRendererConfiguration parameter, ref BehaviourContext behaviourContext)
  15. {
  16. uint version = behaviourContext.GetPerformanceMetricsDataFormat();
  17. if (version == 2)
  18. {
  19. return (ulong)PerformanceManagerGeneric<PerformanceFrameHeaderVersion2,
  20. PerformanceEntryVersion2,
  21. PerformanceDetailVersion2>.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter);
  22. }
  23. else if (version == 1)
  24. {
  25. return (ulong)PerformanceManagerGeneric<PerformanceFrameHeaderVersion1,
  26. PerformanceEntryVersion1,
  27. PerformanceDetailVersion1>.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter);
  28. }
  29. throw new NotImplementedException($"Unknown Performance metrics data format version {version}");
  30. }
  31. /// <summary>
  32. /// Copy the performance frame history to the supplied user buffer and returns the size copied.
  33. /// </summary>
  34. /// <param name="performanceOutput">The supplied user buffer to store the performance frame into.</param>
  35. /// <returns>The size copied to the supplied buffer.</returns>
  36. public abstract uint CopyHistories(Span<byte> performanceOutput);
  37. /// <summary>
  38. /// Set the target node id to profile.
  39. /// </summary>
  40. /// <param name="target">The target node id to profile.</param>
  41. public abstract void SetTargetNodeId(int target);
  42. /// <summary>
  43. /// Check if the given target node id is profiled.
  44. /// </summary>
  45. /// <param name="target">The target node id to check.</param>
  46. /// <returns>Return true, if the given target node id is profiled.</returns>
  47. public abstract bool IsTargetNodeId(int target);
  48. /// <summary>
  49. /// Get the next buffer to store a performance entry.
  50. /// </summary>
  51. /// <param name="performanceEntry">The output <see cref="PerformanceEntryAddresses"/>.</param>
  52. /// <param name="entryType">The <see cref="PerformanceEntryType"/> info.</param>
  53. /// <param name="nodeId">The node id of the entry.</param>
  54. /// <returns>Return true, if a valid <see cref="PerformanceEntryAddresses"/> was returned.</returns>
  55. public abstract bool GetNextEntry(out PerformanceEntryAddresses performanceEntry, PerformanceEntryType entryType, int nodeId);
  56. /// <summary>
  57. /// Get the next buffer to store a performance detailed entry.
  58. /// </summary>
  59. /// <param name="performanceEntry">The output <see cref="PerformanceEntryAddresses"/>.</param>
  60. /// <param name="detailType">The <see cref="PerformanceDetailType"/> info.</param>
  61. /// <param name="entryType">The <see cref="PerformanceEntryType"/> info.</param>
  62. /// <param name="nodeId">The node id of the entry.</param>
  63. /// <returns>Return true, if a valid <see cref="PerformanceEntryAddresses"/> was returned.</returns>
  64. public abstract bool GetNextEntry(out PerformanceEntryAddresses performanceEntry, PerformanceDetailType detailType, PerformanceEntryType entryType, int nodeId);
  65. /// <summary>
  66. /// Finalize the current performance frame.
  67. /// </summary>
  68. /// <param name="dspRunningBehind">Indicate if the DSP is running behind.</param>
  69. /// <param name="voiceDropCount">The count of voices that were dropped.</param>
  70. /// <param name="startRenderingTicks">The start ticks of the audio rendering.</param>
  71. public abstract void TapFrame(bool dspRunningBehind, uint voiceDropCount, ulong startRenderingTicks);
  72. /// <summary>
  73. /// Create a new <see cref="PerformanceManager"/>.
  74. /// </summary>
  75. /// <param name="performanceBuffer">The backing memory available for use by the manager.</param>
  76. /// <param name="parameter">The audio renderer configuration.</param>
  77. /// <param name="behaviourContext">The behaviour context;</param>
  78. /// <returns>A new <see cref="PerformanceManager"/>.</returns>
  79. public static PerformanceManager Create(Memory<byte> performanceBuffer, ref AudioRendererConfiguration parameter, BehaviourContext behaviourContext)
  80. {
  81. uint version = behaviourContext.GetPerformanceMetricsDataFormat();
  82. switch (version)
  83. {
  84. case 1:
  85. return new PerformanceManagerGeneric<PerformanceFrameHeaderVersion1, PerformanceEntryVersion1, PerformanceDetailVersion1>(performanceBuffer,
  86. ref parameter);
  87. case 2:
  88. return new PerformanceManagerGeneric<PerformanceFrameHeaderVersion2, PerformanceEntryVersion2, PerformanceDetailVersion2>(performanceBuffer,
  89. ref parameter);
  90. default:
  91. throw new NotImplementedException($"Unknown Performance metrics data format version {version}");
  92. }
  93. }
  94. }
  95. }