From be3f06bfe8122990fd984300ca8061f5e238b0a8 Mon Sep 17 00:00:00 2001 From: Dean Galvin Date: Sun, 4 Oct 2026 19:26:06 +1300 Subject: [PATCH] feat(libSceAudioPropagation): render silence for propagated sources sceAudioPropagationSourceRender takes the system, an array of RenderInfo descriptors and their count: PPSA21564 and PPSA21567 pass one RenderInfo {0x010107d6, 0x30} per call, with the source handle at +0x10, its output buffer at +0x18, the buffer size in bytes at +0x20 and the word 2 at +0x28, once per audio grain for each propagated source. Without acoustic propagation a source contributes nothing, so each output buffer is zeroed for its size. Every RenderInfo is checked first (descriptor, a live source of this system, a non-empty output), and a count of 0 or a format word other than 2 throws, as neither has been observed. --- .../AudioPropagation.hpp | 15 +++- .../prx/libSceAudioPropagation/Export.cpp | 18 ++++- core/libs/tests/GuestAudioPropagation.cpp | 76 ++++++++++++++++++- docs/dev/TechnicalDebt.md | 4 +- 4 files changed, 105 insertions(+), 8 deletions(-) diff --git a/core/libs/prx/libSceAudioPropagation/AudioPropagation.hpp b/core/libs/prx/libSceAudioPropagation/AudioPropagation.hpp index 623d28745..31904b0c5 100644 --- a/core/libs/prx/libSceAudioPropagation/AudioPropagation.hpp +++ b/core/libs/prx/libSceAudioPropagation/AudioPropagation.hpp @@ -15,6 +15,7 @@ inline constexpr std::uint32_t SystemMemoryId = 0x010107d4; inline constexpr std::size_t SystemMemorySize = 0x30; inline constexpr std::uint32_t RenderInfoId = 0x010107d6; inline constexpr std::size_t RenderInfoSize = 0x30; +inline constexpr std::uint32_t RenderFormat = 2; inline constexpr std::uint32_t RayId = 0x010107d7; inline constexpr std::size_t RaySize = 0x58; inline constexpr std::uint32_t PortalParamsId = 0x010107d8; @@ -31,6 +32,15 @@ struct Attribute { std::uint32_t reserved2; }; +struct RenderInfo { + AudioPropagationStructDescriptor desc; + AudioPropagationHandle source; + void* output; + std::size_t outputSize; + std::uint32_t format; + std::uint32_t reserved; +}; + struct PortalParams { AudioPropagationStructDescriptor desc; float rows[4][4]; @@ -40,6 +50,9 @@ struct PortalParams { static_assert(sizeof(AudioPropagationStructDescriptor) == 0x10); static_assert(sizeof(AudioPropagationSystemMemory) == SystemMemorySize); static_assert(sizeof(Attribute) == 0x20); +static_assert(sizeof(RenderInfo) == RenderInfoSize); +static_assert(offsetof(RenderInfo, source) == 0x10); +static_assert(offsetof(RenderInfo, format) == 0x28); static_assert(sizeof(PortalParams) == PortalParamsSize); static_assert(offsetof(PortalParams, rooms) == 0x50); @@ -68,7 +81,7 @@ std::int32_t APS5_VABI sceAudioPropagationSourceGetAudioPath(AudioPropagationHan std::int32_t APS5_VABI sceAudioPropagationSourceGetRays(AudioPropagationHandle source, void* rays, std::uint32_t* count); std::int32_t APS5_VABI sceAudioPropagationSourceCalculateAudioPaths(AudioPropagationHandle source, const void* rays, std::uint32_t rayCount, std::uint32_t flags, void* paths, std::uint32_t pathCount); std::int32_t APS5_VABI sceAudioPropagationSourceSetAudioPaths(AudioPropagationHandle source, const void* entries, std::uint32_t count); -std::int32_t APS5_VABI sceAudioPropagationSourceRender(AudioPropagationHandle system, const AudioPropagationStructDescriptor* renderInfo); +std::int32_t APS5_VABI sceAudioPropagationSourceRender(AudioPropagationHandle system, const AudioPropagation::RenderInfo* infos, std::uint32_t count); } diff --git a/core/libs/prx/libSceAudioPropagation/Export.cpp b/core/libs/prx/libSceAudioPropagation/Export.cpp index f28a6edb1..59e0a7b18 100644 --- a/core/libs/prx/libSceAudioPropagation/Export.cpp +++ b/core/libs/prx/libSceAudioPropagation/Export.cpp @@ -1,6 +1,7 @@ #include "AudioPropagation.hpp" #include +#include #include #include #include @@ -290,10 +291,19 @@ std::int32_t APS5_VABI sceAudioPropagationSourceSetAudioPaths(AudioPropagationHa return 0; } -std::int32_t APS5_VABI sceAudioPropagationSourceRender(AudioPropagationHandle system, const AudioPropagationStructDescriptor* renderInfo) { - static_cast(system); - static_cast(renderInfo); - NotImplemented_nid_no_patch(__func__); +std::int32_t APS5_VABI sceAudioPropagationSourceRender(AudioPropagationHandle system, const RenderInfo* infos, std::uint32_t count) { + require(infos != nullptr && count != 0, __func__); + auto& state = registry(); + std::lock_guard lock(state.mutex); + requireSystem(state, system, __func__); + for (std::uint32_t index = 0; index < count; ++index) { + const auto& info = infos[index]; + requireDescriptor(&info.desc, RenderInfoId, RenderInfoSize, __func__); + require(requireObject(state, info.source, Kind::Source, __func__).system == system, __func__); + require(info.output != nullptr && info.outputSize != 0, __func__); + if (info.format != RenderFormat) throw std::runtime_error(std::string(__func__) + ": render format " + std::to_string(info.format) + " is unknown"); + } + for (std::uint32_t index = 0; index < count; ++index) std::memset(infos[index].output, 0, infos[index].outputSize); return 0; } diff --git a/core/libs/tests/GuestAudioPropagation.cpp b/core/libs/tests/GuestAudioPropagation.cpp index 475c8c598..8930cf679 100644 --- a/core/libs/tests/GuestAudioPropagation.cpp +++ b/core/libs/tests/GuestAudioPropagation.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include namespace { @@ -129,7 +130,80 @@ int main() { RequireThrows([&] { sceAudioPropagationSourceCalculateAudioPaths(source, rays, 1, 1, nullptr, 0); }, "path calculation with rays"); Require(sceAudioPropagationSourceSetAudioPaths(source, nullptr, 0) == 0, "empty audio paths failed"); RequireThrows([&] { sceAudioPropagationSourceSetAudioPaths(source, rays, 1); }, "set audio paths"); - RequireThrows([&] { sceAudioPropagationSourceRender(system, nullptr); }, "render is not modelled"); + + alignas(16) std::uint8_t otherArena[64]{}; + auto otherMemory = Memory(); + Require(sceAudioPropagationSystemQueryMemory(options, &otherMemory) == 0, "second query memory failed"); + otherMemory.p_cpu_mem = otherArena; + AudioPropagationHandle otherSystem = 0; + Require(sceAudioPropagationSystemCreate(options, &otherMemory, &otherSystem) == 0, "second system create failed"); + AudioPropagationHandle otherSource = 0; + Require(sceAudioPropagationSourceCreate(otherSystem, &otherSource) == 0, "second system source create failed"); + AudioPropagationHandle secondSource = 0; + Require(sceAudioPropagationSourceCreate(system, &secondSource) == 0, "second source create failed"); + + float outputs[2][64]; + const auto fill = [&] { std::memset(outputs, 0xab, sizeof(outputs)); }; + const auto zeroed = [&](int index) { + for (const float sample : outputs[index]) { + if (sample != 0.0f) return false; + } + return true; + }; + const auto untouched = [&] { + const auto* bytes = reinterpret_cast(outputs); + for (std::size_t index = 0; index < sizeof(outputs); ++index) { + if (bytes[index] != 0xab) return false; + } + return true; + }; + AudioPropagation::RenderInfo infos[2]{}; + const auto reset = [&] { + infos[0] = {{AudioPropagation::RenderInfoId, AudioPropagation::RenderInfoSize}, source, outputs[0], sizeof(outputs[0]), AudioPropagation::RenderFormat, 0}; + infos[1] = {{AudioPropagation::RenderInfoId, AudioPropagation::RenderInfoSize}, secondSource, outputs[1], sizeof(outputs[1]), AudioPropagation::RenderFormat, 0}; + fill(); + }; + reset(); + Require(sceAudioPropagationSourceRender(system, infos, 1) == 0, "render failed"); + Require(zeroed(0), "render left the output unwritten"); + const auto* tail = reinterpret_cast(outputs[1]); + Require(tail[0] == 0xab, "render wrote past the output size"); + reset(); + infos[0].outputSize = sizeof(float) * 16; + Require(sceAudioPropagationSourceRender(system, infos, 2) == 0, "render of two sources failed"); + Require(outputs[0][15] == 0.0f && outputs[0][16] != 0.0f && zeroed(1), "render did not write each output for its size"); + + reset(); + RequireThrows([&] { sceAudioPropagationSourceRender(system, infos, 0); }, "render without infos"); + RequireThrows([&] { sceAudioPropagationSourceRender(system, nullptr, 1); }, "render with null infos"); + RequireThrows([&] { sceAudioPropagationSourceRender(system + 16, infos, 1); }, "render on an unknown system"); + infos[1].desc.id = AudioPropagation::RayId; + RequireThrows([&] { sceAudioPropagationSourceRender(system, infos, 2); }, "render info with a wrong descriptor id"); + Require(untouched(), "rejected render wrote an output"); + reset(); + infos[0].desc.size = 0x28; + RequireThrows([&] { sceAudioPropagationSourceRender(system, infos, 1); }, "render info with a wrong descriptor size"); + reset(); + infos[0].source = rooms[0]; + RequireThrows([&] { sceAudioPropagationSourceRender(system, infos, 1); }, "render of a room"); + reset(); + infos[0].source = otherSource; + RequireThrows([&] { sceAudioPropagationSourceRender(system, infos, 1); }, "render of another system's source"); + reset(); + infos[0].output = nullptr; + RequireThrows([&] { sceAudioPropagationSourceRender(system, infos, 1); }, "render without output"); + reset(); + infos[0].outputSize = 0; + RequireThrows([&] { sceAudioPropagationSourceRender(system, infos, 1); }, "render with an empty output"); + reset(); + infos[1].format = 1; + RequireThrows([&] { sceAudioPropagationSourceRender(system, infos, 2); }, "render with an unknown format"); + Require(untouched(), "render with an unknown format wrote an output"); + + Require(sceAudioPropagationSourceDestroy(system, secondSource) == 0, "second source destroy failed"); + reset(); + RequireThrows([&] { sceAudioPropagationSourceRender(system, infos, 2); }, "render of a destroyed source"); + Require(sceAudioPropagationSystemDestroy(otherSystem) == 0, "second system destroy failed"); RequireThrows([&] { sceAudioPropagationRoomDestroy(system, source); }, "room destroy of a source"); RequireThrows([&] { sceAudioPropagationSourceDestroy(system + 16, source); }, "source destroy with another system"); diff --git a/docs/dev/TechnicalDebt.md b/docs/dev/TechnicalDebt.md index 44f42cc7d..16bd5cdd4 100644 --- a/docs/dev/TechnicalDebt.md +++ b/docs/dev/TechnicalDebt.md @@ -14,7 +14,7 @@ Throughout the project, every function at every stage either **does exactly what - [libSceSaveDataDialog.native](../../core/libs/prx/libSceSaveDataDialog.native/Export.cpp) - [libSceCommonDialog](../../core/libs/prx/libSceCommonDialog/Export.cpp) - [libSceHmd](../../core/libs/prx/libSceHmd/Export.cpp) implements only the disconnected-headset path: initialization succeeds, device queries report `NotDetected`, and opening a device returns `DeviceDisconnected`. Headset support, tracking, rendering and additional HMD exports are not implemented; SDK-level ABI compatibility and in-game behaviour remain unverified. -- [libSceAudioPropagation](../../core/libs/prx/libSceAudioPropagation/Export.cpp) implements only the no-acoustic-propagation path: the system keeps a 16-byte header in the title's CPU memory (no GPU memory), rooms, portals, sources and materials are tracked handles, attributes are validated and have no effect, no rays are requested and sources report no audio paths. Ray results, path calculation and audio paths are accepted only when empty and throw otherwise; `sceAudioPropagationSourceRender` is not implemented. Objects still alive when their system is destroyed become unusable, and their later destroy or unregister is a no-op: PPSA21567 releases its reference-counted room, portal and source owners just before `sceAudioPropagationSystemDestroy`, so the order for every object is not proven. Occlusion, reflections and reverb from level geometry are absent; in-game behaviour remains unverified. +- [libSceAudioPropagation](../../core/libs/prx/libSceAudioPropagation/Export.cpp) implements only the no-acoustic-propagation path: the system keeps a 16-byte header in the title's CPU memory (no GPU memory), rooms, portals, sources and materials are tracked handles, attributes are validated and have no effect, no rays are requested and sources report no audio paths. Ray results, path calculation and audio paths are accepted only when empty and throw otherwise; `sceAudioPropagationSourceRender` writes silence (zeroes) to each source's output buffer for the given size, without a dry signal. Objects still alive when their system is destroyed become unusable, and their later destroy or unregister is a no-op: PPSA21567 releases its reference-counted room, portal and source owners just before `sceAudioPropagationSystemDestroy`, so the order for every object is not proven. Occlusion, reflections and reverb from level geometry are absent; in-game behaviour remains unverified. - [libSceNpCommerce](../../core/libs/prx/libSceNpCommerce/Export.cpp) - the PS Store icon show/hide calls do nothing - [sceVideoOutOpen](../../core/libs/prx/libSceVideoOut/src/Output.cpp) validates the priority and CPU affinity that the open param requests for the VideoOut service thread but does not apply them: the port's present and vblank threads are host threads, and guest priorities and affinities do not reach host scheduling - The shader recompiler [skips baryctric coordinates](../../core/shader/recompiler/Recompiler.cpp) (is not even passed to SpirvTargetOptions at row 212). @@ -46,7 +46,7 @@ Throughout the project, every function at every stage either **does exactly what - [GQTObcITIXI](../../core/libs/prx/libSceShare/Export.cpp) (libSceShare) - unknown name, signature - [BnMAMrsfVWo](../../core/libs/prx/libc/src/HeapDiagnostics.cpp) (libc) - unknown name, signature - AudioIn, NpSessionSignaling and PlayerInvitationDialog exports added without an implementation have assumed signatures -- [libSceAudioPropagation](../../core/libs/prx/libSceAudioPropagation/Export.cpp) (libSceAudioPropagation) - signatures and struct descriptors recovered from PPSA21567's calls (#481), not from documentation. The system options layout is unknown (only checked for non-null); the fourth argument of `sceAudioPropagationSourceCalculateAudioPaths` is unknown; `sceAudioPropagationSourceGetAudioPath` is assumed to output an 8-byte path handle. No error code is known, so invalid input throws instead of returning one +- [libSceAudioPropagation](../../core/libs/prx/libSceAudioPropagation/Export.cpp) (libSceAudioPropagation) - signatures and struct descriptors recovered from PPSA21567's calls (#481), not from documentation. The system options layout is unknown (only checked for non-null); the fourth argument of `sceAudioPropagationSourceCalculateAudioPaths` is unknown; `sceAudioPropagationSourceGetAudioPath` is assumed to output an 8-byte path handle. The meaning of the `RenderInfo` word at +0x28 is unknown (PPSA21567 and PPSA21564 pass 2); only 2 is accepted. Both titles pass one `RenderInfo` per call: a count of 0 throws, and larger counts are handled element by element without proof. No error code is known, so invalid input throws instead of returning one - [sceAvPlayerStartEx](../../core/libs/prx/libSceAvPlayer/Export.cpp) (libSceAvPlayer) - start info layout unknown; it is ignored and playback starts as with `sceAvPlayerStart` - [sceAvPlayerInit / sceAvPlayerInitEx](../../core/libs/prx/libSceAvPlayer/src/Player.cpp) (libSceAvPlayer) - behaviour without a memory replacement unknown; frame and sample buffers then come from the guest heap - [SceAvPlayerVideoEx](../../core/libs/SceTypes.hpp) (libSceAvPlayer) - frame rate field and encoding unknown; it is left zero in frame and stream info