diff options
| author | 2023-05-29 00:35:51 +0100 | |
|---|---|---|
| committer | 2023-07-02 23:09:48 +0100 | |
| commit | 6f7cb69c94bef0795f054d881e061745f69d1eda (patch) | |
| tree | cc0bec2fed92a5645886dde773add00c84d8b9f4 /src/audio_core/renderer | |
| parent | Merge pull request #10998 from Morph1984/qt-stop-messing-with-me (diff) | |
| download | yuzu-6f7cb69c94bef0795f054d881e061745f69d1eda.tar.gz yuzu-6f7cb69c94bef0795f054d881e061745f69d1eda.tar.xz yuzu-6f7cb69c94bef0795f054d881e061745f69d1eda.zip | |
Use spans over guest memory where possible instead of copying data.
Diffstat (limited to 'src/audio_core/renderer')
| -rw-r--r-- | src/audio_core/renderer/command/data_source/decode.cpp | 21 | ||||
| -rw-r--r-- | src/audio_core/renderer/command/effect/aux_.cpp | 82 |
2 files changed, 29 insertions, 74 deletions
diff --git a/src/audio_core/renderer/command/data_source/decode.cpp b/src/audio_core/renderer/command/data_source/decode.cpp index f45933203..257aa866e 100644 --- a/src/audio_core/renderer/command/data_source/decode.cpp +++ b/src/audio_core/renderer/command/data_source/decode.cpp | |||
| @@ -28,7 +28,6 @@ constexpr std::array<u8, 3> PitchBySrcQuality = {4, 8, 4}; | |||
| 28 | template <typename T> | 28 | template <typename T> |
| 29 | static u32 DecodePcm(Core::Memory::Memory& memory, std::span<s16> out_buffer, | 29 | static u32 DecodePcm(Core::Memory::Memory& memory, std::span<s16> out_buffer, |
| 30 | const DecodeArg& req) { | 30 | const DecodeArg& req) { |
| 31 | std::array<T, TempBufferSize> tmp_samples{}; | ||
| 32 | constexpr s32 min{std::numeric_limits<s16>::min()}; | 31 | constexpr s32 min{std::numeric_limits<s16>::min()}; |
| 33 | constexpr s32 max{std::numeric_limits<s16>::max()}; | 32 | constexpr s32 max{std::numeric_limits<s16>::max()}; |
| 34 | 33 | ||
| @@ -49,19 +48,18 @@ static u32 DecodePcm(Core::Memory::Memory& memory, std::span<s16> out_buffer, | |||
| 49 | const VAddr source{req.buffer + | 48 | const VAddr source{req.buffer + |
| 50 | (((req.start_offset + req.offset) * channel_count) * sizeof(T))}; | 49 | (((req.start_offset + req.offset) * channel_count) * sizeof(T))}; |
| 51 | const u64 size{channel_count * samples_to_decode}; | 50 | const u64 size{channel_count * samples_to_decode}; |
| 52 | const u64 size_bytes{size * sizeof(T)}; | ||
| 53 | |||
| 54 | memory.ReadBlockUnsafe(source, tmp_samples.data(), size_bytes); | ||
| 55 | 51 | ||
| 52 | Core::Memory::CpuGuestMemory<T, Core::Memory::GuestMemoryFlags::UnsafeRead> samples( | ||
| 53 | memory, source, size); | ||
| 56 | if constexpr (std::is_floating_point_v<T>) { | 54 | if constexpr (std::is_floating_point_v<T>) { |
| 57 | for (u32 i = 0; i < samples_to_decode; i++) { | 55 | for (u32 i = 0; i < samples_to_decode; i++) { |
| 58 | auto sample{static_cast<s32>(tmp_samples[i * channel_count + req.target_channel] * | 56 | auto sample{static_cast<s32>(samples[i * channel_count + req.target_channel] * |
| 59 | std::numeric_limits<s16>::max())}; | 57 | std::numeric_limits<s16>::max())}; |
| 60 | out_buffer[i] = static_cast<s16>(std::clamp(sample, min, max)); | 58 | out_buffer[i] = static_cast<s16>(std::clamp(sample, min, max)); |
| 61 | } | 59 | } |
| 62 | } else { | 60 | } else { |
| 63 | for (u32 i = 0; i < samples_to_decode; i++) { | 61 | for (u32 i = 0; i < samples_to_decode; i++) { |
| 64 | out_buffer[i] = tmp_samples[i * channel_count + req.target_channel]; | 62 | out_buffer[i] = samples[i * channel_count + req.target_channel]; |
| 65 | } | 63 | } |
| 66 | } | 64 | } |
| 67 | } break; | 65 | } break; |
| @@ -74,16 +72,17 @@ static u32 DecodePcm(Core::Memory::Memory& memory, std::span<s16> out_buffer, | |||
| 74 | } | 72 | } |
| 75 | 73 | ||
| 76 | const VAddr source{req.buffer + ((req.start_offset + req.offset) * sizeof(T))}; | 74 | const VAddr source{req.buffer + ((req.start_offset + req.offset) * sizeof(T))}; |
| 77 | memory.ReadBlockUnsafe(source, tmp_samples.data(), samples_to_decode * sizeof(T)); | 75 | Core::Memory::CpuGuestMemory<T, Core::Memory::GuestMemoryFlags::UnsafeRead> samples( |
| 76 | memory, source, samples_to_decode); | ||
| 78 | 77 | ||
| 79 | if constexpr (std::is_floating_point_v<T>) { | 78 | if constexpr (std::is_floating_point_v<T>) { |
| 80 | for (u32 i = 0; i < samples_to_decode; i++) { | 79 | for (u32 i = 0; i < samples_to_decode; i++) { |
| 81 | auto sample{static_cast<s32>(tmp_samples[i * channel_count + req.target_channel] * | 80 | auto sample{static_cast<s32>(samples[i * channel_count + req.target_channel] * |
| 82 | std::numeric_limits<s16>::max())}; | 81 | std::numeric_limits<s16>::max())}; |
| 83 | out_buffer[i] = static_cast<s16>(std::clamp(sample, min, max)); | 82 | out_buffer[i] = static_cast<s16>(std::clamp(sample, min, max)); |
| 84 | } | 83 | } |
| 85 | } else { | 84 | } else { |
| 86 | std::memcpy(out_buffer.data(), tmp_samples.data(), samples_to_decode * sizeof(s16)); | 85 | std::memcpy(out_buffer.data(), samples.data(), samples_to_decode * sizeof(s16)); |
| 87 | } | 86 | } |
| 88 | break; | 87 | break; |
| 89 | } | 88 | } |
| @@ -101,7 +100,6 @@ static u32 DecodePcm(Core::Memory::Memory& memory, std::span<s16> out_buffer, | |||
| 101 | */ | 100 | */ |
| 102 | static u32 DecodeAdpcm(Core::Memory::Memory& memory, std::span<s16> out_buffer, | 101 | static u32 DecodeAdpcm(Core::Memory::Memory& memory, std::span<s16> out_buffer, |
| 103 | const DecodeArg& req) { | 102 | const DecodeArg& req) { |
| 104 | std::array<u8, TempBufferSize> wavebuffer{}; | ||
| 105 | constexpr u32 SamplesPerFrame{14}; | 103 | constexpr u32 SamplesPerFrame{14}; |
| 106 | constexpr u32 NibblesPerFrame{16}; | 104 | constexpr u32 NibblesPerFrame{16}; |
| 107 | 105 | ||
| @@ -139,7 +137,8 @@ static u32 DecodeAdpcm(Core::Memory::Memory& memory, std::span<s16> out_buffer, | |||
| 139 | } | 137 | } |
| 140 | 138 | ||
| 141 | const auto size{std::max((samples_to_process / 8U) * SamplesPerFrame, 8U)}; | 139 | const auto size{std::max((samples_to_process / 8U) * SamplesPerFrame, 8U)}; |
| 142 | memory.ReadBlockUnsafe(req.buffer + position_in_frame / 2, wavebuffer.data(), size); | 140 | Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead> wavebuffer( |
| 141 | memory, req.buffer + position_in_frame / 2, size); | ||
| 143 | 142 | ||
| 144 | auto context{req.adpcm_context}; | 143 | auto context{req.adpcm_context}; |
| 145 | auto header{context->header}; | 144 | auto header{context->header}; |
diff --git a/src/audio_core/renderer/command/effect/aux_.cpp b/src/audio_core/renderer/command/effect/aux_.cpp index c5650effa..a3e12b3e7 100644 --- a/src/audio_core/renderer/command/effect/aux_.cpp +++ b/src/audio_core/renderer/command/effect/aux_.cpp | |||
| @@ -21,23 +21,13 @@ static void ResetAuxBufferDsp(Core::Memory::Memory& memory, const CpuAddr aux_in | |||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | AuxInfo::AuxInfoDsp info{}; | 23 | AuxInfo::AuxInfoDsp info{}; |
| 24 | auto info_ptr{&info}; | 24 | memory.ReadBlockUnsafe(aux_info, &info, sizeof(AuxInfo::AuxInfoDsp)); |
| 25 | bool host_safe{(aux_info & Core::Memory::YUZU_PAGEMASK) <= | ||
| 26 | (Core::Memory::YUZU_PAGESIZE - sizeof(AuxInfo::AuxInfoDsp))}; | ||
| 27 | 25 | ||
| 28 | if (host_safe) [[likely]] { | 26 | info.read_offset = 0; |
| 29 | info_ptr = memory.GetPointer<AuxInfo::AuxInfoDsp>(aux_info); | 27 | info.write_offset = 0; |
| 30 | } else { | 28 | info.total_sample_count = 0; |
| 31 | memory.ReadBlockUnsafe(aux_info, info_ptr, sizeof(AuxInfo::AuxInfoDsp)); | ||
| 32 | } | ||
| 33 | 29 | ||
| 34 | info_ptr->read_offset = 0; | 30 | memory.WriteBlockUnsafe(aux_info, &info, sizeof(AuxInfo::AuxInfoDsp)); |
| 35 | info_ptr->write_offset = 0; | ||
| 36 | info_ptr->total_sample_count = 0; | ||
| 37 | |||
| 38 | if (!host_safe) [[unlikely]] { | ||
| 39 | memory.WriteBlockUnsafe(aux_info, info_ptr, sizeof(AuxInfo::AuxInfoDsp)); | ||
| 40 | } | ||
| 41 | } | 31 | } |
| 42 | 32 | ||
| 43 | /** | 33 | /** |
| @@ -86,17 +76,9 @@ static u32 WriteAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr send_info_, | |||
| 86 | } | 76 | } |
| 87 | 77 | ||
| 88 | AuxInfo::AuxInfoDsp send_info{}; | 78 | AuxInfo::AuxInfoDsp send_info{}; |
| 89 | auto send_ptr = &send_info; | 79 | memory.ReadBlockUnsafe(send_info_, &send_info, sizeof(AuxInfo::AuxInfoDsp)); |
| 90 | bool host_safe = (send_info_ & Core::Memory::YUZU_PAGEMASK) <= | ||
| 91 | (Core::Memory::YUZU_PAGESIZE - sizeof(AuxInfo::AuxInfoDsp)); | ||
| 92 | |||
| 93 | if (host_safe) [[likely]] { | ||
| 94 | send_ptr = memory.GetPointer<AuxInfo::AuxInfoDsp>(send_info_); | ||
| 95 | } else { | ||
| 96 | memory.ReadBlockUnsafe(send_info_, send_ptr, sizeof(AuxInfo::AuxInfoDsp)); | ||
| 97 | } | ||
| 98 | 80 | ||
| 99 | u32 target_write_offset{send_ptr->write_offset + write_offset}; | 81 | u32 target_write_offset{send_info.write_offset + write_offset}; |
| 100 | if (target_write_offset > count_max) { | 82 | if (target_write_offset > count_max) { |
| 101 | return 0; | 83 | return 0; |
| 102 | } | 84 | } |
| @@ -105,15 +87,9 @@ static u32 WriteAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr send_info_, | |||
| 105 | u32 read_pos{0}; | 87 | u32 read_pos{0}; |
| 106 | while (write_count > 0) { | 88 | while (write_count > 0) { |
| 107 | u32 to_write{std::min(count_max - target_write_offset, write_count)}; | 89 | u32 to_write{std::min(count_max - target_write_offset, write_count)}; |
| 108 | const auto write_addr = send_buffer + target_write_offset * sizeof(s32); | 90 | if (to_write > 0) { |
| 109 | bool write_safe{(write_addr & Core::Memory::YUZU_PAGEMASK) <= | 91 | const auto write_addr = send_buffer + target_write_offset * sizeof(s32); |
| 110 | (Core::Memory::YUZU_PAGESIZE - (write_addr + to_write * sizeof(s32)))}; | 92 | memory.WriteBlockUnsafe(write_addr, &input[read_pos], to_write * sizeof(s32)); |
| 111 | if (write_safe) [[likely]] { | ||
| 112 | auto ptr = memory.GetPointer(write_addr); | ||
| 113 | std::memcpy(ptr, &input[read_pos], to_write * sizeof(s32)); | ||
| 114 | } else { | ||
| 115 | memory.WriteBlockUnsafe(send_buffer + target_write_offset * sizeof(s32), | ||
| 116 | &input[read_pos], to_write * sizeof(s32)); | ||
| 117 | } | 93 | } |
| 118 | target_write_offset = (target_write_offset + to_write) % count_max; | 94 | target_write_offset = (target_write_offset + to_write) % count_max; |
| 119 | write_count -= to_write; | 95 | write_count -= to_write; |
| @@ -121,13 +97,10 @@ static u32 WriteAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr send_info_, | |||
| 121 | } | 97 | } |
| 122 | 98 | ||
| 123 | if (update_count) { | 99 | if (update_count) { |
| 124 | send_ptr->write_offset = (send_ptr->write_offset + update_count) % count_max; | 100 | send_info.write_offset = (send_info.write_offset + update_count) % count_max; |
| 125 | } | ||
| 126 | |||
| 127 | if (!host_safe) [[unlikely]] { | ||
| 128 | memory.WriteBlockUnsafe(send_info_, send_ptr, sizeof(AuxInfo::AuxInfoDsp)); | ||
| 129 | } | 101 | } |
| 130 | 102 | ||
| 103 | memory.WriteBlockUnsafe(send_info_, &send_info, sizeof(AuxInfo::AuxInfoDsp)); | ||
| 131 | return write_count_; | 104 | return write_count_; |
| 132 | } | 105 | } |
| 133 | 106 | ||
| @@ -174,17 +147,9 @@ static u32 ReadAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr return_info_, | |||
| 174 | } | 147 | } |
| 175 | 148 | ||
| 176 | AuxInfo::AuxInfoDsp return_info{}; | 149 | AuxInfo::AuxInfoDsp return_info{}; |
| 177 | auto return_ptr = &return_info; | 150 | memory.ReadBlockUnsafe(return_info_, &return_info, sizeof(AuxInfo::AuxInfoDsp)); |
| 178 | bool host_safe = (return_info_ & Core::Memory::YUZU_PAGEMASK) <= | ||
| 179 | (Core::Memory::YUZU_PAGESIZE - sizeof(AuxInfo::AuxInfoDsp)); | ||
| 180 | 151 | ||
| 181 | if (host_safe) [[likely]] { | 152 | u32 target_read_offset{return_info.read_offset + read_offset}; |
| 182 | return_ptr = memory.GetPointer<AuxInfo::AuxInfoDsp>(return_info_); | ||
| 183 | } else { | ||
| 184 | memory.ReadBlockUnsafe(return_info_, return_ptr, sizeof(AuxInfo::AuxInfoDsp)); | ||
| 185 | } | ||
| 186 | |||
| 187 | u32 target_read_offset{return_ptr->read_offset + read_offset}; | ||
| 188 | if (target_read_offset > count_max) { | 153 | if (target_read_offset > count_max) { |
| 189 | return 0; | 154 | return 0; |
| 190 | } | 155 | } |
| @@ -193,15 +158,9 @@ static u32 ReadAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr return_info_, | |||
| 193 | u32 write_pos{0}; | 158 | u32 write_pos{0}; |
| 194 | while (read_count > 0) { | 159 | while (read_count > 0) { |
| 195 | u32 to_read{std::min(count_max - target_read_offset, read_count)}; | 160 | u32 to_read{std::min(count_max - target_read_offset, read_count)}; |
| 196 | const auto read_addr = return_buffer + target_read_offset * sizeof(s32); | 161 | if (to_read > 0) { |
| 197 | bool read_safe{(read_addr & Core::Memory::YUZU_PAGEMASK) <= | 162 | const auto read_addr = return_buffer + target_read_offset * sizeof(s32); |
| 198 | (Core::Memory::YUZU_PAGESIZE - (read_addr + to_read * sizeof(s32)))}; | 163 | memory.ReadBlockUnsafe(read_addr, &output[write_pos], to_read * sizeof(s32)); |
| 199 | if (read_safe) [[likely]] { | ||
| 200 | auto ptr = memory.GetPointer(read_addr); | ||
| 201 | std::memcpy(&output[write_pos], ptr, to_read * sizeof(s32)); | ||
| 202 | } else { | ||
| 203 | memory.ReadBlockUnsafe(return_buffer + target_read_offset * sizeof(s32), | ||
| 204 | &output[write_pos], to_read * sizeof(s32)); | ||
| 205 | } | 164 | } |
| 206 | target_read_offset = (target_read_offset + to_read) % count_max; | 165 | target_read_offset = (target_read_offset + to_read) % count_max; |
| 207 | read_count -= to_read; | 166 | read_count -= to_read; |
| @@ -209,13 +168,10 @@ static u32 ReadAuxBufferDsp(Core::Memory::Memory& memory, CpuAddr return_info_, | |||
| 209 | } | 168 | } |
| 210 | 169 | ||
| 211 | if (update_count) { | 170 | if (update_count) { |
| 212 | return_ptr->read_offset = (return_ptr->read_offset + update_count) % count_max; | 171 | return_info.read_offset = (return_info.read_offset + update_count) % count_max; |
| 213 | } | ||
| 214 | |||
| 215 | if (!host_safe) [[unlikely]] { | ||
| 216 | memory.WriteBlockUnsafe(return_info_, return_ptr, sizeof(AuxInfo::AuxInfoDsp)); | ||
| 217 | } | 172 | } |
| 218 | 173 | ||
| 174 | memory.WriteBlockUnsafe(return_info_, &return_info, sizeof(AuxInfo::AuxInfoDsp)); | ||
| 219 | return read_count_; | 175 | return read_count_; |
| 220 | } | 176 | } |
| 221 | 177 | ||