GpuChannel.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Ryujinx.Graphics.Gpu.Engine.GPFifo;
  2. using Ryujinx.Graphics.Gpu.Image;
  3. using Ryujinx.Graphics.Gpu.Memory;
  4. using System;
  5. namespace Ryujinx.Graphics.Gpu
  6. {
  7. /// <summary>
  8. /// Represents a GPU channel.
  9. /// </summary>
  10. public class GpuChannel : IDisposable
  11. {
  12. private readonly GpuContext _context;
  13. private readonly GPFifoDevice _device;
  14. private readonly GPFifoProcessor _processor;
  15. /// <summary>
  16. /// Channel buffer bindings manager.
  17. /// </summary>
  18. internal BufferManager BufferManager { get; }
  19. /// <summary>
  20. /// Channel texture bindings manager.
  21. /// </summary>
  22. internal TextureManager TextureManager { get; }
  23. /// <summary>
  24. /// Creates a new instance of a GPU channel.
  25. /// </summary>
  26. /// <param name="context">GPU context that the channel belongs to</param>
  27. internal GpuChannel(GpuContext context)
  28. {
  29. _context = context;
  30. _device = context.GPFifo;
  31. _processor = new GPFifoProcessor(context, this);
  32. BufferManager = new BufferManager(context);
  33. TextureManager = new TextureManager(context, this);
  34. }
  35. /// <summary>
  36. /// Push a GPFIFO entry in the form of a prefetched command buffer.
  37. /// It is intended to be used by nvservices to handle special cases.
  38. /// </summary>
  39. /// <param name="commandBuffer">The command buffer containing the prefetched commands</param>
  40. public void PushHostCommandBuffer(int[] commandBuffer)
  41. {
  42. _device.PushHostCommandBuffer(_processor, commandBuffer);
  43. }
  44. /// <summary>
  45. /// Pushes GPFIFO entries.
  46. /// </summary>
  47. /// <param name="entries">GPFIFO entries</param>
  48. public void PushEntries(ReadOnlySpan<ulong> entries)
  49. {
  50. _device.PushEntries(_processor, entries);
  51. }
  52. /// <summary>
  53. /// Disposes the GPU channel.
  54. /// It's an error to use the GPU channel after disposal.
  55. /// </summary>
  56. public void Dispose()
  57. {
  58. _context.DisposedChannels.Enqueue(this);
  59. }
  60. /// <summary>
  61. /// Performs disposal of the host GPU resources used by this channel, that are not shared.
  62. /// This must only be called from the render thread.
  63. /// </summary>
  64. internal void Destroy()
  65. {
  66. BufferManager.Dispose();
  67. TextureManager.Dispose();
  68. }
  69. }
  70. }