Duckstation/src/duckstation-libretro/libretro_host_interface.h
Connor McLaughlin b6f871d2b9
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
2020-07-31 17:09:18 +10:00

100 lines
3.9 KiB
C++

#pragma once
#include "core/host_interface.h"
#include "core/system.h"
#include "libretro.h"
#include <limits>
#include <optional>
class LibretroHostInterface : public HostInterface
{
public:
LibretroHostInterface();
~LibretroHostInterface() override;
static void InitLogging();
static bool SetCoreOptions();
static bool HasCoreVariablesChanged();
static void InitDiskControlInterface();
ALWAYS_INLINE u32 GetResolutionScale() const { return g_settings.gpu_resolution_scale; }
bool Initialize() override;
void Shutdown() override;
void ReportError(const char* message) override;
void ReportMessage(const char* message) override;
bool ConfirmMessage(const char* message) override;
void AddOSDMessage(std::string message, float duration = 2.0f) override;
void GetGameInfo(const char* path, CDImage* image, std::string* code, std::string* title) override;
std::string GetSharedMemoryCardPath(u32 slot) const override;
std::string GetGameMemoryCardPath(const char* game_code, u32 slot) const override;
std::string GetShaderCacheBasePath() const override;
std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "") override;
// Called by frontend
void retro_get_system_av_info(struct retro_system_av_info* info);
bool retro_load_game(const struct retro_game_info* game);
void retro_run_frame();
unsigned retro_get_region();
size_t retro_serialize_size();
bool retro_serialize(void* data, size_t size);
bool retro_unserialize(const void* data, size_t size);
void* retro_get_memory_data(unsigned id);
size_t retro_get_memory_size(unsigned id);
protected:
bool AcquireHostDisplay() override;
void ReleaseHostDisplay() override;
std::unique_ptr<AudioStream> CreateAudioStream(AudioBackend backend) override;
void OnSystemDestroyed() override;
void CheckForSettingsChanges(const Settings& old_settings) override;
private:
void LoadSettings();
void UpdateSettings();
void UpdateControllers();
void UpdateControllersDigitalController(u32 index);
void UpdateControllersAnalogController(u32 index);
void GetSystemAVInfo(struct retro_system_av_info* info, bool use_resolution_scale);
void UpdateSystemAVInfo(bool use_resolution_scale);
void UpdateGeometry();
void UpdateLogging();
// Hardware renderer setup.
bool RequestHardwareRendererContext();
void SwitchToHardwareRenderer();
void SwitchToSoftwareRenderer();
static void HardwareRendererContextReset();
static void HardwareRendererContextDestroy();
// Disk control callbacks
static bool RETRO_CALLCONV DiskControlSetEjectState(bool ejected);
static bool RETRO_CALLCONV DiskControlGetEjectState();
static unsigned RETRO_CALLCONV DiskControlGetImageIndex();
static bool RETRO_CALLCONV DiskControlSetImageIndex(unsigned index);
static unsigned RETRO_CALLCONV DiskControlGetNumImages();
static bool RETRO_CALLCONV DiskControlReplaceImageIndex(unsigned index, const retro_game_info* info);
static bool RETRO_CALLCONV DiskControlAddImageIndex();
static bool RETRO_CALLCONV DiskControlSetInitialImage(unsigned index, const char* path);
static bool RETRO_CALLCONV DiskControlGetImagePath(unsigned index, char* path, size_t len);
static bool RETRO_CALLCONV DiskControlGetImageLabel(unsigned index, char* label, size_t len);
retro_hw_render_callback m_hw_render_callback = {};
std::unique_ptr<HostDisplay> m_hw_render_display;
bool m_hw_render_callback_valid = false;
bool m_using_hardware_renderer = false;
std::optional<u32> m_next_disc_index;
};
extern LibretroHostInterface g_libretro_host_interface;
// libretro callbacks
extern retro_environment_t g_retro_environment_callback;
extern retro_video_refresh_t g_retro_video_refresh_callback;
extern retro_audio_sample_t g_retro_audio_sample_callback;
extern retro_audio_sample_batch_t g_retro_audio_sample_batch_callback;
extern retro_input_poll_t g_retro_input_poll_callback;
extern retro_input_state_t g_retro_input_state_callback;