using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Gpu.Engine; using Ryujinx.Graphics.Gpu.Memory; using Ryujinx.Graphics.Gpu.Synchronization; using System; namespace Ryujinx.Graphics.Gpu { /// /// GPU emulation context. /// public sealed class GpuContext : IDisposable { /// /// Host renderer. /// public IRenderer Renderer { get; } /// /// Physical memory access (it actually accesses the process memory, not actual physical memory). /// internal PhysicalMemory PhysicalMemory { get; private set; } /// /// GPU memory manager. /// public MemoryManager MemoryManager { get; } /// /// GPU memory accessor. /// public MemoryAccessor MemoryAccessor { get; } /// /// GPU engine methods processing. /// internal Methods Methods { get; } /// /// GPU commands FIFO. /// internal NvGpuFifo Fifo { get; } /// /// DMA pusher. /// public DmaPusher DmaPusher { get; } /// /// GPU synchronization manager. /// public SynchronizationManager Synchronization { get; } /// /// Presentation window. /// public Window Window { get; } /// /// Internal sequence number, used to avoid needless resource data updates /// in the middle of a command buffer before synchronizations. /// internal int SequenceNumber { get; private set; } private readonly Lazy _caps; /// /// Host hardware capabilities. /// internal Capabilities Capabilities => _caps.Value; /// /// Creates a new instance of the GPU emulation context. /// /// Host renderer public GpuContext(IRenderer renderer) { Renderer = renderer; MemoryManager = new MemoryManager(); MemoryAccessor = new MemoryAccessor(this); Methods = new Methods(this); Fifo = new NvGpuFifo(this); DmaPusher = new DmaPusher(this); Synchronization = new SynchronizationManager(); Window = new Window(this); _caps = new Lazy(Renderer.GetCapabilities); } /// /// Advances internal sequence number. /// This forces the update of any modified GPU resource. /// internal void AdvanceSequence() { SequenceNumber++; } /// /// Sets the process memory manager, after the application process is initialized. /// This is required for any GPU memory access. /// /// CPU memory manager public void SetVmm(ARMeilleure.Memory.MemoryManager cpuMemory) { PhysicalMemory = new PhysicalMemory(cpuMemory); } /// /// Disposes all GPU resources currently cached. /// It's an error to push any GPU commands after disposal. /// Additionally, the GPU commands FIFO must be empty for disposal, /// and processing of all commands must have finished. /// public void Dispose() { Methods.ShaderCache.Dispose(); Methods.BufferManager.Dispose(); Methods.TextureManager.Dispose(); Renderer.Dispose(); } } }