using Ryujinx.Common.Configuration; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Gpu.Engine; using Ryujinx.Graphics.Gpu.Engine.GPFifo; using Ryujinx.Graphics.Gpu.Memory; using Ryujinx.Graphics.Gpu.Synchronization; using System; using System.Threading; namespace Ryujinx.Graphics.Gpu { /// /// GPU emulation context. /// public sealed class GpuContext : IDisposable { /// /// Event signaled when the host emulation context is ready to be used by the gpu context. /// public ManualResetEvent HostInitalized { get; } /// /// Event signaled when the gpu context is ready to be used. /// public ManualResetEvent ReadyEvent { get; } /// /// 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 engine methods processing. /// internal Methods Methods { get; } /// /// GPU General Purpose FIFO queue. /// public GPFifoDevice GPFifo { 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(this); Methods = new Methods(this); GPFifo = new GPFifoDevice(this); Synchronization = new SynchronizationManager(); Window = new Window(this); _caps = new Lazy(Renderer.GetCapabilities); HostInitalized = new ManualResetEvent(false); ReadyEvent = new ManualResetEvent(false); } /// /// Initialize the GPU emulation context. /// /// The log level required. public void Initialize(GraphicsDebugLevel logLevel) { HostInitalized.WaitOne(); Renderer.Initialize(logLevel); Methods.ShaderCache.Initialize(); ReadyEvent.Set(); } /// /// 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(Cpu.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(); GPFifo.Dispose(); HostInitalized.Dispose(); ReadyEvent.Dispose(); } } }