Use the input process handle to get the correct application's memory
This commit is contained in:
parent
bd8635e26a
commit
19a2f12692
@ -89,11 +89,13 @@ u32 AudioRenderer::Receive(Direction dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AudioRenderer::SetCommandBuffer(s32 session_id, CpuAddr buffer, u64 size, u64 time_limit,
|
void AudioRenderer::SetCommandBuffer(s32 session_id, CpuAddr buffer, u64 size, u64 time_limit,
|
||||||
u64 applet_resource_user_id, bool reset) noexcept {
|
u64 applet_resource_user_id, Kernel::KProcess* process,
|
||||||
|
bool reset) noexcept {
|
||||||
command_buffers[session_id].buffer = buffer;
|
command_buffers[session_id].buffer = buffer;
|
||||||
command_buffers[session_id].size = size;
|
command_buffers[session_id].size = size;
|
||||||
command_buffers[session_id].time_limit = time_limit;
|
command_buffers[session_id].time_limit = time_limit;
|
||||||
command_buffers[session_id].applet_resource_user_id = applet_resource_user_id;
|
command_buffers[session_id].applet_resource_user_id = applet_resource_user_id;
|
||||||
|
command_buffers[session_id].process = process;
|
||||||
command_buffers[session_id].reset_buffer = reset;
|
command_buffers[session_id].reset_buffer = reset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +175,8 @@ void AudioRenderer::Main(std::stop_token stop_token) {
|
|||||||
// If there are no remaining commands (from the previous list),
|
// If there are no remaining commands (from the previous list),
|
||||||
// this is a new command list, initialize it.
|
// this is a new command list, initialize it.
|
||||||
if (command_buffer.remaining_command_count == 0) {
|
if (command_buffer.remaining_command_count == 0) {
|
||||||
command_list_processor.Initialize(system, command_buffer.buffer,
|
command_list_processor.Initialize(system, *command_buffer.process,
|
||||||
|
command_buffer.buffer,
|
||||||
command_buffer.size, streams[index]);
|
command_buffer.size, streams[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,10 @@ namespace Core {
|
|||||||
class System;
|
class System;
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class KProcess;
|
||||||
|
}
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
namespace Sink {
|
namespace Sink {
|
||||||
class Sink;
|
class Sink;
|
||||||
@ -69,7 +73,8 @@ public:
|
|||||||
u32 Receive(Direction dir);
|
u32 Receive(Direction dir);
|
||||||
|
|
||||||
void SetCommandBuffer(s32 session_id, CpuAddr buffer, u64 size, u64 time_limit,
|
void SetCommandBuffer(s32 session_id, CpuAddr buffer, u64 size, u64 time_limit,
|
||||||
u64 applet_resource_user_id, bool reset) noexcept;
|
u64 applet_resource_user_id, Kernel::KProcess* process,
|
||||||
|
bool reset) noexcept;
|
||||||
u32 GetRemainCommandCount(s32 session_id) const noexcept;
|
u32 GetRemainCommandCount(s32 session_id) const noexcept;
|
||||||
void ClearRemainCommandCount(s32 session_id) noexcept;
|
void ClearRemainCommandCount(s32 session_id) noexcept;
|
||||||
u64 GetRenderingStartTick(s32 session_id) const noexcept;
|
u64 GetRenderingStartTick(s32 session_id) const noexcept;
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
#include "audio_core/common/common.h"
|
#include "audio_core/common/common.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class KProcess;
|
||||||
|
}
|
||||||
|
|
||||||
namespace AudioCore::ADSP::AudioRenderer {
|
namespace AudioCore::ADSP::AudioRenderer {
|
||||||
|
|
||||||
struct CommandBuffer {
|
struct CommandBuffer {
|
||||||
@ -14,6 +18,7 @@ struct CommandBuffer {
|
|||||||
u64 size{};
|
u64 size{};
|
||||||
u64 time_limit{};
|
u64 time_limit{};
|
||||||
u64 applet_resource_user_id{};
|
u64 applet_resource_user_id{};
|
||||||
|
Kernel::KProcess* process{};
|
||||||
bool reset_buffer{};
|
bool reset_buffer{};
|
||||||
// Set by the DSP
|
// Set by the DSP
|
||||||
u32 remaining_command_count{};
|
u32 remaining_command_count{};
|
||||||
|
@ -9,14 +9,15 @@
|
|||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
#include "core/hle/kernel/k_process.h"
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
|
|
||||||
namespace AudioCore::ADSP::AudioRenderer {
|
namespace AudioCore::ADSP::AudioRenderer {
|
||||||
|
|
||||||
void CommandListProcessor::Initialize(Core::System& system_, CpuAddr buffer, u64 size,
|
void CommandListProcessor::Initialize(Core::System& system_, Kernel::KProcess& process,
|
||||||
Sink::SinkStream* stream_) {
|
CpuAddr buffer, u64 size, Sink::SinkStream* stream_) {
|
||||||
system = &system_;
|
system = &system_;
|
||||||
memory = &system->ApplicationMemory();
|
memory = &process.GetMemory();
|
||||||
stream = stream_;
|
stream = stream_;
|
||||||
header = reinterpret_cast<Renderer::CommandListHeader*>(buffer);
|
header = reinterpret_cast<Renderer::CommandListHeader*>(buffer);
|
||||||
commands = reinterpret_cast<u8*>(buffer + sizeof(Renderer::CommandListHeader));
|
commands = reinterpret_cast<u8*>(buffer + sizeof(Renderer::CommandListHeader));
|
||||||
|
@ -16,6 +16,10 @@ class Memory;
|
|||||||
class System;
|
class System;
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class KProcess;
|
||||||
|
}
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
namespace Sink {
|
namespace Sink {
|
||||||
class SinkStream;
|
class SinkStream;
|
||||||
@ -40,7 +44,8 @@ public:
|
|||||||
* @param size - The size of the buffer.
|
* @param size - The size of the buffer.
|
||||||
* @param stream - The stream to be used for sending the samples.
|
* @param stream - The stream to be used for sending the samples.
|
||||||
*/
|
*/
|
||||||
void Initialize(Core::System& system, CpuAddr buffer, u64 size, Sink::SinkStream* stream);
|
void Initialize(Core::System& system, Kernel::KProcess& process, CpuAddr buffer, u64 size,
|
||||||
|
Sink::SinkStream* stream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the maximum processing time for this command list.
|
* Set the maximum processing time for this command list.
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "audio_core/renderer/audio_renderer.h"
|
#include "audio_core/renderer/audio_renderer.h"
|
||||||
#include "audio_core/renderer/system_manager.h"
|
#include "audio_core/renderer/system_manager.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
|
#include "core/hle/kernel/k_process.h"
|
||||||
#include "core/hle/kernel/k_transfer_memory.h"
|
#include "core/hle/kernel/k_transfer_memory.h"
|
||||||
#include "core/hle/service/audio/errors.h"
|
#include "core/hle/service/audio/errors.h"
|
||||||
|
|
||||||
@ -17,7 +18,8 @@ Renderer::Renderer(Core::System& system_, Manager& manager_, Kernel::KEvent* ren
|
|||||||
Result Renderer::Initialize(const AudioRendererParameterInternal& params,
|
Result Renderer::Initialize(const AudioRendererParameterInternal& params,
|
||||||
Kernel::KTransferMemory* transfer_memory,
|
Kernel::KTransferMemory* transfer_memory,
|
||||||
const u64 transfer_memory_size, const u32 process_handle,
|
const u64 transfer_memory_size, const u32 process_handle,
|
||||||
const u64 applet_resource_user_id, const s32 session_id) {
|
Kernel::KProcess& process, const u64 applet_resource_user_id,
|
||||||
|
const s32 session_id) {
|
||||||
if (params.execution_mode == ExecutionMode::Auto) {
|
if (params.execution_mode == ExecutionMode::Auto) {
|
||||||
if (!manager.AddSystem(system)) {
|
if (!manager.AddSystem(system)) {
|
||||||
LOG_ERROR(Service_Audio,
|
LOG_ERROR(Service_Audio,
|
||||||
@ -28,7 +30,7 @@ Result Renderer::Initialize(const AudioRendererParameterInternal& params,
|
|||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
system.Initialize(params, transfer_memory, transfer_memory_size, process_handle,
|
system.Initialize(params, transfer_memory, transfer_memory_size, process_handle, process,
|
||||||
applet_resource_user_id, session_id);
|
applet_resource_user_id, session_id);
|
||||||
|
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
|
@ -14,7 +14,8 @@ class System;
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
class KTransferMemory;
|
class KTransferMemory;
|
||||||
}
|
class KProcess;
|
||||||
|
} // namespace Kernel
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
struct AudioRendererParameterInternal;
|
struct AudioRendererParameterInternal;
|
||||||
@ -44,7 +45,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
Result Initialize(const AudioRendererParameterInternal& params,
|
Result Initialize(const AudioRendererParameterInternal& params,
|
||||||
Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size,
|
Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size,
|
||||||
u32 process_handle, u64 applet_resource_user_id, s32 session_id);
|
u32 process_handle, Kernel::KProcess& process, u64 applet_resource_user_id,
|
||||||
|
s32 session_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finalize the renderer for shutdown.
|
* Finalize the renderer for shutdown.
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "core/hle/kernel/k_event.h"
|
#include "core/hle/kernel/k_event.h"
|
||||||
|
#include "core/hle/kernel/k_process.h"
|
||||||
#include "core/hle/kernel/k_transfer_memory.h"
|
#include "core/hle/kernel/k_transfer_memory.h"
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
|
|
||||||
@ -101,7 +102,8 @@ System::System(Core::System& core_, Kernel::KEvent* adsp_rendered_event_)
|
|||||||
|
|
||||||
Result System::Initialize(const AudioRendererParameterInternal& params,
|
Result System::Initialize(const AudioRendererParameterInternal& params,
|
||||||
Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size,
|
Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size,
|
||||||
u32 process_handle_, u64 applet_resource_user_id_, s32 session_id_) {
|
u32 process_handle_, Kernel::KProcess& process_,
|
||||||
|
u64 applet_resource_user_id_, s32 session_id_) {
|
||||||
if (!CheckValidRevision(params.revision)) {
|
if (!CheckValidRevision(params.revision)) {
|
||||||
return Service::Audio::ResultInvalidRevision;
|
return Service::Audio::ResultInvalidRevision;
|
||||||
}
|
}
|
||||||
@ -117,6 +119,7 @@ Result System::Initialize(const AudioRendererParameterInternal& params,
|
|||||||
behavior.SetUserLibRevision(params.revision);
|
behavior.SetUserLibRevision(params.revision);
|
||||||
|
|
||||||
process_handle = process_handle_;
|
process_handle = process_handle_;
|
||||||
|
process = &process_;
|
||||||
applet_resource_user_id = applet_resource_user_id_;
|
applet_resource_user_id = applet_resource_user_id_;
|
||||||
session_id = session_id_;
|
session_id = session_id_;
|
||||||
|
|
||||||
@ -129,7 +132,7 @@ Result System::Initialize(const AudioRendererParameterInternal& params,
|
|||||||
render_device = params.rendering_device;
|
render_device = params.rendering_device;
|
||||||
execution_mode = params.execution_mode;
|
execution_mode = params.execution_mode;
|
||||||
|
|
||||||
core.ApplicationMemory().ZeroBlock(transfer_memory->GetSourceAddress(), transfer_memory_size);
|
process->GetMemory().ZeroBlock(transfer_memory->GetSourceAddress(), transfer_memory_size);
|
||||||
|
|
||||||
// Note: We're not actually using the transfer memory because it's a pain to code for.
|
// Note: We're not actually using the transfer memory because it's a pain to code for.
|
||||||
// Allocate the memory normally instead and hope the game doesn't try to read anything back
|
// Allocate the memory normally instead and hope the game doesn't try to read anything back
|
||||||
@ -613,7 +616,8 @@ void System::SendCommandToDsp() {
|
|||||||
static_cast<u64>((time_limit_percent / 100) * 2'880'000.0 *
|
static_cast<u64>((time_limit_percent / 100) * 2'880'000.0 *
|
||||||
(static_cast<f32>(render_time_limit_percent) / 100.0f))};
|
(static_cast<f32>(render_time_limit_percent) / 100.0f))};
|
||||||
audio_renderer.SetCommandBuffer(session_id, translated_addr, command_size, time_limit,
|
audio_renderer.SetCommandBuffer(session_id, translated_addr, command_size, time_limit,
|
||||||
applet_resource_user_id, reset_command_buffers);
|
applet_resource_user_id, process,
|
||||||
|
reset_command_buffers);
|
||||||
reset_command_buffers = false;
|
reset_command_buffers = false;
|
||||||
command_buffer_size = command_size;
|
command_buffer_size = command_size;
|
||||||
if (remaining_command_count == 0) {
|
if (remaining_command_count == 0) {
|
||||||
|
@ -29,6 +29,7 @@ class System;
|
|||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
class KEvent;
|
class KEvent;
|
||||||
|
class KProcess;
|
||||||
class KTransferMemory;
|
class KTransferMemory;
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
||||||
@ -80,7 +81,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
Result Initialize(const AudioRendererParameterInternal& params,
|
Result Initialize(const AudioRendererParameterInternal& params,
|
||||||
Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size,
|
Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size,
|
||||||
u32 process_handle, u64 applet_resource_user_id, s32 session_id);
|
u32 process_handle, Kernel::KProcess& process, u64 applet_resource_user_id,
|
||||||
|
s32 session_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finalize the system.
|
* Finalize the system.
|
||||||
@ -275,6 +277,8 @@ private:
|
|||||||
Common::Event terminate_event{};
|
Common::Event terminate_event{};
|
||||||
/// Does what locks do
|
/// Does what locks do
|
||||||
std::mutex lock{};
|
std::mutex lock{};
|
||||||
|
/// Process this audio render is operating within, used for memory reads/writes.
|
||||||
|
Kernel::KProcess* process{};
|
||||||
/// Handle for the process for this system, unused
|
/// Handle for the process for this system, unused
|
||||||
u32 process_handle{};
|
u32 process_handle{};
|
||||||
/// Applet resource id for this system, unused
|
/// Applet resource id for this system, unused
|
||||||
|
@ -35,10 +35,11 @@ public:
|
|||||||
explicit IAudioRenderer(Core::System& system_, Manager& manager_,
|
explicit IAudioRenderer(Core::System& system_, Manager& manager_,
|
||||||
AudioCore::AudioRendererParameterInternal& params,
|
AudioCore::AudioRendererParameterInternal& params,
|
||||||
Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size,
|
Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size,
|
||||||
u32 process_handle, u64 applet_resource_user_id, s32 session_id)
|
u32 process_handle, Kernel::KProcess& process_,
|
||||||
|
u64 applet_resource_user_id, s32 session_id)
|
||||||
: ServiceFramework{system_, "IAudioRenderer"}, service_context{system_, "IAudioRenderer"},
|
: ServiceFramework{system_, "IAudioRenderer"}, service_context{system_, "IAudioRenderer"},
|
||||||
rendered_event{service_context.CreateEvent("IAudioRendererEvent")}, manager{manager_},
|
rendered_event{service_context.CreateEvent("IAudioRendererEvent")}, manager{manager_},
|
||||||
impl{std::make_unique<Renderer>(system_, manager, rendered_event)} {
|
impl{std::make_unique<Renderer>(system_, manager, rendered_event)}, process{process_} {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &IAudioRenderer::GetSampleRate, "GetSampleRate"},
|
{0, &IAudioRenderer::GetSampleRate, "GetSampleRate"},
|
||||||
@ -59,13 +60,15 @@ public:
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
RegisterHandlers(functions);
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
impl->Initialize(params, transfer_memory, transfer_memory_size, process_handle,
|
process.Open();
|
||||||
|
impl->Initialize(params, transfer_memory, transfer_memory_size, process_handle, process,
|
||||||
applet_resource_user_id, session_id);
|
applet_resource_user_id, session_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
~IAudioRenderer() override {
|
~IAudioRenderer() override {
|
||||||
impl->Finalize();
|
impl->Finalize();
|
||||||
service_context.CloseEvent(rendered_event);
|
service_context.CloseEvent(rendered_event);
|
||||||
|
process.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -235,6 +238,7 @@ private:
|
|||||||
Kernel::KEvent* rendered_event;
|
Kernel::KEvent* rendered_event;
|
||||||
Manager& manager;
|
Manager& manager;
|
||||||
std::unique_ptr<Renderer> impl;
|
std::unique_ptr<Renderer> impl;
|
||||||
|
Kernel::KProcess& process;
|
||||||
Common::ScratchBuffer<u8> output_buffer;
|
Common::ScratchBuffer<u8> output_buffer;
|
||||||
Common::ScratchBuffer<u8> performance_buffer;
|
Common::ScratchBuffer<u8> performance_buffer;
|
||||||
};
|
};
|
||||||
@ -455,7 +459,7 @@ void AudRenU::OpenAudioRenderer(HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto process{ctx.GetObjectFromHandle<Kernel::KProcess>(process_handle)};
|
auto process{ctx.GetObjectFromHandle<Kernel::KProcess>(process_handle).GetPointerUnsafe()};
|
||||||
auto transfer_memory{ctx.GetObjectFromHandle<Kernel::KTransferMemory>(transfer_memory_handle)};
|
auto transfer_memory{ctx.GetObjectFromHandle<Kernel::KTransferMemory>(transfer_memory_handle)};
|
||||||
|
|
||||||
const auto session_id{impl->GetSessionId()};
|
const auto session_id{impl->GetSessionId()};
|
||||||
@ -472,7 +476,7 @@ void AudRenU::OpenAudioRenderer(HLERequestContext& ctx) {
|
|||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
rb.PushIpcInterface<IAudioRenderer>(system, *impl, params, transfer_memory.GetPointerUnsafe(),
|
rb.PushIpcInterface<IAudioRenderer>(system, *impl, params, transfer_memory.GetPointerUnsafe(),
|
||||||
transfer_memory_size, process_handle,
|
transfer_memory_size, process_handle, *process,
|
||||||
applet_resource_user_id, session_id);
|
applet_resource_user_id, session_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,7 +526,7 @@ void AudRenU::GetAudioDeviceService(HLERequestContext& ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AudRenU::OpenAudioRendererForManualExecution(HLERequestContext& ctx) {
|
void AudRenU::OpenAudioRendererForManualExecution(HLERequestContext& ctx) {
|
||||||
LOG_DEBUG(Service_Audio, "called");
|
LOG_ERROR(Service_Audio, "called. Implement me!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudRenU::GetAudioDeviceServiceWithRevisionInfo(HLERequestContext& ctx) {
|
void AudRenU::GetAudioDeviceServiceWithRevisionInfo(HLERequestContext& ctx) {
|
||||||
|
Loading…
Reference in New Issue
Block a user