GpuContext.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Ryujinx.Graphics.GAL;
  2. using Ryujinx.Graphics.GAL.Texture;
  3. using Ryujinx.Graphics.Gpu.Engine;
  4. using Ryujinx.Graphics.Gpu.Image;
  5. using Ryujinx.Graphics.Gpu.Memory;
  6. using Ryujinx.Graphics.Gpu.State;
  7. using System;
  8. namespace Ryujinx.Graphics.Gpu
  9. {
  10. public class GpuContext
  11. {
  12. public IRenderer Renderer { get; }
  13. internal GpuState State { get; }
  14. internal IPhysicalMemory PhysicalMemory { get; private set; }
  15. public MemoryManager MemoryManager { get; }
  16. internal MemoryAccessor MemoryAccessor { get; }
  17. internal Methods Methods { get; }
  18. internal NvGpuFifo Fifo { get; }
  19. public DmaPusher DmaPusher { get; }
  20. internal int SequenceNumber { get; private set; }
  21. private Lazy<Capabilities> _caps;
  22. internal Capabilities Capabilities => _caps.Value;
  23. public GpuContext(IRenderer renderer)
  24. {
  25. Renderer = renderer;
  26. State = new GpuState();
  27. MemoryManager = new MemoryManager();
  28. MemoryAccessor = new MemoryAccessor(this);
  29. Methods = new Methods(this);
  30. Fifo = new NvGpuFifo(this);
  31. DmaPusher = new DmaPusher(this);
  32. _caps = new Lazy<Capabilities>(GetCapabilities);
  33. }
  34. internal void AdvanceSequence()
  35. {
  36. SequenceNumber++;
  37. }
  38. public ITexture GetTexture(
  39. ulong address,
  40. int width,
  41. int height,
  42. int stride,
  43. bool isLinear,
  44. int gobBlocksInY,
  45. Format format,
  46. int bytesPerPixel)
  47. {
  48. FormatInfo formatInfo = new FormatInfo(format, 1, 1, bytesPerPixel);
  49. TextureInfo info = new TextureInfo(
  50. address,
  51. width,
  52. height,
  53. 1,
  54. 1,
  55. 1,
  56. 1,
  57. stride,
  58. isLinear,
  59. gobBlocksInY,
  60. 1,
  61. 1,
  62. Target.Texture2D,
  63. formatInfo);
  64. return Methods.GetTexture(address)?.HostTexture;
  65. }
  66. private Capabilities GetCapabilities()
  67. {
  68. return Renderer.GetCapabilities();
  69. }
  70. public void SetVmm(IPhysicalMemory mm)
  71. {
  72. PhysicalMemory = mm;
  73. }
  74. }
  75. }