Loop GLScreen with custom method
This commit is contained in:
parent
1968386808
commit
59a5fb397f
4 changed files with 88 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
||||||
using Ryujinx.HLE.Gpu.Memory;
|
using Ryujinx.HLE.Gpu.Memory;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.Gpu.Engines
|
namespace Ryujinx.HLE.Gpu.Engines
|
||||||
{
|
{
|
||||||
|
@ -18,6 +19,8 @@ namespace Ryujinx.HLE.Gpu.Engines
|
||||||
|
|
||||||
private NvGpuEngine[] SubChannels;
|
private NvGpuEngine[] SubChannels;
|
||||||
|
|
||||||
|
public ManualResetEvent Event { get; private set; }
|
||||||
|
|
||||||
private struct CachedMacro
|
private struct CachedMacro
|
||||||
{
|
{
|
||||||
public int Position { get; private set; }
|
public int Position { get; private set; }
|
||||||
|
@ -60,6 +63,8 @@ namespace Ryujinx.HLE.Gpu.Engines
|
||||||
Macros = new CachedMacro[MacrosCount];
|
Macros = new CachedMacro[MacrosCount];
|
||||||
|
|
||||||
Mme = new int[MmeWords];
|
Mme = new int[MmeWords];
|
||||||
|
|
||||||
|
Event = new ManualResetEvent(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PushBuffer(NvGpuVmm Vmm, NvGpuPBEntry[] Buffer)
|
public void PushBuffer(NvGpuVmm Vmm, NvGpuPBEntry[] Buffer)
|
||||||
|
@ -68,6 +73,8 @@ namespace Ryujinx.HLE.Gpu.Engines
|
||||||
{
|
{
|
||||||
BufferQueue.Enqueue((Vmm, PBEntry));
|
BufferQueue.Enqueue((Vmm, PBEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Event.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DispatchCalls()
|
public void DispatchCalls()
|
||||||
|
|
|
@ -71,9 +71,16 @@ namespace Ryujinx.HLE
|
||||||
Os.LoadProgram(FileName);
|
Os.LoadProgram(FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool WaitFifo()
|
||||||
|
{
|
||||||
|
return Gpu.Fifo.Event.WaitOne(1);
|
||||||
|
}
|
||||||
|
|
||||||
public void ProcessFrame()
|
public void ProcessFrame()
|
||||||
{
|
{
|
||||||
Gpu.Fifo.DispatchCalls();
|
Gpu.Fifo.DispatchCalls();
|
||||||
|
|
||||||
|
Gpu.Fifo.Event.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal virtual void OnFinish(EventArgs e)
|
internal virtual void OnFinish(EventArgs e)
|
||||||
|
|
|
@ -5,6 +5,9 @@ using Ryujinx.Graphics.Gal;
|
||||||
using Ryujinx.HLE;
|
using Ryujinx.HLE;
|
||||||
using Ryujinx.HLE.Input;
|
using Ryujinx.HLE.Input;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
using Stopwatch = System.Diagnostics.Stopwatch;
|
||||||
|
|
||||||
namespace Ryujinx
|
namespace Ryujinx
|
||||||
{
|
{
|
||||||
|
@ -16,6 +19,8 @@ namespace Ryujinx
|
||||||
private const float TouchScreenRatioX = (float)TouchScreenWidth / TouchScreenHeight;
|
private const float TouchScreenRatioX = (float)TouchScreenWidth / TouchScreenHeight;
|
||||||
private const float TouchScreenRatioY = (float)TouchScreenHeight / TouchScreenWidth;
|
private const float TouchScreenRatioY = (float)TouchScreenHeight / TouchScreenWidth;
|
||||||
|
|
||||||
|
private const int TargetFPS = 60;
|
||||||
|
|
||||||
private Switch Ns;
|
private Switch Ns;
|
||||||
|
|
||||||
private IGalRenderer Renderer;
|
private IGalRenderer Renderer;
|
||||||
|
@ -24,6 +29,8 @@ namespace Ryujinx
|
||||||
|
|
||||||
private MouseState? Mouse = null;
|
private MouseState? Mouse = null;
|
||||||
|
|
||||||
|
private Thread RenderThread;
|
||||||
|
|
||||||
public GLScreen(Switch Ns, IGalRenderer Renderer)
|
public GLScreen(Switch Ns, IGalRenderer Renderer)
|
||||||
: base(1280, 720,
|
: base(1280, 720,
|
||||||
new GraphicsMode(), "Ryujinx", 0,
|
new GraphicsMode(), "Ryujinx", 0,
|
||||||
|
@ -38,11 +45,66 @@ namespace Ryujinx
|
||||||
(DisplayDevice.Default.Height / 2) - (Height / 2));
|
(DisplayDevice.Default.Height / 2) - (Height / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnLoad(EventArgs e)
|
private void RenderLoop()
|
||||||
{
|
{
|
||||||
VSync = VSyncMode.On;
|
MakeCurrent();
|
||||||
|
|
||||||
|
Stopwatch Chrono = new Stopwatch();
|
||||||
|
|
||||||
|
Chrono.Start();
|
||||||
|
|
||||||
|
long TicksPerFrame = Stopwatch.Frequency / TargetFPS;
|
||||||
|
|
||||||
|
long Ticks = 0;
|
||||||
|
|
||||||
|
while (!IsExiting)
|
||||||
|
{
|
||||||
|
//Sleeping until Fifo event improves performance, but it deadlocks most games
|
||||||
|
//should not be uncommented until it's found why it happens
|
||||||
|
//if (Ns.WaitFifo())
|
||||||
|
{
|
||||||
|
Ns.ProcessFrame();
|
||||||
|
|
||||||
|
Renderer.RunActions();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ticks += Chrono.ElapsedTicks;
|
||||||
|
|
||||||
|
Chrono.Restart();
|
||||||
|
|
||||||
|
if (Ticks >= TicksPerFrame)
|
||||||
|
{
|
||||||
|
RenderFrame();
|
||||||
|
|
||||||
|
Ticks -= TicksPerFrame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MainLoop()
|
||||||
|
{
|
||||||
|
VSync = VSyncMode.Off;
|
||||||
|
|
||||||
|
Visible = true;
|
||||||
|
|
||||||
Renderer.FrameBuffer.SetWindowSize(Width, Height);
|
Renderer.FrameBuffer.SetWindowSize(Width, Height);
|
||||||
|
|
||||||
|
Context.MakeCurrent(null);
|
||||||
|
|
||||||
|
//OpenTK doesn't like sleeps in its thread, to avoid these a renderer thread is created
|
||||||
|
RenderThread = new Thread(RenderLoop);
|
||||||
|
|
||||||
|
RenderThread.Start();
|
||||||
|
|
||||||
|
while (Exists && !IsExiting)
|
||||||
|
{
|
||||||
|
ProcessEvents();
|
||||||
|
|
||||||
|
if (!IsExiting)
|
||||||
|
{
|
||||||
|
UpdateFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsGamePadButtonPressedFromString(GamePadState GamePad, string Button)
|
private bool IsGamePadButtonPressedFromString(GamePadState GamePad, string Button)
|
||||||
|
@ -99,7 +161,7 @@ namespace Ryujinx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
private new void UpdateFrame()
|
||||||
{
|
{
|
||||||
HidControllerButtons CurrentButton = 0;
|
HidControllerButtons CurrentButton = 0;
|
||||||
HidJoystickPosition LeftJoystick;
|
HidJoystickPosition LeftJoystick;
|
||||||
|
@ -278,13 +340,9 @@ namespace Ryujinx
|
||||||
CurrentButton,
|
CurrentButton,
|
||||||
LeftJoystick,
|
LeftJoystick,
|
||||||
RightJoystick);
|
RightJoystick);
|
||||||
|
|
||||||
Ns.ProcessFrame();
|
|
||||||
|
|
||||||
Renderer.RunActions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnRenderFrame(FrameEventArgs e)
|
private new void RenderFrame()
|
||||||
{
|
{
|
||||||
Renderer.FrameBuffer.Render();
|
Renderer.FrameBuffer.Render();
|
||||||
|
|
||||||
|
@ -300,6 +358,13 @@ namespace Ryujinx
|
||||||
Ns.Os.SignalVsync();
|
Ns.Os.SignalVsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnUnload(EventArgs e)
|
||||||
|
{
|
||||||
|
RenderThread.Join();
|
||||||
|
|
||||||
|
base.OnUnload(e);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnResize(EventArgs e)
|
protected override void OnResize(EventArgs e)
|
||||||
{
|
{
|
||||||
Renderer.FrameBuffer.SetWindowSize(Width, Height);
|
Renderer.FrameBuffer.SetWindowSize(Width, Height);
|
||||||
|
|
|
@ -67,7 +67,7 @@ namespace Ryujinx
|
||||||
Screen.Exit();
|
Screen.Exit();
|
||||||
};
|
};
|
||||||
|
|
||||||
Screen.Run(0.0, 60.0);
|
Screen.MainLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue