2021-02-25 19:11:56 -05:00
|
|
|
using Ryujinx.Audio.Backends.CompatLayer;
|
|
|
|
using Ryujinx.Audio.Integration;
|
2022-05-02 19:30:02 -04:00
|
|
|
using Ryujinx.Common.Configuration;
|
2019-10-13 02:02:07 -04:00
|
|
|
using Ryujinx.Graphics.Gpu;
|
2018-09-08 18:04:26 -04:00
|
|
|
using Ryujinx.HLE.FileSystem;
|
2018-08-16 19:47:36 -04:00
|
|
|
using Ryujinx.HLE.HOS;
|
2020-11-12 00:59:18 -05:00
|
|
|
using Ryujinx.HLE.HOS.Services.Apm;
|
2020-04-02 20:10:02 -04:00
|
|
|
using Ryujinx.HLE.HOS.Services.Hid;
|
2023-03-31 15:16:46 -04:00
|
|
|
using Ryujinx.HLE.Loaders.Processes;
|
2021-10-12 15:54:21 -04:00
|
|
|
using Ryujinx.HLE.Ui;
|
2020-05-03 18:54:50 -04:00
|
|
|
using Ryujinx.Memory;
|
2018-02-04 18:08:20 -05:00
|
|
|
using System;
|
|
|
|
|
2018-06-10 20:46:42 -04:00
|
|
|
namespace Ryujinx.HLE
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
public class Switch : IDisposable
|
|
|
|
{
|
2022-03-22 15:46:16 -04:00
|
|
|
public HLEConfiguration Configuration { get; }
|
2021-05-16 11:12:14 -04:00
|
|
|
public IHardwareDeviceDriver AudioDeviceDriver { get; }
|
2022-03-22 15:46:16 -04:00
|
|
|
public MemoryBlock Memory { get; }
|
|
|
|
public GpuContext Gpu { get; }
|
|
|
|
public VirtualFileSystem FileSystem { get; }
|
2023-01-04 17:15:45 -05:00
|
|
|
public HOS.Horizon System { get; }
|
2023-03-31 15:16:46 -04:00
|
|
|
public ProcessLoader Processes { get; }
|
2022-03-22 15:46:16 -04:00
|
|
|
public PerformanceStatistics Statistics { get; }
|
|
|
|
public Hid Hid { get; }
|
|
|
|
public TamperMachine TamperMachine { get; }
|
|
|
|
public IHostUiHandler UiHandler { get; }
|
2020-08-02 21:30:58 -04:00
|
|
|
|
2018-09-09 19:38:56 -04:00
|
|
|
public bool EnableDeviceVsync { get; set; } = true;
|
|
|
|
|
2022-05-15 07:30:15 -04:00
|
|
|
public bool IsFrameAvailable => Gpu.Window.IsFrameAvailable;
|
|
|
|
|
2021-05-16 11:12:14 -04:00
|
|
|
public Switch(HLEConfiguration configuration)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2022-12-27 14:27:11 -05:00
|
|
|
ArgumentNullException.ThrowIfNull(configuration.GpuRenderer);
|
|
|
|
ArgumentNullException.ThrowIfNull(configuration.AudioDeviceDriver);
|
|
|
|
ArgumentNullException.ThrowIfNull(configuration.UserChannelPersistence);
|
2020-09-20 23:45:30 -04:00
|
|
|
|
2021-05-16 11:12:14 -04:00
|
|
|
Configuration = configuration;
|
2022-03-22 15:46:16 -04:00
|
|
|
FileSystem = Configuration.VirtualFileSystem;
|
|
|
|
UiHandler = Configuration.HostUiHandler;
|
|
|
|
|
2022-05-02 19:30:02 -04:00
|
|
|
MemoryAllocationFlags memoryAllocationFlags = configuration.MemoryManagerMode == MemoryManagerMode.SoftwarePageTable
|
|
|
|
? MemoryAllocationFlags.Reserve
|
|
|
|
: MemoryAllocationFlags.Reserve | MemoryAllocationFlags.Mirrorable;
|
|
|
|
|
2022-03-22 15:46:16 -04:00
|
|
|
AudioDeviceDriver = new CompatLayerHardwareDeviceDriver(Configuration.AudioDeviceDriver);
|
2022-05-02 19:30:02 -04:00
|
|
|
Memory = new MemoryBlock(Configuration.MemoryConfiguration.ToDramSize(), memoryAllocationFlags);
|
2022-03-22 15:46:16 -04:00
|
|
|
Gpu = new GpuContext(Configuration.GpuRenderer);
|
2023-01-04 17:15:45 -05:00
|
|
|
System = new HOS.Horizon(this);
|
2022-03-22 15:46:16 -04:00
|
|
|
Statistics = new PerformanceStatistics();
|
|
|
|
Hid = new Hid(this, System.HidStorage);
|
2023-03-31 15:16:46 -04:00
|
|
|
Processes = new ProcessLoader(this);
|
2022-03-22 15:46:16 -04:00
|
|
|
TamperMachine = new TamperMachine();
|
2020-09-20 23:45:30 -04:00
|
|
|
|
2021-05-16 11:12:14 -04:00
|
|
|
System.State.SetLanguage(Configuration.SystemLanguage);
|
|
|
|
System.State.SetRegion(Configuration.Region);
|
2020-03-19 18:37:55 -04:00
|
|
|
|
2022-03-22 15:46:16 -04:00
|
|
|
EnableDeviceVsync = Configuration.EnableVsync;
|
|
|
|
System.State.DockedMode = Configuration.EnableDockedMode;
|
2020-11-12 00:59:18 -05:00
|
|
|
System.PerformanceState.PerformanceMode = System.State.DockedMode ? PerformanceMode.Boost : PerformanceMode.Default;
|
2022-03-22 15:46:16 -04:00
|
|
|
System.EnablePtc = Configuration.EnablePtc;
|
|
|
|
System.FsIntegrityCheckLevel = Configuration.FsIntegrityCheckLevel;
|
|
|
|
System.GlobalAccessLogMode = Configuration.FsGlobalAccessLogMode;
|
2020-01-21 17:23:11 -05:00
|
|
|
}
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
public bool LoadCart(string exeFsDir, string romFsFile = null)
|
2018-02-20 15:09:23 -05:00
|
|
|
{
|
2023-03-31 15:16:46 -04:00
|
|
|
return Processes.LoadUnpackedNca(exeFsDir, romFsFile);
|
2018-02-20 15:09:23 -05:00
|
|
|
}
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
public bool LoadXci(string xciFile)
|
2018-09-08 14:33:27 -04:00
|
|
|
{
|
2023-03-31 15:16:46 -04:00
|
|
|
return Processes.LoadXci(xciFile);
|
2018-09-08 14:33:27 -04:00
|
|
|
}
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
public bool LoadNca(string ncaFile)
|
2018-09-08 14:33:27 -04:00
|
|
|
{
|
2023-03-31 15:16:46 -04:00
|
|
|
return Processes.LoadNca(ncaFile);
|
2018-09-08 14:33:27 -04:00
|
|
|
}
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
public bool LoadNsp(string nspFile)
|
2018-09-08 14:33:27 -04:00
|
|
|
{
|
2023-03-31 15:16:46 -04:00
|
|
|
return Processes.LoadNsp(nspFile);
|
2018-09-08 14:33:27 -04:00
|
|
|
}
|
|
|
|
|
2023-03-31 15:16:46 -04:00
|
|
|
public bool LoadProgram(string fileName)
|
2018-02-20 15:09:23 -05:00
|
|
|
{
|
2023-03-31 15:16:46 -04:00
|
|
|
return Processes.LoadNxo(fileName);
|
2018-02-20 15:09:23 -05:00
|
|
|
}
|
|
|
|
|
2018-07-12 13:03:52 -04:00
|
|
|
public bool WaitFifo()
|
|
|
|
{
|
2020-07-23 22:53:25 -04:00
|
|
|
return Gpu.GPFifo.WaitForCommands();
|
2018-07-12 13:03:52 -04:00
|
|
|
}
|
|
|
|
|
2018-06-23 20:39:25 -04: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 18:31:29 -04:00
|
|
|
Gpu.ProcessShaderCacheQueue();
|
2020-09-10 15:44:04 -04:00
|
|
|
Gpu.Renderer.PreFrame();
|
2020-07-23 22:53:25 -04:00
|
|
|
Gpu.GPFifo.DispatchCalls();
|
2018-06-23 20:39:25 -04:00
|
|
|
}
|
|
|
|
|
2020-12-17 13:39:52 -05:00
|
|
|
public bool ConsumeFrameAvailable()
|
|
|
|
{
|
|
|
|
return Gpu.Window.ConsumeFrameAvailable();
|
|
|
|
}
|
|
|
|
|
2022-09-19 14:05:26 -04:00
|
|
|
public void PresentFrame(Action swapBuffersCallback)
|
2019-11-23 21:24:03 -05:00
|
|
|
{
|
|
|
|
Gpu.Window.Present(swapBuffersCallback);
|
|
|
|
}
|
|
|
|
|
2021-12-23 11:33:56 -05:00
|
|
|
public void SetVolume(float volume)
|
|
|
|
{
|
2022-10-02 05:38:37 -04:00
|
|
|
System.SetVolume(Math.Clamp(volume, 0, 1));
|
2021-12-23 11:33:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public float GetVolume()
|
|
|
|
{
|
|
|
|
return System.GetVolume();
|
|
|
|
}
|
|
|
|
|
2022-01-03 03:39:43 -05:00
|
|
|
public void EnableCheats()
|
|
|
|
{
|
2023-03-31 15:16:46 -04:00
|
|
|
FileSystem.ModLoader.EnableCheats(Processes.ActiveApplication.ProgramId, TamperMachine);
|
2022-01-03 03:39:43 -05:00
|
|
|
}
|
|
|
|
|
2021-12-23 11:33:56 -05:00
|
|
|
public bool IsAudioMuted()
|
|
|
|
{
|
|
|
|
return System.GetVolume() == 0;
|
|
|
|
}
|
|
|
|
|
2019-12-31 17:09:49 -05:00
|
|
|
public void DisposeGpu()
|
|
|
|
{
|
|
|
|
Gpu.Dispose();
|
|
|
|
}
|
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
protected virtual void Dispose(bool disposing)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
if (disposing)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-08-16 19:47:36 -04:00
|
|
|
System.Dispose();
|
2021-02-25 19:11:56 -05:00
|
|
|
AudioDeviceDriver.Dispose();
|
2022-03-22 15:46:16 -04:00
|
|
|
FileSystem.Dispose();
|
2020-07-11 23:07:01 -04:00
|
|
|
Memory.Dispose();
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-31 15:16:46 -04:00
|
|
|
}
|