Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
4d84df9487 | |||
9ec8b2c01a | |||
091230af22 | |||
3aea194606 | |||
cdccf89e10 | |||
2ca0b17339 | |||
47639e6eeb | |||
cd78adf07f | |||
a3dc295c5f | |||
2ef4f92b07 | |||
2b6cc4b353 | |||
075575200d | |||
3a3b51893e | |||
44dbab3848 | |||
cada4d04ef | |||
e9edf0ab7f | |||
6e40b64554 | |||
1a676ee913 | |||
a23d8cb92f | |||
ab12fbe963 | |||
d0cc13ce0b | |||
65c035cdf8 | |||
56c5dbe557 | |||
5976a5161b | |||
3d4dea624d | |||
89a274c6a6 | |||
c6f8bfed90 | |||
9b94662b4b | |||
216026c096 | |||
7070cf6ae5 | |||
9839cd56fb | |||
99f46e22e2 | |||
22fb8c9d4f |
1
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
1
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
@ -1,6 +1,7 @@
|
||||
name: Feature Request
|
||||
description: Suggest a new feature for Ryujinx.
|
||||
title: "[Feature Request]"
|
||||
labels: enhancement
|
||||
body:
|
||||
- type: textarea
|
||||
id: overview
|
||||
|
18
.github/workflows/build.yml
vendored
18
.github/workflows/build.yml
vendored
@ -20,7 +20,7 @@ jobs:
|
||||
- { name: win-x64, os: windows-latest, zip_os_name: win_x64 }
|
||||
- { name: linux-x64, os: ubuntu-latest, zip_os_name: linux_x64 }
|
||||
- { name: linux-arm64, os: ubuntu-latest, zip_os_name: linux_arm64 }
|
||||
- { name: osx-x64, os: macOS-latest, zip_os_name: osx_x64 }
|
||||
- { name: osx-x64, os: macos-13, zip_os_name: osx_x64 }
|
||||
|
||||
fail-fast: false
|
||||
steps:
|
||||
@ -41,12 +41,12 @@ jobs:
|
||||
- name: Change config filename
|
||||
run: sed -r --in-place 's/\%\%RYUJINX_CONFIG_FILE_NAME\%\%/PRConfig\.json/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
shell: bash
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macOS-latest'
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macos-13'
|
||||
|
||||
- name: Change config filename for macOS
|
||||
run: sed -r -i '' 's/\%\%RYUJINX_CONFIG_FILE_NAME\%\%/PRConfig\.json/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
shell: bash
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os == 'macOS-latest'
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os == 'macos-13'
|
||||
|
||||
- name: Build
|
||||
run: dotnet build -c "${{ matrix.configuration }}" -p:Version="${{ env.RYUJINX_BASE_VERSION }}" -p:SourceRevisionId="${{ steps.git_short_hash.outputs.result }}" -p:ExtraDefineConstants=DISABLE_UPDATER
|
||||
@ -61,15 +61,15 @@ jobs:
|
||||
|
||||
- name: Publish Ryujinx
|
||||
run: dotnet publish -c "${{ matrix.configuration }}" -r "${{ matrix.platform.name }}" -o ./publish -p:Version="${{ env.RYUJINX_BASE_VERSION }}" -p:DebugType=embedded -p:SourceRevisionId="${{ steps.git_short_hash.outputs.result }}" -p:ExtraDefineConstants=DISABLE_UPDATER src/Ryujinx --self-contained true
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macOS-latest'
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macos-13'
|
||||
|
||||
- name: Publish Ryujinx.Headless.SDL2
|
||||
run: dotnet publish -c "${{ matrix.configuration }}" -r "${{ matrix.platform.name }}" -o ./publish_sdl2_headless -p:Version="${{ env.RYUJINX_BASE_VERSION }}" -p:DebugType=embedded -p:SourceRevisionId="${{ steps.git_short_hash.outputs.result }}" -p:ExtraDefineConstants=DISABLE_UPDATER src/Ryujinx.Headless.SDL2 --self-contained true
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macOS-latest'
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macos-13'
|
||||
|
||||
- name: Publish Ryujinx.Gtk3
|
||||
run: dotnet publish -c "${{ matrix.configuration }}" -r "${{ matrix.platform.name }}" -o ./publish_gtk -p:Version="${{ env.RYUJINX_BASE_VERSION }}" -p:DebugType=embedded -p:SourceRevisionId="${{ steps.git_short_hash.outputs.result }}" -p:ExtraDefineConstants=DISABLE_UPDATER src/Ryujinx.Gtk3 --self-contained true
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macOS-latest'
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macos-13'
|
||||
|
||||
- name: Set executable bit
|
||||
run: |
|
||||
@ -83,21 +83,21 @@ jobs:
|
||||
with:
|
||||
name: ryujinx-${{ matrix.configuration }}-${{ env.RYUJINX_BASE_VERSION }}+${{ steps.git_short_hash.outputs.result }}-${{ matrix.platform.zip_os_name }}
|
||||
path: publish
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macOS-latest'
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macos-13'
|
||||
|
||||
- name: Upload Ryujinx.Headless.SDL2 artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sdl2-ryujinx-headless-${{ matrix.configuration }}-${{ env.RYUJINX_BASE_VERSION }}+${{ steps.git_short_hash.outputs.result }}-${{ matrix.platform.zip_os_name }}
|
||||
path: publish_sdl2_headless
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macOS-latest'
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macos-13'
|
||||
|
||||
- name: Upload Ryujinx.Gtk3 artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: gtk-ryujinx-${{ matrix.configuration }}-${{ env.RYUJINX_BASE_VERSION }}+${{ steps.git_short_hash.outputs.result }}-${{ matrix.platform.zip_os_name }}
|
||||
path: publish_gtk
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macOS-latest'
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macos-13'
|
||||
|
||||
build_macos:
|
||||
name: macOS Universal (${{ matrix.configuration }})
|
||||
|
@ -8,8 +8,8 @@
|
||||
<PackageVersion Include="Avalonia.Desktop" Version="11.0.10" />
|
||||
<PackageVersion Include="Avalonia.Diagnostics" Version="11.0.10" />
|
||||
<PackageVersion Include="Avalonia.Markup.Xaml.Loader" Version="11.0.10" />
|
||||
<PackageVersion Include="Avalonia.Svg" Version="11.0.0.16" />
|
||||
<PackageVersion Include="Avalonia.Svg.Skia" Version="11.0.0.16" />
|
||||
<PackageVersion Include="Avalonia.Svg" Version="11.0.0.18" />
|
||||
<PackageVersion Include="Avalonia.Svg.Skia" Version="11.0.0.18" />
|
||||
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageVersion Include="Concentus" Version="1.1.7" />
|
||||
<PackageVersion Include="DiscordRichPresence" Version="1.2.1.24" />
|
||||
|
@ -36,8 +36,8 @@
|
||||
|
||||
## Compatibility
|
||||
|
||||
As of October 2023, Ryujinx has been tested on approximately 4,200 titles;
|
||||
over 4,150 boot past menus and into gameplay, with roughly 3,500 of those being considered playable.
|
||||
As of May 2024, Ryujinx has been tested on approximately 4,300 titles;
|
||||
over 4,100 boot past menus and into gameplay, with roughly 3,550 of those being considered playable.
|
||||
|
||||
You can check out the compatibility list [here](https://github.com/Ryujinx/Ryujinx-Games-List/issues).
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseExplicitType</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseExplicitType</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="I" Suffix="" Style="AaBb" /></Policy></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0b4bc4d_002Dd13b_002D4a37_002Db37e_002Dc9c6864e4302/@EntryIndexedValue"><Policy><Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"><ElementKinds><Kind Name="NAMESPACE" /><Kind Name="CLASS" /><Kind Name="STRUCT" /><Kind Name="ENUM" /><Kind Name="DELEGATE" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="I" Suffix="" Style="AaBb" /></Policy></Policy></s:String>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ASET/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Astc/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Luma/@EntryIndexedValue">True</s:Boolean>
|
||||
|
@ -857,8 +857,14 @@ namespace ARMeilleure.Translation.PTC
|
||||
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
|
||||
threads.ForEach((thread) => thread.Start());
|
||||
threads.ForEach((thread) => thread.Join());
|
||||
foreach (var thread in threads)
|
||||
{
|
||||
thread.Start();
|
||||
}
|
||||
foreach (var thread in threads)
|
||||
{
|
||||
thread.Join();
|
||||
}
|
||||
|
||||
threads.Clear();
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
using Ryujinx.Audio.Backends.Common;
|
||||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
|
||||
@ -87,7 +89,9 @@ namespace Ryujinx.Audio.Backends.SDL2
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] samples = new byte[frameCount * _bytesPerFrame];
|
||||
using IMemoryOwner<byte> samplesOwner = ByteMemoryPool.Rent(frameCount * _bytesPerFrame);
|
||||
|
||||
Span<byte> samples = samplesOwner.Memory.Span;
|
||||
|
||||
_ringBuffer.Read(samples, 0, samples.Length);
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
using Ryujinx.Audio.Backends.Common;
|
||||
using Ryujinx.Audio.Backends.SoundIo.Native;
|
||||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
@ -37,7 +39,7 @@ namespace Ryujinx.Audio.Backends.SoundIo
|
||||
_outputStream = _driver.OpenStream(RequestedSampleFormat, RequestedSampleRate, RequestedChannelCount);
|
||||
_outputStream.WriteCallback += Update;
|
||||
_outputStream.Volume = requestedVolume;
|
||||
// TODO: Setup other callbacks (errors, ect).
|
||||
// TODO: Setup other callbacks (errors, etc.)
|
||||
|
||||
_outputStream.Open();
|
||||
}
|
||||
@ -120,7 +122,9 @@ namespace Ryujinx.Audio.Backends.SoundIo
|
||||
|
||||
int channelCount = areas.Length;
|
||||
|
||||
byte[] samples = new byte[frameCount * bytesPerFrame];
|
||||
using IMemoryOwner<byte> samplesOwner = ByteMemoryPool.Rent(frameCount * bytesPerFrame);
|
||||
|
||||
Span<byte> samples = samplesOwner.Memory.Span;
|
||||
|
||||
_ringBuffer.Read(samples, 0, samples.Length);
|
||||
|
||||
|
@ -15,7 +15,6 @@ namespace Ryujinx.Audio.Renderer.Common
|
||||
{
|
||||
public const int Align = 0x10;
|
||||
public const int BiquadStateOffset = 0x0;
|
||||
public const int BiquadStateSize = 0x10;
|
||||
|
||||
/// <summary>
|
||||
/// The state of the biquad filters of this voice.
|
||||
|
@ -16,10 +16,15 @@ namespace Ryujinx.Audio.Renderer.Dsp
|
||||
/// <param name="parameter">The biquad filter parameter</param>
|
||||
/// <param name="state">The biquad filter state</param>
|
||||
/// <param name="outputBuffer">The output buffer to write the result</param>
|
||||
/// <param name="inputBuffer">The input buffer to write the result</param>
|
||||
/// <param name="inputBuffer">The input buffer to read the samples from</param>
|
||||
/// <param name="sampleCount">The count of samples to process</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ProcessBiquadFilter(ref BiquadFilterParameter parameter, ref BiquadFilterState state, Span<float> outputBuffer, ReadOnlySpan<float> inputBuffer, uint sampleCount)
|
||||
public static void ProcessBiquadFilter(
|
||||
ref BiquadFilterParameter parameter,
|
||||
ref BiquadFilterState state,
|
||||
Span<float> outputBuffer,
|
||||
ReadOnlySpan<float> inputBuffer,
|
||||
uint sampleCount)
|
||||
{
|
||||
float a0 = FixedPointHelper.ToFloat(parameter.Numerator[0], FixedPointPrecisionForParameter);
|
||||
float a1 = FixedPointHelper.ToFloat(parameter.Numerator[1], FixedPointPrecisionForParameter);
|
||||
@ -40,6 +45,96 @@ namespace Ryujinx.Audio.Renderer.Dsp
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply a single biquad filter and mix the result into the output buffer.
|
||||
/// </summary>
|
||||
/// <remarks>This is implemented with a direct form 1.</remarks>
|
||||
/// <param name="parameter">The biquad filter parameter</param>
|
||||
/// <param name="state">The biquad filter state</param>
|
||||
/// <param name="outputBuffer">The output buffer to write the result</param>
|
||||
/// <param name="inputBuffer">The input buffer to read the samples from</param>
|
||||
/// <param name="sampleCount">The count of samples to process</param>
|
||||
/// <param name="volume">Mix volume</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ProcessBiquadFilterAndMix(
|
||||
ref BiquadFilterParameter parameter,
|
||||
ref BiquadFilterState state,
|
||||
Span<float> outputBuffer,
|
||||
ReadOnlySpan<float> inputBuffer,
|
||||
uint sampleCount,
|
||||
float volume)
|
||||
{
|
||||
float a0 = FixedPointHelper.ToFloat(parameter.Numerator[0], FixedPointPrecisionForParameter);
|
||||
float a1 = FixedPointHelper.ToFloat(parameter.Numerator[1], FixedPointPrecisionForParameter);
|
||||
float a2 = FixedPointHelper.ToFloat(parameter.Numerator[2], FixedPointPrecisionForParameter);
|
||||
|
||||
float b1 = FixedPointHelper.ToFloat(parameter.Denominator[0], FixedPointPrecisionForParameter);
|
||||
float b2 = FixedPointHelper.ToFloat(parameter.Denominator[1], FixedPointPrecisionForParameter);
|
||||
|
||||
for (int i = 0; i < sampleCount; i++)
|
||||
{
|
||||
float input = inputBuffer[i];
|
||||
float output = input * a0 + state.State0 * a1 + state.State1 * a2 + state.State2 * b1 + state.State3 * b2;
|
||||
|
||||
state.State1 = state.State0;
|
||||
state.State0 = input;
|
||||
state.State3 = state.State2;
|
||||
state.State2 = output;
|
||||
|
||||
outputBuffer[i] += FloatingPointHelper.MultiplyRoundUp(output, volume);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply a single biquad filter and mix the result into the output buffer with volume ramp.
|
||||
/// </summary>
|
||||
/// <remarks>This is implemented with a direct form 1.</remarks>
|
||||
/// <param name="parameter">The biquad filter parameter</param>
|
||||
/// <param name="state">The biquad filter state</param>
|
||||
/// <param name="outputBuffer">The output buffer to write the result</param>
|
||||
/// <param name="inputBuffer">The input buffer to read the samples from</param>
|
||||
/// <param name="sampleCount">The count of samples to process</param>
|
||||
/// <param name="volume">Initial mix volume</param>
|
||||
/// <param name="ramp">Volume increment step</param>
|
||||
/// <returns>Last filtered sample value</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float ProcessBiquadFilterAndMixRamp(
|
||||
ref BiquadFilterParameter parameter,
|
||||
ref BiquadFilterState state,
|
||||
Span<float> outputBuffer,
|
||||
ReadOnlySpan<float> inputBuffer,
|
||||
uint sampleCount,
|
||||
float volume,
|
||||
float ramp)
|
||||
{
|
||||
float a0 = FixedPointHelper.ToFloat(parameter.Numerator[0], FixedPointPrecisionForParameter);
|
||||
float a1 = FixedPointHelper.ToFloat(parameter.Numerator[1], FixedPointPrecisionForParameter);
|
||||
float a2 = FixedPointHelper.ToFloat(parameter.Numerator[2], FixedPointPrecisionForParameter);
|
||||
|
||||
float b1 = FixedPointHelper.ToFloat(parameter.Denominator[0], FixedPointPrecisionForParameter);
|
||||
float b2 = FixedPointHelper.ToFloat(parameter.Denominator[1], FixedPointPrecisionForParameter);
|
||||
|
||||
float mixState = 0f;
|
||||
|
||||
for (int i = 0; i < sampleCount; i++)
|
||||
{
|
||||
float input = inputBuffer[i];
|
||||
float output = input * a0 + state.State0 * a1 + state.State1 * a2 + state.State2 * b1 + state.State3 * b2;
|
||||
|
||||
state.State1 = state.State0;
|
||||
state.State0 = input;
|
||||
state.State3 = state.State2;
|
||||
state.State2 = output;
|
||||
|
||||
mixState = FloatingPointHelper.MultiplyRoundUp(output, volume);
|
||||
|
||||
outputBuffer[i] += mixState;
|
||||
volume += ramp;
|
||||
}
|
||||
|
||||
return mixState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply multiple biquad filter.
|
||||
/// </summary>
|
||||
@ -47,10 +142,15 @@ namespace Ryujinx.Audio.Renderer.Dsp
|
||||
/// <param name="parameters">The biquad filter parameter</param>
|
||||
/// <param name="states">The biquad filter state</param>
|
||||
/// <param name="outputBuffer">The output buffer to write the result</param>
|
||||
/// <param name="inputBuffer">The input buffer to write the result</param>
|
||||
/// <param name="inputBuffer">The input buffer to read the samples from</param>
|
||||
/// <param name="sampleCount">The count of samples to process</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ProcessBiquadFilter(ReadOnlySpan<BiquadFilterParameter> parameters, Span<BiquadFilterState> states, Span<float> outputBuffer, ReadOnlySpan<float> inputBuffer, uint sampleCount)
|
||||
public static void ProcessBiquadFilter(
|
||||
ReadOnlySpan<BiquadFilterParameter> parameters,
|
||||
Span<BiquadFilterState> states,
|
||||
Span<float> outputBuffer,
|
||||
ReadOnlySpan<float> inputBuffer,
|
||||
uint sampleCount)
|
||||
{
|
||||
for (int stageIndex = 0; stageIndex < parameters.Length; stageIndex++)
|
||||
{
|
||||
@ -67,7 +167,7 @@ namespace Ryujinx.Audio.Renderer.Dsp
|
||||
|
||||
for (int i = 0; i < sampleCount; i++)
|
||||
{
|
||||
float input = inputBuffer[i];
|
||||
float input = stageIndex != 0 ? outputBuffer[i] : inputBuffer[i];
|
||||
float output = input * a0 + state.State0 * a1 + state.State1 * a2 + state.State2 * b1 + state.State3 * b2;
|
||||
|
||||
state.State1 = state.State0;
|
||||
@ -79,5 +179,129 @@ namespace Ryujinx.Audio.Renderer.Dsp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply double biquad filter and mix the result into the output buffer.
|
||||
/// </summary>
|
||||
/// <remarks>This is implemented with a direct form 1.</remarks>
|
||||
/// <param name="parameters">The biquad filter parameter</param>
|
||||
/// <param name="states">The biquad filter state</param>
|
||||
/// <param name="outputBuffer">The output buffer to write the result</param>
|
||||
/// <param name="inputBuffer">The input buffer to read the samples from</param>
|
||||
/// <param name="sampleCount">The count of samples to process</param>
|
||||
/// <param name="volume">Mix volume</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ProcessDoubleBiquadFilterAndMix(
|
||||
ref BiquadFilterParameter parameter0,
|
||||
ref BiquadFilterParameter parameter1,
|
||||
ref BiquadFilterState state0,
|
||||
ref BiquadFilterState state1,
|
||||
Span<float> outputBuffer,
|
||||
ReadOnlySpan<float> inputBuffer,
|
||||
uint sampleCount,
|
||||
float volume)
|
||||
{
|
||||
float a00 = FixedPointHelper.ToFloat(parameter0.Numerator[0], FixedPointPrecisionForParameter);
|
||||
float a10 = FixedPointHelper.ToFloat(parameter0.Numerator[1], FixedPointPrecisionForParameter);
|
||||
float a20 = FixedPointHelper.ToFloat(parameter0.Numerator[2], FixedPointPrecisionForParameter);
|
||||
|
||||
float b10 = FixedPointHelper.ToFloat(parameter0.Denominator[0], FixedPointPrecisionForParameter);
|
||||
float b20 = FixedPointHelper.ToFloat(parameter0.Denominator[1], FixedPointPrecisionForParameter);
|
||||
|
||||
float a01 = FixedPointHelper.ToFloat(parameter1.Numerator[0], FixedPointPrecisionForParameter);
|
||||
float a11 = FixedPointHelper.ToFloat(parameter1.Numerator[1], FixedPointPrecisionForParameter);
|
||||
float a21 = FixedPointHelper.ToFloat(parameter1.Numerator[2], FixedPointPrecisionForParameter);
|
||||
|
||||
float b11 = FixedPointHelper.ToFloat(parameter1.Denominator[0], FixedPointPrecisionForParameter);
|
||||
float b21 = FixedPointHelper.ToFloat(parameter1.Denominator[1], FixedPointPrecisionForParameter);
|
||||
|
||||
for (int i = 0; i < sampleCount; i++)
|
||||
{
|
||||
float input = inputBuffer[i];
|
||||
float output = input * a00 + state0.State0 * a10 + state0.State1 * a20 + state0.State2 * b10 + state0.State3 * b20;
|
||||
|
||||
state0.State1 = state0.State0;
|
||||
state0.State0 = input;
|
||||
state0.State3 = state0.State2;
|
||||
state0.State2 = output;
|
||||
|
||||
input = output;
|
||||
output = input * a01 + state1.State0 * a11 + state1.State1 * a21 + state1.State2 * b11 + state1.State3 * b21;
|
||||
|
||||
state1.State1 = state1.State0;
|
||||
state1.State0 = input;
|
||||
state1.State3 = state1.State2;
|
||||
state1.State2 = output;
|
||||
|
||||
outputBuffer[i] += FloatingPointHelper.MultiplyRoundUp(output, volume);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply double biquad filter and mix the result into the output buffer with volume ramp.
|
||||
/// </summary>
|
||||
/// <remarks>This is implemented with a direct form 1.</remarks>
|
||||
/// <param name="parameters">The biquad filter parameter</param>
|
||||
/// <param name="states">The biquad filter state</param>
|
||||
/// <param name="outputBuffer">The output buffer to write the result</param>
|
||||
/// <param name="inputBuffer">The input buffer to read the samples from</param>
|
||||
/// <param name="sampleCount">The count of samples to process</param>
|
||||
/// <param name="volume">Initial mix volume</param>
|
||||
/// <param name="ramp">Volume increment step</param>
|
||||
/// <returns>Last filtered sample value</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float ProcessDoubleBiquadFilterAndMixRamp(
|
||||
ref BiquadFilterParameter parameter0,
|
||||
ref BiquadFilterParameter parameter1,
|
||||
ref BiquadFilterState state0,
|
||||
ref BiquadFilterState state1,
|
||||
Span<float> outputBuffer,
|
||||
ReadOnlySpan<float> inputBuffer,
|
||||
uint sampleCount,
|
||||
float volume,
|
||||
float ramp)
|
||||
{
|
||||
float a00 = FixedPointHelper.ToFloat(parameter0.Numerator[0], FixedPointPrecisionForParameter);
|
||||
float a10 = FixedPointHelper.ToFloat(parameter0.Numerator[1], FixedPointPrecisionForParameter);
|
||||
float a20 = FixedPointHelper.ToFloat(parameter0.Numerator[2], FixedPointPrecisionForParameter);
|
||||
|
||||
float b10 = FixedPointHelper.ToFloat(parameter0.Denominator[0], FixedPointPrecisionForParameter);
|
||||
float b20 = FixedPointHelper.ToFloat(parameter0.Denominator[1], FixedPointPrecisionForParameter);
|
||||
|
||||
float a01 = FixedPointHelper.ToFloat(parameter1.Numerator[0], FixedPointPrecisionForParameter);
|
||||
float a11 = FixedPointHelper.ToFloat(parameter1.Numerator[1], FixedPointPrecisionForParameter);
|
||||
float a21 = FixedPointHelper.ToFloat(parameter1.Numerator[2], FixedPointPrecisionForParameter);
|
||||
|
||||
float b11 = FixedPointHelper.ToFloat(parameter1.Denominator[0], FixedPointPrecisionForParameter);
|
||||
float b21 = FixedPointHelper.ToFloat(parameter1.Denominator[1], FixedPointPrecisionForParameter);
|
||||
|
||||
float mixState = 0f;
|
||||
|
||||
for (int i = 0; i < sampleCount; i++)
|
||||
{
|
||||
float input = inputBuffer[i];
|
||||
float output = input * a00 + state0.State0 * a10 + state0.State1 * a20 + state0.State2 * b10 + state0.State3 * b20;
|
||||
|
||||
state0.State1 = state0.State0;
|
||||
state0.State0 = input;
|
||||
state0.State3 = state0.State2;
|
||||
state0.State2 = output;
|
||||
|
||||
input = output;
|
||||
output = input * a01 + state1.State0 * a11 + state1.State1 * a21 + state1.State2 * b11 + state1.State3 * b21;
|
||||
|
||||
state1.State1 = state1.State0;
|
||||
state1.State0 = input;
|
||||
state1.State3 = state1.State2;
|
||||
state1.State2 = output;
|
||||
|
||||
mixState = FloatingPointHelper.MultiplyRoundUp(output, volume);
|
||||
|
||||
outputBuffer[i] += mixState;
|
||||
volume += ramp;
|
||||
}
|
||||
|
||||
return mixState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,123 @@
|
||||
using Ryujinx.Audio.Renderer.Common;
|
||||
using Ryujinx.Audio.Renderer.Dsp.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Dsp.Command
|
||||
{
|
||||
public class BiquadFilterAndMixCommand : ICommand
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public int NodeId { get; }
|
||||
|
||||
public CommandType CommandType => CommandType.BiquadFilterAndMix;
|
||||
|
||||
public uint EstimatedProcessingTime { get; set; }
|
||||
|
||||
public ushort InputBufferIndex { get; }
|
||||
public ushort OutputBufferIndex { get; }
|
||||
|
||||
private BiquadFilterParameter _parameter;
|
||||
|
||||
public Memory<BiquadFilterState> BiquadFilterState { get; }
|
||||
public Memory<BiquadFilterState> PreviousBiquadFilterState { get; }
|
||||
|
||||
public Memory<VoiceUpdateState> State { get; }
|
||||
|
||||
public int LastSampleIndex { get; }
|
||||
|
||||
public float Volume0 { get; }
|
||||
public float Volume1 { get; }
|
||||
|
||||
public bool NeedInitialization { get; }
|
||||
public bool HasVolumeRamp { get; }
|
||||
public bool IsFirstMixBuffer { get; }
|
||||
|
||||
public BiquadFilterAndMixCommand(
|
||||
float volume0,
|
||||
float volume1,
|
||||
uint inputBufferIndex,
|
||||
uint outputBufferIndex,
|
||||
int lastSampleIndex,
|
||||
Memory<VoiceUpdateState> state,
|
||||
ref BiquadFilterParameter filter,
|
||||
Memory<BiquadFilterState> biquadFilterState,
|
||||
Memory<BiquadFilterState> previousBiquadFilterState,
|
||||
bool needInitialization,
|
||||
bool hasVolumeRamp,
|
||||
bool isFirstMixBuffer,
|
||||
int nodeId)
|
||||
{
|
||||
Enabled = true;
|
||||
NodeId = nodeId;
|
||||
|
||||
InputBufferIndex = (ushort)inputBufferIndex;
|
||||
OutputBufferIndex = (ushort)outputBufferIndex;
|
||||
|
||||
_parameter = filter;
|
||||
BiquadFilterState = biquadFilterState;
|
||||
PreviousBiquadFilterState = previousBiquadFilterState;
|
||||
|
||||
State = state;
|
||||
LastSampleIndex = lastSampleIndex;
|
||||
|
||||
Volume0 = volume0;
|
||||
Volume1 = volume1;
|
||||
|
||||
NeedInitialization = needInitialization;
|
||||
HasVolumeRamp = hasVolumeRamp;
|
||||
IsFirstMixBuffer = isFirstMixBuffer;
|
||||
}
|
||||
|
||||
public void Process(CommandList context)
|
||||
{
|
||||
ReadOnlySpan<float> inputBuffer = context.GetBuffer(InputBufferIndex);
|
||||
Span<float> outputBuffer = context.GetBuffer(OutputBufferIndex);
|
||||
|
||||
if (NeedInitialization)
|
||||
{
|
||||
// If there is no previous state, initialize to zero.
|
||||
|
||||
BiquadFilterState.Span[0] = new BiquadFilterState();
|
||||
}
|
||||
else if (IsFirstMixBuffer)
|
||||
{
|
||||
// This is the first buffer, set previous state to current state.
|
||||
|
||||
PreviousBiquadFilterState.Span[0] = BiquadFilterState.Span[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Rewind the current state by copying back the previous state.
|
||||
|
||||
BiquadFilterState.Span[0] = PreviousBiquadFilterState.Span[0];
|
||||
}
|
||||
|
||||
if (HasVolumeRamp)
|
||||
{
|
||||
float volume = Volume0;
|
||||
float ramp = (Volume1 - Volume0) / (int)context.SampleCount;
|
||||
|
||||
State.Span[0].LastSamples[LastSampleIndex] = BiquadFilterHelper.ProcessBiquadFilterAndMixRamp(
|
||||
ref _parameter,
|
||||
ref BiquadFilterState.Span[0],
|
||||
outputBuffer,
|
||||
inputBuffer,
|
||||
context.SampleCount,
|
||||
volume,
|
||||
ramp);
|
||||
}
|
||||
else
|
||||
{
|
||||
BiquadFilterHelper.ProcessBiquadFilterAndMix(
|
||||
ref _parameter,
|
||||
ref BiquadFilterState.Span[0],
|
||||
outputBuffer,
|
||||
inputBuffer,
|
||||
context.SampleCount,
|
||||
Volume1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -30,8 +30,10 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
|
||||
CopyMixBuffer,
|
||||
LimiterVersion1,
|
||||
LimiterVersion2,
|
||||
GroupedBiquadFilter,
|
||||
MultiTapBiquadFilter,
|
||||
CaptureBuffer,
|
||||
Compressor,
|
||||
BiquadFilterAndMix,
|
||||
MultiTapBiquadFilterAndMix,
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,14 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
|
||||
|
||||
public Memory<VoiceUpdateState> State { get; }
|
||||
|
||||
public MixRampGroupedCommand(uint mixBufferCount, uint inputBufferIndex, uint outputBufferIndex, Span<float> volume0, Span<float> volume1, Memory<VoiceUpdateState> state, int nodeId)
|
||||
public MixRampGroupedCommand(
|
||||
uint mixBufferCount,
|
||||
uint inputBufferIndex,
|
||||
uint outputBufferIndex,
|
||||
ReadOnlySpan<float> volume0,
|
||||
ReadOnlySpan<float> volume1,
|
||||
Memory<VoiceUpdateState> state,
|
||||
int nodeId)
|
||||
{
|
||||
Enabled = true;
|
||||
MixBufferCount = mixBufferCount;
|
||||
@ -48,7 +55,12 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static float ProcessMixRampGrouped(Span<float> outputBuffer, ReadOnlySpan<float> inputBuffer, float volume0, float volume1, int sampleCount)
|
||||
private static float ProcessMixRampGrouped(
|
||||
Span<float> outputBuffer,
|
||||
ReadOnlySpan<float> inputBuffer,
|
||||
float volume0,
|
||||
float volume1,
|
||||
int sampleCount)
|
||||
{
|
||||
float ramp = (volume1 - volume0) / sampleCount;
|
||||
float volume = volume0;
|
||||
|
@ -0,0 +1,145 @@
|
||||
using Ryujinx.Audio.Renderer.Common;
|
||||
using Ryujinx.Audio.Renderer.Dsp.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Dsp.Command
|
||||
{
|
||||
public class MultiTapBiquadFilterAndMixCommand : ICommand
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public int NodeId { get; }
|
||||
|
||||
public CommandType CommandType => CommandType.MultiTapBiquadFilterAndMix;
|
||||
|
||||
public uint EstimatedProcessingTime { get; set; }
|
||||
|
||||
public ushort InputBufferIndex { get; }
|
||||
public ushort OutputBufferIndex { get; }
|
||||
|
||||
private BiquadFilterParameter _parameter0;
|
||||
private BiquadFilterParameter _parameter1;
|
||||
|
||||
public Memory<BiquadFilterState> BiquadFilterState0 { get; }
|
||||
public Memory<BiquadFilterState> BiquadFilterState1 { get; }
|
||||
public Memory<BiquadFilterState> PreviousBiquadFilterState0 { get; }
|
||||
public Memory<BiquadFilterState> PreviousBiquadFilterState1 { get; }
|
||||
|
||||
public Memory<VoiceUpdateState> State { get; }
|
||||
|
||||
public int LastSampleIndex { get; }
|
||||
|
||||
public float Volume0 { get; }
|
||||
public float Volume1 { get; }
|
||||
|
||||
public bool NeedInitialization0 { get; }
|
||||
public bool NeedInitialization1 { get; }
|
||||
public bool HasVolumeRamp { get; }
|
||||
public bool IsFirstMixBuffer { get; }
|
||||
|
||||
public MultiTapBiquadFilterAndMixCommand(
|
||||
float volume0,
|
||||
float volume1,
|
||||
uint inputBufferIndex,
|
||||
uint outputBufferIndex,
|
||||
int lastSampleIndex,
|
||||
Memory<VoiceUpdateState> state,
|
||||
ref BiquadFilterParameter filter0,
|
||||
ref BiquadFilterParameter filter1,
|
||||
Memory<BiquadFilterState> biquadFilterState0,
|
||||
Memory<BiquadFilterState> biquadFilterState1,
|
||||
Memory<BiquadFilterState> previousBiquadFilterState0,
|
||||
Memory<BiquadFilterState> previousBiquadFilterState1,
|
||||
bool needInitialization0,
|
||||
bool needInitialization1,
|
||||
bool hasVolumeRamp,
|
||||
bool isFirstMixBuffer,
|
||||
int nodeId)
|
||||
{
|
||||
Enabled = true;
|
||||
NodeId = nodeId;
|
||||
|
||||
InputBufferIndex = (ushort)inputBufferIndex;
|
||||
OutputBufferIndex = (ushort)outputBufferIndex;
|
||||
|
||||
_parameter0 = filter0;
|
||||
_parameter1 = filter1;
|
||||
BiquadFilterState0 = biquadFilterState0;
|
||||
BiquadFilterState1 = biquadFilterState1;
|
||||
PreviousBiquadFilterState0 = previousBiquadFilterState0;
|
||||
PreviousBiquadFilterState1 = previousBiquadFilterState1;
|
||||
|
||||
State = state;
|
||||
LastSampleIndex = lastSampleIndex;
|
||||
|
||||
Volume0 = volume0;
|
||||
Volume1 = volume1;
|
||||
|
||||
NeedInitialization0 = needInitialization0;
|
||||
NeedInitialization1 = needInitialization1;
|
||||
HasVolumeRamp = hasVolumeRamp;
|
||||
IsFirstMixBuffer = isFirstMixBuffer;
|
||||
}
|
||||
|
||||
private void UpdateState(Memory<BiquadFilterState> state, Memory<BiquadFilterState> previousState, bool needInitialization)
|
||||
{
|
||||
if (needInitialization)
|
||||
{
|
||||
// If there is no previous state, initialize to zero.
|
||||
|
||||
state.Span[0] = new BiquadFilterState();
|
||||
}
|
||||
else if (IsFirstMixBuffer)
|
||||
{
|
||||
// This is the first buffer, set previous state to current state.
|
||||
|
||||
previousState.Span[0] = state.Span[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Rewind the current state by copying back the previous state.
|
||||
|
||||
state.Span[0] = previousState.Span[0];
|
||||
}
|
||||
}
|
||||
|
||||
public void Process(CommandList context)
|
||||
{
|
||||
ReadOnlySpan<float> inputBuffer = context.GetBuffer(InputBufferIndex);
|
||||
Span<float> outputBuffer = context.GetBuffer(OutputBufferIndex);
|
||||
|
||||
UpdateState(BiquadFilterState0, PreviousBiquadFilterState0, NeedInitialization0);
|
||||
UpdateState(BiquadFilterState1, PreviousBiquadFilterState1, NeedInitialization1);
|
||||
|
||||
if (HasVolumeRamp)
|
||||
{
|
||||
float volume = Volume0;
|
||||
float ramp = (Volume1 - Volume0) / (int)context.SampleCount;
|
||||
|
||||
State.Span[0].LastSamples[LastSampleIndex] = BiquadFilterHelper.ProcessDoubleBiquadFilterAndMixRamp(
|
||||
ref _parameter0,
|
||||
ref _parameter1,
|
||||
ref BiquadFilterState0.Span[0],
|
||||
ref BiquadFilterState1.Span[0],
|
||||
outputBuffer,
|
||||
inputBuffer,
|
||||
context.SampleCount,
|
||||
volume,
|
||||
ramp);
|
||||
}
|
||||
else
|
||||
{
|
||||
BiquadFilterHelper.ProcessDoubleBiquadFilterAndMix(
|
||||
ref _parameter0,
|
||||
ref _parameter1,
|
||||
ref BiquadFilterState0.Span[0],
|
||||
ref BiquadFilterState1.Span[0],
|
||||
outputBuffer,
|
||||
inputBuffer,
|
||||
context.SampleCount,
|
||||
Volume1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,13 +4,13 @@ using System;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Dsp.Command
|
||||
{
|
||||
public class GroupedBiquadFilterCommand : ICommand
|
||||
public class MultiTapBiquadFilterCommand : ICommand
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public int NodeId { get; }
|
||||
|
||||
public CommandType CommandType => CommandType.GroupedBiquadFilter;
|
||||
public CommandType CommandType => CommandType.MultiTapBiquadFilter;
|
||||
|
||||
public uint EstimatedProcessingTime { get; set; }
|
||||
|
||||
@ -20,7 +20,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
|
||||
private readonly int _outputBufferIndex;
|
||||
private readonly bool[] _isInitialized;
|
||||
|
||||
public GroupedBiquadFilterCommand(int baseIndex, ReadOnlySpan<BiquadFilterParameter> filters, Memory<BiquadFilterState> biquadFilterStateMemory, int inputBufferOffset, int outputBufferOffset, ReadOnlySpan<bool> isInitialized, int nodeId)
|
||||
public MultiTapBiquadFilterCommand(int baseIndex, ReadOnlySpan<BiquadFilterParameter> filters, Memory<BiquadFilterState> biquadFilterStateMemory, int inputBufferOffset, int outputBufferOffset, ReadOnlySpan<bool> isInitialized, int nodeId)
|
||||
{
|
||||
_parameters = filters.ToArray();
|
||||
_biquadFilterStates = biquadFilterStateMemory;
|
@ -2,12 +2,16 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Dsp.State
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x10)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x20)]
|
||||
public struct BiquadFilterState
|
||||
{
|
||||
public float State0;
|
||||
public float State1;
|
||||
public float State2;
|
||||
public float State3;
|
||||
public float State4;
|
||||
public float State5;
|
||||
public float State6;
|
||||
public float State7;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Parameter
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic interface for the splitter destination parameters.
|
||||
/// </summary>
|
||||
public interface ISplitterDestinationInParameter
|
||||
{
|
||||
/// <summary>
|
||||
/// Target splitter destination data id.
|
||||
/// </summary>
|
||||
int Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The mix to output the result of the splitter.
|
||||
/// </summary>
|
||||
int DestinationId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Biquad filter parameters.
|
||||
/// </summary>
|
||||
Array2<BiquadFilterParameter> BiquadFilters { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if in use.
|
||||
/// </summary>
|
||||
bool IsUsed { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Mix buffer volumes.
|
||||
/// </summary>
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
Span<float> MixBufferVolume { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Check if the magic is valid.
|
||||
/// </summary>
|
||||
/// <returns>Returns true if the magic is valid.</returns>
|
||||
bool IsMagicValid();
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -5,10 +6,10 @@ using System.Runtime.InteropServices;
|
||||
namespace Ryujinx.Audio.Renderer.Parameter
|
||||
{
|
||||
/// <summary>
|
||||
/// Input header for a splitter destination update.
|
||||
/// Input header for a splitter destination version 1 update.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct SplitterDestinationInParameter
|
||||
public struct SplitterDestinationInParameterVersion1 : ISplitterDestinationInParameter
|
||||
{
|
||||
/// <summary>
|
||||
/// Magic of the input header.
|
||||
@ -41,7 +42,7 @@ namespace Ryujinx.Audio.Renderer.Parameter
|
||||
/// </summary>
|
||||
private unsafe fixed byte _reserved[3];
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Size = 4 * Constants.MixBufferCountMax, Pack = 1)]
|
||||
[StructLayout(LayoutKind.Sequential, Size = sizeof(float) * Constants.MixBufferCountMax, Pack = 1)]
|
||||
private struct MixArray { }
|
||||
|
||||
/// <summary>
|
||||
@ -50,6 +51,14 @@ namespace Ryujinx.Audio.Renderer.Parameter
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
public Span<float> MixBufferVolume => SpanHelpers.AsSpan<MixArray, float>(ref _mixBufferVolume);
|
||||
|
||||
readonly int ISplitterDestinationInParameter.Id => Id;
|
||||
|
||||
readonly int ISplitterDestinationInParameter.DestinationId => DestinationId;
|
||||
|
||||
readonly Array2<BiquadFilterParameter> ISplitterDestinationInParameter.BiquadFilters => default;
|
||||
|
||||
readonly bool ISplitterDestinationInParameter.IsUsed => IsUsed;
|
||||
|
||||
/// <summary>
|
||||
/// The expected constant of any input header.
|
||||
/// </summary>
|
@ -0,0 +1,81 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Parameter
|
||||
{
|
||||
/// <summary>
|
||||
/// Input header for a splitter destination version 2 update.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct SplitterDestinationInParameterVersion2 : ISplitterDestinationInParameter
|
||||
{
|
||||
/// <summary>
|
||||
/// Magic of the input header.
|
||||
/// </summary>
|
||||
public uint Magic;
|
||||
|
||||
/// <summary>
|
||||
/// Target splitter destination data id.
|
||||
/// </summary>
|
||||
public int Id;
|
||||
|
||||
/// <summary>
|
||||
/// Mix buffer volumes storage.
|
||||
/// </summary>
|
||||
private MixArray _mixBufferVolume;
|
||||
|
||||
/// <summary>
|
||||
/// The mix to output the result of the splitter.
|
||||
/// </summary>
|
||||
public int DestinationId;
|
||||
|
||||
/// <summary>
|
||||
/// Biquad filter parameters.
|
||||
/// </summary>
|
||||
public Array2<BiquadFilterParameter> BiquadFilters;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if in use.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsUsed;
|
||||
|
||||
/// <summary>
|
||||
/// Reserved/padding.
|
||||
/// </summary>
|
||||
private unsafe fixed byte _reserved[11];
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Size = sizeof(float) * Constants.MixBufferCountMax, Pack = 1)]
|
||||
private struct MixArray { }
|
||||
|
||||
/// <summary>
|
||||
/// Mix buffer volumes.
|
||||
/// </summary>
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
public Span<float> MixBufferVolume => SpanHelpers.AsSpan<MixArray, float>(ref _mixBufferVolume);
|
||||
|
||||
readonly int ISplitterDestinationInParameter.Id => Id;
|
||||
|
||||
readonly int ISplitterDestinationInParameter.DestinationId => DestinationId;
|
||||
|
||||
readonly Array2<BiquadFilterParameter> ISplitterDestinationInParameter.BiquadFilters => BiquadFilters;
|
||||
|
||||
readonly bool ISplitterDestinationInParameter.IsUsed => IsUsed;
|
||||
|
||||
/// <summary>
|
||||
/// The expected constant of any input header.
|
||||
/// </summary>
|
||||
private const uint ValidMagic = 0x44444E53;
|
||||
|
||||
/// <summary>
|
||||
/// Check if the magic is valid.
|
||||
/// </summary>
|
||||
/// <returns>Returns true if the magic is valid.</returns>
|
||||
public readonly bool IsMagicValid()
|
||||
{
|
||||
return Magic == ValidMagic;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using Ryujinx.Audio.Integration;
|
||||
using Ryujinx.Audio.Renderer.Common;
|
||||
using Ryujinx.Audio.Renderer.Dsp.Command;
|
||||
using Ryujinx.Audio.Renderer.Dsp.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Server.Effect;
|
||||
using Ryujinx.Audio.Renderer.Server.MemoryPool;
|
||||
@ -173,6 +174,22 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
return ResultCode.WorkBufferTooSmall;
|
||||
}
|
||||
|
||||
Memory<BiquadFilterState> splitterBqfStates = Memory<BiquadFilterState>.Empty;
|
||||
|
||||
if (_behaviourContext.IsBiquadFilterParameterForSplitterEnabled() &&
|
||||
parameter.SplitterCount > 0 &&
|
||||
parameter.SplitterDestinationCount > 0)
|
||||
{
|
||||
splitterBqfStates = workBufferAllocator.Allocate<BiquadFilterState>(parameter.SplitterDestinationCount * SplitterContext.BqfStatesPerDestination, 0x10);
|
||||
|
||||
if (splitterBqfStates.IsEmpty)
|
||||
{
|
||||
return ResultCode.WorkBufferTooSmall;
|
||||
}
|
||||
|
||||
splitterBqfStates.Span.Clear();
|
||||
}
|
||||
|
||||
// Invalidate DSP cache on what was currently allocated with workBuffer.
|
||||
AudioProcessorMemoryManager.InvalidateDspCache(_dspMemoryPoolState.Translate(workBuffer, workBufferAllocator.Offset), workBufferAllocator.Offset);
|
||||
|
||||
@ -292,7 +309,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
state = MemoryPoolState.Create(MemoryPoolState.LocationType.Cpu);
|
||||
}
|
||||
|
||||
if (!_splitterContext.Initialize(ref _behaviourContext, ref parameter, workBufferAllocator))
|
||||
if (!_splitterContext.Initialize(ref _behaviourContext, ref parameter, workBufferAllocator, splitterBqfStates))
|
||||
{
|
||||
return ResultCode.WorkBufferTooSmall;
|
||||
}
|
||||
@ -775,6 +792,13 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
// Splitter
|
||||
size = SplitterContext.GetWorkBufferSize(size, ref behaviourContext, ref parameter);
|
||||
|
||||
if (behaviourContext.IsBiquadFilterParameterForSplitterEnabled() &&
|
||||
parameter.SplitterCount > 0 &&
|
||||
parameter.SplitterDestinationCount > 0)
|
||||
{
|
||||
size = WorkBufferAllocator.GetTargetSize<BiquadFilterState>(size, parameter.SplitterDestinationCount * SplitterContext.BqfStatesPerDestination, 0x10);
|
||||
}
|
||||
|
||||
// DSP Voice
|
||||
size = WorkBufferAllocator.GetTargetSize<VoiceUpdateState>(size, parameter.VoiceCount, VoiceUpdateState.Align);
|
||||
|
||||
|
@ -45,7 +45,6 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <see cref="Parameter.RendererInfoOutStatus"/> was added to supply the count of update done sent to the DSP.
|
||||
/// A new version of the command estimator was added to address timing changes caused by the voice changes.
|
||||
/// Additionally, the rendering limit percent was incremented to 80%.
|
||||
///
|
||||
/// </summary>
|
||||
/// <remarks>This was added in system update 6.0.0</remarks>
|
||||
public const int Revision5 = 5 << 24;
|
||||
@ -101,10 +100,18 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <remarks>This was added in system update 14.0.0 but some changes were made in 15.0.0</remarks>
|
||||
public const int Revision11 = 11 << 24;
|
||||
|
||||
/// <summary>
|
||||
/// REV12:
|
||||
/// Two new commands were added to for biquad filtering and mixing (with optinal volume ramp) on the same command.
|
||||
/// Splitter destinations can now specify up to two biquad filtering parameters, used for filtering the buffer before mixing.
|
||||
/// </summary>
|
||||
/// <remarks>This was added in system update 17.0.0</remarks>
|
||||
public const int Revision12 = 12 << 24;
|
||||
|
||||
/// <summary>
|
||||
/// Last revision supported by the implementation.
|
||||
/// </summary>
|
||||
public const int LastRevision = Revision11;
|
||||
public const int LastRevision = Revision12;
|
||||
|
||||
/// <summary>
|
||||
/// Target revision magic supported by the implementation.
|
||||
@ -212,7 +219,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <summary>
|
||||
/// Check if the audio renderer should fix the GC-ADPCM context not being provided to the DSP.
|
||||
/// </summary>
|
||||
/// <returns>True if if the audio renderer should fix it.</returns>
|
||||
/// <returns>True if the audio renderer should fix it.</returns>
|
||||
public bool IsAdpcmLoopContextBugFixed()
|
||||
{
|
||||
return CheckFeatureSupported(UserRevision, BaseRevisionMagic + Revision2);
|
||||
@ -354,7 +361,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// Check if the audio renderer should use an optimized Biquad Filter (Direct Form 1) in case of two biquad filters are defined on a voice.
|
||||
/// </summary>
|
||||
/// <returns>True if the audio renderer should use the optimization.</returns>
|
||||
public bool IsBiquadFilterGroupedOptimizationSupported()
|
||||
public bool UseMultiTapBiquadFilterProcessing()
|
||||
{
|
||||
return CheckFeatureSupported(UserRevision, BaseRevisionMagic + Revision10);
|
||||
}
|
||||
@ -368,6 +375,15 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
return CheckFeatureSupported(UserRevision, BaseRevisionMagic + Revision11);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the audio renderer should support biquad filter on splitter.
|
||||
/// </summary>
|
||||
/// <returns>True if the audio renderer support biquad filter on splitter</returns>
|
||||
public bool IsBiquadFilterParameterForSplitterEnabled()
|
||||
{
|
||||
return CheckFeatureSupported(UserRevision, BaseRevisionMagic + Revision12);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the version of the <see cref="ICommandProcessingTimeEstimator"/>.
|
||||
/// </summary>
|
||||
|
@ -204,7 +204,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="GroupedBiquadFilterCommand"/>.
|
||||
/// Create a new <see cref="MultiTapBiquadFilterCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="baseIndex">The base index of the input and output buffer.</param>
|
||||
/// <param name="filters">The biquad filter parameters.</param>
|
||||
@ -213,9 +213,9 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="outputBufferOffset">The output buffer offset.</param>
|
||||
/// <param name="isInitialized">Set to true if the biquad filter state is initialized.</param>
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateGroupedBiquadFilter(int baseIndex, ReadOnlySpan<BiquadFilterParameter> filters, Memory<BiquadFilterState> biquadFilterStatesMemory, int inputBufferOffset, int outputBufferOffset, ReadOnlySpan<bool> isInitialized, int nodeId)
|
||||
public void GenerateMultiTapBiquadFilter(int baseIndex, ReadOnlySpan<BiquadFilterParameter> filters, Memory<BiquadFilterState> biquadFilterStatesMemory, int inputBufferOffset, int outputBufferOffset, ReadOnlySpan<bool> isInitialized, int nodeId)
|
||||
{
|
||||
GroupedBiquadFilterCommand command = new(baseIndex, filters, biquadFilterStatesMemory, inputBufferOffset, outputBufferOffset, isInitialized, nodeId);
|
||||
MultiTapBiquadFilterCommand command = new(baseIndex, filters, biquadFilterStatesMemory, inputBufferOffset, outputBufferOffset, isInitialized, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@ -232,7 +232,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="volume">The new volume.</param>
|
||||
/// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateMixRampGrouped(uint mixBufferCount, uint inputBufferIndex, uint outputBufferIndex, Span<float> previousVolume, Span<float> volume, Memory<VoiceUpdateState> state, int nodeId)
|
||||
public void GenerateMixRampGrouped(uint mixBufferCount, uint inputBufferIndex, uint outputBufferIndex, ReadOnlySpan<float> previousVolume, ReadOnlySpan<float> volume, Memory<VoiceUpdateState> state, int nodeId)
|
||||
{
|
||||
MixRampGroupedCommand command = new(mixBufferCount, inputBufferIndex, outputBufferIndex, previousVolume, volume, state, nodeId);
|
||||
|
||||
@ -260,6 +260,120 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
AddCommand(command);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a new <see cref="BiquadFilterAndMixCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="previousVolume">The previous volume.</param>
|
||||
/// <param name="volume">The new volume.</param>
|
||||
/// <param name="inputBufferIndex">The input buffer index.</param>
|
||||
/// <param name="outputBufferIndex">The output buffer index.</param>
|
||||
/// <param name="lastSampleIndex">The index in the <see cref="VoiceUpdateState.LastSamples"/> array to store the ramped sample.</param>
|
||||
/// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
|
||||
/// <param name="filter">The biquad filter parameter.</param>
|
||||
/// <param name="biquadFilterState">The biquad state.</param>
|
||||
/// <param name="previousBiquadFilterState">The previous biquad state.</param>
|
||||
/// <param name="needInitialization">Set to true if the biquad filter state needs to be initialized.</param>
|
||||
/// <param name="hasVolumeRamp">Set to true if the mix has volume ramp, and <paramref name="previousVolume"/> should be taken into account.</param>
|
||||
/// <param name="isFirstMixBuffer">Set to true if the buffer is the first mix buffer.</param>
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateBiquadFilterAndMix(
|
||||
float previousVolume,
|
||||
float volume,
|
||||
uint inputBufferIndex,
|
||||
uint outputBufferIndex,
|
||||
int lastSampleIndex,
|
||||
Memory<VoiceUpdateState> state,
|
||||
ref BiquadFilterParameter filter,
|
||||
Memory<BiquadFilterState> biquadFilterState,
|
||||
Memory<BiquadFilterState> previousBiquadFilterState,
|
||||
bool needInitialization,
|
||||
bool hasVolumeRamp,
|
||||
bool isFirstMixBuffer,
|
||||
int nodeId)
|
||||
{
|
||||
BiquadFilterAndMixCommand command = new(
|
||||
previousVolume,
|
||||
volume,
|
||||
inputBufferIndex,
|
||||
outputBufferIndex,
|
||||
lastSampleIndex,
|
||||
state,
|
||||
ref filter,
|
||||
biquadFilterState,
|
||||
previousBiquadFilterState,
|
||||
needInitialization,
|
||||
hasVolumeRamp,
|
||||
isFirstMixBuffer,
|
||||
nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
AddCommand(command);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a new <see cref="MultiTapBiquadFilterAndMixCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="previousVolume">The previous volume.</param>
|
||||
/// <param name="volume">The new volume.</param>
|
||||
/// <param name="inputBufferIndex">The input buffer index.</param>
|
||||
/// <param name="outputBufferIndex">The output buffer index.</param>
|
||||
/// <param name="lastSampleIndex">The index in the <see cref="VoiceUpdateState.LastSamples"/> array to store the ramped sample.</param>
|
||||
/// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
|
||||
/// <param name="filter0">First biquad filter parameter.</param>
|
||||
/// <param name="filter1">Second biquad filter parameter.</param>
|
||||
/// <param name="biquadFilterState0">First biquad state.</param>
|
||||
/// <param name="biquadFilterState1">Second biquad state.</param>
|
||||
/// <param name="previousBiquadFilterState0">First previous biquad state.</param>
|
||||
/// <param name="previousBiquadFilterState1">Second previous biquad state.</param>
|
||||
/// <param name="needInitialization0">Set to true if the first biquad filter state needs to be initialized.</param>
|
||||
/// <param name="needInitialization1">Set to true if the second biquad filter state needs to be initialized.</param>
|
||||
/// <param name="hasVolumeRamp">Set to true if the mix has volume ramp, and <paramref name="previousVolume"/> should be taken into account.</param>
|
||||
/// <param name="isFirstMixBuffer">Set to true if the buffer is the first mix buffer.</param>
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateMultiTapBiquadFilterAndMix(
|
||||
float previousVolume,
|
||||
float volume,
|
||||
uint inputBufferIndex,
|
||||
uint outputBufferIndex,
|
||||
int lastSampleIndex,
|
||||
Memory<VoiceUpdateState> state,
|
||||
ref BiquadFilterParameter filter0,
|
||||
ref BiquadFilterParameter filter1,
|
||||
Memory<BiquadFilterState> biquadFilterState0,
|
||||
Memory<BiquadFilterState> biquadFilterState1,
|
||||
Memory<BiquadFilterState> previousBiquadFilterState0,
|
||||
Memory<BiquadFilterState> previousBiquadFilterState1,
|
||||
bool needInitialization0,
|
||||
bool needInitialization1,
|
||||
bool hasVolumeRamp,
|
||||
bool isFirstMixBuffer,
|
||||
int nodeId)
|
||||
{
|
||||
MultiTapBiquadFilterAndMixCommand command = new(
|
||||
previousVolume,
|
||||
volume,
|
||||
inputBufferIndex,
|
||||
outputBufferIndex,
|
||||
lastSampleIndex,
|
||||
state,
|
||||
ref filter0,
|
||||
ref filter1,
|
||||
biquadFilterState0,
|
||||
biquadFilterState1,
|
||||
previousBiquadFilterState0,
|
||||
previousBiquadFilterState1,
|
||||
needInitialization0,
|
||||
needInitialization1,
|
||||
hasVolumeRamp,
|
||||
isFirstMixBuffer,
|
||||
nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
AddCommand(command);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a new <see cref="DepopForMixBuffersCommand"/>.
|
||||
/// </summary>
|
||||
@ -268,7 +382,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="bufferCount">The buffer count.</param>
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
/// <param name="sampleRate">The target sample rate in use.</param>
|
||||
public void GenerateDepopForMixBuffersCommand(Memory<float> depopBuffer, uint bufferOffset, uint bufferCount, int nodeId, uint sampleRate)
|
||||
public void GenerateDepopForMixBuffers(Memory<float> depopBuffer, uint bufferOffset, uint bufferCount, int nodeId, uint sampleRate)
|
||||
{
|
||||
DepopForMixBuffersCommand command = new(depopBuffer, bufferOffset, bufferCount, nodeId, sampleRate);
|
||||
|
||||
|
@ -12,6 +12,7 @@ using Ryujinx.Audio.Renderer.Server.Voice;
|
||||
using Ryujinx.Audio.Renderer.Utils;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
@ -46,12 +47,13 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
ref MixState mix = ref _mixContext.GetState(voiceState.MixId);
|
||||
|
||||
_commandBuffer.GenerateDepopPrepare(dspState,
|
||||
_rendererContext.DepopBuffer,
|
||||
mix.BufferCount,
|
||||
mix.BufferOffset,
|
||||
voiceState.NodeId,
|
||||
voiceState.WasPlaying);
|
||||
_commandBuffer.GenerateDepopPrepare(
|
||||
dspState,
|
||||
_rendererContext.DepopBuffer,
|
||||
mix.BufferCount,
|
||||
mix.BufferOffset,
|
||||
voiceState.NodeId,
|
||||
voiceState.WasPlaying);
|
||||
}
|
||||
else if (voiceState.SplitterId != Constants.UnusedSplitterId)
|
||||
{
|
||||
@ -59,15 +61,13 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
while (true)
|
||||
{
|
||||
Span<SplitterDestination> destinationSpan = _splitterContext.GetDestination((int)voiceState.SplitterId, destinationId++);
|
||||
SplitterDestination destination = _splitterContext.GetDestination((int)voiceState.SplitterId, destinationId++);
|
||||
|
||||
if (destinationSpan.IsEmpty)
|
||||
if (destination.IsNull)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
ref SplitterDestination destination = ref destinationSpan[0];
|
||||
|
||||
if (destination.IsConfigured())
|
||||
{
|
||||
int mixId = destination.DestinationId;
|
||||
@ -76,12 +76,13 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
ref MixState mix = ref _mixContext.GetState(mixId);
|
||||
|
||||
_commandBuffer.GenerateDepopPrepare(dspState,
|
||||
_rendererContext.DepopBuffer,
|
||||
mix.BufferCount,
|
||||
mix.BufferOffset,
|
||||
voiceState.NodeId,
|
||||
voiceState.WasPlaying);
|
||||
_commandBuffer.GenerateDepopPrepare(
|
||||
dspState,
|
||||
_rendererContext.DepopBuffer,
|
||||
mix.BufferCount,
|
||||
mix.BufferOffset,
|
||||
voiceState.NodeId,
|
||||
voiceState.WasPlaying);
|
||||
|
||||
destination.MarkAsNeedToUpdateInternalState();
|
||||
}
|
||||
@ -95,35 +96,39 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
if (_rendererContext.BehaviourContext.IsWaveBufferVersion2Supported())
|
||||
{
|
||||
_commandBuffer.GenerateDataSourceVersion2(ref voiceState,
|
||||
dspState,
|
||||
(ushort)_rendererContext.MixBufferCount,
|
||||
(ushort)channelIndex,
|
||||
voiceState.NodeId);
|
||||
_commandBuffer.GenerateDataSourceVersion2(
|
||||
ref voiceState,
|
||||
dspState,
|
||||
(ushort)_rendererContext.MixBufferCount,
|
||||
(ushort)channelIndex,
|
||||
voiceState.NodeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (voiceState.SampleFormat)
|
||||
{
|
||||
case SampleFormat.PcmInt16:
|
||||
_commandBuffer.GeneratePcmInt16DataSourceVersion1(ref voiceState,
|
||||
dspState,
|
||||
(ushort)_rendererContext.MixBufferCount,
|
||||
(ushort)channelIndex,
|
||||
voiceState.NodeId);
|
||||
_commandBuffer.GeneratePcmInt16DataSourceVersion1(
|
||||
ref voiceState,
|
||||
dspState,
|
||||
(ushort)_rendererContext.MixBufferCount,
|
||||
(ushort)channelIndex,
|
||||
voiceState.NodeId);
|
||||
break;
|
||||
case SampleFormat.PcmFloat:
|
||||
_commandBuffer.GeneratePcmFloatDataSourceVersion1(ref voiceState,
|
||||
dspState,
|
||||
(ushort)_rendererContext.MixBufferCount,
|
||||
(ushort)channelIndex,
|
||||
voiceState.NodeId);
|
||||
_commandBuffer.GeneratePcmFloatDataSourceVersion1(
|
||||
ref voiceState,
|
||||
dspState,
|
||||
(ushort)_rendererContext.MixBufferCount,
|
||||
(ushort)channelIndex,
|
||||
voiceState.NodeId);
|
||||
break;
|
||||
case SampleFormat.Adpcm:
|
||||
_commandBuffer.GenerateAdpcmDataSourceVersion1(ref voiceState,
|
||||
dspState,
|
||||
(ushort)_rendererContext.MixBufferCount,
|
||||
voiceState.NodeId);
|
||||
_commandBuffer.GenerateAdpcmDataSourceVersion1(
|
||||
ref voiceState,
|
||||
dspState,
|
||||
(ushort)_rendererContext.MixBufferCount,
|
||||
voiceState.NodeId);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException($"Unsupported data source {voiceState.SampleFormat}");
|
||||
@ -134,14 +139,14 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
private void GenerateBiquadFilterForVoice(ref VoiceState voiceState, Memory<VoiceUpdateState> state, int baseIndex, int bufferOffset, int nodeId)
|
||||
{
|
||||
bool supportsOptimizedPath = _rendererContext.BehaviourContext.IsBiquadFilterGroupedOptimizationSupported();
|
||||
bool supportsOptimizedPath = _rendererContext.BehaviourContext.UseMultiTapBiquadFilterProcessing();
|
||||
|
||||
if (supportsOptimizedPath && voiceState.BiquadFilters[0].Enable && voiceState.BiquadFilters[1].Enable)
|
||||
{
|
||||
Memory<byte> biquadStateRawMemory = SpanMemoryManager<byte>.Cast(state)[..(VoiceUpdateState.BiquadStateSize * Constants.VoiceBiquadFilterCount)];
|
||||
Memory<byte> biquadStateRawMemory = SpanMemoryManager<byte>.Cast(state)[..(Unsafe.SizeOf<BiquadFilterState>() * Constants.VoiceBiquadFilterCount)];
|
||||
Memory<BiquadFilterState> stateMemory = SpanMemoryManager<BiquadFilterState>.Cast(biquadStateRawMemory);
|
||||
|
||||
_commandBuffer.GenerateGroupedBiquadFilter(baseIndex, voiceState.BiquadFilters.AsSpan(), stateMemory, bufferOffset, bufferOffset, voiceState.BiquadFilterNeedInitialization, nodeId);
|
||||
_commandBuffer.GenerateMultiTapBiquadFilter(baseIndex, voiceState.BiquadFilters.AsSpan(), stateMemory, bufferOffset, bufferOffset, voiceState.BiquadFilterNeedInitialization, nodeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -151,33 +156,134 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
if (filter.Enable)
|
||||
{
|
||||
Memory<byte> biquadStateRawMemory = SpanMemoryManager<byte>.Cast(state)[..(VoiceUpdateState.BiquadStateSize * Constants.VoiceBiquadFilterCount)];
|
||||
|
||||
Memory<byte> biquadStateRawMemory = SpanMemoryManager<byte>.Cast(state)[..(Unsafe.SizeOf<BiquadFilterState>() * Constants.VoiceBiquadFilterCount)];
|
||||
Memory<BiquadFilterState> stateMemory = SpanMemoryManager<BiquadFilterState>.Cast(biquadStateRawMemory);
|
||||
|
||||
_commandBuffer.GenerateBiquadFilter(baseIndex,
|
||||
ref filter,
|
||||
stateMemory.Slice(i, 1),
|
||||
bufferOffset,
|
||||
bufferOffset,
|
||||
!voiceState.BiquadFilterNeedInitialization[i],
|
||||
nodeId);
|
||||
_commandBuffer.GenerateBiquadFilter(
|
||||
baseIndex,
|
||||
ref filter,
|
||||
stateMemory.Slice(i, 1),
|
||||
bufferOffset,
|
||||
bufferOffset,
|
||||
!voiceState.BiquadFilterNeedInitialization[i],
|
||||
nodeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateVoiceMix(Span<float> mixVolumes, Span<float> previousMixVolumes, Memory<VoiceUpdateState> state, uint bufferOffset, uint bufferCount, uint bufferIndex, int nodeId)
|
||||
private void GenerateVoiceMixWithSplitter(
|
||||
SplitterDestination destination,
|
||||
Memory<VoiceUpdateState> state,
|
||||
uint bufferOffset,
|
||||
uint bufferCount,
|
||||
uint bufferIndex,
|
||||
int nodeId)
|
||||
{
|
||||
ReadOnlySpan<float> mixVolumes = destination.MixBufferVolume;
|
||||
ReadOnlySpan<float> previousMixVolumes = destination.PreviousMixBufferVolume;
|
||||
|
||||
ref BiquadFilterParameter bqf0 = ref destination.GetBiquadFilterParameter(0);
|
||||
ref BiquadFilterParameter bqf1 = ref destination.GetBiquadFilterParameter(1);
|
||||
|
||||
Memory<BiquadFilterState> bqfState = _splitterContext.GetBiquadFilterState(destination);
|
||||
|
||||
bool isFirstMixBuffer = true;
|
||||
|
||||
for (int i = 0; i < bufferCount; i++)
|
||||
{
|
||||
float previousMixVolume = previousMixVolumes[i];
|
||||
float mixVolume = mixVolumes[i];
|
||||
|
||||
if (mixVolume != 0.0f || previousMixVolume != 0.0f)
|
||||
{
|
||||
if (bqf0.Enable && bqf1.Enable)
|
||||
{
|
||||
_commandBuffer.GenerateMultiTapBiquadFilterAndMix(
|
||||
previousMixVolume,
|
||||
mixVolume,
|
||||
bufferIndex,
|
||||
bufferOffset + (uint)i,
|
||||
i,
|
||||
state,
|
||||
ref bqf0,
|
||||
ref bqf1,
|
||||
bqfState[..1],
|
||||
bqfState.Slice(1, 1),
|
||||
bqfState.Slice(2, 1),
|
||||
bqfState.Slice(3, 1),
|
||||
!destination.IsBiquadFilterEnabledPrev(),
|
||||
!destination.IsBiquadFilterEnabledPrev(),
|
||||
true,
|
||||
isFirstMixBuffer,
|
||||
nodeId);
|
||||
|
||||
destination.UpdateBiquadFilterEnabledPrev(0);
|
||||
destination.UpdateBiquadFilterEnabledPrev(1);
|
||||
}
|
||||
else if (bqf0.Enable)
|
||||
{
|
||||
_commandBuffer.GenerateBiquadFilterAndMix(
|
||||
previousMixVolume,
|
||||
mixVolume,
|
||||
bufferIndex,
|
||||
bufferOffset + (uint)i,
|
||||
i,
|
||||
state,
|
||||
ref bqf0,
|
||||
bqfState[..1],
|
||||
bqfState.Slice(1, 1),
|
||||
!destination.IsBiquadFilterEnabledPrev(),
|
||||
true,
|
||||
isFirstMixBuffer,
|
||||
nodeId);
|
||||
|
||||
destination.UpdateBiquadFilterEnabledPrev(0);
|
||||
}
|
||||
else if (bqf1.Enable)
|
||||
{
|
||||
_commandBuffer.GenerateBiquadFilterAndMix(
|
||||
previousMixVolume,
|
||||
mixVolume,
|
||||
bufferIndex,
|
||||
bufferOffset + (uint)i,
|
||||
i,
|
||||
state,
|
||||
ref bqf1,
|
||||
bqfState[..1],
|
||||
bqfState.Slice(1, 1),
|
||||
!destination.IsBiquadFilterEnabledPrev(),
|
||||
true,
|
||||
isFirstMixBuffer,
|
||||
nodeId);
|
||||
|
||||
destination.UpdateBiquadFilterEnabledPrev(1);
|
||||
}
|
||||
|
||||
isFirstMixBuffer = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateVoiceMix(
|
||||
ReadOnlySpan<float> mixVolumes,
|
||||
ReadOnlySpan<float> previousMixVolumes,
|
||||
Memory<VoiceUpdateState> state,
|
||||
uint bufferOffset,
|
||||
uint bufferCount,
|
||||
uint bufferIndex,
|
||||
int nodeId)
|
||||
{
|
||||
if (bufferCount > Constants.VoiceChannelCountMax)
|
||||
{
|
||||
_commandBuffer.GenerateMixRampGrouped(bufferCount,
|
||||
bufferIndex,
|
||||
bufferOffset,
|
||||
previousMixVolumes,
|
||||
mixVolumes,
|
||||
state,
|
||||
nodeId);
|
||||
_commandBuffer.GenerateMixRampGrouped(
|
||||
bufferCount,
|
||||
bufferIndex,
|
||||
bufferOffset,
|
||||
previousMixVolumes,
|
||||
mixVolumes,
|
||||
state,
|
||||
nodeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -188,13 +294,14 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
if (mixVolume != 0.0f || previousMixVolume != 0.0f)
|
||||
{
|
||||
_commandBuffer.GenerateMixRamp(previousMixVolume,
|
||||
mixVolume,
|
||||
bufferIndex,
|
||||
bufferOffset + (uint)i,
|
||||
i,
|
||||
state,
|
||||
nodeId);
|
||||
_commandBuffer.GenerateMixRamp(
|
||||
previousMixVolume,
|
||||
mixVolume,
|
||||
bufferIndex,
|
||||
bufferOffset + (uint)i,
|
||||
i,
|
||||
state,
|
||||
nodeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -271,10 +378,11 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
GeneratePerformance(ref performanceEntry, PerformanceCommand.Type.Start, nodeId);
|
||||
}
|
||||
|
||||
_commandBuffer.GenerateVolumeRamp(voiceState.PreviousVolume,
|
||||
voiceState.Volume,
|
||||
_rendererContext.MixBufferCount + (uint)channelIndex,
|
||||
nodeId);
|
||||
_commandBuffer.GenerateVolumeRamp(
|
||||
voiceState.PreviousVolume,
|
||||
voiceState.Volume,
|
||||
_rendererContext.MixBufferCount + (uint)channelIndex,
|
||||
nodeId);
|
||||
|
||||
if (performanceInitialized)
|
||||
{
|
||||
@ -291,15 +399,13 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
while (true)
|
||||
{
|
||||
Span<SplitterDestination> destinationSpan = _splitterContext.GetDestination((int)voiceState.SplitterId, destinationId);
|
||||
SplitterDestination destination = _splitterContext.GetDestination((int)voiceState.SplitterId, destinationId);
|
||||
|
||||
if (destinationSpan.IsEmpty)
|
||||
if (destination.IsNull)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
ref SplitterDestination destination = ref destinationSpan[0];
|
||||
|
||||
destinationId += (int)channelsCount;
|
||||
|
||||
if (destination.IsConfigured())
|
||||
@ -310,13 +416,27 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
ref MixState mix = ref _mixContext.GetState(mixId);
|
||||
|
||||
GenerateVoiceMix(destination.MixBufferVolume,
|
||||
destination.PreviousMixBufferVolume,
|
||||
dspStateMemory,
|
||||
mix.BufferOffset,
|
||||
mix.BufferCount,
|
||||
_rendererContext.MixBufferCount + (uint)channelIndex,
|
||||
nodeId);
|
||||
if (destination.IsBiquadFilterEnabled())
|
||||
{
|
||||
GenerateVoiceMixWithSplitter(
|
||||
destination,
|
||||
dspStateMemory,
|
||||
mix.BufferOffset,
|
||||
mix.BufferCount,
|
||||
_rendererContext.MixBufferCount + (uint)channelIndex,
|
||||
nodeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
GenerateVoiceMix(
|
||||
destination.MixBufferVolume,
|
||||
destination.PreviousMixBufferVolume,
|
||||
dspStateMemory,
|
||||
mix.BufferOffset,
|
||||
mix.BufferCount,
|
||||
_rendererContext.MixBufferCount + (uint)channelIndex,
|
||||
nodeId);
|
||||
}
|
||||
|
||||
destination.MarkAsNeedToUpdateInternalState();
|
||||
}
|
||||
@ -337,13 +457,14 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
GeneratePerformance(ref performanceEntry, PerformanceCommand.Type.Start, nodeId);
|
||||
}
|
||||
|
||||
GenerateVoiceMix(channelResource.Mix.AsSpan(),
|
||||
channelResource.PreviousMix.AsSpan(),
|
||||
dspStateMemory,
|
||||
mix.BufferOffset,
|
||||
mix.BufferCount,
|
||||
_rendererContext.MixBufferCount + (uint)channelIndex,
|
||||
nodeId);
|
||||
GenerateVoiceMix(
|
||||
channelResource.Mix.AsSpan(),
|
||||
channelResource.PreviousMix.AsSpan(),
|
||||
dspStateMemory,
|
||||
mix.BufferOffset,
|
||||
mix.BufferCount,
|
||||
_rendererContext.MixBufferCount + (uint)channelIndex,
|
||||
nodeId);
|
||||
|
||||
if (performanceInitialized)
|
||||
{
|
||||
@ -409,10 +530,11 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
if (effect.Parameter.Volumes[i] != 0.0f)
|
||||
{
|
||||
_commandBuffer.GenerateMix((uint)bufferOffset + effect.Parameter.Input[i],
|
||||
(uint)bufferOffset + effect.Parameter.Output[i],
|
||||
nodeId,
|
||||
effect.Parameter.Volumes[i]);
|
||||
_commandBuffer.GenerateMix(
|
||||
(uint)bufferOffset + effect.Parameter.Input[i],
|
||||
(uint)bufferOffset + effect.Parameter.Output[i],
|
||||
nodeId,
|
||||
effect.Parameter.Volumes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -447,17 +569,18 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
updateCount = newUpdateCount;
|
||||
}
|
||||
|
||||
_commandBuffer.GenerateAuxEffect(bufferOffset,
|
||||
effect.Parameter.Input[i],
|
||||
effect.Parameter.Output[i],
|
||||
ref effect.State,
|
||||
effect.IsEnabled,
|
||||
effect.Parameter.BufferStorageSize,
|
||||
effect.State.SendBufferInfoBase,
|
||||
effect.State.ReturnBufferInfoBase,
|
||||
updateCount,
|
||||
writeOffset,
|
||||
nodeId);
|
||||
_commandBuffer.GenerateAuxEffect(
|
||||
bufferOffset,
|
||||
effect.Parameter.Input[i],
|
||||
effect.Parameter.Output[i],
|
||||
ref effect.State,
|
||||
effect.IsEnabled,
|
||||
effect.Parameter.BufferStorageSize,
|
||||
effect.State.SendBufferInfoBase,
|
||||
effect.State.ReturnBufferInfoBase,
|
||||
updateCount,
|
||||
writeOffset,
|
||||
nodeId);
|
||||
|
||||
writeOffset = newUpdateCount;
|
||||
|
||||
@ -500,7 +623,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
if (effect.IsEnabled)
|
||||
{
|
||||
bool needInitialization = effect.Parameter.Status == UsageState.Invalid ||
|
||||
(effect.Parameter.Status == UsageState.New && !_rendererContext.BehaviourContext.IsBiquadFilterEffectStateClearBugFixed());
|
||||
(effect.Parameter.Status == UsageState.New && !_rendererContext.BehaviourContext.IsBiquadFilterEffectStateClearBugFixed());
|
||||
|
||||
BiquadFilterParameter parameter = new()
|
||||
{
|
||||
@ -512,11 +635,14 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
for (int i = 0; i < effect.Parameter.ChannelCount; i++)
|
||||
{
|
||||
_commandBuffer.GenerateBiquadFilter((int)bufferOffset, ref parameter, effect.State.Slice(i, 1),
|
||||
effect.Parameter.Input[i],
|
||||
effect.Parameter.Output[i],
|
||||
needInitialization,
|
||||
nodeId);
|
||||
_commandBuffer.GenerateBiquadFilter(
|
||||
(int)bufferOffset,
|
||||
ref parameter,
|
||||
effect.State.Slice(i, 1),
|
||||
effect.Parameter.Input[i],
|
||||
effect.Parameter.Output[i],
|
||||
needInitialization,
|
||||
nodeId);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -591,15 +717,16 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
updateCount = newUpdateCount;
|
||||
}
|
||||
|
||||
_commandBuffer.GenerateCaptureEffect(bufferOffset,
|
||||
effect.Parameter.Input[i],
|
||||
effect.State.SendBufferInfo,
|
||||
effect.IsEnabled,
|
||||
effect.Parameter.BufferStorageSize,
|
||||
effect.State.SendBufferInfoBase,
|
||||
updateCount,
|
||||
writeOffset,
|
||||
nodeId);
|
||||
_commandBuffer.GenerateCaptureEffect(
|
||||
bufferOffset,
|
||||
effect.Parameter.Input[i],
|
||||
effect.State.SendBufferInfo,
|
||||
effect.IsEnabled,
|
||||
effect.Parameter.BufferStorageSize,
|
||||
effect.State.SendBufferInfoBase,
|
||||
updateCount,
|
||||
writeOffset,
|
||||
nodeId);
|
||||
|
||||
writeOffset = newUpdateCount;
|
||||
|
||||
@ -612,11 +739,12 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
Debug.Assert(effect.Type == EffectType.Compressor);
|
||||
|
||||
_commandBuffer.GenerateCompressorEffect(bufferOffset,
|
||||
effect.Parameter,
|
||||
effect.State,
|
||||
effect.IsEnabled,
|
||||
nodeId);
|
||||
_commandBuffer.GenerateCompressorEffect(
|
||||
bufferOffset,
|
||||
effect.Parameter,
|
||||
effect.State,
|
||||
effect.IsEnabled,
|
||||
nodeId);
|
||||
}
|
||||
|
||||
private void GenerateEffect(ref MixState mix, int effectId, BaseEffect effect)
|
||||
@ -629,8 +757,11 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
bool performanceInitialized = false;
|
||||
|
||||
if (_performanceManager != null && _performanceManager.GetNextEntry(out performanceEntry, effect.GetPerformanceDetailType(),
|
||||
isFinalMix ? PerformanceEntryType.FinalMix : PerformanceEntryType.SubMix, nodeId))
|
||||
if (_performanceManager != null && _performanceManager.GetNextEntry(
|
||||
out performanceEntry,
|
||||
effect.GetPerformanceDetailType(),
|
||||
isFinalMix ? PerformanceEntryType.FinalMix : PerformanceEntryType.SubMix,
|
||||
nodeId))
|
||||
{
|
||||
performanceInitialized = true;
|
||||
|
||||
@ -706,6 +837,85 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateMixWithSplitter(
|
||||
uint inputBufferIndex,
|
||||
uint outputBufferIndex,
|
||||
float volume,
|
||||
SplitterDestination destination,
|
||||
ref bool isFirstMixBuffer,
|
||||
int nodeId)
|
||||
{
|
||||
ref BiquadFilterParameter bqf0 = ref destination.GetBiquadFilterParameter(0);
|
||||
ref BiquadFilterParameter bqf1 = ref destination.GetBiquadFilterParameter(1);
|
||||
|
||||
Memory<BiquadFilterState> bqfState = _splitterContext.GetBiquadFilterState(destination);
|
||||
|
||||
if (bqf0.Enable && bqf1.Enable)
|
||||
{
|
||||
_commandBuffer.GenerateMultiTapBiquadFilterAndMix(
|
||||
0f,
|
||||
volume,
|
||||
inputBufferIndex,
|
||||
outputBufferIndex,
|
||||
0,
|
||||
Memory<VoiceUpdateState>.Empty,
|
||||
ref bqf0,
|
||||
ref bqf1,
|
||||
bqfState[..1],
|
||||
bqfState.Slice(1, 1),
|
||||
bqfState.Slice(2, 1),
|
||||
bqfState.Slice(3, 1),
|
||||
!destination.IsBiquadFilterEnabledPrev(),
|
||||
!destination.IsBiquadFilterEnabledPrev(),
|
||||
false,
|
||||
isFirstMixBuffer,
|
||||
nodeId);
|
||||
|
||||
destination.UpdateBiquadFilterEnabledPrev(0);
|
||||
destination.UpdateBiquadFilterEnabledPrev(1);
|
||||
}
|
||||
else if (bqf0.Enable)
|
||||
{
|
||||
_commandBuffer.GenerateBiquadFilterAndMix(
|
||||
0f,
|
||||
volume,
|
||||
inputBufferIndex,
|
||||
outputBufferIndex,
|
||||
0,
|
||||
Memory<VoiceUpdateState>.Empty,
|
||||
ref bqf0,
|
||||
bqfState[..1],
|
||||
bqfState.Slice(1, 1),
|
||||
!destination.IsBiquadFilterEnabledPrev(),
|
||||
false,
|
||||
isFirstMixBuffer,
|
||||
nodeId);
|
||||
|
||||
destination.UpdateBiquadFilterEnabledPrev(0);
|
||||
}
|
||||
else if (bqf1.Enable)
|
||||
{
|
||||
_commandBuffer.GenerateBiquadFilterAndMix(
|
||||
0f,
|
||||
volume,
|
||||
inputBufferIndex,
|
||||
outputBufferIndex,
|
||||
0,
|
||||
Memory<VoiceUpdateState>.Empty,
|
||||
ref bqf1,
|
||||
bqfState[..1],
|
||||
bqfState.Slice(1, 1),
|
||||
!destination.IsBiquadFilterEnabledPrev(),
|
||||
false,
|
||||
isFirstMixBuffer,
|
||||
nodeId);
|
||||
|
||||
destination.UpdateBiquadFilterEnabledPrev(1);
|
||||
}
|
||||
|
||||
isFirstMixBuffer = false;
|
||||
}
|
||||
|
||||
private void GenerateMix(ref MixState mix)
|
||||
{
|
||||
if (mix.HasAnyDestination())
|
||||
@ -722,15 +932,13 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
int destinationIndex = destinationId++;
|
||||
|
||||
Span<SplitterDestination> destinationSpan = _splitterContext.GetDestination((int)mix.DestinationSplitterId, destinationIndex);
|
||||
SplitterDestination destination = _splitterContext.GetDestination((int)mix.DestinationSplitterId, destinationIndex);
|
||||
|
||||
if (destinationSpan.IsEmpty)
|
||||
if (destination.IsNull)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
ref SplitterDestination destination = ref destinationSpan[0];
|
||||
|
||||
if (destination.IsConfigured())
|
||||
{
|
||||
int mixId = destination.DestinationId;
|
||||
@ -741,16 +949,32 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
uint inputBufferIndex = mix.BufferOffset + ((uint)destinationIndex % mix.BufferCount);
|
||||
|
||||
bool isFirstMixBuffer = true;
|
||||
|
||||
for (uint bufferDestinationIndex = 0; bufferDestinationIndex < destinationMix.BufferCount; bufferDestinationIndex++)
|
||||
{
|
||||
float volume = mix.Volume * destination.GetMixVolume((int)bufferDestinationIndex);
|
||||
|
||||
if (volume != 0.0f)
|
||||
{
|
||||
_commandBuffer.GenerateMix(inputBufferIndex,
|
||||
destinationMix.BufferOffset + bufferDestinationIndex,
|
||||
mix.NodeId,
|
||||
volume);
|
||||
if (destination.IsBiquadFilterEnabled())
|
||||
{
|
||||
GenerateMixWithSplitter(
|
||||
inputBufferIndex,
|
||||
destinationMix.BufferOffset + bufferDestinationIndex,
|
||||
volume,
|
||||
destination,
|
||||
ref isFirstMixBuffer,
|
||||
mix.NodeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_commandBuffer.GenerateMix(
|
||||
inputBufferIndex,
|
||||
destinationMix.BufferOffset + bufferDestinationIndex,
|
||||
mix.NodeId,
|
||||
volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -770,10 +994,11 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
if (volume != 0.0f)
|
||||
{
|
||||
_commandBuffer.GenerateMix(mix.BufferOffset + bufferIndex,
|
||||
destinationMix.BufferOffset + bufferDestinationIndex,
|
||||
mix.NodeId,
|
||||
volume);
|
||||
_commandBuffer.GenerateMix(
|
||||
mix.BufferOffset + bufferIndex,
|
||||
destinationMix.BufferOffset + bufferDestinationIndex,
|
||||
mix.NodeId,
|
||||
volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -783,11 +1008,12 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
private void GenerateSubMix(ref MixState subMix)
|
||||
{
|
||||
_commandBuffer.GenerateDepopForMixBuffersCommand(_rendererContext.DepopBuffer,
|
||||
subMix.BufferOffset,
|
||||
subMix.BufferCount,
|
||||
subMix.NodeId,
|
||||
subMix.SampleRate);
|
||||
_commandBuffer.GenerateDepopForMixBuffers(
|
||||
_rendererContext.DepopBuffer,
|
||||
subMix.BufferOffset,
|
||||
subMix.BufferCount,
|
||||
subMix.NodeId,
|
||||
subMix.SampleRate);
|
||||
|
||||
GenerateEffects(ref subMix);
|
||||
|
||||
@ -847,11 +1073,12 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
ref MixState finalMix = ref _mixContext.GetFinalState();
|
||||
|
||||
_commandBuffer.GenerateDepopForMixBuffersCommand(_rendererContext.DepopBuffer,
|
||||
finalMix.BufferOffset,
|
||||
finalMix.BufferCount,
|
||||
finalMix.NodeId,
|
||||
finalMix.SampleRate);
|
||||
_commandBuffer.GenerateDepopForMixBuffers(
|
||||
_rendererContext.DepopBuffer,
|
||||
finalMix.BufferOffset,
|
||||
finalMix.BufferCount,
|
||||
finalMix.NodeId,
|
||||
finalMix.SampleRate);
|
||||
|
||||
GenerateEffects(ref finalMix);
|
||||
|
||||
@ -882,9 +1109,10 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
GeneratePerformance(ref performanceEntry, PerformanceCommand.Type.Start, nodeId);
|
||||
}
|
||||
|
||||
_commandBuffer.GenerateVolume(finalMix.Volume,
|
||||
finalMix.BufferOffset + bufferIndex,
|
||||
nodeId);
|
||||
_commandBuffer.GenerateVolume(
|
||||
finalMix.Volume,
|
||||
finalMix.BufferOffset + bufferIndex,
|
||||
nodeId);
|
||||
|
||||
if (performanceSubInitialized)
|
||||
{
|
||||
@ -938,41 +1166,45 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
if (useCustomDownMixingCommand)
|
||||
{
|
||||
_commandBuffer.GenerateDownMixSurroundToStereo(finalMix.BufferOffset,
|
||||
sink.Parameter.Input.AsSpan(),
|
||||
sink.Parameter.Input.AsSpan(),
|
||||
sink.DownMixCoefficients,
|
||||
Constants.InvalidNodeId);
|
||||
_commandBuffer.GenerateDownMixSurroundToStereo(
|
||||
finalMix.BufferOffset,
|
||||
sink.Parameter.Input.AsSpan(),
|
||||
sink.Parameter.Input.AsSpan(),
|
||||
sink.DownMixCoefficients,
|
||||
Constants.InvalidNodeId);
|
||||
}
|
||||
// NOTE: We do the downmixing at the DSP level as it's easier that way.
|
||||
else if (_rendererContext.ChannelCount == 2 && sink.Parameter.InputCount == 6)
|
||||
{
|
||||
_commandBuffer.GenerateDownMixSurroundToStereo(finalMix.BufferOffset,
|
||||
sink.Parameter.Input.AsSpan(),
|
||||
sink.Parameter.Input.AsSpan(),
|
||||
Constants.DefaultSurroundToStereoCoefficients,
|
||||
Constants.InvalidNodeId);
|
||||
_commandBuffer.GenerateDownMixSurroundToStereo(
|
||||
finalMix.BufferOffset,
|
||||
sink.Parameter.Input.AsSpan(),
|
||||
sink.Parameter.Input.AsSpan(),
|
||||
Constants.DefaultSurroundToStereoCoefficients,
|
||||
Constants.InvalidNodeId);
|
||||
}
|
||||
|
||||
CommandList commandList = _commandBuffer.CommandList;
|
||||
|
||||
if (sink.UpsamplerState != null)
|
||||
{
|
||||
_commandBuffer.GenerateUpsample(finalMix.BufferOffset,
|
||||
sink.UpsamplerState,
|
||||
sink.Parameter.InputCount,
|
||||
sink.Parameter.Input.AsSpan(),
|
||||
commandList.BufferCount,
|
||||
commandList.SampleCount,
|
||||
commandList.SampleRate,
|
||||
Constants.InvalidNodeId);
|
||||
_commandBuffer.GenerateUpsample(
|
||||
finalMix.BufferOffset,
|
||||
sink.UpsamplerState,
|
||||
sink.Parameter.InputCount,
|
||||
sink.Parameter.Input.AsSpan(),
|
||||
commandList.BufferCount,
|
||||
commandList.SampleCount,
|
||||
commandList.SampleRate,
|
||||
Constants.InvalidNodeId);
|
||||
}
|
||||
|
||||
_commandBuffer.GenerateDeviceSink(finalMix.BufferOffset,
|
||||
sink,
|
||||
_rendererContext.SessionId,
|
||||
commandList.Buffers,
|
||||
Constants.InvalidNodeId);
|
||||
_commandBuffer.GenerateDeviceSink(
|
||||
finalMix.BufferOffset,
|
||||
sink,
|
||||
_rendererContext.SessionId,
|
||||
commandList.Buffers,
|
||||
Constants.InvalidNodeId);
|
||||
}
|
||||
|
||||
private void GenerateSink(BaseSink sink, ref MixState finalMix)
|
||||
|
@ -170,7 +170,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
return 0;
|
||||
}
|
||||
|
||||
public uint Estimate(GroupedBiquadFilterCommand command)
|
||||
public uint Estimate(MultiTapBiquadFilterCommand command)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -184,5 +184,15 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public uint Estimate(BiquadFilterAndMixCommand command)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public uint Estimate(MultiTapBiquadFilterAndMixCommand command)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
return 0;
|
||||
}
|
||||
|
||||
public uint Estimate(GroupedBiquadFilterCommand command)
|
||||
public uint Estimate(MultiTapBiquadFilterCommand command)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -476,5 +476,15 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public uint Estimate(BiquadFilterAndMixCommand command)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public uint Estimate(MultiTapBiquadFilterAndMixCommand command)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -632,7 +632,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
};
|
||||
}
|
||||
|
||||
public virtual uint Estimate(GroupedBiquadFilterCommand command)
|
||||
public virtual uint Estimate(MultiTapBiquadFilterCommand command)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -646,5 +646,15 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public virtual uint Estimate(BiquadFilterAndMixCommand command)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public virtual uint Estimate(MultiTapBiquadFilterAndMixCommand command)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
public CommandProcessingTimeEstimatorVersion4(uint sampleCount, uint bufferCount) : base(sampleCount, bufferCount) { }
|
||||
|
||||
public override uint Estimate(GroupedBiquadFilterCommand command)
|
||||
public override uint Estimate(MultiTapBiquadFilterCommand command)
|
||||
{
|
||||
Debug.Assert(SampleCount == 160 || SampleCount == 240);
|
||||
|
||||
|
@ -210,5 +210,53 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
_ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"),
|
||||
};
|
||||
}
|
||||
|
||||
public override uint Estimate(BiquadFilterAndMixCommand command)
|
||||
{
|
||||
Debug.Assert(SampleCount == 160 || SampleCount == 240);
|
||||
|
||||
if (command.HasVolumeRamp)
|
||||
{
|
||||
if (SampleCount == 160)
|
||||
{
|
||||
return 5204;
|
||||
}
|
||||
|
||||
return 6683;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SampleCount == 160)
|
||||
{
|
||||
return 3427;
|
||||
}
|
||||
|
||||
return 4752;
|
||||
}
|
||||
}
|
||||
|
||||
public override uint Estimate(MultiTapBiquadFilterAndMixCommand command)
|
||||
{
|
||||
Debug.Assert(SampleCount == 160 || SampleCount == 240);
|
||||
|
||||
if (command.HasVolumeRamp)
|
||||
{
|
||||
if (SampleCount == 160)
|
||||
{
|
||||
return 7939;
|
||||
}
|
||||
|
||||
return 10669;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SampleCount == 160)
|
||||
{
|
||||
return 6256;
|
||||
}
|
||||
|
||||
return 8683;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,10 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
uint Estimate(UpsampleCommand command);
|
||||
uint Estimate(LimiterCommandVersion1 command);
|
||||
uint Estimate(LimiterCommandVersion2 command);
|
||||
uint Estimate(GroupedBiquadFilterCommand command);
|
||||
uint Estimate(MultiTapBiquadFilterCommand command);
|
||||
uint Estimate(CaptureBufferCommand command);
|
||||
uint Estimate(CompressorCommand command);
|
||||
uint Estimate(BiquadFilterAndMixCommand command);
|
||||
uint Estimate(MultiTapBiquadFilterAndMixCommand command);
|
||||
}
|
||||
}
|
||||
|
@ -225,11 +225,11 @@ namespace Ryujinx.Audio.Renderer.Server.Mix
|
||||
|
||||
for (int i = 0; i < splitter.DestinationCount; i++)
|
||||
{
|
||||
Span<SplitterDestination> destination = splitter.GetData(i);
|
||||
SplitterDestination destination = splitter.GetData(i);
|
||||
|
||||
if (!destination.IsEmpty)
|
||||
if (!destination.IsNull)
|
||||
{
|
||||
int destinationMixId = destination[0].DestinationId;
|
||||
int destinationMixId = destination.DestinationId;
|
||||
|
||||
if (destinationMixId != UnusedMixId)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Ryujinx.Audio.Renderer.Common;
|
||||
using Ryujinx.Audio.Renderer.Dsp.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Utils;
|
||||
using Ryujinx.Common;
|
||||
@ -15,15 +16,35 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
/// </summary>
|
||||
public class SplitterContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Amount of biquad filter states per splitter destination.
|
||||
/// </summary>
|
||||
public const int BqfStatesPerDestination = 4;
|
||||
|
||||
/// <summary>
|
||||
/// Storage for <see cref="SplitterState"/>.
|
||||
/// </summary>
|
||||
private Memory<SplitterState> _splitters;
|
||||
|
||||
/// <summary>
|
||||
/// Storage for <see cref="SplitterDestination"/>.
|
||||
/// Storage for <see cref="SplitterDestinationVersion1"/>.
|
||||
/// </summary>
|
||||
private Memory<SplitterDestination> _splitterDestinations;
|
||||
private Memory<SplitterDestinationVersion1> _splitterDestinationsV1;
|
||||
|
||||
/// <summary>
|
||||
/// Storage for <see cref="SplitterDestinationVersion2"/>.
|
||||
/// </summary>
|
||||
private Memory<SplitterDestinationVersion2> _splitterDestinationsV2;
|
||||
|
||||
/// <summary>
|
||||
/// Splitter biquad filtering states.
|
||||
/// </summary>
|
||||
private Memory<BiquadFilterState> _splitterBqfStates;
|
||||
|
||||
/// <summary>
|
||||
/// Version of the splitter context that is being used, currently can be 1 or 2.
|
||||
/// </summary>
|
||||
public int Version { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// If set to true, trust the user destination count in <see cref="SplitterState.Update(SplitterContext, in SplitterInParameter, ref SequenceReader{byte})"/>.
|
||||
@ -36,12 +57,17 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
/// <param name="behaviourContext">The behaviour context.</param>
|
||||
/// <param name="parameter">The audio renderer configuration.</param>
|
||||
/// <param name="workBufferAllocator">The <see cref="WorkBufferAllocator"/>.</param>
|
||||
/// <param name="splitterBqfStates">Memory to store the biquad filtering state for splitters during processing.</param>
|
||||
/// <returns>Return true if the initialization was successful.</returns>
|
||||
public bool Initialize(ref BehaviourContext behaviourContext, ref AudioRendererConfiguration parameter, WorkBufferAllocator workBufferAllocator)
|
||||
public bool Initialize(
|
||||
ref BehaviourContext behaviourContext,
|
||||
ref AudioRendererConfiguration parameter,
|
||||
WorkBufferAllocator workBufferAllocator,
|
||||
Memory<BiquadFilterState> splitterBqfStates)
|
||||
{
|
||||
if (!behaviourContext.IsSplitterSupported() || parameter.SplitterCount <= 0 || parameter.SplitterDestinationCount <= 0)
|
||||
{
|
||||
Setup(Memory<SplitterState>.Empty, Memory<SplitterDestination>.Empty, false);
|
||||
Setup(Memory<SplitterState>.Empty, Memory<SplitterDestinationVersion1>.Empty, Memory<SplitterDestinationVersion2>.Empty, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -60,23 +86,62 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
splitter = new SplitterState(splitterId++);
|
||||
}
|
||||
|
||||
Memory<SplitterDestination> splitterDestinations = workBufferAllocator.Allocate<SplitterDestination>(parameter.SplitterDestinationCount,
|
||||
SplitterDestination.Alignment);
|
||||
Memory<SplitterDestinationVersion1> splitterDestinationsV1 = Memory<SplitterDestinationVersion1>.Empty;
|
||||
Memory<SplitterDestinationVersion2> splitterDestinationsV2 = Memory<SplitterDestinationVersion2>.Empty;
|
||||
|
||||
if (splitterDestinations.IsEmpty)
|
||||
if (!behaviourContext.IsBiquadFilterParameterForSplitterEnabled())
|
||||
{
|
||||
return false;
|
||||
Version = 1;
|
||||
|
||||
splitterDestinationsV1 = workBufferAllocator.Allocate<SplitterDestinationVersion1>(parameter.SplitterDestinationCount,
|
||||
SplitterDestinationVersion1.Alignment);
|
||||
|
||||
if (splitterDestinationsV1.IsEmpty)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int splitterDestinationId = 0;
|
||||
foreach (ref SplitterDestinationVersion1 data in splitterDestinationsV1.Span)
|
||||
{
|
||||
data = new SplitterDestinationVersion1(splitterDestinationId++);
|
||||
}
|
||||
}
|
||||
|
||||
int splitterDestinationId = 0;
|
||||
foreach (ref SplitterDestination data in splitterDestinations.Span)
|
||||
else
|
||||
{
|
||||
data = new SplitterDestination(splitterDestinationId++);
|
||||
Version = 2;
|
||||
|
||||
splitterDestinationsV2 = workBufferAllocator.Allocate<SplitterDestinationVersion2>(parameter.SplitterDestinationCount,
|
||||
SplitterDestinationVersion2.Alignment);
|
||||
|
||||
if (splitterDestinationsV2.IsEmpty)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int splitterDestinationId = 0;
|
||||
foreach (ref SplitterDestinationVersion2 data in splitterDestinationsV2.Span)
|
||||
{
|
||||
data = new SplitterDestinationVersion2(splitterDestinationId++);
|
||||
}
|
||||
|
||||
if (parameter.SplitterDestinationCount > 0)
|
||||
{
|
||||
// Official code stores it in the SplitterDestinationVersion2 struct,
|
||||
// but we don't to avoid using unsafe code.
|
||||
|
||||
splitterBqfStates.Span.Clear();
|
||||
_splitterBqfStates = splitterBqfStates;
|
||||
}
|
||||
else
|
||||
{
|
||||
_splitterBqfStates = Memory<BiquadFilterState>.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
SplitterState.InitializeSplitters(splitters.Span);
|
||||
|
||||
Setup(splitters, splitterDestinations, behaviourContext.IsSplitterBugFixed());
|
||||
Setup(splitters, splitterDestinationsV1, splitterDestinationsV2, behaviourContext.IsSplitterBugFixed());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -93,7 +158,15 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
if (behaviourContext.IsSplitterSupported())
|
||||
{
|
||||
size = WorkBufferAllocator.GetTargetSize<SplitterState>(size, parameter.SplitterCount, SplitterState.Alignment);
|
||||
size = WorkBufferAllocator.GetTargetSize<SplitterDestination>(size, parameter.SplitterDestinationCount, SplitterDestination.Alignment);
|
||||
|
||||
if (behaviourContext.IsBiquadFilterParameterForSplitterEnabled())
|
||||
{
|
||||
size = WorkBufferAllocator.GetTargetSize<SplitterDestinationVersion2>(size, parameter.SplitterDestinationCount, SplitterDestinationVersion2.Alignment);
|
||||
}
|
||||
else
|
||||
{
|
||||
size = WorkBufferAllocator.GetTargetSize<SplitterDestinationVersion1>(size, parameter.SplitterDestinationCount, SplitterDestinationVersion1.Alignment);
|
||||
}
|
||||
|
||||
if (behaviourContext.IsSplitterBugFixed())
|
||||
{
|
||||
@ -110,12 +183,18 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
/// Setup the <see cref="SplitterContext"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="splitters">The <see cref="SplitterState"/> storage.</param>
|
||||
/// <param name="splitterDestinations">The <see cref="SplitterDestination"/> storage.</param>
|
||||
/// <param name="splitterDestinationsV1">The <see cref="SplitterDestinationVersion1"/> storage.</param>
|
||||
/// <param name="splitterDestinationsV2">The <see cref="SplitterDestinationVersion2"/> storage.</param>
|
||||
/// <param name="isBugFixed">If set to true, trust the user destination count in <see cref="SplitterState.Update(SplitterContext, in SplitterInParameter, ref SequenceReader{byte})"/>.</param>
|
||||
private void Setup(Memory<SplitterState> splitters, Memory<SplitterDestination> splitterDestinations, bool isBugFixed)
|
||||
private void Setup(
|
||||
Memory<SplitterState> splitters,
|
||||
Memory<SplitterDestinationVersion1> splitterDestinationsV1,
|
||||
Memory<SplitterDestinationVersion2> splitterDestinationsV2,
|
||||
bool isBugFixed)
|
||||
{
|
||||
_splitters = splitters;
|
||||
_splitterDestinations = splitterDestinations;
|
||||
_splitterDestinationsV1 = splitterDestinationsV1;
|
||||
_splitterDestinationsV2 = splitterDestinationsV2;
|
||||
IsBugFixed = isBugFixed;
|
||||
}
|
||||
|
||||
@ -141,7 +220,9 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _splitterDestinations.Length / _splitters.Length;
|
||||
int length = _splitterDestinationsV2.IsEmpty ? _splitterDestinationsV1.Length : _splitterDestinationsV2.Length;
|
||||
|
||||
return length / _splitters.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -178,7 +259,39 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update one or multiple <see cref="SplitterDestination"/> from user parameters.
|
||||
/// Update one splitter destination data from user parameters.
|
||||
/// </summary>
|
||||
/// <param name="input">The raw data after the splitter header.</param>
|
||||
/// <returns>True if the update was successful, false otherwise</returns>
|
||||
private bool UpdateData<T>(ref SequenceReader<byte> input) where T : unmanaged, ISplitterDestinationInParameter
|
||||
{
|
||||
ref readonly T parameter = ref input.GetRefOrRefToCopy<T>(out _);
|
||||
|
||||
Debug.Assert(parameter.IsMagicValid());
|
||||
|
||||
if (parameter.IsMagicValid())
|
||||
{
|
||||
int length = _splitterDestinationsV2.IsEmpty ? _splitterDestinationsV1.Length : _splitterDestinationsV2.Length;
|
||||
|
||||
if (parameter.Id >= 0 && parameter.Id < length)
|
||||
{
|
||||
SplitterDestination destination = GetDestination(parameter.Id);
|
||||
|
||||
destination.Update(parameter);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
input.Rewind(Unsafe.SizeOf<T>());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update one or multiple splitter destination data from user parameters.
|
||||
/// </summary>
|
||||
/// <param name="inputHeader">The splitter header.</param>
|
||||
/// <param name="input">The raw data after the splitter header.</param>
|
||||
@ -186,23 +299,23 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
{
|
||||
for (int i = 0; i < inputHeader.SplitterDestinationCount; i++)
|
||||
{
|
||||
ref readonly SplitterDestinationInParameter parameter = ref input.GetRefOrRefToCopy<SplitterDestinationInParameter>(out _);
|
||||
|
||||
Debug.Assert(parameter.IsMagicValid());
|
||||
|
||||
if (parameter.IsMagicValid())
|
||||
if (Version == 1)
|
||||
{
|
||||
if (parameter.Id >= 0 && parameter.Id < _splitterDestinations.Length)
|
||||
if (!UpdateData<SplitterDestinationInParameterVersion1>(ref input))
|
||||
{
|
||||
ref SplitterDestination destination = ref GetDestination(parameter.Id);
|
||||
|
||||
destination.Update(parameter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (Version == 2)
|
||||
{
|
||||
if (!UpdateData<SplitterDestinationInParameterVersion2>(ref input))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
input.Rewind(Unsafe.SizeOf<SplitterDestinationInParameter>());
|
||||
break;
|
||||
Debug.Fail($"Invalid splitter context version {Version}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -214,7 +327,7 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
/// <returns>Return true if the update was successful.</returns>
|
||||
public bool Update(ref SequenceReader<byte> input)
|
||||
{
|
||||
if (_splitterDestinations.IsEmpty || _splitters.IsEmpty)
|
||||
if (!UsingSplitter())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -251,45 +364,52 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a reference to a <see cref="SplitterDestination"/> at the given <paramref name="id"/>.
|
||||
/// Get a reference to the splitter destination data at the given <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The index to use.</param>
|
||||
/// <returns>A reference to a <see cref="SplitterDestination"/> at the given <paramref name="id"/>.</returns>
|
||||
public ref SplitterDestination GetDestination(int id)
|
||||
/// <returns>A reference to the splitter destination data at the given <paramref name="id"/>.</returns>
|
||||
public SplitterDestination GetDestination(int id)
|
||||
{
|
||||
return ref SpanIOHelper.GetFromMemory(_splitterDestinations, id, (uint)_splitterDestinations.Length);
|
||||
if (_splitterDestinationsV2.IsEmpty)
|
||||
{
|
||||
return new SplitterDestination(ref SpanIOHelper.GetFromMemory(_splitterDestinationsV1, id, (uint)_splitterDestinationsV1.Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new SplitterDestination(ref SpanIOHelper.GetFromMemory(_splitterDestinationsV2, id, (uint)_splitterDestinationsV2.Length));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a <see cref="Memory{SplitterDestination}"/> at the given <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The index to use.</param>
|
||||
/// <returns>A <see cref="Memory{SplitterDestination}"/> at the given <paramref name="id"/>.</returns>
|
||||
public Memory<SplitterDestination> GetDestinationMemory(int id)
|
||||
{
|
||||
return SpanIOHelper.GetMemory(_splitterDestinations, id, (uint)_splitterDestinations.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a <see cref="Span{SplitterDestination}"/> in the <see cref="SplitterState"/> at <paramref name="id"/> and pass <paramref name="destinationId"/> to <see cref="SplitterState.GetData(int)"/>.
|
||||
/// Get a <see cref="SplitterDestination"/> in the <see cref="SplitterState"/> at <paramref name="id"/> and pass <paramref name="destinationId"/> to <see cref="SplitterState.GetData(int)"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The index to use to get the <see cref="SplitterState"/>.</param>
|
||||
/// <param name="destinationId">The index of the <see cref="SplitterDestination"/>.</param>
|
||||
/// <returns>A <see cref="Span{SplitterDestination}"/>.</returns>
|
||||
public Span<SplitterDestination> GetDestination(int id, int destinationId)
|
||||
/// <returns>A <see cref="SplitterDestination"/>.</returns>
|
||||
public SplitterDestination GetDestination(int id, int destinationId)
|
||||
{
|
||||
ref SplitterState splitter = ref GetState(id);
|
||||
|
||||
return splitter.GetData(destinationId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the biquad filter state for a given splitter destination.
|
||||
/// </summary>
|
||||
/// <param name="destination">The splitter destination.</param>
|
||||
/// <returns>Biquad filter state for the specified destination.</returns>
|
||||
public Memory<BiquadFilterState> GetBiquadFilterState(SplitterDestination destination)
|
||||
{
|
||||
return _splitterBqfStates.Slice(destination.Id * BqfStatesPerDestination, BqfStatesPerDestination);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return true if the audio renderer has any splitters.
|
||||
/// </summary>
|
||||
/// <returns>True if the audio renderer has any splitters.</returns>
|
||||
public bool UsingSplitter()
|
||||
{
|
||||
return !_splitters.IsEmpty && !_splitterDestinations.IsEmpty;
|
||||
return !_splitters.IsEmpty && (!_splitterDestinationsV1.IsEmpty || !_splitterDestinationsV2.IsEmpty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,115 +1,198 @@
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
{
|
||||
/// <summary>
|
||||
/// Server state for a splitter destination.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0xE0, Pack = Alignment)]
|
||||
public struct SplitterDestination
|
||||
public ref struct SplitterDestination
|
||||
{
|
||||
public const int Alignment = 0x10;
|
||||
private ref SplitterDestinationVersion1 _v1;
|
||||
private ref SplitterDestinationVersion2 _v2;
|
||||
|
||||
/// <summary>
|
||||
/// The unique id of this <see cref="SplitterDestination"/>.
|
||||
/// Checks if the splitter destination data reference is null.
|
||||
/// </summary>
|
||||
public int Id;
|
||||
public bool IsNull => Unsafe.IsNullRef(ref _v1) && Unsafe.IsNullRef(ref _v2);
|
||||
|
||||
/// <summary>
|
||||
/// The mix to output the result of the splitter.
|
||||
/// The splitter unique id.
|
||||
/// </summary>
|
||||
public int DestinationId;
|
||||
|
||||
/// <summary>
|
||||
/// Mix buffer volumes storage.
|
||||
/// </summary>
|
||||
private MixArray _mix;
|
||||
private MixArray _previousMix;
|
||||
|
||||
/// <summary>
|
||||
/// Pointer to the next linked element.
|
||||
/// </summary>
|
||||
private unsafe SplitterDestination* _next;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if in use.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsUsed;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if the internal state need to be updated.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool NeedToUpdateInternalState;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Size = 4 * Constants.MixBufferCountMax, Pack = 1)]
|
||||
private struct MixArray { }
|
||||
|
||||
/// <summary>
|
||||
/// Mix buffer volumes.
|
||||
/// </summary>
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
public Span<float> MixBufferVolume => SpanHelpers.AsSpan<MixArray, float>(ref _mix);
|
||||
|
||||
/// <summary>
|
||||
/// Previous mix buffer volumes.
|
||||
/// </summary>
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
public Span<float> PreviousMixBufferVolume => SpanHelpers.AsSpan<MixArray, float>(ref _previousMix);
|
||||
|
||||
/// <summary>
|
||||
/// Get the <see cref="Span{SplitterDestination}"/> of the next element or <see cref="Span{SplitterDestination}.Empty"/> if not present.
|
||||
/// </summary>
|
||||
public readonly Span<SplitterDestination> Next
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
unsafe
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
return _next != null ? new Span<SplitterDestination>(_next, 1) : Span<SplitterDestination>.Empty;
|
||||
if (Unsafe.IsNullRef(ref _v1))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _v1.Id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return _v2.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="SplitterDestination"/>.
|
||||
/// The mix to output the result of the splitter.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique id of this <see cref="SplitterDestination"/>.</param>
|
||||
public SplitterDestination(int id) : this()
|
||||
public int DestinationId
|
||||
{
|
||||
Id = id;
|
||||
DestinationId = Constants.UnusedMixId;
|
||||
|
||||
ClearVolumes();
|
||||
get
|
||||
{
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
if (Unsafe.IsNullRef(ref _v1))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _v1.DestinationId;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return _v2.DestinationId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the <see cref="SplitterDestination"/> from user parameter.
|
||||
/// Mix buffer volumes.
|
||||
/// </summary>
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
public Span<float> MixBufferVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
if (Unsafe.IsNullRef(ref _v1))
|
||||
{
|
||||
return Span<float>.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _v1.MixBufferVolume;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return _v2.MixBufferVolume;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Previous mix buffer volumes.
|
||||
/// </summary>
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
public Span<float> PreviousMixBufferVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
if (Unsafe.IsNullRef(ref _v1))
|
||||
{
|
||||
return Span<float>.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _v1.PreviousMixBufferVolume;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return _v2.PreviousMixBufferVolume;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the <see cref="SplitterDestination"/> of the next element or null if not present.
|
||||
/// </summary>
|
||||
public readonly SplitterDestination Next
|
||||
{
|
||||
get
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
if (Unsafe.IsNullRef(ref _v1))
|
||||
{
|
||||
return new SplitterDestination();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new SplitterDestination(ref _v1.Next);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new SplitterDestination(ref _v2.Next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new splitter destination wrapper for the version 1 splitter destination data.
|
||||
/// </summary>
|
||||
/// <param name="v1">Version 1 splitter destination data</param>
|
||||
public SplitterDestination(ref SplitterDestinationVersion1 v1)
|
||||
{
|
||||
_v1 = ref v1;
|
||||
_v2 = ref Unsafe.NullRef<SplitterDestinationVersion2>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new splitter destination wrapper for the version 2 splitter destination data.
|
||||
/// </summary>
|
||||
/// <param name="v2">Version 2 splitter destination data</param>
|
||||
public SplitterDestination(ref SplitterDestinationVersion2 v2)
|
||||
{
|
||||
|
||||
_v1 = ref Unsafe.NullRef<SplitterDestinationVersion1>();
|
||||
_v2 = ref v2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new splitter destination wrapper for the splitter destination data.
|
||||
/// </summary>
|
||||
/// <param name="v1">Version 1 splitter destination data</param>
|
||||
/// <param name="v2">Version 2 splitter destination data</param>
|
||||
public unsafe SplitterDestination(SplitterDestinationVersion1* v1, SplitterDestinationVersion2* v2)
|
||||
{
|
||||
_v1 = ref Unsafe.AsRef<SplitterDestinationVersion1>(v1);
|
||||
_v2 = ref Unsafe.AsRef<SplitterDestinationVersion2>(v2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the splitter destination data from user parameter.
|
||||
/// </summary>
|
||||
/// <param name="parameter">The user parameter.</param>
|
||||
public void Update(SplitterDestinationInParameter parameter)
|
||||
public void Update<T>(in T parameter) where T : ISplitterDestinationInParameter
|
||||
{
|
||||
Debug.Assert(Id == parameter.Id);
|
||||
|
||||
if (parameter.IsMagicValid() && Id == parameter.Id)
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
DestinationId = parameter.DestinationId;
|
||||
|
||||
parameter.MixBufferVolume.CopyTo(MixBufferVolume);
|
||||
|
||||
if (!IsUsed && parameter.IsUsed)
|
||||
{
|
||||
MixBufferVolume.CopyTo(PreviousMixBufferVolume);
|
||||
|
||||
NeedToUpdateInternalState = false;
|
||||
}
|
||||
|
||||
IsUsed = parameter.IsUsed;
|
||||
_v1.Update(parameter);
|
||||
}
|
||||
else
|
||||
{
|
||||
_v2.Update(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,12 +201,14 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
/// </summary>
|
||||
public void UpdateInternalState()
|
||||
{
|
||||
if (IsUsed && NeedToUpdateInternalState)
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
MixBufferVolume.CopyTo(PreviousMixBufferVolume);
|
||||
_v1.UpdateInternalState();
|
||||
}
|
||||
else
|
||||
{
|
||||
_v2.UpdateInternalState();
|
||||
}
|
||||
|
||||
NeedToUpdateInternalState = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -131,16 +216,23 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
/// </summary>
|
||||
public void MarkAsNeedToUpdateInternalState()
|
||||
{
|
||||
NeedToUpdateInternalState = true;
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
_v1.MarkAsNeedToUpdateInternalState();
|
||||
}
|
||||
else
|
||||
{
|
||||
_v2.MarkAsNeedToUpdateInternalState();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return true if the <see cref="SplitterDestination"/> is used and has a destination.
|
||||
/// Return true if the splitter destination is used and has a destination.
|
||||
/// </summary>
|
||||
/// <returns>True if the <see cref="SplitterDestination"/> is used and has a destination.</returns>
|
||||
/// <returns>True if the splitter destination is used and has a destination.</returns>
|
||||
public readonly bool IsConfigured()
|
||||
{
|
||||
return IsUsed && DestinationId != Constants.UnusedMixId;
|
||||
return Unsafe.IsNullRef(ref _v2) ? _v1.IsConfigured() : _v2.IsConfigured();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -150,9 +242,17 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
/// <returns>The volume for the given destination.</returns>
|
||||
public float GetMixVolume(int destinationIndex)
|
||||
{
|
||||
Debug.Assert(destinationIndex >= 0 && destinationIndex < Constants.MixBufferCountMax);
|
||||
return Unsafe.IsNullRef(ref _v2) ? _v1.GetMixVolume(destinationIndex) : _v2.GetMixVolume(destinationIndex);
|
||||
}
|
||||
|
||||
return MixBufferVolume[destinationIndex];
|
||||
/// <summary>
|
||||
/// Get the previous volume for a given destination.
|
||||
/// </summary>
|
||||
/// <param name="destinationIndex">The destination index to use.</param>
|
||||
/// <returns>The volume for the given destination.</returns>
|
||||
public float GetMixVolumePrev(int destinationIndex)
|
||||
{
|
||||
return Unsafe.IsNullRef(ref _v2) ? _v1.GetMixVolumePrev(destinationIndex) : _v2.GetMixVolumePrev(destinationIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -160,22 +260,33 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
/// </summary>
|
||||
public void ClearVolumes()
|
||||
{
|
||||
MixBufferVolume.Clear();
|
||||
PreviousMixBufferVolume.Clear();
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
_v1.ClearVolumes();
|
||||
}
|
||||
else
|
||||
{
|
||||
_v2.ClearVolumes();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the next element to the given <see cref="SplitterDestination"/>.
|
||||
/// Link the next element to the given splitter destination.
|
||||
/// </summary>
|
||||
/// <param name="next">The given <see cref="SplitterDestination"/> to link.</param>
|
||||
public void Link(ref SplitterDestination next)
|
||||
/// <param name="next">The given splitter destination to link.</param>
|
||||
public void Link(SplitterDestination next)
|
||||
{
|
||||
unsafe
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
fixed (SplitterDestination* nextPtr = &next)
|
||||
{
|
||||
_next = nextPtr;
|
||||
}
|
||||
Debug.Assert(!Unsafe.IsNullRef(ref next._v1));
|
||||
|
||||
_v1.Link(ref next._v1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Assert(!Unsafe.IsNullRef(ref next._v2));
|
||||
|
||||
_v2.Link(ref next._v2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,10 +295,74 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
/// </summary>
|
||||
public void Unlink()
|
||||
{
|
||||
unsafe
|
||||
if (Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
_next = null;
|
||||
_v1.Unlink();
|
||||
}
|
||||
else
|
||||
{
|
||||
_v2.Unlink();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if any biquad filter is enabled.
|
||||
/// </summary>
|
||||
/// <returns>True if any biquad filter is enabled.</returns>
|
||||
public bool IsBiquadFilterEnabled()
|
||||
{
|
||||
return !Unsafe.IsNullRef(ref _v2) && _v2.IsBiquadFilterEnabled();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if any biquad filter was previously enabled.
|
||||
/// </summary>
|
||||
/// <returns>True if any biquad filter was previously enabled.</returns>
|
||||
public bool IsBiquadFilterEnabledPrev()
|
||||
{
|
||||
return !Unsafe.IsNullRef(ref _v2) && _v2.IsBiquadFilterEnabledPrev();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the biquad filter parameters.
|
||||
/// </summary>
|
||||
/// <param name="index">Biquad filter index (0 or 1).</param>
|
||||
/// <returns>Biquad filter parameters.</returns>
|
||||
public ref BiquadFilterParameter GetBiquadFilterParameter(int index)
|
||||
{
|
||||
Debug.Assert(!Unsafe.IsNullRef(ref _v2));
|
||||
|
||||
return ref _v2.GetBiquadFilterParameter(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if any biquad filter was previously enabled.
|
||||
/// </summary>
|
||||
/// <param name="index">Biquad filter index (0 or 1).</param>
|
||||
public void UpdateBiquadFilterEnabledPrev(int index)
|
||||
{
|
||||
if (!Unsafe.IsNullRef(ref _v2))
|
||||
{
|
||||
_v2.UpdateBiquadFilterEnabledPrev(index);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the reference for the version 1 splitter destination data, or null if version 2 is being used or the destination is null.
|
||||
/// </summary>
|
||||
/// <returns>Reference for the version 1 splitter destination data.</returns>
|
||||
public ref SplitterDestinationVersion1 GetV1RefOrNull()
|
||||
{
|
||||
return ref _v1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the reference for the version 2 splitter destination data, or null if version 1 is being used or the destination is null.
|
||||
/// </summary>
|
||||
/// <returns>Reference for the version 2 splitter destination data.</returns>
|
||||
public ref SplitterDestinationVersion2 GetV2RefOrNull()
|
||||
{
|
||||
return ref _v2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,206 @@
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
{
|
||||
/// <summary>
|
||||
/// Server state for a splitter destination (version 1).
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0xE0, Pack = Alignment)]
|
||||
public struct SplitterDestinationVersion1
|
||||
{
|
||||
public const int Alignment = 0x10;
|
||||
|
||||
/// <summary>
|
||||
/// The unique id of this <see cref="SplitterDestinationVersion1"/>.
|
||||
/// </summary>
|
||||
public int Id;
|
||||
|
||||
/// <summary>
|
||||
/// The mix to output the result of the splitter.
|
||||
/// </summary>
|
||||
public int DestinationId;
|
||||
|
||||
/// <summary>
|
||||
/// Mix buffer volumes storage.
|
||||
/// </summary>
|
||||
private MixArray _mix;
|
||||
private MixArray _previousMix;
|
||||
|
||||
/// <summary>
|
||||
/// Pointer to the next linked element.
|
||||
/// </summary>
|
||||
private unsafe SplitterDestinationVersion1* _next;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if in use.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsUsed;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if the internal state need to be updated.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool NeedToUpdateInternalState;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Size = sizeof(float) * Constants.MixBufferCountMax, Pack = 1)]
|
||||
private struct MixArray { }
|
||||
|
||||
/// <summary>
|
||||
/// Mix buffer volumes.
|
||||
/// </summary>
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
public Span<float> MixBufferVolume => SpanHelpers.AsSpan<MixArray, float>(ref _mix);
|
||||
|
||||
/// <summary>
|
||||
/// Previous mix buffer volumes.
|
||||
/// </summary>
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
public Span<float> PreviousMixBufferVolume => SpanHelpers.AsSpan<MixArray, float>(ref _previousMix);
|
||||
|
||||
/// <summary>
|
||||
/// Get the reference of the next element or null if not present.
|
||||
/// </summary>
|
||||
public readonly ref SplitterDestinationVersion1 Next
|
||||
{
|
||||
get
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return ref Unsafe.AsRef<SplitterDestinationVersion1>(_next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="SplitterDestinationVersion1"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique id of this <see cref="SplitterDestinationVersion1"/>.</param>
|
||||
public SplitterDestinationVersion1(int id) : this()
|
||||
{
|
||||
Id = id;
|
||||
DestinationId = Constants.UnusedMixId;
|
||||
|
||||
ClearVolumes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the <see cref="SplitterDestinationVersion1"/> from user parameter.
|
||||
/// </summary>
|
||||
/// <param name="parameter">The user parameter.</param>
|
||||
public void Update<T>(in T parameter) where T : ISplitterDestinationInParameter
|
||||
{
|
||||
Debug.Assert(Id == parameter.Id);
|
||||
|
||||
if (parameter.IsMagicValid() && Id == parameter.Id)
|
||||
{
|
||||
DestinationId = parameter.DestinationId;
|
||||
|
||||
parameter.MixBufferVolume.CopyTo(MixBufferVolume);
|
||||
|
||||
if (!IsUsed && parameter.IsUsed)
|
||||
{
|
||||
MixBufferVolume.CopyTo(PreviousMixBufferVolume);
|
||||
|
||||
NeedToUpdateInternalState = false;
|
||||
}
|
||||
|
||||
IsUsed = parameter.IsUsed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the internal state of the instance.
|
||||
/// </summary>
|
||||
public void UpdateInternalState()
|
||||
{
|
||||
if (IsUsed && NeedToUpdateInternalState)
|
||||
{
|
||||
MixBufferVolume.CopyTo(PreviousMixBufferVolume);
|
||||
}
|
||||
|
||||
NeedToUpdateInternalState = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the update internal state marker.
|
||||
/// </summary>
|
||||
public void MarkAsNeedToUpdateInternalState()
|
||||
{
|
||||
NeedToUpdateInternalState = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return true if the <see cref="SplitterDestinationVersion1"/> is used and has a destination.
|
||||
/// </summary>
|
||||
/// <returns>True if the <see cref="SplitterDestinationVersion1"/> is used and has a destination.</returns>
|
||||
public readonly bool IsConfigured()
|
||||
{
|
||||
return IsUsed && DestinationId != Constants.UnusedMixId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the volume for a given destination.
|
||||
/// </summary>
|
||||
/// <param name="destinationIndex">The destination index to use.</param>
|
||||
/// <returns>The volume for the given destination.</returns>
|
||||
public float GetMixVolume(int destinationIndex)
|
||||
{
|
||||
Debug.Assert(destinationIndex >= 0 && destinationIndex < Constants.MixBufferCountMax);
|
||||
|
||||
return MixBufferVolume[destinationIndex];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the previous volume for a given destination.
|
||||
/// </summary>
|
||||
/// <param name="destinationIndex">The destination index to use.</param>
|
||||
/// <returns>The volume for the given destination.</returns>
|
||||
public float GetMixVolumePrev(int destinationIndex)
|
||||
{
|
||||
Debug.Assert(destinationIndex >= 0 && destinationIndex < Constants.MixBufferCountMax);
|
||||
|
||||
return PreviousMixBufferVolume[destinationIndex];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear the volumes.
|
||||
/// </summary>
|
||||
public void ClearVolumes()
|
||||
{
|
||||
MixBufferVolume.Clear();
|
||||
PreviousMixBufferVolume.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the next element to the given <see cref="SplitterDestinationVersion1"/>.
|
||||
/// </summary>
|
||||
/// <param name="next">The given <see cref="SplitterDestinationVersion1"/> to link.</param>
|
||||
public void Link(ref SplitterDestinationVersion1 next)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (SplitterDestinationVersion1* nextPtr = &next)
|
||||
{
|
||||
_next = nextPtr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the link to the next element.
|
||||
/// </summary>
|
||||
public void Unlink()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
_next = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,250 @@
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
{
|
||||
/// <summary>
|
||||
/// Server state for a splitter destination (version 2).
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x110, Pack = Alignment)]
|
||||
public struct SplitterDestinationVersion2
|
||||
{
|
||||
public const int Alignment = 0x10;
|
||||
|
||||
/// <summary>
|
||||
/// The unique id of this <see cref="SplitterDestinationVersion2"/>.
|
||||
/// </summary>
|
||||
public int Id;
|
||||
|
||||
/// <summary>
|
||||
/// The mix to output the result of the splitter.
|
||||
/// </summary>
|
||||
public int DestinationId;
|
||||
|
||||
/// <summary>
|
||||
/// Mix buffer volumes storage.
|
||||
/// </summary>
|
||||
private MixArray _mix;
|
||||
private MixArray _previousMix;
|
||||
|
||||
/// <summary>
|
||||
/// Pointer to the next linked element.
|
||||
/// </summary>
|
||||
private unsafe SplitterDestinationVersion2* _next;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if in use.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool IsUsed;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if the internal state need to be updated.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
public bool NeedToUpdateInternalState;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Size = sizeof(float) * Constants.MixBufferCountMax, Pack = 1)]
|
||||
private struct MixArray { }
|
||||
|
||||
/// <summary>
|
||||
/// Mix buffer volumes.
|
||||
/// </summary>
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
public Span<float> MixBufferVolume => SpanHelpers.AsSpan<MixArray, float>(ref _mix);
|
||||
|
||||
/// <summary>
|
||||
/// Previous mix buffer volumes.
|
||||
/// </summary>
|
||||
/// <remarks>Used when a splitter id is specified in the mix.</remarks>
|
||||
public Span<float> PreviousMixBufferVolume => SpanHelpers.AsSpan<MixArray, float>(ref _previousMix);
|
||||
|
||||
/// <summary>
|
||||
/// Get the reference of the next element or null if not present.
|
||||
/// </summary>
|
||||
public readonly ref SplitterDestinationVersion2 Next
|
||||
{
|
||||
get
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return ref Unsafe.AsRef<SplitterDestinationVersion2>(_next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Array2<BiquadFilterParameter> _biquadFilters;
|
||||
|
||||
private Array2<bool> _isPreviousBiquadFilterEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="SplitterDestinationVersion2"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique id of this <see cref="SplitterDestinationVersion2"/>.</param>
|
||||
public SplitterDestinationVersion2(int id) : this()
|
||||
{
|
||||
Id = id;
|
||||
DestinationId = Constants.UnusedMixId;
|
||||
|
||||
ClearVolumes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the <see cref="SplitterDestinationVersion2"/> from user parameter.
|
||||
/// </summary>
|
||||
/// <param name="parameter">The user parameter.</param>
|
||||
public void Update<T>(in T parameter) where T : ISplitterDestinationInParameter
|
||||
{
|
||||
Debug.Assert(Id == parameter.Id);
|
||||
|
||||
if (parameter.IsMagicValid() && Id == parameter.Id)
|
||||
{
|
||||
DestinationId = parameter.DestinationId;
|
||||
|
||||
parameter.MixBufferVolume.CopyTo(MixBufferVolume);
|
||||
|
||||
_biquadFilters = parameter.BiquadFilters;
|
||||
|
||||
if (!IsUsed && parameter.IsUsed)
|
||||
{
|
||||
MixBufferVolume.CopyTo(PreviousMixBufferVolume);
|
||||
|
||||
NeedToUpdateInternalState = false;
|
||||
}
|
||||
|
||||
IsUsed = parameter.IsUsed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the internal state of the instance.
|
||||
/// </summary>
|
||||
public void UpdateInternalState()
|
||||
{
|
||||
if (IsUsed && NeedToUpdateInternalState)
|
||||
{
|
||||
MixBufferVolume.CopyTo(PreviousMixBufferVolume);
|
||||
}
|
||||
|
||||
NeedToUpdateInternalState = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the update internal state marker.
|
||||
/// </summary>
|
||||
public void MarkAsNeedToUpdateInternalState()
|
||||
{
|
||||
NeedToUpdateInternalState = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return true if the <see cref="SplitterDestinationVersion2"/> is used and has a destination.
|
||||
/// </summary>
|
||||
/// <returns>True if the <see cref="SplitterDestinationVersion2"/> is used and has a destination.</returns>
|
||||
public readonly bool IsConfigured()
|
||||
{
|
||||
return IsUsed && DestinationId != Constants.UnusedMixId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the volume for a given destination.
|
||||
/// </summary>
|
||||
/// <param name="destinationIndex">The destination index to use.</param>
|
||||
/// <returns>The volume for the given destination.</returns>
|
||||
public float GetMixVolume(int destinationIndex)
|
||||
{
|
||||
Debug.Assert(destinationIndex >= 0 && destinationIndex < Constants.MixBufferCountMax);
|
||||
|
||||
return MixBufferVolume[destinationIndex];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the previous volume for a given destination.
|
||||
/// </summary>
|
||||
/// <param name="destinationIndex">The destination index to use.</param>
|
||||
/// <returns>The volume for the given destination.</returns>
|
||||
public float GetMixVolumePrev(int destinationIndex)
|
||||
{
|
||||
Debug.Assert(destinationIndex >= 0 && destinationIndex < Constants.MixBufferCountMax);
|
||||
|
||||
return PreviousMixBufferVolume[destinationIndex];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear the volumes.
|
||||
/// </summary>
|
||||
public void ClearVolumes()
|
||||
{
|
||||
MixBufferVolume.Clear();
|
||||
PreviousMixBufferVolume.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the next element to the given <see cref="SplitterDestinationVersion2"/>.
|
||||
/// </summary>
|
||||
/// <param name="next">The given <see cref="SplitterDestinationVersion2"/> to link.</param>
|
||||
public void Link(ref SplitterDestinationVersion2 next)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (SplitterDestinationVersion2* nextPtr = &next)
|
||||
{
|
||||
_next = nextPtr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the link to the next element.
|
||||
/// </summary>
|
||||
public void Unlink()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
_next = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if any biquad filter is enabled.
|
||||
/// </summary>
|
||||
/// <returns>True if any biquad filter is enabled.</returns>
|
||||
public bool IsBiquadFilterEnabled()
|
||||
{
|
||||
return _biquadFilters[0].Enable || _biquadFilters[1].Enable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if any biquad filter was previously enabled.
|
||||
/// </summary>
|
||||
/// <returns>True if any biquad filter was previously enabled.</returns>
|
||||
public bool IsBiquadFilterEnabledPrev()
|
||||
{
|
||||
return _isPreviousBiquadFilterEnabled[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the biquad filter parameters.
|
||||
/// </summary>
|
||||
/// <param name="index">Biquad filter index (0 or 1).</param>
|
||||
/// <returns>Biquad filter parameters.</returns>
|
||||
public ref BiquadFilterParameter GetBiquadFilterParameter(int index)
|
||||
{
|
||||
return ref _biquadFilters[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if any biquad filter was previously enabled.
|
||||
/// </summary>
|
||||
/// <param name="index">Biquad filter index (0 or 1).</param>
|
||||
public void UpdateBiquadFilterEnabledPrev(int index)
|
||||
{
|
||||
_isPreviousBiquadFilterEnabled[index] = _biquadFilters[index].Enable;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
{
|
||||
public const int Alignment = 0x10;
|
||||
|
||||
private delegate void SplitterDestinationAction(SplitterDestination destination, int index);
|
||||
|
||||
/// <summary>
|
||||
/// The unique id of this <see cref="SplitterState"/>.
|
||||
/// </summary>
|
||||
@ -26,7 +28,7 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
public uint SampleRate;
|
||||
|
||||
/// <summary>
|
||||
/// Count of splitter destinations (<see cref="SplitterDestination"/>).
|
||||
/// Count of splitter destinations.
|
||||
/// </summary>
|
||||
public int DestinationCount;
|
||||
|
||||
@ -37,20 +39,25 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
public bool HasNewConnection;
|
||||
|
||||
/// <summary>
|
||||
/// Linked list of <see cref="SplitterDestination"/>.
|
||||
/// Linked list of <see cref="SplitterDestinationVersion1"/>.
|
||||
/// </summary>
|
||||
private unsafe SplitterDestination* _destinationsData;
|
||||
private unsafe SplitterDestinationVersion1* _destinationDataV1;
|
||||
|
||||
/// <summary>
|
||||
/// Span to the first element of the linked list of <see cref="SplitterDestination"/>.
|
||||
/// Linked list of <see cref="SplitterDestinationVersion2"/>.
|
||||
/// </summary>
|
||||
public readonly Span<SplitterDestination> Destinations
|
||||
private unsafe SplitterDestinationVersion2* _destinationDataV2;
|
||||
|
||||
/// <summary>
|
||||
/// First element of the linked list of splitter destinations data.
|
||||
/// </summary>
|
||||
public readonly SplitterDestination Destination
|
||||
{
|
||||
get
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return (IntPtr)_destinationsData != IntPtr.Zero ? new Span<SplitterDestination>(_destinationsData, 1) : Span<SplitterDestination>.Empty;
|
||||
return new SplitterDestination(_destinationDataV1, _destinationDataV2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -64,20 +71,20 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public readonly Span<SplitterDestination> GetData(int index)
|
||||
public readonly SplitterDestination GetData(int index)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
Span<SplitterDestination> result = Destinations;
|
||||
SplitterDestination result = Destination;
|
||||
|
||||
while (i < index)
|
||||
{
|
||||
if (result.IsEmpty)
|
||||
if (result.IsNull)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
result = result[0].Next;
|
||||
result = result.Next;
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -93,25 +100,25 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Utility function to apply a given <see cref="SpanAction{T, TArg}"/> to all <see cref="Destinations"/>.
|
||||
/// Utility function to apply an action to all <see cref="Destination"/>.
|
||||
/// </summary>
|
||||
/// <param name="action">The action to execute on each elements.</param>
|
||||
private readonly void ForEachDestination(SpanAction<SplitterDestination, int> action)
|
||||
private readonly void ForEachDestination(SplitterDestinationAction action)
|
||||
{
|
||||
Span<SplitterDestination> temp = Destinations;
|
||||
SplitterDestination temp = Destination;
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (temp.IsEmpty)
|
||||
if (temp.IsNull)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Span<SplitterDestination> next = temp[0].Next;
|
||||
SplitterDestination next = temp.Next;
|
||||
|
||||
action.Invoke(temp, i++);
|
||||
action(temp, i++);
|
||||
|
||||
temp = next;
|
||||
}
|
||||
@ -142,9 +149,9 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
{
|
||||
input.ReadLittleEndian(out int destinationId);
|
||||
|
||||
Memory<SplitterDestination> destination = context.GetDestinationMemory(destinationId);
|
||||
SplitterDestination destination = context.GetDestination(destinationId);
|
||||
|
||||
SetDestination(ref destination.Span[0]);
|
||||
SetDestination(destination);
|
||||
|
||||
DestinationCount = destinationCount;
|
||||
|
||||
@ -152,9 +159,9 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
{
|
||||
input.ReadLittleEndian(out destinationId);
|
||||
|
||||
Memory<SplitterDestination> nextDestination = context.GetDestinationMemory(destinationId);
|
||||
SplitterDestination nextDestination = context.GetDestination(destinationId);
|
||||
|
||||
destination.Span[0].Link(ref nextDestination.Span[0]);
|
||||
destination.Link(nextDestination);
|
||||
destination = nextDestination;
|
||||
}
|
||||
}
|
||||
@ -174,16 +181,21 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the head of the linked list of <see cref="Destinations"/>.
|
||||
/// Set the head of the linked list of <see cref="Destination"/>.
|
||||
/// </summary>
|
||||
/// <param name="newValue">A reference to a <see cref="SplitterDestination"/>.</param>
|
||||
public void SetDestination(ref SplitterDestination newValue)
|
||||
/// <param name="newValue">New destination value.</param>
|
||||
public void SetDestination(SplitterDestination newValue)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (SplitterDestination* newValuePtr = &newValue)
|
||||
fixed (SplitterDestinationVersion1* newValuePtr = &newValue.GetV1RefOrNull())
|
||||
{
|
||||
_destinationsData = newValuePtr;
|
||||
_destinationDataV1 = newValuePtr;
|
||||
}
|
||||
|
||||
fixed (SplitterDestinationVersion2* newValuePtr = &newValue.GetV2RefOrNull())
|
||||
{
|
||||
_destinationDataV2 = newValuePtr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -193,19 +205,20 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
/// </summary>
|
||||
public readonly void UpdateInternalState()
|
||||
{
|
||||
ForEachDestination((destination, _) => destination[0].UpdateInternalState());
|
||||
ForEachDestination((destination, _) => destination.UpdateInternalState());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear all links from the <see cref="Destinations"/>.
|
||||
/// Clear all links from the <see cref="Destination"/>.
|
||||
/// </summary>
|
||||
public void ClearLinks()
|
||||
{
|
||||
ForEachDestination((destination, _) => destination[0].Unlink());
|
||||
ForEachDestination((destination, _) => destination.Unlink());
|
||||
|
||||
unsafe
|
||||
{
|
||||
_destinationsData = (SplitterDestination*)IntPtr.Zero;
|
||||
_destinationDataV1 = null;
|
||||
_destinationDataV2 = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,7 +232,8 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
splitter._destinationsData = (SplitterDestination*)IntPtr.Zero;
|
||||
splitter._destinationDataV1 = null;
|
||||
splitter._destinationDataV2 = null;
|
||||
}
|
||||
|
||||
splitter.DestinationCount = 0;
|
||||
|
@ -44,7 +44,7 @@ namespace Ryujinx.Common.Extensions
|
||||
/// <remarks>
|
||||
/// DO NOT use <paramref name="copyDestinationIfRequiredDoNotUse"/> after calling this method, as it will only
|
||||
/// contain a value if the value couldn't be referenced directly because it spans multiple <see cref="ReadOnlyMemory{Byte}"/> segments.
|
||||
/// To discourage use, it is recommended to to call this method like the following:
|
||||
/// To discourage use, it is recommended to call this method like the following:
|
||||
/// <c>
|
||||
/// ref readonly MyStruct value = ref sequenceReader.GetRefOrRefToCopy{MyStruct}(out _);
|
||||
/// </c>
|
||||
|
@ -85,6 +85,70 @@ namespace Ryujinx.Cpu.Jit
|
||||
_addressSpace = new(Tracking, backingMemory, _nativePageTable, useProtectionMirrors);
|
||||
}
|
||||
|
||||
public override ReadOnlySequence<byte> GetReadOnlySequence(ulong va, int size, bool tracked = false)
|
||||
{
|
||||
if (size == 0)
|
||||
{
|
||||
return ReadOnlySequence<byte>.Empty;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (tracked)
|
||||
{
|
||||
SignalMemoryTracking(va, (ulong)size, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
AssertValidAddressAndSize(va, (ulong)size);
|
||||
}
|
||||
|
||||
ulong endVa = va + (ulong)size;
|
||||
int offset = 0;
|
||||
|
||||
BytesReadOnlySequenceSegment first = null, last = null;
|
||||
|
||||
while (va < endVa)
|
||||
{
|
||||
(MemoryBlock memory, ulong rangeOffset, ulong copySize) = GetMemoryOffsetAndSize(va, (ulong)(size - offset));
|
||||
|
||||
Memory<byte> physicalMemory = memory.GetMemory(rangeOffset, (int)copySize);
|
||||
|
||||
if (first is null)
|
||||
{
|
||||
first = last = new BytesReadOnlySequenceSegment(physicalMemory);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (last.IsContiguousWith(physicalMemory, out nuint contiguousStart, out int contiguousSize))
|
||||
{
|
||||
Memory<byte> contiguousPhysicalMemory = new NativeMemoryManager<byte>(contiguousStart, contiguousSize).Memory;
|
||||
|
||||
last.Replace(contiguousPhysicalMemory);
|
||||
}
|
||||
else
|
||||
{
|
||||
last = last.Append(physicalMemory);
|
||||
}
|
||||
}
|
||||
|
||||
va += copySize;
|
||||
offset += (int)copySize;
|
||||
}
|
||||
|
||||
return new ReadOnlySequence<byte>(first, 0, last, (int)(size - last.RunningIndex));
|
||||
}
|
||||
catch (InvalidMemoryRegionException)
|
||||
{
|
||||
if (_invalidAccessHandler == null || !_invalidAccessHandler(va))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
return ReadOnlySequence<byte>.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Map(ulong va, ulong pa, ulong size, MemoryMapFlags flags)
|
||||
{
|
||||
|
@ -36,6 +36,8 @@ namespace Ryujinx.Graphics.GAL
|
||||
public readonly bool SupportsMismatchingViewFormat;
|
||||
public readonly bool SupportsCubemapView;
|
||||
public readonly bool SupportsNonConstantTextureOffset;
|
||||
public readonly bool SupportsQuads;
|
||||
public readonly bool SupportsSeparateSampler;
|
||||
public readonly bool SupportsShaderBallot;
|
||||
public readonly bool SupportsShaderBarrierDivergence;
|
||||
public readonly bool SupportsShaderFloat64;
|
||||
@ -92,6 +94,8 @@ namespace Ryujinx.Graphics.GAL
|
||||
bool supportsMismatchingViewFormat,
|
||||
bool supportsCubemapView,
|
||||
bool supportsNonConstantTextureOffset,
|
||||
bool supportsQuads,
|
||||
bool supportsSeparateSampler,
|
||||
bool supportsShaderBallot,
|
||||
bool supportsShaderBarrierDivergence,
|
||||
bool supportsShaderFloat64,
|
||||
@ -144,6 +148,8 @@ namespace Ryujinx.Graphics.GAL
|
||||
SupportsMismatchingViewFormat = supportsMismatchingViewFormat;
|
||||
SupportsCubemapView = supportsCubemapView;
|
||||
SupportsNonConstantTextureOffset = supportsNonConstantTextureOffset;
|
||||
SupportsQuads = supportsQuads;
|
||||
SupportsSeparateSampler = supportsSeparateSampler;
|
||||
SupportsShaderBallot = supportsShaderBallot;
|
||||
SupportsShaderBarrierDivergence = supportsShaderBarrierDivergence;
|
||||
SupportsShaderFloat64 = supportsShaderFloat64;
|
||||
|
@ -126,6 +126,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute
|
||||
ulong samplerPoolGpuVa = ((ulong)_state.State.SetTexSamplerPoolAOffsetUpper << 32) | _state.State.SetTexSamplerPoolB;
|
||||
ulong texturePoolGpuVa = ((ulong)_state.State.SetTexHeaderPoolAOffsetUpper << 32) | _state.State.SetTexHeaderPoolB;
|
||||
|
||||
int samplerPoolMaximumId = _state.State.SetTexSamplerPoolCMaximumIndex;
|
||||
|
||||
GpuChannelPoolState poolState = new(
|
||||
texturePoolGpuVa,
|
||||
_state.State.SetTexHeaderPoolCMaximumIndex,
|
||||
@ -139,7 +141,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute
|
||||
sharedMemorySize,
|
||||
_channel.BufferManager.HasUnalignedStorageBuffers);
|
||||
|
||||
CachedShaderProgram cs = memoryManager.Physical.ShaderCache.GetComputeShader(_channel, poolState, computeState, shaderGpuVa);
|
||||
CachedShaderProgram cs = memoryManager.Physical.ShaderCache.GetComputeShader(_channel, samplerPoolMaximumId, poolState, computeState, shaderGpuVa);
|
||||
|
||||
_context.Renderer.Pipeline.SetProgram(cs.HostProgram);
|
||||
|
||||
@ -184,7 +186,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute
|
||||
sharedMemorySize,
|
||||
_channel.BufferManager.HasUnalignedStorageBuffers);
|
||||
|
||||
cs = memoryManager.Physical.ShaderCache.GetComputeShader(_channel, poolState, computeState, shaderGpuVa);
|
||||
cs = memoryManager.Physical.ShaderCache.GetComputeShader(_channel, samplerPoolMaximumId, poolState, computeState, shaderGpuVa);
|
||||
|
||||
_context.Renderer.Pipeline.SetProgram(cs.HostProgram);
|
||||
}
|
||||
|
@ -157,6 +157,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
|
||||
}
|
||||
else if (operation == SyncpointbOperation.Incr)
|
||||
{
|
||||
// "Unbind" render targets since a syncpoint increment might indicate future CPU access for the textures.
|
||||
_parent.TextureManager.RefreshModifiedTextures();
|
||||
|
||||
_context.CreateHostSyncIfNeeded(HostSyncFlags.StrictSyncpoint);
|
||||
_context.Synchronization.IncrementSyncpoint(syncpointId);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using Ryujinx.Graphics.Gpu.Engine.Dma;
|
||||
using Ryujinx.Graphics.Gpu.Engine.InlineToMemory;
|
||||
using Ryujinx.Graphics.Gpu.Engine.Threed;
|
||||
using Ryujinx.Graphics.Gpu.Engine.Twod;
|
||||
using Ryujinx.Graphics.Gpu.Image;
|
||||
using Ryujinx.Graphics.Gpu.Memory;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
@ -28,6 +29,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
|
||||
/// </summary>
|
||||
public MemoryManager MemoryManager => _channel.MemoryManager;
|
||||
|
||||
/// <summary>
|
||||
/// Channel texture manager.
|
||||
/// </summary>
|
||||
public TextureManager TextureManager => _channel.TextureManager;
|
||||
|
||||
/// <summary>
|
||||
/// 3D Engine.
|
||||
/// </summary>
|
||||
|
@ -1429,7 +1429,18 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||
addressesSpan[index] = baseAddress + shader.Offset;
|
||||
}
|
||||
|
||||
CachedShaderProgram gs = shaderCache.GetGraphicsShader(ref _state.State, ref _pipeline, _channel, ref _currentSpecState.GetPoolState(), ref _currentSpecState.GetGraphicsState(), addresses);
|
||||
int samplerPoolMaximumId = _state.State.SamplerIndex == SamplerIndex.ViaHeaderIndex
|
||||
? _state.State.TexturePoolState.MaximumId
|
||||
: _state.State.SamplerPoolState.MaximumId;
|
||||
|
||||
CachedShaderProgram gs = shaderCache.GetGraphicsShader(
|
||||
ref _state.State,
|
||||
ref _pipeline,
|
||||
_channel,
|
||||
samplerPoolMaximumId,
|
||||
ref _currentSpecState.GetPoolState(),
|
||||
ref _currentSpecState.GetGraphicsState(),
|
||||
addresses);
|
||||
|
||||
// Consume the modified flag for spec state so that it isn't checked again.
|
||||
_currentSpecState.SetShader(gs);
|
||||
|
@ -395,8 +395,14 @@ namespace Ryujinx.Graphics.Gpu
|
||||
{
|
||||
Renderer.CreateSync(SyncNumber, strict);
|
||||
|
||||
SyncActions.ForEach(action => action.SyncPreAction(syncpoint));
|
||||
SyncpointActions.ForEach(action => action.SyncPreAction(syncpoint));
|
||||
foreach (var action in SyncActions)
|
||||
{
|
||||
action.SyncPreAction(syncpoint);
|
||||
}
|
||||
foreach (var action in SyncpointActions)
|
||||
{
|
||||
action.SyncPreAction(syncpoint);
|
||||
}
|
||||
|
||||
SyncNumber++;
|
||||
|
||||
|
@ -62,8 +62,9 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// <param name="channel">GPU channel that the texture pool cache belongs to</param>
|
||||
/// <param name="address">Start address of the texture pool</param>
|
||||
/// <param name="maximumId">Maximum ID of the texture pool</param>
|
||||
/// <param name="bindingsArrayCache">Cache of texture array bindings</param>
|
||||
/// <returns>The found or newly created texture pool</returns>
|
||||
public T FindOrCreate(GpuChannel channel, ulong address, int maximumId)
|
||||
public T FindOrCreate(GpuChannel channel, ulong address, int maximumId, TextureBindingsArrayCache bindingsArrayCache)
|
||||
{
|
||||
// Remove old entries from the cache, if possible.
|
||||
while (_pools.Count > MaxCapacity && (_currentTimestamp - _pools.First.Value.CacheTimestamp) >= MinDeltaForRemoval)
|
||||
@ -73,6 +74,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
_pools.RemoveFirst();
|
||||
oldestPool.Dispose();
|
||||
oldestPool.CacheNode = null;
|
||||
bindingsArrayCache.RemoveAllWithPool(oldestPool);
|
||||
}
|
||||
|
||||
T pool;
|
||||
@ -87,8 +89,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
if (pool.CacheNode != _pools.Last)
|
||||
{
|
||||
_pools.Remove(pool.CacheNode);
|
||||
|
||||
pool.CacheNode = _pools.AddLast(pool);
|
||||
_pools.AddLast(pool.CacheNode);
|
||||
}
|
||||
|
||||
pool.CacheTimestamp = _currentTimestamp;
|
||||
|
@ -390,7 +390,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
{
|
||||
_views.Remove(texture);
|
||||
|
||||
Group.RemoveView(texture);
|
||||
Group.RemoveView(_views, texture);
|
||||
|
||||
texture._viewStorage = texture;
|
||||
|
||||
|
@ -44,6 +44,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// </summary>
|
||||
public TextureUsageFlags Flags { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the binding is for a sampler.
|
||||
/// </summary>
|
||||
public bool IsSamplerOnly { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the texture binding information structure.
|
||||
/// </summary>
|
||||
@ -74,8 +79,17 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// <param name="cbufSlot">Constant buffer slot where the texture handle is located</param>
|
||||
/// <param name="handle">The shader texture handle (read index into the texture constant buffer)</param>
|
||||
/// <param name="flags">The texture's usage flags, indicating how it is used in the shader</param>
|
||||
public TextureBindingInfo(Target target, int binding, int arrayLength, int cbufSlot, int handle, TextureUsageFlags flags) : this(target, (Format)0, binding, arrayLength, cbufSlot, handle, flags)
|
||||
/// <param name="isSamplerOnly">Indicates that the binding is for a sampler</param>
|
||||
public TextureBindingInfo(
|
||||
Target target,
|
||||
int binding,
|
||||
int arrayLength,
|
||||
int cbufSlot,
|
||||
int handle,
|
||||
TextureUsageFlags flags,
|
||||
bool isSamplerOnly) : this(target, 0, binding, arrayLength, cbufSlot, handle, flags)
|
||||
{
|
||||
IsSamplerOnly = isSamplerOnly;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,12 +21,98 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
private readonly GpuContext _context;
|
||||
private readonly GpuChannel _channel;
|
||||
private readonly bool _isCompute;
|
||||
|
||||
/// <summary>
|
||||
/// Array cache entry key.
|
||||
/// </summary>
|
||||
private readonly struct CacheEntryKey : IEquatable<CacheEntryKey>
|
||||
private readonly struct CacheEntryFromPoolKey : IEquatable<CacheEntryFromPoolKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the entry is for an image.
|
||||
/// </summary>
|
||||
public readonly bool IsImage;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the entry is for a sampler.
|
||||
/// </summary>
|
||||
public readonly bool IsSampler;
|
||||
|
||||
/// <summary>
|
||||
/// Texture or image target type.
|
||||
/// </summary>
|
||||
public readonly Target Target;
|
||||
|
||||
/// <summary>
|
||||
/// Number of entries of the array.
|
||||
/// </summary>
|
||||
public readonly int ArrayLength;
|
||||
|
||||
private readonly TexturePool _texturePool;
|
||||
private readonly SamplerPool _samplerPool;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new array cache entry.
|
||||
/// </summary>
|
||||
/// <param name="isImage">Whether the entry is for an image</param>
|
||||
/// <param name="bindingInfo">Binding information for the array</param>
|
||||
/// <param name="texturePool">Texture pool where the array textures are located</param>
|
||||
/// <param name="samplerPool">Sampler pool where the array samplers are located</param>
|
||||
public CacheEntryFromPoolKey(bool isImage, TextureBindingInfo bindingInfo, TexturePool texturePool, SamplerPool samplerPool)
|
||||
{
|
||||
IsImage = isImage;
|
||||
IsSampler = bindingInfo.IsSamplerOnly;
|
||||
Target = bindingInfo.Target;
|
||||
ArrayLength = bindingInfo.ArrayLength;
|
||||
|
||||
_texturePool = texturePool;
|
||||
_samplerPool = samplerPool;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the pool matches the cached pool.
|
||||
/// </summary>
|
||||
/// <param name="texturePool">Texture or sampler pool instance</param>
|
||||
/// <returns>True if the pool matches, false otherwise</returns>
|
||||
public bool MatchesPool<T>(IPool<T> pool)
|
||||
{
|
||||
return _texturePool == pool || _samplerPool == pool;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the texture and sampler pools matches the cached pools.
|
||||
/// </summary>
|
||||
/// <param name="texturePool">Texture pool instance</param>
|
||||
/// <param name="samplerPool">Sampler pool instance</param>
|
||||
/// <returns>True if the pools match, false otherwise</returns>
|
||||
private bool MatchesPools(TexturePool texturePool, SamplerPool samplerPool)
|
||||
{
|
||||
return _texturePool == texturePool && _samplerPool == samplerPool;
|
||||
}
|
||||
|
||||
public bool Equals(CacheEntryFromPoolKey other)
|
||||
{
|
||||
return IsImage == other.IsImage &&
|
||||
IsSampler == other.IsSampler &&
|
||||
Target == other.Target &&
|
||||
ArrayLength == other.ArrayLength &&
|
||||
MatchesPools(other._texturePool, other._samplerPool);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is CacheEntryFromBufferKey other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(_texturePool, _samplerPool, IsSampler);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Array cache entry key.
|
||||
/// </summary>
|
||||
private readonly struct CacheEntryFromBufferKey : IEquatable<CacheEntryFromBufferKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the entry is for an image.
|
||||
@ -61,7 +147,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// <param name="texturePool">Texture pool where the array textures are located</param>
|
||||
/// <param name="samplerPool">Sampler pool where the array samplers are located</param>
|
||||
/// <param name="textureBufferBounds">Constant buffer bounds with the texture handles</param>
|
||||
public CacheEntryKey(
|
||||
public CacheEntryFromBufferKey(
|
||||
bool isImage,
|
||||
TextureBindingInfo bindingInfo,
|
||||
TexturePool texturePool,
|
||||
@ -100,7 +186,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
return _textureBufferBounds.Equals(textureBufferBounds);
|
||||
}
|
||||
|
||||
public bool Equals(CacheEntryKey other)
|
||||
public bool Equals(CacheEntryFromBufferKey other)
|
||||
{
|
||||
return IsImage == other.IsImage &&
|
||||
Target == other.Target &&
|
||||
@ -112,7 +198,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is CacheEntryKey other && Equals(other);
|
||||
return obj is CacheEntryFromBufferKey other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
@ -122,40 +208,15 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Array cache entry.
|
||||
/// Array cache entry from pool.
|
||||
/// </summary>
|
||||
private class CacheEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Key for this entry on the cache.
|
||||
/// </summary>
|
||||
public readonly CacheEntryKey Key;
|
||||
|
||||
/// <summary>
|
||||
/// Linked list node used on the texture bindings array cache.
|
||||
/// </summary>
|
||||
public LinkedListNode<CacheEntry> CacheNode;
|
||||
|
||||
/// <summary>
|
||||
/// Timestamp set on the last use of the array by the cache.
|
||||
/// </summary>
|
||||
public int CacheTimestamp;
|
||||
|
||||
/// <summary>
|
||||
/// All cached textures, along with their invalidated sequence number as value.
|
||||
/// </summary>
|
||||
public readonly Dictionary<Texture, int> Textures;
|
||||
|
||||
/// <summary>
|
||||
/// All pool texture IDs along with their textures.
|
||||
/// </summary>
|
||||
public readonly Dictionary<int, Texture> TextureIds;
|
||||
|
||||
/// <summary>
|
||||
/// All pool sampler IDs along with their samplers.
|
||||
/// </summary>
|
||||
public readonly Dictionary<int, Sampler> SamplerIds;
|
||||
|
||||
/// <summary>
|
||||
/// Backend texture array if the entry is for a texture, otherwise null.
|
||||
/// </summary>
|
||||
@ -166,44 +227,39 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// </summary>
|
||||
public readonly IImageArray ImageArray;
|
||||
|
||||
private readonly TexturePool _texturePool;
|
||||
private readonly SamplerPool _samplerPool;
|
||||
/// <summary>
|
||||
/// Texture pool where the array textures are located.
|
||||
/// </summary>
|
||||
protected readonly TexturePool TexturePool;
|
||||
|
||||
/// <summary>
|
||||
/// Sampler pool where the array samplers are located.
|
||||
/// </summary>
|
||||
protected readonly SamplerPool SamplerPool;
|
||||
|
||||
private int _texturePoolSequence;
|
||||
private int _samplerPoolSequence;
|
||||
|
||||
private int[] _cachedTextureBuffer;
|
||||
private int[] _cachedSamplerBuffer;
|
||||
|
||||
private int _lastSequenceNumber;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new array cache entry.
|
||||
/// </summary>
|
||||
/// <param name="key">Key for this entry on the cache</param>
|
||||
/// <param name="texturePool">Texture pool where the array textures are located</param>
|
||||
/// <param name="samplerPool">Sampler pool where the array samplers are located</param>
|
||||
private CacheEntry(ref CacheEntryKey key, TexturePool texturePool, SamplerPool samplerPool)
|
||||
private CacheEntry(TexturePool texturePool, SamplerPool samplerPool)
|
||||
{
|
||||
Key = key;
|
||||
Textures = new Dictionary<Texture, int>();
|
||||
TextureIds = new Dictionary<int, Texture>();
|
||||
SamplerIds = new Dictionary<int, Sampler>();
|
||||
|
||||
_texturePool = texturePool;
|
||||
_samplerPool = samplerPool;
|
||||
|
||||
_lastSequenceNumber = -1;
|
||||
TexturePool = texturePool;
|
||||
SamplerPool = samplerPool;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new array cache entry.
|
||||
/// </summary>
|
||||
/// <param name="key">Key for this entry on the cache</param>
|
||||
/// <param name="array">Backend texture array</param>
|
||||
/// <param name="texturePool">Texture pool where the array textures are located</param>
|
||||
/// <param name="samplerPool">Sampler pool where the array samplers are located</param>
|
||||
public CacheEntry(ref CacheEntryKey key, ITextureArray array, TexturePool texturePool, SamplerPool samplerPool) : this(ref key, texturePool, samplerPool)
|
||||
public CacheEntry(ITextureArray array, TexturePool texturePool, SamplerPool samplerPool) : this(texturePool, samplerPool)
|
||||
{
|
||||
TextureArray = array;
|
||||
}
|
||||
@ -211,11 +267,10 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// <summary>
|
||||
/// Creates a new array cache entry.
|
||||
/// </summary>
|
||||
/// <param name="key">Key for this entry on the cache</param>
|
||||
/// <param name="array">Backend image array</param>
|
||||
/// <param name="texturePool">Texture pool where the array textures are located</param>
|
||||
/// <param name="samplerPool">Sampler pool where the array samplers are located</param>
|
||||
public CacheEntry(ref CacheEntryKey key, IImageArray array, TexturePool texturePool, SamplerPool samplerPool) : this(ref key, texturePool, samplerPool)
|
||||
public CacheEntry(IImageArray array, TexturePool texturePool, SamplerPool samplerPool) : this(texturePool, samplerPool)
|
||||
{
|
||||
ImageArray = array;
|
||||
}
|
||||
@ -248,23 +303,9 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// <summary>
|
||||
/// Clears all cached texture instances.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
public virtual void Reset()
|
||||
{
|
||||
Textures.Clear();
|
||||
TextureIds.Clear();
|
||||
SamplerIds.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the cached constant buffer data.
|
||||
/// </summary>
|
||||
/// <param name="cachedTextureBuffer">Constant buffer data with the texture handles (and sampler handles, if they are combined)</param>
|
||||
/// <param name="cachedSamplerBuffer">Constant buffer data with the sampler handles</param>
|
||||
/// <param name="separateSamplerBuffer">Whether <paramref name="cachedTextureBuffer"/> and <paramref name="cachedSamplerBuffer"/> comes from different buffers</param>
|
||||
public void UpdateData(ReadOnlySpan<int> cachedTextureBuffer, ReadOnlySpan<int> cachedSamplerBuffer, bool separateSamplerBuffer)
|
||||
{
|
||||
_cachedTextureBuffer = cachedTextureBuffer.ToArray();
|
||||
_cachedSamplerBuffer = separateSamplerBuffer ? cachedSamplerBuffer.ToArray() : _cachedTextureBuffer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -287,39 +328,105 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// <summary>
|
||||
/// Checks if the cached texture or sampler pool has been modified since the last call to this method.
|
||||
/// </summary>
|
||||
/// <returns>True if any used entries of the pools might have been modified, false otherwise</returns>
|
||||
public bool PoolsModified()
|
||||
/// <returns>True if any used entries of the pool might have been modified, false otherwise</returns>
|
||||
public bool TexturePoolModified()
|
||||
{
|
||||
bool texturePoolModified = _texturePool.WasModified(ref _texturePoolSequence);
|
||||
bool samplerPoolModified = _samplerPool.WasModified(ref _samplerPoolSequence);
|
||||
return TexturePool.WasModified(ref _texturePoolSequence);
|
||||
}
|
||||
|
||||
// If both pools were not modified since the last check, we have nothing else to check.
|
||||
if (!texturePoolModified && !samplerPoolModified)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Checks if the cached texture or sampler pool has been modified since the last call to this method.
|
||||
/// </summary>
|
||||
/// <returns>True if any used entries of the pool might have been modified, false otherwise</returns>
|
||||
public bool SamplerPoolModified()
|
||||
{
|
||||
return SamplerPool.WasModified(ref _samplerPoolSequence);
|
||||
}
|
||||
}
|
||||
|
||||
// If the pools were modified, let's check if any of the entries we care about changed.
|
||||
/// <summary>
|
||||
/// Array cache entry from constant buffer.
|
||||
/// </summary>
|
||||
private class CacheEntryFromBuffer : CacheEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Key for this entry on the cache.
|
||||
/// </summary>
|
||||
public readonly CacheEntryFromBufferKey Key;
|
||||
|
||||
// Check if any of our cached textures changed on the pool.
|
||||
foreach ((int textureId, Texture texture) in TextureIds)
|
||||
{
|
||||
if (_texturePool.GetCachedItem(textureId) != texture)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Linked list node used on the texture bindings array cache.
|
||||
/// </summary>
|
||||
public LinkedListNode<CacheEntryFromBuffer> CacheNode;
|
||||
|
||||
// Check if any of our cached samplers changed on the pool.
|
||||
foreach ((int samplerId, Sampler sampler) in SamplerIds)
|
||||
{
|
||||
if (_samplerPool.GetCachedItem(samplerId) != sampler)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Timestamp set on the last use of the array by the cache.
|
||||
/// </summary>
|
||||
public int CacheTimestamp;
|
||||
|
||||
return false;
|
||||
/// <summary>
|
||||
/// All pool texture IDs along with their textures.
|
||||
/// </summary>
|
||||
public readonly Dictionary<int, (Texture, TextureDescriptor)> TextureIds;
|
||||
|
||||
/// <summary>
|
||||
/// All pool sampler IDs along with their samplers.
|
||||
/// </summary>
|
||||
public readonly Dictionary<int, (Sampler, SamplerDescriptor)> SamplerIds;
|
||||
|
||||
private int[] _cachedTextureBuffer;
|
||||
private int[] _cachedSamplerBuffer;
|
||||
|
||||
private int _lastSequenceNumber;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new array cache entry.
|
||||
/// </summary>
|
||||
/// <param name="key">Key for this entry on the cache</param>
|
||||
/// <param name="array">Backend texture array</param>
|
||||
/// <param name="texturePool">Texture pool where the array textures are located</param>
|
||||
/// <param name="samplerPool">Sampler pool where the array samplers are located</param>
|
||||
public CacheEntryFromBuffer(ref CacheEntryFromBufferKey key, ITextureArray array, TexturePool texturePool, SamplerPool samplerPool) : base(array, texturePool, samplerPool)
|
||||
{
|
||||
Key = key;
|
||||
_lastSequenceNumber = -1;
|
||||
TextureIds = new Dictionary<int, (Texture, TextureDescriptor)>();
|
||||
SamplerIds = new Dictionary<int, (Sampler, SamplerDescriptor)>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new array cache entry.
|
||||
/// </summary>
|
||||
/// <param name="key">Key for this entry on the cache</param>
|
||||
/// <param name="array">Backend image array</param>
|
||||
/// <param name="texturePool">Texture pool where the array textures are located</param>
|
||||
/// <param name="samplerPool">Sampler pool where the array samplers are located</param>
|
||||
public CacheEntryFromBuffer(ref CacheEntryFromBufferKey key, IImageArray array, TexturePool texturePool, SamplerPool samplerPool) : base(array, texturePool, samplerPool)
|
||||
{
|
||||
Key = key;
|
||||
_lastSequenceNumber = -1;
|
||||
TextureIds = new Dictionary<int, (Texture, TextureDescriptor)>();
|
||||
SamplerIds = new Dictionary<int, (Sampler, SamplerDescriptor)>();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
TextureIds.Clear();
|
||||
SamplerIds.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the cached constant buffer data.
|
||||
/// </summary>
|
||||
/// <param name="cachedTextureBuffer">Constant buffer data with the texture handles (and sampler handles, if they are combined)</param>
|
||||
/// <param name="cachedSamplerBuffer">Constant buffer data with the sampler handles</param>
|
||||
/// <param name="separateSamplerBuffer">Whether <paramref name="cachedTextureBuffer"/> and <paramref name="cachedSamplerBuffer"/> comes from different buffers</param>
|
||||
public void UpdateData(ReadOnlySpan<int> cachedTextureBuffer, ReadOnlySpan<int> cachedSamplerBuffer, bool separateSamplerBuffer)
|
||||
{
|
||||
_cachedTextureBuffer = cachedTextureBuffer.ToArray();
|
||||
_cachedSamplerBuffer = separateSamplerBuffer ? cachedSamplerBuffer.ToArray() : _cachedTextureBuffer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -380,10 +487,51 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the cached texture or sampler pool has been modified since the last call to this method.
|
||||
/// </summary>
|
||||
/// <returns>True if any used entries of the pools might have been modified, false otherwise</returns>
|
||||
public bool PoolsModified()
|
||||
{
|
||||
bool texturePoolModified = TexturePoolModified();
|
||||
bool samplerPoolModified = SamplerPoolModified();
|
||||
|
||||
// If both pools were not modified since the last check, we have nothing else to check.
|
||||
if (!texturePoolModified && !samplerPoolModified)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the pools were modified, let's check if any of the entries we care about changed.
|
||||
|
||||
// Check if any of our cached textures changed on the pool.
|
||||
foreach ((int textureId, (Texture texture, TextureDescriptor descriptor)) in TextureIds)
|
||||
{
|
||||
if (TexturePool.GetCachedItem(textureId) != texture ||
|
||||
(texture == null && TexturePool.IsValidId(textureId) && !TexturePool.GetDescriptorRef(textureId).Equals(descriptor)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any of our cached samplers changed on the pool.
|
||||
foreach ((int samplerId, (Sampler sampler, SamplerDescriptor descriptor)) in SamplerIds)
|
||||
{
|
||||
if (SamplerPool.GetCachedItem(samplerId) != sampler ||
|
||||
(sampler == null && SamplerPool.IsValidId(samplerId) && !SamplerPool.GetDescriptorRef(samplerId).Equals(descriptor)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<CacheEntryKey, CacheEntry> _cache;
|
||||
private readonly LinkedList<CacheEntry> _lruCache;
|
||||
private readonly Dictionary<CacheEntryFromBufferKey, CacheEntryFromBuffer> _cacheFromBuffer;
|
||||
private readonly Dictionary<CacheEntryFromPoolKey, CacheEntry> _cacheFromPool;
|
||||
private readonly LinkedList<CacheEntryFromBuffer> _lruCache;
|
||||
|
||||
private int _currentTimestamp;
|
||||
|
||||
@ -392,14 +540,13 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// </summary>
|
||||
/// <param name="context">GPU context</param>
|
||||
/// <param name="channel">GPU channel</param>
|
||||
/// <param name="isCompute">Whether the bindings will be used for compute or graphics pipelines</param>
|
||||
public TextureBindingsArrayCache(GpuContext context, GpuChannel channel, bool isCompute)
|
||||
public TextureBindingsArrayCache(GpuContext context, GpuChannel channel)
|
||||
{
|
||||
_context = context;
|
||||
_channel = channel;
|
||||
_isCompute = isCompute;
|
||||
_cache = new Dictionary<CacheEntryKey, CacheEntry>();
|
||||
_lruCache = new LinkedList<CacheEntry>();
|
||||
_cacheFromBuffer = new Dictionary<CacheEntryFromBufferKey, CacheEntryFromBuffer>();
|
||||
_cacheFromPool = new Dictionary<CacheEntryFromPoolKey, CacheEntry>();
|
||||
_lruCache = new LinkedList<CacheEntryFromBuffer>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -457,15 +604,180 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
bool isImage,
|
||||
SamplerIndex samplerIndex,
|
||||
TextureBindingInfo bindingInfo)
|
||||
{
|
||||
if (IsDirectHandleType(bindingInfo.Handle))
|
||||
{
|
||||
UpdateFromPool(texturePool, samplerPool, stage, isImage, bindingInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateFromBuffer(texturePool, samplerPool, stage, stageIndex, textureBufferIndex, isImage, samplerIndex, bindingInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a texture or image array bindings and textures from a texture or sampler pool.
|
||||
/// </summary>
|
||||
/// <param name="texturePool">Texture pool</param>
|
||||
/// <param name="samplerPool">Sampler pool</param>
|
||||
/// <param name="stage">Shader stage where the array is used</param>
|
||||
/// <param name="isImage">Whether the array is a image or texture array</param>
|
||||
/// <param name="bindingInfo">Array binding information</param>
|
||||
private void UpdateFromPool(TexturePool texturePool, SamplerPool samplerPool, ShaderStage stage, bool isImage, TextureBindingInfo bindingInfo)
|
||||
{
|
||||
CacheEntry entry = GetOrAddEntry(texturePool, samplerPool, bindingInfo, isImage, out bool isNewEntry);
|
||||
|
||||
bool isSampler = bindingInfo.IsSamplerOnly;
|
||||
bool poolModified = isSampler ? entry.SamplerPoolModified() : entry.TexturePoolModified();
|
||||
bool isStore = bindingInfo.Flags.HasFlag(TextureUsageFlags.ImageStore);
|
||||
bool resScaleUnsupported = bindingInfo.Flags.HasFlag(TextureUsageFlags.ResScaleUnsupported);
|
||||
|
||||
if (!poolModified && !isNewEntry && entry.ValidateTextures())
|
||||
{
|
||||
entry.SynchronizeMemory(isStore, resScaleUnsupported);
|
||||
|
||||
if (isImage)
|
||||
{
|
||||
_context.Renderer.Pipeline.SetImageArray(stage, bindingInfo.Binding, entry.ImageArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
_context.Renderer.Pipeline.SetTextureArray(stage, bindingInfo.Binding, entry.TextureArray);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isNewEntry)
|
||||
{
|
||||
entry.Reset();
|
||||
}
|
||||
|
||||
int length = (isSampler ? samplerPool.MaximumId : texturePool.MaximumId) + 1;
|
||||
length = Math.Min(length, bindingInfo.ArrayLength);
|
||||
|
||||
Format[] formats = isImage ? new Format[bindingInfo.ArrayLength] : null;
|
||||
ISampler[] samplers = isImage ? null : new ISampler[bindingInfo.ArrayLength];
|
||||
ITexture[] textures = new ITexture[bindingInfo.ArrayLength];
|
||||
|
||||
for (int index = 0; index < length; index++)
|
||||
{
|
||||
Texture texture = null;
|
||||
Sampler sampler = null;
|
||||
|
||||
if (isSampler)
|
||||
{
|
||||
sampler = samplerPool?.Get(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
ref readonly TextureDescriptor descriptor = ref texturePool.GetForBinding(index, out texture);
|
||||
|
||||
if (texture != null)
|
||||
{
|
||||
entry.Textures[texture] = texture.InvalidatedSequence;
|
||||
|
||||
if (isStore)
|
||||
{
|
||||
texture.SignalModified();
|
||||
}
|
||||
|
||||
if (resScaleUnsupported && texture.ScaleMode != TextureScaleMode.Blacklisted)
|
||||
{
|
||||
// Scaling textures used on arrays is currently not supported.
|
||||
|
||||
texture.BlacklistScale();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ITexture hostTexture = texture?.GetTargetTexture(bindingInfo.Target);
|
||||
ISampler hostSampler = sampler?.GetHostSampler(texture);
|
||||
|
||||
Format format = bindingInfo.Format;
|
||||
|
||||
if (hostTexture != null && texture.Target == Target.TextureBuffer)
|
||||
{
|
||||
// Ensure that the buffer texture is using the correct buffer as storage.
|
||||
// Buffers are frequently re-created to accommodate larger data, so we need to re-bind
|
||||
// to ensure we're not using a old buffer that was already deleted.
|
||||
if (isImage)
|
||||
{
|
||||
if (format == 0 && texture != null)
|
||||
{
|
||||
format = texture.Format;
|
||||
}
|
||||
|
||||
_channel.BufferManager.SetBufferTextureStorage(entry.ImageArray, hostTexture, texture.Range, bindingInfo, index, format);
|
||||
}
|
||||
else
|
||||
{
|
||||
_channel.BufferManager.SetBufferTextureStorage(entry.TextureArray, hostTexture, texture.Range, bindingInfo, index, format);
|
||||
}
|
||||
}
|
||||
else if (isImage)
|
||||
{
|
||||
if (format == 0 && texture != null)
|
||||
{
|
||||
format = texture.Format;
|
||||
}
|
||||
|
||||
formats[index] = format;
|
||||
textures[index] = hostTexture;
|
||||
}
|
||||
else
|
||||
{
|
||||
samplers[index] = hostSampler;
|
||||
textures[index] = hostTexture;
|
||||
}
|
||||
}
|
||||
|
||||
if (isImage)
|
||||
{
|
||||
entry.ImageArray.SetFormats(0, formats);
|
||||
entry.ImageArray.SetImages(0, textures);
|
||||
|
||||
_context.Renderer.Pipeline.SetImageArray(stage, bindingInfo.Binding, entry.ImageArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.TextureArray.SetSamplers(0, samplers);
|
||||
entry.TextureArray.SetTextures(0, textures);
|
||||
|
||||
_context.Renderer.Pipeline.SetTextureArray(stage, bindingInfo.Binding, entry.TextureArray);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a texture or image array bindings and textures from constant buffer handles.
|
||||
/// </summary>
|
||||
/// <param name="texturePool">Texture pool</param>
|
||||
/// <param name="samplerPool">Sampler pool</param>
|
||||
/// <param name="stage">Shader stage where the array is used</param>
|
||||
/// <param name="stageIndex">Shader stage index where the array is used</param>
|
||||
/// <param name="textureBufferIndex">Texture constant buffer index</param>
|
||||
/// <param name="isImage">Whether the array is a image or texture array</param>
|
||||
/// <param name="samplerIndex">Sampler handles source</param>
|
||||
/// <param name="bindingInfo">Array binding information</param>
|
||||
private void UpdateFromBuffer(
|
||||
TexturePool texturePool,
|
||||
SamplerPool samplerPool,
|
||||
ShaderStage stage,
|
||||
int stageIndex,
|
||||
int textureBufferIndex,
|
||||
bool isImage,
|
||||
SamplerIndex samplerIndex,
|
||||
TextureBindingInfo bindingInfo)
|
||||
{
|
||||
(textureBufferIndex, int samplerBufferIndex) = TextureHandle.UnpackSlots(bindingInfo.CbufSlot, textureBufferIndex);
|
||||
|
||||
bool separateSamplerBuffer = textureBufferIndex != samplerBufferIndex;
|
||||
bool isCompute = stage == ShaderStage.Compute;
|
||||
|
||||
ref BufferBounds textureBufferBounds = ref _channel.BufferManager.GetUniformBufferBounds(_isCompute, stageIndex, textureBufferIndex);
|
||||
ref BufferBounds samplerBufferBounds = ref _channel.BufferManager.GetUniformBufferBounds(_isCompute, stageIndex, samplerBufferIndex);
|
||||
ref BufferBounds textureBufferBounds = ref _channel.BufferManager.GetUniformBufferBounds(isCompute, stageIndex, textureBufferIndex);
|
||||
ref BufferBounds samplerBufferBounds = ref _channel.BufferManager.GetUniformBufferBounds(isCompute, stageIndex, samplerBufferIndex);
|
||||
|
||||
CacheEntry entry = GetOrAddEntry(
|
||||
CacheEntryFromBuffer entry = GetOrAddEntry(
|
||||
texturePool,
|
||||
samplerPool,
|
||||
bindingInfo,
|
||||
@ -589,8 +901,8 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
Sampler sampler = samplerPool?.Get(samplerId);
|
||||
|
||||
entry.TextureIds[textureId] = texture;
|
||||
entry.SamplerIds[samplerId] = sampler;
|
||||
entry.TextureIds[textureId] = (texture, descriptor);
|
||||
entry.SamplerIds[samplerId] = (sampler, samplerPool?.GetDescriptorRef(samplerId) ?? default);
|
||||
|
||||
ITexture hostTexture = texture?.GetTargetTexture(bindingInfo.Target);
|
||||
ISampler hostSampler = sampler?.GetHostSampler(texture);
|
||||
@ -650,13 +962,12 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a cached texture entry, or creates a new one if not found.
|
||||
/// Gets a cached texture entry from pool, or creates a new one if not found.
|
||||
/// </summary>
|
||||
/// <param name="texturePool">Texture pool</param>
|
||||
/// <param name="samplerPool">Sampler pool</param>
|
||||
/// <param name="bindingInfo">Array binding information</param>
|
||||
/// <param name="isImage">Whether the array is a image or texture array</param>
|
||||
/// <param name="textureBufferBounds">Constant buffer bounds with the texture handles</param>
|
||||
/// <param name="isNew">Whether a new entry was created, or an existing one was returned</param>
|
||||
/// <returns>Cache entry</returns>
|
||||
private CacheEntry GetOrAddEntry(
|
||||
@ -664,17 +975,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
SamplerPool samplerPool,
|
||||
TextureBindingInfo bindingInfo,
|
||||
bool isImage,
|
||||
ref BufferBounds textureBufferBounds,
|
||||
out bool isNew)
|
||||
{
|
||||
CacheEntryKey key = new CacheEntryKey(
|
||||
isImage,
|
||||
bindingInfo,
|
||||
texturePool,
|
||||
samplerPool,
|
||||
ref textureBufferBounds);
|
||||
CacheEntryFromPoolKey key = new CacheEntryFromPoolKey(isImage, bindingInfo, texturePool, samplerPool);
|
||||
|
||||
isNew = !_cache.TryGetValue(key, out CacheEntry entry);
|
||||
isNew = !_cacheFromPool.TryGetValue(key, out CacheEntry entry);
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
@ -684,13 +989,61 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
{
|
||||
IImageArray array = _context.Renderer.CreateImageArray(arrayLength, bindingInfo.Target == Target.TextureBuffer);
|
||||
|
||||
_cache.Add(key, entry = new CacheEntry(ref key, array, texturePool, samplerPool));
|
||||
_cacheFromPool.Add(key, entry = new CacheEntry(array, texturePool, samplerPool));
|
||||
}
|
||||
else
|
||||
{
|
||||
ITextureArray array = _context.Renderer.CreateTextureArray(arrayLength, bindingInfo.Target == Target.TextureBuffer);
|
||||
|
||||
_cache.Add(key, entry = new CacheEntry(ref key, array, texturePool, samplerPool));
|
||||
_cacheFromPool.Add(key, entry = new CacheEntry(array, texturePool, samplerPool));
|
||||
}
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a cached texture entry from constant buffer, or creates a new one if not found.
|
||||
/// </summary>
|
||||
/// <param name="texturePool">Texture pool</param>
|
||||
/// <param name="samplerPool">Sampler pool</param>
|
||||
/// <param name="bindingInfo">Array binding information</param>
|
||||
/// <param name="isImage">Whether the array is a image or texture array</param>
|
||||
/// <param name="textureBufferBounds">Constant buffer bounds with the texture handles</param>
|
||||
/// <param name="isNew">Whether a new entry was created, or an existing one was returned</param>
|
||||
/// <returns>Cache entry</returns>
|
||||
private CacheEntryFromBuffer GetOrAddEntry(
|
||||
TexturePool texturePool,
|
||||
SamplerPool samplerPool,
|
||||
TextureBindingInfo bindingInfo,
|
||||
bool isImage,
|
||||
ref BufferBounds textureBufferBounds,
|
||||
out bool isNew)
|
||||
{
|
||||
CacheEntryFromBufferKey key = new CacheEntryFromBufferKey(
|
||||
isImage,
|
||||
bindingInfo,
|
||||
texturePool,
|
||||
samplerPool,
|
||||
ref textureBufferBounds);
|
||||
|
||||
isNew = !_cacheFromBuffer.TryGetValue(key, out CacheEntryFromBuffer entry);
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
int arrayLength = bindingInfo.ArrayLength;
|
||||
|
||||
if (isImage)
|
||||
{
|
||||
IImageArray array = _context.Renderer.CreateImageArray(arrayLength, bindingInfo.Target == Target.TextureBuffer);
|
||||
|
||||
_cacheFromBuffer.Add(key, entry = new CacheEntryFromBuffer(ref key, array, texturePool, samplerPool));
|
||||
}
|
||||
else
|
||||
{
|
||||
ITextureArray array = _context.Renderer.CreateTextureArray(arrayLength, bindingInfo.Target == Target.TextureBuffer);
|
||||
|
||||
_cacheFromBuffer.Add(key, entry = new CacheEntryFromBuffer(ref key, array, texturePool, samplerPool));
|
||||
}
|
||||
}
|
||||
|
||||
@ -716,15 +1069,52 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// </summary>
|
||||
private void RemoveLeastUsedEntries()
|
||||
{
|
||||
LinkedListNode<CacheEntry> nextNode = _lruCache.First;
|
||||
LinkedListNode<CacheEntryFromBuffer> nextNode = _lruCache.First;
|
||||
|
||||
while (nextNode != null && _currentTimestamp - nextNode.Value.CacheTimestamp >= MinDeltaForRemoval)
|
||||
{
|
||||
LinkedListNode<CacheEntry> toRemove = nextNode;
|
||||
LinkedListNode<CacheEntryFromBuffer> toRemove = nextNode;
|
||||
nextNode = nextNode.Next;
|
||||
_cache.Remove(toRemove.Value.Key);
|
||||
_cacheFromBuffer.Remove(toRemove.Value.Key);
|
||||
_lruCache.Remove(toRemove);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all cached texture arrays matching the specified texture pool.
|
||||
/// </summary>
|
||||
/// <param name="pool">Texture pool</param>
|
||||
public void RemoveAllWithPool<T>(IPool<T> pool)
|
||||
{
|
||||
List<CacheEntryFromPoolKey> keysToRemove = null;
|
||||
|
||||
foreach (CacheEntryFromPoolKey key in _cacheFromPool.Keys)
|
||||
{
|
||||
if (key.MatchesPool(pool))
|
||||
{
|
||||
(keysToRemove ??= new()).Add(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (keysToRemove != null)
|
||||
{
|
||||
foreach (CacheEntryFromPoolKey key in keysToRemove)
|
||||
{
|
||||
_cacheFromPool.Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a handle indicates the binding should have all its textures sourced directly from a pool.
|
||||
/// </summary>
|
||||
/// <param name="handle">Handle to check</param>
|
||||
/// <returns>True if the handle represents direct pool access, false otherwise</returns>
|
||||
private static bool IsDirectHandleType(int handle)
|
||||
{
|
||||
(_, _, TextureHandleType type) = TextureHandle.UnpackOffsets(handle);
|
||||
|
||||
return type == TextureHandleType.Direct;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
private readonly TexturePoolCache _texturePoolCache;
|
||||
private readonly SamplerPoolCache _samplerPoolCache;
|
||||
|
||||
private readonly TextureBindingsArrayCache _arrayBindingsCache;
|
||||
private readonly TextureBindingsArrayCache _bindingsArrayCache;
|
||||
|
||||
private TexturePool _cachedTexturePool;
|
||||
private SamplerPool _cachedSamplerPool;
|
||||
@ -72,12 +72,14 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// </summary>
|
||||
/// <param name="context">The GPU context that the texture bindings manager belongs to</param>
|
||||
/// <param name="channel">The GPU channel that the texture bindings manager belongs to</param>
|
||||
/// <param name="bindingsArrayCache">Cache of texture array bindings</param>
|
||||
/// <param name="texturePoolCache">Texture pools cache used to get texture pools from</param>
|
||||
/// <param name="samplerPoolCache">Sampler pools cache used to get sampler pools from</param>
|
||||
/// <param name="isCompute">True if the bindings manager is used for the compute engine</param>
|
||||
public TextureBindingsManager(
|
||||
GpuContext context,
|
||||
GpuChannel channel,
|
||||
TextureBindingsArrayCache bindingsArrayCache,
|
||||
TexturePoolCache texturePoolCache,
|
||||
SamplerPoolCache samplerPoolCache,
|
||||
bool isCompute)
|
||||
@ -89,7 +91,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
_isCompute = isCompute;
|
||||
|
||||
_arrayBindingsCache = new TextureBindingsArrayCache(context, channel, isCompute);
|
||||
_bindingsArrayCache = bindingsArrayCache;
|
||||
|
||||
int stages = isCompute ? 1 : Constants.ShaderStages;
|
||||
|
||||
@ -456,7 +458,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
if (bindingInfo.ArrayLength > 1)
|
||||
{
|
||||
_arrayBindingsCache.UpdateTextureArray(texturePool, samplerPool, stage, stageIndex, _textureBufferIndex, _samplerIndex, bindingInfo);
|
||||
_bindingsArrayCache.UpdateTextureArray(texturePool, samplerPool, stage, stageIndex, _textureBufferIndex, _samplerIndex, bindingInfo);
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -594,7 +596,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
if (bindingInfo.ArrayLength > 1)
|
||||
{
|
||||
_arrayBindingsCache.UpdateImageArray(pool, stage, stageIndex, _textureBufferIndex, bindingInfo);
|
||||
_bindingsArrayCache.UpdateImageArray(pool, stage, stageIndex, _textureBufferIndex, bindingInfo);
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -732,7 +734,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
ulong poolAddress = _channel.MemoryManager.Translate(poolGpuVa);
|
||||
|
||||
TexturePool texturePool = _texturePoolCache.FindOrCreate(_channel, poolAddress, maximumId);
|
||||
TexturePool texturePool = _texturePoolCache.FindOrCreate(_channel, poolAddress, maximumId, _bindingsArrayCache);
|
||||
|
||||
TextureDescriptor descriptor;
|
||||
|
||||
@ -828,7 +830,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
if (poolAddress != MemoryManager.PteUnmapped)
|
||||
{
|
||||
texturePool = _texturePoolCache.FindOrCreate(_channel, poolAddress, _texturePoolMaximumId);
|
||||
texturePool = _texturePoolCache.FindOrCreate(_channel, poolAddress, _texturePoolMaximumId, _bindingsArrayCache);
|
||||
_texturePool = texturePool;
|
||||
}
|
||||
}
|
||||
@ -839,7 +841,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
if (poolAddress != MemoryManager.PteUnmapped)
|
||||
{
|
||||
samplerPool = _samplerPoolCache.FindOrCreate(_channel, poolAddress, _samplerPoolMaximumId);
|
||||
samplerPool = _samplerPoolCache.FindOrCreate(_channel, poolAddress, _samplerPoolMaximumId, _bindingsArrayCache);
|
||||
_samplerPool = samplerPool;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ using Ryujinx.Graphics.Texture;
|
||||
using Ryujinx.Memory.Range;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.Graphics.Gpu.Image
|
||||
{
|
||||
@ -39,6 +40,8 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
private readonly MultiRangeList<Texture> _textures;
|
||||
private readonly HashSet<Texture> _partiallyMappedTextures;
|
||||
|
||||
private readonly ReaderWriterLockSlim _texturesLock;
|
||||
|
||||
private Texture[] _textureOverlaps;
|
||||
private OverlapInfo[] _overlapInfo;
|
||||
|
||||
@ -57,6 +60,8 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
_textures = new MultiRangeList<Texture>();
|
||||
_partiallyMappedTextures = new HashSet<Texture>();
|
||||
|
||||
_texturesLock = new ReaderWriterLockSlim();
|
||||
|
||||
_textureOverlaps = new Texture[OverlapsBufferInitialCapacity];
|
||||
_overlapInfo = new OverlapInfo[OverlapsBufferInitialCapacity];
|
||||
|
||||
@ -75,10 +80,16 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
MultiRange unmapped = ((MemoryManager)sender).GetPhysicalRegions(e.Address, e.Size);
|
||||
|
||||
lock (_textures)
|
||||
_texturesLock.EnterReadLock();
|
||||
|
||||
try
|
||||
{
|
||||
overlapCount = _textures.FindOverlaps(unmapped, ref overlaps);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_texturesLock.ExitReadLock();
|
||||
}
|
||||
|
||||
if (overlapCount > 0)
|
||||
{
|
||||
@ -217,7 +228,18 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
public bool UpdateMapping(Texture texture, MultiRange range)
|
||||
{
|
||||
// There cannot be an existing texture compatible with this mapping in the texture cache already.
|
||||
int overlapCount = _textures.FindOverlaps(range, ref _textureOverlaps);
|
||||
int overlapCount;
|
||||
|
||||
_texturesLock.EnterReadLock();
|
||||
|
||||
try
|
||||
{
|
||||
overlapCount = _textures.FindOverlaps(range, ref _textureOverlaps);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_texturesLock.ExitReadLock();
|
||||
}
|
||||
|
||||
for (int i = 0; i < overlapCount; i++)
|
||||
{
|
||||
@ -231,11 +253,20 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
}
|
||||
}
|
||||
|
||||
_textures.Remove(texture);
|
||||
_texturesLock.EnterWriteLock();
|
||||
|
||||
texture.ReplaceRange(range);
|
||||
try
|
||||
{
|
||||
_textures.Remove(texture);
|
||||
|
||||
_textures.Add(texture);
|
||||
texture.ReplaceRange(range);
|
||||
|
||||
_textures.Add(texture);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_texturesLock.ExitWriteLock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -611,11 +642,17 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
int sameAddressOverlapsCount;
|
||||
|
||||
lock (_textures)
|
||||
_texturesLock.EnterReadLock();
|
||||
|
||||
try
|
||||
{
|
||||
// Try to find a perfect texture match, with the same address and parameters.
|
||||
sameAddressOverlapsCount = _textures.FindOverlaps(address, ref _textureOverlaps);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_texturesLock.ExitReadLock();
|
||||
}
|
||||
|
||||
Texture texture = null;
|
||||
|
||||
@ -698,10 +735,16 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
if (info.Target != Target.TextureBuffer)
|
||||
{
|
||||
lock (_textures)
|
||||
_texturesLock.EnterReadLock();
|
||||
|
||||
try
|
||||
{
|
||||
overlapsCount = _textures.FindOverlaps(range.Value, ref _textureOverlaps);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_texturesLock.ExitReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
if (_overlapInfo.Length != _textureOverlaps.Length)
|
||||
@ -1025,10 +1068,16 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
_cache.Add(texture);
|
||||
}
|
||||
|
||||
lock (_textures)
|
||||
_texturesLock.EnterWriteLock();
|
||||
|
||||
try
|
||||
{
|
||||
_textures.Add(texture);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_texturesLock.ExitWriteLock();
|
||||
}
|
||||
|
||||
if (partiallyMapped)
|
||||
{
|
||||
@ -1091,7 +1140,19 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
return null;
|
||||
}
|
||||
|
||||
int addressMatches = _textures.FindOverlaps(address, ref _textureOverlaps);
|
||||
int addressMatches;
|
||||
|
||||
_texturesLock.EnterReadLock();
|
||||
|
||||
try
|
||||
{
|
||||
addressMatches = _textures.FindOverlaps(address, ref _textureOverlaps);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_texturesLock.ExitReadLock();
|
||||
}
|
||||
|
||||
Texture textureMatch = null;
|
||||
|
||||
for (int i = 0; i < addressMatches; i++)
|
||||
@ -1232,10 +1293,16 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// <param name="texture">The texture to be removed</param>
|
||||
public void RemoveTextureFromCache(Texture texture)
|
||||
{
|
||||
lock (_textures)
|
||||
_texturesLock.EnterWriteLock();
|
||||
|
||||
try
|
||||
{
|
||||
_textures.Remove(texture);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_texturesLock.ExitWriteLock();
|
||||
}
|
||||
|
||||
lock (_partiallyMappedTextures)
|
||||
{
|
||||
@ -1324,13 +1391,19 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
lock (_textures)
|
||||
_texturesLock.EnterReadLock();
|
||||
|
||||
try
|
||||
{
|
||||
foreach (Texture texture in _textures)
|
||||
{
|
||||
texture.Dispose();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_texturesLock.ExitReadLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,9 +88,9 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
private MultiRange TextureRange => Storage.Range;
|
||||
|
||||
/// <summary>
|
||||
/// The views list from the storage texture.
|
||||
/// The views array from the storage texture.
|
||||
/// </summary>
|
||||
private List<Texture> _views;
|
||||
private Texture[] _views;
|
||||
private TextureGroupHandle[] _handles;
|
||||
private bool[] _loadNeeded;
|
||||
|
||||
@ -1074,7 +1074,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
public void UpdateViews(List<Texture> views, Texture texture)
|
||||
{
|
||||
// This is saved to calculate overlapping views for each handle.
|
||||
_views = views;
|
||||
_views = views.ToArray();
|
||||
|
||||
bool layerViews = _hasLayerViews;
|
||||
bool mipViews = _hasMipViews;
|
||||
@ -1136,9 +1136,13 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// <summary>
|
||||
/// Removes a view from the group, removing it from all overlap lists.
|
||||
/// </summary>
|
||||
/// <param name="views">The views list of the storage texture</param>
|
||||
/// <param name="view">View to remove from the group</param>
|
||||
public void RemoveView(Texture view)
|
||||
public void RemoveView(List<Texture> views, Texture view)
|
||||
{
|
||||
// This is saved to calculate overlapping views for each handle.
|
||||
_views = views.ToArray();
|
||||
|
||||
int offset = FindOffset(view);
|
||||
|
||||
foreach (TextureGroupHandle handle in _handles)
|
||||
@ -1605,9 +1609,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
Storage.SignalModifiedDirty();
|
||||
|
||||
if (_views != null)
|
||||
Texture[] views = _views;
|
||||
|
||||
if (views != null)
|
||||
{
|
||||
foreach (Texture texture in _views)
|
||||
foreach (Texture texture in views)
|
||||
{
|
||||
texture.SignalModifiedDirty();
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
public TextureGroupHandle(TextureGroup group,
|
||||
int offset,
|
||||
ulong size,
|
||||
List<Texture> views,
|
||||
IEnumerable<Texture> views,
|
||||
int firstLayer,
|
||||
int firstLevel,
|
||||
int baseSlice,
|
||||
@ -201,8 +201,8 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// Calculate a list of which views overlap this handle.
|
||||
/// </summary>
|
||||
/// <param name="group">The parent texture group, used to find a view's base CPU VA offset</param>
|
||||
/// <param name="views">The list of views to search for overlaps</param>
|
||||
public void RecalculateOverlaps(TextureGroup group, List<Texture> views)
|
||||
/// <param name="views">The views to search for overlaps</param>
|
||||
public void RecalculateOverlaps(TextureGroup group, IEnumerable<Texture> views)
|
||||
{
|
||||
// Overlaps can be accessed from the memory tracking signal handler, so access must be atomic.
|
||||
lock (Overlaps)
|
||||
|
@ -15,6 +15,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
|
||||
private readonly TextureBindingsManager _cpBindingsManager;
|
||||
private readonly TextureBindingsManager _gpBindingsManager;
|
||||
private readonly TextureBindingsArrayCache _bindingsArrayCache;
|
||||
private readonly TexturePoolCache _texturePoolCache;
|
||||
private readonly SamplerPoolCache _samplerPoolCache;
|
||||
|
||||
@ -46,8 +47,9 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
TexturePoolCache texturePoolCache = new(context);
|
||||
SamplerPoolCache samplerPoolCache = new(context);
|
||||
|
||||
_cpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, samplerPoolCache, isCompute: true);
|
||||
_gpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, samplerPoolCache, isCompute: false);
|
||||
_bindingsArrayCache = new TextureBindingsArrayCache(context, channel);
|
||||
_cpBindingsManager = new TextureBindingsManager(context, channel, _bindingsArrayCache, texturePoolCache, samplerPoolCache, isCompute: true);
|
||||
_gpBindingsManager = new TextureBindingsManager(context, channel, _bindingsArrayCache, texturePoolCache, samplerPoolCache, isCompute: false);
|
||||
_texturePoolCache = texturePoolCache;
|
||||
_samplerPoolCache = samplerPoolCache;
|
||||
|
||||
@ -384,7 +386,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
{
|
||||
ulong poolAddress = _channel.MemoryManager.Translate(poolGpuVa);
|
||||
|
||||
TexturePool texturePool = _texturePoolCache.FindOrCreate(_channel, poolAddress, maximumId);
|
||||
TexturePool texturePool = _texturePoolCache.FindOrCreate(_channel, poolAddress, maximumId, _bindingsArrayCache);
|
||||
|
||||
return texturePool;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
|
||||
TextureBindings[i] = stage.Info.Textures.Select(descriptor =>
|
||||
{
|
||||
Target target = ShaderTexture.GetTarget(descriptor.Type);
|
||||
Target target = descriptor.Type != SamplerType.None ? ShaderTexture.GetTarget(descriptor.Type) : default;
|
||||
|
||||
var result = new TextureBindingInfo(
|
||||
target,
|
||||
@ -66,7 +66,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
descriptor.ArrayLength,
|
||||
descriptor.CbufSlot,
|
||||
descriptor.HandleIndex,
|
||||
descriptor.Flags);
|
||||
descriptor.Flags,
|
||||
descriptor.Type == SamplerType.None);
|
||||
|
||||
if (descriptor.ArrayLength <= 1)
|
||||
{
|
||||
|
@ -141,7 +141,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
|
||||
if (algorithm == CompressionAlgorithm.Deflate)
|
||||
{
|
||||
_activeStream = new DeflateStream(_stream, CompressionLevel.SmallestSize, true);
|
||||
_activeStream = new DeflateStream(_stream, CompressionLevel.Fastest, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
stream.Write(data);
|
||||
break;
|
||||
case CompressionAlgorithm.Deflate:
|
||||
stream = new DeflateStream(stream, CompressionLevel.SmallestSize, true);
|
||||
stream = new DeflateStream(stream, CompressionLevel.Fastest, true);
|
||||
stream.Write(data);
|
||||
stream.Dispose();
|
||||
break;
|
||||
|
@ -18,6 +18,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
private readonly ShaderSpecializationState _newSpecState;
|
||||
private readonly int _stageIndex;
|
||||
private readonly bool _isVulkan;
|
||||
private readonly bool _hasGeometryShader;
|
||||
private readonly bool _supportsQuads;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the cached GPU state accessor for shader translation.
|
||||
@ -29,6 +31,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
/// <param name="newSpecState">Shader specialization state of the recompiled shader</param>
|
||||
/// <param name="counts">Resource counts shared across all shader stages</param>
|
||||
/// <param name="stageIndex">Shader stage index</param>
|
||||
/// <param name="hasGeometryShader">Indicates if a geometry shader is present</param>
|
||||
public DiskCacheGpuAccessor(
|
||||
GpuContext context,
|
||||
ReadOnlyMemory<byte> data,
|
||||
@ -36,7 +39,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
ShaderSpecializationState oldSpecState,
|
||||
ShaderSpecializationState newSpecState,
|
||||
ResourceCounts counts,
|
||||
int stageIndex) : base(context, counts, stageIndex)
|
||||
int stageIndex,
|
||||
bool hasGeometryShader) : base(context, counts, stageIndex)
|
||||
{
|
||||
_data = data;
|
||||
_cb1Data = cb1Data;
|
||||
@ -44,6 +48,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
_newSpecState = newSpecState;
|
||||
_stageIndex = stageIndex;
|
||||
_isVulkan = context.Capabilities.Api == TargetApi.Vulkan;
|
||||
_hasGeometryShader = hasGeometryShader;
|
||||
_supportsQuads = context.Capabilities.SupportsQuads;
|
||||
|
||||
if (stageIndex == (int)ShaderStage.Geometry - 1)
|
||||
{
|
||||
@ -100,7 +106,11 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
/// <inheritdoc/>
|
||||
public GpuGraphicsState QueryGraphicsState()
|
||||
{
|
||||
return _oldSpecState.GraphicsState.CreateShaderGraphicsState(!_isVulkan, _isVulkan || _oldSpecState.GraphicsState.YNegateEnabled);
|
||||
return _oldSpecState.GraphicsState.CreateShaderGraphicsState(
|
||||
!_isVulkan,
|
||||
_supportsQuads,
|
||||
_hasGeometryShader,
|
||||
_isVulkan || _oldSpecState.GraphicsState.YNegateEnabled);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@ -109,6 +119,13 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
return _oldSpecState.GraphicsState.HasConstantBufferDrawParameters;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <exception cref="DiskCacheLoadException">Pool length is not available on the cache</exception>
|
||||
public int QuerySamplerArrayLengthFromPool()
|
||||
{
|
||||
return QueryArrayLengthFromPool(isSampler: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SamplerType QuerySamplerType(int handle, int cbufSlot)
|
||||
{
|
||||
@ -117,6 +134,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <exception cref="DiskCacheLoadException">Constant buffer derived length is not available on the cache</exception>
|
||||
public int QueryTextureArrayLengthFromBuffer(int slot)
|
||||
{
|
||||
if (!_oldSpecState.TextureArrayFromBufferRegistered(_stageIndex, 0, slot))
|
||||
@ -130,6 +148,13 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
return arrayLength;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <exception cref="DiskCacheLoadException">Pool length is not available on the cache</exception>
|
||||
public int QueryTextureArrayLengthFromPool()
|
||||
{
|
||||
return QueryArrayLengthFromPool(isSampler: false);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public TextureFormat QueryTextureFormat(int handle, int cbufSlot)
|
||||
{
|
||||
@ -170,6 +195,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <exception cref="DiskCacheLoadException">Texture information is not available on the cache</exception>
|
||||
public void RegisterTexture(int handle, int cbufSlot)
|
||||
{
|
||||
if (!_oldSpecState.TextureRegistered(_stageIndex, handle, cbufSlot))
|
||||
@ -182,5 +208,24 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
bool coordNormalized = _oldSpecState.GetCoordNormalized(_stageIndex, handle, cbufSlot);
|
||||
_newSpecState.RegisterTexture(_stageIndex, handle, cbufSlot, format, formatSrgb, target, coordNormalized);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cached texture or sampler pool capacity.
|
||||
/// </summary>
|
||||
/// <param name="isSampler">True to get sampler pool length, false for texture pool length</param>
|
||||
/// <returns>Pool length</returns>
|
||||
/// <exception cref="DiskCacheLoadException">Pool length is not available on the cache</exception>
|
||||
private int QueryArrayLengthFromPool(bool isSampler)
|
||||
{
|
||||
if (!_oldSpecState.TextureArrayFromPoolRegistered(isSampler))
|
||||
{
|
||||
throw new DiskCacheLoadException(DiskCacheLoadResult.MissingTextureArrayLength);
|
||||
}
|
||||
|
||||
int arrayLength = _oldSpecState.GetTextureArrayFromPoolLength(isSampler);
|
||||
_newSpecState.RegisterTextureArrayLengthFromPool(isSampler, arrayLength);
|
||||
|
||||
return arrayLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
private const ushort FileFormatVersionMajor = 1;
|
||||
private const ushort FileFormatVersionMinor = 2;
|
||||
private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
|
||||
private const uint CodeGenVersion = 6489;
|
||||
private const uint CodeGenVersion = 5936;
|
||||
|
||||
private const string SharedTocFileName = "shared.toc";
|
||||
private const string SharedDataFileName = "shared.data";
|
||||
|
@ -601,6 +601,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
|
||||
TargetApi api = _context.Capabilities.Api;
|
||||
|
||||
bool hasCachedGs = guestShaders[4].HasValue;
|
||||
|
||||
for (int stageIndex = Constants.ShaderStages - 1; stageIndex >= 0; stageIndex--)
|
||||
{
|
||||
if (guestShaders[stageIndex + 1].HasValue)
|
||||
@ -610,7 +612,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
byte[] guestCode = shader.Code;
|
||||
byte[] cb1Data = shader.Cb1Data;
|
||||
|
||||
DiskCacheGpuAccessor gpuAccessor = new(_context, guestCode, cb1Data, specState, newSpecState, counts, stageIndex);
|
||||
DiskCacheGpuAccessor gpuAccessor = new(_context, guestCode, cb1Data, specState, newSpecState, counts, stageIndex, hasCachedGs);
|
||||
TranslatorContext currentStage = DecodeGraphicsShader(gpuAccessor, api, DefaultFlags, 0);
|
||||
|
||||
if (nextStage != null)
|
||||
@ -623,7 +625,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
byte[] guestCodeA = guestShaders[0].Value.Code;
|
||||
byte[] cb1DataA = guestShaders[0].Value.Cb1Data;
|
||||
|
||||
DiskCacheGpuAccessor gpuAccessorA = new(_context, guestCodeA, cb1DataA, specState, newSpecState, counts, 0);
|
||||
DiskCacheGpuAccessor gpuAccessorA = new(_context, guestCodeA, cb1DataA, specState, newSpecState, counts, 0, hasCachedGs);
|
||||
translatorContexts[0] = DecodeGraphicsShader(gpuAccessorA, api, DefaultFlags | TranslationFlags.VertexA, 0);
|
||||
}
|
||||
|
||||
@ -711,7 +713,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
GuestCodeAndCbData shader = guestShaders[0].Value;
|
||||
ResourceCounts counts = new();
|
||||
ShaderSpecializationState newSpecState = new(ref specState.ComputeState);
|
||||
DiskCacheGpuAccessor gpuAccessor = new(_context, shader.Code, shader.Cb1Data, specState, newSpecState, counts, 0);
|
||||
DiskCacheGpuAccessor gpuAccessor = new(_context, shader.Code, shader.Cb1Data, specState, newSpecState, counts, 0, false);
|
||||
gpuAccessor.InitializeReservedCounts(tfEnabled: false, vertexAsCompute: false);
|
||||
|
||||
TranslatorContext translatorContext = DecodeComputeShader(gpuAccessor, _context.Capabilities.Api, 0);
|
||||
|
@ -17,6 +17,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
private readonly int _stageIndex;
|
||||
private readonly bool _compute;
|
||||
private readonly bool _isVulkan;
|
||||
private readonly bool _hasGeometryShader;
|
||||
private readonly bool _supportsQuads;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the GPU state accessor for graphics shader translation.
|
||||
@ -25,12 +27,20 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// <param name="channel">GPU channel</param>
|
||||
/// <param name="state">Current GPU state</param>
|
||||
/// <param name="stageIndex">Graphics shader stage index (0 = Vertex, 4 = Fragment)</param>
|
||||
public GpuAccessor(GpuContext context, GpuChannel channel, GpuAccessorState state, int stageIndex) : base(context, state.ResourceCounts, stageIndex)
|
||||
/// <param name="hasGeometryShader">Indicates if a geometry shader is present</param>
|
||||
public GpuAccessor(
|
||||
GpuContext context,
|
||||
GpuChannel channel,
|
||||
GpuAccessorState state,
|
||||
int stageIndex,
|
||||
bool hasGeometryShader) : base(context, state.ResourceCounts, stageIndex)
|
||||
{
|
||||
_isVulkan = context.Capabilities.Api == TargetApi.Vulkan;
|
||||
_channel = channel;
|
||||
_state = state;
|
||||
_stageIndex = stageIndex;
|
||||
_isVulkan = context.Capabilities.Api == TargetApi.Vulkan;
|
||||
_hasGeometryShader = hasGeometryShader;
|
||||
_supportsQuads = context.Capabilities.SupportsQuads;
|
||||
|
||||
if (stageIndex == (int)ShaderStage.Geometry - 1)
|
||||
{
|
||||
@ -105,7 +115,11 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// <inheritdoc/>
|
||||
public GpuGraphicsState QueryGraphicsState()
|
||||
{
|
||||
return _state.GraphicsState.CreateShaderGraphicsState(!_isVulkan, _isVulkan || _state.GraphicsState.YNegateEnabled);
|
||||
return _state.GraphicsState.CreateShaderGraphicsState(
|
||||
!_isVulkan,
|
||||
_supportsQuads,
|
||||
_hasGeometryShader,
|
||||
_isVulkan || _state.GraphicsState.YNegateEnabled);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@ -120,6 +134,15 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
return _state.GraphicsState.HasUnalignedStorageBuffer || _state.ComputeState.HasUnalignedStorageBuffer;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int QuerySamplerArrayLengthFromPool()
|
||||
{
|
||||
int length = _state.SamplerPoolMaximumId + 1;
|
||||
_state.SpecializationState?.RegisterTextureArrayLengthFromPool(isSampler: true, length);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SamplerType QuerySamplerType(int handle, int cbufSlot)
|
||||
{
|
||||
@ -141,6 +164,15 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
return arrayLength;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int QueryTextureArrayLengthFromPool()
|
||||
{
|
||||
int length = _state.PoolState.TexturePoolMaximumId + 1;
|
||||
_state.SpecializationState?.RegisterTextureArrayLengthFromPool(isSampler: false, length);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
//// <inheritdoc/>
|
||||
public TextureFormat QueryTextureFormat(int handle, int cbufSlot)
|
||||
{
|
||||
|
@ -213,6 +213,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
|
||||
public bool QueryHostSupportsScaledVertexFormats() => _context.Capabilities.SupportsScaledVertexFormats;
|
||||
|
||||
public bool QueryHostSupportsSeparateSampler() => _context.Capabilities.SupportsSeparateSampler;
|
||||
|
||||
public bool QueryHostSupportsShaderBallot() => _context.Capabilities.SupportsShaderBallot;
|
||||
|
||||
public bool QueryHostSupportsShaderBarrierDivergence() => _context.Capabilities.SupportsShaderBarrierDivergence;
|
||||
|
@ -5,6 +5,11 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// </summary>
|
||||
class GpuAccessorState
|
||||
{
|
||||
/// <summary>
|
||||
/// Maximum ID that a sampler pool entry may have.
|
||||
/// </summary>
|
||||
public readonly int SamplerPoolMaximumId;
|
||||
|
||||
/// <summary>
|
||||
/// GPU texture pool state.
|
||||
/// </summary>
|
||||
@ -38,18 +43,21 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// <summary>
|
||||
/// Creates a new GPU accessor state.
|
||||
/// </summary>
|
||||
/// <param name="samplerPoolMaximumId">Maximum ID that a sampler pool entry may have</param>
|
||||
/// <param name="poolState">GPU texture pool state</param>
|
||||
/// <param name="computeState">GPU compute state, for compute shaders</param>
|
||||
/// <param name="graphicsState">GPU graphics state, for vertex, tessellation, geometry and fragment shaders</param>
|
||||
/// <param name="specializationState">Shader specialization state (shared by all stages)</param>
|
||||
/// <param name="transformFeedbackDescriptors">Transform feedback information, if the shader uses transform feedback. Otherwise, should be null</param>
|
||||
public GpuAccessorState(
|
||||
int samplerPoolMaximumId,
|
||||
GpuChannelPoolState poolState,
|
||||
GpuChannelComputeState computeState,
|
||||
GpuChannelGraphicsState graphicsState,
|
||||
ShaderSpecializationState specializationState,
|
||||
TransformFeedbackDescriptor[] transformFeedbackDescriptors = null)
|
||||
{
|
||||
SamplerPoolMaximumId = samplerPoolMaximumId;
|
||||
PoolState = poolState;
|
||||
GraphicsState = graphicsState;
|
||||
ComputeState = computeState;
|
||||
|
@ -106,8 +106,11 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// Creates a new graphics state from this state that can be used for shader generation.
|
||||
/// </summary>
|
||||
/// <param name="hostSupportsAlphaTest">Indicates if the host API supports alpha test operations</param>
|
||||
/// <param name="hostSupportsQuads">Indicates if the host API supports quad primitives</param>
|
||||
/// <param name="hasGeometryShader">Indicates if a geometry shader is used</param>
|
||||
/// <param name="originUpperLeft">If true, indicates that the fragment origin is the upper left corner of the viewport, otherwise it is the lower left corner</param>
|
||||
/// <returns>GPU graphics state that can be used for shader translation</returns>
|
||||
public readonly GpuGraphicsState CreateShaderGraphicsState(bool hostSupportsAlphaTest, bool originUpperLeft)
|
||||
public readonly GpuGraphicsState CreateShaderGraphicsState(bool hostSupportsAlphaTest, bool hostSupportsQuads, bool hasGeometryShader, bool originUpperLeft)
|
||||
{
|
||||
AlphaTestOp alphaTestOp;
|
||||
|
||||
@ -130,6 +133,9 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
};
|
||||
}
|
||||
|
||||
bool isQuad = Topology == PrimitiveTopology.Quads || Topology == PrimitiveTopology.QuadStrip;
|
||||
bool halvePrimitiveId = !hostSupportsQuads && !hasGeometryShader && isQuad;
|
||||
|
||||
return new GpuGraphicsState(
|
||||
EarlyZForce,
|
||||
ConvertToInputTopology(Topology, TessellationMode),
|
||||
@ -149,7 +155,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
in FragmentOutputTypes,
|
||||
DualSourceBlendEnable,
|
||||
YNegateEnabled,
|
||||
originUpperLeft);
|
||||
originUpperLeft,
|
||||
halvePrimitiveId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -2,7 +2,6 @@ using System;
|
||||
|
||||
namespace Ryujinx.Graphics.Gpu.Shader
|
||||
{
|
||||
#pragma warning disable CS0659 // Class overrides Object.Equals(object o) but does not override Object.GetHashCode()
|
||||
/// <summary>
|
||||
/// State used by the <see cref="GpuAccessor"/>.
|
||||
/// </summary>
|
||||
@ -52,6 +51,10 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
{
|
||||
return obj is GpuChannelPoolState state && Equals(state);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(TexturePoolGpuVa, TexturePoolMaximumId, TextureBufferIndex);
|
||||
}
|
||||
}
|
||||
#pragma warning restore CS0659
|
||||
}
|
||||
|
@ -192,12 +192,14 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// This automatically translates, compiles and adds the code to the cache if not present.
|
||||
/// </remarks>
|
||||
/// <param name="channel">GPU channel</param>
|
||||
/// <param name="samplerPoolMaximumId">Maximum ID that an entry in the sampler pool may have</param>
|
||||
/// <param name="poolState">Texture pool state</param>
|
||||
/// <param name="computeState">Compute engine state</param>
|
||||
/// <param name="gpuVa">GPU virtual address of the binary shader code</param>
|
||||
/// <returns>Compiled compute shader code</returns>
|
||||
public CachedShaderProgram GetComputeShader(
|
||||
GpuChannel channel,
|
||||
int samplerPoolMaximumId,
|
||||
GpuChannelPoolState poolState,
|
||||
GpuChannelComputeState computeState,
|
||||
ulong gpuVa)
|
||||
@ -214,7 +216,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
}
|
||||
|
||||
ShaderSpecializationState specState = new(ref computeState);
|
||||
GpuAccessorState gpuAccessorState = new(poolState, computeState, default, specState);
|
||||
GpuAccessorState gpuAccessorState = new(samplerPoolMaximumId, poolState, computeState, default, specState);
|
||||
GpuAccessor gpuAccessor = new(_context, channel, gpuAccessorState);
|
||||
gpuAccessor.InitializeReservedCounts(tfEnabled: false, vertexAsCompute: false);
|
||||
|
||||
@ -291,6 +293,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// <param name="state">GPU state</param>
|
||||
/// <param name="pipeline">Pipeline state</param>
|
||||
/// <param name="channel">GPU channel</param>
|
||||
/// <param name="samplerPoolMaximumId">Maximum ID that an entry in the sampler pool may have</param>
|
||||
/// <param name="poolState">Texture pool state</param>
|
||||
/// <param name="graphicsState">3D engine state</param>
|
||||
/// <param name="addresses">Addresses of the shaders for each stage</param>
|
||||
@ -299,6 +302,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
ref ThreedClassState state,
|
||||
ref ProgramPipelineState pipeline,
|
||||
GpuChannel channel,
|
||||
int samplerPoolMaximumId,
|
||||
ref GpuChannelPoolState poolState,
|
||||
ref GpuChannelGraphicsState graphicsState,
|
||||
ShaderAddresses addresses)
|
||||
@ -319,7 +323,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
UpdatePipelineInfo(ref state, ref pipeline, graphicsState, channel);
|
||||
|
||||
ShaderSpecializationState specState = new(ref graphicsState, ref pipeline, transformFeedbackDescriptors);
|
||||
GpuAccessorState gpuAccessorState = new(poolState, default, graphicsState, specState, transformFeedbackDescriptors);
|
||||
GpuAccessorState gpuAccessorState = new(samplerPoolMaximumId, poolState, default, graphicsState, specState, transformFeedbackDescriptors);
|
||||
|
||||
ReadOnlySpan<ulong> addressesSpan = addresses.AsSpan();
|
||||
|
||||
@ -335,7 +339,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
|
||||
if (gpuVa != 0)
|
||||
{
|
||||
GpuAccessor gpuAccessor = new(_context, channel, gpuAccessorState, stageIndex);
|
||||
GpuAccessor gpuAccessor = new(_context, channel, gpuAccessorState, stageIndex, addresses.Geometry != 0);
|
||||
TranslatorContext currentStage = DecodeGraphicsShader(gpuAccessor, api, DefaultFlags, gpuVa);
|
||||
|
||||
if (nextStage != null)
|
||||
|
@ -185,11 +185,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
{
|
||||
if (texture.ArrayLength > 1)
|
||||
{
|
||||
bool isBuffer = (texture.Type & SamplerType.Mask) == SamplerType.TextureBuffer;
|
||||
|
||||
ResourceType type = isBuffer
|
||||
? (isImage ? ResourceType.BufferImage : ResourceType.BufferTexture)
|
||||
: (isImage ? ResourceType.Image : ResourceType.TextureAndSampler);
|
||||
ResourceType type = GetTextureResourceType(texture, isImage);
|
||||
|
||||
_resourceDescriptors[setIndex].Add(new ResourceDescriptor(texture.Binding, texture.ArrayLength, type, stages));
|
||||
}
|
||||
@ -242,16 +238,38 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
{
|
||||
foreach (TextureDescriptor texture in textures)
|
||||
{
|
||||
bool isBuffer = (texture.Type & SamplerType.Mask) == SamplerType.TextureBuffer;
|
||||
|
||||
ResourceType type = isBuffer
|
||||
? (isImage ? ResourceType.BufferImage : ResourceType.BufferTexture)
|
||||
: (isImage ? ResourceType.Image : ResourceType.TextureAndSampler);
|
||||
ResourceType type = GetTextureResourceType(texture, isImage);
|
||||
|
||||
_resourceUsages[setIndex].Add(new ResourceUsage(texture.Binding, texture.ArrayLength, type, stages));
|
||||
}
|
||||
}
|
||||
|
||||
private static ResourceType GetTextureResourceType(TextureDescriptor texture, bool isImage)
|
||||
{
|
||||
bool isBuffer = (texture.Type & SamplerType.Mask) == SamplerType.TextureBuffer;
|
||||
|
||||
if (isBuffer)
|
||||
{
|
||||
return isImage ? ResourceType.BufferImage : ResourceType.BufferTexture;
|
||||
}
|
||||
else if (isImage)
|
||||
{
|
||||
return ResourceType.Image;
|
||||
}
|
||||
else if (texture.Type == SamplerType.None)
|
||||
{
|
||||
return ResourceType.Sampler;
|
||||
}
|
||||
else if (texture.Separate)
|
||||
{
|
||||
return ResourceType.Texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ResourceType.TextureAndSampler;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new shader information structure from the added information.
|
||||
/// </summary>
|
||||
|
@ -31,6 +31,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
PrimitiveTopology = 1 << 1,
|
||||
TransformFeedback = 1 << 3,
|
||||
TextureArrayFromBuffer = 1 << 4,
|
||||
TextureArrayFromPool = 1 << 5,
|
||||
}
|
||||
|
||||
private QueriedStateFlags _queriedState;
|
||||
@ -154,7 +155,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
}
|
||||
|
||||
private readonly Dictionary<TextureKey, Box<TextureSpecializationState>> _textureSpecialization;
|
||||
private readonly Dictionary<TextureKey, int> _textureArraySpecialization;
|
||||
private readonly Dictionary<TextureKey, int> _textureArrayFromBufferSpecialization;
|
||||
private readonly Dictionary<bool, int> _textureArrayFromPoolSpecialization;
|
||||
private KeyValuePair<TextureKey, Box<TextureSpecializationState>>[] _allTextures;
|
||||
private Box<TextureSpecializationState>[][] _textureByBinding;
|
||||
private Box<TextureSpecializationState>[][] _imageByBinding;
|
||||
@ -165,7 +167,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
private ShaderSpecializationState()
|
||||
{
|
||||
_textureSpecialization = new Dictionary<TextureKey, Box<TextureSpecializationState>>();
|
||||
_textureArraySpecialization = new Dictionary<TextureKey, int>();
|
||||
_textureArrayFromBufferSpecialization = new Dictionary<TextureKey, int>();
|
||||
_textureArrayFromPoolSpecialization = new Dictionary<bool, int>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -327,7 +330,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the coordinate normalization state of a given texture was used during the shader translation process.
|
||||
/// Registers the length of a texture array calculated from a constant buffer size.
|
||||
/// </summary>
|
||||
/// <param name="stageIndex">Shader stage where the texture is used</param>
|
||||
/// <param name="handle">Offset in words of the texture handle on the texture buffer</param>
|
||||
@ -335,10 +338,21 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// <param name="length">Number of elements in the texture array</param>
|
||||
public void RegisterTextureArrayLengthFromBuffer(int stageIndex, int handle, int cbufSlot, int length)
|
||||
{
|
||||
_textureArraySpecialization[new TextureKey(stageIndex, handle, cbufSlot)] = length;
|
||||
_textureArrayFromBufferSpecialization[new TextureKey(stageIndex, handle, cbufSlot)] = length;
|
||||
_queriedState |= QueriedStateFlags.TextureArrayFromBuffer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the length of a texture array calculated from a texture or sampler pool capacity.
|
||||
/// </summary>
|
||||
/// <param name="isSampler">True for sampler pool, false for texture pool</param>
|
||||
/// <param name="length">Number of elements in the texture array</param>
|
||||
public void RegisterTextureArrayLengthFromPool(bool isSampler, int length)
|
||||
{
|
||||
_textureArrayFromPoolSpecialization[isSampler] = length;
|
||||
_queriedState |= QueriedStateFlags.TextureArrayFromPool;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the format of a given texture was used during the shader translation process.
|
||||
/// </summary>
|
||||
@ -385,7 +399,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given texture was registerd on this specialization state.
|
||||
/// Checks if a given texture was registered on this specialization state.
|
||||
/// </summary>
|
||||
/// <param name="stageIndex">Shader stage where the texture is used</param>
|
||||
/// <param name="handle">Offset in words of the texture handle on the texture buffer</param>
|
||||
@ -396,14 +410,25 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given texture array (from constant buffer) was registerd on this specialization state.
|
||||
/// Checks if a given texture array (from constant buffer) was registered on this specialization state.
|
||||
/// </summary>
|
||||
/// <param name="stageIndex">Shader stage where the texture is used</param>
|
||||
/// <param name="handle">Offset in words of the texture handle on the texture buffer</param>
|
||||
/// <param name="cbufSlot">Slot of the texture buffer constant buffer</param>
|
||||
/// <returns>True if the length for the given buffer and stage exists, false otherwise</returns>
|
||||
public bool TextureArrayFromBufferRegistered(int stageIndex, int handle, int cbufSlot)
|
||||
{
|
||||
return _textureArraySpecialization.ContainsKey(new TextureKey(stageIndex, handle, cbufSlot));
|
||||
return _textureArrayFromBufferSpecialization.ContainsKey(new TextureKey(stageIndex, handle, cbufSlot));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given texture array (from a sampler pool or texture pool) was registered on this specialization state.
|
||||
/// </summary>
|
||||
/// <param name="isSampler">True for sampler pool, false for texture pool</param>
|
||||
/// <returns>True if the length for the given pool, false otherwise</returns>
|
||||
public bool TextureArrayFromPoolRegistered(bool isSampler)
|
||||
{
|
||||
return _textureArrayFromPoolSpecialization.ContainsKey(isSampler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -412,6 +437,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// <param name="stageIndex">Shader stage where the texture is used</param>
|
||||
/// <param name="handle">Offset in words of the texture handle on the texture buffer</param>
|
||||
/// <param name="cbufSlot">Slot of the texture buffer constant buffer</param>
|
||||
/// <returns>Format and sRGB tuple</returns>
|
||||
public (uint, bool) GetFormat(int stageIndex, int handle, int cbufSlot)
|
||||
{
|
||||
TextureSpecializationState state = GetTextureSpecState(stageIndex, handle, cbufSlot).Value;
|
||||
@ -424,6 +450,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// <param name="stageIndex">Shader stage where the texture is used</param>
|
||||
/// <param name="handle">Offset in words of the texture handle on the texture buffer</param>
|
||||
/// <param name="cbufSlot">Slot of the texture buffer constant buffer</param>
|
||||
/// <returns>Texture target</returns>
|
||||
public TextureTarget GetTextureTarget(int stageIndex, int handle, int cbufSlot)
|
||||
{
|
||||
return GetTextureSpecState(stageIndex, handle, cbufSlot).Value.TextureTarget;
|
||||
@ -435,6 +462,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// <param name="stageIndex">Shader stage where the texture is used</param>
|
||||
/// <param name="handle">Offset in words of the texture handle on the texture buffer</param>
|
||||
/// <param name="cbufSlot">Slot of the texture buffer constant buffer</param>
|
||||
/// <returns>True if coordinates are normalized, false otherwise</returns>
|
||||
public bool GetCoordNormalized(int stageIndex, int handle, int cbufSlot)
|
||||
{
|
||||
return GetTextureSpecState(stageIndex, handle, cbufSlot).Value.CoordNormalized;
|
||||
@ -446,9 +474,20 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
/// <param name="stageIndex">Shader stage where the texture is used</param>
|
||||
/// <param name="handle">Offset in words of the texture handle on the texture buffer</param>
|
||||
/// <param name="cbufSlot">Slot of the texture buffer constant buffer</param>
|
||||
/// <returns>Texture array length</returns>
|
||||
public int GetTextureArrayFromBufferLength(int stageIndex, int handle, int cbufSlot)
|
||||
{
|
||||
return _textureArraySpecialization[new TextureKey(stageIndex, handle, cbufSlot)];
|
||||
return _textureArrayFromBufferSpecialization[new TextureKey(stageIndex, handle, cbufSlot)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the recorded length of a given texture array (from a sampler or texture pool).
|
||||
/// </summary>
|
||||
/// <param name="isSampler">True to get the sampler pool length, false to get the texture pool length</param>
|
||||
/// <returns>Texture array length</returns>
|
||||
public int GetTextureArrayFromPoolLength(bool isSampler)
|
||||
{
|
||||
return _textureArrayFromPoolSpecialization[isSampler];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -894,7 +933,23 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
dataReader.ReadWithMagicAndSize(ref textureKey, TexkMagic);
|
||||
dataReader.Read(ref length);
|
||||
|
||||
specState._textureArraySpecialization[textureKey] = length;
|
||||
specState._textureArrayFromBufferSpecialization[textureKey] = length;
|
||||
}
|
||||
}
|
||||
|
||||
if (specState._queriedState.HasFlag(QueriedStateFlags.TextureArrayFromPool))
|
||||
{
|
||||
dataReader.Read(ref count);
|
||||
|
||||
for (int index = 0; index < count; index++)
|
||||
{
|
||||
bool textureKey = default;
|
||||
int length = 0;
|
||||
|
||||
dataReader.ReadWithMagicAndSize(ref textureKey, TexkMagic);
|
||||
dataReader.Read(ref length);
|
||||
|
||||
specState._textureArrayFromPoolSpecialization[textureKey] = length;
|
||||
}
|
||||
}
|
||||
|
||||
@ -965,10 +1020,25 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
||||
|
||||
if (_queriedState.HasFlag(QueriedStateFlags.TextureArrayFromBuffer))
|
||||
{
|
||||
count = (ushort)_textureArraySpecialization.Count;
|
||||
count = (ushort)_textureArrayFromBufferSpecialization.Count;
|
||||
dataWriter.Write(ref count);
|
||||
|
||||
foreach (var kv in _textureArraySpecialization)
|
||||
foreach (var kv in _textureArrayFromBufferSpecialization)
|
||||
{
|
||||
var textureKey = kv.Key;
|
||||
var length = kv.Value;
|
||||
|
||||
dataWriter.WriteWithMagicAndSize(ref textureKey, TexkMagic);
|
||||
dataWriter.Write(ref length);
|
||||
}
|
||||
}
|
||||
|
||||
if (_queriedState.HasFlag(QueriedStateFlags.TextureArrayFromPool))
|
||||
{
|
||||
count = (ushort)_textureArrayFromPoolSpecialization.Count;
|
||||
dataWriter.Write(ref count);
|
||||
|
||||
foreach (var kv in _textureArrayFromPoolSpecialization)
|
||||
{
|
||||
var textureKey = kv.Key;
|
||||
var length = kv.Value;
|
||||
|
@ -161,6 +161,7 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
supportsBgraFormat: false,
|
||||
supportsR4G4Format: false,
|
||||
supportsR4G4B4A4Format: true,
|
||||
supportsScaledVertexFormats: true,
|
||||
supportsSnormBufferTextureFormat: false,
|
||||
supports5BitComponentFormat: true,
|
||||
supportsSparseBuffer: false,
|
||||
@ -175,7 +176,8 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
supportsMismatchingViewFormat: HwCapabilities.SupportsMismatchingViewFormat,
|
||||
supportsCubemapView: true,
|
||||
supportsNonConstantTextureOffset: HwCapabilities.SupportsNonConstantTextureOffset,
|
||||
supportsScaledVertexFormats: true,
|
||||
supportsQuads: HwCapabilities.SupportsQuads,
|
||||
supportsSeparateSampler: false,
|
||||
supportsShaderBallot: HwCapabilities.SupportsShaderBallot,
|
||||
supportsShaderBarrierDivergence: !(intelWindows || intelUnix),
|
||||
supportsShaderFloat64: true,
|
||||
|
@ -6,7 +6,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||
{
|
||||
@ -352,7 +351,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||
arrayDecl = "[]";
|
||||
}
|
||||
|
||||
string samplerTypeName = definition.Type.ToGlslSamplerType();
|
||||
string samplerTypeName = definition.Separate ? definition.Type.ToGlslTextureType() : definition.Type.ToGlslSamplerType();
|
||||
|
||||
string layout = string.Empty;
|
||||
|
||||
|
@ -639,14 +639,27 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
||||
|
||||
private static string GetSamplerName(CodeGenContext context, AstTextureOperation texOp, ref int srcIndex)
|
||||
{
|
||||
TextureDefinition definition = context.Properties.Textures[texOp.Binding];
|
||||
string name = definition.Name;
|
||||
TextureDefinition textureDefinition = context.Properties.Textures[texOp.Binding];
|
||||
string name = textureDefinition.Name;
|
||||
|
||||
if (definition.ArrayLength != 1)
|
||||
if (textureDefinition.ArrayLength != 1)
|
||||
{
|
||||
name = $"{name}[{GetSourceExpr(context, texOp.GetSource(srcIndex++), AggregateType.S32)}]";
|
||||
}
|
||||
|
||||
if (texOp.IsSeparate)
|
||||
{
|
||||
TextureDefinition samplerDefinition = context.Properties.Textures[texOp.SamplerBinding];
|
||||
string samplerName = samplerDefinition.Name;
|
||||
|
||||
if (samplerDefinition.ArrayLength != 1)
|
||||
{
|
||||
samplerName = $"{samplerName}[{GetSourceExpr(context, texOp.GetSource(srcIndex++), AggregateType.S32)}]";
|
||||
}
|
||||
|
||||
name = $"{texOp.Type.ToGlslSamplerType()}({name}, {samplerName})";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -160,37 +160,49 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
||||
{
|
||||
int setIndex = context.TargetApi == TargetApi.Vulkan ? sampler.Set : 0;
|
||||
|
||||
var dim = (sampler.Type & SamplerType.Mask) switch
|
||||
SpvInstruction imageType;
|
||||
SpvInstruction sampledImageType;
|
||||
|
||||
if (sampler.Type != SamplerType.None)
|
||||
{
|
||||
SamplerType.Texture1D => Dim.Dim1D,
|
||||
SamplerType.Texture2D => Dim.Dim2D,
|
||||
SamplerType.Texture3D => Dim.Dim3D,
|
||||
SamplerType.TextureCube => Dim.Cube,
|
||||
SamplerType.TextureBuffer => Dim.Buffer,
|
||||
_ => throw new InvalidOperationException($"Invalid sampler type \"{sampler.Type & SamplerType.Mask}\"."),
|
||||
};
|
||||
var dim = (sampler.Type & SamplerType.Mask) switch
|
||||
{
|
||||
SamplerType.Texture1D => Dim.Dim1D,
|
||||
SamplerType.Texture2D => Dim.Dim2D,
|
||||
SamplerType.Texture3D => Dim.Dim3D,
|
||||
SamplerType.TextureCube => Dim.Cube,
|
||||
SamplerType.TextureBuffer => Dim.Buffer,
|
||||
_ => throw new InvalidOperationException($"Invalid sampler type \"{sampler.Type & SamplerType.Mask}\"."),
|
||||
};
|
||||
|
||||
var imageType = context.TypeImage(
|
||||
context.TypeFP32(),
|
||||
dim,
|
||||
sampler.Type.HasFlag(SamplerType.Shadow),
|
||||
sampler.Type.HasFlag(SamplerType.Array),
|
||||
sampler.Type.HasFlag(SamplerType.Multisample),
|
||||
1,
|
||||
ImageFormat.Unknown);
|
||||
imageType = context.TypeImage(
|
||||
context.TypeFP32(),
|
||||
dim,
|
||||
sampler.Type.HasFlag(SamplerType.Shadow),
|
||||
sampler.Type.HasFlag(SamplerType.Array),
|
||||
sampler.Type.HasFlag(SamplerType.Multisample),
|
||||
1,
|
||||
ImageFormat.Unknown);
|
||||
|
||||
var sampledImageType = context.TypeSampledImage(imageType);
|
||||
var sampledImagePointerType = context.TypePointer(StorageClass.UniformConstant, sampledImageType);
|
||||
sampledImageType = context.TypeSampledImage(imageType);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageType = sampledImageType = context.TypeSampler();
|
||||
}
|
||||
|
||||
var sampledOrSeparateImageType = sampler.Separate ? imageType : sampledImageType;
|
||||
var sampledImagePointerType = context.TypePointer(StorageClass.UniformConstant, sampledOrSeparateImageType);
|
||||
var sampledImageArrayPointerType = sampledImagePointerType;
|
||||
|
||||
if (sampler.ArrayLength == 0)
|
||||
{
|
||||
var sampledImageArrayType = context.TypeRuntimeArray(sampledImageType);
|
||||
var sampledImageArrayType = context.TypeRuntimeArray(sampledOrSeparateImageType);
|
||||
sampledImageArrayPointerType = context.TypePointer(StorageClass.UniformConstant, sampledImageArrayType);
|
||||
}
|
||||
else if (sampler.ArrayLength != 1)
|
||||
{
|
||||
var sampledImageArrayType = context.TypeArray(sampledImageType, context.Constant(context.TypeU32(), sampler.ArrayLength));
|
||||
var sampledImageArrayType = context.TypeArray(sampledOrSeparateImageType, context.Constant(context.TypeU32(), sampler.ArrayLength));
|
||||
sampledImageArrayPointerType = context.TypePointer(StorageClass.UniformConstant, sampledImageArrayType);
|
||||
}
|
||||
|
||||
|
@ -838,16 +838,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
||||
}
|
||||
|
||||
SamplerDeclaration declaration = context.Samplers[texOp.Binding];
|
||||
SpvInstruction image = declaration.Image;
|
||||
|
||||
if (declaration.IsIndexed)
|
||||
{
|
||||
SpvInstruction textureIndex = Src(AggregateType.S32);
|
||||
|
||||
image = context.AccessChain(declaration.SampledImagePointerType, image, textureIndex);
|
||||
}
|
||||
|
||||
image = context.Load(declaration.SampledImageType, image);
|
||||
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
||||
|
||||
int pCount = texOp.Type.GetDimensions();
|
||||
|
||||
@ -1171,16 +1162,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
||||
}
|
||||
|
||||
SamplerDeclaration declaration = context.Samplers[texOp.Binding];
|
||||
SpvInstruction image = declaration.Image;
|
||||
|
||||
if (declaration.IsIndexed)
|
||||
{
|
||||
SpvInstruction textureIndex = Src(AggregateType.S32);
|
||||
|
||||
image = context.AccessChain(declaration.SampledImagePointerType, image, textureIndex);
|
||||
}
|
||||
|
||||
image = context.Load(declaration.SampledImageType, image);
|
||||
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
||||
|
||||
int coordsCount = texOp.Type.GetDimensions();
|
||||
|
||||
@ -1449,17 +1431,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
||||
{
|
||||
AstTextureOperation texOp = (AstTextureOperation)operation;
|
||||
|
||||
int srcIndex = 0;
|
||||
|
||||
SamplerDeclaration declaration = context.Samplers[texOp.Binding];
|
||||
SpvInstruction image = declaration.Image;
|
||||
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
||||
|
||||
if (declaration.IsIndexed)
|
||||
{
|
||||
SpvInstruction textureIndex = context.GetS32(texOp.GetSource(0));
|
||||
|
||||
image = context.AccessChain(declaration.SampledImagePointerType, image, textureIndex);
|
||||
}
|
||||
|
||||
image = context.Load(declaration.SampledImageType, image);
|
||||
image = context.Image(declaration.ImageType, image);
|
||||
|
||||
SpvInstruction result = context.ImageQuerySamples(context.TypeS32(), image);
|
||||
@ -1471,17 +1447,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
||||
{
|
||||
AstTextureOperation texOp = (AstTextureOperation)operation;
|
||||
|
||||
int srcIndex = 0;
|
||||
|
||||
SamplerDeclaration declaration = context.Samplers[texOp.Binding];
|
||||
SpvInstruction image = declaration.Image;
|
||||
SpvInstruction image = GenerateSampledImageLoad(context, texOp, declaration, ref srcIndex);
|
||||
|
||||
if (declaration.IsIndexed)
|
||||
{
|
||||
SpvInstruction textureIndex = context.GetS32(texOp.GetSource(0));
|
||||
|
||||
image = context.AccessChain(declaration.SampledImagePointerType, image, textureIndex);
|
||||
}
|
||||
|
||||
image = context.Load(declaration.SampledImageType, image);
|
||||
image = context.Image(declaration.ImageType, image);
|
||||
|
||||
if (texOp.Index == 3)
|
||||
@ -1506,8 +1476,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
||||
|
||||
if (hasLod)
|
||||
{
|
||||
int lodSrcIndex = declaration.IsIndexed ? 1 : 0;
|
||||
var lod = context.GetS32(operation.GetSource(lodSrcIndex));
|
||||
var lod = context.GetS32(operation.GetSource(srcIndex));
|
||||
result = context.ImageQuerySizeLod(resultType, image, lod);
|
||||
}
|
||||
else
|
||||
@ -1905,6 +1874,43 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
||||
}
|
||||
}
|
||||
|
||||
private static SpvInstruction GenerateSampledImageLoad(CodeGenContext context, AstTextureOperation texOp, SamplerDeclaration declaration, ref int srcIndex)
|
||||
{
|
||||
SpvInstruction image = declaration.Image;
|
||||
|
||||
if (declaration.IsIndexed)
|
||||
{
|
||||
SpvInstruction textureIndex = context.Get(AggregateType.S32, texOp.GetSource(srcIndex++));
|
||||
|
||||
image = context.AccessChain(declaration.SampledImagePointerType, image, textureIndex);
|
||||
}
|
||||
|
||||
if (texOp.IsSeparate)
|
||||
{
|
||||
image = context.Load(declaration.ImageType, image);
|
||||
|
||||
SamplerDeclaration samplerDeclaration = context.Samplers[texOp.SamplerBinding];
|
||||
|
||||
SpvInstruction sampler = samplerDeclaration.Image;
|
||||
|
||||
if (samplerDeclaration.IsIndexed)
|
||||
{
|
||||
SpvInstruction samplerIndex = context.Get(AggregateType.S32, texOp.GetSource(srcIndex++));
|
||||
|
||||
sampler = context.AccessChain(samplerDeclaration.SampledImagePointerType, sampler, samplerIndex);
|
||||
}
|
||||
|
||||
sampler = context.Load(samplerDeclaration.ImageType, sampler);
|
||||
image = context.SampledImage(declaration.SampledImageType, image, sampler);
|
||||
}
|
||||
else
|
||||
{
|
||||
image = context.Load(declaration.SampledImageType, image);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
private static OperationResult GenerateUnary(
|
||||
CodeGenContext context,
|
||||
AstOperation operation,
|
||||
|
@ -102,6 +102,11 @@ namespace Ryujinx.Graphics.Shader
|
||||
/// </summary>
|
||||
public readonly bool OriginUpperLeft;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the primitive ID values on the shader should be halved due to quad to triangles conversion.
|
||||
/// </summary>
|
||||
public readonly bool HalvePrimitiveId;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new GPU graphics state.
|
||||
/// </summary>
|
||||
@ -124,6 +129,7 @@ namespace Ryujinx.Graphics.Shader
|
||||
/// <param name="dualSourceBlendEnable">Indicates whether dual source blend is enabled</param>
|
||||
/// <param name="yNegateEnabled">Indicates if negation of the viewport Y axis is enabled</param>
|
||||
/// <param name="originUpperLeft">If true, indicates that the fragment origin is the upper left corner of the viewport, otherwise it is the lower left corner</param>
|
||||
/// <param name="halvePrimitiveId">Indicates that the primitive ID values on the shader should be halved due to quad to triangles conversion</param>
|
||||
public GpuGraphicsState(
|
||||
bool earlyZForce,
|
||||
InputTopology topology,
|
||||
@ -143,7 +149,8 @@ namespace Ryujinx.Graphics.Shader
|
||||
in Array8<AttributeType> fragmentOutputTypes,
|
||||
bool dualSourceBlendEnable,
|
||||
bool yNegateEnabled,
|
||||
bool originUpperLeft)
|
||||
bool originUpperLeft,
|
||||
bool halvePrimitiveId)
|
||||
{
|
||||
EarlyZForce = earlyZForce;
|
||||
Topology = topology;
|
||||
@ -164,6 +171,7 @@ namespace Ryujinx.Graphics.Shader
|
||||
DualSourceBlendEnable = dualSourceBlendEnable;
|
||||
YNegateEnabled = yNegateEnabled;
|
||||
OriginUpperLeft = originUpperLeft;
|
||||
HalvePrimitiveId = halvePrimitiveId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,13 +26,6 @@ namespace Ryujinx.Graphics.Shader
|
||||
/// <returns>Span of the memory location</returns>
|
||||
ReadOnlySpan<ulong> GetCode(ulong address, int minimumSize);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size in bytes of a bound constant buffer for the current shader stage.
|
||||
/// </summary>
|
||||
/// <param name="slot">The number of the constant buffer to get the size from</param>
|
||||
/// <returns>Size in bytes</returns>
|
||||
int QueryTextureArrayLengthFromBuffer(int slot);
|
||||
|
||||
/// <summary>
|
||||
/// Queries the binding number of a constant buffer.
|
||||
/// </summary>
|
||||
@ -142,6 +135,7 @@ namespace Ryujinx.Graphics.Shader
|
||||
default,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false);
|
||||
}
|
||||
|
||||
@ -298,6 +292,15 @@ namespace Ryujinx.Graphics.Shader
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queries host API support for separate textures and samplers.
|
||||
/// </summary>
|
||||
/// <returns>True if the API supports samplers and textures to be combined on the shader, false otherwise</returns>
|
||||
bool QueryHostSupportsSeparateSampler()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queries host GPU shader ballot support.
|
||||
/// </summary>
|
||||
@ -388,6 +391,12 @@ namespace Ryujinx.Graphics.Shader
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum number of samplers that the bound texture pool may have.
|
||||
/// </summary>
|
||||
/// <returns>Maximum amount of samplers that the pool may have</returns>
|
||||
int QuerySamplerArrayLengthFromPool();
|
||||
|
||||
/// <summary>
|
||||
/// Queries sampler type information.
|
||||
/// </summary>
|
||||
@ -399,6 +408,19 @@ namespace Ryujinx.Graphics.Shader
|
||||
return SamplerType.Texture2D;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size in bytes of a bound constant buffer for the current shader stage.
|
||||
/// </summary>
|
||||
/// <param name="slot">The number of the constant buffer to get the size from</param>
|
||||
/// <returns>Size in bytes</returns>
|
||||
int QueryTextureArrayLengthFromBuffer(int slot);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum number of textures that the bound texture pool may have.
|
||||
/// </summary>
|
||||
/// <returns>Maximum amount of textures that the pool may have</returns>
|
||||
int QueryTextureArrayLengthFromPool();
|
||||
|
||||
/// <summary>
|
||||
/// Queries texture coordinate normalization information.
|
||||
/// </summary>
|
||||
|
@ -84,6 +84,10 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
value = context.IConvertU32ToFP32(value);
|
||||
}
|
||||
}
|
||||
else if (offset == AttributeConsts.PrimitiveId && context.TranslatorContext.Definitions.HalvePrimitiveId)
|
||||
{
|
||||
value = context.ShiftRightS32(value, Const(1));
|
||||
}
|
||||
|
||||
context.Copy(Register(rd), value);
|
||||
}
|
||||
@ -187,6 +191,12 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (op.Imm10 == AttributeConsts.PrimitiveId && context.TranslatorContext.Definitions.HalvePrimitiveId)
|
||||
{
|
||||
// If quads are used, but the host does not support them, they need to be converted to triangles.
|
||||
// Since each quad becomes 2 triangles, we need to compensate here and divide primitive ID by 2.
|
||||
res = context.ShiftRightS32(res, Const(1));
|
||||
}
|
||||
else if (op.Imm10 == AttributeConsts.FrontFacing && context.TranslatorContext.GpuAccessor.QueryHostHasFrontFacingBug())
|
||||
{
|
||||
// gl_FrontFacing sometimes has incorrect (flipped) values depending how it is accessed on Intel GPUs.
|
||||
|
@ -216,6 +216,11 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
|
||||
|
||||
newSources[index] = source;
|
||||
|
||||
if (source != null && source.Type == OperandType.LocalVariable)
|
||||
{
|
||||
source.UseOps.Add(this);
|
||||
}
|
||||
|
||||
_sources = newSources;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
|
||||
public TextureFlags Flags { get; private set; }
|
||||
|
||||
public int Binding { get; private set; }
|
||||
public int SamplerBinding { get; private set; }
|
||||
|
||||
public TextureOperation(
|
||||
Instruction inst,
|
||||
@ -24,6 +25,7 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
|
||||
Format = format;
|
||||
Flags = flags;
|
||||
Binding = binding;
|
||||
SamplerBinding = -1;
|
||||
}
|
||||
|
||||
public void TurnIntoArray(int binding)
|
||||
@ -32,6 +34,13 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
|
||||
Binding = binding;
|
||||
}
|
||||
|
||||
public void TurnIntoArray(int textureBinding, int samplerBinding)
|
||||
{
|
||||
TurnIntoArray(textureBinding);
|
||||
|
||||
SamplerBinding = samplerBinding;
|
||||
}
|
||||
|
||||
public void SetBinding(int binding)
|
||||
{
|
||||
if ((Flags & TextureFlags.Bindless) != 0)
|
||||
|
@ -69,6 +69,7 @@ namespace Ryujinx.Graphics.Shader
|
||||
{
|
||||
string typeName = (type & SamplerType.Mask) switch
|
||||
{
|
||||
SamplerType.None => "sampler",
|
||||
SamplerType.Texture1D => "sampler1D",
|
||||
SamplerType.TextureBuffer => "samplerBuffer",
|
||||
SamplerType.Texture2D => "sampler2D",
|
||||
@ -95,6 +96,31 @@ namespace Ryujinx.Graphics.Shader
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public static string ToGlslTextureType(this SamplerType type)
|
||||
{
|
||||
string typeName = (type & SamplerType.Mask) switch
|
||||
{
|
||||
SamplerType.Texture1D => "texture1D",
|
||||
SamplerType.TextureBuffer => "textureBuffer",
|
||||
SamplerType.Texture2D => "texture2D",
|
||||
SamplerType.Texture3D => "texture3D",
|
||||
SamplerType.TextureCube => "textureCube",
|
||||
_ => throw new ArgumentException($"Invalid texture type \"{type}\"."),
|
||||
};
|
||||
|
||||
if ((type & SamplerType.Multisample) != 0)
|
||||
{
|
||||
typeName += "MS";
|
||||
}
|
||||
|
||||
if ((type & SamplerType.Array) != 0)
|
||||
{
|
||||
typeName += "Array";
|
||||
}
|
||||
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public static string ToGlslImageType(this SamplerType type, AggregateType componentType)
|
||||
{
|
||||
string typeName = (type & SamplerType.Mask) switch
|
||||
|
@ -9,6 +9,9 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
||||
public TextureFlags Flags { get; }
|
||||
|
||||
public int Binding { get; }
|
||||
public int SamplerBinding { get; }
|
||||
|
||||
public bool IsSeparate => SamplerBinding >= 0;
|
||||
|
||||
public AstTextureOperation(
|
||||
Instruction inst,
|
||||
@ -16,6 +19,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
||||
TextureFormat format,
|
||||
TextureFlags flags,
|
||||
int binding,
|
||||
int samplerBinding,
|
||||
int index,
|
||||
params IAstNode[] sources) : base(inst, StorageKind.None, false, index, sources, sources.Length)
|
||||
{
|
||||
@ -23,6 +27,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
||||
Format = format;
|
||||
Flags = flags;
|
||||
Binding = binding;
|
||||
SamplerBinding = samplerBinding;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
||||
|
||||
AstTextureOperation GetAstTextureOperation(TextureOperation texOp)
|
||||
{
|
||||
return new AstTextureOperation(inst, texOp.Type, texOp.Format, texOp.Flags, texOp.Binding, texOp.Index, sources);
|
||||
return new AstTextureOperation(inst, texOp.Type, texOp.Format, texOp.Flags, texOp.Binding, texOp.SamplerBinding, texOp.Index, sources);
|
||||
}
|
||||
|
||||
int componentsCount = BitOperations.PopCount((uint)operation.Index);
|
||||
|
@ -5,25 +5,39 @@ namespace Ryujinx.Graphics.Shader
|
||||
public int Set { get; }
|
||||
public int Binding { get; }
|
||||
public int ArrayLength { get; }
|
||||
public bool Separate { get; }
|
||||
public string Name { get; }
|
||||
public SamplerType Type { get; }
|
||||
public TextureFormat Format { get; }
|
||||
public TextureUsageFlags Flags { get; }
|
||||
|
||||
public TextureDefinition(int set, int binding, int arrayLength, string name, SamplerType type, TextureFormat format, TextureUsageFlags flags)
|
||||
public TextureDefinition(
|
||||
int set,
|
||||
int binding,
|
||||
int arrayLength,
|
||||
bool separate,
|
||||
string name,
|
||||
SamplerType type,
|
||||
TextureFormat format,
|
||||
TextureUsageFlags flags)
|
||||
{
|
||||
Set = set;
|
||||
Binding = binding;
|
||||
ArrayLength = arrayLength;
|
||||
Separate = separate;
|
||||
Name = name;
|
||||
Type = type;
|
||||
Format = format;
|
||||
Flags = flags;
|
||||
}
|
||||
|
||||
public TextureDefinition(int set, int binding, string name, SamplerType type) : this(set, binding, 1, false, name, type, TextureFormat.Unknown, TextureUsageFlags.None)
|
||||
{
|
||||
}
|
||||
|
||||
public TextureDefinition SetFlag(TextureUsageFlags flag)
|
||||
{
|
||||
return new TextureDefinition(Set, Binding, ArrayLength, Name, Type, Format, Flags | flag);
|
||||
return new TextureDefinition(Set, Binding, ArrayLength, Separate, Name, Type, Format, Flags | flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ namespace Ryujinx.Graphics.Shader
|
||||
public readonly int HandleIndex;
|
||||
public readonly int ArrayLength;
|
||||
|
||||
public readonly bool Separate;
|
||||
|
||||
public readonly TextureUsageFlags Flags;
|
||||
|
||||
public TextureDescriptor(
|
||||
@ -22,6 +24,7 @@ namespace Ryujinx.Graphics.Shader
|
||||
int cbufSlot,
|
||||
int handleIndex,
|
||||
int arrayLength,
|
||||
bool separate,
|
||||
TextureUsageFlags flags)
|
||||
{
|
||||
Binding = binding;
|
||||
@ -30,6 +33,7 @@ namespace Ryujinx.Graphics.Shader
|
||||
CbufSlot = cbufSlot;
|
||||
HandleIndex = handleIndex;
|
||||
ArrayLength = arrayLength;
|
||||
Separate = separate;
|
||||
Flags = flags;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ namespace Ryujinx.Graphics.Shader
|
||||
SeparateSamplerHandle = 1,
|
||||
SeparateSamplerId = 2,
|
||||
SeparateConstantSamplerHandle = 3,
|
||||
Direct = 4,
|
||||
}
|
||||
|
||||
public static class TextureHandle
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Ryujinx.Graphics.Shader.Instructions;
|
||||
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
||||
using Ryujinx.Graphics.Shader.StructuredIr;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
@ -31,7 +32,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!TryConvertBindless(block, resourceManager, gpuAccessor, texOp))
|
||||
if (!TryConvertBindless(block, resourceManager, gpuAccessor, texOp) &&
|
||||
!GenerateBindlessAccess(block, resourceManager, gpuAccessor, texOp, node))
|
||||
{
|
||||
// If we can't do bindless elimination, remove the texture operation.
|
||||
// Set any destination variables to zero.
|
||||
@ -46,6 +48,88 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
}
|
||||
}
|
||||
|
||||
private static bool GenerateBindlessAccess(
|
||||
BasicBlock block,
|
||||
ResourceManager resourceManager,
|
||||
IGpuAccessor gpuAccessor,
|
||||
TextureOperation texOp,
|
||||
LinkedListNode<INode> node)
|
||||
{
|
||||
if (!gpuAccessor.QueryHostSupportsSeparateSampler())
|
||||
{
|
||||
// We depend on combining samplers and textures in the shader being supported for this.
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Operand nvHandle = texOp.GetSource(0);
|
||||
|
||||
if (nvHandle.AsgOp is not Operation handleOp ||
|
||||
handleOp.Inst != Instruction.Load ||
|
||||
(handleOp.StorageKind != StorageKind.Input && handleOp.StorageKind != StorageKind.StorageBuffer))
|
||||
{
|
||||
// Right now, we only allow bindless access when the handle comes from a shader input or storage buffer.
|
||||
// This is an artificial limitation to prevent it from being used in cases where it
|
||||
// would have a large performance impact of loading all textures in the pool.
|
||||
// It might be removed in the future, if we can mitigate the performance impact.
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Operand textureHandle = OperandHelper.Local();
|
||||
Operand samplerHandle = OperandHelper.Local();
|
||||
Operand textureIndex = OperandHelper.Local();
|
||||
|
||||
block.Operations.AddBefore(node, new Operation(Instruction.BitwiseAnd, textureHandle, nvHandle, OperandHelper.Const(0xfffff)));
|
||||
block.Operations.AddBefore(node, new Operation(Instruction.ShiftRightU32, samplerHandle, nvHandle, OperandHelper.Const(20)));
|
||||
|
||||
int texturePoolLength = Math.Max(BindlessToArray.MinimumArrayLength, gpuAccessor.QueryTextureArrayLengthFromPool());
|
||||
|
||||
block.Operations.AddBefore(node, new Operation(Instruction.MinimumU32, textureIndex, textureHandle, OperandHelper.Const(texturePoolLength - 1)));
|
||||
|
||||
texOp.SetSource(0, textureIndex);
|
||||
|
||||
bool hasSampler = !texOp.Inst.IsImage();
|
||||
|
||||
int textureBinding = resourceManager.GetTextureOrImageBinding(
|
||||
texOp.Inst,
|
||||
texOp.Type,
|
||||
texOp.Format,
|
||||
texOp.Flags & ~TextureFlags.Bindless,
|
||||
0,
|
||||
TextureHandle.PackOffsets(0, 0, TextureHandleType.Direct),
|
||||
texturePoolLength,
|
||||
hasSampler);
|
||||
|
||||
if (hasSampler)
|
||||
{
|
||||
Operand samplerIndex = OperandHelper.Local();
|
||||
|
||||
int samplerPoolLength = Math.Max(BindlessToArray.MinimumArrayLength, gpuAccessor.QuerySamplerArrayLengthFromPool());
|
||||
|
||||
block.Operations.AddBefore(node, new Operation(Instruction.MinimumU32, samplerIndex, samplerHandle, OperandHelper.Const(samplerPoolLength - 1)));
|
||||
|
||||
texOp.InsertSource(1, samplerIndex);
|
||||
|
||||
int samplerBinding = resourceManager.GetTextureOrImageBinding(
|
||||
texOp.Inst,
|
||||
SamplerType.None,
|
||||
texOp.Format,
|
||||
TextureFlags.None,
|
||||
0,
|
||||
TextureHandle.PackOffsets(0, 0, TextureHandleType.Direct),
|
||||
samplerPoolLength);
|
||||
|
||||
texOp.TurnIntoArray(textureBinding, samplerBinding);
|
||||
}
|
||||
else
|
||||
{
|
||||
texOp.TurnIntoArray(textureBinding);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryConvertBindless(BasicBlock block, ResourceManager resourceManager, IGpuAccessor gpuAccessor, TextureOperation texOp)
|
||||
{
|
||||
if (texOp.Inst == Instruction.TextureSample || texOp.Inst.IsTextureQuery())
|
||||
|
@ -11,7 +11,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
private const int HardcodedArrayLengthOgl = 4;
|
||||
|
||||
// 1 and 0 elements are not considered arrays anymore.
|
||||
private const int MinimumArrayLength = 2;
|
||||
public const int MinimumArrayLength = 2;
|
||||
|
||||
public static void RunPassOgl(BasicBlock block, ResourceManager resourceManager)
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
private readonly HashSet<int> _usedConstantBufferBindings;
|
||||
|
||||
private readonly record struct TextureInfo(int CbufSlot, int Handle, int ArrayLength, SamplerType Type, TextureFormat Format);
|
||||
private readonly record struct TextureInfo(int CbufSlot, int Handle, int ArrayLength, bool Separate, SamplerType Type, TextureFormat Format);
|
||||
|
||||
private struct TextureMeta
|
||||
{
|
||||
@ -225,7 +225,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
TextureFlags flags,
|
||||
int cbufSlot,
|
||||
int handle,
|
||||
int arrayLength = 1)
|
||||
int arrayLength = 1,
|
||||
bool separate = false)
|
||||
{
|
||||
inst &= Instruction.Mask;
|
||||
bool isImage = inst.IsImage();
|
||||
@ -239,7 +240,18 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
format = TextureFormat.Unknown;
|
||||
}
|
||||
|
||||
int binding = GetTextureOrImageBinding(cbufSlot, handle, arrayLength, type, format, isImage, intCoords, isWrite, accurateType, coherent);
|
||||
int binding = GetTextureOrImageBinding(
|
||||
cbufSlot,
|
||||
handle,
|
||||
arrayLength,
|
||||
type,
|
||||
format,
|
||||
isImage,
|
||||
intCoords,
|
||||
isWrite,
|
||||
accurateType,
|
||||
coherent,
|
||||
separate);
|
||||
|
||||
_gpuAccessor.RegisterTexture(handle, cbufSlot);
|
||||
|
||||
@ -256,9 +268,10 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
bool intCoords,
|
||||
bool write,
|
||||
bool accurateType,
|
||||
bool coherent)
|
||||
bool coherent,
|
||||
bool separate)
|
||||
{
|
||||
var dimensions = type.GetDimensions();
|
||||
var dimensions = type == SamplerType.None ? 0 : type.GetDimensions();
|
||||
var dict = isImage ? _usedImages : _usedTextures;
|
||||
|
||||
var usageFlags = TextureUsageFlags.None;
|
||||
@ -290,7 +303,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
// For array textures, we also want to use type as key,
|
||||
// since we may have texture handles stores in the same buffer, but for textures with different types.
|
||||
var keyType = arrayLength > 1 ? type : SamplerType.None;
|
||||
var info = new TextureInfo(cbufSlot, handle, arrayLength, keyType, format);
|
||||
var info = new TextureInfo(cbufSlot, handle, arrayLength, separate, keyType, format);
|
||||
var meta = new TextureMeta()
|
||||
{
|
||||
AccurateType = accurateType,
|
||||
@ -332,6 +345,10 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
? $"{prefix}_tcb_{handle:X}_{format.ToGlslFormat()}"
|
||||
: $"{prefix}_cb{cbufSlot}_{handle:X}_{format.ToGlslFormat()}";
|
||||
}
|
||||
else if (type == SamplerType.None)
|
||||
{
|
||||
nameSuffix = cbufSlot < 0 ? $"s_tcb_{handle:X}" : $"s_cb{cbufSlot}_{handle:X}";
|
||||
}
|
||||
else
|
||||
{
|
||||
nameSuffix = cbufSlot < 0 ? $"{prefix}_tcb_{handle:X}" : $"{prefix}_cb{cbufSlot}_{handle:X}";
|
||||
@ -341,6 +358,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
isImage ? 3 : 2,
|
||||
binding,
|
||||
arrayLength,
|
||||
separate,
|
||||
$"{_stagePrefix}_{nameSuffix}",
|
||||
meta.Type,
|
||||
info.Format,
|
||||
@ -495,6 +513,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
info.CbufSlot,
|
||||
info.Handle,
|
||||
info.ArrayLength,
|
||||
info.Separate,
|
||||
meta.UsageFlags));
|
||||
}
|
||||
|
||||
@ -514,6 +533,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
info.CbufSlot,
|
||||
info.Handle,
|
||||
info.ArrayLength,
|
||||
info.Separate,
|
||||
meta.UsageFlags));
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
public bool YNegateEnabled => _graphicsState.YNegateEnabled;
|
||||
public bool OriginUpperLeft => _graphicsState.OriginUpperLeft;
|
||||
|
||||
public bool HalvePrimitiveId => _graphicsState.HalvePrimitiveId;
|
||||
|
||||
public ImapPixelType[] ImapTypes { get; }
|
||||
public bool IaIndexing { get; private set; }
|
||||
public bool OaIndexing { get; private set; }
|
||||
|
@ -413,7 +413,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
if (Stage == ShaderStage.Vertex)
|
||||
{
|
||||
int ibBinding = resourceManager.Reservations.IndexBufferTextureBinding;
|
||||
TextureDefinition indexBuffer = new(2, ibBinding, 1, "ib_data", SamplerType.TextureBuffer, TextureFormat.Unknown, TextureUsageFlags.None);
|
||||
TextureDefinition indexBuffer = new(2, ibBinding, "ib_data", SamplerType.TextureBuffer);
|
||||
resourceManager.Properties.AddOrUpdateTexture(indexBuffer);
|
||||
|
||||
int inputMap = _program.AttributeUsage.UsedInputAttributes;
|
||||
@ -422,7 +422,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
{
|
||||
int location = BitOperations.TrailingZeroCount(inputMap);
|
||||
int binding = resourceManager.Reservations.GetVertexBufferTextureBinding(location);
|
||||
TextureDefinition vaBuffer = new(2, binding, 1, $"vb_data{location}", SamplerType.TextureBuffer, TextureFormat.Unknown, TextureUsageFlags.None);
|
||||
TextureDefinition vaBuffer = new(2, binding, $"vb_data{location}", SamplerType.TextureBuffer);
|
||||
resourceManager.Properties.AddOrUpdateTexture(vaBuffer);
|
||||
|
||||
inputMap &= ~(1 << location);
|
||||
@ -431,7 +431,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
else if (Stage == ShaderStage.Geometry)
|
||||
{
|
||||
int trbBinding = resourceManager.Reservations.TopologyRemapBufferTextureBinding;
|
||||
TextureDefinition remapBuffer = new(2, trbBinding, 1, "trb_data", SamplerType.TextureBuffer, TextureFormat.Unknown, TextureUsageFlags.None);
|
||||
TextureDefinition remapBuffer = new(2, trbBinding, "trb_data", SamplerType.TextureBuffer);
|
||||
resourceManager.Properties.AddOrUpdateTexture(remapBuffer);
|
||||
|
||||
int geometryVbOutputSbBinding = resourceManager.Reservations.GeometryVertexOutputStorageBufferBinding;
|
||||
|
@ -302,12 +302,12 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
SubmitInfo sInfo = new()
|
||||
{
|
||||
SType = StructureType.SubmitInfo,
|
||||
WaitSemaphoreCount = waitSemaphores != null ? (uint)waitSemaphores.Length : 0,
|
||||
WaitSemaphoreCount = !waitSemaphores.IsEmpty ? (uint)waitSemaphores.Length : 0,
|
||||
PWaitSemaphores = pWaitSemaphores,
|
||||
PWaitDstStageMask = pWaitDstStageMask,
|
||||
CommandBufferCount = 1,
|
||||
PCommandBuffers = &commandBuffer,
|
||||
SignalSemaphoreCount = signalSemaphores != null ? (uint)signalSemaphores.Length : 0,
|
||||
SignalSemaphoreCount = !signalSemaphores.IsEmpty ? (uint)signalSemaphores.Length : 0,
|
||||
PSignalSemaphores = pSignalSemaphores,
|
||||
};
|
||||
|
||||
|
@ -43,11 +43,11 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
int binding = segment.Binding;
|
||||
int count = segment.Count;
|
||||
|
||||
if (setIndex == PipelineBase.UniformSetIndex)
|
||||
if (IsBufferType(segment.Type))
|
||||
{
|
||||
entries[seg] = new DescriptorUpdateTemplateEntry()
|
||||
{
|
||||
DescriptorType = DescriptorType.UniformBuffer,
|
||||
DescriptorType = segment.Type.Convert(),
|
||||
DstBinding = (uint)binding,
|
||||
DescriptorCount = (uint)count,
|
||||
Offset = structureOffset,
|
||||
@ -56,76 +56,31 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
|
||||
structureOffset += (nuint)(Unsafe.SizeOf<DescriptorBufferInfo>() * count);
|
||||
}
|
||||
else if (setIndex == PipelineBase.StorageSetIndex)
|
||||
else if (IsBufferTextureType(segment.Type))
|
||||
{
|
||||
entries[seg] = new DescriptorUpdateTemplateEntry()
|
||||
{
|
||||
DescriptorType = DescriptorType.StorageBuffer,
|
||||
DescriptorType = segment.Type.Convert(),
|
||||
DstBinding = (uint)binding,
|
||||
DescriptorCount = (uint)count,
|
||||
Offset = structureOffset,
|
||||
Stride = (nuint)Unsafe.SizeOf<DescriptorBufferInfo>()
|
||||
Stride = (nuint)Unsafe.SizeOf<BufferView>()
|
||||
};
|
||||
|
||||
structureOffset += (nuint)(Unsafe.SizeOf<DescriptorBufferInfo>() * count);
|
||||
structureOffset += (nuint)(Unsafe.SizeOf<BufferView>() * count);
|
||||
}
|
||||
else if (setIndex == PipelineBase.TextureSetIndex)
|
||||
else
|
||||
{
|
||||
if (segment.Type != ResourceType.BufferTexture)
|
||||
entries[seg] = new DescriptorUpdateTemplateEntry()
|
||||
{
|
||||
entries[seg] = new DescriptorUpdateTemplateEntry()
|
||||
{
|
||||
DescriptorType = DescriptorType.CombinedImageSampler,
|
||||
DstBinding = (uint)binding,
|
||||
DescriptorCount = (uint)count,
|
||||
Offset = structureOffset,
|
||||
Stride = (nuint)Unsafe.SizeOf<DescriptorImageInfo>()
|
||||
};
|
||||
DescriptorType = segment.Type.Convert(),
|
||||
DstBinding = (uint)binding,
|
||||
DescriptorCount = (uint)count,
|
||||
Offset = structureOffset,
|
||||
Stride = (nuint)Unsafe.SizeOf<DescriptorImageInfo>()
|
||||
};
|
||||
|
||||
structureOffset += (nuint)(Unsafe.SizeOf<DescriptorImageInfo>() * count);
|
||||
}
|
||||
else
|
||||
{
|
||||
entries[seg] = new DescriptorUpdateTemplateEntry()
|
||||
{
|
||||
DescriptorType = DescriptorType.UniformTexelBuffer,
|
||||
DstBinding = (uint)binding,
|
||||
DescriptorCount = (uint)count,
|
||||
Offset = structureOffset,
|
||||
Stride = (nuint)Unsafe.SizeOf<BufferView>()
|
||||
};
|
||||
|
||||
structureOffset += (nuint)(Unsafe.SizeOf<BufferView>() * count);
|
||||
}
|
||||
}
|
||||
else if (setIndex == PipelineBase.ImageSetIndex)
|
||||
{
|
||||
if (segment.Type != ResourceType.BufferImage)
|
||||
{
|
||||
entries[seg] = new DescriptorUpdateTemplateEntry()
|
||||
{
|
||||
DescriptorType = DescriptorType.StorageImage,
|
||||
DstBinding = (uint)binding,
|
||||
DescriptorCount = (uint)count,
|
||||
Offset = structureOffset,
|
||||
Stride = (nuint)Unsafe.SizeOf<DescriptorImageInfo>()
|
||||
};
|
||||
|
||||
structureOffset += (nuint)(Unsafe.SizeOf<DescriptorImageInfo>() * count);
|
||||
}
|
||||
else
|
||||
{
|
||||
entries[seg] = new DescriptorUpdateTemplateEntry()
|
||||
{
|
||||
DescriptorType = DescriptorType.StorageTexelBuffer,
|
||||
DstBinding = (uint)binding,
|
||||
DescriptorCount = (uint)count,
|
||||
Offset = structureOffset,
|
||||
Stride = (nuint)Unsafe.SizeOf<BufferView>()
|
||||
};
|
||||
|
||||
structureOffset += (nuint)(Unsafe.SizeOf<BufferView>() * count);
|
||||
}
|
||||
structureOffset += (nuint)(Unsafe.SizeOf<DescriptorImageInfo>() * count);
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,6 +192,16 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
Template = result;
|
||||
}
|
||||
|
||||
private static bool IsBufferType(ResourceType type)
|
||||
{
|
||||
return type == ResourceType.UniformBuffer || type == ResourceType.StorageBuffer;
|
||||
}
|
||||
|
||||
private static bool IsBufferTextureType(ResourceType type)
|
||||
{
|
||||
return type == ResourceType.BufferTexture || type == ResourceType.BufferImage;
|
||||
}
|
||||
|
||||
public unsafe void Dispose()
|
||||
{
|
||||
_gd.Api.DestroyDescriptorUpdateTemplate(_device, Template, null);
|
||||
|
@ -691,6 +691,7 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
supportsBgraFormat: true,
|
||||
supportsR4G4Format: false,
|
||||
supportsR4G4B4A4Format: supportsR4G4B4A4Format,
|
||||
supportsScaledVertexFormats: FormatCapabilities.SupportsScaledVertexFormats(),
|
||||
supportsSnormBufferTextureFormat: true,
|
||||
supports5BitComponentFormat: supports5BitComponentFormat,
|
||||
supportsSparseBuffer: features2.Features.SparseBinding && mainQueueProperties.QueueFlags.HasFlag(QueueFlags.SparseBindingBit),
|
||||
@ -705,7 +706,8 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
supportsMismatchingViewFormat: true,
|
||||
supportsCubemapView: !IsAmdGcn,
|
||||
supportsNonConstantTextureOffset: false,
|
||||
supportsScaledVertexFormats: FormatCapabilities.SupportsScaledVertexFormats(),
|
||||
supportsQuads: false,
|
||||
supportsSeparateSampler: true,
|
||||
supportsShaderBallot: false,
|
||||
supportsShaderBarrierDivergence: Vendor != Vendor.Intel,
|
||||
supportsShaderFloat64: Capabilities.SupportsShaderFloat64,
|
||||
|
@ -75,7 +75,7 @@ namespace Ryujinx
|
||||
|
||||
if (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134))
|
||||
{
|
||||
MessageBoxA(IntPtr.Zero, "You are running an outdated version of Windows.\n\nStarting on June 1st 2022, Ryujinx will only support Windows 10 1803 and newer.\n", $"Ryujinx {Version}", MbIconWarning);
|
||||
MessageBoxA(IntPtr.Zero, "You are running an outdated version of Windows.\n\nRyujinx supports Windows 10 version 1803 and newer.\n", $"Ryujinx {Version}", MbIconWarning);
|
||||
}
|
||||
|
||||
// Parse arguments
|
||||
@ -181,21 +181,24 @@ namespace Ryujinx
|
||||
{
|
||||
// No configuration, we load the default values and save it to disk
|
||||
ConfigurationPath = appDataConfigurationPath;
|
||||
Logger.Notice.Print(LogClass.Application, $"No configuration file found. Saving default configuration to: {ConfigurationPath}");
|
||||
|
||||
ConfigurationState.Instance.LoadDefault();
|
||||
ConfigurationState.Instance.ToFileFormat().SaveConfig(ConfigurationPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Notice.Print(LogClass.Application, $"Loading configuration from: {ConfigurationPath}");
|
||||
|
||||
if (ConfigurationFileFormat.TryLoad(ConfigurationPath, out ConfigurationFileFormat configurationFileFormat))
|
||||
{
|
||||
ConfigurationState.Instance.Load(configurationFileFormat, ConfigurationPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfigurationState.Instance.LoadDefault();
|
||||
Logger.Warning?.PrintMsg(LogClass.Application, $"Failed to load config! Loading the default config instead.\nFailed config location: {ConfigurationPath}");
|
||||
|
||||
Logger.Warning?.PrintMsg(LogClass.Application, $"Failed to load config! Loading the default config instead.\nFailed config location {ConfigurationPath}");
|
||||
ConfigurationState.Instance.LoadDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'linux-x64' OR '$(RuntimeIdentifier)' == 'linux-arm64'">
|
||||
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'linux-x64' OR '$(RuntimeIdentifier)' == 'linux-arm64' OR ('$(RuntimeIdentifier)' == '' AND $([MSBuild]::IsOSPlatform('Linux')))">
|
||||
<Content Include="..\..\distribution\linux\Ryujinx.sh">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
@ -570,7 +570,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
|
||||
}
|
||||
else
|
||||
{
|
||||
serverProcess.CpuMemory.Write(copyDst, clientProcess.CpuMemory.GetSpan(copySrc, (int)copySize));
|
||||
serverProcess.CpuMemory.Write(copyDst, clientProcess.CpuMemory.GetReadOnlySequence(copySrc, (int)copySize));
|
||||
}
|
||||
|
||||
if (clientResult != Result.Success)
|
||||
@ -858,7 +858,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
|
||||
}
|
||||
else
|
||||
{
|
||||
clientProcess.CpuMemory.Write(copyDst, serverProcess.CpuMemory.GetSpan(copySrc, (int)copySize));
|
||||
clientProcess.CpuMemory.Write(copyDst, serverProcess.CpuMemory.GetReadOnlySequence(copySrc, (int)copySize));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ using Ryujinx.Horizon.Common;
|
||||
using Ryujinx.Memory;
|
||||
using Ryujinx.Memory.Range;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
@ -34,6 +35,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override ReadOnlySequence<byte> GetReadOnlySequence(ulong va, int size)
|
||||
{
|
||||
return _cpuMemory.GetReadOnlySequence(va, size);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override ReadOnlySpan<byte> GetSpan(ulong va, int size)
|
||||
{
|
||||
@ -247,6 +254,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
_cpuMemory.SignalMemoryTracking(va, size, write);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Write(ulong va, ReadOnlySequence<byte> data)
|
||||
{
|
||||
_cpuMemory.Write(va, data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Write(ulong va, ReadOnlySpan<byte> data)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ using Ryujinx.Horizon.Common;
|
||||
using Ryujinx.Memory;
|
||||
using Ryujinx.Memory.Range;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
@ -1568,7 +1569,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
ulong copySize = 0x100000; // Copy chunck size. Any value will do, moderate sizes are recommended.
|
||||
ulong copySize = int.MaxValue;
|
||||
|
||||
if (copySize > size)
|
||||
{
|
||||
@ -1577,11 +1578,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
|
||||
if (toServer)
|
||||
{
|
||||
currentProcess.CpuMemory.Write(serverAddress, GetSpan(clientAddress, (int)copySize));
|
||||
currentProcess.CpuMemory.Write(serverAddress, GetReadOnlySequence(clientAddress, (int)copySize));
|
||||
}
|
||||
else
|
||||
{
|
||||
Write(clientAddress, currentProcess.CpuMemory.GetSpan(serverAddress, (int)copySize));
|
||||
Write(clientAddress, currentProcess.CpuMemory.GetReadOnlySequence(serverAddress, (int)copySize));
|
||||
}
|
||||
|
||||
serverAddress += copySize;
|
||||
@ -1911,9 +1912,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
Context.Memory.Fill(GetDramAddressFromPa(dstFirstPagePa), unusedSizeBefore, (byte)_ipcFillValue);
|
||||
|
||||
ulong copySize = addressRounded <= endAddr ? addressRounded - address : size;
|
||||
var data = srcPageTable.GetSpan(addressTruncated + unusedSizeBefore, (int)copySize);
|
||||
var data = srcPageTable.GetReadOnlySequence(addressTruncated + unusedSizeBefore, (int)copySize);
|
||||
|
||||
Context.Memory.Write(GetDramAddressFromPa(dstFirstPagePa + unusedSizeBefore), data);
|
||||
((IWritableBlock)Context.Memory).Write(GetDramAddressFromPa(dstFirstPagePa + unusedSizeBefore), data);
|
||||
|
||||
firstPageFillAddress += unusedSizeBefore + copySize;
|
||||
|
||||
@ -1977,9 +1978,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
if (send)
|
||||
{
|
||||
ulong copySize = endAddr - endAddrTruncated;
|
||||
var data = srcPageTable.GetSpan(endAddrTruncated, (int)copySize);
|
||||
var data = srcPageTable.GetReadOnlySequence(endAddrTruncated, (int)copySize);
|
||||
|
||||
Context.Memory.Write(GetDramAddressFromPa(dstLastPagePa), data);
|
||||
((IWritableBlock)Context.Memory).Write(GetDramAddressFromPa(dstLastPagePa), data);
|
||||
|
||||
lastPageFillAddr += copySize;
|
||||
|
||||
@ -2943,6 +2944,18 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
/// <param name="pageList">Page list where the ranges will be added</param>
|
||||
protected abstract void GetPhysicalRegions(ulong va, ulong size, KPageList pageList);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only sequence of data from CPU mapped memory.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Allows reading non-contiguous memory without first copying it to a newly allocated single contiguous block.
|
||||
/// </remarks>
|
||||
/// <param name="va">Virtual address of the data</param>
|
||||
/// <param name="size">Size of the data</param>
|
||||
/// <returns>A read-only sequence of the data</returns>
|
||||
/// <exception cref="Ryujinx.Memory.InvalidMemoryRegionException">Throw for unhandled invalid or unmapped memory accesses</exception>
|
||||
protected abstract ReadOnlySequence<byte> GetReadOnlySequence(ulong va, int size);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only span of data from CPU mapped memory.
|
||||
/// </summary>
|
||||
@ -2952,7 +2965,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
/// </remarks>
|
||||
/// <param name="va">Virtual address of the data</param>
|
||||
/// <param name="size">Size of the data</param>
|
||||
/// <param name="tracked">True if read tracking is triggered on the span</param>
|
||||
/// <returns>A read-only span of the data</returns>
|
||||
/// <exception cref="Ryujinx.Memory.InvalidMemoryRegionException">Throw for unhandled invalid or unmapped memory accesses</exception>
|
||||
protected abstract ReadOnlySpan<byte> GetSpan(ulong va, int size);
|
||||
@ -3060,6 +3072,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
/// <param name="size">Size of the region</param>
|
||||
protected abstract void SignalMemoryTracking(ulong va, ulong size, bool write);
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to CPU mapped memory, with write tracking.
|
||||
/// </summary>
|
||||
/// <param name="va">Virtual address to write the data into</param>
|
||||
/// <param name="data">Data to be written</param>
|
||||
/// <exception cref="Ryujinx.Memory.InvalidMemoryRegionException">Throw for unhandled invalid or unmapped memory accesses</exception>
|
||||
protected abstract void Write(ulong va, ReadOnlySequence<byte> data);
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to CPU mapped memory, with write tracking.
|
||||
/// </summary>
|
||||
|
@ -60,7 +60,7 @@ namespace Ryujinx.HLE.HOS.Services.Fatal
|
||||
errorReport.AppendLine($"\tResultCode: {((int)resultCode & 0x1FF) + 2000}-{((int)resultCode >> 9) & 0x3FFF:d4}");
|
||||
errorReport.AppendLine($"\tFatalPolicy: {fatalPolicy}");
|
||||
|
||||
if (cpuContext != null)
|
||||
if (!cpuContext.IsEmpty)
|
||||
{
|
||||
errorReport.AppendLine("CPU Context:");
|
||||
|
||||
|
@ -23,8 +23,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
newState.Buttons = (MouseButton)buttons;
|
||||
newState.X = mouseX;
|
||||
newState.Y = mouseY;
|
||||
newState.DeltaX = mouseX - previousEntry.DeltaX;
|
||||
newState.DeltaY = mouseY - previousEntry.DeltaY;
|
||||
newState.DeltaX = mouseX - previousEntry.X;
|
||||
newState.DeltaY = mouseY - previousEntry.Y;
|
||||
newState.WheelDeltaX = scrollX;
|
||||
newState.WheelDeltaY = scrollY;
|
||||
newState.Attributes = connected ? MouseAttribute.IsConnected : MouseAttribute.None;
|
||||
|
@ -22,6 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
|
||||
private bool _sixAxisSensorFusionEnabled;
|
||||
private bool _unintendedHomeButtonInputProtectionEnabled;
|
||||
private bool _npadAnalogStickCenterClampEnabled;
|
||||
private bool _vibrationPermitted;
|
||||
private bool _usbFullKeyControllerEnabled;
|
||||
private readonly bool _isFirmwareUpdateAvailableForSixAxisSensor;
|
||||
@ -1107,6 +1108,19 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
// If not, it returns nothing.
|
||||
}
|
||||
|
||||
[CommandCmif(134)] // 6.1.0+
|
||||
// SetNpadUseAnalogStickUseCenterClamp(bool Enable, nn::applet::AppletResourceUserId)
|
||||
public ResultCode SetNpadUseAnalogStickUseCenterClamp(ServiceCtx context)
|
||||
{
|
||||
ulong pid = context.RequestData.ReadUInt64();
|
||||
_npadAnalogStickCenterClampEnabled = context.RequestData.ReadUInt32() != 0;
|
||||
long appletResourceUserId = context.RequestData.ReadInt64();
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { pid, appletResourceUserId, _npadAnalogStickCenterClampEnabled });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(200)]
|
||||
// GetVibrationDeviceInfo(nn::hid::VibrationDeviceHandle) -> nn::hid::VibrationDeviceInfo
|
||||
public ResultCode GetVibrationDeviceInfo(ServiceCtx context)
|
||||
|
@ -13,10 +13,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
|
||||
ResultCode OnTransact(uint code, uint flags, ReadOnlySpan<byte> inputParcel, Span<byte> outputParcel)
|
||||
{
|
||||
Parcel inputParcelReader = new(inputParcel.ToArray());
|
||||
using Parcel inputParcelReader = new(inputParcel);
|
||||
|
||||
// TODO: support objects?
|
||||
Parcel outputParcelWriter = new((uint)(outputParcel.Length - Unsafe.SizeOf<ParcelHeader>()), 0);
|
||||
using Parcel outputParcelWriter = new((uint)(outputParcel.Length - Unsafe.SizeOf<ParcelHeader>()), 0);
|
||||
|
||||
string inputInterfaceToken = inputParcelReader.ReadInterfaceToken();
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.HLE.HOS.Services.SurfaceFlinger.Types;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -9,13 +11,13 @@ using System.Text;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
{
|
||||
class Parcel
|
||||
sealed class Parcel : IDisposable
|
||||
{
|
||||
private readonly byte[] _rawData;
|
||||
private readonly IMemoryOwner<byte> _rawDataOwner;
|
||||
|
||||
private Span<byte> Raw => new(_rawData);
|
||||
private Span<byte> Raw => _rawDataOwner.Memory.Span;
|
||||
|
||||
private ref ParcelHeader Header => ref MemoryMarshal.Cast<byte, ParcelHeader>(_rawData)[0];
|
||||
private ref ParcelHeader Header => ref MemoryMarshal.Cast<byte, ParcelHeader>(Raw)[0];
|
||||
|
||||
private Span<byte> Payload => Raw.Slice((int)Header.PayloadOffset, (int)Header.PayloadSize);
|
||||
|
||||
@ -24,9 +26,11 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
private int _payloadPosition;
|
||||
private int _objectPosition;
|
||||
|
||||
public Parcel(byte[] rawData)
|
||||
private bool _isDisposed;
|
||||
|
||||
public Parcel(ReadOnlySpan<byte> data)
|
||||
{
|
||||
_rawData = rawData;
|
||||
_rawDataOwner = ByteMemoryPool.RentCopy(data);
|
||||
|
||||
_payloadPosition = 0;
|
||||
_objectPosition = 0;
|
||||
@ -36,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
{
|
||||
uint headerSize = (uint)Unsafe.SizeOf<ParcelHeader>();
|
||||
|
||||
_rawData = new byte[BitUtils.AlignUp<uint>(headerSize + payloadSize + objectsSize, 4)];
|
||||
_rawDataOwner = ByteMemoryPool.RentCleared(BitUtils.AlignUp<uint>(headerSize + payloadSize + objectsSize, 4));
|
||||
|
||||
Header.PayloadSize = payloadSize;
|
||||
Header.ObjectsSize = objectsSize;
|
||||
@ -132,7 +136,9 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
|
||||
// TODO: figure out what this value is
|
||||
|
||||
WriteInplaceObject(new byte[4] { 0, 0, 0, 0 });
|
||||
Span<byte> fourBytes = stackalloc byte[4];
|
||||
|
||||
WriteInplaceObject(fourBytes);
|
||||
}
|
||||
|
||||
public AndroidStrongPointer<T> ReadStrongPointer<T>() where T : unmanaged, IFlattenable
|
||||
@ -219,5 +225,15 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
|
||||
return Raw[..(int)(Header.PayloadSize + Header.ObjectsSize + Unsafe.SizeOf<ParcelHeader>())];
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_isDisposed)
|
||||
{
|
||||
_isDisposed = true;
|
||||
|
||||
_rawDataOwner.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService
|
||||
|
||||
context.Device.System.SurfaceFlinger.SetRenderLayer(layerId);
|
||||
|
||||
Parcel parcel = new(0x28, 0x4);
|
||||
using Parcel parcel = new(0x28, 0x4);
|
||||
|
||||
parcel.WriteObject(producer, "dispdrv\0");
|
||||
|
||||
@ -288,7 +288,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService
|
||||
|
||||
context.Device.System.SurfaceFlinger.SetRenderLayer(layerId);
|
||||
|
||||
Parcel parcel = new(0x28, 0x4);
|
||||
using Parcel parcel = new(0x28, 0x4);
|
||||
|
||||
parcel.WriteObject(producer, "dispdrv\0");
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user