CaptureBufferEffect.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 DspAddress = System.UInt64;
  26. namespace Ryujinx.Audio.Renderer.Server.Effect
  27. {
  28. /// <summary>
  29. /// Server state for an capture buffer effect.
  30. /// </summary>
  31. public class CaptureBufferEffect : BaseEffect
  32. {
  33. /// <summary>
  34. /// The capture buffer parameter.
  35. /// </summary>
  36. public AuxiliaryBufferParameter Parameter;
  37. /// <summary>
  38. /// Capture buffer state.
  39. /// </summary>
  40. public AuxiliaryBufferAddresses State;
  41. public override EffectType TargetEffectType => EffectType.CaptureBuffer;
  42. public override DspAddress GetWorkBuffer(int index)
  43. {
  44. return WorkBuffers[index].GetReference(true);
  45. }
  46. public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameterVersion1 parameter, PoolMapper mapper)
  47. {
  48. Update(out updateErrorInfo, ref parameter, mapper);
  49. }
  50. public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameterVersion2 parameter, PoolMapper mapper)
  51. {
  52. Update(out updateErrorInfo, ref parameter, mapper);
  53. }
  54. public void Update<T>(out BehaviourParameter.ErrorInfo updateErrorInfo, ref T parameter, PoolMapper mapper) where T : unmanaged, IEffectInParameter
  55. {
  56. Debug.Assert(IsTypeValid(ref parameter));
  57. UpdateParameterBase(ref parameter);
  58. Parameter = MemoryMarshal.Cast<byte, AuxiliaryBufferParameter>(parameter.SpecificData)[0];
  59. IsEnabled = parameter.IsEnabled;
  60. updateErrorInfo = new BehaviourParameter.ErrorInfo();
  61. if (BufferUnmapped || parameter.IsNew)
  62. {
  63. ulong bufferSize = (ulong)Unsafe.SizeOf<int>() * Parameter.BufferStorageSize + (ulong)Unsafe.SizeOf<AuxiliaryBufferHeader>();
  64. bool sendBufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[0], Parameter.SendBufferInfoAddress, bufferSize);
  65. BufferUnmapped = sendBufferUnmapped;
  66. if (!BufferUnmapped)
  67. {
  68. DspAddress sendDspAddress = WorkBuffers[0].GetReference(false);
  69. // NOTE: Nintendo directly interact with the CPU side structure in the processing of the DSP command.
  70. State.SendBufferInfo = sendDspAddress;
  71. State.SendBufferInfoBase = sendDspAddress + (ulong)Unsafe.SizeOf<AuxiliaryBufferHeader>();
  72. State.ReturnBufferInfo = 0;
  73. State.ReturnBufferInfoBase = 0;
  74. }
  75. }
  76. }
  77. public override void UpdateForCommandGeneration()
  78. {
  79. UpdateUsageStateForCommandGeneration();
  80. }
  81. }
  82. }