AuxiliaryBufferEffect.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // Copyright (c) 2019-2021 Ryujinx
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. //
  17. using Ryujinx.Audio.Renderer.Common;
  18. using Ryujinx.Audio.Renderer.Dsp.State;
  19. using Ryujinx.Audio.Renderer.Parameter;
  20. using Ryujinx.Audio.Renderer.Parameter.Effect;
  21. using Ryujinx.Audio.Renderer.Server.MemoryPool;
  22. using System.Diagnostics;
  23. using System.Runtime.CompilerServices;
  24. using System.Runtime.InteropServices;
  25. using static Ryujinx.Audio.Renderer.Dsp.State.AuxiliaryBufferHeader;
  26. using DspAddress = System.UInt64;
  27. namespace Ryujinx.Audio.Renderer.Server.Effect
  28. {
  29. /// <summary>
  30. /// Server state for an auxiliary buffer effect.
  31. /// </summary>
  32. public class AuxiliaryBufferEffect : BaseEffect
  33. {
  34. /// <summary>
  35. /// The auxiliary buffer parameter.
  36. /// </summary>
  37. public AuxiliaryBufferParameter Parameter;
  38. /// <summary>
  39. /// Auxiliary buffer state.
  40. /// </summary>
  41. public AuxiliaryBufferAddresses State;
  42. public override EffectType TargetEffectType => EffectType.AuxiliaryBuffer;
  43. public override DspAddress GetWorkBuffer(int index)
  44. {
  45. return WorkBuffers[index].GetReference(true);
  46. }
  47. public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameterVersion1 parameter, PoolMapper mapper)
  48. {
  49. Update(out updateErrorInfo, ref parameter, mapper);
  50. }
  51. public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameterVersion2 parameter, PoolMapper mapper)
  52. {
  53. Update(out updateErrorInfo, ref parameter, mapper);
  54. }
  55. public void Update<T>(out BehaviourParameter.ErrorInfo updateErrorInfo, ref T parameter, PoolMapper mapper) where T : unmanaged, IEffectInParameter
  56. {
  57. Debug.Assert(IsTypeValid(ref parameter));
  58. UpdateParameterBase(ref parameter);
  59. Parameter = MemoryMarshal.Cast<byte, AuxiliaryBufferParameter>(parameter.SpecificData)[0];
  60. IsEnabled = parameter.IsEnabled;
  61. updateErrorInfo = new BehaviourParameter.ErrorInfo();
  62. if (BufferUnmapped || parameter.IsNew)
  63. {
  64. ulong bufferSize = (ulong)Unsafe.SizeOf<int>() * Parameter.BufferStorageSize + (ulong)Unsafe.SizeOf<AuxiliaryBufferHeader>();
  65. bool sendBufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[0], Parameter.SendBufferInfoAddress, bufferSize);
  66. bool returnBufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[1], Parameter.ReturnBufferInfoAddress, bufferSize);
  67. BufferUnmapped = sendBufferUnmapped && returnBufferUnmapped;
  68. if (!BufferUnmapped)
  69. {
  70. DspAddress sendDspAddress = WorkBuffers[0].GetReference(false);
  71. DspAddress returnDspAddress = WorkBuffers[1].GetReference(false);
  72. State.SendBufferInfo = sendDspAddress + (uint)Unsafe.SizeOf<AuxiliaryBufferInfo>();
  73. State.SendBufferInfoBase = sendDspAddress + (uint)Unsafe.SizeOf<AuxiliaryBufferHeader>();
  74. State.ReturnBufferInfo = returnDspAddress + (uint)Unsafe.SizeOf<AuxiliaryBufferInfo>();
  75. State.ReturnBufferInfoBase = returnDspAddress + (uint)Unsafe.SizeOf<AuxiliaryBufferHeader>();
  76. }
  77. }
  78. }
  79. public override void UpdateForCommandGeneration()
  80. {
  81. UpdateUsageStateForCommandGeneration();
  82. }
  83. }
  84. }