diff options
author | Kelebek1 <eeeedddccc@hotmail.co.uk> | 2023-02-11 17:27:43 +0100 |
---|---|---|
committer | Kelebek1 <eeeedddccc@hotmail.co.uk> | 2023-02-11 17:27:43 +0100 |
commit | 2e02ed8bb574255383667969a46280d435964c2c (patch) | |
tree | 0d3309c4e0f433c330650a0c69316938f7d052cc /src/audio_core/renderer | |
parent | Fix depop prepare receiving bad mix infos and writing out of bounds, and update aux a bit, may help (diff) | |
download | yuzu-2e02ed8bb574255383667969a46280d435964c2c.tar yuzu-2e02ed8bb574255383667969a46280d435964c2c.tar.gz yuzu-2e02ed8bb574255383667969a46280d435964c2c.tar.bz2 yuzu-2e02ed8bb574255383667969a46280d435964c2c.tar.lz yuzu-2e02ed8bb574255383667969a46280d435964c2c.tar.xz yuzu-2e02ed8bb574255383667969a46280d435964c2c.tar.zst yuzu-2e02ed8bb574255383667969a46280d435964c2c.zip |
Diffstat (limited to 'src/audio_core/renderer')
-rw-r--r-- | src/audio_core/renderer/command/effect/aux_.cpp | 76 |
1 files changed, 64 insertions, 12 deletions
diff --git a/src/audio_core/renderer/command/effect/aux_.cpp b/src/audio_core/renderer/command/effect/aux_.cpp index 0c69dcc28..c5650effa 100644 --- a/src/audio_core/renderer/command/effect/aux_.cpp +++ b/src/audio_core/renderer/command/effect/aux_.cpp @@ -20,10 +20,24 @@ static void ResetAuxBufferDsp(Core::Memory::Memory& memory, const CpuAddr aux_in return; } - auto info{reinterpret_cast<AuxInfo::AuxInfoDsp*>(memory.GetPointer(aux_info))}; - info->read_offset = 0; - info->write_offset = 0; - info->total_sample_count = 0; + AuxInfo::AuxInfoDsp info{}; + auto info_ptr{&info}; + bool host_safe{(aux_info & Core::Memory::YUZU_PAGEMASK) <= + (Core::Memory::YUZU_PAGESIZE - sizeof(AuxInfo::AuxInfoDsp))}; + + if (host_safe) [[likely]] { + info_ptr = memory.GetPointer<AuxInfo::AuxInfoDsp>(aux_info); + } else { + memory.ReadBlockUnsafe(aux_info, info_ptr, sizeof(AuxInfo::AuxInfoDsp)); + } + + info_ptr->read_offset = 0; + info_ptr->write_offset = 0; + info_ptr->total_sample_count = 0; + + if (!host_safe) [[unlikely]] { + memory.WriteBlockUnsafe(aux_info, info_ptr, sizeof(AuxInfo::AuxInfoDsp)); + } } /** @@ -71,9 +85,18 @@ static u32 WriteAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr send_info_, return 0; } - auto send_info{reinterpret_cast<AuxInfo::AuxInfoDsp*>(memory.GetPointer(send_info_))}; + AuxInfo::AuxInfoDsp send_info{}; + auto send_ptr = &send_info; + bool host_safe = (send_info_ & Core::Memory::YUZU_PAGEMASK) <= + (Core::Memory::YUZU_PAGESIZE - sizeof(AuxInfo::AuxInfoDsp)); + + if (host_safe) [[likely]] { + send_ptr = memory.GetPointer<AuxInfo::AuxInfoDsp>(send_info_); + } else { + memory.ReadBlockUnsafe(send_info_, send_ptr, sizeof(AuxInfo::AuxInfoDsp)); + } - u32 target_write_offset{send_info->write_offset + write_offset}; + u32 target_write_offset{send_ptr->write_offset + write_offset}; if (target_write_offset > count_max) { return 0; } @@ -82,7 +105,13 @@ static u32 WriteAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr send_info_, u32 read_pos{0}; while (write_count > 0) { u32 to_write{std::min(count_max - target_write_offset, write_count)}; - if (to_write) { + const auto write_addr = send_buffer + target_write_offset * sizeof(s32); + bool write_safe{(write_addr & Core::Memory::YUZU_PAGEMASK) <= + (Core::Memory::YUZU_PAGESIZE - (write_addr + to_write * sizeof(s32)))}; + if (write_safe) [[likely]] { + auto ptr = memory.GetPointer(write_addr); + std::memcpy(ptr, &input[read_pos], to_write * sizeof(s32)); + } else { memory.WriteBlockUnsafe(send_buffer + target_write_offset * sizeof(s32), &input[read_pos], to_write * sizeof(s32)); } @@ -92,7 +121,11 @@ static u32 WriteAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr send_info_, } if (update_count) { - send_info->write_offset = (send_info->write_offset + update_count) % count_max; + send_ptr->write_offset = (send_ptr->write_offset + update_count) % count_max; + } + + if (!host_safe) [[unlikely]] { + memory.WriteBlockUnsafe(send_info_, send_ptr, sizeof(AuxInfo::AuxInfoDsp)); } return write_count_; @@ -140,9 +173,18 @@ static u32 ReadAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr return_info_, return 0; } - auto return_info{reinterpret_cast<AuxInfo::AuxInfoDsp*>(memory.GetPointer(return_info_))}; + AuxInfo::AuxInfoDsp return_info{}; + auto return_ptr = &return_info; + bool host_safe = (return_info_ & Core::Memory::YUZU_PAGEMASK) <= + (Core::Memory::YUZU_PAGESIZE - sizeof(AuxInfo::AuxInfoDsp)); + + if (host_safe) [[likely]] { + return_ptr = memory.GetPointer<AuxInfo::AuxInfoDsp>(return_info_); + } else { + memory.ReadBlockUnsafe(return_info_, return_ptr, sizeof(AuxInfo::AuxInfoDsp)); + } - u32 target_read_offset{return_info->read_offset + read_offset}; + u32 target_read_offset{return_ptr->read_offset + read_offset}; if (target_read_offset > count_max) { return 0; } @@ -151,7 +193,13 @@ static u32 ReadAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr return_info_, u32 write_pos{0}; while (read_count > 0) { u32 to_read{std::min(count_max - target_read_offset, read_count)}; - if (to_read) { + const auto read_addr = return_buffer + target_read_offset * sizeof(s32); + bool read_safe{(read_addr & Core::Memory::YUZU_PAGEMASK) <= + (Core::Memory::YUZU_PAGESIZE - (read_addr + to_read * sizeof(s32)))}; + if (read_safe) [[likely]] { + auto ptr = memory.GetPointer(read_addr); + std::memcpy(&output[write_pos], ptr, to_read * sizeof(s32)); + } else { memory.ReadBlockUnsafe(return_buffer + target_read_offset * sizeof(s32), &output[write_pos], to_read * sizeof(s32)); } @@ -161,7 +209,11 @@ static u32 ReadAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr return_info_, } if (update_count) { - return_info->read_offset = (return_info->read_offset + update_count) % count_max; + return_ptr->read_offset = (return_ptr->read_offset + update_count) % count_max; + } + + if (!host_safe) [[unlikely]] { + memory.WriteBlockUnsafe(return_info_, return_ptr, sizeof(AuxInfo::AuxInfoDsp)); } return read_count_; |