GpuContext.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 IPhysicalMemory PhysicalMemory { get; private set; }
  14. public MemoryManager MemoryManager { get; }
  15. internal MemoryAccessor MemoryAccessor { get; }
  16. internal Methods Methods { get; }
  17. internal NvGpuFifo Fifo { get; }
  18. public DmaPusher DmaPusher { get; }
  19. internal int SequenceNumber { get; private set; }
  20. private Lazy<Capabilities> _caps;
  21. internal Capabilities Capabilities => _caps.Value;
  22. public GpuContext(IRenderer renderer)
  23. {
  24. Renderer = renderer;
  25. MemoryManager = new MemoryManager();
  26. MemoryAccessor = new MemoryAccessor(this);
  27. Methods = new Methods(this);
  28. Fifo = new NvGpuFifo(this);
  29. DmaPusher = new DmaPusher(this);
  30. _caps = new Lazy<Capabilities>(GetCapabilities);
  31. }
  32. internal void AdvanceSequence()
  33. {
  34. SequenceNumber++;
  35. }
  36. public ITexture GetTexture(
  37. ulong address,
  38. int width,
  39. int height,
  40. int stride,
  41. bool isLinear,
  42. int gobBlocksInY,
  43. Format format,
  44. int bytesPerPixel)
  45. {
  46. FormatInfo formatInfo = new FormatInfo(format, 1, 1, bytesPerPixel);
  47. TextureInfo info = new TextureInfo(
  48. address,
  49. width,
  50. height,
  51. 1,
  52. 1,
  53. 1,
  54. 1,
  55. stride,
  56. isLinear,
  57. gobBlocksInY,
  58. 1,
  59. 1,
  60. Target.Texture2D,
  61. formatInfo);
  62. return Methods.GetTexture(address)?.HostTexture;
  63. }
  64. private Capabilities GetCapabilities()
  65. {
  66. return Renderer.GetCapabilities();
  67. }
  68. public void SetVmm(IPhysicalMemory mm)
  69. {
  70. PhysicalMemory = mm;
  71. }
  72. }
  73. }