Merge pull request #3996 from NarcolepticK/dsp-remove-weakptr

service/dsp: Clean up global state
This commit is contained in:
Weiyi Wang 2018-08-02 11:14:59 +03:00 committed by GitHub
commit 14bc20fc8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 24 deletions

View file

@ -11,6 +11,12 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "core/memory.h" #include "core/memory.h"
namespace Service {
namespace DSP {
class DSP_DSP;
} // namespace DSP
} // namespace Service
namespace AudioCore { namespace AudioCore {
class Sink; class Sink;
@ -60,6 +66,9 @@ public:
/// Returns a reference to the array backing DSP memory /// Returns a reference to the array backing DSP memory
virtual std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() = 0; virtual std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() = 0;
/// Sets the dsp class that we trigger interrupts for
virtual void SetServiceToInterrupt(std::weak_ptr<Service::DSP::DSP_DSP> dsp) = 0;
/// Select the sink to use based on sink id. /// Select the sink to use based on sink id.
void SetSink(const std::string& sink_id, const std::string& audio_device); void SetSink(const std::string& sink_id, const std::string& audio_device);
/// Get the current sink /// Get the current sink

View file

@ -13,7 +13,9 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hle/service/dsp/dsp_dsp.h"
using InterruptType = Service::DSP::DSP_DSP::InterruptType;
using Service::DSP::DSP_DSP;
namespace AudioCore { namespace AudioCore {
@ -32,6 +34,8 @@ public:
std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory(); std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory();
void SetServiceToInterrupt(std::weak_ptr<DSP_DSP> dsp);
private: private:
void ResetPipes(); void ResetPipes();
void WriteU16(DspPipe pipe_number, u16 value); void WriteU16(DspPipe pipe_number, u16 value);
@ -60,6 +64,8 @@ private:
DspHle& parent; DspHle& parent;
CoreTiming::EventType* tick_event; CoreTiming::EventType* tick_event;
std::weak_ptr<DSP_DSP> dsp_dsp;
}; };
DspHle::Impl::Impl(DspHle& parent_) : parent(parent_) { DspHle::Impl::Impl(DspHle& parent_) : parent(parent_) {
@ -187,6 +193,10 @@ std::array<u8, Memory::DSP_RAM_SIZE>& DspHle::Impl::GetDspMemory() {
return dsp_memory.raw_memory; return dsp_memory.raw_memory;
} }
void DspHle::Impl::SetServiceToInterrupt(std::weak_ptr<DSP_DSP> dsp) {
dsp_dsp = std::move(dsp);
}
void DspHle::Impl::ResetPipes() { void DspHle::Impl::ResetPipes() {
for (auto& data : pipe_data) { for (auto& data : pipe_data) {
data.clear(); data.clear();
@ -231,7 +241,9 @@ void DspHle::Impl::AudioPipeWriteStructAddresses() {
WriteU16(DspPipe::Audio, addr); WriteU16(DspPipe::Audio, addr);
} }
// Signal that we have data on this pipe. // Signal that we have data on this pipe.
Service::DSP::SignalPipeInterrupt(DspPipe::Audio); if (auto service = dsp_dsp.lock()) {
service->SignalInterrupt(InterruptType::Pipe, DspPipe::Audio);
}
} }
size_t DspHle::Impl::CurrentRegionIndex() const { size_t DspHle::Impl::CurrentRegionIndex() const {
@ -307,9 +319,11 @@ bool DspHle::Impl::Tick() {
void DspHle::Impl::AudioTickCallback(int cycles_late) { void DspHle::Impl::AudioTickCallback(int cycles_late) {
if (Tick()) { if (Tick()) {
// TODO(merry): Signal all the other interrupts as appropriate. // TODO(merry): Signal all the other interrupts as appropriate.
Service::DSP::SignalPipeInterrupt(DspPipe::Audio); if (auto service = dsp_dsp.lock()) {
// HACK(merry): Added to prevent regressions. Will remove soon. service->SignalInterrupt(InterruptType::Pipe, DspPipe::Audio);
Service::DSP::SignalPipeInterrupt(DspPipe::Binary); // HACK(merry): Added to prevent regressions. Will remove soon.
service->SignalInterrupt(InterruptType::Pipe, DspPipe::Binary);
}
} }
// Reschedule recurrent event // Reschedule recurrent event
@ -339,4 +353,8 @@ std::array<u8, Memory::DSP_RAM_SIZE>& DspHle::GetDspMemory() {
return impl->GetDspMemory(); return impl->GetDspMemory();
} }
void DspHle::SetServiceToInterrupt(std::weak_ptr<DSP_DSP> dsp) {
impl->SetServiceToInterrupt(std::move(dsp));
}
} // namespace AudioCore } // namespace AudioCore

View file

@ -10,6 +10,7 @@
#include "audio_core/audio_types.h" #include "audio_core/audio_types.h"
#include "audio_core/dsp_interface.h" #include "audio_core/dsp_interface.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/service/dsp/dsp_dsp.h"
#include "core/memory.h" #include "core/memory.h"
namespace AudioCore { namespace AudioCore {
@ -27,6 +28,8 @@ public:
std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() override; std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() override;
void SetServiceToInterrupt(std::weak_ptr<Service::DSP::DSP_DSP> dsp) override;
private: private:
struct Impl; struct Impl;
friend struct Impl; friend struct Impl;

View file

@ -21,8 +21,6 @@ enum class DspPipe;
namespace Service { namespace Service {
namespace DSP { namespace DSP {
static std::weak_ptr<DSP_DSP> dsp_dsp;
void DSP_DSP::RecvData(Kernel::HLERequestContext& ctx) { void DSP_DSP::RecvData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x01, 1, 0); IPC::RequestParser rp(ctx, 0x01, 1, 0);
const u32 register_number = rp.Pop<u32>(); const u32 register_number = rp.Pop<u32>();
@ -313,6 +311,10 @@ void DSP_DSP::ForceHeadphoneOut(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_DSP, "(STUBBED) called, force={}", force); LOG_DEBUG(Service_DSP, "(STUBBED) called, force={}", force);
} }
// DSP Interrupts:
// The audio-pipe interrupt occurs every frame tick. Userland programs normally have a thread
// that's waiting for an interrupt event. Immediately after this interrupt event, userland
// normally updates the state in the next region and increments the relevant frame counter by two.
void DSP_DSP::SignalInterrupt(InterruptType type, DspPipe pipe) { void DSP_DSP::SignalInterrupt(InterruptType type, DspPipe pipe) {
LOG_DEBUG(Service_DSP, "called, type={}, pipe={}", static_cast<u32>(type), LOG_DEBUG(Service_DSP, "called, type={}, pipe={}", static_cast<u32>(type),
static_cast<u32>(pipe)); static_cast<u32>(pipe));
@ -398,20 +400,10 @@ DSP_DSP::~DSP_DSP() {
pipes = {}; pipes = {};
} }
// DSP Interrupts:
// The audio-pipe interrupt occurs every frame tick. Userland programs normally have a thread
// that's waiting for an interrupt event. Immediately after this interrupt event, userland
// normally updates the state in the next region and increments the relevant frame counter by two.
void SignalPipeInterrupt(DspPipe pipe) {
auto dsp = dsp_dsp.lock();
ASSERT(dsp != nullptr);
return dsp->SignalInterrupt(InterruptType::Pipe, pipe);
}
void InstallInterfaces(SM::ServiceManager& service_manager) { void InstallInterfaces(SM::ServiceManager& service_manager) {
auto dsp = std::make_shared<DSP_DSP>(); auto dsp = std::make_shared<DSP_DSP>();
dsp->InstallAsService(service_manager); dsp->InstallAsService(service_manager);
dsp_dsp = dsp; Core::DSP().SetServiceToInterrupt(std::move(dsp));
} }
} // namespace DSP } // namespace DSP

View file

@ -251,12 +251,6 @@ private:
std::array<Kernel::SharedPtr<Kernel::Event>, AudioCore::num_dsp_pipe> pipes = {{}}; std::array<Kernel::SharedPtr<Kernel::Event>, AudioCore::num_dsp_pipe> pipes = {{}};
}; };
/**
* 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(AudioCore::DspPipe pipe);
void InstallInterfaces(SM::ServiceManager& service_manager); void InstallInterfaces(SM::ServiceManager& service_manager);
} // namespace DSP } // namespace DSP