Merge pull request #3322 from MerryMage/DSP

audio_core: Remove global state
This commit is contained in:
James Rowe 2018-02-19 09:08:37 -07:00 committed by GitHub
commit 33fe6c30e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 714 additions and 657 deletions

View file

@ -4,7 +4,8 @@
#include <memory>
#include <utility>
#include "audio_core/audio_core.h"
#include "audio_core/dsp_interface.h"
#include "audio_core/hle/hle.h"
#include "common/logging/log.h"
#include "core/arm/arm_interface.h"
#ifdef ARCHITECTURE_x86_64
@ -149,6 +150,8 @@ void System::Reschedule() {
System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
LOG_DEBUG(HW_Memory, "initialized OK");
CoreTiming::Init();
if (Settings::values.use_cpu_jit) {
#ifdef ARCHITECTURE_x86_64
cpu_core = std::make_unique<ARM_Dynarmic>(USER32MODE);
@ -160,13 +163,15 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
cpu_core = std::make_unique<ARM_DynCom>(USER32MODE);
}
dsp_core = std::make_unique<AudioCore::DspHle>();
dsp_core->SetSink(Settings::values.sink_id);
dsp_core->EnableStretching(Settings::values.enable_audio_stretching);
telemetry_session = std::make_unique<Core::TelemetrySession>();
CoreTiming::Init();
HW::Init();
Kernel::Init(system_mode);
Service::Init();
AudioCore::Init();
GDBStub::Init();
Movie::GetInstance().Init();
@ -196,15 +201,16 @@ void System::Shutdown() {
// Shutdown emulation session
Movie::GetInstance().Shutdown();
GDBStub::Shutdown();
AudioCore::Shutdown();
VideoCore::Shutdown();
Service::Shutdown();
Kernel::Shutdown();
HW::Shutdown();
CoreTiming::Shutdown();
cpu_core = nullptr;
app_loader = nullptr;
telemetry_session = nullptr;
dsp_core = nullptr;
cpu_core = nullptr;
CoreTiming::Shutdown();
app_loader = nullptr;
if (auto room_member = Network::GetRoomMember().lock()) {
Network::GameInfo game_info{};
room_member->SendGameInfo(game_info);

View file

@ -15,6 +15,10 @@
class EmuWindow;
class ARM_Interface;
namespace AudioCore {
class DspInterface;
}
namespace Core {
class System {
@ -102,6 +106,14 @@ public:
return *cpu_core;
}
/**
* Gets a reference to the emulated DSP.
* @returns A reference to the emulated DSP.
*/
AudioCore::DspInterface& DSP() {
return *dsp_core;
}
PerfStats perf_stats;
FrameLimiter frame_limiter;
@ -138,6 +150,9 @@ private:
///< ARM11 CPU core
std::unique_ptr<ARM_Interface> cpu_core;
///< DSP core
std::unique_ptr<AudioCore::DspInterface> dsp_core;
/// When true, signals that a reschedule should happen
bool reschedule_pending{};
@ -154,6 +169,10 @@ inline ARM_Interface& CPU() {
return System::GetInstance().CPU();
}
inline AudioCore::DspInterface& DSP() {
return System::GetInstance().DSP();
}
inline TelemetrySession& Telemetry() {
return System::GetInstance().TelemetrySession();
}

View file

@ -5,10 +5,12 @@
#include <algorithm>
#include <array>
#include <cinttypes>
#include "audio_core/hle/pipe.h"
#include "audio_core/audio_types.h"
#include "audio_core/dsp_interface.h"
#include "common/assert.h"
#include "common/hash.h"
#include "common/logging/log.h"
#include "core/core.h"
#include "core/hle/ipc.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/handle_table.h"
@ -16,7 +18,7 @@
#include "core/hle/service/dsp_dsp.h"
#include "core/memory.h"
using DspPipe = DSP::HLE::DspPipe;
using DspPipe = AudioCore::DspPipe;
namespace Service {
namespace DSP_DSP {
@ -44,7 +46,7 @@ public:
return one;
case InterruptType::Pipe: {
const size_t pipe_index = static_cast<size_t>(dsp_pipe);
ASSERT(pipe_index < DSP::HLE::NUM_DSP_PIPE);
ASSERT(pipe_index < AudioCore::num_dsp_pipe);
return pipe[pipe_index];
}
}
@ -73,7 +75,7 @@ private:
/// Currently unknown purpose
Kernel::SharedPtr<Kernel::Event> one = nullptr;
/// Each DSP pipe has an associated interrupt
std::array<Kernel::SharedPtr<Kernel::Event>, DSP::HLE::NUM_DSP_PIPE> pipe = {{}};
std::array<Kernel::SharedPtr<Kernel::Event>, AudioCore::num_dsp_pipe> pipe = {{}};
};
static InterruptEvents interrupt_events;
@ -216,7 +218,7 @@ static void RegisterInterruptEvents(Service::Interface* self) {
u32 pipe_index = cmd_buff[2];
u32 event_handle = cmd_buff[4];
ASSERT_MSG(type_index < NUM_INTERRUPT_TYPE && pipe_index < DSP::HLE::NUM_DSP_PIPE,
ASSERT_MSG(type_index < NUM_INTERRUPT_TYPE && pipe_index < AudioCore::num_dsp_pipe,
"Invalid type or pipe: type = %u, pipe = %u", type_index, pipe_index);
InterruptType type = static_cast<InterruptType>(cmd_buff[1]);
@ -289,7 +291,7 @@ static void WriteProcessPipe(Service::Interface* self) {
u32 size = cmd_buff[2];
u32 buffer = cmd_buff[4];
DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index);
AudioCore::DspPipe pipe = static_cast<AudioCore::DspPipe>(pipe_index);
if (IPC::StaticBufferDesc(size, 1) != cmd_buff[3]) {
LOG_ERROR(Service_DSP, "IPC static buffer descriptor failed validation (0x%X). pipe=%u, "
@ -312,12 +314,12 @@ static void WriteProcessPipe(Service::Interface* self) {
// The likely reason for this is that games tend to pass in garbage at these bytes
// because they read random bytes off the stack.
switch (pipe) {
case DSP::HLE::DspPipe::Audio:
case AudioCore::DspPipe::Audio:
ASSERT(message.size() >= 4);
message[2] = 0;
message[3] = 0;
break;
case DSP::HLE::DspPipe::Binary:
case AudioCore::DspPipe::Binary:
ASSERT(message.size() >= 8);
message[4] = 1;
message[5] = 0;
@ -326,7 +328,7 @@ static void WriteProcessPipe(Service::Interface* self) {
break;
}
DSP::HLE::PipeWrite(pipe, message);
Core::DSP().PipeWrite(pipe, message);
cmd_buff[0] = IPC::MakeHeader(0xD, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
@ -338,7 +340,7 @@ static void WriteProcessPipe(Service::Interface* self) {
* DSP_DSP::ReadPipeIfPossible service function
* A pipe is a means of communication between the ARM11 and DSP that occurs on
* hardware by writing to/reading from the DSP registers at 0x10203000.
* Pipes are used for initialisation. See also DSP::HLE::PipeRead.
* Pipes are used for initialisation. See also DspInterface::PipeRead.
* Inputs:
* 1 : Pipe Number
* 2 : Unknown
@ -356,7 +358,7 @@ static void ReadPipeIfPossible(Service::Interface* self) {
u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size
VAddr addr = cmd_buff[0x41];
DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index);
AudioCore::DspPipe pipe = static_cast<AudioCore::DspPipe>(pipe_index);
ASSERT_MSG(Memory::IsValidVirtualAddress(addr),
"Invalid addr: pipe=0x%08X, unknown=0x%08X, size=0x%X, buffer=0x%08X", pipe_index,
@ -364,8 +366,8 @@ static void ReadPipeIfPossible(Service::Interface* self) {
cmd_buff[0] = IPC::MakeHeader(0x10, 1, 2);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
if (DSP::HLE::GetPipeReadableSize(pipe) >= size) {
std::vector<u8> response = DSP::HLE::PipeRead(pipe, size);
if (Core::DSP().GetPipeReadableSize(pipe) >= size) {
std::vector<u8> response = Core::DSP().PipeRead(pipe, size);
Memory::WriteBlock(addr, response.data(), response.size());
@ -400,14 +402,14 @@ static void ReadPipe(Service::Interface* self) {
u32 size = cmd_buff[3] & 0xFFFF; // Lower 16 bits are size
VAddr addr = cmd_buff[0x41];
DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index);
AudioCore::DspPipe pipe = static_cast<AudioCore::DspPipe>(pipe_index);
ASSERT_MSG(Memory::IsValidVirtualAddress(addr),
"Invalid addr: pipe=0x%08X, unknown=0x%08X, size=0x%X, buffer=0x%08X", pipe_index,
unknown, size, addr);
if (DSP::HLE::GetPipeReadableSize(pipe) >= size) {
std::vector<u8> response = DSP::HLE::PipeRead(pipe, size);
if (Core::DSP().GetPipeReadableSize(pipe) >= size) {
std::vector<u8> response = Core::DSP().PipeRead(pipe, size);
Memory::WriteBlock(addr, response.data(), response.size());
@ -441,11 +443,11 @@ static void GetPipeReadableSize(Service::Interface* self) {
u32 pipe_index = cmd_buff[1];
u32 unknown = cmd_buff[2];
DSP::HLE::DspPipe pipe = static_cast<DSP::HLE::DspPipe>(pipe_index);
AudioCore::DspPipe pipe = static_cast<AudioCore::DspPipe>(pipe_index);
cmd_buff[0] = IPC::MakeHeader(0xF, 2, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
cmd_buff[2] = static_cast<u32>(DSP::HLE::GetPipeReadableSize(pipe));
cmd_buff[2] = static_cast<u32>(Core::DSP().GetPipeReadableSize(pipe));
LOG_DEBUG(Service_DSP, "pipe=%u, unknown=0x%08X, return cmd_buff[2]=0x%08X", pipe_index,
unknown, cmd_buff[2]);
@ -511,12 +513,12 @@ static void RecvData(Service::Interface* self) {
cmd_buff[0] = IPC::MakeHeader(0x1, 2, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
switch (DSP::HLE::GetDspState()) {
case DSP::HLE::DspState::On:
switch (Core::DSP().GetDspState()) {
case AudioCore::DspState::On:
cmd_buff[2] = 0;
break;
case DSP::HLE::DspState::Off:
case DSP::HLE::DspState::Sleeping:
case AudioCore::DspState::Off:
case AudioCore::DspState::Sleeping:
cmd_buff[2] = 1;
break;
default:

View file

@ -7,11 +7,9 @@
#include <string>
#include "core/hle/service/service.h"
namespace DSP {
namespace HLE {
namespace AudioCore {
enum class DspPipe;
}
}
namespace Service {
namespace DSP_DSP {
@ -30,7 +28,7 @@ public:
* Signal a specific DSP related interrupt of type == InterruptType::Pipe, pipe == pipe.
* @param pipe The DSP pipe for which to signal an interrupt for.
*/
void SignalPipeInterrupt(DSP::HLE::DspPipe pipe);
void SignalPipeInterrupt(AudioCore::DspPipe pipe);
} // namespace DSP_DSP
} // namespace Service

View file

@ -4,7 +4,7 @@
#include <array>
#include <cstring>
#include "audio_core/audio_core.h"
#include "audio_core/dsp_interface.h"
#include "common/assert.h"
#include "common/common_types.h"
#include "common/logging/log.h"
@ -311,7 +311,7 @@ u8* GetPhysicalPointer(PAddr address) {
target_pointer = vram.data() + offset_into_region;
break;
case DSP_RAM_PADDR:
target_pointer = AudioCore::GetDspMemory().data() + offset_into_region;
target_pointer = Core::DSP().GetDspMemory().data() + offset_into_region;
break;
case FCRAM_PADDR:
for (const auto& region : Kernel::memory_regions) {

View file

@ -2,7 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "audio_core/audio_core.h"
#include "audio_core/dsp_interface.h"
#include "core/core.h"
#include "core/gdbstub/gdbstub.h"
#include "core/hle/service/hid/hid.h"
#include "core/hle/service/ir/ir.h"
@ -28,8 +29,10 @@ void Apply() {
VideoCore::g_emu_window->UpdateCurrentFramebufferLayout(layout.width, layout.height);
}
AudioCore::SelectSink(values.sink_id);
AudioCore::EnableStretching(values.enable_audio_stretching);
if (Core::System::GetInstance().IsPoweredOn()) {
Core::DSP().SetSink(values.sink_id);
Core::DSP().EnableStretching(values.enable_audio_stretching);
}
Service::HID::ReloadInputDevices();
Service::IR::ReloadInputDevices();