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