Segmentation.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Ryujinx.Common.Memory;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4. namespace Ryujinx.Graphics.Nvdec.Vp9.Types
  5. {
  6. internal struct Segmentation
  7. {
  8. private static readonly int[] SegFeatureDataSigned = new int[] { 1, 1, 0, 0 };
  9. private static readonly int[] SegFeatureDataMax = new int[] { QuantCommon.MaxQ, Vp9.LoopFilter.MaxLoopFilter, 3, 0 };
  10. public bool Enabled;
  11. public bool UpdateMap;
  12. public byte UpdateData;
  13. public byte AbsDelta;
  14. public bool TemporalUpdate;
  15. public Array8<Array4<short>> FeatureData;
  16. public Array8<uint> FeatureMask;
  17. public int AqAvOffset;
  18. public static byte GetPredProbSegId(ref Array3<byte> segPredProbs, ref MacroBlockD xd)
  19. {
  20. return segPredProbs[xd.GetPredContextSegId()];
  21. }
  22. public void ClearAllSegFeatures()
  23. {
  24. MemoryMarshal.CreateSpan(ref FeatureData[0][0], 8 * 4).Fill(0);
  25. MemoryMarshal.CreateSpan(ref FeatureMask[0], 8).Fill(0);
  26. AqAvOffset = 0;
  27. }
  28. internal void EnableSegFeature(int segmentId, SegLvlFeatures featureId)
  29. {
  30. FeatureMask[segmentId] |= 1u << (int)featureId;
  31. }
  32. internal static int FeatureDataMax(SegLvlFeatures featureId)
  33. {
  34. return SegFeatureDataMax[(int)featureId];
  35. }
  36. internal static int IsSegFeatureSigned(SegLvlFeatures featureId)
  37. {
  38. return SegFeatureDataSigned[(int)featureId];
  39. }
  40. internal void SetSegData(int segmentId, SegLvlFeatures featureId, int segData)
  41. {
  42. Debug.Assert(segData <= SegFeatureDataMax[(int)featureId]);
  43. if (segData < 0)
  44. {
  45. Debug.Assert(SegFeatureDataSigned[(int)featureId] != 0);
  46. Debug.Assert(-segData <= SegFeatureDataMax[(int)featureId]);
  47. }
  48. FeatureData[segmentId][(int)featureId] = (short)segData;
  49. }
  50. internal int IsSegFeatureActive(int segmentId, SegLvlFeatures featureId)
  51. {
  52. return Enabled && (FeatureMask[segmentId] & (1 << (int)featureId)) != 0 ? 1 : 0;
  53. }
  54. internal short GetSegData(int segmentId, SegLvlFeatures featureId)
  55. {
  56. return FeatureData[segmentId][(int)featureId];
  57. }
  58. }
  59. }