Skip to content

Commit

Permalink
misc: chore: move ThreadedRenderer creation logic into IRenderer base…
Browse files Browse the repository at this point in the history
… (since ThreadedRenderer is a GAL construct anyways)
  • Loading branch information
GreemDev committed Mar 4, 2025
1 parent b45a65f commit f797675
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
16 changes: 16 additions & 0 deletions src/Ryujinx.Graphics.GAL/IRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL.Multithreading;
using System;
using System.Threading;

Expand All @@ -10,6 +12,20 @@ public interface IRenderer : IDisposable

bool PreferThreading { get; }

public IRenderer TryMakeThreaded(BackendThreading backendThreading = BackendThreading.Auto)
{
if (backendThreading is BackendThreading.On ||
(backendThreading is BackendThreading.Auto && PreferThreading))
{
Logger.Info?.PrintMsg(LogClass.Gpu, $"Backend Threading ({backendThreading}): True");
return new ThreadedRenderer(this);
}

Logger.Info?.PrintMsg(LogClass.Gpu, $"Backend Threading ({backendThreading}): False");

return this;
}

IPipeline Pipeline { get; }

IWindow Window { get; }
Expand Down
12 changes: 1 addition & 11 deletions src/Ryujinx/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -902,16 +902,6 @@ private void InitEmulatedSwitch()
_ => new OpenGLRenderer()
};

BackendThreading threadingMode = ConfigurationState.Instance.Graphics.BackendThreading;

bool isGALThreaded = threadingMode == BackendThreading.On || (threadingMode == BackendThreading.Auto && renderer.PreferThreading);
if (isGALThreaded)
{
renderer = new ThreadedRenderer(renderer);
}

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

// Initialize Configuration.
Device = new Switch(ConfigurationState.Instance.CreateHleConfiguration()
.Configure(
Expand All @@ -920,7 +910,7 @@ private void InitEmulatedSwitch()
ContentManager,
_accountManager,
_userChannelPersistence,
renderer,
renderer.TryMakeThreaded(ConfigurationState.Instance.Graphics.BackendThreading),
InitializeAudio(),
_viewModel.UiHandler
)
Expand Down
17 changes: 3 additions & 14 deletions src/Ryujinx/Headless/HeadlessRyujinx.Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,8 @@ private static IRenderer CreateRenderer(Options options, WindowBase window)
return new OpenGLRenderer();
}

private static Switch InitializeEmulationContext(WindowBase window, IRenderer renderer, Options options)
{
BackendThreading threadingMode = options.BackendThreading;

bool threadedGAL = threadingMode == BackendThreading.On || (threadingMode == BackendThreading.Auto && renderer.PreferThreading);

if (threadedGAL)
{
renderer = new ThreadedRenderer(renderer);
}

return new Switch(
private static Switch InitializeEmulationContext(WindowBase window, IRenderer renderer, Options options) =>
new(
new HleConfiguration(
options.DramSize,
options.SystemLanguage,
Expand Down Expand Up @@ -354,11 +344,10 @@ private static Switch InitializeEmulationContext(WindowBase window, IRenderer re
_contentManager,
_accountManager,
_userChannelPersistence,
renderer,
renderer.TryMakeThreaded(options.BackendThreading),
new SDL2HardwareDeviceDriver(),
window
)
);
}
}
}

0 comments on commit f797675

Please sign in to comment.