GpuContext.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using Ryujinx.Graphics.GAL;
  2. using Ryujinx.Graphics.Gpu.Engine;
  3. using Ryujinx.Graphics.Gpu.Engine.GPFifo;
  4. using Ryujinx.Graphics.Gpu.Memory;
  5. using Ryujinx.Graphics.Gpu.Synchronization;
  6. using System;
  7. namespace Ryujinx.Graphics.Gpu
  8. {
  9. /// <summary>
  10. /// GPU emulation context.
  11. /// </summary>
  12. public sealed class GpuContext : IDisposable
  13. {
  14. /// <summary>
  15. /// Host renderer.
  16. /// </summary>
  17. public IRenderer Renderer { get; }
  18. /// <summary>
  19. /// Physical memory access (it actually accesses the process memory, not actual physical memory).
  20. /// </summary>
  21. internal PhysicalMemory PhysicalMemory { get; private set; }
  22. /// <summary>
  23. /// GPU memory manager.
  24. /// </summary>
  25. public MemoryManager MemoryManager { get; }
  26. /// <summary>
  27. /// GPU engine methods processing.
  28. /// </summary>
  29. internal Methods Methods { get; }
  30. /// <summary>
  31. /// GPU General Purpose FIFO queue.
  32. /// </summary>
  33. public GPFifoDevice GPFifo { get; }
  34. /// <summary>
  35. /// GPU synchronization manager.
  36. /// </summary>
  37. public SynchronizationManager Synchronization { get; }
  38. /// <summary>
  39. /// Presentation window.
  40. /// </summary>
  41. public Window Window { get; }
  42. /// <summary>
  43. /// Internal sequence number, used to avoid needless resource data updates
  44. /// in the middle of a command buffer before synchronizations.
  45. /// </summary>
  46. internal int SequenceNumber { get; private set; }
  47. private readonly Lazy<Capabilities> _caps;
  48. /// <summary>
  49. /// Host hardware capabilities.
  50. /// </summary>
  51. internal Capabilities Capabilities => _caps.Value;
  52. /// <summary>
  53. /// Creates a new instance of the GPU emulation context.
  54. /// </summary>
  55. /// <param name="renderer">Host renderer</param>
  56. public GpuContext(IRenderer renderer)
  57. {
  58. Renderer = renderer;
  59. MemoryManager = new MemoryManager(this);
  60. Methods = new Methods(this);
  61. GPFifo = new GPFifoDevice(this);
  62. Synchronization = new SynchronizationManager();
  63. Window = new Window(this);
  64. _caps = new Lazy<Capabilities>(Renderer.GetCapabilities);
  65. }
  66. /// <summary>
  67. /// Advances internal sequence number.
  68. /// This forces the update of any modified GPU resource.
  69. /// </summary>
  70. internal void AdvanceSequence()
  71. {
  72. SequenceNumber++;
  73. }
  74. /// <summary>
  75. /// Sets the process memory manager, after the application process is initialized.
  76. /// This is required for any GPU memory access.
  77. /// </summary>
  78. /// <param name="cpuMemory">CPU memory manager</param>
  79. public void SetVmm(Cpu.MemoryManager cpuMemory)
  80. {
  81. PhysicalMemory = new PhysicalMemory(cpuMemory);
  82. }
  83. /// <summary>
  84. /// Disposes all GPU resources currently cached.
  85. /// It's an error to push any GPU commands after disposal.
  86. /// Additionally, the GPU commands FIFO must be empty for disposal,
  87. /// and processing of all commands must have finished.
  88. /// </summary>
  89. public void Dispose()
  90. {
  91. Methods.ShaderCache.Dispose();
  92. Methods.BufferManager.Dispose();
  93. Methods.TextureManager.Dispose();
  94. Renderer.Dispose();
  95. GPFifo.Dispose();
  96. }
  97. }
  98. }