Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Wrap game texture in skia image and render that
Browse files Browse the repository at this point in the history
  • Loading branch information
emmauss committed Mar 26, 2022
1 parent 848366d commit 3df95a0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 197 deletions.
79 changes: 32 additions & 47 deletions Ryujinx.Ava/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public class AppHost : IDisposable
private ManualResetEventSlim _vsyncResetEvent;
private AdjustableRenderTimer _renderTimer;
private bool _frameRateUnlocked;
private bool _isGALthreaded;

public event EventHandler AppExit;
public event EventHandler<StatusUpdatedEventArgs> StatusUpdatedEvent;
Expand Down Expand Up @@ -646,14 +645,14 @@ private void InitializeSwitchInstance()

BackendThreading threadingMode = ConfigurationState.Instance.Graphics.BackendThreading;

_isGALthreaded = threadingMode == BackendThreading.On || (threadingMode == BackendThreading.Auto && renderer.PreferThreading);
var isGALthreaded = threadingMode == BackendThreading.On || (threadingMode == BackendThreading.Auto && renderer.PreferThreading);

if (_isGALthreaded)
if (isGALthreaded)
{
renderer = new ThreadedRenderer(renderer);
}

Logger.Info?.PrintMsg(LogClass.Gpu, $"Backend Threading ({threadingMode}): {_isGALthreaded}");
Logger.Info?.PrintMsg(LogClass.Gpu, $"Backend Threading ({threadingMode}): {isGALthreaded}");

if (ConfigurationState.Instance.System.AudioBackend.Value == AudioBackend.SDL2)
{
Expand Down Expand Up @@ -881,18 +880,8 @@ private unsafe void RenderLoop()

_renderer.Window.SetSize((int)(Width * Program.WindowScaleFactor), (int)(Height * Program.WindowScaleFactor));

if (!_isGALthreaded)
{
Renderer.MakeCurrent(null);
}

Device.Gpu.Renderer.RunLoop(() =>
{
if (!_isGALthreaded)
{
Renderer.MakeCurrent();
}

Device.Gpu.SetGpuThread();
Device.Gpu.InitializeShaderCache();
Translator.IsReadyForTranslation.Set();
Expand All @@ -903,53 +892,33 @@ private unsafe void RenderLoop()
_renderTimer.Tick += RenderTimer_Tick;
UpdateTimer(ConfigurationState.Instance.Graphics.HostRefreshRate.Value);

if (!_isGALthreaded)
{
Renderer.MakeCurrent(null);
}

Renderer.IsThreaded = _isGALthreaded;

Renderer.Start();

EventHandler renderPass = (object s, EventArgs e) =>
Renderer.QueueRender();

while (_isActive)
{
if (!Device.IsFrameAvailable && Device.WaitFifo())
_ticks += _chrono.ElapsedTicks;

_chrono.Restart();

if (Device.WaitFifo())
{
Device.Statistics.RecordFifoStart();
Device.ProcessFrame();
Device.Statistics.RecordFifoEnd();
}

if (Device.ConsumeFrameAvailable())
while (Device.ConsumeFrameAvailable())
{
if (!_renderingStarted)
{
_renderingStarted = true;
_parent.SwitchToGameControl();
}

Device.PresentFrame(Renderer.Present);
Device.PresentFrame(Present);
}
else
{
Renderer.Continue();
}
};

Renderer.Rendered += renderPass;

Renderer.QueueRender();

while (_isActive)
{
_vsyncResetEvent.Wait();

_vsyncResetEvent.Reset();

_ticks += _chrono.ElapsedTicks;

_chrono.Restart();

if (_ticks >= _ticksPerFrame)
{
Expand Down Expand Up @@ -980,8 +949,6 @@ private unsafe void RenderLoop()

Renderer.Stop();

Renderer.Rendered -= renderPass;

_renderTimer.Tick -= RenderTimer_Tick;
_renderTimer.Dispose();
_vsyncResetEvent.Set();
Expand All @@ -996,10 +963,28 @@ private unsafe void RenderLoop()

private void RenderTimer_Tick(TimeSpan obj)
{
Renderer.QueueRender();
_vsyncResetEvent.Set();
}

private bool Present(int image)
{
bool presented = Renderer.Present(image);

try
{
if (_isActive && !_frameRateUnlocked)
{
_vsyncResetEvent.Wait();

}

_vsyncResetEvent.Reset();
}
catch (Exception) { }

return presented;
}

public async Task ShowExitPrompt()
{
bool shouldExit = !ConfigurationState.Instance.ShowConfirmExit;
Expand Down
110 changes: 0 additions & 110 deletions Ryujinx.Ava/Ui/Controls/OpenGlRenderer.cs

This file was deleted.

47 changes: 7 additions & 40 deletions Ryujinx.Ava/Ui/Controls/RendererControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class RendererControl : Control
public bool IsStarted { get; private set; }

protected IntPtr Fence { get; set; } = IntPtr.Zero;
public bool IsThreaded { get; internal set; }

public int Major { get; }
public int Minor { get; }
Expand Down Expand Up @@ -90,20 +89,6 @@ public override void Render(DrawingContext context)
return;
}

GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

if (!IsThreaded)
{
MakeCurrent();
}

CallRenderEvent();

if (!IsThreaded)
{
MakeCurrent(null);
}

if (Image == 0)
{
return;
Expand All @@ -115,22 +100,12 @@ public override void Render(DrawingContext context)
_postFrameResetEvent.Set();
}

protected void CallRenderEvent()
{
_preFrameResetEvent.Reset();
Rendered?.Invoke(this, EventArgs.Empty);
_preFrameResetEvent.Wait();
}

public void Continue()
{
_preFrameResetEvent?.Set();
}

protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
Continue();
_preFrameResetEvent.Dispose();
_preFrameResetEvent?.Set();
_preFrameResetEvent?.Dispose();
_postFrameResetEvent?.Set();
_postFrameResetEvent?.Dispose();

Window.SwapInterval = 1;
base.OnDetachedFromVisualTree(e);
Expand Down Expand Up @@ -172,6 +147,8 @@ internal bool Present(int image)
{
Image = image;

QueueRender();

if(Fence != IntPtr.Zero)
{
GL.DeleteSync(Fence);
Expand All @@ -180,18 +157,9 @@ internal bool Present(int image)

Fence = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None);

_postFrameResetEvent.Reset();

GL.Finish();

Continue();

if (IsThreaded)
{
_postFrameResetEvent.Wait();
}

return false;
return true;
}

internal void Start()
Expand All @@ -202,7 +170,6 @@ internal void Start()

internal void Stop()
{
Continue();
IsStarted = false;
}

Expand Down

0 comments on commit 3df95a0

Please sign in to comment.