aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs
diff options
context:
space:
mode:
authorMary <me@thog.eu>2021-07-18 13:05:11 +0200
committerGitHub <noreply@github.com>2021-07-18 13:05:11 +0200
commitb8ad676fb8cbe0a43617df41daaf284ab4421c75 (patch)
tree743775369a175af0859f3e27e14e4ed4ce8b6877 /Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs
parent97a21332071aceeef6f5035178a3523177570448 (diff)
Amadeus: DSP code generation improvements (#2460)
This improve RyuJIT codegen drastically on the DSP side. This may reduce CPU usage of the DSP thread quite a lot.
Diffstat (limited to 'Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs')
-rw-r--r--Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs21
1 files changed, 10 insertions, 11 deletions
diff --git a/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs b/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs
index 0a4b14b7..3ff758ba 100644
--- a/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs
+++ b/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs
@@ -20,6 +20,7 @@ using Ryujinx.Audio.Renderer.Parameter;
using Ryujinx.Audio.Renderer.Parameter.Effect;
using System;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ryujinx.Audio.Renderer.Dsp.Command
@@ -81,17 +82,15 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
}
}
- ProcessLimiter(context);
+ ProcessLimiter(context, ref state);
}
- private void ProcessLimiter(CommandList context)
+ private unsafe void ProcessLimiter(CommandList context, ref LimiterState state)
{
Debug.Assert(Parameter.IsChannelCountValid());
if (IsEffectEnabled && Parameter.IsChannelCountValid())
{
- ref LimiterState state = ref State.Span[0];
-
if (!ResultState.IsEmpty && Parameter.StatisticsReset)
{
ref LimiterStatistics statistics = ref MemoryMarshal.Cast<byte, LimiterStatistics>(ResultState.Span[0].SpecificData)[0];
@@ -99,20 +98,20 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
statistics.Reset();
}
- ReadOnlyMemory<float>[] inputBuffers = new ReadOnlyMemory<float>[Parameter.ChannelCount];
- Memory<float>[] outputBuffers = new Memory<float>[Parameter.ChannelCount];
+ Span<IntPtr> inputBuffers = stackalloc IntPtr[Parameter.ChannelCount];
+ Span<IntPtr> outputBuffers = stackalloc IntPtr[Parameter.ChannelCount];
for (int i = 0; i < Parameter.ChannelCount; i++)
{
- inputBuffers[i] = context.GetBufferMemory(InputBufferIndices[i]);
- outputBuffers[i] = context.GetBufferMemory(OutputBufferIndices[i]);
+ inputBuffers[i] = context.GetBufferPointer(InputBufferIndices[i]);
+ outputBuffers[i] = context.GetBufferPointer(OutputBufferIndices[i]);
}
for (int channelIndex = 0; channelIndex < Parameter.ChannelCount; channelIndex++)
{
for (int sampleIndex = 0; sampleIndex < context.SampleCount; sampleIndex++)
{
- float inputSample = inputBuffers[channelIndex].Span[sampleIndex];
+ float inputSample = *((float*)inputBuffers[channelIndex] + sampleIndex);
float sampleInputMax = Math.Abs(inputSample * Parameter.InputGain);
@@ -143,7 +142,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
ref float delayedSample = ref state.DelayedSampleBuffer[channelIndex * Parameter.DelayBufferSampleCountMax + state.DelayedSampleBufferPosition[channelIndex]];
- outputBuffers[channelIndex].Span[sampleIndex] = delayedSample * state.CompressionGain[channelIndex] * Parameter.OutputGain;
+ *((float*)outputBuffers[channelIndex] + sampleIndex) = delayedSample * state.CompressionGain[channelIndex] * Parameter.OutputGain;
delayedSample = inputSample;
@@ -170,7 +169,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
{
if (InputBufferIndices[i] != OutputBufferIndices[i])
{
- context.GetBufferMemory(InputBufferIndices[i]).CopyTo(context.GetBufferMemory(OutputBufferIndices[i]));
+ context.CopyBuffer(OutputBufferIndices[i], InputBufferIndices[i]);
}
}
}