Merge pull request #4683 from wwylele/misc-global-clean

Misc global instance reference cleaup
This commit is contained in:
Weiyi Wang 2019-03-22 22:28:50 -04:00 committed by GitHub
commit 9b07ff9681
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 59 additions and 38 deletions

View file

@ -198,6 +198,8 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) {
dsp_core = std::make_unique<AudioCore::DspHle>(*memory); dsp_core = std::make_unique<AudioCore::DspHle>(*memory);
} }
memory->SetDSP(*dsp_core);
dsp_core->SetSink(Settings::values.sink_id, Settings::values.audio_device_id); dsp_core->SetSink(Settings::values.sink_id, Settings::values.audio_device_id);
dsp_core->EnableStretching(Settings::values.enable_audio_stretching); dsp_core->EnableStretching(Settings::values.enable_audio_stretching);

View file

@ -103,7 +103,7 @@ static u32 DecompressLZ11(const u8* in, u8* out) {
bool Module::LoadSharedFont() { bool Module::LoadSharedFont() {
u8 font_region_code; u8 font_region_code;
auto cfg = Service::CFG::GetModule(Core::System::GetInstance()); auto cfg = Service::CFG::GetModule(system);
ASSERT_MSG(cfg, "CFG Module missing!"); ASSERT_MSG(cfg, "CFG Module missing!");
switch (cfg->GetRegionValue()) { switch (cfg->GetRegionValue()) {
case 4: // CHN case 4: // CHN

View file

@ -394,7 +394,7 @@ void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager(); auto& service_manager = system.ServiceManager();
auto dsp = std::make_shared<DSP_DSP>(system); auto dsp = std::make_shared<DSP_DSP>(system);
dsp->InstallAsService(service_manager); dsp->InstallAsService(service_manager);
Core::DSP().SetServiceToInterrupt(std::move(dsp)); system.DSP().SetServiceToInterrupt(std::move(dsp));
} }
} // namespace Service::DSP } // namespace Service::DSP

View file

@ -64,7 +64,7 @@ enum class ResponseID : u8 {
ReadCalibrationData = 0x11, ReadCalibrationData = 0x11,
}; };
ExtraHID::ExtraHID(SendFunc send_func) : IRDevice(send_func) { ExtraHID::ExtraHID(SendFunc send_func, Core::Timing& timing) : IRDevice(send_func), timing(timing) {
LoadInputDevices(); LoadInputDevices();
// The data below was retrieved from a New 3DS // The data below was retrieved from a New 3DS
@ -145,11 +145,11 @@ ExtraHID::ExtraHID(SendFunc send_func) : IRDevice(send_func) {
0x65, 0x65,
}}; }};
hid_polling_callback_id = Core::System::GetInstance().CoreTiming().RegisterEvent( hid_polling_callback_id =
"ExtraHID::SendHIDStatus", [this](u64, s64 cycles_late) { timing.RegisterEvent("ExtraHID::SendHIDStatus", [this](u64, s64 cycles_late) {
SendHIDStatus(); SendHIDStatus();
Core::System::GetInstance().CoreTiming().ScheduleEvent( this->timing.ScheduleEvent(msToCycles(hid_period) - cycles_late,
msToCycles(hid_period) - cycles_late, hid_polling_callback_id); hid_polling_callback_id);
}); });
} }
@ -160,7 +160,7 @@ ExtraHID::~ExtraHID() {
void ExtraHID::OnConnect() {} void ExtraHID::OnConnect() {}
void ExtraHID::OnDisconnect() { void ExtraHID::OnDisconnect() {
Core::System::GetInstance().CoreTiming().UnscheduleEvent(hid_polling_callback_id, 0); timing.UnscheduleEvent(hid_polling_callback_id, 0);
} }
void ExtraHID::HandleConfigureHIDPollingRequest(const std::vector<u8>& request) { void ExtraHID::HandleConfigureHIDPollingRequest(const std::vector<u8>& request) {
@ -171,10 +171,9 @@ void ExtraHID::HandleConfigureHIDPollingRequest(const std::vector<u8>& request)
} }
// Change HID input polling interval // Change HID input polling interval
Core::System::GetInstance().CoreTiming().UnscheduleEvent(hid_polling_callback_id, 0); timing.UnscheduleEvent(hid_polling_callback_id, 0);
hid_period = request[1]; hid_period = request[1];
Core::System::GetInstance().CoreTiming().ScheduleEvent(msToCycles(hid_period), timing.ScheduleEvent(msToCycles(hid_period), hid_polling_callback_id);
hid_polling_callback_id);
} }
void ExtraHID::HandleReadCalibrationDataRequest(const std::vector<u8>& request_buf) { void ExtraHID::HandleReadCalibrationDataRequest(const std::vector<u8>& request_buf) {

View file

@ -13,6 +13,7 @@
namespace Core { namespace Core {
struct TimingEventType; struct TimingEventType;
class Timing;
} // namespace Core } // namespace Core
namespace Service::IR { namespace Service::IR {
@ -40,7 +41,7 @@ static_assert(sizeof(ExtraHIDResponse) == 6, "HID status response has wrong size
*/ */
class ExtraHID final : public IRDevice { class ExtraHID final : public IRDevice {
public: public:
explicit ExtraHID(SendFunc send_func); explicit ExtraHID(SendFunc send_func, Core::Timing& timing);
~ExtraHID(); ~ExtraHID();
void OnConnect() override; void OnConnect() override;
@ -56,6 +57,7 @@ private:
void HandleReadCalibrationDataRequest(const std::vector<u8>& request); void HandleReadCalibrationDataRequest(const std::vector<u8>& request);
void LoadInputDevices(); void LoadInputDevices();
Core::Timing& timing;
u8 hid_period; u8 hid_period;
Core::TimingEventType* hid_polling_callback_id; Core::TimingEventType* hid_polling_callback_id;
std::array<u8, 0x40> calibration_data; std::array<u8, 0x40> calibration_data;

View file

@ -418,8 +418,8 @@ IR_USER::IR_USER(Core::System& system) : ServiceFramework("ir:USER", 1) {
send_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:SendEvent"); send_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:SendEvent");
receive_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:ReceiveEvent"); receive_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:ReceiveEvent");
extra_hid = extra_hid = std::make_unique<ExtraHID>(
std::make_unique<ExtraHID>([this](const std::vector<u8>& data) { PutToReceive(data); }); [this](const std::vector<u8>& data) { PutToReceive(data); }, system.CoreTiming());
} }
IR_USER::~IR_USER() { IR_USER::~IR_USER() {

View file

@ -507,7 +507,7 @@ void Y2R_U::StartConversion(Kernel::HLERequestContext& ctx) {
Memory::RasterizerFlushVirtualRegion(conversion.dst.address, total_output_size, Memory::RasterizerFlushVirtualRegion(conversion.dst.address, total_output_size,
Memory::FlushMode::FlushAndInvalidate); Memory::FlushMode::FlushAndInvalidate);
HW::Y2R::PerformConversion(conversion); HW::Y2R::PerformConversion(system.Memory(), conversion);
completion_event->Signal(); completion_event->Signal();
@ -632,7 +632,7 @@ void Y2R_U::GetPackageParameter(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_Y2R, "called"); LOG_DEBUG(Service_Y2R, "called");
} }
Y2R_U::Y2R_U(Core::System& system) : ServiceFramework("y2r:u", 1) { Y2R_U::Y2R_U(Core::System& system) : ServiceFramework("y2r:u", 1), system(system) {
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0x00010040, &Y2R_U::SetInputFormat, "SetInputFormat"}, {0x00010040, &Y2R_U::SetInputFormat, "SetInputFormat"},
{0x00020000, &Y2R_U::GetInputFormat, "GetInputFormat"}, {0x00020000, &Y2R_U::GetInputFormat, "GetInputFormat"},

View file

@ -294,6 +294,8 @@ private:
void DriverFinalize(Kernel::HLERequestContext& ctx); void DriverFinalize(Kernel::HLERequestContext& ctx);
void GetPackageParameter(Kernel::HLERequestContext& ctx); void GetPackageParameter(Kernel::HLERequestContext& ctx);
Core::System& system;
Kernel::SharedPtr<Kernel::Event> completion_event; Kernel::SharedPtr<Kernel::Event> completion_event;
ConversionConfiguration conversion{}; ConversionConfiguration conversion{};
DitheringWeightParams dithering_weight_params{}; DitheringWeightParams dithering_weight_params{};

View file

@ -79,8 +79,9 @@ static void ConvertYUVToRGB(InputFormat input_format, const u8* input_Y, const u
/// Simulates an incoming CDMA transfer. The N parameter is used to automatically convert 16-bit /// Simulates an incoming CDMA transfer. The N parameter is used to automatically convert 16-bit
/// formats to 8-bit. /// formats to 8-bit.
template <std::size_t N> template <std::size_t N>
static void ReceiveData(u8* output, ConversionBuffer& buf, std::size_t amount_of_data) { static void ReceiveData(Memory::MemorySystem& memory, u8* output, ConversionBuffer& buf,
const u8* input = Core::System::GetInstance().Memory().GetPointer(buf.address); std::size_t amount_of_data) {
const u8* input = memory.GetPointer(buf.address);
std::size_t output_unit = buf.transfer_unit / N; std::size_t output_unit = buf.transfer_unit / N;
ASSERT(amount_of_data % output_unit == 0); ASSERT(amount_of_data % output_unit == 0);
@ -101,10 +102,10 @@ static void ReceiveData(u8* output, ConversionBuffer& buf, std::size_t amount_of
/// Convert intermediate RGB32 format to the final output format while simulating an outgoing CDMA /// Convert intermediate RGB32 format to the final output format while simulating an outgoing CDMA
/// transfer. /// transfer.
static void SendData(const u32* input, ConversionBuffer& buf, int amount_of_data, static void SendData(Memory::MemorySystem& memory, const u32* input, ConversionBuffer& buf,
OutputFormat output_format, u8 alpha) { int amount_of_data, OutputFormat output_format, u8 alpha) {
u8* output = Core::System::GetInstance().Memory().GetPointer(buf.address); u8* output = memory.GetPointer(buf.address);
while (amount_of_data > 0) { while (amount_of_data > 0) {
u8* unit_end = output + buf.transfer_unit; u8* unit_end = output + buf.transfer_unit;
@ -259,7 +260,7 @@ static void WriteTileToOutput(u32* output, const ImageTile& tile, int height, in
* Hardware behaves strangely (doesn't fire the completion interrupt, for example) in these cases, * Hardware behaves strangely (doesn't fire the completion interrupt, for example) in these cases,
* so they are believed to be invalid configurations anyway. * so they are believed to be invalid configurations anyway.
*/ */
void PerformConversion(ConversionConfiguration& cvt) { void PerformConversion(Memory::MemorySystem& memory, ConversionConfiguration& cvt) {
ASSERT(cvt.input_line_width % 8 == 0); ASSERT(cvt.input_line_width % 8 == 0);
ASSERT(cvt.block_alignment != BlockAlignment::Block8x8 || cvt.input_lines % 8 == 0); ASSERT(cvt.block_alignment != BlockAlignment::Block8x8 || cvt.input_lines % 8 == 0);
// Tiles per row // Tiles per row
@ -296,29 +297,29 @@ void PerformConversion(ConversionConfiguration& cvt) {
switch (cvt.input_format) { switch (cvt.input_format) {
case InputFormat::YUV422_Indiv8: case InputFormat::YUV422_Indiv8:
ReceiveData<1>(input_Y, cvt.src_Y, row_data_size); ReceiveData<1>(memory, input_Y, cvt.src_Y, row_data_size);
ReceiveData<1>(input_U, cvt.src_U, row_data_size / 2); ReceiveData<1>(memory, input_U, cvt.src_U, row_data_size / 2);
ReceiveData<1>(input_V, cvt.src_V, row_data_size / 2); ReceiveData<1>(memory, input_V, cvt.src_V, row_data_size / 2);
break; break;
case InputFormat::YUV420_Indiv8: case InputFormat::YUV420_Indiv8:
ReceiveData<1>(input_Y, cvt.src_Y, row_data_size); ReceiveData<1>(memory, input_Y, cvt.src_Y, row_data_size);
ReceiveData<1>(input_U, cvt.src_U, row_data_size / 4); ReceiveData<1>(memory, input_U, cvt.src_U, row_data_size / 4);
ReceiveData<1>(input_V, cvt.src_V, row_data_size / 4); ReceiveData<1>(memory, input_V, cvt.src_V, row_data_size / 4);
break; break;
case InputFormat::YUV422_Indiv16: case InputFormat::YUV422_Indiv16:
ReceiveData<2>(input_Y, cvt.src_Y, row_data_size); ReceiveData<2>(memory, input_Y, cvt.src_Y, row_data_size);
ReceiveData<2>(input_U, cvt.src_U, row_data_size / 2); ReceiveData<2>(memory, input_U, cvt.src_U, row_data_size / 2);
ReceiveData<2>(input_V, cvt.src_V, row_data_size / 2); ReceiveData<2>(memory, input_V, cvt.src_V, row_data_size / 2);
break; break;
case InputFormat::YUV420_Indiv16: case InputFormat::YUV420_Indiv16:
ReceiveData<2>(input_Y, cvt.src_Y, row_data_size); ReceiveData<2>(memory, input_Y, cvt.src_Y, row_data_size);
ReceiveData<2>(input_U, cvt.src_U, row_data_size / 4); ReceiveData<2>(memory, input_U, cvt.src_U, row_data_size / 4);
ReceiveData<2>(input_V, cvt.src_V, row_data_size / 4); ReceiveData<2>(memory, input_V, cvt.src_V, row_data_size / 4);
break; break;
case InputFormat::YUYV422_Interleaved: case InputFormat::YUYV422_Interleaved:
input_U = nullptr; input_U = nullptr;
input_V = nullptr; input_V = nullptr;
ReceiveData<1>(input_Y, cvt.src_YUYV, row_data_size * 2); ReceiveData<1>(memory, input_Y, cvt.src_YUYV, row_data_size * 2);
break; break;
} }
@ -372,7 +373,7 @@ void PerformConversion(ConversionConfiguration& cvt) {
// Note(yuriks): If additional optimization is required, output_format can be moved to a // Note(yuriks): If additional optimization is required, output_format can be moved to a
// template parameter, so that its dispatch can be moved to outside the inner loop. // template parameter, so that its dispatch can be moved to outside the inner loop.
SendData(reinterpret_cast<u32*>(data_buffer.get()), cvt.dst, (int)row_data_size, SendData(memory, reinterpret_cast<u32*>(data_buffer.get()), cvt.dst, (int)row_data_size,
cvt.output_format, (u8)cvt.alpha); cvt.output_format, (u8)cvt.alpha);
} }
} }

View file

@ -4,10 +4,14 @@
#pragma once #pragma once
namespace Memory {
class MemorySystem;
}
namespace Service::Y2R { namespace Service::Y2R {
struct ConversionConfiguration; struct ConversionConfiguration;
} // namespace Service::Y2R } // namespace Service::Y2R
namespace HW::Y2R { namespace HW::Y2R {
void PerformConversion(Service::Y2R::ConversionConfiguration& cvt); void PerformConversion(Memory::MemorySystem& memory, Service::Y2R::ConversionConfiguration& cvt);
} // namespace HW::Y2R } // namespace HW::Y2R

View file

@ -67,6 +67,7 @@ public:
std::vector<PageTable*> page_table_list; std::vector<PageTable*> page_table_list;
ARM_Interface* cpu = nullptr; ARM_Interface* cpu = nullptr;
AudioCore::DspInterface* dsp = nullptr;
}; };
MemorySystem::MemorySystem() : impl(std::make_unique<Impl>()) {} MemorySystem::MemorySystem() : impl(std::make_unique<Impl>()) {}
@ -325,7 +326,7 @@ u8* MemorySystem::GetPhysicalPointer(PAddr address) {
target_pointer = impl->vram.get() + offset_into_region; target_pointer = impl->vram.get() + offset_into_region;
break; break;
case DSP_RAM_PADDR: case DSP_RAM_PADDR:
target_pointer = Core::DSP().GetDspMemory().data() + offset_into_region; target_pointer = impl->dsp->GetDspMemory().data() + offset_into_region;
break; break;
case FCRAM_PADDR: case FCRAM_PADDR:
target_pointer = impl->fcram.get() + offset_into_region; target_pointer = impl->fcram.get() + offset_into_region;
@ -808,4 +809,8 @@ u8* MemorySystem::GetFCRAMPointer(u32 offset) {
return impl->fcram.get() + offset; return impl->fcram.get() + offset;
} }
void MemorySystem::SetDSP(AudioCore::DspInterface& dsp) {
impl->dsp = &dsp;
}
} // namespace Memory } // namespace Memory

View file

@ -18,6 +18,10 @@ namespace Kernel {
class Process; class Process;
} }
namespace AudioCore {
class DspInterface;
}
namespace Memory { namespace Memory {
// Are defined in a system header // Are defined in a system header
@ -292,6 +296,8 @@ public:
/// Unregisters page table for rasterizer cache marking /// Unregisters page table for rasterizer cache marking
void UnregisterPageTable(PageTable* page_table); void UnregisterPageTable(PageTable* page_table);
void SetDSP(AudioCore::DspInterface& dsp);
private: private:
template <typename T> template <typename T>
T Read(const VAddr vaddr); T Read(const VAddr vaddr);