mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2025-06-28 21:00:47 -07:00
Audio rendering: reduce memory allocations (#6604)
* - WritableRegion: enable wrapping IMemoryOwner<byte> - IVirtualMemoryManager impls of GetWritableRegion() use pooled memory when region is non-contiguous. - IVirtualMemoryManager: add GetReadOnlySequence() and impls - ByteMemoryPool: add new method RentCopy() - ByteMemoryPool: make class static, remove ctor and singleton field from earlier impl * - BytesReadOnlySequenceSegment: move from Ryujinx.Common.Memory to Ryujinx.Memory - BytesReadOnlySequenceSegment: add IsContiguousWith() and Replace() methods - VirtualMemoryManagerBase: - remove generic type parameters, instead use ulong for virtual addresses and nuint for host/physical addresses - implement IWritableBlock - add virtual GetReadOnlySequence() with coalescing of contiguous segments - add virtual GetSpan() - add virtual GetWritableRegion() - add abstract IsMapped() - add virtual MapForeign(ulong, nuint, ulong) - add virtual Read<T>() - add virtual Read(ulong, Span<byte>) - add virtual ReadTracked<T>() - add virtual SignalMemoryTracking() - add virtual Write() - add virtual Write<T>() - add virtual WriteUntracked() - add virtual WriteWithRedundancyCheck() - VirtualMemoryManagerRefCountedBase: remove generic type parameters - AddressSpaceManager: remove redundant methods, add required overrides - HvMemoryManager: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling - MemoryManager: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling - MemoryManagerHostMapped: remove redundant methods, add required overrides, add overrides for _invalidAccessHandler handling - NativeMemoryManager: add get properties for Pointer and Length - throughout: removed invalid <inheritdoc/> comments * - WritableRegion: enable wrapping IMemoryOwner<byte> - IVirtualMemoryManager impls of GetWritableRegion() use pooled memory when region is non-contiguous. - IVirtualMemoryManager: add GetReadOnlySequence() and impls - ByteMemoryPool: add new method RentCopy() - ByteMemoryPool: make class static, remove ctor and singleton field from earlier impl * add PagedMemoryRange enumerator types, use them in IVirtualMemoryManager implementations to consolidate page-handling logic and add a new capability - the coalescing of pages for consolidating memory copies and segmentation. * new: more tests for PagedMemoryRangeCoalescingEnumerator showing coalescing of contiguous segments * make some struct properties readonly * put braces around `foreach` bodies * encourage inlining of some PagedMemoryRange*Enumerator members * DynamicRingBuffer: - use ByteMemoryPool - make some methods return without locking when size/count argument = 0 - make generic Read<T>()/Write<T>() non-generic because its only usage is as T = byte - change Read(byte[]...) to Read(Span<byte>...) - change Write(byte[]...) to Write(Span<byte>...) * change IAudioRenderer.RequestUpdate() to take a ReadOnlySequence<byte>, enabling zero-copy audio rendering * HipcGenerator: support ReadOnlySequence<byte> as IPC method parameter * change IAudioRenderer/AudioRenderer RequestUpdate* methods to take input as ReadOnlySequence<byte> * MemoryManagerHostTracked: use rented memory when contiguous in `GetWritableRegion()` * rebase cleanup * dotnet format fixes * format and comment fixes * format long parameter list - take 2 * - add support to HipcGenerator for buffers of type `Memory<byte>` - change `AudioRenderer` `RequestUpdate()` and `RequestUpdateAuto()` to use Memory<byte> for output buffers, removing another memory block allocation/copy * SplitterContext `UpdateState()` and `UpdateData()` smooth out advance/rewind logic, only rewind if magic is invalid * DynamicRingBuffer.Write(): change Span<byte> to ReadOnlySpan<byte>
This commit is contained in:
@ -57,23 +57,11 @@ namespace Ryujinx.Horizon.Sdk.Audio.Detail
|
||||
|
||||
[CmifCommand(4)]
|
||||
public Result RequestUpdate(
|
||||
[Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span<byte> output,
|
||||
[Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span<byte> performanceOutput,
|
||||
[Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan<byte> input)
|
||||
[Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Memory<byte> output,
|
||||
[Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Memory<byte> performanceOutput,
|
||||
[Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySequence<byte> input)
|
||||
{
|
||||
using IMemoryOwner<byte> outputOwner = ByteMemoryPool.Rent(output.Length);
|
||||
using IMemoryOwner<byte> performanceOutputOwner = ByteMemoryPool.Rent(performanceOutput.Length);
|
||||
|
||||
Memory<byte> outputMemory = outputOwner.Memory;
|
||||
Memory<byte> performanceOutputMemory = performanceOutputOwner.Memory;
|
||||
|
||||
using MemoryHandle outputHandle = outputMemory.Pin();
|
||||
using MemoryHandle performanceOutputHandle = performanceOutputMemory.Pin();
|
||||
|
||||
Result result = new Result((int)_renderSystem.Update(outputMemory, performanceOutputMemory, input.ToArray()));
|
||||
|
||||
outputMemory.Span.CopyTo(output);
|
||||
performanceOutputMemory.Span.CopyTo(performanceOutput);
|
||||
Result result = new Result((int)_renderSystem.Update(output, performanceOutput, input));
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -127,9 +115,9 @@ namespace Ryujinx.Horizon.Sdk.Audio.Detail
|
||||
|
||||
[CmifCommand(10)] // 3.0.0+
|
||||
public Result RequestUpdateAuto(
|
||||
[Buffer(HipcBufferFlags.Out | HipcBufferFlags.AutoSelect)] Span<byte> output,
|
||||
[Buffer(HipcBufferFlags.Out | HipcBufferFlags.AutoSelect)] Span<byte> performanceOutput,
|
||||
[Buffer(HipcBufferFlags.In | HipcBufferFlags.AutoSelect)] ReadOnlySpan<byte> input)
|
||||
[Buffer(HipcBufferFlags.Out | HipcBufferFlags.AutoSelect)] Memory<byte> output,
|
||||
[Buffer(HipcBufferFlags.Out | HipcBufferFlags.AutoSelect)] Memory<byte> performanceOutput,
|
||||
[Buffer(HipcBufferFlags.In | HipcBufferFlags.AutoSelect)] ReadOnlySequence<byte> input)
|
||||
{
|
||||
return RequestUpdate(output, performanceOutput, input);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Ryujinx.Horizon.Common;
|
||||
using Ryujinx.Horizon.Sdk.Sf;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
|
||||
namespace Ryujinx.Horizon.Sdk.Audio.Detail
|
||||
{
|
||||
@ -10,13 +11,13 @@ namespace Ryujinx.Horizon.Sdk.Audio.Detail
|
||||
Result GetSampleCount(out int sampleCount);
|
||||
Result GetMixBufferCount(out int mixBufferCount);
|
||||
Result GetState(out int state);
|
||||
Result RequestUpdate(Span<byte> output, Span<byte> performanceOutput, ReadOnlySpan<byte> input);
|
||||
Result RequestUpdate(Memory<byte> output, Memory<byte> performanceOutput, ReadOnlySequence<byte> input);
|
||||
Result Start();
|
||||
Result Stop();
|
||||
Result QuerySystemEvent(out int eventHandle);
|
||||
Result SetRenderingTimeLimit(int percent);
|
||||
Result GetRenderingTimeLimit(out int percent);
|
||||
Result RequestUpdateAuto(Span<byte> output, Span<byte> performanceOutput, ReadOnlySpan<byte> input);
|
||||
Result RequestUpdateAuto(Memory<byte> output, Memory<byte> performanceOutput, ReadOnlySequence<byte> input);
|
||||
Result ExecuteAudioRendererRendering();
|
||||
Result SetVoiceDropParameter(float voiceDropParameter);
|
||||
Result GetVoiceDropParameter(out float voiceDropParameter);
|
||||
|
@ -2,6 +2,7 @@ using Ryujinx.Horizon.Sdk.Sf.Cmif;
|
||||
using Ryujinx.Horizon.Sdk.Sf.Hipc;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@ -9,6 +10,11 @@ namespace Ryujinx.Horizon.Sdk.Sf
|
||||
{
|
||||
static class CommandSerialization
|
||||
{
|
||||
public static ReadOnlySequence<byte> GetReadOnlySequence(PointerAndSize bufferRange)
|
||||
{
|
||||
return HorizonStatic.AddressSpace.GetReadOnlySequence(bufferRange.Address, checked((int)bufferRange.Size));
|
||||
}
|
||||
|
||||
public static ReadOnlySpan<byte> GetReadOnlySpan(PointerAndSize bufferRange)
|
||||
{
|
||||
return HorizonStatic.AddressSpace.GetSpan(bufferRange.Address, checked((int)bufferRange.Size));
|
||||
|
Reference in New Issue
Block a user