diff options
| author | 2024-01-28 17:45:01 +0000 | |
|---|---|---|
| committer | 2024-01-28 18:51:43 +0000 | |
| commit | 19a2f12692f2ba871b4bec7c56757a455bf03e7d (patch) | |
| tree | 52aa105751bffd4b9bb671e307c3922bc0d0a6a0 /src/audio_core | |
| parent | Merge pull request #12808 from t895/uri-moment (diff) | |
| download | yuzu-19a2f12692f2ba871b4bec7c56757a455bf03e7d.tar.gz yuzu-19a2f12692f2ba871b4bec7c56757a455bf03e7d.tar.xz yuzu-19a2f12692f2ba871b4bec7c56757a455bf03e7d.zip | |
Use the input process handle to get the correct application's memory
Diffstat (limited to 'src/audio_core')
9 files changed, 46 insertions, 15 deletions
diff --git a/src/audio_core/adsp/apps/audio_renderer/audio_renderer.cpp b/src/audio_core/adsp/apps/audio_renderer/audio_renderer.cpp index ef301d8b4..7a76c3d0b 100644 --- a/src/audio_core/adsp/apps/audio_renderer/audio_renderer.cpp +++ b/src/audio_core/adsp/apps/audio_renderer/audio_renderer.cpp | |||
| @@ -89,11 +89,13 @@ u32 AudioRenderer::Receive(Direction dir) { | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | void AudioRenderer::SetCommandBuffer(s32 session_id, CpuAddr buffer, u64 size, u64 time_limit, | 91 | void AudioRenderer::SetCommandBuffer(s32 session_id, CpuAddr buffer, u64 size, u64 time_limit, |
| 92 | u64 applet_resource_user_id, bool reset) noexcept { | 92 | u64 applet_resource_user_id, Kernel::KProcess* process, |
| 93 | bool reset) noexcept { | ||
| 93 | command_buffers[session_id].buffer = buffer; | 94 | command_buffers[session_id].buffer = buffer; |
| 94 | command_buffers[session_id].size = size; | 95 | command_buffers[session_id].size = size; |
| 95 | command_buffers[session_id].time_limit = time_limit; | 96 | command_buffers[session_id].time_limit = time_limit; |
| 96 | command_buffers[session_id].applet_resource_user_id = applet_resource_user_id; | 97 | command_buffers[session_id].applet_resource_user_id = applet_resource_user_id; |
| 98 | command_buffers[session_id].process = process; | ||
| 97 | command_buffers[session_id].reset_buffer = reset; | 99 | command_buffers[session_id].reset_buffer = reset; |
| 98 | } | 100 | } |
| 99 | 101 | ||
| @@ -173,7 +175,8 @@ void AudioRenderer::Main(std::stop_token stop_token) { | |||
| 173 | // If there are no remaining commands (from the previous list), | 175 | // If there are no remaining commands (from the previous list), |
| 174 | // this is a new command list, initialize it. | 176 | // this is a new command list, initialize it. |
| 175 | if (command_buffer.remaining_command_count == 0) { | 177 | if (command_buffer.remaining_command_count == 0) { |
| 176 | command_list_processor.Initialize(system, command_buffer.buffer, | 178 | command_list_processor.Initialize(system, *command_buffer.process, |
| 179 | command_buffer.buffer, | ||
| 177 | command_buffer.size, streams[index]); | 180 | command_buffer.size, streams[index]); |
| 178 | } | 181 | } |
| 179 | 182 | ||
diff --git a/src/audio_core/adsp/apps/audio_renderer/audio_renderer.h b/src/audio_core/adsp/apps/audio_renderer/audio_renderer.h index 57b89d9fe..875266f27 100644 --- a/src/audio_core/adsp/apps/audio_renderer/audio_renderer.h +++ b/src/audio_core/adsp/apps/audio_renderer/audio_renderer.h | |||
| @@ -19,6 +19,10 @@ namespace Core { | |||
| 19 | class System; | 19 | class System; |
| 20 | } // namespace Core | 20 | } // namespace Core |
| 21 | 21 | ||
| 22 | namespace Kernel { | ||
| 23 | class KProcess; | ||
| 24 | } | ||
| 25 | |||
| 22 | namespace AudioCore { | 26 | namespace AudioCore { |
| 23 | namespace Sink { | 27 | namespace Sink { |
| 24 | class Sink; | 28 | class Sink; |
| @@ -69,7 +73,8 @@ public: | |||
| 69 | u32 Receive(Direction dir); | 73 | u32 Receive(Direction dir); |
| 70 | 74 | ||
| 71 | void SetCommandBuffer(s32 session_id, CpuAddr buffer, u64 size, u64 time_limit, | 75 | void SetCommandBuffer(s32 session_id, CpuAddr buffer, u64 size, u64 time_limit, |
| 72 | u64 applet_resource_user_id, bool reset) noexcept; | 76 | u64 applet_resource_user_id, Kernel::KProcess* process, |
| 77 | bool reset) noexcept; | ||
| 73 | u32 GetRemainCommandCount(s32 session_id) const noexcept; | 78 | u32 GetRemainCommandCount(s32 session_id) const noexcept; |
| 74 | void ClearRemainCommandCount(s32 session_id) noexcept; | 79 | void ClearRemainCommandCount(s32 session_id) noexcept; |
| 75 | u64 GetRenderingStartTick(s32 session_id) const noexcept; | 80 | u64 GetRenderingStartTick(s32 session_id) const noexcept; |
diff --git a/src/audio_core/adsp/apps/audio_renderer/command_buffer.h b/src/audio_core/adsp/apps/audio_renderer/command_buffer.h index 3fd1b09dc..d6a721f34 100644 --- a/src/audio_core/adsp/apps/audio_renderer/command_buffer.h +++ b/src/audio_core/adsp/apps/audio_renderer/command_buffer.h | |||
| @@ -6,6 +6,10 @@ | |||
| 6 | #include "audio_core/common/common.h" | 6 | #include "audio_core/common/common.h" |
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | 8 | ||
| 9 | namespace Kernel { | ||
| 10 | class KProcess; | ||
| 11 | } | ||
| 12 | |||
| 9 | namespace AudioCore::ADSP::AudioRenderer { | 13 | namespace AudioCore::ADSP::AudioRenderer { |
| 10 | 14 | ||
| 11 | struct CommandBuffer { | 15 | struct CommandBuffer { |
| @@ -14,6 +18,7 @@ struct CommandBuffer { | |||
| 14 | u64 size{}; | 18 | u64 size{}; |
| 15 | u64 time_limit{}; | 19 | u64 time_limit{}; |
| 16 | u64 applet_resource_user_id{}; | 20 | u64 applet_resource_user_id{}; |
| 21 | Kernel::KProcess* process{}; | ||
| 17 | bool reset_buffer{}; | 22 | bool reset_buffer{}; |
| 18 | // Set by the DSP | 23 | // Set by the DSP |
| 19 | u32 remaining_command_count{}; | 24 | u32 remaining_command_count{}; |
diff --git a/src/audio_core/adsp/apps/audio_renderer/command_list_processor.cpp b/src/audio_core/adsp/apps/audio_renderer/command_list_processor.cpp index 24e4d0496..eef2c0b89 100644 --- a/src/audio_core/adsp/apps/audio_renderer/command_list_processor.cpp +++ b/src/audio_core/adsp/apps/audio_renderer/command_list_processor.cpp | |||
| @@ -9,14 +9,15 @@ | |||
| 9 | #include "common/settings.h" | 9 | #include "common/settings.h" |
| 10 | #include "core/core.h" | 10 | #include "core/core.h" |
| 11 | #include "core/core_timing.h" | 11 | #include "core/core_timing.h" |
| 12 | #include "core/hle/kernel/k_process.h" | ||
| 12 | #include "core/memory.h" | 13 | #include "core/memory.h" |
| 13 | 14 | ||
| 14 | namespace AudioCore::ADSP::AudioRenderer { | 15 | namespace AudioCore::ADSP::AudioRenderer { |
| 15 | 16 | ||
| 16 | void CommandListProcessor::Initialize(Core::System& system_, CpuAddr buffer, u64 size, | 17 | void CommandListProcessor::Initialize(Core::System& system_, Kernel::KProcess& process, |
| 17 | Sink::SinkStream* stream_) { | 18 | CpuAddr buffer, u64 size, Sink::SinkStream* stream_) { |
| 18 | system = &system_; | 19 | system = &system_; |
| 19 | memory = &system->ApplicationMemory(); | 20 | memory = &process.GetMemory(); |
| 20 | stream = stream_; | 21 | stream = stream_; |
| 21 | header = reinterpret_cast<Renderer::CommandListHeader*>(buffer); | 22 | header = reinterpret_cast<Renderer::CommandListHeader*>(buffer); |
| 22 | commands = reinterpret_cast<u8*>(buffer + sizeof(Renderer::CommandListHeader)); | 23 | commands = reinterpret_cast<u8*>(buffer + sizeof(Renderer::CommandListHeader)); |
diff --git a/src/audio_core/adsp/apps/audio_renderer/command_list_processor.h b/src/audio_core/adsp/apps/audio_renderer/command_list_processor.h index 4e5fb793e..944e82505 100644 --- a/src/audio_core/adsp/apps/audio_renderer/command_list_processor.h +++ b/src/audio_core/adsp/apps/audio_renderer/command_list_processor.h | |||
| @@ -16,6 +16,10 @@ class Memory; | |||
| 16 | class System; | 16 | class System; |
| 17 | } // namespace Core | 17 | } // namespace Core |
| 18 | 18 | ||
| 19 | namespace Kernel { | ||
| 20 | class KProcess; | ||
| 21 | } | ||
| 22 | |||
| 19 | namespace AudioCore { | 23 | namespace AudioCore { |
| 20 | namespace Sink { | 24 | namespace Sink { |
| 21 | class SinkStream; | 25 | class SinkStream; |
| @@ -40,7 +44,8 @@ public: | |||
| 40 | * @param size - The size of the buffer. | 44 | * @param size - The size of the buffer. |
| 41 | * @param stream - The stream to be used for sending the samples. | 45 | * @param stream - The stream to be used for sending the samples. |
| 42 | */ | 46 | */ |
| 43 | void Initialize(Core::System& system, CpuAddr buffer, u64 size, Sink::SinkStream* stream); | 47 | void Initialize(Core::System& system, Kernel::KProcess& process, CpuAddr buffer, u64 size, |
| 48 | Sink::SinkStream* stream); | ||
| 44 | 49 | ||
| 45 | /** | 50 | /** |
| 46 | * Set the maximum processing time for this command list. | 51 | * Set the maximum processing time for this command list. |
diff --git a/src/audio_core/renderer/audio_renderer.cpp b/src/audio_core/renderer/audio_renderer.cpp index 09efe9be9..df03d03aa 100644 --- a/src/audio_core/renderer/audio_renderer.cpp +++ b/src/audio_core/renderer/audio_renderer.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include "audio_core/renderer/audio_renderer.h" | 6 | #include "audio_core/renderer/audio_renderer.h" |
| 7 | #include "audio_core/renderer/system_manager.h" | 7 | #include "audio_core/renderer/system_manager.h" |
| 8 | #include "core/core.h" | 8 | #include "core/core.h" |
| 9 | #include "core/hle/kernel/k_process.h" | ||
| 9 | #include "core/hle/kernel/k_transfer_memory.h" | 10 | #include "core/hle/kernel/k_transfer_memory.h" |
| 10 | #include "core/hle/service/audio/errors.h" | 11 | #include "core/hle/service/audio/errors.h" |
| 11 | 12 | ||
| @@ -17,7 +18,8 @@ Renderer::Renderer(Core::System& system_, Manager& manager_, Kernel::KEvent* ren | |||
| 17 | Result Renderer::Initialize(const AudioRendererParameterInternal& params, | 18 | Result Renderer::Initialize(const AudioRendererParameterInternal& params, |
| 18 | Kernel::KTransferMemory* transfer_memory, | 19 | Kernel::KTransferMemory* transfer_memory, |
| 19 | const u64 transfer_memory_size, const u32 process_handle, | 20 | const u64 transfer_memory_size, const u32 process_handle, |
| 20 | const u64 applet_resource_user_id, const s32 session_id) { | 21 | Kernel::KProcess& process, const u64 applet_resource_user_id, |
| 22 | const s32 session_id) { | ||
| 21 | if (params.execution_mode == ExecutionMode::Auto) { | 23 | if (params.execution_mode == ExecutionMode::Auto) { |
| 22 | if (!manager.AddSystem(system)) { | 24 | if (!manager.AddSystem(system)) { |
| 23 | LOG_ERROR(Service_Audio, | 25 | LOG_ERROR(Service_Audio, |
| @@ -28,7 +30,7 @@ Result Renderer::Initialize(const AudioRendererParameterInternal& params, | |||
| 28 | } | 30 | } |
| 29 | 31 | ||
| 30 | initialized = true; | 32 | initialized = true; |
| 31 | system.Initialize(params, transfer_memory, transfer_memory_size, process_handle, | 33 | system.Initialize(params, transfer_memory, transfer_memory_size, process_handle, process, |
| 32 | applet_resource_user_id, session_id); | 34 | applet_resource_user_id, session_id); |
| 33 | 35 | ||
| 34 | return ResultSuccess; | 36 | return ResultSuccess; |
diff --git a/src/audio_core/renderer/audio_renderer.h b/src/audio_core/renderer/audio_renderer.h index 24650278b..1219f74ca 100644 --- a/src/audio_core/renderer/audio_renderer.h +++ b/src/audio_core/renderer/audio_renderer.h | |||
| @@ -14,7 +14,8 @@ class System; | |||
| 14 | 14 | ||
| 15 | namespace Kernel { | 15 | namespace Kernel { |
| 16 | class KTransferMemory; | 16 | class KTransferMemory; |
| 17 | } | 17 | class KProcess; |
| 18 | } // namespace Kernel | ||
| 18 | 19 | ||
| 19 | namespace AudioCore { | 20 | namespace AudioCore { |
| 20 | struct AudioRendererParameterInternal; | 21 | struct AudioRendererParameterInternal; |
| @@ -44,7 +45,8 @@ public: | |||
| 44 | */ | 45 | */ |
| 45 | Result Initialize(const AudioRendererParameterInternal& params, | 46 | Result Initialize(const AudioRendererParameterInternal& params, |
| 46 | Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size, | 47 | Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size, |
| 47 | u32 process_handle, u64 applet_resource_user_id, s32 session_id); | 48 | u32 process_handle, Kernel::KProcess& process, u64 applet_resource_user_id, |
| 49 | s32 session_id); | ||
| 48 | 50 | ||
| 49 | /** | 51 | /** |
| 50 | * Finalize the renderer for shutdown. | 52 | * Finalize the renderer for shutdown. |
diff --git a/src/audio_core/renderer/system.cpp b/src/audio_core/renderer/system.cpp index 31f92087c..ca656edae 100644 --- a/src/audio_core/renderer/system.cpp +++ b/src/audio_core/renderer/system.cpp | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #include "core/core.h" | 32 | #include "core/core.h" |
| 33 | #include "core/core_timing.h" | 33 | #include "core/core_timing.h" |
| 34 | #include "core/hle/kernel/k_event.h" | 34 | #include "core/hle/kernel/k_event.h" |
| 35 | #include "core/hle/kernel/k_process.h" | ||
| 35 | #include "core/hle/kernel/k_transfer_memory.h" | 36 | #include "core/hle/kernel/k_transfer_memory.h" |
| 36 | #include "core/memory.h" | 37 | #include "core/memory.h" |
| 37 | 38 | ||
| @@ -101,7 +102,8 @@ System::System(Core::System& core_, Kernel::KEvent* adsp_rendered_event_) | |||
| 101 | 102 | ||
| 102 | Result System::Initialize(const AudioRendererParameterInternal& params, | 103 | Result System::Initialize(const AudioRendererParameterInternal& params, |
| 103 | Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size, | 104 | Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size, |
| 104 | u32 process_handle_, u64 applet_resource_user_id_, s32 session_id_) { | 105 | u32 process_handle_, Kernel::KProcess& process_, |
| 106 | u64 applet_resource_user_id_, s32 session_id_) { | ||
| 105 | if (!CheckValidRevision(params.revision)) { | 107 | if (!CheckValidRevision(params.revision)) { |
| 106 | return Service::Audio::ResultInvalidRevision; | 108 | return Service::Audio::ResultInvalidRevision; |
| 107 | } | 109 | } |
| @@ -117,6 +119,7 @@ Result System::Initialize(const AudioRendererParameterInternal& params, | |||
| 117 | behavior.SetUserLibRevision(params.revision); | 119 | behavior.SetUserLibRevision(params.revision); |
| 118 | 120 | ||
| 119 | process_handle = process_handle_; | 121 | process_handle = process_handle_; |
| 122 | process = &process_; | ||
| 120 | applet_resource_user_id = applet_resource_user_id_; | 123 | applet_resource_user_id = applet_resource_user_id_; |
| 121 | session_id = session_id_; | 124 | session_id = session_id_; |
| 122 | 125 | ||
| @@ -129,7 +132,7 @@ Result System::Initialize(const AudioRendererParameterInternal& params, | |||
| 129 | render_device = params.rendering_device; | 132 | render_device = params.rendering_device; |
| 130 | execution_mode = params.execution_mode; | 133 | execution_mode = params.execution_mode; |
| 131 | 134 | ||
| 132 | core.ApplicationMemory().ZeroBlock(transfer_memory->GetSourceAddress(), transfer_memory_size); | 135 | process->GetMemory().ZeroBlock(transfer_memory->GetSourceAddress(), transfer_memory_size); |
| 133 | 136 | ||
| 134 | // Note: We're not actually using the transfer memory because it's a pain to code for. | 137 | // Note: We're not actually using the transfer memory because it's a pain to code for. |
| 135 | // Allocate the memory normally instead and hope the game doesn't try to read anything back | 138 | // Allocate the memory normally instead and hope the game doesn't try to read anything back |
| @@ -613,7 +616,8 @@ void System::SendCommandToDsp() { | |||
| 613 | static_cast<u64>((time_limit_percent / 100) * 2'880'000.0 * | 616 | static_cast<u64>((time_limit_percent / 100) * 2'880'000.0 * |
| 614 | (static_cast<f32>(render_time_limit_percent) / 100.0f))}; | 617 | (static_cast<f32>(render_time_limit_percent) / 100.0f))}; |
| 615 | audio_renderer.SetCommandBuffer(session_id, translated_addr, command_size, time_limit, | 618 | audio_renderer.SetCommandBuffer(session_id, translated_addr, command_size, time_limit, |
| 616 | applet_resource_user_id, reset_command_buffers); | 619 | applet_resource_user_id, process, |
| 620 | reset_command_buffers); | ||
| 617 | reset_command_buffers = false; | 621 | reset_command_buffers = false; |
| 618 | command_buffer_size = command_size; | 622 | command_buffer_size = command_size; |
| 619 | if (remaining_command_count == 0) { | 623 | if (remaining_command_count == 0) { |
diff --git a/src/audio_core/renderer/system.h b/src/audio_core/renderer/system.h index 8a8341710..753a0b796 100644 --- a/src/audio_core/renderer/system.h +++ b/src/audio_core/renderer/system.h | |||
| @@ -29,6 +29,7 @@ class System; | |||
| 29 | 29 | ||
| 30 | namespace Kernel { | 30 | namespace Kernel { |
| 31 | class KEvent; | 31 | class KEvent; |
| 32 | class KProcess; | ||
| 32 | class KTransferMemory; | 33 | class KTransferMemory; |
| 33 | } // namespace Kernel | 34 | } // namespace Kernel |
| 34 | 35 | ||
| @@ -80,7 +81,8 @@ public: | |||
| 80 | */ | 81 | */ |
| 81 | Result Initialize(const AudioRendererParameterInternal& params, | 82 | Result Initialize(const AudioRendererParameterInternal& params, |
| 82 | Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size, | 83 | Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size, |
| 83 | u32 process_handle, u64 applet_resource_user_id, s32 session_id); | 84 | u32 process_handle, Kernel::KProcess& process, u64 applet_resource_user_id, |
| 85 | s32 session_id); | ||
| 84 | 86 | ||
| 85 | /** | 87 | /** |
| 86 | * Finalize the system. | 88 | * Finalize the system. |
| @@ -275,6 +277,8 @@ private: | |||
| 275 | Common::Event terminate_event{}; | 277 | Common::Event terminate_event{}; |
| 276 | /// Does what locks do | 278 | /// Does what locks do |
| 277 | std::mutex lock{}; | 279 | std::mutex lock{}; |
| 280 | /// Process this audio render is operating within, used for memory reads/writes. | ||
| 281 | Kernel::KProcess* process{}; | ||
| 278 | /// Handle for the process for this system, unused | 282 | /// Handle for the process for this system, unused |
| 279 | u32 process_handle{}; | 283 | u32 process_handle{}; |
| 280 | /// Applet resource id for this system, unused | 284 | /// Applet resource id for this system, unused |