2021-02-26 00:11:56 +00:00
|
|
|
using Ryujinx.Audio.Backends.CompatLayer;
|
|
|
|
using Ryujinx.Audio.Integration;
|
2022-05-03 00:30:02 +01:00
|
|
|
using Ryujinx.Common.Configuration;
|
2019-10-13 07:02:07 +01:00
|
|
|
using Ryujinx.Graphics.Gpu;
|
2018-09-08 23:04:26 +01:00
|
|
|
using Ryujinx.HLE.FileSystem;
|
2018-08-17 00:47:36 +01:00
|
|
|
using Ryujinx.HLE.HOS;
|
2020-11-12 05:59:18 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Apm;
|
2020-04-03 01:10:02 +01:00
|
|
|
using Ryujinx.HLE.HOS.Services.Hid;
|
2023-03-31 20:16:46 +01:00
|
|
|
using Ryujinx.HLE.Loaders.Processes;
|
2021-10-12 20:54:21 +01:00
|
|
|
using Ryujinx.HLE.Ui;
|
2020-05-03 23:54:50 +01:00
|
|
|
using Ryujinx.Memory;
|
2018-02-04 23:08:20 +00:00
|
|
|
using System;
|
|
|
|
|
2018-06-11 01:46:42 +01:00
|
|
|
namespace Ryujinx.HLE
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
|
|
|
public class Switch : IDisposable
|
|
|
|
{
|
2022-03-22 19:46:16 +00:00
|
|
|
public HLEConfiguration Configuration { get; }
|
2021-05-16 16:12:14 +01:00
|
|
|
public IHardwareDeviceDriver AudioDeviceDriver { get; }
|
2022-03-22 19:46:16 +00:00
|
|
|
public MemoryBlock Memory { get; }
|
|
|
|
public GpuContext Gpu { get; }
|
|
|
|
public VirtualFileSystem FileSystem { get; }
|
2023-01-04 22:15:45 +00:00
|
|
|
public HOS.Horizon System { get; }
|
2023-03-31 20:16:46 +01:00
|
|
|
public ProcessLoader Processes { get; }
|
2022-03-22 19:46:16 +00:00
|
|
|
public PerformanceStatistics Statistics { get; }
|
|
|
|
public Hid Hid { get; }
|
|
|
|
public TamperMachine TamperMachine { get; }
|
|
|
|
public IHostUiHandler UiHandler { get; }
|
2020-08-03 02:30:58 +01:00
|
|
|
|
2018-09-10 00:38:56 +01:00
|
|
|
public bool EnableDeviceVsync { get; set; } = true;
|
|
|
|
|
2022-05-15 12:30:15 +01:00
|
|
|
public bool IsFrameAvailable => Gpu.Window.IsFrameAvailable;
|
|
|
|
|
2021-05-16 16:12:14 +01:00
|
|
|
public Switch(HLEConfiguration configuration)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2022-12-27 19:27:11 +00:00
|
|
|
ArgumentNullException.ThrowIfNull(configuration.GpuRenderer);
|
|
|
|
ArgumentNullException.ThrowIfNull(configuration.AudioDeviceDriver);
|
|
|
|
ArgumentNullException.ThrowIfNull(configuration.UserChannelPersistence);
|
2020-09-21 04:45:30 +01:00
|
|
|
|
2021-05-16 16:12:14 +01:00
|
|
|
Configuration = configuration;
|
2022-03-22 19:46:16 +00:00
|
|
|
FileSystem = Configuration.VirtualFileSystem;
|
|
|
|
UiHandler = Configuration.HostUiHandler;
|
|
|
|
|
2022-05-03 00:30:02 +01:00
|
|
|
MemoryAllocationFlags memoryAllocationFlags = configuration.MemoryManagerMode == MemoryManagerMode.SoftwarePageTable
|
|
|
|
? MemoryAllocationFlags.Reserve
|
|
|
|
: MemoryAllocationFlags.Reserve | MemoryAllocationFlags.Mirrorable;
|
|
|
|
|
2022-03-22 19:46:16 +00:00
|
|
|
AudioDeviceDriver = new CompatLayerHardwareDeviceDriver(Configuration.AudioDeviceDriver);
|
2022-05-03 00:30:02 +01:00
|
|
|
Memory = new MemoryBlock(Configuration.MemoryConfiguration.ToDramSize(), memoryAllocationFlags);
|
2022-03-22 19:46:16 +00:00
|
|
|
Gpu = new GpuContext(Configuration.GpuRenderer);
|
2023-01-04 22:15:45 +00:00
|
|
|
System = new HOS.Horizon(this);
|
2022-03-22 19:46:16 +00:00
|
|
|
Statistics = new PerformanceStatistics();
|
|
|
|
Hid = new Hid(this, System.HidStorage);
|
2023-03-31 20:16:46 +01:00
|
|
|
Processes = new ProcessLoader(this);
|
2022-03-22 19:46:16 +00:00
|
|
|
TamperMachine = new TamperMachine();
|
2020-09-21 04:45:30 +01:00
|
|
|
|
2021-05-16 16:12:14 +01:00
|
|
|
System.State.SetLanguage(Configuration.SystemLanguage);
|
|
|
|
System.State.SetRegion(Configuration.Region);
|
2020-03-19 22:37:55 +00:00
|
|
|
|
2022-03-22 19:46:16 +00:00
|
|
|
EnableDeviceVsync = Configuration.EnableVsync;
|
|
|
|
System.State.DockedMode = Configuration.EnableDockedMode;
|
2020-11-12 05:59:18 +00:00
|
|
|
System.PerformanceState.PerformanceMode = System.State.DockedMode ? PerformanceMode.Boost : PerformanceMode.Default;
|
2022-03-22 19:46:16 +00:00
|
|
|
System.EnablePtc = Configuration.EnablePtc;
|
|
|
|
System.FsIntegrityCheckLevel = Configuration.FsIntegrityCheckLevel;
|
|
|
|
System.GlobalAccessLogMode = Configuration.FsGlobalAccessLogMode;
|
2020-01-21 22:23:11 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 20:16:46 +01:00
|
|
|
public bool LoadCart(string exeFsDir, string romFsFile = null)
|
2018-02-20 20:09:23 +00:00
|
|
|
{
|
2023-03-31 20:16:46 +01:00
|
|
|
return Processes.LoadUnpackedNca(exeFsDir, romFsFile);
|
2018-02-20 20:09:23 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 20:16:46 +01:00
|
|
|
public bool LoadXci(string xciFile)
|
2018-09-08 19:33:27 +01:00
|
|
|
{
|
2023-03-31 20:16:46 +01:00
|
|
|
return Processes.LoadXci(xciFile);
|
2018-09-08 19:33:27 +01:00
|
|
|
}
|
|
|
|
|
2023-03-31 20:16:46 +01:00
|
|
|
public bool LoadNca(string ncaFile)
|
2018-09-08 19:33:27 +01:00
|
|
|
{
|
2023-03-31 20:16:46 +01:00
|
|
|
return Processes.LoadNca(ncaFile);
|
2018-09-08 19:33:27 +01:00
|
|
|
}
|
|
|
|
|
2023-03-31 20:16:46 +01:00
|
|
|
public bool LoadNsp(string nspFile)
|
2018-09-08 19:33:27 +01:00
|
|
|
{
|
2023-03-31 20:16:46 +01:00
|
|
|
return Processes.LoadNsp(nspFile);
|
2018-09-08 19:33:27 +01:00
|
|
|
}
|
|
|
|
|
2023-03-31 20:16:46 +01:00
|
|
|
public bool LoadProgram(string fileName)
|
2018-02-20 20:09:23 +00:00
|
|
|
{
|
2023-03-31 20:16:46 +01:00
|
|
|
return Processes.LoadNxo(fileName);
|
2018-02-20 20:09:23 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 18:03:52 +01:00
|
|
|
public bool WaitFifo()
|
|
|
|
{
|
2020-07-24 03:53:25 +01:00
|
|
|
return Gpu.GPFifo.WaitForCommands();
|
2018-07-12 18:03:52 +01:00
|
|
|
}
|
|
|
|
|
2018-06-24 01:39:25 +01:00
|
|
|
public void ProcessFrame()
|
|
|
|
{
|
Add a Multithreading layer for the GAL, multi-thread shader compilation at runtime (#2501)
* Initial Implementation
About as fast as nvidia GL multithreading, can be improved with faster command queuing.
* Struct based command list
Speeds up a bit. Still a lot of time lost to resource copy.
* Do shader init while the render thread is active.
* Introduce circular span pool V1
Ideally should be able to use structs instead of references for storing these spans on commands. Will try that next.
* Refactor SpanRef some more
Use a struct to represent SpanRef, rather than a reference.
* Flush buffers on background thread
* Use a span for UpdateRenderScale.
Much faster than copying the array.
* Calculate command size using reflection
* WIP parallel shaders
* Some minor optimisation
* Only 2 max refs per command now.
The command with 3 refs is gone. :relieved:
* Don't cast on the GPU side
* Remove redundant casts, force sync on window present
* Fix Shader Cache
* Fix host shader save.
* Fixup to work with new renderer stuff
* Make command Run static, use array of delegates as lookup
Profile says this takes less time than the previous way.
* Bring up to date
* Add settings toggle. Fix Muiltithreading Off mode.
* Fix warning.
* Release tracking lock for flushes
* Fix Conditional Render fast path with threaded gal
* Make handle iteration safe when releasing the lock
This is mostly temporary.
* Attempt to set backend threading on driver
Only really works on nvidia before launching a game.
* Fix race condition with BufferModifiedRangeList, exceptions in tracking actions
* Update buffer set commands
* Some cleanup
* Only use stutter workaround when using opengl renderer non-threaded
* Add host-conditional reservation of counter events
There has always been the possibility that conditional rendering could use a query object just as it is disposed by the counter queue. This change makes it so that when the host decides to use host conditional rendering, the query object is reserved so that it cannot be deleted. Counter events can optionally start reserved, as the threaded implementation can reserve them before the backend creates them, and there would otherwise be a short amount of time where the counter queue could dispose the event before a call to reserve it could be made.
* Address Feedback
* Make counter flush tracked again.
Hopefully does not cause any issues this time.
* Wait for FlushTo on the main queue thread.
Currently assumes only one thread will want to FlushTo (in this case, the GPU thread)
* Add SDL2 headless integration
* Add HLE macro commands.
Co-authored-by: Mary <mary@mary.zone>
2021-08-26 23:31:29 +01:00
|
|
|
Gpu.ProcessShaderCacheQueue();
|
2020-09-10 20:44:04 +01:00
|
|
|
Gpu.Renderer.PreFrame();
|
2020-07-24 03:53:25 +01:00
|
|
|
Gpu.GPFifo.DispatchCalls();
|
2018-06-24 01:39:25 +01:00
|
|
|
}
|
|
|
|
|
2020-12-17 18:39:52 +00:00
|
|
|
public bool ConsumeFrameAvailable()
|
|
|
|
{
|
|
|
|
return Gpu.Window.ConsumeFrameAvailable();
|
|
|
|
}
|
|
|
|
|
2022-09-19 19:05:26 +01:00
|
|
|
public void PresentFrame(Action swapBuffersCallback)
|
2019-11-24 02:24:03 +00:00
|
|
|
{
|
|
|
|
Gpu.Window.Present(swapBuffersCallback);
|
|
|
|
}
|
|
|
|
|
2021-12-23 16:33:56 +00:00
|
|
|
public void SetVolume(float volume)
|
|
|
|
{
|
2022-10-02 10:38:37 +01:00
|
|
|
System.SetVolume(Math.Clamp(volume, 0, 1));
|
2021-12-23 16:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public float GetVolume()
|
|
|
|
{
|
|
|
|
return System.GetVolume();
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:39:43 +00:00
|
|
|
public void EnableCheats()
|
|
|
|
{
|
2023-03-31 20:16:46 +01:00
|
|
|
FileSystem.ModLoader.EnableCheats(Processes.ActiveApplication.ProgramId, TamperMachine);
|
2022-01-03 08:39:43 +00:00
|
|
|
}
|
|
|
|
|
2021-12-23 16:33:56 +00:00
|
|
|
public bool IsAudioMuted()
|
|
|
|
{
|
|
|
|
return System.GetVolume() == 0;
|
|
|
|
}
|
|
|
|
|
2019-12-31 22:09:49 +00:00
|
|
|
public void DisposeGpu()
|
|
|
|
{
|
|
|
|
Gpu.Dispose();
|
|
|
|
}
|
|
|
|
|
2018-02-04 23:08:20 +00:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
protected virtual void Dispose(bool disposing)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
if (disposing)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-08-17 00:47:36 +01:00
|
|
|
System.Dispose();
|
2021-02-26 00:11:56 +00:00
|
|
|
AudioDeviceDriver.Dispose();
|
2022-03-22 19:46:16 +00:00
|
|
|
FileSystem.Dispose();
|
2020-07-12 04:07:01 +01:00
|
|
|
Memory.Dispose();
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-31 20:16:46 +01:00
|
|
|
}
|