diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/BitDepth.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/BitDepth.cs
index fdf0aff9c..1f0c65c7b 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/BitDepth.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/BitDepth.cs
@@ -6,4 +6,4 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
Bits10 = 10, // < 10 bits
Bits12 = 12, // < 12 bits
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/CodecErr.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/CodecErr.cs
index 3bd149df4..9bcf4ac01 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/CodecErr.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/CodecErr.cs
@@ -1,56 +1,75 @@
-namespace Ryujinx.Graphics.Nvdec.Vp9
+namespace Ryujinx.Graphics.Nvdec.Vp9
{
internal enum CodecErr
{
- /*!\brief Operation completed without error */
- CodecOk,
+ ///
+ /// Operation completed without error
+ ///
+ Ok,
- /*!\brief Unspecified error */
- CodecError,
+ ///
+ /// Unspecified error
+ ///
+ Error,
- /*!\brief Memory operation failed */
- CodecMemError,
+ ///
+ /// Memory operation failed
+ ///
+ MemError,
- /*!\brief ABI version mismatch */
- CodecAbiMismatch,
+ ///
+ /// ABI version mismatch
+ ///
+ AbiMismatch,
- /*!\brief Algorithm does not have required capability */
- CodecIncapable,
+ ///
+ /// Algorithm does not have required capability
+ ///
+ Incapable,
- /*!\brief The given bitstream is not supported.
- *
- * The bitstream was unable to be parsed at the highest level. The decoder
- * is unable to proceed. This error \ref SHOULD be treated as fatal to the
- * stream. */
- CodecUnsupBitstream,
+ ///
+ /// The given bitstream is not supported.
+ ///
+ ///
+ /// The bitstream was unable to be parsed at the highest level.
+ /// The decoder is unable to proceed.
+ /// This error SHOULD be treated as fatal to the stream.
+ ///
+ UnsupBitstream,
- /*!\brief Encoded bitstream uses an unsupported feature
- *
- * The decoder does not implement a feature required by the encoder. This
- * return code should only be used for features that prevent future
- * pictures from being properly decoded. This error \ref MAY be treated as
- * fatal to the stream or \ref MAY be treated as fatal to the current GOP.
- */
- CodecUnsupFeature,
+ ///
+ /// Encoded bitstream uses an unsupported feature
+ ///
+ ///
+ /// The decoder does not implement a feature required by the encoder.
+ /// This return code should only be used for features that prevent future
+ /// pictures from being properly decoded.
+ ///
+ /// This error MAY be treated as fatal to the stream or MAY be treated as fatal to the current GOP.
+ ///
+ UnsupFeature,
- /*!\brief The coded data for this stream is corrupt or incomplete
- *
- * There was a problem decoding the current frame. This return code
- * should only be used for failures that prevent future pictures from
- * being properly decoded. This error \ref MAY be treated as fatal to the
- * stream or \ref MAY be treated as fatal to the current GOP. If decoding
- * is continued for the current GOP, artifacts may be present.
- */
- CodecCorruptFrame,
+ ///
+ /// The coded data for this stream is corrupt or incomplete.
+ ///
+ ///
+ /// There was a problem decoding the current frame.
+ /// This return code should only be used
+ /// for failures that prevent future pictures from being properly decoded.
+ ///
+ /// This error MAY be treated as fatal to the stream or MAY be treated as fatal to the current GOP.
+ /// If decoding is continued for the current GOP, artifacts may be present.
+ ///
+ CorruptFrame,
- /*!\brief An application-supplied parameter is not valid.
- *
- */
- CodecInvalidParam,
+ ///
+ /// An application-supplied parameter is not valid.
+ ///
+ InvalidParam,
- /*!\brief An iterator reached the end of list.
- *
- */
- CodecListEnd,
+ ///
+ /// An iterator reached the end of list.
+ ///
+ ListEnd
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Common/BitUtils.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Common/BitUtils.cs
index 807f1293e..900b9d1c1 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/Common/BitUtils.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Common/BitUtils.cs
@@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte ClipPixel(int val)
{
- return (byte)((val > 255) ? 255 : (val < 0) ? 0 : val);
+ return (byte)(val > 255 ? 255 : val < 0 ? 0 : val);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -56,4 +56,4 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common
return numValues > 0 ? GetMsb(numValues) + 1 : 0;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryAllocator.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryAllocator.cs
index 18ed172f8..2dda25ac0 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryAllocator.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryAllocator.cs
@@ -51,6 +51,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common
{
Marshal.FreeHGlobal(item.Pointer);
}
+
item.Pointer = ptr;
item.Length = lengthInBytes;
break;
@@ -58,7 +59,11 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common
}
}
- return new ArrayPtr(ptr, length);
+ ArrayPtr allocation = new ArrayPtr(ptr, length);
+
+ allocation.AsSpan().Fill(default);
+
+ return allocation;
}
public unsafe void Free(ArrayPtr arr) where T : unmanaged
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryUtil.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryUtil.cs
index afdc6b0b2..66c41f8cc 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryUtil.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryUtil.cs
@@ -20,4 +20,4 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common
new Span(ptr, length).Fill(value);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Constants.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Constants.cs
index 17efb203b..4d7f919e5 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/Constants.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Constants.cs
@@ -1,8 +1,10 @@
+using Ryujinx.Graphics.Nvdec.Vp9.Types;
+
namespace Ryujinx.Graphics.Nvdec.Vp9
{
internal static class Constants
{
- public const int Vp9InterpExtend = 4;
+ public const int InterpExtend = 4;
public const int MaxMbPlane = 3;
@@ -25,6 +27,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
/* Segment Feature Masks */
public const int MaxMvRefCandidates = 2;
+ public const int IntraInterContexts = 4;
public const int CompInterContexts = 5;
public const int RefContexts = 5;
@@ -32,12 +35,26 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
public const int EightTapSmooth = 1;
public const int EightTapSharp = 2;
public const int SwitchableFilters = 3; /* Number of switchable filters */
+
public const int Bilinear = 3;
- public const int Switchable = 4; /* should be the last one */
+
+ // The codec can operate in four possible inter prediction filter mode:
+ // 8-tap, 8-tap-smooth, 8-tap-sharp, and switching between the three.
+ public const int SwitchableFilterContexts = SwitchableFilters + 1;
+ public const int Switchable = 4; /* Should be the last one */
// Frame
public const int RefsPerFrame = 3;
+ public const int RefFramesLog2 = 3;
+ public const int RefFrames = 1 << RefFramesLog2;
+
+ // 1 scratch frame for the new frame, 3 for scaled references on the encoder.
+ public const int FrameBuffers = RefFrames + 4;
+
+ public const int FrameContextsLog2 = 2;
+ public const int FrameContexts = 1 << FrameContextsLog2;
+
public const int NumPingPongBuffers = 2;
public const int Class0Bits = 1; /* bits at integer precision for class 0 */
@@ -48,9 +65,9 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
public const int MvLow = -(1 << MvInUseBits);
// Coefficient token alphabet
- public const int ZeroToken = 0; // 0 Extra Bits 0+0
- public const int OneToken = 1; // 1 Extra Bits 0+1
- public const int TwoToken = 2; // 2 Extra Bits 0+1
+ public const int ZeroToken = 0; // 0 Extra Bits 0+0
+ public const int OneToken = 1; // 1 Extra Bits 0+1
+ public const int TwoToken = 2; // 2 Extra Bits 0+1
public const int PivotNode = 2;
@@ -65,5 +82,19 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
public const int SegmentAbsData = 1;
public const int MaxSegments = 8;
+
+ public const int PartitionTypes = (int)PartitionType.PartitionTypes;
+
+ public const int PartitionPlOffset = 4; // Number of probability models per block size
+ public const int PartitionContexts = 4 * PartitionPlOffset;
+
+ public const int PlaneTypes = (int)PlaneType.PlaneTypes;
+
+ public const int IntraModes = (int)PredictionMode.TmPred + 1;
+
+ public const int InterModes = 1 + (int)PredictionMode.NewMv - (int)PredictionMode.NearestMv;
+
+ public const int SkipContexts = 3;
+ public const int InterModeContexts = 7;
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/DSubExp.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/DSubExp.cs
new file mode 100644
index 000000000..cac1b67f6
--- /dev/null
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/DSubExp.cs
@@ -0,0 +1,47 @@
+using System.Diagnostics;
+
+namespace Ryujinx.Graphics.Nvdec.Vp9
+{
+ internal static class DSubExp
+ {
+ public static int InvRecenterNonneg(int v, int m)
+ {
+ if (v > 2 * m)
+ {
+ return v;
+ }
+
+ return (v & 1) != 0 ? m - ((v + 1) >> 1) : m + (v >> 1);
+ }
+
+ private static readonly byte[] InvMapTable =
+ {
+ 7, 20, 33, 46, 59, 72, 85, 98, 111, 124, 137, 150, 163, 176, 189, 202, 215, 228, 241, 254, 1, 2, 3, 4,
+ 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34,
+ 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62,
+ 63, 64, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90,
+ 91, 92, 93, 94, 95, 96, 97, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114,
+ 115, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
+ 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 177, 178, 179, 180, 181, 182,
+ 183, 184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205,
+ 206, 207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
+ 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 250,
+ 251, 252, 253, 253
+ };
+
+ public static int InvRemapProb(int v, int m)
+ {
+ Debug.Assert(v < InvMapTable.Length / sizeof(byte));
+
+ v = InvMapTable[v];
+ m--;
+ if (m << 1 <= Prob.MaxProb)
+ {
+ return 1 + InvRecenterNonneg(v, m);
+ }
+
+ return Prob.MaxProb - InvRecenterNonneg(v, Prob.MaxProb - 1 - m);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/DecodeFrame.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/DecodeFrame.cs
index 5f03e1afc..e61c9567e 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/DecodeFrame.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/DecodeFrame.cs
@@ -1,4 +1,4 @@
-using Ryujinx.Common.Memory;
+using Ryujinx.Common.Memory;
using Ryujinx.Graphics.Nvdec.Vp9.Common;
using Ryujinx.Graphics.Nvdec.Vp9.Dsp;
using Ryujinx.Graphics.Nvdec.Vp9.Types;
@@ -12,14 +12,96 @@ using System.Threading.Tasks;
namespace Ryujinx.Graphics.Nvdec.Vp9
{
- static class DecodeFrame
+ internal static class DecodeFrame
{
private static bool ReadIsValid(ArrayPtr start, int len)
{
return len != 0 && len <= start.Length;
}
- private static void InverseTransformBlockInter(ref MacroBlockD xd, int plane, TxSize txSize, Span dst, int stride, int eob)
+ private static void ReadTxModeProbs(ref Vp9EntropyProbs txProbs, ref Reader r)
+ {
+ for (int i = 0; i < EntropyMode.TxSizeContexts; ++i)
+ {
+ for (int j = 0; j < (int)TxSize.TxSizes - 3; ++j)
+ {
+ r.DiffUpdateProb(ref txProbs.Tx8x8Prob[i][j]);
+ }
+ }
+
+ for (int i = 0; i < EntropyMode.TxSizeContexts; ++i)
+ {
+ for (int j = 0; j < (int)TxSize.TxSizes - 2; ++j)
+ {
+ r.DiffUpdateProb(ref txProbs.Tx16x16Prob[i][j]);
+ }
+ }
+
+ for (int i = 0; i < EntropyMode.TxSizeContexts; ++i)
+ {
+ for (int j = 0; j < (int)TxSize.TxSizes - 1; ++j)
+ {
+ r.DiffUpdateProb(ref txProbs.Tx32x32Prob[i][j]);
+ }
+ }
+ }
+
+ private static void ReadSwitchableInterpProbs(ref Vp9EntropyProbs fc, ref Reader r)
+ {
+ for (int j = 0; j < Constants.SwitchableFilterContexts; ++j)
+ {
+ for (int i = 0; i < Constants.SwitchableFilters - 1; ++i)
+ {
+ r.DiffUpdateProb(ref fc.SwitchableInterpProb[j][i]);
+ }
+ }
+ }
+
+ private static void ReadInterModeProbs(ref Vp9EntropyProbs fc, ref Reader r)
+ {
+ for (int i = 0; i < Constants.InterModeContexts; ++i)
+ {
+ for (int j = 0; j < Constants.InterModes - 1; ++j)
+ {
+ r.DiffUpdateProb( ref fc.InterModeProb[i][j]);
+ }
+ }
+ }
+
+ private static void ReadMvProbs(ref Vp9EntropyProbs ctx, bool allowHp, ref Reader r)
+ {
+ r.UpdateMvProbs(ctx.Joints.AsSpan(), EntropyMv.Joints - 1);
+
+ for (int i = 0; i < 2; ++i)
+ {
+ r.UpdateMvProbs(MemoryMarshal.CreateSpan(ref ctx.Sign[i], 1), 1);
+ r.UpdateMvProbs(ctx.Classes[i].AsSpan(), EntropyMv.Classes - 1);
+ r.UpdateMvProbs(ctx.Class0[i].AsSpan(), EntropyMv.Class0Size - 1);
+ r.UpdateMvProbs(ctx.Bits[i].AsSpan(), EntropyMv.OffsetBits);
+ }
+
+ for (int i = 0; i < 2; ++i)
+ {
+ for (int j = 0; j < EntropyMv.Class0Size; ++j)
+ {
+ r.UpdateMvProbs(ctx.Class0Fp[i][j].AsSpan(), EntropyMv.FpSize - 1);
+ }
+
+ r.UpdateMvProbs(ctx.Fp[i].AsSpan(), 3);
+ }
+
+ if (allowHp)
+ {
+ for (int i = 0; i < 2; ++i)
+ {
+ r.UpdateMvProbs(MemoryMarshal.CreateSpan(ref ctx.Class0Hp[i], 1), 1);
+ r.UpdateMvProbs(MemoryMarshal.CreateSpan(ref ctx.Hp[i], 1), 1);
+ }
+ }
+ }
+
+ private static void InverseTransformBlockInter(ref MacroBlockD xd, int plane, TxSize txSize, Span dst,
+ int stride, int eob)
{
ref MacroBlockDPlane pd = ref xd.Plane[plane];
ArrayPtr dqcoeff = pd.DqCoeff;
@@ -90,15 +172,15 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
if (txSize <= TxSize.Tx16x16 && eob <= 10)
{
- dqcoeff.AsSpan()[..(4 * (4 << (int)txSize))].Clear();
+ dqcoeff.AsSpan().Slice(0, 4 * (4 << (int)txSize)).Clear();
}
else if (txSize == TxSize.Tx32x32 && eob <= 34)
{
- dqcoeff.AsSpan()[..256].Clear();
+ dqcoeff.AsSpan().Slice(0, 256).Clear();
}
else
{
- dqcoeff.AsSpan()[..(16 << ((int)txSize << 1))].Clear();
+ dqcoeff.AsSpan().Slice(0, 16 << ((int)txSize << 1)).Clear();
}
}
}
@@ -181,15 +263,15 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
if (txType == TxType.DctDct && txSize <= TxSize.Tx16x16 && eob <= 10)
{
- dqcoeff.AsSpan()[..(4 * (4 << (int)txSize))].Clear();
+ dqcoeff.AsSpan().Slice(0, 4 * (4 << (int)txSize)).Clear();
}
else if (txSize == TxSize.Tx32x32 && eob <= 34)
{
- dqcoeff.AsSpan()[..256].Clear();
+ dqcoeff.AsSpan().Slice(0, 256).Clear();
}
else
{
- dqcoeff.AsSpan()[..(16 << ((int)txSize << 1))].Clear();
+ dqcoeff.AsSpan().Slice(0, 16 << ((int)txSize << 1)).Clear();
}
}
}
@@ -204,10 +286,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
ref MacroBlockD xd = ref twd.Xd;
ref MacroBlockDPlane pd = ref xd.Plane[plane];
- PredictionMode mode = (plane == 0) ? mi.Mode : mi.UvMode;
- int dstOffset = 4 * row * pd.Dst.Stride + 4 * col;
+ PredictionMode mode = plane == 0 ? mi.Mode : mi.UvMode;
+ int dstOffset = (4 * row * pd.Dst.Stride) + (4 * col);
byte* dst = &pd.Dst.Buf.ToPointer()[dstOffset];
- Span dstSpan = pd.Dst.Buf.AsSpan()[dstOffset..];
+ Span dstSpan = pd.Dst.Buf.AsSpan().Slice(dstOffset);
if (mi.SbType < BlockSize.Block8x8)
{
@@ -217,15 +299,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
}
- ReconIntra.PredictIntraBlock(ref xd, pd.N4Wl, txSize, mode, dst, pd.Dst.Stride, dst, pd.Dst.Stride, col, row, plane);
+ ReconIntra.PredictIntraBlock(ref xd, pd.N4Wl, txSize, mode, dst, pd.Dst.Stride, dst, pd.Dst.Stride, col,
+ row, plane);
if (mi.Skip == 0)
{
TxType txType =
- (plane != 0 || xd.Lossless) ? TxType.DctDct : ReconIntra.IntraModeToTxTypeLookup[(int)mode];
- var sc = (plane != 0 || xd.Lossless)
- ? Luts.Vp9DefaultScanOrders[(int)txSize]
- : Luts.Vp9ScanOrders[(int)txSize][(int)txType];
+ plane != 0 || xd.Lossless ? TxType.DctDct : ReconIntra.IntraModeToTxTypeLookup[(int)mode];
+ Luts.ScanOrder sc = plane != 0 || xd.Lossless
+ ? Luts.DefaultScanOrders[(int)txSize]
+ : Luts.ScanOrders[(int)txSize][(int)txType];
int eob = Detokenize.DecodeBlockTokens(ref twd, plane, sc, col, row, txSize, mi.SegmentId);
if (eob > 0)
{
@@ -244,14 +327,15 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
ref MacroBlockD xd = ref twd.Xd;
ref MacroBlockDPlane pd = ref xd.Plane[plane];
- var sc = Luts.Vp9DefaultScanOrders[(int)txSize];
+ Luts.ScanOrder sc = Luts.DefaultScanOrders[(int)txSize];
int eob = Detokenize.DecodeBlockTokens(ref twd, plane, sc, col, row, txSize, mi.SegmentId);
- Span dst = pd.Dst.Buf.AsSpan()[(4 * row * pd.Dst.Stride + 4 * col)..];
+ Span dst = pd.Dst.Buf.AsSpan().Slice((4 * row * pd.Dst.Stride) + (4 * col));
if (eob > 0)
{
InverseTransformBlockInter(ref xd, plane, txSize, dst, pd.Dst.Stride, eob);
}
+
return eob;
}
@@ -268,7 +352,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int h)
{
// Get a pointer to the start of the real data for this row.
- byte* refRow = src - x - y * srcStride;
+ byte* refRow = src - x - (y * srcStride);
if (y >= h)
{
@@ -340,7 +424,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
// Get a pointer to the start of the real data for this row.
ushort* src = (ushort*)src8;
- ushort* refRow = src - x - y * srcStride;
+ ushort* refRow = src - x - (y * srcStride);
if (y >= h)
{
@@ -483,9 +567,9 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int refr)
{
ref MacroBlockDPlane pd = ref xd.Plane[plane];
- byte* dst = dstBuf.Buf.ToPointer() + dstBuf.Stride * y + x;
+ byte* dst = dstBuf.Buf.ToPointer() + (dstBuf.Stride * y) + x;
Mv32 scaledMv;
- int xs, ys, x0, y0, x0_16, y0_16, frameWidth, frameHeight, bufStride, subpelX, subpelY;
+ int xs, ys, x0, y0, x016, y016, frameWidth, frameHeight, bufStride, subpelX, subpelY;
byte* refFrame;
byte* bufPtr;
@@ -507,16 +591,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
Mv mvQ4 = ReconInter.ClampMvToUmvBorderSb(ref xd, ref mv, bw, bh, pd.SubsamplingX, pd.SubsamplingY);
// Co-ordinate of containing block to pixel precision.
- int xStart = (-xd.MbToLeftEdge >> (3 + pd.SubsamplingX));
- int yStart = (-xd.MbToTopEdge >> (3 + pd.SubsamplingY));
+ int xStart = -xd.MbToLeftEdge >> (3 + pd.SubsamplingX);
+ int yStart = -xd.MbToTopEdge >> (3 + pd.SubsamplingY);
// Co-ordinate of the block to 1/16th pixel precision.
- x0_16 = (xStart + x) << Filter.SubpelBits;
- y0_16 = (yStart + y) << Filter.SubpelBits;
+ x016 = (xStart + x) << Filter.SubpelBits;
+ y016 = (yStart + y) << Filter.SubpelBits;
// Co-ordinate of current block in reference frame
// to 1/16th pixel precision.
- x0_16 = sf.ScaleValueX(x0_16);
- y0_16 = sf.ScaleValueY(y0_16);
+ x016 = sf.ScaleValueX(x016);
+ y016 = sf.ScaleValueY(y016);
// Map the top left corner of the block into the reference frame.
x0 = sf.ScaleValueX(xStart + x);
@@ -535,13 +619,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
y0 = (-xd.MbToTopEdge >> (3 + pd.SubsamplingY)) + y;
// Co-ordinate of the block to 1/16th pixel precision.
- x0_16 = x0 << Filter.SubpelBits;
- y0_16 = y0 << Filter.SubpelBits;
+ x016 = x0 << Filter.SubpelBits;
+ y016 = y0 << Filter.SubpelBits;
scaledMv.Row = mv.Row * (1 << (1 - pd.SubsamplingY));
scaledMv.Col = mv.Col * (1 << (1 - pd.SubsamplingX));
xs = ys = 16;
}
+
subpelX = scaledMv.Col & Filter.SubpelMask;
subpelY = scaledMv.Row & Filter.SubpelMask;
@@ -549,34 +634,35 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
// reference frame.
x0 += scaledMv.Col >> Filter.SubpelBits;
y0 += scaledMv.Row >> Filter.SubpelBits;
- x0_16 += scaledMv.Col;
- y0_16 += scaledMv.Row;
+ x016 += scaledMv.Col;
+ y016 += scaledMv.Row;
// Get reference block pointer.
- bufPtr = refFrame + y0 * preBuf.Stride + x0;
+ bufPtr = refFrame + (y0 * preBuf.Stride) + x0;
bufStride = preBuf.Stride;
// Do border extension if there is motion or the
// width/height is not a multiple of 8 pixels.
- if (isScaled || scaledMv.Col != 0 || scaledMv.Row != 0 || (frameWidth & 0x7) != 0 || (frameHeight & 0x7) != 0)
+ if (isScaled || scaledMv.Col != 0 || scaledMv.Row != 0 || (frameWidth & 0x7) != 0 ||
+ (frameHeight & 0x7) != 0)
{
- int y1 = ((y0_16 + (h - 1) * ys) >> Filter.SubpelBits) + 1;
+ int y1 = ((y016 + ((h - 1) * ys)) >> Filter.SubpelBits) + 1;
// Get reference block bottom right horizontal coordinate.
- int x1 = ((x0_16 + (w - 1) * xs) >> Filter.SubpelBits) + 1;
+ int x1 = ((x016 + ((w - 1) * xs)) >> Filter.SubpelBits) + 1;
int xPad = 0, yPad = 0;
- if (subpelX != 0 || (sf.XStepQ4 != Filter.SubpelShifts))
+ if (subpelX != 0 || sf.XStepQ4 != Filter.SubpelShifts)
{
- x0 -= Constants.Vp9InterpExtend - 1;
- x1 += Constants.Vp9InterpExtend;
+ x0 -= Constants.InterpExtend - 1;
+ x1 += Constants.InterpExtend;
xPad = 1;
}
- if (subpelY != 0 || (sf.YStepQ4 != Filter.SubpelShifts))
+ if (subpelY != 0 || sf.YStepQ4 != Filter.SubpelShifts)
{
- y0 -= Constants.Vp9InterpExtend - 1;
- y1 += Constants.Vp9InterpExtend;
+ y0 -= Constants.InterpExtend - 1;
+ y1 += Constants.InterpExtend;
yPad = 1;
}
@@ -585,10 +671,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
y0 < 0 || y0 > frameHeight - 1 || y1 < 0 || y1 > frameHeight - 1)
{
// Extend the border.
- byte* bufPtr1 = refFrame + y0 * bufStride + x0;
+ byte* bufPtr1 = refFrame + (y0 * bufStride) + x0;
int bW = x1 - x0 + 1;
int bH = y1 - y0 + 1;
- int borderOffset = yPad * 3 * bW + xPad * 3;
+ int borderOffset = (yPad * 3 * bW) + (xPad * 3);
ExtendAndPredict(
bufPtr1,
@@ -612,7 +698,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
refr,
xs,
ys);
-
return;
}
}
@@ -660,7 +745,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int miX = miCol * Constants.MiSize;
int miY = miRow * Constants.MiSize;
ref ModeInfo mi = ref xd.Mi[0].Value;
- Array8[] kernel = Luts.Vp9FilterKernels[mi.InterpFilter];
+ Array8[] kernel = Luts.FilterKernels[mi.InterpFilter];
BlockSize sbType = mi.SbType;
int isCompound = mi.HasSecondRef() ? 1 : 0;
int refr;
@@ -675,11 +760,13 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (!sf.IsValidScale())
{
- xd.ErrorInfo.Value.InternalError(CodecErr.CodecUnsupBitstream, "Reference frame has invalid dimensions");
+ xd.ErrorInfo.Value.InternalError(CodecErr.UnsupBitstream,
+ "Reference frame has invalid dimensions");
}
isScaled = sf.IsScaled();
- ReconInter.SetupPrePlanes(ref xd, refr, ref refFrameBuf, miRow, miCol, isScaled ? new Ptr(ref sf) : Ptr.Null);
+ ReconInter.SetupPrePlanes(ref xd, refr, ref refFrameBuf, miRow, miCol,
+ isScaled ? new Ptr(ref sf) : Ptr.Null);
xd.BlockRefs[refr] = new Ptr(ref refBuf);
if (sbType < BlockSize.Block8x8)
@@ -693,10 +780,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int n4Wx4 = 4 * num4x4W;
int n4Hx4 = 4 * num4x4H;
ref Buf2D preBuf = ref pd.Pre[refr];
- int i = 0, x, y;
- for (y = 0; y < num4x4H; ++y)
+ int i = 0;
+ for (int y = 0; y < num4x4H; ++y)
{
- for (x = 0; x < num4x4W; ++x)
+ for (int x = 0; x < num4x4W; ++x)
{
Mv mv = ReconInter.AverageSplitMvs(ref pd, ref mi, refr, i++);
DecBuildInterPredictors(
@@ -758,21 +845,9 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
}
- private static unsafe void DecResetSkipContext(ref MacroBlockD xd)
- {
- int i;
- for (i = 0; i < Constants.MaxMbPlane; i++)
- {
- ref MacroBlockDPlane pd = ref xd.Plane[i];
- MemoryUtil.Fill(pd.AboveContext.ToPointer(), (sbyte)0, pd.N4W);
- MemoryUtil.Fill(pd.LeftContext.ToPointer(), (sbyte)0, pd.N4H);
- }
- }
-
private static void SetPlaneN4(ref MacroBlockD xd, int bw, int bh, int bwl, int bhl)
{
- int i;
- for (i = 0; i < Constants.MaxMbPlane; i++)
+ for (int i = 0; i < Constants.MaxMbPlane; i++)
{
xd.Plane[i].N4W = (ushort)((bw << 1) >> xd.Plane[i].SubsamplingX);
xd.Plane[i].N4H = (ushort)((bh << 1) >> xd.Plane[i].SubsamplingY);
@@ -794,18 +869,18 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int bwl,
int bhl)
{
- int offset = miRow * cm.MiStride + miCol;
- int x, y;
+ int offset = (miRow * cm.MiStride) + miCol;
+
ref TileInfo tile = ref xd.Tile;
xd.Mi = cm.MiGridVisible.Slice(offset);
xd.Mi[0] = new Ptr(ref cm.Mi[offset]);
xd.Mi[0].Value.SbType = bsize;
- for (y = 0; y < yMis; ++y)
+ for (int y = 0; y < yMis; ++y)
{
- for (x = y == 0 ? 1 : 0; x < xMis; ++x)
+ for (int x = y == 0 ? 1 : 0; x < xMis; ++x)
{
- xd.Mi[y * cm.MiStride + x] = xd.Mi[0];
+ xd.Mi[(y * cm.MiStride) + x] = xd.Mi[0];
}
}
@@ -818,7 +893,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
xd.SetMiRowCol(ref tile, miRow, bh, miCol, bw, cm.MiRows, cm.MiCols);
ReconInter.SetupDstPlanes(ref xd.Plane, ref xd.CurBuf, miRow, miCol);
-
return ref xd.Mi[0].Value;
}
@@ -846,7 +920,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
BlockSize uvSubsize = Luts.SsSizeLookup[(int)bsize][cm.SubsamplingX][cm.SubsamplingY];
if (uvSubsize == BlockSize.BlockInvalid)
{
- xd.ErrorInfo.Value.InternalError(CodecErr.CodecCorruptFrame, "Invalid block size.");
+ xd.ErrorInfo.Value.InternalError(CodecErr.CorruptFrame, "Invalid block size.");
}
}
@@ -854,7 +928,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (mi.Skip != 0)
{
- DecResetSkipContext(ref xd);
+ xd.DecResetSkipContext();
}
if (!mi.IsInterBlock())
@@ -868,8 +942,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int num4x4H = pd.N4H;
int step = 1 << (int)txSize;
int row, col;
- int maxBlocksWide = num4x4W + (xd.MbToRightEdge >= 0 ? 0 : xd.MbToRightEdge >> (5 + pd.SubsamplingX));
- int maxBlocksHigh = num4x4H + (xd.MbToBottomEdge >= 0 ? 0 : xd.MbToBottomEdge >> (5 + pd.SubsamplingY));
+ int maxBlocksWide =
+ num4x4W + (xd.MbToRightEdge >= 0 ? 0 : xd.MbToRightEdge >> (5 + pd.SubsamplingX));
+ int maxBlocksHigh =
+ num4x4H + (xd.MbToBottomEdge >= 0 ? 0 : xd.MbToBottomEdge >> (5 + pd.SubsamplingY));
xd.MaxBlocksWide = (uint)(xd.MbToRightEdge >= 0 ? 0 : maxBlocksWide);
xd.MaxBlocksHigh = (uint)(xd.MbToBottomEdge >= 0 ? 0 : maxBlocksHigh);
@@ -902,8 +978,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int num4x4H = pd.N4H;
int step = 1 << (int)txSize;
int row, col;
- int maxBlocksWide = num4x4W + (xd.MbToRightEdge >= 0 ? 0 : xd.MbToRightEdge >> (5 + pd.SubsamplingX));
- int maxBlocksHigh = num4x4H + (xd.MbToBottomEdge >= 0 ? 0 : xd.MbToBottomEdge >> (5 + pd.SubsamplingY));
+ int maxBlocksWide =
+ num4x4W + (xd.MbToRightEdge >= 0 ? 0 : xd.MbToRightEdge >> (5 + pd.SubsamplingX));
+ int maxBlocksHigh = num4x4H +
+ (xd.MbToBottomEdge >= 0 ? 0 : xd.MbToBottomEdge >> (5 + pd.SubsamplingY));
xd.MaxBlocksWide = (uint)(xd.MbToRightEdge >= 0 ? 0 : maxBlocksWide);
xd.MaxBlocksHigh = (uint)(xd.MbToBottomEdge >= 0 ? 0 : maxBlocksHigh);
@@ -932,15 +1010,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
}
- private static int DecPartitionPlaneContext(ref TileWorkerData twd, int miRow, int miCol, int bsl)
- {
- ref sbyte aboveCtx = ref twd.Xd.AboveSegContext[miCol];
- ref sbyte leftCtx = ref twd.Xd.LeftSegContext[miRow & Constants.MiMask];
- int above = (aboveCtx >> bsl) & 1, left = (leftCtx >> bsl) & 1;
-
- return (left * 2 + above) + bsl * Constants.PartitionPloffset;
- }
-
private static void DecUpdatePartitionContext(
ref TileWorkerData twd,
int miRow,
@@ -949,13 +1018,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int bw)
{
Span aboveCtx = twd.Xd.AboveSegContext.Slice(miCol).AsSpan();
- Span leftCtx = MemoryMarshal.CreateSpan(ref twd.Xd.LeftSegContext[miRow & Constants.MiMask], 8 - (miRow & Constants.MiMask));
+ Span leftCtx = MemoryMarshal.CreateSpan(ref twd.Xd.LeftSegContext[miRow & Constants.MiMask],
+ 8 - (miRow & Constants.MiMask));
// Update the partition context at the end notes. Set partition bits
// of block sizes larger than the current one to be one, and partition
// bits of smaller block sizes to be zero.
- aboveCtx[..bw].Fill(Luts.PartitionContextLookup[(int)subsize].Above);
- leftCtx[..bw].Fill(Luts.PartitionContextLookup[(int)subsize].Left);
+ aboveCtx.Slice(0, bw).Fill(Luts.PartitionContextLookup[(int)subsize].Above);
+ leftCtx.Slice(0, bw).Fill(Luts.PartitionContextLookup[(int)subsize].Left);
}
private static PartitionType ReadPartition(
@@ -966,14 +1036,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int hasCols,
int bsl)
{
- int ctx = DecPartitionPlaneContext(ref twd, miRow, miCol, bsl);
+ int ctx = twd.DecPartitionPlaneContext(miRow, miCol, bsl);
ReadOnlySpan probs = MemoryMarshal.CreateReadOnlySpan(ref twd.Xd.PartitionProbs[ctx][0], 3);
PartitionType p;
ref Reader r = ref twd.BitReader;
if (hasRows != 0 && hasCols != 0)
{
- p = (PartitionType)r.ReadTree(Luts.Vp9PartitionTree, probs);
+ p = (PartitionType)r.ReadTree(Luts.PartitionTree, probs);
}
else if (hasRows == 0 && hasCols != 0)
{
@@ -1009,8 +1079,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int hbs = num8x8Wh >> 1;
PartitionType partition;
BlockSize subsize;
- bool hasRows = (miRow + hbs) < cm.MiRows;
- bool hasCols = (miCol + hbs) < cm.MiCols;
+ bool hasRows = miRow + hbs < cm.MiRows;
+ bool hasCols = miCol + hbs < cm.MiCols;
ref MacroBlockD xd = ref twd.Xd;
if (miRow >= cm.MiRows || miCol >= cm.MiCols)
@@ -1063,7 +1133,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
// Update partition context
- if (bsize >= BlockSize.Block8x8 && (bsize == BlockSize.Block8x8 || partition != PartitionType.PartitionSplit))
+ if (bsize >= BlockSize.Block8x8 &&
+ (bsize == BlockSize.Block8x8 || partition != PartitionType.PartitionSplit))
{
DecUpdatePartitionContext(ref twd, miRow, miCol, subsize, num8x8Wh);
}
@@ -1079,15 +1150,257 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
// partition can't be fully read then throw an error.
if (!ReadIsValid(data, readSize))
{
- errorInfo.InternalError(CodecErr.CodecCorruptFrame, "Truncated packet or corrupt tile length");
+ errorInfo.InternalError(CodecErr.CorruptFrame, "Truncated packet or corrupt tile length");
}
if (r.Init(data, readSize))
{
- errorInfo.InternalError(CodecErr.CodecMemError, "Failed to allocate bool decoder 1");
+ errorInfo.InternalError(CodecErr.MemError, "Failed to allocate bool decoder 1");
}
}
+ private static void ReadCoefProbsCommon(ref Array2>>>> coefProbs,
+ ref Reader r, int txSize)
+ {
+ if (r.ReadBit() != 0)
+ {
+ for (int i = 0; i < Constants.PlaneTypes; ++i)
+ {
+ for (int j = 0; j < Entropy.RefTypes; ++j)
+ {
+ for (int k = 0; k < Entropy.CoefBands; ++k)
+ {
+ for (int l = 0; l < Entropy.BAND_COEFF_CONTEXTS(k); ++l)
+ {
+ for (int m = 0; m < Entropy.UnconstrainedNodes; ++m)
+ {
+ r.DiffUpdateProb( ref coefProbs[i][j][k][l][m]);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private static void ReadCoefProbs(ref Vp9EntropyProbs fc, TxMode txMode, ref Reader r)
+ {
+ int maxTxSize = (int)Luts.TxModeToBiggestTxSize[(int)txMode];
+ for (int txSize = (int)TxSize.Tx4x4; txSize <= maxTxSize; ++txSize)
+ {
+ ReadCoefProbsCommon(ref fc.CoefProbs[txSize], ref r, txSize);
+ }
+ }
+
+ private static void SetupLoopfilter(ref Types.LoopFilter lf, ref ReadBitBuffer rb)
+ {
+ lf.FilterLevel = rb.ReadLiteral(6);
+ lf.SharpnessLevel = rb.ReadLiteral(3);
+
+ // Read in loop filter deltas applied at the MB level based on mode or ref
+ // frame.
+ lf.ModeRefDeltaUpdate = false;
+
+ lf.ModeRefDeltaEnabled = rb.ReadBit() != 0;
+ if (lf.ModeRefDeltaEnabled)
+ {
+ lf.ModeRefDeltaUpdate = rb.ReadBit() != 0;
+ if (lf.ModeRefDeltaUpdate)
+ {
+ for (int i = 0; i < LoopFilter.MaxRefLfDeltas; i++)
+ {
+ if (rb.ReadBit() != 0)
+ {
+ lf.RefDeltas[i] = (sbyte)rb.ReadSignedLiteral(6);
+ }
+ }
+
+ for (int i = 0; i < LoopFilter.MaxModeLfDeltas; i++)
+ {
+ if (rb.ReadBit() != 0)
+ {
+ lf.ModeDeltas[i] = (sbyte)rb.ReadSignedLiteral(6);
+ }
+ }
+ }
+ }
+ }
+
+ private static void SetupQuantization(ref Vp9Common cm, ref MacroBlockD xd, ref ReadBitBuffer rb)
+ {
+ cm.BaseQindex = rb.ReadLiteral(QuantCommon.QindexBits);
+ cm.YDcDeltaQ = rb.ReadDeltaQ();
+ cm.UvDcDeltaQ = rb.ReadDeltaQ();
+ cm.UvAcDeltaQ = rb.ReadDeltaQ();
+ cm.DequantBitDepth = cm.BitDepth;
+ xd.Lossless = cm.BaseQindex == 0 && cm.YDcDeltaQ == 0 && cm.UvDcDeltaQ == 0 && cm.UvAcDeltaQ == 0;
+
+ xd.Bd = (int)cm.BitDepth;
+ }
+
+ private static readonly byte[] LiteralToFilter =
+ {
+ Constants.EightTapSmooth, Constants.EightTap, Constants.EightTapSharp, Constants.Bilinear
+ };
+
+ private static byte ReadInterpFilter(ref ReadBitBuffer rb)
+ {
+ return rb.ReadBit() != 0
+ ? (byte)Constants.Switchable
+ : LiteralToFilter[rb.ReadLiteral(2)];
+ }
+
+ private static void SetupRenderSize(ref Vp9Common cm, ref ReadBitBuffer rb)
+ {
+ cm.RenderWidth = cm.Width;
+ cm.RenderHeight = cm.Height;
+ if (rb.ReadBit() != 0)
+ {
+ rb.ReadFrameSize(out cm.RenderWidth, out cm.RenderHeight);
+ }
+ }
+
+ private static void SetupFrameSize(MemoryAllocator allocator, ref Vp9Common cm, ref ReadBitBuffer rb)
+ {
+ int width = 0, height = 0;
+ ref BufferPool pool = ref cm.BufferPool.Value;
+ rb.ReadFrameSize(out width, out height);
+ cm.ResizeContextBuffers(allocator, width, height);
+ SetupRenderSize(ref cm, ref rb);
+
+ if (cm.GetFrameNewBuffer().ReallocFrameBuffer(
+ allocator,
+ cm.Width,
+ cm.Height,
+ cm.SubsamplingX,
+ cm.SubsamplingY,
+ cm.UseHighBitDepth,
+ Surface.DecBorderInPixels,
+ cm.ByteAlignment,
+ new Ptr(ref pool.FrameBufs[cm.NewFbIdx].RawFrameBuffer),
+ FrameBuffers.GetFrameBuffer,
+ pool.CbPriv) != 0)
+ {
+ cm.Error.InternalError(CodecErr.MemError, "Failed to allocate frame buffer");
+ }
+
+ pool.FrameBufs[cm.NewFbIdx].Released = 0;
+ pool.FrameBufs[cm.NewFbIdx].Buf.SubsamplingX = cm.SubsamplingX;
+ pool.FrameBufs[cm.NewFbIdx].Buf.SubsamplingY = cm.SubsamplingY;
+ pool.FrameBufs[cm.NewFbIdx].Buf.BitDepth = (uint)cm.BitDepth;
+ pool.FrameBufs[cm.NewFbIdx].Buf.ColorSpace = cm.ColorSpace;
+ pool.FrameBufs[cm.NewFbIdx].Buf.ColorRange = cm.ColorRange;
+ pool.FrameBufs[cm.NewFbIdx].Buf.RenderWidth = cm.RenderWidth;
+ pool.FrameBufs[cm.NewFbIdx].Buf.RenderHeight = cm.RenderHeight;
+ }
+
+ private static bool ValidRefFrameImgFmt(
+ BitDepth refBitDepth,
+ int refXss, int refYss,
+ BitDepth thisBitDepth,
+ int thisXss,
+ int thisYss)
+ {
+ return refBitDepth == thisBitDepth && refXss == thisXss && refYss == thisYss;
+ }
+
+ private static void SetupFrameSizeWithRefs(MemoryAllocator allocator, ref Vp9Common cm,
+ ref ReadBitBuffer rb)
+ {
+ int width = 0, height = 0;
+ bool found = false;
+
+ bool hasValidRefFrame = false;
+ ref BufferPool pool = ref cm.BufferPool.Value;
+ for (int i = 0; i < Constants.RefsPerFrame; ++i)
+ {
+ if (rb.ReadBit() != 0)
+ {
+ if (cm.FrameRefs[i].Idx != RefBuffer.InvalidIdx)
+ {
+ ref Surface buf = ref cm.FrameRefs[i].Buf;
+ width = buf.YCropWidth;
+ height = buf.YCropHeight;
+ found = true;
+ break;
+ }
+
+ cm.Error.InternalError(CodecErr.CorruptFrame, "Failed to decode frame size");
+ }
+ }
+
+ if (!found)
+ {
+ rb.ReadFrameSize(out width, out height);
+ }
+
+ if (width <= 0 || height <= 0)
+ {
+ cm.Error.InternalError(CodecErr.CorruptFrame, "Invalid frame size");
+ }
+
+ // Check to make sure at least one of frames that this frame references
+ // has valid dimensions.
+ for (int i = 0; i < Constants.RefsPerFrame; ++i)
+ {
+ ref RefBuffer refFrame = ref cm.FrameRefs[i];
+ hasValidRefFrame |=
+ refFrame.Idx != RefBuffer.InvalidIdx &&
+ ScaleFactors.ValidRefFrameSize(refFrame.Buf.YCropWidth, refFrame.Buf.YCropHeight, width,
+ height);
+ }
+
+ if (!hasValidRefFrame)
+ {
+ cm.Error.InternalError(CodecErr.CorruptFrame, "Referenced frame has invalid size");
+ }
+
+ for (int i = 0; i < Constants.RefsPerFrame; ++i)
+ {
+ ref RefBuffer refFrame = ref cm.FrameRefs[i];
+ if (refFrame.Idx == RefBuffer.InvalidIdx ||
+ !ValidRefFrameImgFmt(
+ (BitDepth)refFrame.Buf.BitDepth,
+ refFrame.Buf.SubsamplingX,
+ refFrame.Buf.SubsamplingY,
+ cm.BitDepth,
+ cm.SubsamplingX,
+ cm.SubsamplingY))
+ {
+ cm.Error.InternalError(CodecErr.CorruptFrame,
+ "Referenced frame has incompatible color format");
+ }
+ }
+
+ cm.ResizeContextBuffers(allocator, width, height);
+ SetupRenderSize(ref cm, ref rb);
+
+ if (cm.GetFrameNewBuffer().ReallocFrameBuffer(
+ allocator,
+ cm.Width,
+ cm.Height,
+ cm.SubsamplingX,
+ cm.SubsamplingY,
+ cm.UseHighBitDepth,
+ Surface.DecBorderInPixels,
+ cm.ByteAlignment,
+ new Ptr(ref pool.FrameBufs[cm.NewFbIdx].RawFrameBuffer),
+ FrameBuffers.GetFrameBuffer,
+ pool.CbPriv) != 0)
+ {
+ cm.Error.InternalError(CodecErr.MemError, "Failed to allocate frame buffer");
+ }
+
+ pool.FrameBufs[cm.NewFbIdx].Released = 0;
+ pool.FrameBufs[cm.NewFbIdx].Buf.SubsamplingX = cm.SubsamplingX;
+ pool.FrameBufs[cm.NewFbIdx].Buf.SubsamplingY = cm.SubsamplingY;
+ pool.FrameBufs[cm.NewFbIdx].Buf.BitDepth = (uint)cm.BitDepth;
+ pool.FrameBufs[cm.NewFbIdx].Buf.ColorSpace = cm.ColorSpace;
+ pool.FrameBufs[cm.NewFbIdx].Buf.ColorRange = cm.ColorRange;
+ pool.FrameBufs[cm.NewFbIdx].Buf.RenderWidth = cm.RenderWidth;
+ pool.FrameBufs[cm.NewFbIdx].Buf.RenderHeight = cm.RenderHeight;
+ }
+
// Reads the next tile returning its size and adjusting '*data' accordingly
// based on 'isLast'.
private static void GetTileBuffer(
@@ -1102,7 +1415,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
if (!ReadIsValid(data, 4))
{
- errorInfo.InternalError(CodecErr.CodecCorruptFrame, "Truncated packet or corrupt tile length");
+ errorInfo.InternalError(CodecErr.CorruptFrame, "Truncated packet or corrupt tile length");
}
size = BinaryPrimitives.ReadInt32BigEndian(data.AsSpan());
@@ -1110,7 +1423,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (size > data.Length)
{
- errorInfo.InternalError(CodecErr.CodecCorruptFrame, "Truncated packet or corrupt tile size");
+ errorInfo.InternalError(CodecErr.CorruptFrame, "Truncated packet or corrupt tile size");
}
}
else
@@ -1124,11 +1437,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
data = data.Slice(size);
}
- private static void GetTileBuffers(ref Vp9Common cm, ArrayPtr data, int tileCols, ref Array64 tileBuffers)
+ private static void GetTileBuffers(ref Vp9Common cm, ArrayPtr data, int tileCols,
+ ref Array64 tileBuffers)
{
- int c;
-
- for (c = 0; c < tileCols; ++c)
+ for (int c = 0; c < tileCols; ++c)
{
bool isLast = c == tileCols - 1;
ref TileBuffer buf = ref tileBuffers[c];
@@ -1144,13 +1456,11 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int tileRows,
ref Array4> tileBuffers)
{
- int r, c;
-
- for (r = 0; r < tileRows; ++r)
+ for (int r = 0; r < tileRows; ++r)
{
- for (c = 0; c < tileCols; ++c)
+ for (int c = 0; c < tileCols; ++c)
{
- bool isLast = (r == tileRows - 1) && (c == tileCols - 1);
+ bool isLast = r == tileRows - 1 && c == tileCols - 1;
ref TileBuffer buf = ref tileBuffers[r][c];
GetTileBuffer(isLast, ref cm.Error, ref data, ref buf);
}
@@ -1167,7 +1477,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int miRow, miCol;
Debug.Assert(tileRows <= 4);
- Debug.Assert(tileCols <= (1 << 6));
+ Debug.Assert(tileCols <= 1 << 6);
// Note: this memset assumes above_context[0], [1] and [2]
// are allocated as part of the same buffer.
@@ -1183,7 +1493,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
for (tileCol = 0; tileCol < tileCols; ++tileCol)
{
ref TileBuffer buf = ref tileBuffers[tileRow][tileCol];
- ref TileWorkerData tileData = ref cm.TileWorkerData[tileCols * tileRow + tileCol];
+ ref TileWorkerData tileData = ref cm.TileWorkerData[(tileCols * tileRow) + tileCol];
tileData.Xd = cm.Mb;
tileData.Xd.Corrupted = false;
tileData.Xd.Counts = cm.Counts;
@@ -1203,7 +1513,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
for (tileCol = 0; tileCol < tileCols; ++tileCol)
{
int col = tileCol;
- ref TileWorkerData tileData = ref cm.TileWorkerData[tileCols * tileRow + col];
+ ref TileWorkerData tileData = ref cm.TileWorkerData[(tileCols * tileRow) + col];
tile.SetCol(ref cm, col);
tileData.Xd.LeftContext = new Array3>();
tileData.Xd.LeftSegContext = new Array8();
@@ -1211,20 +1521,22 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
DecodePartition(ref tileData, ref cm, miRow, miCol, BlockSize.Block64x64, 4);
}
+
cm.Mb.Corrupted |= tileData.Xd.Corrupted;
if (cm.Mb.Corrupted)
{
- cm.Error.InternalError(CodecErr.CodecCorruptFrame, "Failed to decode tile data");
+ cm.Error.InternalError(CodecErr.CorruptFrame, "Failed to decode tile data");
}
}
}
}
// Get last tile data.
- return cm.TileWorkerData[tileCols * tileRows - 1].BitReader.FindEnd();
+ return cm.TileWorkerData[(tileCols * tileRows) - 1].BitReader.FindEnd();
}
- private static bool DecodeTileCol(ref TileWorkerData tileData, ref Vp9Common cm, ref Array64 tileBuffers)
+ private static bool DecodeTileCol(ref TileWorkerData tileData, ref Vp9Common cm,
+ ref Array64 tileBuffers)
{
ref TileInfo tile = ref tileData.Xd.Tile;
int finalCol = (1 << cm.Log2TileCols) - 1;
@@ -1262,7 +1574,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
} while (!tileData.Xd.Corrupted && ++n <= tileData.BufEnd);
tileData.DataEnd = bitReaderEnd;
-
return !tileData.Xd.Corrupted;
}
@@ -1276,9 +1587,11 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int numWorkers = Math.Min(maxThreads, tileCols);
int n;
- Debug.Assert(tileCols <= (1 << 6));
+ Debug.Assert(tileCols <= 1 << 6);
Debug.Assert(tileRows == 1);
+ LoopFilter.ResetLfm(ref cm);
+
cm.AboveContext.AsSpan().Clear();
cm.AboveSegContext.AsSpan().Clear();
@@ -1295,13 +1608,13 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
GetTileBuffers(ref cm, data, tileCols, ref tileBuffers);
- tileBuffers.AsSpan()[..tileCols].Sort(CompareTileBuffers);
+ tileBuffers.AsSpan().Slice(0, tileCols).Sort(CompareTileBuffers);
if (numWorkers == tileCols)
{
TileBuffer largest = tileBuffers[0];
Span buffers = tileBuffers.AsSpan();
- buffers[1..].CopyTo(buffers[..(tileBuffers.Length - 1)]);
+ buffers.Slice(1).CopyTo(buffers.Slice(0, tileBuffers.Length - 1));
tileBuffers[tileCols - 1] = largest;
}
else
@@ -1327,7 +1640,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
for (n = 0; n < numWorkers; ++n)
{
- int count = baseVal + (remain + n) / numWorkers;
+ int count = baseVal + ((remain + n) / numWorkers);
ref TileWorkerData tileData = ref cm.TileWorkerData[n + totalTiles];
tileData.BufStart = bufStart;
@@ -1364,7 +1677,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
Debug.Assert(!bitReaderEnd.IsNull || cm.Mb.Corrupted);
-
return bitReaderEnd;
}
@@ -1383,5 +1695,477 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
a[i] += c[i];
}
}
+
+ private static void ErrorHandler(Ptr data)
+ {
+ ref Vp9Common cm = ref data.Value;
+ cm.Error.InternalError(CodecErr.CorruptFrame, "Truncated packet");
+ }
+
+ private static void FlushAllFbOnKey(ref Vp9Common cm)
+ {
+ if (cm.FrameType == FrameType.KeyFrame && cm.CurrentVideoFrame > 0)
+ {
+ ref Array12 frameBufs = ref cm.BufferPool.Value.FrameBufs;
+ ref BufferPool pool = ref cm.BufferPool.Value;
+
+ for (int i = 0; i < Constants.FrameBuffers; ++i)
+ {
+ if (i == cm.NewFbIdx)
+ {
+ continue;
+ }
+
+ frameBufs[i].RefCount = 0;
+ if (frameBufs[i].Released == 0)
+ {
+ FrameBuffers.ReleaseFrameBuffer(pool.CbPriv, ref frameBufs[i].RawFrameBuffer);
+ frameBufs[i].Released = 1;
+ }
+ }
+ }
+ }
+
+ private const int SyncCode0 = 0x49;
+ private const int SyncCode1 = 0x83;
+ private const int SyncCode2 = 0x42;
+
+ private const int FrameMarker = 0x2;
+
+ private static bool ReadSyncCode(ref ReadBitBuffer rb)
+ {
+ return rb.ReadLiteral(8) == SyncCode0 &&
+ rb.ReadLiteral(8) == SyncCode1 &&
+ rb.ReadLiteral(8) == SyncCode2;
+ }
+
+ private static void RefCntFb(ref Array12 bufs, ref int idx, int newIdx)
+ {
+ int refIndex = idx;
+
+ if (refIndex >= 0 && bufs[refIndex].RefCount > 0)
+ {
+ bufs[refIndex].RefCount--;
+ }
+
+ idx = newIdx;
+
+ bufs[newIdx].RefCount++;
+ }
+
+ private static ulong ReadUncompressedHeader(MemoryAllocator allocator, ref Vp9Decoder pbi,
+ ref ReadBitBuffer rb)
+ {
+ ref Vp9Common cm = ref pbi.Common;
+ ref BufferPool pool = ref cm.BufferPool.Value;
+ ref Array12 frameBufs = ref pool.FrameBufs;
+ int mask, refIndex = 0;
+ ulong sz;
+
+ cm.LastFrameType = cm.FrameType;
+ cm.LastIntraOnly = cm.IntraOnly;
+
+ if (rb.ReadLiteral(2) != FrameMarker)
+ {
+ cm.Error.InternalError(CodecErr.UnsupBitstream, "Invalid frame marker");
+ }
+
+ cm.Profile = rb.ReadProfile();
+ if (cm.Profile >= BitstreamProfile.MaxProfiles)
+ {
+ cm.Error.InternalError(CodecErr.UnsupBitstream, "Unsupported bitstream profile");
+ }
+
+ cm.ShowExistingFrame = rb.ReadBit();
+ if (cm.ShowExistingFrame != 0)
+ {
+ // Show an existing frame directly.
+ int frameToShow = cm.RefFrameMap[rb.ReadLiteral(3)];
+ if (frameToShow < 0 || frameBufs[frameToShow].RefCount < 1)
+ {
+ cm.Error.InternalError(CodecErr.UnsupBitstream,
+ $"Buffer {frameToShow} does not contain a decoded frame");
+ }
+
+ RefCntFb(ref frameBufs, ref cm.NewFbIdx, frameToShow);
+ pbi.RefreshFrameFlags = 0;
+ cm.Lf.FilterLevel = 0;
+ cm.ShowFrame = 1;
+
+ return 0;
+ }
+
+ cm.FrameType = (FrameType)rb.ReadBit();
+ cm.ShowFrame = rb.ReadBit();
+ cm.ErrorResilientMode = rb.ReadBit();
+
+ if (cm.FrameType == FrameType.KeyFrame)
+ {
+ if (!ReadSyncCode(ref rb))
+ {
+ cm.Error.InternalError(CodecErr.UnsupBitstream, "Invalid frame sync code");
+ }
+
+ cm.ReadBitdepthColorspaceSampling(ref rb);
+ pbi.RefreshFrameFlags = (1 << Constants.RefFrames) - 1;
+
+ for (int i = 0; i < Constants.RefsPerFrame; ++i)
+ {
+ cm.FrameRefs[i].Idx = RefBuffer.InvalidIdx;
+ cm.FrameRefs[i].Buf = default;
+ }
+
+ SetupFrameSize(allocator, ref cm, ref rb);
+ if (pbi.NeedResync != 0)
+ {
+ cm.RefFrameMap.AsSpan().Fill(-1);
+ FlushAllFbOnKey(ref cm);
+ pbi.NeedResync = 0;
+ }
+ }
+ else
+ {
+ cm.IntraOnly = (cm.ShowFrame != 0 ? 0 : rb.ReadBit()) != 0;
+
+ cm.ResetFrameContext = cm.ErrorResilientMode != 0 ? 0 : rb.ReadLiteral(2);
+
+ if (cm.IntraOnly)
+ {
+ if (!ReadSyncCode(ref rb))
+ {
+ cm.Error.InternalError(CodecErr.UnsupBitstream, "Invalid frame sync code");
+ }
+
+ if (cm.Profile > BitstreamProfile.Profile0)
+ {
+ cm.ReadBitdepthColorspaceSampling(ref rb);
+ }
+ else
+ {
+ // NOTE: The intra-only frame header does not include the specification
+ // of either the color format or color sub-sampling in profile 0. VP9
+ // specifies that the default color format should be YUV 4:2:0 in this
+ // case (normative).
+ cm.ColorSpace = VpxColorSpace.Bt601;
+ cm.ColorRange = VpxColorRange.Studio;
+ cm.SubsamplingY = cm.SubsamplingX = 1;
+ cm.BitDepth = BitDepth.Bits8;
+ cm.UseHighBitDepth = false;
+ }
+
+ pbi.RefreshFrameFlags = rb.ReadLiteral(Constants.RefFrames);
+ SetupFrameSize(allocator, ref cm, ref rb);
+ if (pbi.NeedResync != 0)
+ {
+ cm.RefFrameMap.AsSpan().Fill(-1);
+ pbi.NeedResync = 0;
+ }
+ }
+ else if (pbi.NeedResync != 1)
+ {
+ /* Skip if need resync */
+ pbi.RefreshFrameFlags = rb.ReadLiteral(Constants.RefFrames);
+ for (int i = 0; i < Constants.RefsPerFrame; ++i)
+ {
+ int refr = rb.ReadLiteral(Constants.RefFramesLog2);
+ int idx = cm.RefFrameMap[refr];
+ ref RefBuffer refFrame = ref cm.FrameRefs[i];
+ refFrame.Idx = idx;
+ refFrame.Buf = frameBufs[idx].Buf;
+ cm.RefFrameSignBias[Constants.LastFrame + i] = (sbyte)rb.ReadBit();
+ }
+
+ SetupFrameSizeWithRefs(allocator, ref cm, ref rb);
+
+ cm.AllowHighPrecisionMv = rb.ReadBit() != 0;
+ cm.InterpFilter = ReadInterpFilter(ref rb);
+
+ for (int i = 0; i < Constants.RefsPerFrame; ++i)
+ {
+ ref RefBuffer refBuf = ref cm.FrameRefs[i];
+ refBuf.Sf.SetupScaleFactorsForFrame(
+ refBuf.Buf.YCropWidth,
+ refBuf.Buf.YCropHeight,
+ cm.Width,
+ cm.Height);
+ }
+ }
+ }
+
+ cm.GetFrameNewBuffer().BitDepth = (uint)cm.BitDepth;
+ cm.GetFrameNewBuffer().ColorSpace = cm.ColorSpace;
+ cm.GetFrameNewBuffer().ColorRange = cm.ColorRange;
+ cm.GetFrameNewBuffer().RenderWidth = cm.RenderWidth;
+ cm.GetFrameNewBuffer().RenderHeight = cm.RenderHeight;
+
+ if (pbi.NeedResync != 0)
+ {
+ cm.Error.InternalError(CodecErr.CorruptFrame,
+ "Keyframe / intra-only frame required to reset decoder state");
+ }
+
+ if (cm.ErrorResilientMode == 0)
+ {
+ cm.RefreshFrameContext = rb.ReadBit();
+ cm.FrameParallelDecodingMode = rb.ReadBit();
+ if (cm.FrameParallelDecodingMode == 0)
+ {
+ cm.Counts.Value = new Vp9BackwardUpdates();
+ }
+ }
+ else
+ {
+ cm.RefreshFrameContext = 0;
+ cm.FrameParallelDecodingMode = 1;
+ }
+
+ // This flag will be overridden by the call to SetupPastIndependence
+ // below, forcing the use of context 0 for those frame types.
+ cm.FrameContextIdx = (uint)rb.ReadLiteral(Constants.FrameContextsLog2);
+
+ // Generate next_ref_frame_map.
+ for (mask = pbi.RefreshFrameFlags; mask != 0; mask >>= 1)
+ {
+ if ((mask & 1) != 0)
+ {
+ cm.NextRefFrameMap[refIndex] = cm.NewFbIdx;
+ ++frameBufs[cm.NewFbIdx].RefCount;
+ }
+ else
+ {
+ cm.NextRefFrameMap[refIndex] = cm.RefFrameMap[refIndex];
+ }
+
+ // Current thread holds the reference frame.
+ if (cm.RefFrameMap[refIndex] >= 0)
+ {
+ ++frameBufs[cm.RefFrameMap[refIndex]].RefCount;
+ }
+
+ ++refIndex;
+ }
+
+ for (; refIndex < Constants.RefFrames; ++refIndex)
+ {
+ cm.NextRefFrameMap[refIndex] = cm.RefFrameMap[refIndex];
+ // Current thread holds the reference frame.
+ if (cm.RefFrameMap[refIndex] >= 0)
+ {
+ ++frameBufs[cm.RefFrameMap[refIndex]].RefCount;
+ }
+ }
+
+ pbi.HoldRefBuf = 1;
+
+ if (cm.FrameIsIntraOnly() || cm.ErrorResilientMode != 0)
+ {
+ EntropyMode.SetupPastIndependence(ref cm);
+ }
+
+ SetupLoopfilter(ref cm.Lf, ref rb);
+ SetupQuantization(ref cm, ref cm.Mb, ref rb);
+ cm.Seg.SetupSegmentation(ref cm.Fc.Value, ref rb);
+ cm.SetupSegmentationDequant();
+
+ cm.SetupTileInfo(ref rb);
+ sz = (ulong)rb.ReadLiteral(16);
+
+ if (sz == 0)
+ {
+ cm.Error.InternalError(CodecErr.CorruptFrame, "Invalid header size");
+ }
+
+ return sz;
+ }
+
+ private static bool ReadCompressedHeader(ref Vp9Decoder pbi, ArrayPtr data, ulong partitionSize)
+ {
+ ref Vp9Common cm = ref pbi.Common;
+ ref MacroBlockD xd = ref cm.Mb;
+ ref Vp9EntropyProbs fc = ref cm.Fc.Value;
+ Reader r = new();
+
+ if (r.Init(data, (int)partitionSize))
+ {
+ cm.Error.InternalError(CodecErr.MemError, "Failed to allocate bool decoder 0");
+ }
+
+ cm.TxMode = xd.Lossless ? TxMode.Only4x4 : r.ReadTxMode();
+ if (cm.TxMode == TxMode.TxModeSelect)
+ {
+ ReadTxModeProbs(ref fc, ref r);
+ }
+
+ ReadCoefProbs(ref fc, cm.TxMode, ref r);
+
+ for (int k = 0; k < Constants.SkipContexts; ++k)
+ {
+ r.DiffUpdateProb(ref fc.SkipProb[k]);
+ }
+
+ if (!cm.FrameIsIntraOnly())
+ {
+ ReadInterModeProbs(ref fc, ref r);
+
+ if (cm.InterpFilter == Constants.Switchable)
+ {
+ ReadSwitchableInterpProbs(ref fc, ref r);
+ }
+
+ for (int i = 0; i < Constants.IntraInterContexts; i++)
+ {
+ r.DiffUpdateProb( ref fc.IntraInterProb[i]);
+ }
+
+ cm.ReferenceMode = cm.ReadFrameReferenceMode(ref r);
+ if (cm.ReferenceMode != ReferenceMode.Single)
+ {
+ cm.SetupCompoundReferenceMode();
+ }
+
+ cm.ReadFrameReferenceModeProbs(ref r);
+
+ for (int j = 0; j < EntropyMode.BlockSizeGroups; j++)
+ {
+ for (int i = 0; i < Constants.IntraModes - 1; ++i)
+ {
+ r.DiffUpdateProb( ref fc.YModeProb[j][i]);
+ }
+ }
+
+ for (int j = 0; j < Constants.PartitionContexts; ++j)
+ {
+ for (int i = 0; i < Constants.PartitionTypes - 1; ++i)
+ {
+ r.DiffUpdateProb( ref fc.PartitionProb[j][i]);
+ }
+ }
+
+ ReadMvProbs(ref fc, cm.AllowHighPrecisionMv, ref r);
+ }
+
+ return r.HasError();
+ }
+
+ private static ref ReadBitBuffer InitReadBitBuffer(ref ReadBitBuffer rb, ReadOnlySpan data)
+ {
+ rb.BitOffset = 0;
+ rb.BitBuffer = data;
+ return ref rb;
+ }
+
+ public static unsafe void Decode(MemoryAllocator allocator,
+ ref Vp9Decoder pbi,
+ ArrayPtr data,
+ out ArrayPtr pDataEnd,
+ bool multithreaded = true)
+ {
+ ref Vp9Common cm = ref pbi.Common;
+ ref MacroBlockD xd = ref cm.Mb;
+ ReadBitBuffer rb = new();
+ int contextUpdated = 0;
+ Span clearData = stackalloc byte[80];
+ ulong firstPartitionSize =
+ ReadUncompressedHeader(allocator, ref pbi, ref InitReadBitBuffer(ref rb, data.AsSpan()));
+ int tileRows = 1 << cm.Log2TileRows;
+ int tileCols = 1 << cm.Log2TileCols;
+ ref Surface newFb = ref cm.GetFrameNewBuffer();
+ xd.CurBuf = newFb;
+
+ if (firstPartitionSize == 0)
+ {
+ // showing a frame directly
+ pDataEnd = data.Slice(cm.Profile <= BitstreamProfile.Profile2 ? 1 : 2);
+ return;
+ }
+
+ data = data.Slice((int)rb.BytesRead());
+ if (!ReadIsValid(data, (int)firstPartitionSize))
+ {
+ cm.Error.InternalError(CodecErr.CorruptFrame, "Truncated packet or corrupt header length");
+ }
+
+ cm.UsePrevFrameMvs =
+ cm.ErrorResilientMode == 0 &&
+ cm.Width == cm.LastWidth &&
+ cm.Height == cm.LastHeight &&
+ !cm.LastIntraOnly &&
+ cm.LastShowFrame != 0 &&
+ cm.LastFrameType != FrameType.KeyFrame;
+
+ xd.SetupBlockPlanes(cm.SubsamplingX, cm.SubsamplingY);
+
+ cm.Fc = new Ptr(ref cm.FrameContexts[(int)cm.FrameContextIdx]);
+
+ xd.Corrupted = false;
+ newFb.Corrupted = ReadCompressedHeader(ref pbi, data, firstPartitionSize) ? 1 : 0;
+ if (newFb.Corrupted != 0)
+ {
+ cm.Error.InternalError(CodecErr.CorruptFrame, "Decode failed. Frame data header is corrupted.");
+ }
+
+ if (cm.Lf.FilterLevel != 0 && cm.SkipLoopFilter == 0)
+ {
+ LoopFilter.LoopFilterFrameInit(ref cm, cm.Lf.FilterLevel);
+ }
+
+ int threadCount = multithreaded ? Math.Max(1, Environment.ProcessorCount / 2) : 0;
+
+ if (cm.TileWorkerData.IsNull || tileCols * tileRows != cm.TotalTiles)
+ {
+ int numTileWorkers = (tileCols * tileRows) + threadCount;
+ if (!cm.TileWorkerData.IsNull)
+ {
+ allocator.Free(cm.TileWorkerData);
+ }
+
+ cm.CheckMemError( ref cm.TileWorkerData, allocator.Allocate(numTileWorkers));
+ cm.TotalTiles = tileRows * tileCols;
+ }
+
+ if (multithreaded)
+ {
+ pDataEnd = DecodeTilesMt(ref pbi.Common, data.Slice((int)firstPartitionSize), threadCount);
+
+ LoopFilter.LoopFilterFrameMt(
+ ref cm.Mb.CurBuf,
+ ref cm,
+ ref cm.Mb,
+ cm.Lf.FilterLevel,
+ false,
+ false,
+ threadCount);
+ }
+ else
+ {
+ pDataEnd = DecodeTiles(ref pbi.Common, data.Slice((int)firstPartitionSize));
+
+ LoopFilter.LoopFilterFrame(ref cm.Mb.CurBuf, ref cm, ref cm.Mb, cm.Lf.FilterLevel, false, false);
+ }
+
+ if (!xd.Corrupted)
+ {
+ if (cm.ErrorResilientMode == 0 && cm.FrameParallelDecodingMode == 0)
+ {
+ cm.AdaptCoefProbs();
+
+ if (!cm.FrameIsIntraOnly())
+ {
+ cm.AdaptModeProbs();
+ cm.AdaptMvProbs(cm.AllowHighPrecisionMv);
+ }
+ }
+ }
+ else
+ {
+ cm.Error.InternalError(CodecErr.CorruptFrame, "Decode failed. Frame data is corrupted.");
+ }
+
+ // Non frame parallel update frame context here.
+ if (cm.RefreshFrameContext != 0 && contextUpdated == 0)
+ {
+ cm.FrameContexts[(int)cm.FrameContextIdx] = cm.Fc.Value;
+ }
+ }
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/DecodeMv.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/DecodeMv.cs
index 091490bfa..b77a602b6 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/DecodeMv.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/DecodeMv.cs
@@ -1,4 +1,4 @@
-using Ryujinx.Common.Memory;
+using Ryujinx.Common.Memory;
using Ryujinx.Graphics.Nvdec.Vp9.Dsp;
using Ryujinx.Graphics.Nvdec.Vp9.Types;
using Ryujinx.Graphics.Video;
@@ -10,11 +10,11 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
internal static class DecodeMv
{
- private const int MvrefNeighbours = 8;
+ private const int RefNeighbours = 8;
private static PredictionMode ReadIntraMode(ref Reader r, ReadOnlySpan p)
{
- return (PredictionMode)r.ReadTree(Luts.Vp9IntraModeTree, p);
+ return (PredictionMode)r.ReadTree(Luts.IntraModeTree, p);
}
private static PredictionMode ReadIntraModeY(ref Vp9Common cm, ref MacroBlockD xd, ref Reader r, int sizeGroup)
@@ -41,7 +41,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private static PredictionMode ReadInterMode(ref Vp9Common cm, ref MacroBlockD xd, ref Reader r, int ctx)
{
- int mode = r.ReadTree(Luts.Vp9InterModeTree, cm.Fc.Value.InterModeProb[ctx].AsSpan());
+ int mode = r.ReadTree(Luts.InterModeTree, cm.Fc.Value.InterModeProb[ctx].AsSpan());
if (!xd.Counts.IsNull)
{
++xd.Counts.Value.InterMode[ctx][mode];
@@ -52,22 +52,18 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private static int ReadSegmentId(ref Reader r, ref Array7 segTreeProbs)
{
- return r.ReadTree(Luts.Vp9SegmentTree, segTreeProbs.AsSpan());
+ return r.ReadTree(Luts.SegmentTree, segTreeProbs.AsSpan());
}
private static ReadOnlySpan GetTxProbs(ref Vp9EntropyProbs fc, TxSize maxTxSize, int ctx)
{
switch (maxTxSize)
{
- case TxSize.Tx8x8:
- return fc.Tx8x8Prob[ctx].AsSpan();
- case TxSize.Tx16x16:
- return fc.Tx16x16Prob[ctx].AsSpan();
- case TxSize.Tx32x32:
- return fc.Tx32x32Prob[ctx].AsSpan();
+ case TxSize.Tx8x8: return fc.Tx8x8Prob[ctx].AsSpan();
+ case TxSize.Tx16x16: return fc.Tx16x16Prob[ctx].AsSpan();
+ case TxSize.Tx32x32: return fc.Tx32x32Prob[ctx].AsSpan();
default:
Debug.Assert(false, "Invalid maxTxSize.");
-
return ReadOnlySpan.Empty;
}
}
@@ -76,15 +72,11 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
switch (maxTxSize)
{
- case TxSize.Tx8x8:
- return counts.Tx8x8[ctx].AsSpan();
- case TxSize.Tx16x16:
- return counts.Tx16x16[ctx].AsSpan();
- case TxSize.Tx32x32:
- return counts.Tx32x32[ctx].AsSpan();
+ case TxSize.Tx8x8: return counts.Tx8x8[ctx].AsSpan();
+ case TxSize.Tx16x16: return counts.Tx16x16[ctx].AsSpan();
+ case TxSize.Tx32x32: return counts.Tx32x32[ctx].AsSpan();
default:
Debug.Assert(false, "Invalid maxTxSize.");
-
return Span.Empty;
}
}
@@ -124,34 +116,32 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
return (TxSize)Math.Min((int)maxTxSize, (int)Luts.TxModeToBiggestTxSize[(int)txMode]);
}
- private static int DecGetSegmentId(ref Vp9Common cm, ArrayPtr segmentIds, int miOffset, int xMis, int yMis)
+ private static int DecGetSegmentId(ref Vp9Common cm, ArrayPtr segmentIds, int miOffset, int xMis,
+ int yMis)
{
- int x, y, segmentId = int.MaxValue;
+ int segmentId = int.MaxValue;
- for (y = 0; y < yMis; y++)
+ for (int y = 0; y < yMis; y++)
{
- for (x = 0; x < xMis; x++)
+ for (int x = 0; x < xMis; x++)
{
- segmentId = Math.Min(segmentId, segmentIds[miOffset + y * cm.MiCols + x]);
+ segmentId = Math.Min(segmentId, segmentIds[miOffset + (y * cm.MiCols) + x]);
}
}
Debug.Assert(segmentId >= 0 && segmentId < Constants.MaxSegments);
-
return segmentId;
}
private static void SetSegmentId(ref Vp9Common cm, int miOffset, int xMis, int yMis, int segmentId)
{
- int x, y;
-
Debug.Assert(segmentId >= 0 && segmentId < Constants.MaxSegments);
- for (y = 0; y < yMis; y++)
+ for (int y = 0; y < yMis; y++)
{
- for (x = 0; x < xMis; x++)
+ for (int x = 0; x < xMis; x++)
{
- cm.CurrentFrameSegMap[miOffset + y * cm.MiCols + x] = (byte)segmentId;
+ cm.CurrentFrameSegMap[miOffset + (y * cm.MiCols) + x] = (byte)segmentId;
}
}
}
@@ -164,13 +154,13 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int xMis,
int yMis)
{
- int x, y;
-
- for (y = 0; y < yMis; y++)
+ for (int y = 0; y < yMis; y++)
{
- for (x = 0; x < xMis; x++)
+ for (int x = 0; x < xMis; x++)
{
- currentSegmentIds[miOffset + y * cm.MiCols + x] = (byte)(!lastSegmentIds.IsNull ? lastSegmentIds[miOffset + y * cm.MiCols + x] : 0);
+ currentSegmentIds[miOffset + (y * cm.MiCols) + x] = (byte)(!lastSegmentIds.IsNull
+ ? lastSegmentIds[miOffset + (y * cm.MiCols) + x]
+ : 0);
}
}
}
@@ -188,13 +178,11 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (!seg.UpdateMap)
{
CopySegmentId(ref cm, cm.LastFrameSegMap, cm.CurrentFrameSegMap, miOffset, xMis, yMis);
-
return 0;
}
segmentId = ReadSegmentId(ref r, ref cm.Fc.Value.SegTreeProb);
SetSegmentId(ref cm, miOffset, xMis, yMis, segmentId);
-
return segmentId;
}
@@ -210,7 +198,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ref Segmentation seg = ref cm.Seg;
ref ModeInfo mi = ref xd.Mi[0].Value;
int predictedSegmentId, segmentId;
- int miOffset = miRow * cm.MiCols + miCol;
+ int miOffset = (miRow * cm.MiCols) + miCol;
if (!seg.Enabled)
{
@@ -224,7 +212,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (!seg.UpdateMap)
{
CopySegmentId(ref cm, cm.LastFrameSegMap, cm.CurrentFrameSegMap, miOffset, xMis, yMis);
-
return predictedSegmentId;
}
@@ -232,20 +219,22 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
byte predProb = Segmentation.GetPredProbSegId(ref cm.Fc.Value.SegPredProb, ref xd);
mi.SegIdPredicted = (sbyte)r.Read(predProb);
- segmentId = mi.SegIdPredicted != 0 ? predictedSegmentId : ReadSegmentId(ref r, ref cm.Fc.Value.SegTreeProb);
+ segmentId = mi.SegIdPredicted != 0
+ ? predictedSegmentId
+ : ReadSegmentId(ref r, ref cm.Fc.Value.SegTreeProb);
}
else
{
segmentId = ReadSegmentId(ref r, ref cm.Fc.Value.SegTreeProb);
}
- SetSegmentId(ref cm, miOffset, xMis, yMis, segmentId);
+ SetSegmentId(ref cm, miOffset, xMis, yMis, segmentId);
return segmentId;
}
private static int ReadSkip(ref Vp9Common cm, ref MacroBlockD xd, int segmentId, ref Reader r)
{
- if (cm.Seg.IsSegFeatureActive(segmentId, SegLvlFeatures.SegLvlSkip) != 0)
+ if (cm.Seg.IsSegFeatureActive(segmentId, SegLvlFeatures.Skip) != 0)
{
return 1;
}
@@ -260,12 +249,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
return skip;
}
- private static int ReadMvComponent(ref Reader r, ref Vp9EntropyProbs fc, int mvcomp, bool usehp)
+ private static int ReadComponent(ref Reader r, ref Vp9EntropyProbs fc, int mvcomp, bool usehp)
{
int mag, d, fr, hp;
bool sign = r.Read(fc.Sign[mvcomp]) != 0;
- MvClassType mvClass = (MvClassType)r.ReadTree(Luts.Vp9MvClassTree, fc.Classes[mvcomp].AsSpan());
- bool class0 = mvClass == MvClassType.MvClass0;
+ MvClassType mvClass = (MvClassType)r.ReadTree(Luts.MvClassTree, fc.Classes[mvcomp].AsSpan());
+ bool class0 = mvClass == MvClassType.Class0;
// Integer part
if (class0)
@@ -275,11 +264,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
else
{
- int i;
int n = (int)mvClass + Constants.Class0Bits - 1; // Number of bits
d = 0;
- for (i = 0; i < n; ++i)
+ for (int i = 0; i < n; ++i)
{
d |= r.Read(fc.Bits[mvcomp][i]) << i;
}
@@ -288,40 +276,39 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
// Fractional part
- fr = r.ReadTree(Luts.Vp9MvFPTree, class0 ? fc.Class0Fp[mvcomp][d].AsSpan() : fc.Fp[mvcomp].AsSpan());
+ fr = r.ReadTree(Luts.MvFPTree, class0 ? fc.Class0Fp[mvcomp][d].AsSpan() : fc.Fp[mvcomp].AsSpan());
// High precision part (if hp is not used, the default value of the hp is 1)
hp = usehp ? r.Read(class0 ? fc.Class0Hp[mvcomp] : fc.Hp[mvcomp]) : 1;
// Result
mag += ((d << 3) | (fr << 1) | hp) + 1;
-
return sign ? -mag : mag;
}
- private static void ReadMv(
+ private static void Read(
ref Reader r,
ref Mv mv,
ref Mv refr,
ref Vp9EntropyProbs fc,
Ptr counts,
- bool allowHP)
+ bool allowHp)
{
- MvJointType jointType = (MvJointType)r.ReadTree(Luts.Vp9MvJointTree, fc.Joints.AsSpan());
- bool useHP = allowHP && refr.UseMvHp();
+ MvJointType jointType = (MvJointType)r.ReadTree(Luts.MvJointTree, fc.Joints.AsSpan());
+ bool useHp = allowHp && refr.UseHp();
Mv diff = new();
- if (Mv.MvJointVertical(jointType))
+ if (Mv.JointVertical(jointType))
{
- diff.Row = (short)ReadMvComponent(ref r, ref fc, 0, useHP);
+ diff.Row = (short)ReadComponent(ref r, ref fc, 0, useHp);
}
- if (Mv.MvJointHorizontal(jointType))
+ if (Mv.JointHorizontal(jointType))
{
- diff.Col = (short)ReadMvComponent(ref r, ref fc, 1, useHP);
+ diff.Col = (short)ReadComponent(ref r, ref fc, 1, useHp);
}
- diff.IncMv(counts);
+ diff.Inc(counts);
mv.Row = (short)(refr.Row + diff.Row);
mv.Col = (short)(refr.Col + diff.Col);
@@ -329,7 +316,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private static ReferenceMode ReadBlockReferenceMode(ref Vp9Common cm, ref MacroBlockD xd, ref Reader r)
{
- if (cm.ReferenceMode == ReferenceMode.ReferenceModeSelect)
+ if (cm.ReferenceMode == ReferenceMode.Select)
{
int ctx = PredCommon.GetReferenceModeContext(ref cm, ref xd);
ReferenceMode mode = (ReferenceMode)r.Read(cm.Fc.Value.CompInterProb[ctx]);
@@ -354,15 +341,15 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
ref Vp9EntropyProbs fc = ref cm.Fc.Value;
- if (cm.Seg.IsSegFeatureActive(segmentId, SegLvlFeatures.SegLvlRefFrame) != 0)
+ if (cm.Seg.IsSegFeatureActive(segmentId, SegLvlFeatures.RefFrame) != 0)
{
- refFrame[0] = (sbyte)cm.Seg.GetSegData(segmentId, SegLvlFeatures.SegLvlRefFrame);
+ refFrame[0] = (sbyte)cm.Seg.GetSegData(segmentId, SegLvlFeatures.RefFrame);
refFrame[1] = Constants.None;
}
else
{
ReferenceMode mode = ReadBlockReferenceMode(ref cm, ref xd, ref r);
- if (mode == ReferenceMode.CompoundReference)
+ if (mode == ReferenceMode.Compound)
{
int idx = cm.RefFrameSignBias[cm.CompFixedRef];
int ctx = PredCommon.GetPredContextCompRefP(ref cm, ref xd);
@@ -375,7 +362,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
refFrame[idx] = cm.CompFixedRef;
refFrame[idx == 0 ? 1 : 0] = cm.CompVarRef[bit];
}
- else if (mode == ReferenceMode.SingleReference)
+ else if (mode == ReferenceMode.Single)
{
int ctx0 = PredCommon.GetPredContextSingleRefP1(ref xd);
int bit0 = r.Read(fc.SingleRefProb[ctx0][0]);
@@ -412,7 +399,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private static byte ReadSwitchableInterpFilter(ref Vp9Common cm, ref MacroBlockD xd, ref Reader r)
{
int ctx = xd.GetPredContextSwitchableInterp();
- byte type = (byte)r.ReadTree(Luts.Vp9SwitchableInterpTree, cm.Fc.Value.SwitchableInterpProb[ctx].AsSpan());
+ byte type = (byte)r.ReadTree(Luts.SwitchableInterpTree, cm.Fc.Value.SwitchableInterpProb[ctx].AsSpan());
if (!xd.Counts.IsNull)
{
++xd.Counts.Value.SwitchableInterp[ctx][type];
@@ -424,12 +411,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private static void ReadIntraBlockModeInfo(ref Vp9Common cm, ref MacroBlockD xd, ref ModeInfo mi, ref Reader r)
{
BlockSize bsize = mi.SbType;
- int i;
+
switch (bsize)
{
case BlockSize.Block4x4:
- for (i = 0; i < 4; ++i)
+ for (int i = 0; i < 4; ++i)
{
mi.Bmi[i].Mode = ReadIntraModeY(ref cm, ref xd, ref r, 0);
}
@@ -459,27 +446,19 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
mi.RefFrame[1] = Constants.None;
}
- private static bool IsMvValid(ref Mv mv)
- {
- return mv.Row > Constants.MvLow &&
- mv.Row < Constants.MvUpp &&
- mv.Col > Constants.MvLow &&
- mv.Col < Constants.MvUpp;
- }
-
- private static void CopyMvPair(ref Array2 dst, ref Array2 src)
+ private static void CopyPair(ref Array2 dst, ref Array2 src)
{
dst[0] = src[0];
dst[1] = src[1];
}
- private static void ZeroMvPair(ref Array2 dst)
+ private static void ZeroPair(ref Array2 dst)
{
dst[0] = new Mv();
dst[1] = new Mv();
}
- private static bool AssignMv(
+ private static bool Assign(
ref Vp9Common cm,
ref MacroBlockD xd,
PredictionMode mode,
@@ -487,45 +466,45 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ref Array2 refMv,
ref Array2 nearNearestMv,
int isCompound,
- bool allowHP,
+ bool allowHp,
ref Reader r)
{
- int i;
bool ret = true;
switch (mode)
{
case PredictionMode.NewMv:
{
- for (i = 0; i < 1 + isCompound; ++i)
+ for (int i = 0; i < 1 + isCompound; ++i)
{
- ReadMv(ref r, ref mv[i], ref refMv[i], ref cm.Fc.Value, xd.Counts, allowHP);
- ret = ret && IsMvValid(ref mv[i]);
+ Read(ref r, ref mv[i], ref refMv[i], ref cm.Fc.Value, xd.Counts, allowHp);
+ ret = ret && mv[i].IsValid();
}
+
break;
}
case PredictionMode.NearMv:
case PredictionMode.NearestMv:
{
- CopyMvPair(ref mv, ref nearNearestMv);
+ CopyPair(ref mv, ref nearNearestMv);
break;
}
case PredictionMode.ZeroMv:
{
- ZeroMvPair(ref mv);
+ ZeroPair(ref mv);
break;
}
- default:
- return false;
+ default: return false;
}
+
return ret;
}
private static bool ReadIsInterBlock(ref Vp9Common cm, ref MacroBlockD xd, int segmentId, ref Reader r)
{
- if (cm.Seg.IsSegFeatureActive(segmentId, SegLvlFeatures.SegLvlRefFrame) != 0)
+ if (cm.Seg.IsSegFeatureActive(segmentId, SegLvlFeatures.RefFrame) != 0)
{
- return cm.Seg.GetSegData(segmentId, SegLvlFeatures.SegLvlRefFrame) != Constants.IntraFrame;
+ return cm.Seg.GetSegData(segmentId, SegLvlFeatures.RefFrame) != Constants.IntraFrame;
}
int ctx = xd.GetIntraInterContext();
@@ -538,33 +517,30 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
return isInter;
}
- private static void DecFindBestRefMvs(bool allowHP, Span mvlist, ref Mv bestMv, int refmvCount)
+ private static void DecFindBestRefs(bool allowHp, Span mvlist, ref Mv bestMv, int refmvCount)
{
- int i;
-
// Make sure all the candidates are properly clamped etc
- for (i = 0; i < refmvCount; ++i)
+ for (int i = 0; i < refmvCount; ++i)
{
- mvlist[i].LowerMvPrecision(allowHP);
+ mvlist[i].LowerPrecision(allowHp);
bestMv = mvlist[i];
}
}
- private static bool AddMvRefListEb(Mv mv, ref int refMvCount, Span mvRefList, bool earlyBreak)
+ private static bool AddRefListEb(Mv mv, ref int refCount, Span mvRefList, bool earlyBreak)
{
- if (refMvCount != 0)
+ if (refCount != 0)
{
if (Unsafe.As(ref mv) != Unsafe.As(ref mvRefList[0]))
{
- mvRefList[refMvCount] = mv;
- refMvCount++;
-
+ mvRefList[refCount] = mv;
+ refCount++;
return true;
}
}
else
{
- mvRefList[refMvCount++] = mv;
+ mvRefList[refCount++] = mv;
if (earlyBreak)
{
return true;
@@ -574,19 +550,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
return false;
}
- // Performs mv sign inversion if indicated by the reference frame combination.
- private static Mv ScaleMv(ref ModeInfo mi, int refr, sbyte thisRefFrame, ref Array4 refSignBias)
- {
- Mv mv = mi.Mv[refr];
- if (refSignBias[mi.RefFrame[refr]] != refSignBias[thisRefFrame])
- {
- mv.Row *= -1;
- mv.Col *= -1;
- }
- return mv;
- }
-
- private static bool IsDiffRefFrameAddMvEb(
+ private static bool IsDiffRefFrameAddEb(
ref ModeInfo mbmi,
sbyte refFrame,
ref Array4 refSignBias,
@@ -598,26 +562,30 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
if (mbmi.RefFrame[0] != refFrame)
{
- if (AddMvRefListEb(ScaleMv(ref mbmi, 0, refFrame, ref refSignBias), ref refmvCount, mvRefList, earlyBreak))
- {
- return true;
- }
- }
- if (mbmi.HasSecondRef() && mbmi.RefFrame[1] != refFrame && Unsafe.As(ref mbmi.Mv[1]) != Unsafe.As(ref mbmi.Mv[0]))
- {
- if (AddMvRefListEb(ScaleMv(ref mbmi, 1, refFrame, ref refSignBias), ref refmvCount, mvRefList, earlyBreak))
+ if (AddRefListEb(mbmi.ScaleMv(0, refFrame, ref refSignBias), ref refmvCount, mvRefList,
+ earlyBreak))
{
return true;
}
}
+ if (mbmi.HasSecondRef() && mbmi.RefFrame[1] != refFrame &&
+ Unsafe.As(ref mbmi.Mv[1]) != Unsafe.As(ref mbmi.Mv[0]))
+ {
+ if (AddRefListEb(mbmi.ScaleMv(1, refFrame, ref refSignBias), ref refmvCount, mvRefList,
+ earlyBreak))
+ {
+ return true;
+ }
+ }
}
+
return false;
}
// This function searches the neighborhood of a given MB/SB
// to try and find candidate reference vectors.
- private static int DecFindMvRefs(
+ private static int DecFindRefs(
ref Vp9Common cm,
ref MacroBlockD xd,
PredictionMode mode,
@@ -627,22 +595,24 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
int miRow,
int miCol,
int block,
- int isSub8X8)
+ int isSub8x8)
{
ref Array4 refSignBias = ref cm.RefFrameSignBias;
int i, refmvCount = 0;
bool differentRefFound = false;
- Ptr prevFrameMvs = cm.UsePrevFrameMvs ? new Ptr(ref cm.PrevFrameMvs[miRow * cm.MiCols + miCol]) : Ptr.Null;
+ Ptr prevFrameMvs = cm.UsePrevFrameMvs
+ ? new Ptr(ref cm.PrevFrameMvs[(miRow * cm.MiCols) + miCol])
+ : Ptr.Null;
ref TileInfo tile = ref xd.Tile;
// If mode is nearestmv or newmv (uses nearestmv as a reference) then stop
// searching after the first mv is found.
bool earlyBreak = mode != PredictionMode.NearMv;
// Blank the reference vector list
- mvRefList[..Constants.MaxMvRefCandidates].Clear();
+ mvRefList.Slice(0, Constants.MaxMvRefCandidates).Fill(new Mv());
i = 0;
- if (isSub8X8 != 0)
+ if (isSub8x8 != 0)
{
// If the size < 8x8 we get the mv from the bmi substructure for the
// nearest two blocks.
@@ -651,19 +621,21 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ref Position mvRef = ref mvRefSearch[i];
if (tile.IsInside(miCol, miRow, cm.MiRows, ref mvRef))
{
- ref ModeInfo candidateMi = ref xd.Mi[mvRef.Col + mvRef.Row * xd.MiStride].Value;
+ ref ModeInfo candidateMi = ref xd.Mi[mvRef.Col + (mvRef.Row * xd.MiStride)].Value;
differentRefFound = true;
if (candidateMi.RefFrame[0] == refFrame)
{
- if (AddMvRefListEb(candidateMi.GetSubBlockMv(0, mvRef.Col, block), ref refmvCount, mvRefList, earlyBreak))
+ if (AddRefListEb(candidateMi.GetSubBlockMv(0, mvRef.Col, block), ref refmvCount,
+ mvRefList, earlyBreak))
{
goto Done;
}
}
else if (candidateMi.RefFrame[1] == refFrame)
{
- if (AddMvRefListEb(candidateMi.GetSubBlockMv(1, mvRef.Col, block), ref refmvCount, mvRefList, earlyBreak))
+ if (AddRefListEb(candidateMi.GetSubBlockMv(1, mvRef.Col, block), ref refmvCount,
+ mvRefList, earlyBreak))
{
goto Done;
}
@@ -675,24 +647,24 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
// Check the rest of the neighbors in much the same way
// as before except we don't need to keep track of sub blocks or
// mode counts.
- for (; i < MvrefNeighbours; ++i)
+ for (; i < RefNeighbours; ++i)
{
ref Position mvRef = ref mvRefSearch[i];
if (tile.IsInside(miCol, miRow, cm.MiRows, ref mvRef))
{
- ref ModeInfo candidate = ref xd.Mi[mvRef.Col + mvRef.Row * xd.MiStride].Value;
+ ref ModeInfo candidate = ref xd.Mi[mvRef.Col + (mvRef.Row * xd.MiStride)].Value;
differentRefFound = true;
if (candidate.RefFrame[0] == refFrame)
{
- if (AddMvRefListEb(candidate.Mv[0], ref refmvCount, mvRefList, earlyBreak))
+ if (AddRefListEb(candidate.Mv[0], ref refmvCount, mvRefList, earlyBreak))
{
goto Done;
}
}
else if (candidate.RefFrame[1] == refFrame)
{
- if (AddMvRefListEb(candidate.Mv[1], ref refmvCount, mvRefList, earlyBreak))
+ if (AddRefListEb(candidate.Mv[1], ref refmvCount, mvRefList, earlyBreak))
{
goto Done;
}
@@ -705,14 +677,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
if (prevFrameMvs.Value.RefFrame[0] == refFrame)
{
- if (AddMvRefListEb(prevFrameMvs.Value.Mv[0], ref refmvCount, mvRefList, earlyBreak))
+ if (AddRefListEb(prevFrameMvs.Value.Mv[0], ref refmvCount, mvRefList, earlyBreak))
{
goto Done;
}
}
else if (prevFrameMvs.Value.RefFrame[1] == refFrame)
{
- if (AddMvRefListEb(prevFrameMvs.Value.Mv[1], ref refmvCount, mvRefList, earlyBreak))
+ if (AddRefListEb(prevFrameMvs.Value.Mv[1], ref refmvCount, mvRefList, earlyBreak))
{
goto Done;
}
@@ -724,15 +696,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
// different reference frames.
if (differentRefFound)
{
- for (i = 0; i < MvrefNeighbours; ++i)
+ for (i = 0; i < RefNeighbours; ++i)
{
ref Position mvRef = ref mvRefSearch[i];
if (tile.IsInside(miCol, miRow, cm.MiRows, ref mvRef))
{
- ref ModeInfo candidate = ref xd.Mi[mvRef.Col + mvRef.Row * xd.MiStride].Value;
+ ref ModeInfo candidate = ref xd.Mi[mvRef.Col + (mvRef.Row * xd.MiStride)].Value;
// If the candidate is Intra we don't want to consider its mv.
- if (IsDiffRefFrameAddMvEb(ref candidate, refFrame, ref refSignBias, ref refmvCount, mvRefList, earlyBreak))
+ if (IsDiffRefFrameAddEb(ref candidate, refFrame, ref refSignBias, ref refmvCount, mvRefList,
+ earlyBreak))
{
goto Done;
}
@@ -751,7 +724,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
mv.Row *= -1;
mv.Col *= -1;
}
- if (AddMvRefListEb(mv, ref refmvCount, mvRefList, earlyBreak))
+
+ if (AddRefListEb(mv, ref refmvCount, mvRefList, earlyBreak))
{
goto Done;
}
@@ -759,7 +733,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (prevFrameMvs.Value.RefFrame[1] > Constants.IntraFrame &&
prevFrameMvs.Value.RefFrame[1] != refFrame &&
- Unsafe.As(ref prevFrameMvs.Value.Mv[1]) != Unsafe.As(ref prevFrameMvs.Value.Mv[0]))
+ Unsafe.As(ref prevFrameMvs.Value.Mv[1]) !=
+ Unsafe.As(ref prevFrameMvs.Value.Mv[0]))
{
Mv mv = prevFrameMvs.Value.Mv[1];
if (refSignBias[prevFrameMvs.Value.RefFrame[1]] != refSignBias[refFrame])
@@ -767,7 +742,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
mv.Row *= -1;
mv.Col *= -1;
}
- if (AddMvRefListEb(mv, ref refmvCount, mvRefList, earlyBreak))
+
+ if (AddRefListEb(mv, ref refmvCount, mvRefList, earlyBreak))
{
goto Done;
}
@@ -784,17 +760,17 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
refmvCount = 1;
}
- Done:
+ Done:
// Clamp vectors
for (i = 0; i < refmvCount; ++i)
{
- mvRefList[i].ClampMvRef(ref xd);
+ mvRefList[i].ClampRef(ref xd);
}
return refmvCount;
}
- private static void AppendSub8x8MvsForIdx(
+ private static void AppendSub8x8ForIdx(
ref Vp9Common cm,
ref MacroBlockD xd,
Span mvRefSearch,
@@ -808,12 +784,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
Span mvList = stackalloc Mv[Constants.MaxMvRefCandidates];
ref ModeInfo mi = ref xd.Mi[0].Value;
ref Array4 bmi = ref mi.Bmi;
- int n;
int refmvCount;
Debug.Assert(Constants.MaxMvRefCandidates == 2);
- refmvCount = DecFindMvRefs(ref cm, ref xd, bMode, mi.RefFrame[refr], mvRefSearch, mvList, miRow, miCol, block, 1);
+ refmvCount = DecFindRefs(ref cm, ref xd, bMode, mi.RefFrame[refr], mvRefSearch, mvList, miRow, miCol,
+ block, 1);
switch (block)
{
@@ -829,7 +805,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
else
{
bestSub8x8 = new Mv();
- for (n = 0; n < refmvCount; ++n)
+ for (int n = 0; n < refmvCount; ++n)
{
if (Unsafe.As(ref bmi[0].Mv[refr]) != Unsafe.As(ref mvList[n]))
{
@@ -838,6 +814,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
}
}
+
break;
case 3:
if (bMode == PredictionMode.NearestMv)
@@ -852,7 +829,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
candidates[2] = mvList[0];
candidates[3] = mvList[1];
bestSub8x8 = new Mv();
- for (n = 0; n < 2 + Constants.MaxMvRefCandidates; ++n)
+ for (int n = 0; n < 2 + Constants.MaxMvRefCandidates; ++n)
{
if (Unsafe.As(ref bmi[2].Mv[refr]) != Unsafe.As(ref candidates[n]))
{
@@ -861,6 +838,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
}
}
+
break;
default:
Debug.Assert(false, "Invalid block index.");
@@ -868,19 +846,19 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
}
- private static byte GetModeContext(ref Vp9Common cm, ref MacroBlockD xd, Span mvRefSearch, int miRow, int miCol)
+ private static byte GetModeContext(ref Vp9Common cm, ref MacroBlockD xd, Span mvRefSearch, int miRow,
+ int miCol)
{
- int i;
int contextCounter = 0;
ref TileInfo tile = ref xd.Tile;
// Get mode count from nearest 2 blocks
- for (i = 0; i < 2; ++i)
+ for (int i = 0; i < 2; ++i)
{
ref Position mvRef = ref mvRefSearch[i];
if (tile.IsInside(miCol, miRow, cm.MiRows, ref mvRef))
{
- ref ModeInfo candidate = ref xd.Mi[mvRef.Col + mvRef.Row * xd.MiStride].Value;
+ ref ModeInfo candidate = ref xd.Mi[mvRef.Col + (mvRef.Row * xd.MiStride)].Value;
// Keep counts for entropy encoding.
contextCounter += Luts.Mode2Counter[(int)candidate.Mode];
}
@@ -898,7 +876,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ref Reader r)
{
BlockSize bsize = mi.SbType;
- bool allowHP = cm.AllowHighPrecisionMv;
+ bool allowHp = cm.AllowHighPrecisionMv;
Array2 bestRefMvs = new();
int refr, isCompound;
byte interModeCtx;
@@ -908,13 +886,13 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
isCompound = mi.HasSecondRef() ? 1 : 0;
interModeCtx = GetModeContext(ref cm, ref xd, mvRefSearch, miRow, miCol);
- if (cm.Seg.IsSegFeatureActive(mi.SegmentId, SegLvlFeatures.SegLvlSkip) != 0)
+ if (cm.Seg.IsSegFeatureActive(mi.SegmentId, SegLvlFeatures.Skip) != 0)
{
mi.Mode = PredictionMode.ZeroMv;
if (bsize < BlockSize.Block8x8)
{
- xd.ErrorInfo.Value.InternalError(CodecErr.CodecUnsupBitstream, "Invalid usage of segement feature on small blocks");
-
+ xd.ErrorInfo.Value.InternalError(CodecErr.UnsupBitstream,
+ "Invalid usage of segement feature on small blocks");
return;
}
}
@@ -942,53 +920,58 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
sbyte frame = mi.RefFrame[refr];
int refmvCount;
- refmvCount = DecFindMvRefs(ref cm, ref xd, mi.Mode, frame, mvRefSearch, tmpMvs, miRow, miCol, -1, 0);
+ refmvCount = DecFindRefs(ref cm, ref xd, mi.Mode, frame, mvRefSearch, tmpMvs, miRow, miCol,
+ -1, 0);
- DecFindBestRefMvs(allowHP, tmpMvs, ref bestRefMvs[refr], refmvCount);
+ DecFindBestRefs(allowHp, tmpMvs, ref bestRefMvs[refr], refmvCount);
}
}
}
- mi.InterpFilter = (cm.InterpFilter == Constants.Switchable) ? ReadSwitchableInterpFilter(ref cm, ref xd, ref r) : cm.InterpFilter;
+ mi.InterpFilter = cm.InterpFilter == Constants.Switchable
+ ? ReadSwitchableInterpFilter(ref cm, ref xd, ref r)
+ : cm.InterpFilter;
if (bsize < BlockSize.Block8x8)
{
- int num4X4W = 1 << xd.BmodeBlocksWl;
- int num4X4H = 1 << xd.BmodeBlocksHl;
+ int num4x4W = 1 << xd.BmodeBlocksWl;
+ int num4x4H = 1 << xd.BmodeBlocksHl;
int idx, idy;
PredictionMode bMode = 0;
Array2 bestSub8x8 = new();
- const uint InvalidMv = 0x80008000;
+ const uint invalidMv = 0x80008000;
// Initialize the 2nd element as even though it won't be used meaningfully
// if isCompound is false.
- Unsafe.As(ref bestSub8x8[1]) = InvalidMv;
- for (idy = 0; idy < 2; idy += num4X4H)
+ Unsafe.As(ref bestSub8x8[1]) = invalidMv;
+ for (idy = 0; idy < 2; idy += num4x4H)
{
- for (idx = 0; idx < 2; idx += num4X4W)
+ for (idx = 0; idx < 2; idx += num4x4W)
{
- int j = idy * 2 + idx;
+ int j = (idy * 2) + idx;
bMode = ReadInterMode(ref cm, ref xd, ref r, interModeCtx);
if (bMode == PredictionMode.NearestMv || bMode == PredictionMode.NearMv)
{
for (refr = 0; refr < 1 + isCompound; ++refr)
{
- AppendSub8x8MvsForIdx(ref cm, ref xd, mvRefSearch, bMode, j, refr, miRow, miCol, ref bestSub8x8[refr]);
+ AppendSub8x8ForIdx(ref cm, ref xd, mvRefSearch, bMode, j, refr, miRow, miCol,
+ ref bestSub8x8[refr]);
}
}
- if (!AssignMv(ref cm, ref xd, bMode, ref mi.Bmi[j].Mv, ref bestRefMvs, ref bestSub8x8, isCompound, allowHP, ref r))
+ if (!Assign(ref cm, ref xd, bMode, ref mi.Bmi[j].Mv, ref bestRefMvs, ref bestSub8x8,
+ isCompound, allowHp, ref r))
{
xd.Corrupted |= true;
break;
}
- if (num4X4H == 2)
+ if (num4x4H == 2)
{
mi.Bmi[j + 2] = mi.Bmi[j];
}
- if (num4X4W == 2)
+ if (num4x4W == 2)
{
mi.Bmi[j + 1] = mi.Bmi[j];
}
@@ -997,11 +980,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
mi.Mode = bMode;
- CopyMvPair(ref mi.Mv, ref mi.Bmi[3].Mv);
+ CopyPair(ref mi.Mv, ref mi.Bmi[3].Mv);
}
else
{
- xd.Corrupted |= !AssignMv(ref cm, ref xd, mi.Mode, ref mi.Mv, ref bestRefMvs, ref bestRefMvs, isCompound, allowHP, ref r);
+ xd.Corrupted |= !Assign(ref cm, ref xd, mi.Mode, ref mi.Mv, ref bestRefMvs, ref bestRefMvs,
+ isCompound, allowHp, ref r);
}
}
@@ -1045,7 +1029,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
Debug.Assert(b == 1 || b == 3);
-
return curMi.Value.Bmi[b - 1].Mode;
}
@@ -1062,7 +1045,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
Debug.Assert(b == 2 || b == 3);
-
return curMi.Value.Bmi[b - 2].Mode;
}
@@ -1075,7 +1057,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
PredictionMode above = AboveBlockMode(mi, aboveMi, block);
PredictionMode left = LeftBlockMode(mi, leftMi, block);
-
return fc.KfYModeProb[(int)above][(int)left].AsSpan();
}
@@ -1092,8 +1073,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
Ptr aboveMi = xd.AboveMi;
Ptr leftMi = xd.LeftMi;
BlockSize bsize = mi.Value.SbType;
- int i;
- int miOffset = miRow * cm.MiCols + miCol;
+
+ int miOffset = (miRow * cm.MiCols) + miCol;
mi.Value.SegmentId = (sbyte)ReadIntraSegmentId(ref cm, miOffset, xMis, yMis, ref r);
mi.Value.Skip = (sbyte)ReadSkip(ref cm, ref xd, mi.Value.SegmentId, ref r);
@@ -1104,7 +1085,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
switch (bsize)
{
case BlockSize.Block4x4:
- for (i = 0; i < 4; ++i)
+ for (int i = 0; i < 4; ++i)
{
mi.Value.Bmi[i].Mode =
ReadIntraMode(ref r, GetYModeProbs(ref cm.Fc.Value, mi, aboveMi, leftMi, i));
@@ -1149,8 +1130,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ref Reader r = ref twd.BitReader;
ref MacroBlockD xd = ref twd.Xd;
ref ModeInfo mi = ref xd.Mi[0].Value;
- ArrayPtr frameMvs = cm.CurFrameMvs.Slice(miRow * cm.MiCols + miCol);
- int w, h;
+ ArrayPtr frameMvs = cm.CurFrameMvs.Slice((miRow * cm.MiCols) + miCol);
if (cm.FrameIsIntraOnly())
{
@@ -1160,17 +1140,18 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
ReadInterFrameModeInfo(ref cm, ref xd, miRow, miCol, ref r, xMis, yMis);
- for (h = 0; h < yMis; ++h)
+ for (int h = 0; h < yMis; ++h)
{
- for (w = 0; w < xMis; ++w)
+ for (int w = 0; w < xMis; ++w)
{
ref MvRef mv = ref frameMvs[w];
CopyRefFramePair(ref mv.RefFrame, ref mi.RefFrame);
- CopyMvPair(ref mv.Mv, ref mi.Mv);
+ CopyPair(ref mv.Mv, ref mi.Mv);
}
+
frameMvs = frameMvs.Slice(cm.MiCols);
}
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Decoder.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Decoder.cs
index 57057d5f9..7f50aab3f 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/Decoder.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Decoder.cs
@@ -1,4 +1,4 @@
-using Ryujinx.Common.Memory;
+using Ryujinx.Common.Memory;
using Ryujinx.Graphics.Nvdec.Vp9.Common;
using Ryujinx.Graphics.Nvdec.Vp9.Types;
using Ryujinx.Graphics.Video;
@@ -12,14 +12,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private readonly MemoryAllocator _allocator = new();
- public ISurface CreateSurface(int width, int height) => new Surface(width, height);
+ public ISurface CreateSurface(int width, int height)
+ {
+ return new Surface(width, height);
+ }
private static ReadOnlySpan LiteralToFilter => new byte[]
{
- Constants.EightTapSmooth,
- Constants.EightTap,
- Constants.EightTapSharp,
- Constants.Bilinear,
+ Constants.EightTapSmooth, Constants.EightTap, Constants.EightTapSharp, Constants.Bilinear
};
public unsafe bool Decode(
@@ -29,25 +29,24 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ReadOnlySpan mvsIn,
Span mvsOut)
{
- Vp9Common cm = new()
- {
- FrameType = pictureInfo.IsKeyFrame ? FrameType.KeyFrame : FrameType.InterFrame,
- IntraOnly = pictureInfo.IntraOnly,
+ Vp9Common cm = new();
- Width = output.Width,
- Height = output.Height,
- SubsamplingX = 1,
- SubsamplingY = 1,
+ cm.FrameType = pictureInfo.IsKeyFrame ? FrameType.KeyFrame : FrameType.InterFrame;
+ cm.IntraOnly = pictureInfo.IntraOnly;
- UsePrevFrameMvs = pictureInfo.UsePrevInFindMvRefs,
+ cm.Width = output.Width;
+ cm.Height = output.Height;
+ cm.SubsamplingX = 1;
+ cm.SubsamplingY = 1;
- RefFrameSignBias = pictureInfo.RefFrameSignBias,
+ cm.UsePrevFrameMvs = pictureInfo.UsePrevInFindMvRefs;
- BaseQindex = pictureInfo.BaseQIndex,
- YDcDeltaQ = pictureInfo.YDcDeltaQ,
- UvAcDeltaQ = pictureInfo.UvAcDeltaQ,
- UvDcDeltaQ = pictureInfo.UvDcDeltaQ,
- };
+ cm.RefFrameSignBias = pictureInfo.RefFrameSignBias;
+
+ cm.BaseQindex = pictureInfo.BaseQIndex;
+ cm.YDcDeltaQ = pictureInfo.YDcDeltaQ;
+ cm.UvAcDeltaQ = pictureInfo.UvAcDeltaQ;
+ cm.UvDcDeltaQ = pictureInfo.UvDcDeltaQ;
cm.Mb.Lossless = pictureInfo.Lossless;
cm.Mb.Bd = 8;
@@ -68,6 +67,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
cm.CompFixedRef = pictureInfo.CompFixedRef;
cm.CompVarRef = pictureInfo.CompVarRef;
+ cm.BitDepth = BitDepth.Bits8;
+
cm.Log2TileCols = pictureInfo.Log2TileCols;
cm.Log2TileRows = pictureInfo.Log2TileRows;
@@ -78,6 +79,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
cm.Seg.FeatureMask = pictureInfo.SegmentFeatureEnable;
cm.Seg.FeatureData = pictureInfo.SegmentFeatureData;
+ cm.Lf.FilterLevel = pictureInfo.LoopFilterLevel;
+ cm.Lf.SharpnessLevel = pictureInfo.LoopFilterSharpnessLevel;
cm.Lf.ModeRefDeltaEnabled = pictureInfo.ModeRefDeltaEnabled;
cm.Lf.RefDeltas = pictureInfo.RefDeltas;
cm.Lf.ModeDeltas = pictureInfo.ModeDeltas;
@@ -105,7 +108,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
cm.SetupSegmentationDequant();
cm.SetupScaleFactors();
- SetMvs(ref cm, mvsIn);
+ cm.SetMvs(mvsIn);
+
+ if (cm.Lf.FilterLevel != 0 && cm.SkipLoopFilter == 0)
+ {
+ LoopFilter.LoopFilterFrameInit(ref cm, cm.Lf.FilterLevel);
+ }
fixed (byte* dataPtr = bitstream)
{
@@ -114,10 +122,27 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (maxThreads > 1 && tileRows == 1 && tileCols > 1)
{
DecodeFrame.DecodeTilesMt(ref cm, new ArrayPtr(dataPtr, bitstream.Length), maxThreads);
+
+ LoopFilter.LoopFilterFrameMt(
+ ref cm.Mb.CurBuf,
+ ref cm,
+ ref cm.Mb,
+ cm.Lf.FilterLevel,
+ false,
+ false,
+ maxThreads);
}
else
{
DecodeFrame.DecodeTiles(ref cm, new ArrayPtr(dataPtr, bitstream.Length));
+
+ LoopFilter.LoopFilterFrame(
+ ref cm.Mb.CurBuf,
+ ref cm,
+ ref cm.Mb,
+ cm.Lf.FilterLevel,
+ false,
+ false);
}
}
catch (InternalErrorException)
@@ -126,7 +151,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
}
- GetMvs(ref cm, mvsOut);
+ cm.GetMvs(mvsOut);
cm.FreeTileWorkerData(_allocator);
cm.FreeContextBuffers(_allocator);
@@ -134,48 +159,9 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
return true;
}
- private static void SetMvs(ref Vp9Common cm, ReadOnlySpan mvs)
+ public void Dispose()
{
- if (mvs.Length > cm.PrevFrameMvs.Length)
- {
- throw new ArgumentException($"Size mismatch, expected: {cm.PrevFrameMvs.Length}, but got: {mvs.Length}.");
- }
-
- for (int i = 0; i < mvs.Length; i++)
- {
- ref var mv = ref cm.PrevFrameMvs[i];
-
- mv.Mv[0].Row = mvs[i].Mvs[0].Row;
- mv.Mv[0].Col = mvs[i].Mvs[0].Col;
- mv.Mv[1].Row = mvs[i].Mvs[1].Row;
- mv.Mv[1].Col = mvs[i].Mvs[1].Col;
-
- mv.RefFrame[0] = (sbyte)mvs[i].RefFrames[0];
- mv.RefFrame[1] = (sbyte)mvs[i].RefFrames[1];
- }
+ _allocator.Dispose();
}
-
- private static void GetMvs(ref Vp9Common cm, Span mvs)
- {
- if (mvs.Length > cm.CurFrameMvs.Length)
- {
- throw new ArgumentException($"Size mismatch, expected: {cm.CurFrameMvs.Length}, but got: {mvs.Length}.");
- }
-
- for (int i = 0; i < mvs.Length; i++)
- {
- ref var mv = ref cm.CurFrameMvs[i];
-
- mvs[i].Mvs[0].Row = mv.Mv[0].Row;
- mvs[i].Mvs[0].Col = mv.Mv[0].Col;
- mvs[i].Mvs[1].Row = mv.Mv[1].Row;
- mvs[i].Mvs[1].Col = mv.Mv[1].Col;
-
- mvs[i].RefFrames[0] = mv.RefFrame[0];
- mvs[i].RefFrames[1] = mv.RefFrame[1];
- }
- }
-
- public void Dispose() => _allocator.Dispose();
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Detokenize.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Detokenize.cs
index c255f7486..ebcacd5fd 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/Detokenize.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Detokenize.cs
@@ -1,4 +1,4 @@
-using Ryujinx.Common.Memory;
+using Ryujinx.Common.Memory;
using Ryujinx.Graphics.Nvdec.Vp9.Dsp;
using Ryujinx.Graphics.Nvdec.Vp9.Types;
using Ryujinx.Graphics.Video;
@@ -17,26 +17,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private static int GetCoefContext(ReadOnlySpan neighbors, ReadOnlySpan tokenCache, int c)
{
- const int MaxNeighbors = 2;
+ const int maxNeighbors = 2;
- return (1 + tokenCache[neighbors[MaxNeighbors * c + 0]] + tokenCache[neighbors[MaxNeighbors * c + 1]]) >> 1;
- }
-
- private static int ReadCoeff(
- ref Reader r,
- ReadOnlySpan probs,
- int n,
- ref ulong value,
- ref int count,
- ref uint range)
- {
- int i, val = 0;
- for (i = 0; i < n; ++i)
- {
- val = (val << 1) | r.ReadBool(probs[i], ref value, ref count, ref range);
- }
-
- return val;
+ return (1 + tokenCache[neighbors[(maxNeighbors * c) + 0]] +
+ tokenCache[neighbors[(maxNeighbors * c) + 1]]) >> 1;
}
private static int DecodeCoefs(
@@ -58,13 +42,15 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ref Array6>> coefProbs = ref fc.CoefProbs[(int)txSize][(int)type][refr];
Span tokenCache = stackalloc byte[32 * 32];
ReadOnlySpan bandTranslate = Luts.GetBandTranslate(txSize);
- int dqShift = (txSize == TxSize.Tx32x32) ? 1 : 0;
+ int dqShift = txSize == TxSize.Tx32x32 ? 1 : 0;
int v;
short dqv = dq[0];
- ReadOnlySpan cat6Prob = (xd.Bd == 12)
- ? Luts.Vp9Cat6ProbHigh12
- : (xd.Bd == 10) ? Luts.Vp9Cat6ProbHigh12[2..] : Luts.Vp9Cat6Prob;
- int cat6Bits = (xd.Bd == 12) ? 18 : (xd.Bd == 10) ? 16 : 14;
+ ReadOnlySpan cat6Prob = xd.Bd == 12
+ ? Luts.Cat6ProbHigh12
+ : xd.Bd == 10
+ ? Luts.Cat6ProbHigh12.Slice(2)
+ : Luts.Cat6Prob;
+ int cat6Bits = xd.Bd == 12 ? 18 : xd.Bd == 10 ? 16 : 14;
// Keep value, range, and count as locals. The compiler produces better
// results with the locals than using r directly.
ulong value = r.Value;
@@ -75,7 +61,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
int val = -1;
band = bandTranslate[0];
- bandTranslate = bandTranslate[1..];
+ bandTranslate = bandTranslate.Slice(1);
ref Array3 prob = ref coefProbs[band][ctx];
if (!xd.Counts.IsNull)
{
@@ -107,18 +93,18 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
r.Value = value;
r.Range = range;
r.Count = count;
-
return c; // Zero tokens at the end (no eob token)
}
+
ctx = GetCoefContext(nb, tokenCache, c);
band = bandTranslate[0];
- bandTranslate = bandTranslate[1..];
+ bandTranslate = bandTranslate.Slice(1);
prob = ref coefProbs[band][ctx];
}
if (r.ReadBool(prob[OneContextNode], ref value, ref count, ref range) != 0)
{
- ReadOnlySpan p = Luts.Vp9Pareto8Full[prob[Constants.PivotNode] - 1];
+ ReadOnlySpan p = Luts.Pareto8Full[prob[Constants.PivotNode] - 1];
if (!xd.Counts.IsNull)
{
++counts.Coef[(int)txSize][(int)type][refr][band][ctx][Constants.TwoToken];
@@ -133,20 +119,24 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
if (r.ReadBool(p[7], ref value, ref count, ref range) != 0)
{
- val = Constants.Cat6MinVal + ReadCoeff(ref r, cat6Prob, cat6Bits, ref value, ref count, ref range);
+ val = Constants.Cat6MinVal + r.ReadCoeff(cat6Prob, cat6Bits, ref value,
+ ref count, ref range);
}
else
{
- val = Constants.Cat5MinVal + ReadCoeff(ref r, Luts.Vp9Cat5Prob, 5, ref value, ref count, ref range);
+ val = Constants.Cat5MinVal + r.ReadCoeff(Luts.Cat5Prob, 5, ref value,
+ ref count, ref range);
}
}
else if (r.ReadBool(p[6], ref value, ref count, ref range) != 0)
{
- val = Constants.Cat4MinVal + ReadCoeff(ref r, Luts.Vp9Cat4Prob, 4, ref value, ref count, ref range);
+ val = Constants.Cat4MinVal + r.ReadCoeff(Luts.Cat4Prob, 4, ref value, ref count,
+ ref range);
}
else
{
- val = Constants.Cat3MinVal + ReadCoeff(ref r, Luts.Vp9Cat3Prob, 3, ref value, ref count, ref range);
+ val = Constants.Cat3MinVal + r.ReadCoeff(Luts.Cat3Prob, 3, ref value, ref count,
+ ref range);
}
}
else
@@ -154,13 +144,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
tokenCache[scan[c]] = 4;
if (r.ReadBool(p[4], ref value, ref count, ref range) != 0)
{
- val = Constants.Cat2MinVal + ReadCoeff(ref r, Luts.Vp9Cat2Prob, 2, ref value, ref count, ref range);
+ val = Constants.Cat2MinVal + r.ReadCoeff(Luts.Cat2Prob, 2, ref value, ref count,
+ ref range);
}
else
{
- val = Constants.Cat1MinVal + ReadCoeff(ref r, Luts.Vp9Cat1Prob, 1, ref value, ref count, ref range);
+ val = Constants.Cat1MinVal + r.ReadCoeff(Luts.Cat1Prob, 1, ref value, ref count,
+ ref range);
}
}
+
// Val may use 18-bits
v = (int)(((long)val * dqv) >> dqShift);
}
@@ -188,7 +181,9 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
tokenCache[scan[c]] = 1;
v = dqv >> dqShift;
}
- dqcoeff[scan[c]] = (int)HighbdCheckRange(r.ReadBool(128, ref value, ref count, ref range) != 0 ? -v : v, xd.Bd);
+
+ dqcoeff[scan[c]] = (int)HighbdCheckRange(r.ReadBool(128, ref value, ref count, ref range) != 0 ? -v : v,
+ xd.Bd);
++c;
ctx = GetCoefContext(nb, tokenCache, c);
dqv = dq[1];
@@ -197,11 +192,11 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
r.Value = value;
r.Range = range;
r.Count = count;
-
return c;
}
- private static void GetCtxShift(ref MacroBlockD xd, ref int ctxShiftA, ref int ctxShiftL, int x, int y, uint txSizeInBlocks)
+ private static void GetCtxShift(ref MacroBlockD xd, ref int ctxShiftA, ref int ctxShiftL, int x, int y,
+ uint txSizeInBlocks)
{
if (xd.MaxBlocksWide != 0)
{
@@ -210,6 +205,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ctxShiftA = (int)(txSizeInBlocks - (xd.MaxBlocksWide - x)) * 8;
}
}
+
if (xd.MaxBlocksHigh != 0)
{
if (txSizeInBlocks + y > xd.MaxBlocksHigh)
@@ -238,8 +234,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ref MacroBlockDPlane pd = ref xd.Plane[plane];
ref Array2 dequant = ref pd.SegDequant[segId];
int eob;
- Span a = pd.AboveContext.AsSpan()[x..];
- Span l = pd.LeftContext.AsSpan()[y..];
+ Span a = pd.AboveContext.AsSpan().Slice(x);
+ Span l = pd.LeftContext.AsSpan().Slice(y);
int ctx;
int ctxShiftA = 0;
int ctxShiftL = 0;
@@ -324,4 +320,4 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
return eob;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/Convolve.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/Convolve.cs
index 9e279dd21..8cea09aec 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/Convolve.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/Convolve.cs
@@ -1,4 +1,4 @@
-using Ryujinx.Common.Memory;
+using Ryujinx.Common.Memory;
using Ryujinx.Graphics.Nvdec.Vp9.Common;
using System.Diagnostics;
using System.Runtime.CompilerServices;
@@ -75,17 +75,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Vector128 zero = Vector128.Zero;
Vector128 const64 = Vector128.Create(64);
- ulong x, y;
- src -= SubpelTaps / 2 - 1;
+ src -= (SubpelTaps / 2) - 1;
fixed (Array8* xFilter = xFilters)
{
- Vector128 vfilter = Sse2.LoadVector128((short*)xFilter + (uint)(x0Q4 & SubpelMask) * 8);
+ Vector128 vfilter = Sse2.LoadVector128((short*)xFilter + ((uint)(x0Q4 & SubpelMask) * 8));
- for (y = 0; y < (uint)h; ++y)
+ for (ulong y = 0; y < (uint)h; ++y)
{
ulong srcOffset = (uint)x0Q4 >> SubpelBits;
- for (x = 0; x < (uint)w; x += 4)
+ for (ulong x = 0; x < (uint)w; x += 4)
{
Vector128 vsrc0 = Sse41.ConvertToVector128Int16(&src[srcOffset + x]);
Vector128 vsrc1 = Sse41.ConvertToVector128Int16(&src[srcOffset + x + 1]);
@@ -94,8 +93,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Vector128 sum0123 = MultiplyAddAdjacent(vsrc0, vsrc1, vsrc2, vsrc3, vfilter, zero);
- Sse.StoreScalar((float*)&dst[x], PackUnsignedSaturate(RoundShift(sum0123, const64), zero).AsSingle());
+ Sse.StoreScalar((float*)&dst[x],
+ PackUnsignedSaturate(RoundShift(sum0123, const64), zero).AsSingle());
}
+
src += srcStride;
dst += dstStride;
}
@@ -117,22 +118,20 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
if (Sse41.IsSupported && UseIntrinsics && xStepQ4 == 1 << SubpelBits)
{
ConvolveHorizSse41(src, srcStride, dst, dstStride, xFilters, x0Q4, w, h);
-
return;
}
- int x, y;
- src -= SubpelTaps / 2 - 1;
+ src -= (SubpelTaps / 2) - 1;
- for (y = 0; y < h; ++y)
+ for (int y = 0; y < h; ++y)
{
int xQ4 = x0Q4;
- for (x = 0; x < w; ++x)
+ for (int x = 0; x < w; ++x)
{
byte* srcX = &src[xQ4 >> SubpelBits];
ref Array8 xFilter = ref xFilters[xQ4 & SubpelMask];
- int k, sum = 0;
- for (k = 0; k < SubpelTaps; ++k)
+ int sum = 0;
+ for (int k = 0; k < SubpelTaps; ++k)
{
sum += srcX[k] * xFilter[k];
}
@@ -140,6 +139,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dst[x] = BitUtils.ClipPixel(BitUtils.RoundPowerOfTwo(sum, FilterBits));
xQ4 += xStepQ4;
}
+
src += srcStride;
dst += dstStride;
}
@@ -156,25 +156,26 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
int w,
int h)
{
- int x, y;
- src -= SubpelTaps / 2 - 1;
+ src -= (SubpelTaps / 2) - 1;
- for (y = 0; y < h; ++y)
+ for (int y = 0; y < h; ++y)
{
int xQ4 = x0Q4;
- for (x = 0; x < w; ++x)
+ for (int x = 0; x < w; ++x)
{
byte* srcX = &src[xQ4 >> SubpelBits];
ref Array8 xFilter = ref xFilters[xQ4 & SubpelMask];
- int k, sum = 0;
- for (k = 0; k < SubpelTaps; ++k)
+ int sum = 0;
+ for (int k = 0; k < SubpelTaps; ++k)
{
sum += srcX[k] * xFilter[k];
}
- dst[x] = (byte)BitUtils.RoundPowerOfTwo(dst[x] + BitUtils.ClipPixel(BitUtils.RoundPowerOfTwo(sum, FilterBits)), 1);
+ dst[x] = (byte)BitUtils.RoundPowerOfTwo(
+ dst[x] + BitUtils.ClipPixel(BitUtils.RoundPowerOfTwo(sum, FilterBits)), 1);
xQ4 += xStepQ4;
}
+
src += srcStride;
dst += dstStride;
}
@@ -203,18 +204,17 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
srcStride * 6,
srcStride * 7);
- ulong x, y;
- src -= srcStride * (SubpelTaps / 2 - 1);
+ src -= srcStride * ((SubpelTaps / 2) - 1);
fixed (Array8* yFilter = yFilters)
{
- Vector128 vfilter = Sse2.LoadVector128((short*)yFilter + (uint)(y0Q4 & SubpelMask) * 8);
+ Vector128 vfilter = Sse2.LoadVector128((short*)yFilter + ((uint)(y0Q4 & SubpelMask) * 8));
ulong srcBaseY = (uint)y0Q4 >> SubpelBits;
- for (y = 0; y < (uint)h; ++y)
+ for (ulong y = 0; y < (uint)h; ++y)
{
ulong srcOffset = (srcBaseY + y) * (uint)srcStride;
- for (x = 0; x < (uint)w; x += 4)
+ for (ulong x = 0; x < (uint)w; x += 4)
{
Vector256 vsrc = Avx2.GatherVector256((uint*)&src[srcOffset + x], indices, 1).AsInt32();
@@ -240,8 +240,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Vector128 sum0123 = MultiplyAddAdjacent(vsrc0, vsrc1, vsrc2, vsrc3, vfilter, zero);
- Sse.StoreScalar((float*)&dst[x], PackUnsignedSaturate(RoundShift(sum0123, const64), zero).AsSingle());
+ Sse.StoreScalar((float*)&dst[x],
+ PackUnsignedSaturate(RoundShift(sum0123, const64), zero).AsSingle());
}
+
dst += dstStride;
}
}
@@ -262,22 +264,20 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
if (Avx2.IsSupported && UseIntrinsics && yStepQ4 == 1 << SubpelBits)
{
ConvolveVertAvx2(src, srcStride, dst, dstStride, yFilters, y0Q4, w, h);
-
return;
}
- int x, y;
- src -= srcStride * (SubpelTaps / 2 - 1);
+ src -= srcStride * ((SubpelTaps / 2) - 1);
- for (x = 0; x < w; ++x)
+ for (int x = 0; x < w; ++x)
{
int yQ4 = y0Q4;
- for (y = 0; y < h; ++y)
+ for (int y = 0; y < h; ++y)
{
byte* srcY = &src[(yQ4 >> SubpelBits) * srcStride];
ref Array8 yFilter = ref yFilters[yQ4 & SubpelMask];
- int k, sum = 0;
- for (k = 0; k < SubpelTaps; ++k)
+ int sum = 0;
+ for (int k = 0; k < SubpelTaps; ++k)
{
sum += srcY[k * srcStride] * yFilter[k];
}
@@ -285,6 +285,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dst[y * dstStride] = BitUtils.ClipPixel(BitUtils.RoundPowerOfTwo(sum, FilterBits));
yQ4 += yStepQ4;
}
+
++src;
++dst;
}
@@ -301,18 +302,17 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
int w,
int h)
{
- int x, y;
- src -= srcStride * (SubpelTaps / 2 - 1);
+ src -= srcStride * ((SubpelTaps / 2) - 1);
- for (x = 0; x < w; ++x)
+ for (int x = 0; x < w; ++x)
{
int yQ4 = y0Q4;
- for (y = 0; y < h; ++y)
+ for (int y = 0; y < h; ++y)
{
byte* srcY = &src[(yQ4 >> SubpelBits) * srcStride];
ref Array8 yFilter = ref yFilters[yQ4 & SubpelMask];
- int k, sum = 0;
- for (k = 0; k < SubpelTaps; ++k)
+ int sum = 0;
+ for (int k = 0; k < SubpelTaps; ++k)
{
sum += srcY[k * srcStride] * yFilter[k];
}
@@ -321,6 +321,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dst[y * dstStride] + BitUtils.ClipPixel(BitUtils.RoundPowerOfTwo(sum, FilterBits)), 1);
yQ4 += yStepQ4;
}
+
++src;
++dst;
}
@@ -420,15 +421,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// ==> yStepQ4 = 64. Since w and h are at most 16, the temp buffer is still
// big enough.
byte* temp = stackalloc byte[64 * 135];
- int intermediateHeight = (((h - 1) * yStepQ4 + y0Q4) >> SubpelBits) + SubpelTaps;
+ int intermediateHeight = ((((h - 1) * yStepQ4) + y0Q4) >> SubpelBits) + SubpelTaps;
Debug.Assert(w <= 64);
Debug.Assert(h <= 64);
Debug.Assert(yStepQ4 <= 32 || (yStepQ4 <= 64 && h <= 32));
Debug.Assert(xStepQ4 <= 64);
- ConvolveHoriz(src - srcStride * (SubpelTaps / 2 - 1), srcStride, temp, 64, filter, x0Q4, xStepQ4, w, intermediateHeight);
- ConvolveVert(temp + 64 * (SubpelTaps / 2 - 1), 64, dst, dstStride, filter, y0Q4, yStepQ4, w, h);
+ ConvolveHoriz(src - (srcStride * ((SubpelTaps / 2) - 1)), srcStride, temp, 64, filter, x0Q4, xStepQ4, w,
+ intermediateHeight);
+ ConvolveVert(temp + (64 * ((SubpelTaps / 2) - 1)), 64, dst, dstStride, filter, y0Q4, yStepQ4, w, h);
}
public static unsafe void Convolve8Avg(
@@ -489,11 +491,9 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
int w,
int h)
{
- int x, y;
-
- for (y = 0; y < h; ++y)
+ for (int y = 0; y < h; ++y)
{
- for (x = 0; x < w; ++x)
+ for (int x = 0; x < w; ++x)
{
dst[x] = (byte)BitUtils.RoundPowerOfTwo(dst[x] + src[x], 1);
}
@@ -611,18 +611,17 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
int h,
int bd)
{
- int x, y;
- src -= SubpelTaps / 2 - 1;
+ src -= (SubpelTaps / 2) - 1;
- for (y = 0; y < h; ++y)
+ for (int y = 0; y < h; ++y)
{
int xQ4 = x0Q4;
- for (x = 0; x < w; ++x)
+ for (int x = 0; x < w; ++x)
{
ushort* srcX = &src[xQ4 >> SubpelBits];
ref Array8 xFilter = ref xFilters[xQ4 & SubpelMask];
- int k, sum = 0;
- for (k = 0; k < SubpelTaps; ++k)
+ int sum = 0;
+ for (int k = 0; k < SubpelTaps; ++k)
{
sum += srcX[k] * xFilter[k];
}
@@ -630,6 +629,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dst[x] = BitUtils.ClipPixelHighbd(BitUtils.RoundPowerOfTwo(sum, FilterBits), bd);
xQ4 += xStepQ4;
}
+
src += srcStride;
dst += dstStride;
}
@@ -647,25 +647,26 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
int h,
int bd)
{
- int x, y;
- src -= SubpelTaps / 2 - 1;
+ src -= (SubpelTaps / 2) - 1;
- for (y = 0; y < h; ++y)
+ for (int y = 0; y < h; ++y)
{
int xQ4 = x0Q4;
- for (x = 0; x < w; ++x)
+ for (int x = 0; x < w; ++x)
{
ushort* srcX = &src[xQ4 >> SubpelBits];
ref Array8 xFilter = ref xFilters[xQ4 & SubpelMask];
- int k, sum = 0;
- for (k = 0; k < SubpelTaps; ++k)
+ int sum = 0;
+ for (int k = 0; k < SubpelTaps; ++k)
{
sum += srcX[k] * xFilter[k];
}
- dst[x] = (ushort)BitUtils.RoundPowerOfTwo(dst[x] + BitUtils.ClipPixelHighbd(BitUtils.RoundPowerOfTwo(sum, FilterBits), bd), 1);
+ dst[x] = (ushort)BitUtils.RoundPowerOfTwo(
+ dst[x] + BitUtils.ClipPixelHighbd(BitUtils.RoundPowerOfTwo(sum, FilterBits), bd), 1);
xQ4 += xStepQ4;
}
+
src += srcStride;
dst += dstStride;
}
@@ -683,18 +684,17 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
int h,
int bd)
{
- int x, y;
- src -= srcStride * (SubpelTaps / 2 - 1);
+ src -= srcStride * ((SubpelTaps / 2) - 1);
- for (x = 0; x < w; ++x)
+ for (int x = 0; x < w; ++x)
{
int yQ4 = y0Q4;
- for (y = 0; y < h; ++y)
+ for (int y = 0; y < h; ++y)
{
ushort* srcY = &src[(yQ4 >> SubpelBits) * srcStride];
ref Array8 yFilter = ref yFilters[yQ4 & SubpelMask];
- int k, sum = 0;
- for (k = 0; k < SubpelTaps; ++k)
+ int sum = 0;
+ for (int k = 0; k < SubpelTaps; ++k)
{
sum += srcY[k * srcStride] * yFilter[k];
}
@@ -702,6 +702,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dst[y * dstStride] = BitUtils.ClipPixelHighbd(BitUtils.RoundPowerOfTwo(sum, FilterBits), bd);
yQ4 += yStepQ4;
}
+
++src;
++dst;
}
@@ -719,26 +720,27 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
int h,
int bd)
{
- int x, y;
- src -= srcStride * (SubpelTaps / 2 - 1);
+ src -= srcStride * ((SubpelTaps / 2) - 1);
- for (x = 0; x < w; ++x)
+ for (int x = 0; x < w; ++x)
{
int yQ4 = y0Q4;
- for (y = 0; y < h; ++y)
+ for (int y = 0; y < h; ++y)
{
ushort* srcY = &src[(yQ4 >> SubpelBits) * srcStride];
ref Array8 yFilter = ref yFilters[yQ4 & SubpelMask];
- int k, sum = 0;
- for (k = 0; k < SubpelTaps; ++k)
+ int sum = 0;
+ for (int k = 0; k < SubpelTaps; ++k)
{
sum += srcY[k * srcStride] * yFilter[k];
}
dst[y * dstStride] = (ushort)BitUtils.RoundPowerOfTwo(
- dst[y * dstStride] + BitUtils.ClipPixelHighbd(BitUtils.RoundPowerOfTwo(sum, FilterBits), bd), 1);
+ dst[y * dstStride] + BitUtils.ClipPixelHighbd(BitUtils.RoundPowerOfTwo(sum, FilterBits), bd),
+ 1);
yQ4 += yStepQ4;
}
+
++src;
++dst;
}
@@ -771,15 +773,17 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// --Require an additional SubpelTaps rows for the 8-tap filter tails.
// --((64 - 1) * 32 + 15) >> 4 + 8 = 135.
ushort* temp = stackalloc ushort[64 * 135];
- int intermediateHeight = (((h - 1) * yStepQ4 + y0Q4) >> SubpelBits) + SubpelTaps;
+ int intermediateHeight = ((((h - 1) * yStepQ4) + y0Q4) >> SubpelBits) + SubpelTaps;
Debug.Assert(w <= 64);
Debug.Assert(h <= 64);
Debug.Assert(yStepQ4 <= 32);
Debug.Assert(xStepQ4 <= 32);
- HighbdConvolveHoriz(src - srcStride * (SubpelTaps / 2 - 1), srcStride, temp, 64, filter, x0Q4, xStepQ4, w, intermediateHeight, bd);
- HighbdConvolveVert(temp + 64 * (SubpelTaps / 2 - 1), 64, dst, dstStride, filter, y0Q4, yStepQ4, w, h, bd);
+ HighbdConvolveHoriz(src - (srcStride * ((SubpelTaps / 2) - 1)), srcStride, temp, 64, filter, x0Q4, xStepQ4,
+ w, intermediateHeight, bd);
+ HighbdConvolveVert(temp + (64 * ((SubpelTaps / 2) - 1)), 64, dst, dstStride, filter, y0Q4, yStepQ4, w, h,
+ bd);
}
public static unsafe void HighbdConvolve8Horiz(
@@ -928,11 +932,9 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
int h,
int bd)
{
- int x, y;
-
- for (y = 0; y < h; ++y)
+ for (int y = 0; y < h; ++y)
{
- for (x = 0; x < w; ++x)
+ for (int x = 0; x < w; ++x)
{
dst[x] = (ushort)BitUtils.RoundPowerOfTwo(dst[x] + src[x], 1);
}
@@ -942,4 +944,4 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/Filter.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/Filter.cs
index a32221e09..1dbbc8de5 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/Filter.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/Filter.cs
@@ -9,4 +9,4 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
public const int SubpelShifts = 1 << SubpelBits;
public const int SubpelTaps = 8;
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/IntraPred.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/IntraPred.cs
index 8a570ed59..ce53cccb4 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/IntraPred.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/IntraPred.cs
@@ -1,4 +1,4 @@
-using Ryujinx.Graphics.Nvdec.Vp9.Common;
+using Ryujinx.Graphics.Nvdec.Vp9.Common;
namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
{
@@ -6,22 +6,22 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
{
private static unsafe ref byte Dst(byte* dst, int stride, int x, int y)
{
- return ref dst[x + y * stride];
+ return ref dst[x + (y * stride)];
}
private static unsafe ref ushort Dst(ushort* dst, int stride, int x, int y)
{
- return ref dst[x + y * stride];
+ return ref dst[x + (y * stride)];
}
private static byte Avg3(byte a, byte b, byte c)
{
- return (byte)((a + 2 * b + c + 2) >> 2);
+ return (byte)((a + (2 * b) + c + 2) >> 2);
}
private static ushort Avg3(ushort a, ushort b, ushort c)
{
- return (ushort)((a + 2 * b + c + 2) >> 2);
+ return (ushort)((a + (2 * b) + c + 2) >> 2);
}
private static byte Avg2(byte a, byte b)
@@ -51,9 +51,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void D207Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int r, c;
// First column
- for (r = 0; r < bs - 1; ++r)
+ for (int r = 0; r < bs - 1; ++r)
{
dst[r * stride] = Avg2(left[r], left[r + 1]);
}
@@ -62,7 +61,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dst++;
// Second column
- for (r = 0; r < bs - 2; ++r)
+ for (int r = 0; r < bs - 2; ++r)
{
dst[r * stride] = Avg3(left[r], left[r + 1], left[r + 2]);
}
@@ -72,16 +71,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dst++;
// Rest of last row
- for (c = 0; c < bs - 2; ++c)
+ for (int c = 0; c < bs - 2; ++c)
{
- dst[(bs - 1) * stride + c] = left[bs - 1];
+ dst[((bs - 1) * stride) + c] = left[bs - 1];
}
- for (r = bs - 2; r >= 0; --r)
+ for (int r = bs - 2; r >= 0; --r)
{
- for (c = 0; c < bs - 2; ++c)
+ for (int c = 0; c < bs - 2; ++c)
{
- dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
+ dst[(r * stride) + c] = dst[((r + 1) * stride) + c - 2];
}
}
}
@@ -103,19 +102,18 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void D63Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int r, c;
- int size;
- for (c = 0; c < bs; ++c)
+ for (int c = 0; c < bs; ++c)
{
dst[c] = Avg2(above[c], above[c + 1]);
dst[stride + c] = Avg3(above[c], above[c + 1], above[c + 2]);
}
- for (r = 2, size = bs - 2; r < bs; r += 2, --size)
+
+ for (int r = 2, size = bs - 2; r < bs; r += 2, --size)
{
- MemoryUtil.Copy(dst + (r + 0) * stride, dst + (r >> 1), size);
- MemoryUtil.Fill(dst + (r + 0) * stride + size, above[bs - 1], bs - size);
- MemoryUtil.Copy(dst + (r + 1) * stride, dst + stride + (r >> 1), size);
- MemoryUtil.Fill(dst + (r + 1) * stride + size, above[bs - 1], bs - size);
+ MemoryUtil.Copy(dst + ((r + 0) * stride), dst + (r >> 1), size);
+ MemoryUtil.Fill(dst + ((r + 0) * stride) + size, above[bs - 1], bs - size);
+ MemoryUtil.Copy(dst + ((r + 1) * stride), dst + stride + (r >> 1), size);
+ MemoryUtil.Fill(dst + ((r + 1) * stride) + size, above[bs - 1], bs - size);
}
}
@@ -138,15 +136,15 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
{
byte aboveRight = above[bs - 1];
byte* dstRow0 = dst;
- int x, size;
- for (x = 0; x < bs - 1; ++x)
+ for (int x = 0; x < bs - 1; ++x)
{
dst[x] = Avg3(above[x], above[x + 1], above[x + 2]);
}
+
dst[bs - 1] = aboveRight;
dst += stride;
- for (x = 1, size = bs - 2; x < bs; ++x, --size)
+ for (int x = 1, size = bs - 2; x < bs; ++x, --size)
{
MemoryUtil.Copy(dst, dstRow0 + x, size);
MemoryUtil.Fill(dst + size, aboveRight, x + 1);
@@ -171,10 +169,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void D117Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int r, c;
-
// First row
- for (c = 0; c < bs; c++)
+ for (int c = 0; c < bs; c++)
{
dst[c] = Avg2(above[c - 1], above[c]);
}
@@ -183,7 +179,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// Second row
dst[0] = Avg3(left[0], above[-1], above[0]);
- for (c = 1; c < bs; c++)
+ for (int c = 1; c < bs; c++)
{
dst[c] = Avg3(above[c - 2], above[c - 1], above[c]);
}
@@ -192,17 +188,17 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// The rest of first col
dst[0] = Avg3(above[-1], left[0], left[1]);
- for (r = 3; r < bs; ++r)
+ for (int r = 3; r < bs; ++r)
{
dst[(r - 2) * stride] = Avg3(left[r - 3], left[r - 2], left[r - 1]);
}
// The rest of the block
- for (r = 2; r < bs; ++r)
+ for (int r = 2; r < bs; ++r)
{
- for (c = 1; c < bs; c++)
+ for (int c = 1; c < bs; c++)
{
- dst[c] = dst[-2 * stride + c - 1];
+ dst[c] = dst[(-2 * stride) + c - 1];
}
dst += stride;
@@ -226,26 +222,26 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void D135Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int i;
byte* border = stackalloc byte[32 + 32 - 1]; // outer border from bottom-left to top-right
// Dst(dst, stride, bs, bs - 2)[0], i.e., border starting at bottom-left
- for (i = 0; i < bs - 2; ++i)
+ for (int i = 0; i < bs - 2; ++i)
{
border[i] = Avg3(left[bs - 3 - i], left[bs - 2 - i], left[bs - 1 - i]);
}
+
border[bs - 2] = Avg3(above[-1], left[0], left[1]);
border[bs - 1] = Avg3(left[0], above[-1], above[0]);
border[bs - 0] = Avg3(above[-1], above[0], above[1]);
// dst[0][2, size), i.e., remaining top border ascending
- for (i = 0; i < bs - 2; ++i)
+ for (int i = 0; i < bs - 2; ++i)
{
border[bs + 1 + i] = Avg3(above[i], above[i + 1], above[i + 2]);
}
- for (i = 0; i < bs; ++i)
+ for (int i = 0; i < bs; ++i)
{
- MemoryUtil.Copy(dst + i * stride, border + bs - 1 - i, bs);
+ MemoryUtil.Copy(dst + (i * stride), border + bs - 1 - i, bs);
}
}
@@ -266,9 +262,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void D153Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int r, c;
dst[0] = Avg2(above[-1], left[0]);
- for (r = 1; r < bs; r++)
+ for (int r = 1; r < bs; r++)
{
dst[r * stride] = Avg2(left[r - 1], left[r]);
}
@@ -277,23 +272,23 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dst[0] = Avg3(left[0], above[-1], above[0]);
dst[stride] = Avg3(above[-1], left[0], left[1]);
- for (r = 2; r < bs; r++)
+ for (int r = 2; r < bs; r++)
{
dst[r * stride] = Avg3(left[r - 2], left[r - 1], left[r]);
}
dst++;
- for (c = 0; c < bs - 2; c++)
+ for (int c = 0; c < bs - 2; c++)
{
dst[c] = Avg3(above[c - 1], above[c], above[c + 1]);
}
dst += stride;
- for (r = 1; r < bs; ++r)
+ for (int r = 1; r < bs; ++r)
{
- for (c = 0; c < bs - 2; c++)
+ for (int c = 0; c < bs - 2; c++)
{
dst[c] = dst[-stride + c - 2];
}
@@ -324,9 +319,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void VPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int r;
-
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Copy(dst, above, bs);
dst += stride;
@@ -355,43 +348,40 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void HPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int r;
-
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Fill(dst, left[r], bs);
dst += stride;
}
}
- public static unsafe void TMPredictor4x4(byte* dst, int stride, byte* above, byte* left)
+ public static unsafe void TmPredictor4x4(byte* dst, int stride, byte* above, byte* left)
{
- TMPredictor(dst, stride, 4, above, left);
+ TmPredictor(dst, stride, 4, above, left);
}
- public static unsafe void TMPredictor8x8(byte* dst, int stride, byte* above, byte* left)
+ public static unsafe void TmPredictor8x8(byte* dst, int stride, byte* above, byte* left)
{
- TMPredictor(dst, stride, 8, above, left);
+ TmPredictor(dst, stride, 8, above, left);
}
- public static unsafe void TMPredictor16x16(byte* dst, int stride, byte* above, byte* left)
+ public static unsafe void TmPredictor16x16(byte* dst, int stride, byte* above, byte* left)
{
- TMPredictor(dst, stride, 16, above, left);
+ TmPredictor(dst, stride, 16, above, left);
}
- public static unsafe void TMPredictor32x32(byte* dst, int stride, byte* above, byte* left)
+ public static unsafe void TmPredictor32x32(byte* dst, int stride, byte* above, byte* left)
{
- TMPredictor(dst, stride, 32, above, left);
+ TmPredictor(dst, stride, 32, above, left);
}
- private static unsafe void TMPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
+ private static unsafe void TmPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int r, c;
int yTopLeft = above[-1];
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
- for (c = 0; c < bs; c++)
+ for (int c = 0; c < bs; c++)
{
dst[c] = BitUtils.ClipPixel(left[r] + above[c] - yTopLeft);
}
@@ -422,9 +412,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void Dc128Predictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int r;
-
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Fill(dst, (byte)128, bs);
dst += stride;
@@ -453,16 +441,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void DcLeftPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int i, r, expectedDc, sum = 0;
+ int expectedDc, sum = 0;
- for (i = 0; i < bs; i++)
+ for (int i = 0; i < bs; i++)
{
sum += left[i];
}
expectedDc = (sum + (bs >> 1)) / bs;
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Fill(dst, (byte)expectedDc, bs);
dst += stride;
@@ -491,16 +479,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void DcTopPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int i, r, expectedDc, sum = 0;
+ int expectedDc, sum = 0;
- for (i = 0; i < bs; i++)
+ for (int i = 0; i < bs; i++)
{
sum += above[i];
}
expectedDc = (sum + (bs >> 1)) / bs;
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Fill(dst, (byte)expectedDc, bs);
dst += stride;
@@ -529,10 +517,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static unsafe void DcPredictor(byte* dst, int stride, int bs, byte* above, byte* left)
{
- int i, r, expectedDc, sum = 0;
+ int expectedDc, sum = 0;
int count = 2 * bs;
- for (i = 0; i < bs; i++)
+ for (int i = 0; i < bs; i++)
{
sum += above[i];
sum += left[i];
@@ -540,7 +528,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
expectedDc = (sum + (count >> 1)) / count;
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Fill(dst, (byte)expectedDc, bs);
dst += stride;
@@ -555,10 +543,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
byte k = left[2];
byte l = left[3];
- MemoryUtil.Fill(dst + stride * 0, Avg3(h, I, j), 4);
- MemoryUtil.Fill(dst + stride * 1, Avg3(I, j, k), 4);
- MemoryUtil.Fill(dst + stride * 2, Avg3(j, k, l), 4);
- MemoryUtil.Fill(dst + stride * 3, Avg3(k, l, l), 4);
+ MemoryUtil.Fill(dst + (stride * 0), Avg3(h, I, j), 4);
+ MemoryUtil.Fill(dst + (stride * 1), Avg3(I, j, k), 4);
+ MemoryUtil.Fill(dst + (stride * 2), Avg3(j, k, l), 4);
+ MemoryUtil.Fill(dst + (stride * 3), Avg3(k, l, l), 4);
}
public static unsafe void VePredictor4x4(byte* dst, int stride, byte* above, byte* left)
@@ -574,9 +562,9 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dst[1] = Avg3(I, j, k);
dst[2] = Avg3(j, k, l);
dst[3] = Avg3(k, l, m);
- MemoryUtil.Copy(dst + stride * 1, dst, 4);
- MemoryUtil.Copy(dst + stride * 2, dst, 4);
- MemoryUtil.Copy(dst + stride * 3, dst, 4);
+ MemoryUtil.Copy(dst + (stride * 1), dst, 4);
+ MemoryUtil.Copy(dst + (stride * 2), dst, 4);
+ MemoryUtil.Copy(dst + (stride * 3), dst, 4);
}
public static unsafe void D207Predictor4x4(byte* dst, int stride, byte* above, byte* left)
@@ -591,7 +579,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Dst(dst, stride, 1, 0) = Avg3(I, j, k);
Dst(dst, stride, 3, 0) = Dst(dst, stride, 1, 1) = Avg3(j, k, l);
Dst(dst, stride, 3, 1) = Dst(dst, stride, 1, 2) = Avg3(k, l, l);
- Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 0, 3) = Dst(dst, stride, 1, 3) = Dst(dst, stride, 2, 3) = Dst(dst, stride, 3, 3) = l;
+ Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 0, 3) =
+ Dst(dst, stride, 1, 3) = Dst(dst, stride, 2, 3) = Dst(dst, stride, 3, 3) = l;
}
public static unsafe void D63Predictor4x4(byte* dst, int stride, byte* above, byte* left)
@@ -616,7 +605,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Dst(dst, stride, 3, 3) = Avg3(e, f, g); // Differs from vp8
}
- public static unsafe void D63ePredictor4x4(byte* dst, int stride, byte* above, byte* left)
+ public static unsafe void D63EPredictor4x4(byte* dst, int stride, byte* above, byte* left)
{
byte a = above[0];
byte b = above[1];
@@ -652,13 +641,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Dst(dst, stride, 0, 0) = Avg3(a, b, c);
Dst(dst, stride, 1, 0) = Dst(dst, stride, 0, 1) = Avg3(b, c, d);
Dst(dst, stride, 2, 0) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 2) = Avg3(c, d, e);
- Dst(dst, stride, 3, 0) = Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 3) = Avg3(d, e, f);
+ Dst(dst, stride, 3, 0) =
+ Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 3) = Avg3(d, e, f);
Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 3) = Avg3(e, f, g);
Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 3) = Avg3(f, g, h);
Dst(dst, stride, 3, 3) = h; // differs from vp8
}
- public static unsafe void D45ePredictor4x4(byte* dst, int stride, byte* above, byte* left)
+ public static unsafe void D45EPredictor4x4(byte* dst, int stride, byte* above, byte* left)
{
byte a = above[0];
byte b = above[1];
@@ -671,7 +661,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Dst(dst, stride, 0, 0) = Avg3(a, b, c);
Dst(dst, stride, 1, 0) = Dst(dst, stride, 0, 1) = Avg3(b, c, d);
Dst(dst, stride, 2, 0) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 2) = Avg3(c, d, e);
- Dst(dst, stride, 3, 0) = Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 3) = Avg3(d, e, f);
+ Dst(dst, stride, 3, 0) =
+ Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 3) = Avg3(d, e, f);
Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 3) = Avg3(e, f, g);
Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 3) = Avg3(f, g, h);
Dst(dst, stride, 3, 3) = Avg3(g, h, h);
@@ -714,7 +705,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Dst(dst, stride, 0, 3) = Avg3(j, k, l);
Dst(dst, stride, 1, 3) = Dst(dst, stride, 0, 2) = Avg3(I, j, k);
Dst(dst, stride, 2, 3) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 1) = Avg3(x, I, j);
- Dst(dst, stride, 3, 3) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 0) = Avg3(a, x, I);
+ Dst(dst, stride, 3, 3) =
+ Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 0) = Avg3(a, x, I);
Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 0) = Avg3(b, a, x);
Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 0) = Avg3(c, b, a);
Dst(dst, stride, 3, 0) = Avg3(d, c, b);
@@ -758,38 +750,39 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdD207Predictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdD207Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdD207Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int r, c;
-
// First column.
- for (r = 0; r < bs - 1; ++r)
+ for (int r = 0; r < bs - 1; ++r)
{
dst[r * stride] = Avg2(left[r], left[r + 1]);
}
+
dst[(bs - 1) * stride] = left[bs - 1];
dst++;
// Second column.
- for (r = 0; r < bs - 2; ++r)
+ for (int r = 0; r < bs - 2; ++r)
{
dst[r * stride] = Avg3(left[r], left[r + 1], left[r + 2]);
}
+
dst[(bs - 2) * stride] = Avg3(left[bs - 2], left[bs - 1], left[bs - 1]);
dst[(bs - 1) * stride] = left[bs - 1];
dst++;
// Rest of last row.
- for (c = 0; c < bs - 2; ++c)
+ for (int c = 0; c < bs - 2; ++c)
{
- dst[(bs - 1) * stride + c] = left[bs - 1];
+ dst[((bs - 1) * stride) + c] = left[bs - 1];
}
- for (r = bs - 2; r >= 0; --r)
+ for (int r = bs - 2; r >= 0; --r)
{
- for (c = 0; c < bs - 2; ++c)
+ for (int c = 0; c < bs - 2; ++c)
{
- dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
+ dst[(r * stride) + c] = dst[((r + 1) * stride) + c - 2];
}
}
}
@@ -809,21 +802,21 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdD63Predictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdD63Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdD63Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int r, c;
- int size;
- for (c = 0; c < bs; ++c)
+ for (int c = 0; c < bs; ++c)
{
dst[c] = Avg2(above[c], above[c + 1]);
dst[stride + c] = Avg3(above[c], above[c + 1], above[c + 2]);
}
- for (r = 2, size = bs - 2; r < bs; r += 2, --size)
+
+ for (int r = 2, size = bs - 2; r < bs; r += 2, --size)
{
- MemoryUtil.Copy(dst + (r + 0) * stride, dst + (r >> 1), size);
- MemoryUtil.Fill(dst + (r + 0) * stride + size, above[bs - 1], bs - size);
- MemoryUtil.Copy(dst + (r + 1) * stride, dst + stride + (r >> 1), size);
- MemoryUtil.Fill(dst + (r + 1) * stride + size, above[bs - 1], bs - size);
+ MemoryUtil.Copy(dst + ((r + 0) * stride), dst + (r >> 1), size);
+ MemoryUtil.Fill(dst + ((r + 0) * stride) + size, above[bs - 1], bs - size);
+ MemoryUtil.Copy(dst + ((r + 1) * stride), dst + stride + (r >> 1), size);
+ MemoryUtil.Fill(dst + ((r + 1) * stride) + size, above[bs - 1], bs - size);
}
}
@@ -842,19 +835,20 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdD45Predictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdD45Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdD45Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
ushort aboveRight = above[bs - 1];
ushort* dstRow0 = dst;
- int x, size;
- for (x = 0; x < bs - 1; ++x)
+ for (int x = 0; x < bs - 1; ++x)
{
dst[x] = Avg3(above[x], above[x + 1], above[x + 2]);
}
+
dst[bs - 1] = aboveRight;
dst += stride;
- for (x = 1, size = bs - 2; x < bs; ++x, --size)
+ for (int x = 1, size = bs - 2; x < bs; ++x, --size)
{
MemoryUtil.Copy(dst, dstRow0 + x, size);
MemoryUtil.Fill(dst + size, aboveRight, x + 1);
@@ -877,12 +871,11 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdD117Predictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdD117Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdD117Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int r, c;
-
// First row
- for (c = 0; c < bs; c++)
+ for (int c = 0; c < bs; c++)
{
dst[c] = Avg2(above[c - 1], above[c]);
}
@@ -891,7 +884,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// Second row
dst[0] = Avg3(left[0], above[-1], above[0]);
- for (c = 1; c < bs; c++)
+ for (int c = 1; c < bs; c++)
{
dst[c] = Avg3(above[c - 2], above[c - 1], above[c]);
}
@@ -900,17 +893,17 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// The rest of first col
dst[0] = Avg3(above[-1], left[0], left[1]);
- for (r = 3; r < bs; ++r)
+ for (int r = 3; r < bs; ++r)
{
dst[(r - 2) * stride] = Avg3(left[r - 3], left[r - 2], left[r - 1]);
}
// The rest of the block
- for (r = 2; r < bs; ++r)
+ for (int r = 2; r < bs; ++r)
{
- for (c = 1; c < bs; c++)
+ for (int c = 1; c < bs; c++)
{
- dst[c] = dst[-2 * stride + c - 1];
+ dst[c] = dst[(-2 * stride) + c - 1];
}
dst += stride;
@@ -932,28 +925,29 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdD135Predictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdD135Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdD135Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int i;
ushort* border = stackalloc ushort[32 + 32 - 1]; // Outer border from bottom-left to top-right
// Dst(dst, stride, bs, bs - 2)[0], i.e., border starting at bottom-left
- for (i = 0; i < bs - 2; ++i)
+ for (int i = 0; i < bs - 2; ++i)
{
border[i] = Avg3(left[bs - 3 - i], left[bs - 2 - i], left[bs - 1 - i]);
}
+
border[bs - 2] = Avg3(above[-1], left[0], left[1]);
border[bs - 1] = Avg3(left[0], above[-1], above[0]);
border[bs - 0] = Avg3(above[-1], above[0], above[1]);
// dst[0][2, size), i.e., remaining top border ascending
- for (i = 0; i < bs - 2; ++i)
+ for (int i = 0; i < bs - 2; ++i)
{
border[bs + 1 + i] = Avg3(above[i], above[i + 1], above[i + 2]);
}
- for (i = 0; i < bs; ++i)
+ for (int i = 0; i < bs; ++i)
{
- MemoryUtil.Copy(dst + i * stride, border + bs - 1 - i, bs);
+ MemoryUtil.Copy(dst + (i * stride), border + bs - 1 - i, bs);
}
}
@@ -972,11 +966,11 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdD153Predictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdD153Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdD153Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int r, c;
dst[0] = Avg2(above[-1], left[0]);
- for (r = 1; r < bs; r++)
+ for (int r = 1; r < bs; r++)
{
dst[r * stride] = Avg2(left[r - 1], left[r]);
}
@@ -985,23 +979,23 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dst[0] = Avg3(left[0], above[-1], above[0]);
dst[stride] = Avg3(above[-1], left[0], left[1]);
- for (r = 2; r < bs; r++)
+ for (int r = 2; r < bs; r++)
{
dst[r * stride] = Avg3(left[r - 2], left[r - 1], left[r]);
}
dst++;
- for (c = 0; c < bs - 2; c++)
+ for (int c = 0; c < bs - 2; c++)
{
dst[c] = Avg3(above[c - 1], above[c], above[c + 1]);
}
dst += stride;
- for (r = 1; r < bs; ++r)
+ for (int r = 1; r < bs; ++r)
{
- for (c = 0; c < bs - 2; c++)
+ for (int c = 0; c < bs - 2; c++)
{
dst[c] = dst[-stride + c - 2];
}
@@ -1030,10 +1024,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdVPredictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdVPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdVPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int r;
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Copy(dst, above, bs);
dst += stride;
@@ -1060,44 +1054,44 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdHPredictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdHPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdHPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int r;
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Fill(dst, left[r], bs);
dst += stride;
}
}
- public static unsafe void HighbdTMPredictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
+ public static unsafe void HighbdTmPredictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
{
- HighbdTMPredictor(dst, stride, 4, above, left, bd);
+ HighbdTmPredictor(dst, stride, 4, above, left, bd);
}
- public static unsafe void HighbdTMPredictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
+ public static unsafe void HighbdTmPredictor8x8(ushort* dst, int stride, ushort* above, ushort* left, int bd)
{
- HighbdTMPredictor(dst, stride, 8, above, left, bd);
+ HighbdTmPredictor(dst, stride, 8, above, left, bd);
}
- public static unsafe void HighbdTMPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
+ public static unsafe void HighbdTmPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
{
- HighbdTMPredictor(dst, stride, 16, above, left, bd);
+ HighbdTmPredictor(dst, stride, 16, above, left, bd);
}
- public static unsafe void HighbdTMPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
+ public static unsafe void HighbdTmPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
{
- HighbdTMPredictor(dst, stride, 32, above, left, bd);
+ HighbdTmPredictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdTMPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdTmPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int r, c;
int yTopLeft = above[-1];
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
- for (c = 0; c < bs; c++)
+ for (int c = 0; c < bs; c++)
{
dst[c] = BitUtils.ClipPixelHighbd(left[r] + above[c] - yTopLeft, bd);
}
@@ -1116,21 +1110,22 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdDc128Predictor(dst, stride, 8, above, left, bd);
}
- public static unsafe void HighbdDc128Predictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
+ public static unsafe void HighbdDc128Predictor16x16(ushort* dst, int stride, ushort* above, ushort* left,
+ int bd)
{
HighbdDc128Predictor(dst, stride, 16, above, left, bd);
}
- public static unsafe void HighbdDc128Predictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
+ public static unsafe void HighbdDc128Predictor32x32(ushort* dst, int stride, ushort* above, ushort* left,
+ int bd)
{
HighbdDc128Predictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdDc128Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdDc128Predictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int r;
-
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Fill(dst, (ushort)(128 << (bd - 8)), bs);
dst += stride;
@@ -1147,28 +1142,31 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdDcLeftPredictor(dst, stride, 8, above, left, bd);
}
- public static unsafe void HighbdDcLeftPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
+ public static unsafe void HighbdDcLeftPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left,
+ int bd)
{
HighbdDcLeftPredictor(dst, stride, 16, above, left, bd);
}
- public static unsafe void HighbdDcLeftPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
+ public static unsafe void HighbdDcLeftPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left,
+ int bd)
{
HighbdDcLeftPredictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdDcLeftPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdDcLeftPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int i, r, expectedDc, sum = 0;
+ int expectedDc, sum = 0;
- for (i = 0; i < bs; i++)
+ for (int i = 0; i < bs; i++)
{
sum += left[i];
}
expectedDc = (sum + (bs >> 1)) / bs;
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Fill(dst, (ushort)expectedDc, bs);
dst += stride;
@@ -1185,28 +1183,31 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdDcTopPredictor(dst, stride, 8, above, left, bd);
}
- public static unsafe void HighbdDcTopPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left, int bd)
+ public static unsafe void HighbdDcTopPredictor16x16(ushort* dst, int stride, ushort* above, ushort* left,
+ int bd)
{
HighbdDcTopPredictor(dst, stride, 16, above, left, bd);
}
- public static unsafe void HighbdDcTopPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left, int bd)
+ public static unsafe void HighbdDcTopPredictor32x32(ushort* dst, int stride, ushort* above, ushort* left,
+ int bd)
{
HighbdDcTopPredictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdDcTopPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdDcTopPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int i, r, expectedDc, sum = 0;
+ int expectedDc, sum = 0;
- for (i = 0; i < bs; i++)
+ for (int i = 0; i < bs; i++)
{
sum += above[i];
}
expectedDc = (sum + (bs >> 1)) / bs;
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Fill(dst, (ushort)expectedDc, bs);
dst += stride;
@@ -1233,12 +1234,13 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
HighbdDcPredictor(dst, stride, 32, above, left, bd);
}
- private static unsafe void HighbdDcPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left, int bd)
+ private static unsafe void HighbdDcPredictor(ushort* dst, int stride, int bs, ushort* above, ushort* left,
+ int bd)
{
- int i, r, expectedDc, sum = 0;
+ int expectedDc, sum = 0;
int count = 2 * bs;
- for (i = 0; i < bs; i++)
+ for (int i = 0; i < bs; i++)
{
sum += above[i];
sum += left[i];
@@ -1246,7 +1248,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
expectedDc = (sum + (count >> 1)) / count;
- for (r = 0; r < bs; r++)
+ for (int r = 0; r < bs; r++)
{
MemoryUtil.Fill(dst, (ushort)expectedDc, bs);
dst += stride;
@@ -1265,7 +1267,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Dst(dst, stride, 1, 0) = Avg3(I, j, k);
Dst(dst, stride, 3, 0) = Dst(dst, stride, 1, 1) = Avg3(j, k, l);
Dst(dst, stride, 3, 1) = Dst(dst, stride, 1, 2) = Avg3(k, l, l);
- Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 0, 3) = Dst(dst, stride, 1, 3) = Dst(dst, stride, 2, 3) = Dst(dst, stride, 3, 3) = l;
+ Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 0, 3) =
+ Dst(dst, stride, 1, 3) = Dst(dst, stride, 2, 3) = Dst(dst, stride, 3, 3) = l;
}
public static unsafe void HighbdD63Predictor4x4(ushort* dst, int stride, ushort* above, ushort* left, int bd)
@@ -1303,7 +1306,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Dst(dst, stride, 0, 0) = Avg3(a, b, c);
Dst(dst, stride, 1, 0) = Dst(dst, stride, 0, 1) = Avg3(b, c, d);
Dst(dst, stride, 2, 0) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 2) = Avg3(c, d, e);
- Dst(dst, stride, 3, 0) = Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 3) = Avg3(d, e, f);
+ Dst(dst, stride, 3, 0) =
+ Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 3) = Avg3(d, e, f);
Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 3) = Avg3(e, f, g);
Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 3) = Avg3(f, g, h);
Dst(dst, stride, 3, 3) = h; // Differs from vp8
@@ -1346,7 +1350,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Dst(dst, stride, 0, 3) = Avg3(j, k, l);
Dst(dst, stride, 1, 3) = Dst(dst, stride, 0, 2) = Avg3(I, j, k);
Dst(dst, stride, 2, 3) = Dst(dst, stride, 1, 2) = Dst(dst, stride, 0, 1) = Avg3(x, I, j);
- Dst(dst, stride, 3, 3) = Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 0) = Avg3(a, x, I);
+ Dst(dst, stride, 3, 3) =
+ Dst(dst, stride, 2, 2) = Dst(dst, stride, 1, 1) = Dst(dst, stride, 0, 0) = Avg3(a, x, I);
Dst(dst, stride, 3, 2) = Dst(dst, stride, 2, 1) = Dst(dst, stride, 1, 0) = Avg3(b, a, x);
Dst(dst, stride, 3, 1) = Dst(dst, stride, 2, 0) = Avg3(c, b, a);
Dst(dst, stride, 3, 0) = Avg3(d, c, b);
@@ -1376,4 +1381,4 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
Dst(dst, stride, 1, 3) = Avg3(l, k, j);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/InvTxfm.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/InvTxfm.cs
index c4f45bfda..d93ff25f7 100644
--- a/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/InvTxfm.cs
+++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Dsp/InvTxfm.cs
@@ -1,4 +1,4 @@
-using Ryujinx.Graphics.Nvdec.Vp9.Common;
+using Ryujinx.Graphics.Nvdec.Vp9.Common;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
@@ -10,13 +10,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
{
// 12 signal input bits + 7 2D forward transform amplify bits + 5 1D inverse
// transform amplify bits + 1 bit for contingency in rounding and quantizing
- private const int HighbdValidTxfmMagnitudeRange = (1 << 25);
+ private const int HighbdValidTxfmMagnitudeRange = 1 << 25;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int DetectInvalidHighbdInput(ReadOnlySpan input, int size)
{
- int i;
- for (i = 0; i < size; ++i)
+ for (int i = 0; i < size; ++i)
{
if (Math.Abs(input[i]) >= HighbdValidTxfmMagnitudeRange)
{
@@ -35,7 +34,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// of this range for invalid/corrupt VP9 streams.
Debug.Assert(short.MinValue <= input);
Debug.Assert(input <= short.MaxValue);
-
return input;
}
@@ -71,7 +69,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
public static byte ClipPixelAdd(byte dest, long trans)
{
trans = WrapLow(trans);
-
return BitUtils.ClipPixel(dest + (int)trans);
}
@@ -79,7 +76,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
public static ushort HighbdClipPixelAdd(ushort dest, long trans, int bd)
{
trans = HighbdWrapLow(trans, bd);
-
return BitUtils.ClipPixelHighbd(dest + (int)trans, bd);
}
@@ -87,7 +83,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private static long DctConstRoundShift(long input)
{
long rv = BitUtils.RoundPowerOfTwo(input, DctConstBits);
-
return rv;
}
@@ -96,13 +91,13 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
{
/* 4-point reversible, orthonormal inverse Walsh-Hadamard in 3.5 adds,
0.5 shifts per pixel. */
- int i;
+
Span output = stackalloc int[16];
long a1, b1, c1, d1, e1;
ReadOnlySpan ip = input;
Span op = output;
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
a1 = ip[0] >> UnitQuantShift;
c1 = ip[1] >> UnitQuantShift;
@@ -119,12 +114,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
op[1] = WrapLow(b1);
op[2] = WrapLow(c1);
op[3] = WrapLow(d1);
- ip = ip[4..];
- op = op[4..];
+ ip = ip.Slice(4);
+ op = op.Slice(4);
}
Span ip2 = output;
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
a1 = ip2[4 * 0];
c1 = ip2[4 * 1];
@@ -142,15 +137,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dest[stride * 2] = ClipPixelAdd(dest[stride * 2], WrapLow(c1));
dest[stride * 3] = ClipPixelAdd(dest[stride * 3], WrapLow(d1));
- ip2 = ip2[1..];
- dest = dest[1..];
+ ip2 = ip2.Slice(1);
+ dest = dest.Slice(1);
}
}
[SkipLocalsInit]
public static void Iwht4x41Add(ReadOnlySpan input, Span dest, int stride)
{
- int i;
long a1, e1;
Span tmp = stackalloc int[4];
ReadOnlySpan ip = input;
@@ -163,7 +157,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
op[1] = op[2] = op[3] = WrapLow(e1);
Span ip2 = tmp;
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
e1 = ip2[0] >> 1;
a1 = ip2[0] - e1;
@@ -171,8 +165,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dest[stride * 1] = ClipPixelAdd(dest[stride * 1], e1);
dest[stride * 2] = ClipPixelAdd(dest[stride * 2], e1);
dest[stride * 3] = ClipPixelAdd(dest[stride * 3], e1);
- ip2 = ip2[1..];
- dest = dest[1..];
+ ip2 = ip2.Slice(1);
+ dest = dest.Slice(1);
}
}
@@ -186,25 +180,24 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
if ((x0 | x1 | x2 | x3) == 0)
{
- output[..4].Clear();
-
+ output.Slice(0, 4).Clear();
return;
}
// 32-bit result is enough for the following multiplications.
- s0 = SinPi1_9 * x0;
- s1 = SinPi2_9 * x0;
- s2 = SinPi3_9 * x1;
- s3 = SinPi4_9 * x2;
- s4 = SinPi1_9 * x2;
- s5 = SinPi2_9 * x3;
- s6 = SinPi4_9 * x3;
+ s0 = SinPi19 * x0;
+ s1 = SinPi29 * x0;
+ s2 = SinPi39 * x1;
+ s3 = SinPi49 * x2;
+ s4 = SinPi19 * x2;
+ s5 = SinPi29 * x3;
+ s6 = SinPi49 * x3;
s7 = WrapLow(x0 - x2 + x3);
s0 = s0 + s3 + s5;
s1 = s1 - s4 - s6;
s3 = s2;
- s2 = SinPi3_9 * s7;
+ s2 = SinPi39 * s7;
// 1-D transform scaling factor is sqrt(2).
// The overall dynamic range is 14b (input) + 14b (multiplication scaling)
@@ -223,12 +216,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
long temp1, temp2;
// stage 1
- temp1 = ((short)input[0] + (short)input[2]) * CosPi16_64;
- temp2 = ((short)input[0] - (short)input[2]) * CosPi16_64;
+ temp1 = ((short)input[0] + (short)input[2]) * CosPi1664;
+ temp2 = ((short)input[0] - (short)input[2]) * CosPi1664;
step[0] = (short)WrapLow(DctConstRoundShift(temp1));
step[1] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (short)input[1] * CosPi24_64 - (short)input[3] * CosPi8_64;
- temp2 = (short)input[1] * CosPi8_64 + (short)input[3] * CosPi24_64;
+ temp1 = ((short)input[1] * CosPi2464) - ((short)input[3] * CosPi864);
+ temp2 = ((short)input[1] * CosPi864) + ((short)input[3] * CosPi2464);
step[2] = (short)WrapLow(DctConstRoundShift(temp1));
step[3] = (short)WrapLow(DctConstRoundShift(temp2));
@@ -242,52 +235,51 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void Idct4x416Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
Span output = stackalloc int[4 * 4];
Span outptr = output;
Span tempIn = stackalloc int[4];
Span tempOut = stackalloc int[4];
// Rows
- for (i = 0; i < 4; ++i)
+ for (int i = 0; i < 4; ++i)
{
Idct4(input, outptr);
- input = input[4..];
- outptr = outptr[4..];
+ input = input.Slice(4);
+ outptr = outptr.Slice(4);
}
// Columns
- for (i = 0; i < 4; ++i)
+ for (int i = 0; i < 4; ++i)
{
- for (j = 0; j < 4; ++j)
+ for (int j = 0; j < 4; ++j)
{
- tempIn[j] = output[j * 4 + i];
+ tempIn[j] = output[(j * 4) + i];
}
Idct4(tempIn, tempOut);
- for (j = 0; j < 4; ++j)
+ for (int j = 0; j < 4; ++j)
{
- dest[j * stride + i] = ClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 4));
+ dest[(j * stride) + i] =
+ ClipPixelAdd(dest[(j * stride) + i], BitUtils.RoundPowerOfTwo(tempOut[j], 4));
}
}
}
public static void Idct4x41Add(ReadOnlySpan input, Span dest, int stride)
{
- int i;
long a1;
- int output = WrapLow(DctConstRoundShift((short)input[0] * CosPi16_64));
+ int output = WrapLow(DctConstRoundShift((short)input[0] * CosPi1664));
- output = WrapLow(DctConstRoundShift(output * CosPi16_64));
+ output = WrapLow(DctConstRoundShift(output * CosPi1664));
a1 = BitUtils.RoundPowerOfTwo(output, 4);
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
dest[0] = ClipPixelAdd(dest[0], a1);
dest[1] = ClipPixelAdd(dest[1], a1);
dest[2] = ClipPixelAdd(dest[2], a1);
dest[3] = ClipPixelAdd(dest[3], a1);
- dest = dest[stride..];
+ dest = dest.Slice(stride);
}
}
@@ -305,20 +297,19 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
if ((x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7) == 0)
{
- output[..8].Clear();
-
+ output.Slice(0, 8).Clear();
return;
}
// stage 1
- s0 = (int)(CosPi2_64 * x0 + CosPi30_64 * x1);
- s1 = (int)(CosPi30_64 * x0 - CosPi2_64 * x1);
- s2 = (int)(CosPi10_64 * x2 + CosPi22_64 * x3);
- s3 = (int)(CosPi22_64 * x2 - CosPi10_64 * x3);
- s4 = (int)(CosPi18_64 * x4 + CosPi14_64 * x5);
- s5 = (int)(CosPi14_64 * x4 - CosPi18_64 * x5);
- s6 = (int)(CosPi26_64 * x6 + CosPi6_64 * x7);
- s7 = (int)(CosPi6_64 * x6 - CosPi26_64 * x7);
+ s0 = (int)((CosPi264 * x0) + (CosPi3064 * x1));
+ s1 = (int)((CosPi3064 * x0) - (CosPi264 * x1));
+ s2 = (int)((CosPi1064 * x2) + (CosPi2264 * x3));
+ s3 = (int)((CosPi2264 * x2) - (CosPi1064 * x3));
+ s4 = (int)((CosPi1864 * x4) + (CosPi1464 * x5));
+ s5 = (int)((CosPi1464 * x4) - (CosPi1864 * x5));
+ s6 = (int)((CosPi2664 * x6) + (CosPi664 * x7));
+ s7 = (int)((CosPi664 * x6) - (CosPi2664 * x7));
x0 = WrapLow(DctConstRoundShift(s0 + s4));
x1 = WrapLow(DctConstRoundShift(s1 + s5));
@@ -334,10 +325,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
s1 = (int)x1;
s2 = (int)x2;
s3 = (int)x3;
- s4 = (int)(CosPi8_64 * x4 + CosPi24_64 * x5);
- s5 = (int)(CosPi24_64 * x4 - CosPi8_64 * x5);
- s6 = (int)(-CosPi24_64 * x6 + CosPi8_64 * x7);
- s7 = (int)(CosPi8_64 * x6 + CosPi24_64 * x7);
+ s4 = (int)((CosPi864 * x4) + (CosPi2464 * x5));
+ s5 = (int)((CosPi2464 * x4) - (CosPi864 * x5));
+ s6 = (int)((-CosPi2464 * x6) + (CosPi864 * x7));
+ s7 = (int)((CosPi864 * x6) + (CosPi2464 * x7));
x0 = WrapLow(s0 + s2);
x1 = WrapLow(s1 + s3);
@@ -349,10 +340,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
x7 = WrapLow(DctConstRoundShift(s5 - s7));
// stage 3
- s2 = (int)(CosPi16_64 * (x2 + x3));
- s3 = (int)(CosPi16_64 * (x2 - x3));
- s6 = (int)(CosPi16_64 * (x6 + x7));
- s7 = (int)(CosPi16_64 * (x6 - x7));
+ s2 = (int)(CosPi1664 * (x2 + x3));
+ s3 = (int)(CosPi1664 * (x2 - x3));
+ s6 = (int)(CosPi1664 * (x6 + x7));
+ s7 = (int)(CosPi1664 * (x6 - x7));
x2 = WrapLow(DctConstRoundShift(s2));
x3 = WrapLow(DctConstRoundShift(s3));
@@ -381,22 +372,22 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[2] = (short)input[4];
step1[1] = (short)input[2];
step1[3] = (short)input[6];
- temp1 = (short)input[1] * CosPi28_64 - (short)input[7] * CosPi4_64;
- temp2 = (short)input[1] * CosPi4_64 + (short)input[7] * CosPi28_64;
+ temp1 = ((short)input[1] * CosPi2864) - ((short)input[7] * CosPi464);
+ temp2 = ((short)input[1] * CosPi464) + ((short)input[7] * CosPi2864);
step1[4] = (short)WrapLow(DctConstRoundShift(temp1));
step1[7] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (short)input[5] * CosPi12_64 - (short)input[3] * CosPi20_64;
- temp2 = (short)input[5] * CosPi20_64 + (short)input[3] * CosPi12_64;
+ temp1 = ((short)input[5] * CosPi1264) - ((short)input[3] * CosPi2064);
+ temp2 = ((short)input[5] * CosPi2064) + ((short)input[3] * CosPi1264);
step1[5] = (short)WrapLow(DctConstRoundShift(temp1));
step1[6] = (short)WrapLow(DctConstRoundShift(temp2));
// stage 2
- temp1 = (step1[0] + step1[2]) * CosPi16_64;
- temp2 = (step1[0] - step1[2]) * CosPi16_64;
+ temp1 = (step1[0] + step1[2]) * CosPi1664;
+ temp2 = (step1[0] - step1[2]) * CosPi1664;
step2[0] = (short)WrapLow(DctConstRoundShift(temp1));
step2[1] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step1[1] * CosPi24_64 - step1[3] * CosPi8_64;
- temp2 = step1[1] * CosPi8_64 + step1[3] * CosPi24_64;
+ temp1 = (step1[1] * CosPi2464) - (step1[3] * CosPi864);
+ temp2 = (step1[1] * CosPi864) + (step1[3] * CosPi2464);
step2[2] = (short)WrapLow(DctConstRoundShift(temp1));
step2[3] = (short)WrapLow(DctConstRoundShift(temp2));
step2[4] = (short)WrapLow(step1[4] + step1[5]);
@@ -410,8 +401,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[2] = (short)WrapLow(step2[1] - step2[2]);
step1[3] = (short)WrapLow(step2[0] - step2[3]);
step1[4] = step2[4];
- temp1 = (step2[6] - step2[5]) * CosPi16_64;
- temp2 = (step2[5] + step2[6]) * CosPi16_64;
+ temp1 = (step2[6] - step2[5]) * CosPi1664;
+ temp2 = (step2[5] + step2[6]) * CosPi1664;
step1[5] = (short)WrapLow(DctConstRoundShift(temp1));
step1[6] = (short)WrapLow(DctConstRoundShift(temp2));
step1[7] = step2[7];
@@ -430,33 +421,32 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void Idct8x864Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
Span output = stackalloc int[8 * 8];
Span outptr = output;
Span tempIn = stackalloc int[8];
Span tempOut = stackalloc int[8];
// First transform rows
- for (i = 0; i < 8; ++i)
+ for (int i = 0; i < 8; ++i)
{
Idct8(input, outptr);
- input = input[8..];
- outptr = outptr[8..];
+ input = input.Slice(8);
+ outptr = outptr.Slice(8);
}
// Then transform columns
- for (i = 0; i < 8; ++i)
+ for (int i = 0; i < 8; ++i)
{
- for (j = 0; j < 8; ++j)
+ for (int j = 0; j < 8; ++j)
{
- tempIn[j] = output[j * 8 + i];
+ tempIn[j] = output[(j * 8) + i];
}
Idct8(tempIn, tempOut);
- for (j = 0; j < 8; ++j)
+ for (int j = 0; j < 8; ++j)
{
- dest[j * stride + i] = ClipPixelAdd(dest[j * stride + i],
- BitUtils.RoundPowerOfTwo(tempOut[j], 5));
+ dest[(j * stride) + i] = ClipPixelAdd(dest[(j * stride) + i],
+ BitUtils.RoundPowerOfTwo(tempOut[j], 5));
}
}
}
@@ -464,7 +454,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void Idct8x812Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
Span output = stackalloc int[8 * 8];
Span outptr = output;
Span tempIn = stackalloc int[8];
@@ -474,45 +463,45 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// First transform rows
// Only first 4 row has non-zero coefs
- for (i = 0; i < 4; ++i)
+ for (int i = 0; i < 4; ++i)
{
Idct8(input, outptr);
- input = input[8..];
- outptr = outptr[8..];
+ input = input.Slice(8);
+ outptr = outptr.Slice(8);
}
// Then transform columns
- for (i = 0; i < 8; ++i)
+ for (int i = 0; i < 8; ++i)
{
- for (j = 0; j < 8; ++j)
+ for (int j = 0; j < 8; ++j)
{
- tempIn[j] = output[j * 8 + i];
+ tempIn[j] = output[(j * 8) + i];
}
Idct8(tempIn, tempOut);
- for (j = 0; j < 8; ++j)
+ for (int j = 0; j < 8; ++j)
{
- dest[j * stride + i] = ClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 5));
+ dest[(j * stride) + i] =
+ ClipPixelAdd(dest[(j * stride) + i], BitUtils.RoundPowerOfTwo(tempOut[j], 5));
}
}
}
public static void Idct8x81Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
long a1;
- int output = WrapLow(DctConstRoundShift((short)input[0] * CosPi16_64));
+ int output = WrapLow(DctConstRoundShift((short)input[0] * CosPi1664));
- output = WrapLow(DctConstRoundShift(output * CosPi16_64));
+ output = WrapLow(DctConstRoundShift(output * CosPi1664));
a1 = BitUtils.RoundPowerOfTwo(output, 5);
- for (j = 0; j < 8; ++j)
+ for (int j = 0; j < 8; ++j)
{
- for (i = 0; i < 8; ++i)
+ for (int i = 0; i < 8; ++i)
{
dest[i] = ClipPixelAdd(dest[i], a1);
}
- dest = dest[stride..];
+ dest = dest.Slice(stride);
}
}
@@ -539,28 +528,27 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
if ((x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | x10 | x11 | x12 | x13 | x14 | x15) == 0)
{
- output[..16].Clear();
-
+ output.Slice(0, 16).Clear();
return;
}
// stage 1
- s0 = x0 * CosPi1_64 + x1 * CosPi31_64;
- s1 = x0 * CosPi31_64 - x1 * CosPi1_64;
- s2 = x2 * CosPi5_64 + x3 * CosPi27_64;
- s3 = x2 * CosPi27_64 - x3 * CosPi5_64;
- s4 = x4 * CosPi9_64 + x5 * CosPi23_64;
- s5 = x4 * CosPi23_64 - x5 * CosPi9_64;
- s6 = x6 * CosPi13_64 + x7 * CosPi19_64;
- s7 = x6 * CosPi19_64 - x7 * CosPi13_64;
- s8 = x8 * CosPi17_64 + x9 * CosPi15_64;
- s9 = x8 * CosPi15_64 - x9 * CosPi17_64;
- s10 = x10 * CosPi21_64 + x11 * CosPi11_64;
- s11 = x10 * CosPi11_64 - x11 * CosPi21_64;
- s12 = x12 * CosPi25_64 + x13 * CosPi7_64;
- s13 = x12 * CosPi7_64 - x13 * CosPi25_64;
- s14 = x14 * CosPi29_64 + x15 * CosPi3_64;
- s15 = x14 * CosPi3_64 - x15 * CosPi29_64;
+ s0 = (x0 * CosPi164) + (x1 * CosPi3164);
+ s1 = (x0 * CosPi3164) - (x1 * CosPi164);
+ s2 = (x2 * CosPi564) + (x3 * CosPi2764);
+ s3 = (x2 * CosPi2764) - (x3 * CosPi564);
+ s4 = (x4 * CosPi964) + (x5 * CosPi2364);
+ s5 = (x4 * CosPi2364) - (x5 * CosPi964);
+ s6 = (x6 * CosPi1364) + (x7 * CosPi1964);
+ s7 = (x6 * CosPi1964) - (x7 * CosPi1364);
+ s8 = (x8 * CosPi1764) + (x9 * CosPi1564);
+ s9 = (x8 * CosPi1564) - (x9 * CosPi1764);
+ s10 = (x10 * CosPi2164) + (x11 * CosPi1164);
+ s11 = (x10 * CosPi1164) - (x11 * CosPi2164);
+ s12 = (x12 * CosPi2564) + (x13 * CosPi764);
+ s13 = (x12 * CosPi764) - (x13 * CosPi2564);
+ s14 = (x14 * CosPi2964) + (x15 * CosPi364);
+ s15 = (x14 * CosPi364) - (x15 * CosPi2964);
x0 = WrapLow(DctConstRoundShift(s0 + s8));
x1 = WrapLow(DctConstRoundShift(s1 + s9));
@@ -588,14 +576,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
s5 = x5;
s6 = x6;
s7 = x7;
- s8 = x8 * CosPi4_64 + x9 * CosPi28_64;
- s9 = x8 * CosPi28_64 - x9 * CosPi4_64;
- s10 = x10 * CosPi20_64 + x11 * CosPi12_64;
- s11 = x10 * CosPi12_64 - x11 * CosPi20_64;
- s12 = -x12 * CosPi28_64 + x13 * CosPi4_64;
- s13 = x12 * CosPi4_64 + x13 * CosPi28_64;
- s14 = -x14 * CosPi12_64 + x15 * CosPi20_64;
- s15 = x14 * CosPi20_64 + x15 * CosPi12_64;
+ s8 = (x8 * CosPi464) + (x9 * CosPi2864);
+ s9 = (x8 * CosPi2864) - (x9 * CosPi464);
+ s10 = (x10 * CosPi2064) + (x11 * CosPi1264);
+ s11 = (x10 * CosPi1264) - (x11 * CosPi2064);
+ s12 = (-x12 * CosPi2864) + (x13 * CosPi464);
+ s13 = (x12 * CosPi464) + (x13 * CosPi2864);
+ s14 = (-x14 * CosPi1264) + (x15 * CosPi2064);
+ s15 = (x14 * CosPi2064) + (x15 * CosPi1264);
x0 = WrapLow(s0 + s4);
x1 = WrapLow(s1 + s5);
@@ -619,18 +607,18 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
s1 = x1;
s2 = x2;
s3 = x3;
- s4 = x4 * CosPi8_64 + x5 * CosPi24_64;
- s5 = x4 * CosPi24_64 - x5 * CosPi8_64;
- s6 = -x6 * CosPi24_64 + x7 * CosPi8_64;
- s7 = x6 * CosPi8_64 + x7 * CosPi24_64;
+ s4 = (x4 * CosPi864) + (x5 * CosPi2464);
+ s5 = (x4 * CosPi2464) - (x5 * CosPi864);
+ s6 = (-x6 * CosPi2464) + (x7 * CosPi864);
+ s7 = (x6 * CosPi864) + (x7 * CosPi2464);
s8 = x8;
s9 = x9;
s10 = x10;
s11 = x11;
- s12 = x12 * CosPi8_64 + x13 * CosPi24_64;
- s13 = x12 * CosPi24_64 - x13 * CosPi8_64;
- s14 = -x14 * CosPi24_64 + x15 * CosPi8_64;
- s15 = x14 * CosPi8_64 + x15 * CosPi24_64;
+ s12 = (x12 * CosPi864) + (x13 * CosPi2464);
+ s13 = (x12 * CosPi2464) - (x13 * CosPi864);
+ s14 = (-x14 * CosPi2464) + (x15 * CosPi864);
+ s15 = (x14 * CosPi864) + (x15 * CosPi2464);
x0 = WrapLow(s0 + s2);
x1 = WrapLow(s1 + s3);
@@ -650,14 +638,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
x15 = WrapLow(DctConstRoundShift(s13 - s15));
// stage 4
- s2 = (-CosPi16_64) * (x2 + x3);
- s3 = CosPi16_64 * (x2 - x3);
- s6 = CosPi16_64 * (x6 + x7);
- s7 = CosPi16_64 * (-x6 + x7);
- s10 = CosPi16_64 * (x10 + x11);
- s11 = CosPi16_64 * (-x10 + x11);
- s14 = (-CosPi16_64) * (x14 + x15);
- s15 = CosPi16_64 * (x14 - x15);
+ s2 = -CosPi1664 * (x2 + x3);
+ s3 = CosPi1664 * (x2 - x3);
+ s6 = CosPi1664 * (x6 + x7);
+ s7 = CosPi1664 * (-x6 + x7);
+ s10 = CosPi1664 * (x10 + x11);
+ s11 = CosPi1664 * (-x10 + x11);
+ s14 = -CosPi1664 * (x14 + x15);
+ s15 = CosPi1664 * (x14 - x15);
x2 = WrapLow(DctConstRoundShift(s2));
x3 = WrapLow(DctConstRoundShift(s3));
@@ -721,23 +709,23 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step2[6] = step1[6];
step2[7] = step1[7];
- temp1 = step1[8] * CosPi30_64 - step1[15] * CosPi2_64;
- temp2 = step1[8] * CosPi2_64 + step1[15] * CosPi30_64;
+ temp1 = (step1[8] * CosPi3064) - (step1[15] * CosPi264);
+ temp2 = (step1[8] * CosPi264) + (step1[15] * CosPi3064);
step2[8] = (short)WrapLow(DctConstRoundShift(temp1));
step2[15] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step1[9] * CosPi14_64 - step1[14] * CosPi18_64;
- temp2 = step1[9] * CosPi18_64 + step1[14] * CosPi14_64;
+ temp1 = (step1[9] * CosPi1464) - (step1[14] * CosPi1864);
+ temp2 = (step1[9] * CosPi1864) + (step1[14] * CosPi1464);
step2[9] = (short)WrapLow(DctConstRoundShift(temp1));
step2[14] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step1[10] * CosPi22_64 - step1[13] * CosPi10_64;
- temp2 = step1[10] * CosPi10_64 + step1[13] * CosPi22_64;
+ temp1 = (step1[10] * CosPi2264) - (step1[13] * CosPi1064);
+ temp2 = (step1[10] * CosPi1064) + (step1[13] * CosPi2264);
step2[10] = (short)WrapLow(DctConstRoundShift(temp1));
step2[13] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step1[11] * CosPi6_64 - step1[12] * CosPi26_64;
- temp2 = step1[11] * CosPi26_64 + step1[12] * CosPi6_64;
+ temp1 = (step1[11] * CosPi664) - (step1[12] * CosPi2664);
+ temp2 = (step1[11] * CosPi2664) + (step1[12] * CosPi664);
step2[11] = (short)WrapLow(DctConstRoundShift(temp1));
step2[12] = (short)WrapLow(DctConstRoundShift(temp2));
@@ -747,12 +735,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[2] = step2[2];
step1[3] = step2[3];
- temp1 = step2[4] * CosPi28_64 - step2[7] * CosPi4_64;
- temp2 = step2[4] * CosPi4_64 + step2[7] * CosPi28_64;
+ temp1 = (step2[4] * CosPi2864) - (step2[7] * CosPi464);
+ temp2 = (step2[4] * CosPi464) + (step2[7] * CosPi2864);
step1[4] = (short)WrapLow(DctConstRoundShift(temp1));
step1[7] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step2[5] * CosPi12_64 - step2[6] * CosPi20_64;
- temp2 = step2[5] * CosPi20_64 + step2[6] * CosPi12_64;
+ temp1 = (step2[5] * CosPi1264) - (step2[6] * CosPi2064);
+ temp2 = (step2[5] * CosPi2064) + (step2[6] * CosPi1264);
step1[5] = (short)WrapLow(DctConstRoundShift(temp1));
step1[6] = (short)WrapLow(DctConstRoundShift(temp2));
@@ -766,12 +754,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[15] = (short)WrapLow(step2[14] + step2[15]);
// stage 4
- temp1 = (step1[0] + step1[1]) * CosPi16_64;
- temp2 = (step1[0] - step1[1]) * CosPi16_64;
+ temp1 = (step1[0] + step1[1]) * CosPi1664;
+ temp2 = (step1[0] - step1[1]) * CosPi1664;
step2[0] = (short)WrapLow(DctConstRoundShift(temp1));
step2[1] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step1[2] * CosPi24_64 - step1[3] * CosPi8_64;
- temp2 = step1[2] * CosPi8_64 + step1[3] * CosPi24_64;
+ temp1 = (step1[2] * CosPi2464) - (step1[3] * CosPi864);
+ temp2 = (step1[2] * CosPi864) + (step1[3] * CosPi2464);
step2[2] = (short)WrapLow(DctConstRoundShift(temp1));
step2[3] = (short)WrapLow(DctConstRoundShift(temp2));
step2[4] = (short)WrapLow(step1[4] + step1[5]);
@@ -781,12 +769,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step2[8] = step1[8];
step2[15] = step1[15];
- temp1 = -step1[9] * CosPi8_64 + step1[14] * CosPi24_64;
- temp2 = step1[9] * CosPi24_64 + step1[14] * CosPi8_64;
+ temp1 = (-step1[9] * CosPi864) + (step1[14] * CosPi2464);
+ temp2 = (step1[9] * CosPi2464) + (step1[14] * CosPi864);
step2[9] = (short)WrapLow(DctConstRoundShift(temp1));
step2[14] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = -step1[10] * CosPi24_64 - step1[13] * CosPi8_64;
- temp2 = -step1[10] * CosPi8_64 + step1[13] * CosPi24_64;
+ temp1 = (-step1[10] * CosPi2464) - (step1[13] * CosPi864);
+ temp2 = (-step1[10] * CosPi864) + (step1[13] * CosPi2464);
step2[10] = (short)WrapLow(DctConstRoundShift(temp1));
step2[13] = (short)WrapLow(DctConstRoundShift(temp2));
step2[11] = step1[11];
@@ -798,8 +786,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[2] = (short)WrapLow(step2[1] - step2[2]);
step1[3] = (short)WrapLow(step2[0] - step2[3]);
step1[4] = step2[4];
- temp1 = (step2[6] - step2[5]) * CosPi16_64;
- temp2 = (step2[5] + step2[6]) * CosPi16_64;
+ temp1 = (step2[6] - step2[5]) * CosPi1664;
+ temp2 = (step2[5] + step2[6]) * CosPi1664;
step1[5] = (short)WrapLow(DctConstRoundShift(temp1));
step1[6] = (short)WrapLow(DctConstRoundShift(temp2));
step1[7] = step2[7];
@@ -824,12 +812,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step2[7] = (short)WrapLow(step1[0] - step1[7]);
step2[8] = step1[8];
step2[9] = step1[9];
- temp1 = (-step1[10] + step1[13]) * CosPi16_64;
- temp2 = (step1[10] + step1[13]) * CosPi16_64;
+ temp1 = (-step1[10] + step1[13]) * CosPi1664;
+ temp2 = (step1[10] + step1[13]) * CosPi1664;
step2[10] = (short)WrapLow(DctConstRoundShift(temp1));
step2[13] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (-step1[11] + step1[12]) * CosPi16_64;
- temp2 = (step1[11] + step1[12]) * CosPi16_64;
+ temp1 = (-step1[11] + step1[12]) * CosPi1664;
+ temp2 = (step1[11] + step1[12]) * CosPi1664;
step2[11] = (short)WrapLow(DctConstRoundShift(temp1));
step2[12] = (short)WrapLow(DctConstRoundShift(temp2));
step2[14] = step1[14];
@@ -857,32 +845,32 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void Idct16x16256Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
Span output = stackalloc int[16 * 16];
Span outptr = output;
Span tempIn = stackalloc int[16];
Span tempOut = stackalloc int[16];
// First transform rows
- for (i = 0; i < 16; ++i)
+ for (int i = 0; i < 16; ++i)
{
Idct16(input, outptr);
- input = input[16..];
- outptr = outptr[16..];
+ input = input.Slice(16);
+ outptr = outptr.Slice(16);
}
// Then transform columns
- for (i = 0; i < 16; ++i)
+ for (int i = 0; i < 16; ++i)
{
- for (j = 0; j < 16; ++j)
+ for (int j = 0; j < 16; ++j)
{
- tempIn[j] = output[j * 16 + i];
+ tempIn[j] = output[(j * 16) + i];
}
Idct16(tempIn, tempOut);
- for (j = 0; j < 16; ++j)
+ for (int j = 0; j < 16; ++j)
{
- dest[j * stride + i] = ClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
+ dest[(j * stride) + i] =
+ ClipPixelAdd(dest[(j * stride) + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
}
}
}
@@ -890,7 +878,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void Idct16x1638Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
Span output = stackalloc int[16 * 16];
Span outptr = output;
Span tempIn = stackalloc int[16];
@@ -900,25 +887,26 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// First transform rows. Since all non-zero dct coefficients are in
// upper-left 8x8 area, we only need to calculate first 8 rows here.
- for (i = 0; i < 8; ++i)
+ for (int i = 0; i < 8; ++i)
{
Idct16(input, outptr);
- input = input[16..];
- outptr = outptr[16..];
+ input = input.Slice(16);
+ outptr = outptr.Slice(16);
}
// Then transform columns
- for (i = 0; i < 16; ++i)
+ for (int i = 0; i < 16; ++i)
{
- for (j = 0; j < 16; ++j)
+ for (int j = 0; j < 16; ++j)
{
- tempIn[j] = output[j * 16 + i];
+ tempIn[j] = output[(j * 16) + i];
}
Idct16(tempIn, tempOut);
- for (j = 0; j < 16; ++j)
+ for (int j = 0; j < 16; ++j)
{
- dest[j * stride + i] = ClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
+ dest[(j * stride) + i] =
+ ClipPixelAdd(dest[(j * stride) + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
}
}
}
@@ -926,7 +914,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void Idct16x1610Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
Span output = stackalloc int[16 * 16];
Span outptr = output;
Span tempIn = stackalloc int[16];
@@ -936,45 +923,45 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// First transform rows. Since all non-zero dct coefficients are in
// upper-left 4x4 area, we only need to calculate first 4 rows here.
- for (i = 0; i < 4; ++i)
+ for (int i = 0; i < 4; ++i)
{
Idct16(input, outptr);
- input = input[16..];
- outptr = outptr[16..];
+ input = input.Slice(16);
+ outptr = outptr.Slice(16);
}
// Then transform columns
- for (i = 0; i < 16; ++i)
+ for (int i = 0; i < 16; ++i)
{
- for (j = 0; j < 16; ++j)
+ for (int j = 0; j < 16; ++j)
{
- tempIn[j] = output[j * 16 + i];
+ tempIn[j] = output[(j * 16) + i];
}
Idct16(tempIn, tempOut);
- for (j = 0; j < 16; ++j)
+ for (int j = 0; j < 16; ++j)
{
- dest[j * stride + i] = ClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
+ dest[(j * stride) + i] =
+ ClipPixelAdd(dest[(j * stride) + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
}
}
}
public static void Idct16x161Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
long a1;
- int output = WrapLow(DctConstRoundShift((short)input[0] * CosPi16_64));
+ int output = WrapLow(DctConstRoundShift((short)input[0] * CosPi1664));
- output = WrapLow(DctConstRoundShift(output * CosPi16_64));
+ output = WrapLow(DctConstRoundShift(output * CosPi1664));
a1 = BitUtils.RoundPowerOfTwo(output, 6);
- for (j = 0; j < 16; ++j)
+ for (int j = 0; j < 16; ++j)
{
- for (i = 0; i < 16; ++i)
+ for (int i = 0; i < 16; ++i)
{
dest[i] = ClipPixelAdd(dest[i], a1);
}
- dest = dest[stride..];
+ dest = dest.Slice(stride);
}
}
@@ -1003,43 +990,43 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[14] = (short)input[14];
step1[15] = (short)input[30];
- temp1 = (short)input[1] * CosPi31_64 - (short)input[31] * CosPi1_64;
- temp2 = (short)input[1] * CosPi1_64 + (short)input[31] * CosPi31_64;
+ temp1 = ((short)input[1] * CosPi3164) - ((short)input[31] * CosPi164);
+ temp2 = ((short)input[1] * CosPi164) + ((short)input[31] * CosPi3164);
step1[16] = (short)WrapLow(DctConstRoundShift(temp1));
step1[31] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (short)input[17] * CosPi15_64 - (short)input[15] * CosPi17_64;
- temp2 = (short)input[17] * CosPi17_64 + (short)input[15] * CosPi15_64;
+ temp1 = ((short)input[17] * CosPi1564) - ((short)input[15] * CosPi1764);
+ temp2 = ((short)input[17] * CosPi1764) + ((short)input[15] * CosPi1564);
step1[17] = (short)WrapLow(DctConstRoundShift(temp1));
step1[30] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (short)input[9] * CosPi23_64 - (short)input[23] * CosPi9_64;
- temp2 = (short)input[9] * CosPi9_64 + (short)input[23] * CosPi23_64;
+ temp1 = ((short)input[9] * CosPi2364) - ((short)input[23] * CosPi964);
+ temp2 = ((short)input[9] * CosPi964) + ((short)input[23] * CosPi2364);
step1[18] = (short)WrapLow(DctConstRoundShift(temp1));
step1[29] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (short)input[25] * CosPi7_64 - (short)input[7] * CosPi25_64;
- temp2 = (short)input[25] * CosPi25_64 + (short)input[7] * CosPi7_64;
+ temp1 = ((short)input[25] * CosPi764) - ((short)input[7] * CosPi2564);
+ temp2 = ((short)input[25] * CosPi2564) + ((short)input[7] * CosPi764);
step1[19] = (short)WrapLow(DctConstRoundShift(temp1));
step1[28] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (short)input[5] * CosPi27_64 - (short)input[27] * CosPi5_64;
- temp2 = (short)input[5] * CosPi5_64 + (short)input[27] * CosPi27_64;
+ temp1 = ((short)input[5] * CosPi2764) - ((short)input[27] * CosPi564);
+ temp2 = ((short)input[5] * CosPi564) + ((short)input[27] * CosPi2764);
step1[20] = (short)WrapLow(DctConstRoundShift(temp1));
step1[27] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (short)input[21] * CosPi11_64 - (short)input[11] * CosPi21_64;
- temp2 = (short)input[21] * CosPi21_64 + (short)input[11] * CosPi11_64;
+ temp1 = ((short)input[21] * CosPi1164) - ((short)input[11] * CosPi2164);
+ temp2 = ((short)input[21] * CosPi2164) + ((short)input[11] * CosPi1164);
step1[21] = (short)WrapLow(DctConstRoundShift(temp1));
step1[26] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (short)input[13] * CosPi19_64 - (short)input[19] * CosPi13_64;
- temp2 = (short)input[13] * CosPi13_64 + (short)input[19] * CosPi19_64;
+ temp1 = ((short)input[13] * CosPi1964) - ((short)input[19] * CosPi1364);
+ temp2 = ((short)input[13] * CosPi1364) + ((short)input[19] * CosPi1964);
step1[22] = (short)WrapLow(DctConstRoundShift(temp1));
step1[25] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (short)input[29] * CosPi3_64 - (short)input[3] * CosPi29_64;
- temp2 = (short)input[29] * CosPi29_64 + (short)input[3] * CosPi3_64;
+ temp1 = ((short)input[29] * CosPi364) - ((short)input[3] * CosPi2964);
+ temp2 = ((short)input[29] * CosPi2964) + ((short)input[3] * CosPi364);
step1[23] = (short)WrapLow(DctConstRoundShift(temp1));
step1[24] = (short)WrapLow(DctConstRoundShift(temp2));
@@ -1053,23 +1040,23 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step2[6] = step1[6];
step2[7] = step1[7];
- temp1 = step1[8] * CosPi30_64 - step1[15] * CosPi2_64;
- temp2 = step1[8] * CosPi2_64 + step1[15] * CosPi30_64;
+ temp1 = (step1[8] * CosPi3064) - (step1[15] * CosPi264);
+ temp2 = (step1[8] * CosPi264) + (step1[15] * CosPi3064);
step2[8] = (short)WrapLow(DctConstRoundShift(temp1));
step2[15] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step1[9] * CosPi14_64 - step1[14] * CosPi18_64;
- temp2 = step1[9] * CosPi18_64 + step1[14] * CosPi14_64;
+ temp1 = (step1[9] * CosPi1464) - (step1[14] * CosPi1864);
+ temp2 = (step1[9] * CosPi1864) + (step1[14] * CosPi1464);
step2[9] = (short)WrapLow(DctConstRoundShift(temp1));
step2[14] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step1[10] * CosPi22_64 - step1[13] * CosPi10_64;
- temp2 = step1[10] * CosPi10_64 + step1[13] * CosPi22_64;
+ temp1 = (step1[10] * CosPi2264) - (step1[13] * CosPi1064);
+ temp2 = (step1[10] * CosPi1064) + (step1[13] * CosPi2264);
step2[10] = (short)WrapLow(DctConstRoundShift(temp1));
step2[13] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step1[11] * CosPi6_64 - step1[12] * CosPi26_64;
- temp2 = step1[11] * CosPi26_64 + step1[12] * CosPi6_64;
+ temp1 = (step1[11] * CosPi664) - (step1[12] * CosPi2664);
+ temp2 = (step1[11] * CosPi2664) + (step1[12] * CosPi664);
step2[11] = (short)WrapLow(DctConstRoundShift(temp1));
step2[12] = (short)WrapLow(DctConstRoundShift(temp2));
@@ -1096,12 +1083,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[2] = step2[2];
step1[3] = step2[3];
- temp1 = step2[4] * CosPi28_64 - step2[7] * CosPi4_64;
- temp2 = step2[4] * CosPi4_64 + step2[7] * CosPi28_64;
+ temp1 = (step2[4] * CosPi2864) - (step2[7] * CosPi464);
+ temp2 = (step2[4] * CosPi464) + (step2[7] * CosPi2864);
step1[4] = (short)WrapLow(DctConstRoundShift(temp1));
step1[7] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step2[5] * CosPi12_64 - step2[6] * CosPi20_64;
- temp2 = step2[5] * CosPi20_64 + step2[6] * CosPi12_64;
+ temp1 = (step2[5] * CosPi1264) - (step2[6] * CosPi2064);
+ temp2 = (step2[5] * CosPi2064) + (step2[6] * CosPi1264);
step1[5] = (short)WrapLow(DctConstRoundShift(temp1));
step1[6] = (short)WrapLow(DctConstRoundShift(temp2));
@@ -1116,22 +1103,22 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[16] = step2[16];
step1[31] = step2[31];
- temp1 = -step2[17] * CosPi4_64 + step2[30] * CosPi28_64;
- temp2 = step2[17] * CosPi28_64 + step2[30] * CosPi4_64;
+ temp1 = (-step2[17] * CosPi464) + (step2[30] * CosPi2864);
+ temp2 = (step2[17] * CosPi2864) + (step2[30] * CosPi464);
step1[17] = (short)WrapLow(DctConstRoundShift(temp1));
step1[30] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = -step2[18] * CosPi28_64 - step2[29] * CosPi4_64;
- temp2 = -step2[18] * CosPi4_64 + step2[29] * CosPi28_64;
+ temp1 = (-step2[18] * CosPi2864) - (step2[29] * CosPi464);
+ temp2 = (-step2[18] * CosPi464) + (step2[29] * CosPi2864);
step1[18] = (short)WrapLow(DctConstRoundShift(temp1));
step1[29] = (short)WrapLow(DctConstRoundShift(temp2));
step1[19] = step2[19];
step1[20] = step2[20];
- temp1 = -step2[21] * CosPi20_64 + step2[26] * CosPi12_64;
- temp2 = step2[21] * CosPi12_64 + step2[26] * CosPi20_64;
+ temp1 = (-step2[21] * CosPi2064) + (step2[26] * CosPi1264);
+ temp2 = (step2[21] * CosPi1264) + (step2[26] * CosPi2064);
step1[21] = (short)WrapLow(DctConstRoundShift(temp1));
step1[26] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = -step2[22] * CosPi12_64 - step2[25] * CosPi20_64;
- temp2 = -step2[22] * CosPi20_64 + step2[25] * CosPi12_64;
+ temp1 = (-step2[22] * CosPi1264) - (step2[25] * CosPi2064);
+ temp2 = (-step2[22] * CosPi2064) + (step2[25] * CosPi1264);
step1[22] = (short)WrapLow(DctConstRoundShift(temp1));
step1[25] = (short)WrapLow(DctConstRoundShift(temp2));
step1[23] = step2[23];
@@ -1140,12 +1127,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[28] = step2[28];
// stage 4
- temp1 = (step1[0] + step1[1]) * CosPi16_64;
- temp2 = (step1[0] - step1[1]) * CosPi16_64;
+ temp1 = (step1[0] + step1[1]) * CosPi1664;
+ temp2 = (step1[0] - step1[1]) * CosPi1664;
step2[0] = (short)WrapLow(DctConstRoundShift(temp1));
step2[1] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = step1[2] * CosPi24_64 - step1[3] * CosPi8_64;
- temp2 = step1[2] * CosPi8_64 + step1[3] * CosPi24_64;
+ temp1 = (step1[2] * CosPi2464) - (step1[3] * CosPi864);
+ temp2 = (step1[2] * CosPi864) + (step1[3] * CosPi2464);
step2[2] = (short)WrapLow(DctConstRoundShift(temp1));
step2[3] = (short)WrapLow(DctConstRoundShift(temp2));
step2[4] = (short)WrapLow(step1[4] + step1[5]);
@@ -1155,12 +1142,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step2[8] = step1[8];
step2[15] = step1[15];
- temp1 = -step1[9] * CosPi8_64 + step1[14] * CosPi24_64;
- temp2 = step1[9] * CosPi24_64 + step1[14] * CosPi8_64;
+ temp1 = (-step1[9] * CosPi864) + (step1[14] * CosPi2464);
+ temp2 = (step1[9] * CosPi2464) + (step1[14] * CosPi864);
step2[9] = (short)WrapLow(DctConstRoundShift(temp1));
step2[14] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = -step1[10] * CosPi24_64 - step1[13] * CosPi8_64;
- temp2 = -step1[10] * CosPi8_64 + step1[13] * CosPi24_64;
+ temp1 = (-step1[10] * CosPi2464) - (step1[13] * CosPi864);
+ temp2 = (-step1[10] * CosPi864) + (step1[13] * CosPi2464);
step2[10] = (short)WrapLow(DctConstRoundShift(temp1));
step2[13] = (short)WrapLow(DctConstRoundShift(temp2));
step2[11] = step1[11];
@@ -1190,8 +1177,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[2] = (short)WrapLow(step2[1] - step2[2]);
step1[3] = (short)WrapLow(step2[0] - step2[3]);
step1[4] = step2[4];
- temp1 = (step2[6] - step2[5]) * CosPi16_64;
- temp2 = (step2[5] + step2[6]) * CosPi16_64;
+ temp1 = (step2[6] - step2[5]) * CosPi1664;
+ temp2 = (step2[5] + step2[6]) * CosPi1664;
step1[5] = (short)WrapLow(DctConstRoundShift(temp1));
step1[6] = (short)WrapLow(DctConstRoundShift(temp2));
step1[7] = step2[7];
@@ -1207,20 +1194,20 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[16] = step2[16];
step1[17] = step2[17];
- temp1 = -step2[18] * CosPi8_64 + step2[29] * CosPi24_64;
- temp2 = step2[18] * CosPi24_64 + step2[29] * CosPi8_64;
+ temp1 = (-step2[18] * CosPi864) + (step2[29] * CosPi2464);
+ temp2 = (step2[18] * CosPi2464) + (step2[29] * CosPi864);
step1[18] = (short)WrapLow(DctConstRoundShift(temp1));
step1[29] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = -step2[19] * CosPi8_64 + step2[28] * CosPi24_64;
- temp2 = step2[19] * CosPi24_64 + step2[28] * CosPi8_64;
+ temp1 = (-step2[19] * CosPi864) + (step2[28] * CosPi2464);
+ temp2 = (step2[19] * CosPi2464) + (step2[28] * CosPi864);
step1[19] = (short)WrapLow(DctConstRoundShift(temp1));
step1[28] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = -step2[20] * CosPi24_64 - step2[27] * CosPi8_64;
- temp2 = -step2[20] * CosPi8_64 + step2[27] * CosPi24_64;
+ temp1 = (-step2[20] * CosPi2464) - (step2[27] * CosPi864);
+ temp2 = (-step2[20] * CosPi864) + (step2[27] * CosPi2464);
step1[20] = (short)WrapLow(DctConstRoundShift(temp1));
step1[27] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = -step2[21] * CosPi24_64 - step2[26] * CosPi8_64;
- temp2 = -step2[21] * CosPi8_64 + step2[26] * CosPi24_64;
+ temp1 = (-step2[21] * CosPi2464) - (step2[26] * CosPi864);
+ temp2 = (-step2[21] * CosPi864) + (step2[26] * CosPi2464);
step1[21] = (short)WrapLow(DctConstRoundShift(temp1));
step1[26] = (short)WrapLow(DctConstRoundShift(temp2));
step1[22] = step2[22];
@@ -1241,12 +1228,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step2[7] = (short)WrapLow(step1[0] - step1[7]);
step2[8] = step1[8];
step2[9] = step1[9];
- temp1 = (-step1[10] + step1[13]) * CosPi16_64;
- temp2 = (step1[10] + step1[13]) * CosPi16_64;
+ temp1 = (-step1[10] + step1[13]) * CosPi1664;
+ temp2 = (step1[10] + step1[13]) * CosPi1664;
step2[10] = (short)WrapLow(DctConstRoundShift(temp1));
step2[13] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (-step1[11] + step1[12]) * CosPi16_64;
- temp2 = (step1[11] + step1[12]) * CosPi16_64;
+ temp1 = (-step1[11] + step1[12]) * CosPi1664;
+ temp2 = (step1[11] + step1[12]) * CosPi1664;
step2[11] = (short)WrapLow(DctConstRoundShift(temp1));
step2[12] = (short)WrapLow(DctConstRoundShift(temp2));
step2[14] = step1[14];
@@ -1292,20 +1279,20 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[17] = step2[17];
step1[18] = step2[18];
step1[19] = step2[19];
- temp1 = (-step2[20] + step2[27]) * CosPi16_64;
- temp2 = (step2[20] + step2[27]) * CosPi16_64;
+ temp1 = (-step2[20] + step2[27]) * CosPi1664;
+ temp2 = (step2[20] + step2[27]) * CosPi1664;
step1[20] = (short)WrapLow(DctConstRoundShift(temp1));
step1[27] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (-step2[21] + step2[26]) * CosPi16_64;
- temp2 = (step2[21] + step2[26]) * CosPi16_64;
+ temp1 = (-step2[21] + step2[26]) * CosPi1664;
+ temp2 = (step2[21] + step2[26]) * CosPi1664;
step1[21] = (short)WrapLow(DctConstRoundShift(temp1));
step1[26] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (-step2[22] + step2[25]) * CosPi16_64;
- temp2 = (step2[22] + step2[25]) * CosPi16_64;
+ temp1 = (-step2[22] + step2[25]) * CosPi1664;
+ temp2 = (step2[22] + step2[25]) * CosPi1664;
step1[22] = (short)WrapLow(DctConstRoundShift(temp1));
step1[25] = (short)WrapLow(DctConstRoundShift(temp2));
- temp1 = (-step2[23] + step2[24]) * CosPi16_64;
- temp2 = (step2[23] + step2[24]) * CosPi16_64;
+ temp1 = (-step2[23] + step2[24]) * CosPi1664;
+ temp2 = (step2[23] + step2[24]) * CosPi1664;
step1[23] = (short)WrapLow(DctConstRoundShift(temp1));
step1[24] = (short)WrapLow(DctConstRoundShift(temp2));
step1[28] = step2[28];
@@ -1351,17 +1338,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void Idct32x321024Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
Span output = stackalloc int[32 * 32];
Span outptr = output;
Span tempIn = stackalloc int[32];
Span tempOut = stackalloc int[32];
// Rows
- for (i = 0; i < 32; ++i)
+ for (int i = 0; i < 32; ++i)
{
short zeroCoeff = 0;
- for (j = 0; j < 32; ++j)
+ for (int j = 0; j < 32; ++j)
{
zeroCoeff |= (short)input[j];
}
@@ -1372,25 +1358,26 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
}
else
{
- outptr[..32].Clear();
+ outptr.Slice(0, 32).Clear();
}
- input = input[32..];
- outptr = outptr[32..];
+ input = input.Slice(32);
+ outptr = outptr.Slice(32);
}
// Columns
- for (i = 0; i < 32; ++i)
+ for (int i = 0; i < 32; ++i)
{
- for (j = 0; j < 32; ++j)
+ for (int j = 0; j < 32; ++j)
{
- tempIn[j] = output[j * 32 + i];
+ tempIn[j] = output[(j * 32) + i];
}
Idct32(tempIn, tempOut);
- for (j = 0; j < 32; ++j)
+ for (int j = 0; j < 32; ++j)
{
- dest[j * stride + i] = ClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
+ dest[(j * stride) + i] =
+ ClipPixelAdd(dest[(j * stride) + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
}
}
}
@@ -1398,7 +1385,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void Idct32x32135Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
Span output = stackalloc int[32 * 32];
Span outptr = output;
Span tempIn = stackalloc int[32];
@@ -1408,25 +1394,26 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// Rows
// Only upper-left 16x16 has non-zero coeff
- for (i = 0; i < 16; ++i)
+ for (int i = 0; i < 16; ++i)
{
Idct32(input, outptr);
- input = input[32..];
- outptr = outptr[32..];
+ input = input.Slice(32);
+ outptr = outptr.Slice(32);
}
// Columns
- for (i = 0; i < 32; ++i)
+ for (int i = 0; i < 32; ++i)
{
- for (j = 0; j < 32; ++j)
+ for (int j = 0; j < 32; ++j)
{
- tempIn[j] = output[j * 32 + i];
+ tempIn[j] = output[(j * 32) + i];
}
Idct32(tempIn, tempOut);
- for (j = 0; j < 32; ++j)
+ for (int j = 0; j < 32; ++j)
{
- dest[j * stride + i] = ClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
+ dest[(j * stride) + i] =
+ ClipPixelAdd(dest[(j * stride) + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
}
}
}
@@ -1434,7 +1421,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void Idct32x3234Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
Span output = stackalloc int[32 * 32];
Span outptr = output;
Span tempIn = stackalloc int[32];
@@ -1444,46 +1430,46 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// Rows
// Only upper-left 8x8 has non-zero coeff
- for (i = 0; i < 8; ++i)
+ for (int i = 0; i < 8; ++i)
{
Idct32(input, outptr);
- input = input[32..];
- outptr = outptr[32..];
+ input = input.Slice(32);
+ outptr = outptr.Slice(32);
}
// Columns
- for (i = 0; i < 32; ++i)
+ for (int i = 0; i < 32; ++i)
{
- for (j = 0; j < 32; ++j)
+ for (int j = 0; j < 32; ++j)
{
- tempIn[j] = output[j * 32 + i];
+ tempIn[j] = output[(j * 32) + i];
}
Idct32(tempIn, tempOut);
- for (j = 0; j < 32; ++j)
+ for (int j = 0; j < 32; ++j)
{
- dest[j * stride + i] = ClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
+ dest[(j * stride) + i] =
+ ClipPixelAdd(dest[(j * stride) + i], BitUtils.RoundPowerOfTwo(tempOut[j], 6));
}
}
}
public static void Idct32x321Add(ReadOnlySpan input, Span dest, int stride)
{
- int i, j;
long a1;
- int output = WrapLow(DctConstRoundShift((short)input[0] * CosPi16_64));
+ int output = WrapLow(DctConstRoundShift((short)input[0] * CosPi1664));
- output = WrapLow(DctConstRoundShift(output * CosPi16_64));
+ output = WrapLow(DctConstRoundShift(output * CosPi1664));
a1 = BitUtils.RoundPowerOfTwo(output, 6);
- for (j = 0; j < 32; ++j)
+ for (int j = 0; j < 32; ++j)
{
- for (i = 0; i < 32; ++i)
+ for (int i = 0; i < 32; ++i)
{
dest[i] = ClipPixelAdd(dest[i], a1);
}
- dest = dest[stride..];
+ dest = dest.Slice(stride);
}
}
@@ -1492,13 +1478,13 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
{
/* 4-point reversible, orthonormal inverse Walsh-Hadamard in 3.5 adds,
0.5 shifts per pixel. */
- int i;
+
Span output = stackalloc int[16];
long a1, b1, c1, d1, e1;
ReadOnlySpan ip = input;
Span op = output;
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
a1 = ip[0] >> UnitQuantShift;
c1 = ip[1] >> UnitQuantShift;
@@ -1515,12 +1501,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
op[1] = HighbdWrapLow(b1, bd);
op[2] = HighbdWrapLow(c1, bd);
op[3] = HighbdWrapLow(d1, bd);
- ip = ip[4..];
- op = op[4..];
+ ip = ip.Slice(4);
+ op = op.Slice(4);
}
ReadOnlySpan ip2 = output;
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
a1 = ip2[4 * 0];
c1 = ip2[4 * 1];
@@ -1538,15 +1524,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dest[stride * 2] = HighbdClipPixelAdd(dest[stride * 2], HighbdWrapLow(c1, bd), bd);
dest[stride * 3] = HighbdClipPixelAdd(dest[stride * 3], HighbdWrapLow(d1, bd), bd);
- ip2 = ip2[1..];
- dest = dest[1..];
+ ip2 = ip2.Slice(1);
+ dest = dest.Slice(1);
}
}
[SkipLocalsInit]
public static void HighbdIwht4x41Add(ReadOnlySpan input, Span dest, int stride, int bd)
{
- int i;
long a1, e1;
Span tmp = stackalloc int[4];
ReadOnlySpan ip = input;
@@ -1559,7 +1544,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
op[1] = op[2] = op[3] = HighbdWrapLow(e1, bd);
ReadOnlySpan ip2 = tmp;
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
e1 = ip2[0] >> 1;
a1 = ip2[0] - e1;
@@ -1567,8 +1552,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
dest[stride * 1] = HighbdClipPixelAdd(dest[stride * 1], e1, bd);
dest[stride * 2] = HighbdClipPixelAdd(dest[stride * 2], e1, bd);
dest[stride * 3] = HighbdClipPixelAdd(dest[stride * 3], e1, bd);
- ip2 = ip2[1..];
- dest = dest[1..];
+ ip2 = ip2.Slice(1);
+ dest = dest.Slice(1);
}
}
@@ -1583,31 +1568,29 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
if (DetectInvalidHighbdInput(input, 4) != 0)
{
Debug.Assert(false, "invalid highbd txfm input");
- output[..4].Clear();
-
+ output.Slice(0, 4).Clear();
return;
}
if ((x0 | x1 | x2 | x3) == 0)
{
- output[..4].Clear();
-
+ output.Slice(0, 4).Clear();
return;
}
- s0 = (long)SinPi1_9 * x0;
- s1 = (long)SinPi2_9 * x0;
- s2 = (long)SinPi3_9 * x1;
- s3 = (long)SinPi4_9 * x2;
- s4 = (long)SinPi1_9 * x2;
- s5 = (long)SinPi2_9 * x3;
- s6 = (long)SinPi4_9 * x3;
+ s0 = (long)SinPi19 * x0;
+ s1 = (long)SinPi29 * x0;
+ s2 = (long)SinPi39 * x1;
+ s3 = (long)SinPi49 * x2;
+ s4 = (long)SinPi19 * x2;
+ s5 = (long)SinPi29 * x3;
+ s6 = (long)SinPi49 * x3;
s7 = HighbdWrapLow(x0 - x2 + x3, bd);
s0 = s0 + s3 + s5;
s1 = s1 - s4 - s6;
s3 = s2;
- s2 = SinPi3_9 * s7;
+ s2 = SinPi39 * s7;
// 1-D transform scaling factor is sqrt(2).
// The overall dynamic range is 14b (input) + 14b (multiplication scaling)
@@ -1628,18 +1611,17 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
if (DetectInvalidHighbdInput(input, 4) != 0)
{
Debug.Assert(false, "invalid highbd txfm input");
- output[..4].Clear();
-
+ output.Slice(0, 4).Clear();
return;
}
// stage 1
- temp1 = (input[0] + input[2]) * (long)CosPi16_64;
- temp2 = (input[0] - input[2]) * (long)CosPi16_64;
+ temp1 = (input[0] + input[2]) * (long)CosPi1664;
+ temp2 = (input[0] - input[2]) * (long)CosPi1664;
step[0] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step[1] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
- temp1 = input[1] * (long)CosPi24_64 - input[3] * (long)CosPi8_64;
- temp2 = input[1] * (long)CosPi8_64 + input[3] * (long)CosPi24_64;
+ temp1 = (input[1] * (long)CosPi2464) - (input[3] * (long)CosPi864);
+ temp2 = (input[1] * (long)CosPi864) + (input[3] * (long)CosPi2464);
step[2] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step[3] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
@@ -1653,52 +1635,51 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void HighbdIdct4x416Add(ReadOnlySpan input, Span dest, int stride, int bd)
{
- int i, j;
Span output = stackalloc int[4 * 4];
Span outptr = output;
Span tempIn = stackalloc int[4];
Span tempOut = stackalloc int[4];
// Rows
- for (i = 0; i < 4; ++i)
+ for (int i = 0; i < 4; ++i)
{
HighbdIdct4(input, outptr, bd);
- input = input[4..];
- outptr = outptr[4..];
+ input = input.Slice(4);
+ outptr = outptr.Slice(4);
}
// Columns
- for (i = 0; i < 4; ++i)
+ for (int i = 0; i < 4; ++i)
{
- for (j = 0; j < 4; ++j)
+ for (int j = 0; j < 4; ++j)
{
- tempIn[j] = output[j * 4 + i];
+ tempIn[j] = output[(j * 4) + i];
}
HighbdIdct4(tempIn, tempOut, bd);
- for (j = 0; j < 4; ++j)
+ for (int j = 0; j < 4; ++j)
{
- dest[j * stride + i] = HighbdClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 4), bd);
+ dest[(j * stride) + i] = HighbdClipPixelAdd(dest[(j * stride) + i],
+ BitUtils.RoundPowerOfTwo(tempOut[j], 4), bd);
}
}
}
public static void HighbdIdct4x41Add(ReadOnlySpan input, Span dest, int stride, int bd)
{
- int i;
long a1;
- int output = HighbdWrapLow(DctConstRoundShift(input[0] * (long)CosPi16_64), bd);
+ int output = HighbdWrapLow(DctConstRoundShift(input[0] * (long)CosPi1664), bd);
- output = HighbdWrapLow(DctConstRoundShift(output * (long)CosPi16_64), bd);
+ output = HighbdWrapLow(DctConstRoundShift(output * (long)CosPi1664), bd);
a1 = BitUtils.RoundPowerOfTwo(output, 4);
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
dest[0] = HighbdClipPixelAdd(dest[0], a1, bd);
dest[1] = HighbdClipPixelAdd(dest[1], a1, bd);
dest[2] = HighbdClipPixelAdd(dest[2], a1, bd);
dest[3] = HighbdClipPixelAdd(dest[3], a1, bd);
- dest = dest[stride..];
+ dest = dest.Slice(stride);
}
}
@@ -1717,27 +1698,25 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
if (DetectInvalidHighbdInput(input, 8) != 0)
{
Debug.Assert(false, "invalid highbd txfm input");
- output[..8].Clear();
-
+ output.Slice(0, 8).Clear();
return;
}
if ((x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7) == 0)
{
- output[..8].Clear();
-
+ output.Slice(0, 8).Clear();
return;
}
// stage 1
- s0 = (long)CosPi2_64 * x0 + (long)CosPi30_64 * x1;
- s1 = (long)CosPi30_64 * x0 - (long)CosPi2_64 * x1;
- s2 = (long)CosPi10_64 * x2 + (long)CosPi22_64 * x3;
- s3 = (long)CosPi22_64 * x2 - (long)CosPi10_64 * x3;
- s4 = (long)CosPi18_64 * x4 + (long)CosPi14_64 * x5;
- s5 = (long)CosPi14_64 * x4 - (long)CosPi18_64 * x5;
- s6 = (long)CosPi26_64 * x6 + (long)CosPi6_64 * x7;
- s7 = (long)CosPi6_64 * x6 - (long)CosPi26_64 * x7;
+ s0 = ((long)CosPi264 * x0) + ((long)CosPi3064 * x1);
+ s1 = ((long)CosPi3064 * x0) - ((long)CosPi264 * x1);
+ s2 = ((long)CosPi1064 * x2) + ((long)CosPi2264 * x3);
+ s3 = ((long)CosPi2264 * x2) - ((long)CosPi1064 * x3);
+ s4 = ((long)CosPi1864 * x4) + ((long)CosPi1464 * x5);
+ s5 = ((long)CosPi1464 * x4) - ((long)CosPi1864 * x5);
+ s6 = ((long)CosPi2664 * x6) + ((long)CosPi664 * x7);
+ s7 = ((long)CosPi664 * x6) - ((long)CosPi2664 * x7);
x0 = HighbdWrapLow(DctConstRoundShift(s0 + s4), bd);
x1 = HighbdWrapLow(DctConstRoundShift(s1 + s5), bd);
@@ -1753,10 +1732,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
s1 = x1;
s2 = x2;
s3 = x3;
- s4 = (long)CosPi8_64 * x4 + (long)CosPi24_64 * x5;
- s5 = (long)CosPi24_64 * x4 - (long)CosPi8_64 * x5;
- s6 = (long)(-CosPi24_64) * x6 + (long)CosPi8_64 * x7;
- s7 = (long)CosPi8_64 * x6 + (long)CosPi24_64 * x7;
+ s4 = ((long)CosPi864 * x4) + ((long)CosPi2464 * x5);
+ s5 = ((long)CosPi2464 * x4) - ((long)CosPi864 * x5);
+ s6 = ((long)-CosPi2464 * x6) + ((long)CosPi864 * x7);
+ s7 = ((long)CosPi864 * x6) + ((long)CosPi2464 * x7);
x0 = HighbdWrapLow(s0 + s2, bd);
x1 = HighbdWrapLow(s1 + s3, bd);
@@ -1768,10 +1747,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
x7 = HighbdWrapLow(DctConstRoundShift(s5 - s7), bd);
// stage 3
- s2 = (long)CosPi16_64 * (x2 + x3);
- s3 = (long)CosPi16_64 * (x2 - x3);
- s6 = (long)CosPi16_64 * (x6 + x7);
- s7 = (long)CosPi16_64 * (x6 - x7);
+ s2 = (long)CosPi1664 * (x2 + x3);
+ s3 = (long)CosPi1664 * (x2 - x3);
+ s6 = (long)CosPi1664 * (x6 + x7);
+ s7 = (long)CosPi1664 * (x6 - x7);
x2 = HighbdWrapLow(DctConstRoundShift(s2), bd);
x3 = HighbdWrapLow(DctConstRoundShift(s3), bd);
@@ -1798,8 +1777,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
if (DetectInvalidHighbdInput(input, 8) != 0)
{
Debug.Assert(false, "invalid highbd txfm input");
- output[..8].Clear();
-
+ output.Slice(0, 8).Clear();
return;
}
@@ -1808,12 +1786,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[2] = input[4];
step1[1] = input[2];
step1[3] = input[6];
- temp1 = input[1] * (long)CosPi28_64 - input[7] * (long)CosPi4_64;
- temp2 = input[1] * (long)CosPi4_64 + input[7] * (long)CosPi28_64;
+ temp1 = (input[1] * (long)CosPi2864) - (input[7] * (long)CosPi464);
+ temp2 = (input[1] * (long)CosPi464) + (input[7] * (long)CosPi2864);
step1[4] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step1[7] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
- temp1 = input[5] * (long)CosPi12_64 - input[3] * (long)CosPi20_64;
- temp2 = input[5] * (long)CosPi20_64 + input[3] * (long)CosPi12_64;
+ temp1 = (input[5] * (long)CosPi1264) - (input[3] * (long)CosPi2064);
+ temp2 = (input[5] * (long)CosPi2064) + (input[3] * (long)CosPi1264);
step1[5] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step1[6] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
@@ -1828,8 +1806,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// stage 3 - odd half
step1[4] = step2[4];
- temp1 = (step2[6] - step2[5]) * (long)CosPi16_64;
- temp2 = (step2[5] + step2[6]) * (long)CosPi16_64;
+ temp1 = (step2[6] - step2[5]) * (long)CosPi1664;
+ temp2 = (step2[5] + step2[6]) * (long)CosPi1664;
step1[5] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step1[6] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
step1[7] = step2[7];
@@ -1848,32 +1826,32 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void HighbdIdct8x864Add(ReadOnlySpan input, Span dest, int stride, int bd)
{
- int i, j;
Span output = stackalloc int[8 * 8];
Span outptr = output;
Span tempIn = stackalloc int[8];
Span tempOut = stackalloc int[8];
// First transform rows
- for (i = 0; i < 8; ++i)
+ for (int i = 0; i < 8; ++i)
{
HighbdIdct8(input, outptr, bd);
- input = input[8..];
- outptr = outptr[8..];
+ input = input.Slice(8);
+ outptr = outptr.Slice(8);
}
// Then transform columns
- for (i = 0; i < 8; ++i)
+ for (int i = 0; i < 8; ++i)
{
- for (j = 0; j < 8; ++j)
+ for (int j = 0; j < 8; ++j)
{
- tempIn[j] = output[j * 8 + i];
+ tempIn[j] = output[(j * 8) + i];
}
HighbdIdct8(tempIn, tempOut, bd);
- for (j = 0; j < 8; ++j)
+ for (int j = 0; j < 8; ++j)
{
- dest[j * stride + i] = HighbdClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 5), bd);
+ dest[(j * stride) + i] = HighbdClipPixelAdd(dest[(j * stride) + i],
+ BitUtils.RoundPowerOfTwo(tempOut[j], 5), bd);
}
}
}
@@ -1881,7 +1859,6 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void HighbdIdct8x812Add(ReadOnlySpan input, Span dest, int stride, int bd)
{
- int i, j;
Span output = stackalloc int[8 * 8];
Span outptr = output;
Span tempIn = stackalloc int[8];
@@ -1891,45 +1868,45 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
// First transform rows
// Only first 4 row has non-zero coefs
- for (i = 0; i < 4; ++i)
+ for (int i = 0; i < 4; ++i)
{
HighbdIdct8(input, outptr, bd);
- input = input[8..];
- outptr = outptr[8..];
+ input = input.Slice(8);
+ outptr = outptr.Slice(8);
}
// Then transform columns
- for (i = 0; i < 8; ++i)
+ for (int i = 0; i < 8; ++i)
{
- for (j = 0; j < 8; ++j)
+ for (int j = 0; j < 8; ++j)
{
- tempIn[j] = output[j * 8 + i];
+ tempIn[j] = output[(j * 8) + i];
}
HighbdIdct8(tempIn, tempOut, bd);
- for (j = 0; j < 8; ++j)
+ for (int j = 0; j < 8; ++j)
{
- dest[j * stride + i] = HighbdClipPixelAdd(dest[j * stride + i], BitUtils.RoundPowerOfTwo(tempOut[j], 5), bd);
+ dest[(j * stride) + i] = HighbdClipPixelAdd(dest[(j * stride) + i],
+ BitUtils.RoundPowerOfTwo(tempOut[j], 5), bd);
}
}
}
- public static void Vpx_Highbdidct8x8_1_add_c(ReadOnlySpan input, Span dest, int stride, int bd)
+ public static void VpxHighbdidct8x81AddC(ReadOnlySpan input, Span dest, int stride, int bd)
{
- int i, j;
long a1;
- int output = HighbdWrapLow(DctConstRoundShift(input[0] * (long)CosPi16_64), bd);
+ int output = HighbdWrapLow(DctConstRoundShift(input[0] * (long)CosPi1664), bd);
- output = HighbdWrapLow(DctConstRoundShift(output * (long)CosPi16_64), bd);
+ output = HighbdWrapLow(DctConstRoundShift(output * (long)CosPi1664), bd);
a1 = BitUtils.RoundPowerOfTwo(output, 5);
- for (j = 0; j < 8; ++j)
+ for (int j = 0; j < 8; ++j)
{
- for (i = 0; i < 8; ++i)
+ for (int i = 0; i < 8; ++i)
{
dest[i] = HighbdClipPixelAdd(dest[i], a1, bd);
}
- dest = dest[stride..];
+ dest = dest.Slice(stride);
}
}
@@ -1953,39 +1930,36 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
int x13 = input[12];
int x14 = input[1];
int x15 = input[14];
-
if (DetectInvalidHighbdInput(input, 16) != 0)
{
Debug.Assert(false, "invalid highbd txfm input");
- output[..16].Clear();
-
+ output.Slice(0, 16).Clear();
return;
}
if ((x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | x10 | x11 | x12 | x13 | x14 | x15) == 0)
{
- output[..16].Clear();
-
+ output.Slice(0, 16).Clear();
return;
}
// stage 1
- s0 = x0 * (long)CosPi1_64 + x1 * (long)CosPi31_64;
- s1 = x0 * (long)CosPi31_64 - x1 * (long)CosPi1_64;
- s2 = x2 * (long)CosPi5_64 + x3 * (long)CosPi27_64;
- s3 = x2 * (long)CosPi27_64 - x3 * (long)CosPi5_64;
- s4 = x4 * (long)CosPi9_64 + x5 * (long)CosPi23_64;
- s5 = x4 * (long)CosPi23_64 - x5 * (long)CosPi9_64;
- s6 = x6 * (long)CosPi13_64 + x7 * (long)CosPi19_64;
- s7 = x6 * (long)CosPi19_64 - x7 * (long)CosPi13_64;
- s8 = x8 * (long)CosPi17_64 + x9 * (long)CosPi15_64;
- s9 = x8 * (long)CosPi15_64 - x9 * (long)CosPi17_64;
- s10 = x10 * (long)CosPi21_64 + x11 * (long)CosPi11_64;
- s11 = x10 * (long)CosPi11_64 - x11 * (long)CosPi21_64;
- s12 = x12 * (long)CosPi25_64 + x13 * (long)CosPi7_64;
- s13 = x12 * (long)CosPi7_64 - x13 * (long)CosPi25_64;
- s14 = x14 * (long)CosPi29_64 + x15 * (long)CosPi3_64;
- s15 = x14 * (long)CosPi3_64 - x15 * (long)CosPi29_64;
+ s0 = (x0 * (long)CosPi164) + (x1 * (long)CosPi3164);
+ s1 = (x0 * (long)CosPi3164) - (x1 * (long)CosPi164);
+ s2 = (x2 * (long)CosPi564) + (x3 * (long)CosPi2764);
+ s3 = (x2 * (long)CosPi2764) - (x3 * (long)CosPi564);
+ s4 = (x4 * (long)CosPi964) + (x5 * (long)CosPi2364);
+ s5 = (x4 * (long)CosPi2364) - (x5 * (long)CosPi964);
+ s6 = (x6 * (long)CosPi1364) + (x7 * (long)CosPi1964);
+ s7 = (x6 * (long)CosPi1964) - (x7 * (long)CosPi1364);
+ s8 = (x8 * (long)CosPi1764) + (x9 * (long)CosPi1564);
+ s9 = (x8 * (long)CosPi1564) - (x9 * (long)CosPi1764);
+ s10 = (x10 * (long)CosPi2164) + (x11 * (long)CosPi1164);
+ s11 = (x10 * (long)CosPi1164) - (x11 * (long)CosPi2164);
+ s12 = (x12 * (long)CosPi2564) + (x13 * (long)CosPi764);
+ s13 = (x12 * (long)CosPi764) - (x13 * (long)CosPi2564);
+ s14 = (x14 * (long)CosPi2964) + (x15 * (long)CosPi364);
+ s15 = (x14 * (long)CosPi364) - (x15 * (long)CosPi2964);
x0 = HighbdWrapLow(DctConstRoundShift(s0 + s8), bd);
x1 = HighbdWrapLow(DctConstRoundShift(s1 + s9), bd);
@@ -2013,14 +1987,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
s5 = x5;
s6 = x6;
s7 = x7;
- s8 = x8 * (long)CosPi4_64 + x9 * (long)CosPi28_64;
- s9 = x8 * (long)CosPi28_64 - x9 * (long)CosPi4_64;
- s10 = x10 * (long)CosPi20_64 + x11 * (long)CosPi12_64;
- s11 = x10 * (long)CosPi12_64 - x11 * (long)CosPi20_64;
- s12 = -x12 * (long)CosPi28_64 + x13 * (long)CosPi4_64;
- s13 = x12 * (long)CosPi4_64 + x13 * (long)CosPi28_64;
- s14 = -x14 * (long)CosPi12_64 + x15 * (long)CosPi20_64;
- s15 = x14 * (long)CosPi20_64 + x15 * (long)CosPi12_64;
+ s8 = (x8 * (long)CosPi464) + (x9 * (long)CosPi2864);
+ s9 = (x8 * (long)CosPi2864) - (x9 * (long)CosPi464);
+ s10 = (x10 * (long)CosPi2064) + (x11 * (long)CosPi1264);
+ s11 = (x10 * (long)CosPi1264) - (x11 * (long)CosPi2064);
+ s12 = (-x12 * (long)CosPi2864) + (x13 * (long)CosPi464);
+ s13 = (x12 * (long)CosPi464) + (x13 * (long)CosPi2864);
+ s14 = (-x14 * (long)CosPi1264) + (x15 * (long)CosPi2064);
+ s15 = (x14 * (long)CosPi2064) + (x15 * (long)CosPi1264);
x0 = HighbdWrapLow(s0 + s4, bd);
x1 = HighbdWrapLow(s1 + s5, bd);
@@ -2044,18 +2018,18 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
s1 = x1;
s2 = x2;
s3 = x3;
- s4 = x4 * (long)CosPi8_64 + x5 * (long)CosPi24_64;
- s5 = x4 * (long)CosPi24_64 - x5 * (long)CosPi8_64;
- s6 = -x6 * (long)CosPi24_64 + x7 * (long)CosPi8_64;
- s7 = x6 * (long)CosPi8_64 + x7 * (long)CosPi24_64;
+ s4 = (x4 * (long)CosPi864) + (x5 * (long)CosPi2464);
+ s5 = (x4 * (long)CosPi2464) - (x5 * (long)CosPi864);
+ s6 = (-x6 * (long)CosPi2464) + (x7 * (long)CosPi864);
+ s7 = (x6 * (long)CosPi864) + (x7 * (long)CosPi2464);
s8 = x8;
s9 = x9;
s10 = x10;
s11 = x11;
- s12 = x12 * (long)CosPi8_64 + x13 * (long)CosPi24_64;
- s13 = x12 * (long)CosPi24_64 - x13 * (long)CosPi8_64;
- s14 = -x14 * (long)CosPi24_64 + x15 * (long)CosPi8_64;
- s15 = x14 * (long)CosPi8_64 + x15 * (long)CosPi24_64;
+ s12 = (x12 * (long)CosPi864) + (x13 * (long)CosPi2464);
+ s13 = (x12 * (long)CosPi2464) - (x13 * (long)CosPi864);
+ s14 = (-x14 * (long)CosPi2464) + (x15 * (long)CosPi864);
+ s15 = (x14 * (long)CosPi864) + (x15 * (long)CosPi2464);
x0 = HighbdWrapLow(s0 + s2, bd);
x1 = HighbdWrapLow(s1 + s3, bd);
@@ -2075,14 +2049,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
x15 = HighbdWrapLow(DctConstRoundShift(s13 - s15), bd);
// stage 4
- s2 = (long)(-CosPi16_64) * (x2 + x3);
- s3 = (long)CosPi16_64 * (x2 - x3);
- s6 = (long)CosPi16_64 * (x6 + x7);
- s7 = (long)CosPi16_64 * (-x6 + x7);
- s10 = (long)CosPi16_64 * (x10 + x11);
- s11 = (long)CosPi16_64 * (-x10 + x11);
- s14 = (long)(-CosPi16_64) * (x14 + x15);
- s15 = (long)CosPi16_64 * (x14 - x15);
+ s2 = (long)-CosPi1664 * (x2 + x3);
+ s3 = (long)CosPi1664 * (x2 - x3);
+ s6 = (long)CosPi1664 * (x6 + x7);
+ s7 = (long)CosPi1664 * (-x6 + x7);
+ s10 = (long)CosPi1664 * (x10 + x11);
+ s11 = (long)CosPi1664 * (-x10 + x11);
+ s14 = (long)-CosPi1664 * (x14 + x15);
+ s15 = (long)CosPi1664 * (x14 - x15);
x2 = HighbdWrapLow(DctConstRoundShift(s2), bd);
x3 = HighbdWrapLow(DctConstRoundShift(s3), bd);
@@ -2121,8 +2095,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
if (DetectInvalidHighbdInput(input, 16) != 0)
{
Debug.Assert(false, "invalid highbd txfm input");
- output[..16].Clear();
-
+ output.Slice(0, 16).Clear();
return;
}
@@ -2154,23 +2127,23 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step2[6] = step1[6];
step2[7] = step1[7];
- temp1 = step1[8] * (long)CosPi30_64 - step1[15] * (long)CosPi2_64;
- temp2 = step1[8] * (long)CosPi2_64 + step1[15] * (long)CosPi30_64;
+ temp1 = (step1[8] * (long)CosPi3064) - (step1[15] * (long)CosPi264);
+ temp2 = (step1[8] * (long)CosPi264) + (step1[15] * (long)CosPi3064);
step2[8] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step2[15] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
- temp1 = step1[9] * (long)CosPi14_64 - step1[14] * (long)CosPi18_64;
- temp2 = step1[9] * (long)CosPi18_64 + step1[14] * (long)CosPi14_64;
+ temp1 = (step1[9] * (long)CosPi1464) - (step1[14] * (long)CosPi1864);
+ temp2 = (step1[9] * (long)CosPi1864) + (step1[14] * (long)CosPi1464);
step2[9] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step2[14] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
- temp1 = step1[10] * (long)CosPi22_64 - step1[13] * (long)CosPi10_64;
- temp2 = step1[10] * (long)CosPi10_64 + step1[13] * (long)CosPi22_64;
+ temp1 = (step1[10] * (long)CosPi2264) - (step1[13] * (long)CosPi1064);
+ temp2 = (step1[10] * (long)CosPi1064) + (step1[13] * (long)CosPi2264);
step2[10] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step2[13] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
- temp1 = step1[11] * (long)CosPi6_64 - step1[12] * (long)CosPi26_64;
- temp2 = step1[11] * (long)CosPi26_64 + step1[12] * (long)CosPi6_64;
+ temp1 = (step1[11] * (long)CosPi664) - (step1[12] * (long)CosPi2664);
+ temp2 = (step1[11] * (long)CosPi2664) + (step1[12] * (long)CosPi664);
step2[11] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step2[12] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
@@ -2180,12 +2153,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[2] = step2[2];
step1[3] = step2[3];
- temp1 = step2[4] * (long)CosPi28_64 - step2[7] * (long)CosPi4_64;
- temp2 = step2[4] * (long)CosPi4_64 + step2[7] * (long)CosPi28_64;
+ temp1 = (step2[4] * (long)CosPi2864) - (step2[7] * (long)CosPi464);
+ temp2 = (step2[4] * (long)CosPi464) + (step2[7] * (long)CosPi2864);
step1[4] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step1[7] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
- temp1 = step2[5] * (long)CosPi12_64 - step2[6] * (long)CosPi20_64;
- temp2 = step2[5] * (long)CosPi20_64 + step2[6] * (long)CosPi12_64;
+ temp1 = (step2[5] * (long)CosPi1264) - (step2[6] * (long)CosPi2064);
+ temp2 = (step2[5] * (long)CosPi2064) + (step2[6] * (long)CosPi1264);
step1[5] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step1[6] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
@@ -2199,12 +2172,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[15] = HighbdWrapLow(step2[14] + step2[15], bd);
// stage 4
- temp1 = (step1[0] + step1[1]) * (long)CosPi16_64;
- temp2 = (step1[0] - step1[1]) * (long)CosPi16_64;
+ temp1 = (step1[0] + step1[1]) * (long)CosPi1664;
+ temp2 = (step1[0] - step1[1]) * (long)CosPi1664;
step2[0] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step2[1] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
- temp1 = step1[2] * (long)CosPi24_64 - step1[3] * (long)CosPi8_64;
- temp2 = step1[2] * (long)CosPi8_64 + step1[3] * (long)CosPi24_64;
+ temp1 = (step1[2] * (long)CosPi2464) - (step1[3] * (long)CosPi864);
+ temp2 = (step1[2] * (long)CosPi864) + (step1[3] * (long)CosPi2464);
step2[2] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step2[3] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
step2[4] = HighbdWrapLow(step1[4] + step1[5], bd);
@@ -2214,12 +2187,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step2[8] = step1[8];
step2[15] = step1[15];
- temp1 = -step1[9] * (long)CosPi8_64 + step1[14] * (long)CosPi24_64;
- temp2 = step1[9] * (long)CosPi24_64 + step1[14] * (long)CosPi8_64;
+ temp1 = (-step1[9] * (long)CosPi864) + (step1[14] * (long)CosPi2464);
+ temp2 = (step1[9] * (long)CosPi2464) + (step1[14] * (long)CosPi864);
step2[9] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step2[14] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
- temp1 = -step1[10] * (long)CosPi24_64 - step1[13] * (long)CosPi8_64;
- temp2 = -step1[10] * (long)CosPi8_64 + step1[13] * (long)CosPi24_64;
+ temp1 = (-step1[10] * (long)CosPi2464) - (step1[13] * (long)CosPi864);
+ temp2 = (-step1[10] * (long)CosPi864) + (step1[13] * (long)CosPi2464);
step2[10] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step2[13] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
step2[11] = step1[11];
@@ -2231,8 +2204,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step1[2] = HighbdWrapLow(step2[1] - step2[2], bd);
step1[3] = HighbdWrapLow(step2[0] - step2[3], bd);
step1[4] = step2[4];
- temp1 = (step2[6] - step2[5]) * (long)CosPi16_64;
- temp2 = (step2[5] + step2[6]) * (long)CosPi16_64;
+ temp1 = (step2[6] - step2[5]) * (long)CosPi1664;
+ temp2 = (step2[5] + step2[6]) * (long)CosPi1664;
step1[5] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step1[6] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
step1[7] = step2[7];
@@ -2257,12 +2230,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
step2[7] = HighbdWrapLow(step1[0] - step1[7], bd);
step2[8] = step1[8];
step2[9] = step1[9];
- temp1 = (-step1[10] + step1[13]) * (long)CosPi16_64;
- temp2 = (step1[10] + step1[13]) * (long)CosPi16_64;
+ temp1 = (-step1[10] + step1[13]) * (long)CosPi1664;
+ temp2 = (step1[10] + step1[13]) * (long)CosPi1664;
step2[10] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step2[13] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
- temp1 = (-step1[11] + step1[12]) * (long)CosPi16_64;
- temp2 = (step1[11] + step1[12]) * (long)CosPi16_64;
+ temp1 = (-step1[11] + step1[12]) * (long)CosPi1664;
+ temp2 = (step1[11] + step1[12]) * (long)CosPi1664;
step2[11] = HighbdWrapLow(DctConstRoundShift(temp1), bd);
step2[12] = HighbdWrapLow(DctConstRoundShift(temp2), bd);
step2[14] = step1[14];
@@ -2290,32 +2263,32 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
[SkipLocalsInit]
public static void HighbdIdct16x16256Add(ReadOnlySpan input, Span dest, int stride, int bd)
{
- int i, j;
Span output = stackalloc int[16 * 16];
Span outptr = output;
Span