mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-25 22:57:22 +00:00
DSP: Create backing memory for entire DSP RAM
Also move address space mapping out of video_core.
This commit is contained in:
parent
d3db770cad
commit
b4a93cfdde
5 changed files with 42 additions and 32 deletions
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "audio_core/audio_core.h"
|
#include "audio_core/audio_core.h"
|
||||||
|
@ -10,8 +11,8 @@
|
||||||
#include "audio_core/null_sink.h"
|
#include "audio_core/null_sink.h"
|
||||||
#include "audio_core/sink.h"
|
#include "audio_core/sink.h"
|
||||||
#include "audio_core/sink_details.h"
|
#include "audio_core/sink_details.h"
|
||||||
|
#include "common/common_types.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "core/hle/kernel/vm_manager.h"
|
|
||||||
#include "core/hle/service/dsp_dsp.h"
|
#include "core/hle/service/dsp_dsp.h"
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
@ -39,20 +40,8 @@ void Init() {
|
||||||
CoreTiming::ScheduleEvent(audio_frame_ticks, tick_event);
|
CoreTiming::ScheduleEvent(audio_frame_ticks, tick_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddAddressSpace(Kernel::VMManager& address_space) {
|
std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() {
|
||||||
auto r0_vma = address_space
|
return DSP::HLE::g_dsp_memory.raw_memory;
|
||||||
.MapBackingMemory(DSP::HLE::region0_base,
|
|
||||||
reinterpret_cast<u8*>(&DSP::HLE::g_regions[0]),
|
|
||||||
sizeof(DSP::HLE::SharedMemory), Kernel::MemoryState::IO)
|
|
||||||
.MoveFrom();
|
|
||||||
address_space.Reprotect(r0_vma, Kernel::VMAPermission::ReadWrite);
|
|
||||||
|
|
||||||
auto r1_vma = address_space
|
|
||||||
.MapBackingMemory(DSP::HLE::region1_base,
|
|
||||||
reinterpret_cast<u8*>(&DSP::HLE::g_regions[1]),
|
|
||||||
sizeof(DSP::HLE::SharedMemory), Kernel::MemoryState::IO)
|
|
||||||
.MoveFrom();
|
|
||||||
address_space.Reprotect(r1_vma, Kernel::VMAPermission::ReadWrite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectSink(std::string sink_id) {
|
void SelectSink(std::string sink_id) {
|
||||||
|
|
|
@ -4,11 +4,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "common/common_types.h"
|
||||||
namespace Kernel {
|
#include "core/memory.h"
|
||||||
class VMManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
|
||||||
|
@ -17,8 +16,8 @@ constexpr int native_sample_rate = 32728; ///< 32kHz
|
||||||
/// Initialise Audio Core
|
/// Initialise Audio Core
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
/// Add DSP address spaces to a Process.
|
/// Returns a reference to the array backing DSP memory
|
||||||
void AddAddressSpace(Kernel::VMManager& vm_manager);
|
std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory();
|
||||||
|
|
||||||
/// Select the sink to use based on sink id.
|
/// Select the sink to use based on sink id.
|
||||||
void SelectSink(std::string sink_id);
|
void SelectSink(std::string sink_id);
|
||||||
|
@ -29,4 +28,4 @@ void EnableStretching(bool enable);
|
||||||
/// Shutdown Audio Core
|
/// Shutdown Audio Core
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
} // namespace
|
} // namespace AudioCore
|
||||||
|
|
|
@ -16,31 +16,33 @@ namespace HLE {
|
||||||
|
|
||||||
// Region management
|
// Region management
|
||||||
|
|
||||||
std::array<SharedMemory, 2> g_regions;
|
DspMemory g_dsp_memory;
|
||||||
|
|
||||||
static size_t CurrentRegionIndex() {
|
static size_t CurrentRegionIndex() {
|
||||||
// The region with the higher frame counter is chosen unless there is wraparound.
|
// The region with the higher frame counter is chosen unless there is wraparound.
|
||||||
// This function only returns a 0 or 1.
|
// This function only returns a 0 or 1.
|
||||||
|
u16 frame_counter_0 = g_dsp_memory.region_0.frame_counter;
|
||||||
|
u16 frame_counter_1 = g_dsp_memory.region_1.frame_counter;
|
||||||
|
|
||||||
if (g_regions[0].frame_counter == 0xFFFFu && g_regions[1].frame_counter != 0xFFFEu) {
|
if (frame_counter_0 == 0xFFFFu && frame_counter_1 != 0xFFFEu) {
|
||||||
// Wraparound has occurred.
|
// Wraparound has occurred.
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_regions[1].frame_counter == 0xFFFFu && g_regions[0].frame_counter != 0xFFFEu) {
|
if (frame_counter_1 == 0xFFFFu && frame_counter_0 != 0xFFFEu) {
|
||||||
// Wraparound has occurred.
|
// Wraparound has occurred.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (g_regions[0].frame_counter > g_regions[1].frame_counter) ? 0 : 1;
|
return (frame_counter_0 > frame_counter_1) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SharedMemory& ReadRegion() {
|
static SharedMemory& ReadRegion() {
|
||||||
return g_regions[CurrentRegionIndex()];
|
return CurrentRegionIndex() == 0 ? g_dsp_memory.region_0 : g_dsp_memory.region_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SharedMemory& WriteRegion() {
|
static SharedMemory& WriteRegion() {
|
||||||
return g_regions[1 - CurrentRegionIndex()];
|
return CurrentRegionIndex() != 0 ? g_dsp_memory.region_0 : g_dsp_memory.region_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Audio processing and mixing
|
// Audio processing and mixing
|
||||||
|
|
|
@ -31,8 +31,8 @@ namespace HLE {
|
||||||
// double-buffer. The frame counter is located as the very last u16 of each region and is
|
// double-buffer. The frame counter is located as the very last u16 of each region and is
|
||||||
// incremented each audio tick.
|
// incremented each audio tick.
|
||||||
|
|
||||||
constexpr VAddr region0_base = 0x1FF50000;
|
constexpr u32 region0_offset = 0x50000;
|
||||||
constexpr VAddr region1_base = 0x1FF70000;
|
constexpr u32 region1_offset = 0x70000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DSP is native 16-bit. The DSP also appears to be big-endian. When reading 32-bit numbers from
|
* The DSP is native 16-bit. The DSP also appears to be big-endian. When reading 32-bit numbers from
|
||||||
|
@ -512,7 +512,22 @@ struct SharedMemory {
|
||||||
};
|
};
|
||||||
ASSERT_DSP_STRUCT(SharedMemory, 0x8000);
|
ASSERT_DSP_STRUCT(SharedMemory, 0x8000);
|
||||||
|
|
||||||
extern std::array<SharedMemory, 2> g_regions;
|
union DspMemory {
|
||||||
|
std::array<u8, 0x80000> raw_memory;
|
||||||
|
struct {
|
||||||
|
u8 unused_0[0x50000];
|
||||||
|
SharedMemory region_0;
|
||||||
|
u8 unused_1[0x18000];
|
||||||
|
SharedMemory region_1;
|
||||||
|
u8 unused_2[0x8000];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
static_assert(offsetof(DspMemory, region_0) == region0_offset,
|
||||||
|
"DSP region 0 is at the wrong offset");
|
||||||
|
static_assert(offsetof(DspMemory, region_1) == region1_offset,
|
||||||
|
"DSP region 1 is at the wrong offset");
|
||||||
|
|
||||||
|
extern DspMemory g_dsp_memory;
|
||||||
|
|
||||||
// Structures must have an offset that is a multiple of two.
|
// Structures must have an offset that is a multiple of two.
|
||||||
static_assert(offsetof(SharedMemory, frame_counter) % 2 == 0,
|
static_assert(offsetof(SharedMemory, frame_counter) % 2 == 0,
|
||||||
|
|
|
@ -137,7 +137,12 @@ void InitLegacyAddressSpace(Kernel::VMManager& address_space) {
|
||||||
.MoveFrom();
|
.MoveFrom();
|
||||||
address_space.Reprotect(shared_page_vma, VMAPermission::Read);
|
address_space.Reprotect(shared_page_vma, VMAPermission::Read);
|
||||||
|
|
||||||
AudioCore::AddAddressSpace(address_space);
|
auto& dsp_ram = AudioCore::GetDspMemory();
|
||||||
|
auto dsp_vma = address_space
|
||||||
|
.MapBackingMemory(DSP_RAM_VADDR, dsp_ram.data(), dsp_ram.size(),
|
||||||
|
Kernel::MemoryState::IO)
|
||||||
|
.MoveFrom();
|
||||||
|
address_space.Reprotect(dsp_vma, Kernel::VMAPermission::ReadWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in a new issue