JIT optimizations and refactoring (#675)

* CPU/Recompiler: Use rel32 call where possible for no-args

* JitCodeBuffer: Support using preallocated buffer

* CPU/Recompiler/AArch64: Use bl instead of blr for short branches

* CPU/CodeCache: Allocate recompiler buffer in program space

This means we don't need 64-bit moves for every call out of the
recompiler.

* GTE: Don't store as u16 and load as u32

* CPU/Recompiler: Add methods to emit global load/stores

* GTE: Convert class to namespace

* CPU/Recompiler: Call GTE functions directly

* Settings: Turn into a global variable

* GPU: Replace local pointers with global

* InterruptController: Turn into a global pointer

* System: Replace local pointers with global

* Timers: Turn into a global instance

* DMA: Turn into a global instance

* SPU: Turn into a global instance

* CDROM: Turn into a global instance

* MDEC: Turn into a global instance

* Pad: Turn into a global instance

* SIO: Turn into a global instance

* CDROM: Move audio FIFO to the heap

* CPU/Recompiler: Drop ASMFunctions

No longer needed since we have code in the same 4GB window.

* CPUCodeCache: Turn class into namespace

* Bus: Local pointer -> global pointers

* CPU: Turn class into namespace

* Bus: Turn into namespace

* GTE: Store registers in CPU state struct

Allows relative addressing on ARM.

* CPU/Recompiler: Align code storage to page size

* CPU/Recompiler: Fix relative branches on A64

* HostInterface: Local references to global

* System: Turn into a namespace, move events out

* Add guard pages

* Android: Fix build
This commit is contained in:
Connor McLaughlin
2020-07-31 17:09:18 +10:00
committed by GitHub
parent 1f9fc6ab74
commit b6f871d2b9
88 changed files with 4993 additions and 5045 deletions

View File

@ -9,8 +9,10 @@
#include "common/string_util.h"
#include "controller.h"
#include "cpu_core.h"
#include "cpu_code_cache.h"
#include "dma.h"
#include "gpu.h"
#include "gte.h"
#include "host_display.h"
#include "save_state_version.h"
#include "system.h"
@ -21,8 +23,13 @@
#include <stdlib.h>
Log_SetChannel(HostInterface);
HostInterface* g_host_interface;
HostInterface::HostInterface()
{
Assert(!g_host_interface);
g_host_interface = this;
// we can get the program directory at construction time
const std::string program_path = FileSystem::GetProgramPath();
m_program_directory = FileSystem::GetPathDirectory(program_path.c_str());
@ -31,7 +38,9 @@ HostInterface::HostInterface()
HostInterface::~HostInterface()
{
// system should be shut down prior to the destructor
Assert(!m_system && !m_audio_stream && !m_display);
Assert(System::IsShutdown() && !m_audio_stream && !m_display);
Assert(g_host_interface == this);
g_host_interface = nullptr;
}
bool HostInterface::Initialize()
@ -44,20 +53,20 @@ void HostInterface::Shutdown() {}
void HostInterface::CreateAudioStream()
{
Log_InfoPrintf("Creating '%s' audio stream, sample rate = %u, channels = %u, buffer size = %u",
Settings::GetAudioBackendName(m_settings.audio_backend), AUDIO_SAMPLE_RATE, AUDIO_CHANNELS,
m_settings.audio_buffer_size);
Settings::GetAudioBackendName(g_settings.audio_backend), AUDIO_SAMPLE_RATE, AUDIO_CHANNELS,
g_settings.audio_buffer_size);
m_audio_stream = CreateAudioStream(m_settings.audio_backend);
m_audio_stream = CreateAudioStream(g_settings.audio_backend);
if (!m_audio_stream || !m_audio_stream->Reconfigure(AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, m_settings.audio_buffer_size))
if (!m_audio_stream || !m_audio_stream->Reconfigure(AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, g_settings.audio_buffer_size))
{
ReportFormattedError("Failed to create or configure audio stream, falling back to null output.");
m_audio_stream.reset();
m_audio_stream = AudioStream::CreateNullAudioStream();
m_audio_stream->Reconfigure(AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, m_settings.audio_buffer_size);
m_audio_stream->Reconfigure(AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, g_settings.audio_buffer_size);
}
m_audio_stream->SetOutputVolume(m_settings.audio_output_muted ? 0 : m_settings.audio_output_volume);
m_audio_stream->SetOutputVolume(g_settings.audio_output_muted ? 0 : g_settings.audio_output_volume);
}
bool HostInterface::BootSystem(const SystemBootParameters& parameters)
@ -78,14 +87,13 @@ bool HostInterface::BootSystem(const SystemBootParameters& parameters)
}
// set host display settings
m_display->SetDisplayLinearFiltering(m_settings.display_linear_filtering);
m_display->SetDisplayIntegerScaling(m_settings.display_integer_scaling);
m_display->SetDisplayLinearFiltering(g_settings.display_linear_filtering);
m_display->SetDisplayIntegerScaling(g_settings.display_integer_scaling);
// create the audio stream. this will never fail, since we'll just fall back to null
CreateAudioStream();
m_system = System::Create(this);
if (!m_system->Boot(parameters))
if (!System::Boot(parameters))
{
ReportFormattedError("System failed to boot. The log may contain more information.");
DestroySystem();
@ -101,25 +109,22 @@ bool HostInterface::BootSystem(const SystemBootParameters& parameters)
void HostInterface::ResetSystem()
{
m_system->Reset();
m_system->ResetPerformanceCounters();
System::Reset();
System::ResetPerformanceCounters();
AddOSDMessage("System reset.");
}
void HostInterface::PowerOffSystem()
{
if (!m_system)
return;
DestroySystem();
}
void HostInterface::DestroySystem()
{
if (!m_system)
if (System::IsShutdown())
return;
m_system.reset();
System::Shutdown();
m_audio_stream.reset();
UpdateSoftwareCursor();
ReleaseHostDisplay();
@ -210,50 +215,50 @@ std::optional<std::vector<u8>> HostInterface::GetBIOSImage(ConsoleRegion region)
} while (0)
// Try the configured image.
TRY_FILENAME(m_settings.bios_path.c_str());
TRY_FILENAME(g_settings.bios_path.c_str());
// Try searching in the same folder for other region's images.
switch (region)
{
case ConsoleRegion::NTSC_J:
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph3000.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-11j.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph1000.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-10j.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5500.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-30j.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph7000.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph7500.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph9000.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-40j.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph3000.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "ps-11j.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph1000.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "ps-10j.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph5500.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "ps-30j.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph7000.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph7500.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph9000.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "ps-40j.bin", false, false));
break;
case ConsoleRegion::NTSC_U:
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph1001.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-22a.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5501.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5503.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph7003.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-30a.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph7001.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph7501.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph7503.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph9001.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph9003.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph9903.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-41a.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph1001.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "ps-22a.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph5501.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph5503.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph7003.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "ps-30a.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph7001.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph7501.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph7503.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph9001.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph9003.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph9903.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "ps-41a.bin", false, false));
break;
case ConsoleRegion::PAL:
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph1002.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-21e.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5502.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph5552.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-30e.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph7002.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph7502.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "scph9002.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(m_settings.bios_path.c_str(), "ps-41e.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph1002.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "ps-21e.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph5502.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph5552.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "ps-30e.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph7002.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph7502.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "scph9002.bin", false, false));
TRY_FILENAME(FileSystem::BuildPathRelativeToFile(g_settings.bios_path.c_str(), "ps-41e.bin", false, false));
break;
default:
@ -266,8 +271,8 @@ std::optional<std::vector<u8>> HostInterface::GetBIOSImage(ConsoleRegion region)
// Fall back to the default image.
Log_WarningPrintf("No suitable BIOS image for region %s could be located, using configured image '%s'. This may "
"result in instability.",
Settings::GetConsoleRegionName(region), m_settings.bios_path.c_str());
return BIOS::LoadImageFromFile(m_settings.bios_path);
Settings::GetConsoleRegionName(region), g_settings.bios_path.c_str());
return BIOS::LoadImageFromFile(g_settings.bios_path);
}
bool HostInterface::LoadState(const char* filename)
@ -278,12 +283,12 @@ bool HostInterface::LoadState(const char* filename)
AddFormattedOSDMessage(2.0f, "Loading state from '%s'...", filename);
if (m_system)
if (!System::IsShutdown())
{
if (!m_system->LoadState(stream.get()))
if (!System::LoadState(stream.get()))
{
ReportFormattedError("Loading state from '%s' failed. Resetting.", filename);
m_system->Reset();
ResetSystem();
return false;
}
}
@ -295,7 +300,7 @@ bool HostInterface::LoadState(const char* filename)
return false;
}
m_system->ResetPerformanceCounters();
System::ResetPerformanceCounters();
return true;
}
@ -307,7 +312,7 @@ bool HostInterface::SaveState(const char* filename)
if (!stream)
return false;
const bool result = m_system->SaveState(stream.get());
const bool result = System::SaveState(stream.get());
if (!result)
{
ReportFormattedError("Saving state to '%s' failed.", filename);
@ -422,89 +427,86 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si)
void HostInterface::LoadSettings(SettingsInterface& si)
{
m_settings.Load(si);
g_settings.Load(si);
}
void HostInterface::SaveSettings(SettingsInterface& si)
{
m_settings.Save(si);
g_settings.Save(si);
}
void HostInterface::CheckForSettingsChanges(const Settings& old_settings)
{
if (m_system)
if (!System::IsShutdown())
{
if (m_settings.gpu_renderer != old_settings.gpu_renderer ||
m_settings.gpu_use_debug_device != old_settings.gpu_use_debug_device)
if (g_settings.gpu_renderer != old_settings.gpu_renderer ||
g_settings.gpu_use_debug_device != old_settings.gpu_use_debug_device)
{
ReportFormattedMessage("Switching to %s%s GPU renderer.", Settings::GetRendererName(m_settings.gpu_renderer),
m_settings.gpu_use_debug_device ? " (debug)" : "");
ReportFormattedMessage("Switching to %s%s GPU renderer.", Settings::GetRendererName(g_settings.gpu_renderer),
g_settings.gpu_use_debug_device ? " (debug)" : "");
RecreateSystem();
}
if (m_settings.audio_backend != old_settings.audio_backend ||
m_settings.audio_buffer_size != old_settings.audio_buffer_size)
if (g_settings.audio_backend != old_settings.audio_backend ||
g_settings.audio_buffer_size != old_settings.audio_buffer_size)
{
if (m_settings.audio_backend != old_settings.audio_backend)
if (g_settings.audio_backend != old_settings.audio_backend)
ReportFormattedMessage("Switching to %s audio backend.",
Settings::GetAudioBackendName(m_settings.audio_backend));
Settings::GetAudioBackendName(g_settings.audio_backend));
DebugAssert(m_audio_stream);
m_audio_stream.reset();
CreateAudioStream();
m_audio_stream->PauseOutput(false);
m_audio_stream->PauseOutput(System::IsPaused());
}
if (m_settings.emulation_speed != old_settings.emulation_speed)
m_system->UpdateThrottlePeriod();
if (g_settings.emulation_speed != old_settings.emulation_speed)
System::UpdateThrottlePeriod();
if (m_settings.cpu_execution_mode != old_settings.cpu_execution_mode)
if (g_settings.cpu_execution_mode != old_settings.cpu_execution_mode)
{
ReportFormattedMessage("Switching to %s CPU execution mode.",
Settings::GetCPUExecutionModeName(m_settings.cpu_execution_mode));
m_system->SetCPUExecutionMode(m_settings.cpu_execution_mode);
Settings::GetCPUExecutionModeName(g_settings.cpu_execution_mode));
CPU::CodeCache::SetUseRecompiler(g_settings.cpu_execution_mode == CPUExecutionMode::Recompiler);
}
m_audio_stream->SetOutputVolume(m_settings.audio_output_muted ? 0 : m_settings.audio_output_volume);
m_audio_stream->SetOutputVolume(g_settings.audio_output_muted ? 0 : g_settings.audio_output_volume);
if (m_settings.gpu_resolution_scale != old_settings.gpu_resolution_scale ||
m_settings.gpu_fifo_size != old_settings.gpu_fifo_size ||
m_settings.gpu_max_run_ahead != old_settings.gpu_max_run_ahead ||
m_settings.gpu_true_color != old_settings.gpu_true_color ||
m_settings.gpu_scaled_dithering != old_settings.gpu_scaled_dithering ||
m_settings.gpu_texture_filtering != old_settings.gpu_texture_filtering ||
m_settings.gpu_disable_interlacing != old_settings.gpu_disable_interlacing ||
m_settings.gpu_force_ntsc_timings != old_settings.gpu_force_ntsc_timings ||
m_settings.display_crop_mode != old_settings.display_crop_mode ||
m_settings.display_aspect_ratio != old_settings.display_aspect_ratio)
if (g_settings.gpu_resolution_scale != old_settings.gpu_resolution_scale ||
g_settings.gpu_fifo_size != old_settings.gpu_fifo_size ||
g_settings.gpu_max_run_ahead != old_settings.gpu_max_run_ahead ||
g_settings.gpu_true_color != old_settings.gpu_true_color ||
g_settings.gpu_scaled_dithering != old_settings.gpu_scaled_dithering ||
g_settings.gpu_texture_filtering != old_settings.gpu_texture_filtering ||
g_settings.gpu_disable_interlacing != old_settings.gpu_disable_interlacing ||
g_settings.gpu_force_ntsc_timings != old_settings.gpu_force_ntsc_timings ||
g_settings.display_crop_mode != old_settings.display_crop_mode ||
g_settings.display_aspect_ratio != old_settings.display_aspect_ratio)
{
m_system->UpdateGPUSettings();
g_gpu->UpdateSettings();
}
if (m_settings.cdrom_read_thread != old_settings.cdrom_read_thread)
m_system->GetCDROM()->SetUseReadThread(m_settings.cdrom_read_thread);
if (g_settings.cdrom_read_thread != old_settings.cdrom_read_thread)
g_cdrom.SetUseReadThread(g_settings.cdrom_read_thread);
if (m_settings.memory_card_types != old_settings.memory_card_types ||
m_settings.memory_card_paths != old_settings.memory_card_paths)
if (g_settings.memory_card_types != old_settings.memory_card_types ||
g_settings.memory_card_paths != old_settings.memory_card_paths)
{
m_system->UpdateMemoryCards();
System::UpdateMemoryCards();
}
m_system->GetDMA()->SetMaxSliceTicks(m_settings.dma_max_slice_ticks);
m_system->GetDMA()->SetHaltTicks(m_settings.dma_halt_ticks);
if (m_settings.gpu_widescreen_hack != old_settings.gpu_widescreen_hack)
m_system->GetCPU()->GetCop2().SetWidescreenHack(m_settings.gpu_widescreen_hack);
g_dma.SetMaxSliceTicks(g_settings.dma_max_slice_ticks);
g_dma.SetHaltTicks(g_settings.dma_halt_ticks);
}
bool controllers_updated = false;
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
{
if (m_settings.controller_types[i] != old_settings.controller_types[i])
if (g_settings.controller_types[i] != old_settings.controller_types[i])
{
if (m_system && !controllers_updated)
if (!System::IsShutdown() && !controllers_updated)
{
m_system->UpdateControllers();
m_system->ResetControllers();
System::UpdateControllers();
System::ResetControllers();
UpdateSoftwareCursor();
controllers_updated = true;
}
@ -512,18 +514,18 @@ void HostInterface::CheckForSettingsChanges(const Settings& old_settings)
OnControllerTypeChanged(i);
}
if (m_system && !controllers_updated)
if (!System::IsShutdown() && !controllers_updated)
{
m_system->UpdateControllerSettings();
System::UpdateControllerSettings();
UpdateSoftwareCursor();
}
}
if (m_display && m_settings.display_linear_filtering != old_settings.display_linear_filtering)
m_display->SetDisplayLinearFiltering(m_settings.display_linear_filtering);
if (m_display && g_settings.display_linear_filtering != old_settings.display_linear_filtering)
m_display->SetDisplayLinearFiltering(g_settings.display_linear_filtering);
if (m_display && m_settings.display_integer_scaling != old_settings.display_integer_scaling)
m_display->SetDisplayIntegerScaling(m_settings.display_integer_scaling);
if (m_display && g_settings.display_integer_scaling != old_settings.display_integer_scaling)
m_display->SetDisplayIntegerScaling(g_settings.display_integer_scaling);
}
void HostInterface::SetUserDirectoryToProgramDirectory()
@ -620,35 +622,35 @@ float HostInterface::GetFloatSettingValue(const char* section, const char* key,
void HostInterface::ToggleSoftwareRendering()
{
if (!m_system || m_settings.gpu_renderer == GPURenderer::Software)
if (System::IsShutdown() || g_settings.gpu_renderer == GPURenderer::Software)
return;
const GPURenderer new_renderer =
m_system->GetGPU()->IsHardwareRenderer() ? GPURenderer::Software : m_settings.gpu_renderer;
g_gpu->IsHardwareRenderer() ? GPURenderer::Software : g_settings.gpu_renderer;
AddFormattedOSDMessage(2.0f, "Switching to %s renderer...", Settings::GetRendererDisplayName(new_renderer));
m_system->RecreateGPU(new_renderer);
System::RecreateGPU(new_renderer);
}
void HostInterface::ModifyResolutionScale(s32 increment)
{
const u32 new_resolution_scale = std::clamp<u32>(
static_cast<u32>(static_cast<s32>(m_settings.gpu_resolution_scale) + increment), 1, GPU::MAX_RESOLUTION_SCALE);
if (new_resolution_scale == m_settings.gpu_resolution_scale)
static_cast<u32>(static_cast<s32>(g_settings.gpu_resolution_scale) + increment), 1, GPU::MAX_RESOLUTION_SCALE);
if (new_resolution_scale == g_settings.gpu_resolution_scale)
return;
m_settings.gpu_resolution_scale = new_resolution_scale;
AddFormattedOSDMessage(2.0f, "Resolution scale set to %ux (%ux%u)", m_settings.gpu_resolution_scale,
GPU::VRAM_WIDTH * m_settings.gpu_resolution_scale,
GPU::VRAM_HEIGHT * m_settings.gpu_resolution_scale);
g_settings.gpu_resolution_scale = new_resolution_scale;
AddFormattedOSDMessage(2.0f, "Resolution scale set to %ux (%ux%u)", g_settings.gpu_resolution_scale,
GPU::VRAM_WIDTH * g_settings.gpu_resolution_scale,
GPU::VRAM_HEIGHT * g_settings.gpu_resolution_scale);
if (m_system)
m_system->GetGPU()->UpdateSettings();
if (!System::IsShutdown())
g_gpu->UpdateSettings();
}
void HostInterface::UpdateSoftwareCursor()
{
if (!m_system)
if (System::IsShutdown())
{
m_display->ClearSoftwareCursor();
return;
@ -659,7 +661,7 @@ void HostInterface::UpdateSoftwareCursor()
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
{
Controller* controller = m_system->GetController(i);
Controller* controller = System::GetController(i);
if (controller && controller->GetSoftwareCursor(&image, &image_scale))
break;
}
@ -677,8 +679,10 @@ void HostInterface::UpdateSoftwareCursor()
void HostInterface::RecreateSystem()
{
Assert(!System::IsShutdown());
std::unique_ptr<ByteStream> stream = ByteStream_CreateGrowableMemoryStream(nullptr, 8 * 1024);
if (!m_system->SaveState(stream.get()) || !stream->SeekAbsolute(0))
if (!System::SaveState(stream.get()) || !stream->SeekAbsolute(0))
{
ReportError("Failed to save state before system recreation. Shutting down.");
DestroySystem();
@ -695,7 +699,7 @@ void HostInterface::RecreateSystem()
return;
}
m_system->ResetPerformanceCounters();
System::ResetPerformanceCounters();
}
void HostInterface::DisplayLoadingScreen(const char* message, int progress_min /*= -1*/, int progress_max /*= -1*/,