Rename ToSpan to AsSpan (#3556)

This commit is contained in:
gdkchan 2022-08-11 18:07:37 -03:00 committed by GitHub
parent f9661a54d2
commit a5ff0024fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 281 additions and 281 deletions

View file

@ -30,23 +30,23 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
Span<ushort> dst16 = MemoryMarshal.Cast<byte, ushort>(dst);
if (xd.Lossless)
{
Idct.HighbdIwht4x4Add(dqcoeff.ToSpan(), dst16, stride, eob, xd.Bd);
Idct.HighbdIwht4x4Add(dqcoeff.AsSpan(), dst16, stride, eob, xd.Bd);
}
else
{
switch (txSize)
{
case TxSize.Tx4x4:
Idct.HighbdIdct4x4Add(dqcoeff.ToSpan(), dst16, stride, eob, xd.Bd);
Idct.HighbdIdct4x4Add(dqcoeff.AsSpan(), dst16, stride, eob, xd.Bd);
break;
case TxSize.Tx8x8:
Idct.HighbdIdct8x8Add(dqcoeff.ToSpan(), dst16, stride, eob, xd.Bd);
Idct.HighbdIdct8x8Add(dqcoeff.AsSpan(), dst16, stride, eob, xd.Bd);
break;
case TxSize.Tx16x16:
Idct.HighbdIdct16x16Add(dqcoeff.ToSpan(), dst16, stride, eob, xd.Bd);
Idct.HighbdIdct16x16Add(dqcoeff.AsSpan(), dst16, stride, eob, xd.Bd);
break;
case TxSize.Tx32x32:
Idct.HighbdIdct32x32Add(dqcoeff.ToSpan(), dst16, stride, eob, xd.Bd);
Idct.HighbdIdct32x32Add(dqcoeff.AsSpan(), dst16, stride, eob, xd.Bd);
break;
default: Debug.Assert(false, "Invalid transform size"); break;
}
@ -56,16 +56,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
if (xd.Lossless)
{
Idct.Iwht4x4Add(dqcoeff.ToSpan(), dst, stride, eob);
Idct.Iwht4x4Add(dqcoeff.AsSpan(), dst, stride, eob);
}
else
{
switch (txSize)
{
case TxSize.Tx4x4: Idct.Idct4x4Add(dqcoeff.ToSpan(), dst, stride, eob); break;
case TxSize.Tx8x8: Idct.Idct8x8Add(dqcoeff.ToSpan(), dst, stride, eob); break;
case TxSize.Tx16x16: Idct.Idct16x16Add(dqcoeff.ToSpan(), dst, stride, eob); break;
case TxSize.Tx32x32: Idct.Idct32x32Add(dqcoeff.ToSpan(), dst, stride, eob); break;
case TxSize.Tx4x4: Idct.Idct4x4Add(dqcoeff.AsSpan(), dst, stride, eob); break;
case TxSize.Tx8x8: Idct.Idct8x8Add(dqcoeff.AsSpan(), dst, stride, eob); break;
case TxSize.Tx16x16: Idct.Idct16x16Add(dqcoeff.AsSpan(), dst, stride, eob); break;
case TxSize.Tx32x32: Idct.Idct32x32Add(dqcoeff.AsSpan(), dst, stride, eob); break;
default: Debug.Assert(false, "Invalid transform size"); return;
}
}
@ -73,21 +73,21 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (eob == 1)
{
dqcoeff.ToSpan()[0] = 0;
dqcoeff.AsSpan()[0] = 0;
}
else
{
if (txSize <= TxSize.Tx16x16 && eob <= 10)
{
dqcoeff.ToSpan().Slice(0, 4 * (4 << (int)txSize)).Fill(0);
dqcoeff.AsSpan().Slice(0, 4 * (4 << (int)txSize)).Fill(0);
}
else if (txSize == TxSize.Tx32x32 && eob <= 34)
{
dqcoeff.ToSpan().Slice(0, 256).Fill(0);
dqcoeff.AsSpan().Slice(0, 256).Fill(0);
}
else
{
dqcoeff.ToSpan().Slice(0, 16 << ((int)txSize << 1)).Fill(0);
dqcoeff.AsSpan().Slice(0, 16 << ((int)txSize << 1)).Fill(0);
}
}
}
@ -109,23 +109,23 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
Span<ushort> dst16 = MemoryMarshal.Cast<byte, ushort>(dst);
if (xd.Lossless)
{
Idct.HighbdIwht4x4Add(dqcoeff.ToSpan(), dst16, stride, eob, xd.Bd);
Idct.HighbdIwht4x4Add(dqcoeff.AsSpan(), dst16, stride, eob, xd.Bd);
}
else
{
switch (txSize)
{
case TxSize.Tx4x4:
Idct.HighbdIht4x4Add(txType, dqcoeff.ToSpan(), dst16, stride, eob, xd.Bd);
Idct.HighbdIht4x4Add(txType, dqcoeff.AsSpan(), dst16, stride, eob, xd.Bd);
break;
case TxSize.Tx8x8:
Idct.HighbdIht8x8Add(txType, dqcoeff.ToSpan(), dst16, stride, eob, xd.Bd);
Idct.HighbdIht8x8Add(txType, dqcoeff.AsSpan(), dst16, stride, eob, xd.Bd);
break;
case TxSize.Tx16x16:
Idct.HighbdIht16x16Add(txType, dqcoeff.ToSpan(), dst16, stride, eob, xd.Bd);
Idct.HighbdIht16x16Add(txType, dqcoeff.AsSpan(), dst16, stride, eob, xd.Bd);
break;
case TxSize.Tx32x32:
Idct.HighbdIdct32x32Add(dqcoeff.ToSpan(), dst16, stride, eob, xd.Bd);
Idct.HighbdIdct32x32Add(dqcoeff.AsSpan(), dst16, stride, eob, xd.Bd);
break;
default: Debug.Assert(false, "Invalid transform size"); break;
}
@ -135,16 +135,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
if (xd.Lossless)
{
Idct.Iwht4x4Add(dqcoeff.ToSpan(), dst, stride, eob);
Idct.Iwht4x4Add(dqcoeff.AsSpan(), dst, stride, eob);
}
else
{
switch (txSize)
{
case TxSize.Tx4x4: Idct.Iht4x4Add(txType, dqcoeff.ToSpan(), dst, stride, eob); break;
case TxSize.Tx8x8: Idct.Iht8x8Add(txType, dqcoeff.ToSpan(), dst, stride, eob); break;
case TxSize.Tx16x16: Idct.Iht16x16Add(txType, dqcoeff.ToSpan(), dst, stride, eob); break;
case TxSize.Tx32x32: Idct.Idct32x32Add(dqcoeff.ToSpan(), dst, stride, eob); break;
case TxSize.Tx4x4: Idct.Iht4x4Add(txType, dqcoeff.AsSpan(), dst, stride, eob); break;
case TxSize.Tx8x8: Idct.Iht8x8Add(txType, dqcoeff.AsSpan(), dst, stride, eob); break;
case TxSize.Tx16x16: Idct.Iht16x16Add(txType, dqcoeff.AsSpan(), dst, stride, eob); break;
case TxSize.Tx32x32: Idct.Idct32x32Add(dqcoeff.AsSpan(), dst, stride, eob); break;
default: Debug.Assert(false, "Invalid transform size"); return;
}
}
@ -152,21 +152,21 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (eob == 1)
{
dqcoeff.ToSpan()[0] = 0;
dqcoeff.AsSpan()[0] = 0;
}
else
{
if (txType == TxType.DctDct && txSize <= TxSize.Tx16x16 && eob <= 10)
{
dqcoeff.ToSpan().Slice(0, 4 * (4 << (int)txSize)).Fill(0);
dqcoeff.AsSpan().Slice(0, 4 * (4 << (int)txSize)).Fill(0);
}
else if (txSize == TxSize.Tx32x32 && eob <= 34)
{
dqcoeff.ToSpan().Slice(0, 256).Fill(0);
dqcoeff.AsSpan().Slice(0, 256).Fill(0);
}
else
{
dqcoeff.ToSpan().Slice(0, 16 << ((int)txSize << 1)).Fill(0);
dqcoeff.AsSpan().Slice(0, 16 << ((int)txSize << 1)).Fill(0);
}
}
}
@ -184,7 +184,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
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<byte> dstSpan = pd.Dst.Buf.ToSpan().Slice(dstOffset);
Span<byte> dstSpan = pd.Dst.Buf.AsSpan().Slice(dstOffset);
if (mi.SbType < BlockSize.Block8x8)
{
@ -223,7 +223,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ref MacroBlockDPlane pd = ref xd.Plane[plane];
var sc = Luts.Vp9DefaultScanOrders[(int)txSize];
int eob = Detokenize.DecodeBlockTokens(ref twd, plane, sc, col, row, txSize, mi.SegmentId);
Span<byte> dst = pd.Dst.Buf.ToSpan().Slice(4 * row * pd.Dst.Stride + 4 * col);
Span<byte> dst = pd.Dst.Buf.AsSpan().Slice(4 * row * pd.Dst.Stride + 4 * col);
if (eob > 0)
{
@ -922,7 +922,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
BlockSize subsize,
int bw)
{
Span<sbyte> aboveCtx = twd.Xd.AboveSegContext.Slice(miCol).ToSpan();
Span<sbyte> aboveCtx = twd.Xd.AboveSegContext.Slice(miCol).AsSpan();
Span<sbyte> 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
@ -1077,7 +1077,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
errorInfo.InternalError(CodecErr.CodecCorruptFrame, "Truncated packet or corrupt tile length");
}
size = BinaryPrimitives.ReadInt32BigEndian(data.ToSpan());
size = BinaryPrimitives.ReadInt32BigEndian(data.AsSpan());
data = data.Slice(4);
if (size > data.Length)
@ -1250,8 +1250,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
Debug.Assert(tileCols <= (1 << 6));
Debug.Assert(tileRows == 1);
cm.AboveContext.ToSpan().Fill(0);
cm.AboveSegContext.ToSpan().Fill(0);
cm.AboveContext.AsSpan().Fill(0);
cm.AboveSegContext.AsSpan().Fill(0);
for (n = 0; n < numWorkers; ++n)
{
@ -1266,12 +1266,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
GetTileBuffers(ref cm, data, tileCols, ref tileBuffers);
tileBuffers.ToSpan().Slice(0, tileCols).Sort(CompareTileBuffers);
tileBuffers.AsSpan().Slice(0, tileCols).Sort(CompareTileBuffers);
if (numWorkers == tileCols)
{
TileBuffer largest = tileBuffers[0];
Span<TileBuffer> buffers = tileBuffers.ToSpan();
Span<TileBuffer> buffers = tileBuffers.AsSpan();
buffers.Slice(1).CopyTo(buffers.Slice(0, tileBuffers.Length - 1));
tileBuffers[tileCols - 1] = largest;
}

View file

@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private static PredictionMode ReadIntraModeY(ref Vp9Common cm, ref MacroBlockD xd, ref Reader r, int sizeGroup)
{
PredictionMode yMode = ReadIntraMode(ref r, cm.Fc.Value.YModeProb[sizeGroup].ToSpan());
PredictionMode yMode = ReadIntraMode(ref r, cm.Fc.Value.YModeProb[sizeGroup].AsSpan());
if (!xd.Counts.IsNull)
{
++xd.Counts.Value.YMode[sizeGroup][(int)yMode];
@ -32,7 +32,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private static PredictionMode ReadIntraModeUv(ref Vp9Common cm, ref MacroBlockD xd, ref Reader r, byte yMode)
{
PredictionMode uvMode = ReadIntraMode(ref r, cm.Fc.Value.UvModeProb[yMode].ToSpan());
PredictionMode uvMode = ReadIntraMode(ref r, cm.Fc.Value.UvModeProb[yMode].AsSpan());
if (!xd.Counts.IsNull)
{
++xd.Counts.Value.UvMode[yMode][(int)uvMode];
@ -43,7 +43,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].ToSpan());
int mode = r.ReadTree(Luts.Vp9InterModeTree, cm.Fc.Value.InterModeProb[ctx].AsSpan());
if (!xd.Counts.IsNull)
{
++xd.Counts.Value.InterMode[ctx][mode];
@ -54,16 +54,16 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private static int ReadSegmentId(ref Reader r, ref Array7<byte> segTreeProbs)
{
return r.ReadTree(Luts.Vp9SegmentTree, segTreeProbs.ToSpan());
return r.ReadTree(Luts.Vp9SegmentTree, segTreeProbs.AsSpan());
}
private static ReadOnlySpan<byte> GetTxProbs(ref Vp9EntropyProbs fc, TxSize maxTxSize, int ctx)
{
switch (maxTxSize)
{
case TxSize.Tx8x8: return fc.Tx8x8Prob[ctx].ToSpan();
case TxSize.Tx16x16: return fc.Tx16x16Prob[ctx].ToSpan();
case TxSize.Tx32x32: return fc.Tx32x32Prob[ctx].ToSpan();
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<byte>.Empty;
}
}
@ -72,9 +72,9 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
switch (maxTxSize)
{
case TxSize.Tx8x8: return counts.Tx8x8[ctx].ToSpan();
case TxSize.Tx16x16: return counts.Tx16x16[ctx].ToSpan();
case TxSize.Tx32x32: return counts.Tx32x32[ctx].ToSpan();
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<uint>.Empty;
}
}
@ -253,7 +253,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
int mag, d, fr, hp;
bool sign = r.Read(fc.Sign[mvcomp]) != 0;
MvClassType mvClass = (MvClassType)r.ReadTree(Luts.Vp9MvClassTree, fc.Classes[mvcomp].ToSpan());
MvClassType mvClass = (MvClassType)r.ReadTree(Luts.Vp9MvClassTree, fc.Classes[mvcomp].AsSpan());
bool class0 = mvClass == MvClassType.MvClass0;
// Integer part
@ -277,7 +277,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
}
// Fractional part
fr = r.ReadTree(Luts.Vp9MvFPTree, class0 ? fc.Class0Fp[mvcomp][d].ToSpan() : fc.Fp[mvcomp].ToSpan());
fr = r.ReadTree(Luts.Vp9MvFPTree, 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;
@ -295,7 +295,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
Ptr<Vp9BackwardUpdates> counts,
bool allowHP)
{
MvJointType jointType = (MvJointType)r.ReadTree(Luts.Vp9MvJointTree, fc.Joints.ToSpan());
MvJointType jointType = (MvJointType)r.ReadTree(Luts.Vp9MvJointTree, fc.Joints.AsSpan());
bool useHP = allowHP && refr.UseMvHp();
Mv diff = new Mv();
@ -402,7 +402,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].ToSpan());
byte type = (byte)r.ReadTree(Luts.Vp9SwitchableInterpTree, cm.Fc.Value.SwitchableInterpProb[ctx].AsSpan());
if (!xd.Counts.IsNull)
{
++xd.Counts.Value.SwitchableInterp[ctx][type];
@ -1060,7 +1060,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
PredictionMode above = AboveBlockMode(mi, aboveMi, block);
PredictionMode left = LeftBlockMode(mi, leftMi, block);
return fc.KfYModeProb[(int)above][(int)left].ToSpan();
return fc.KfYModeProb[(int)above][(int)left].AsSpan();
}
private static void ReadIntraFrameModeInfo(
@ -1113,7 +1113,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
break;
}
mi.Value.UvMode = ReadIntraMode(ref r, cm.Fc.Value.KfUvModeProb[(int)mi.Value.Mode].ToSpan());
mi.Value.UvMode = ReadIntraMode(ref r, cm.Fc.Value.KfUvModeProb[(int)mi.Value.Mode].AsSpan());
}
private static void CopyRefFramePair(ref Array2<sbyte> dst, ref Array2<sbyte> src)

View file

@ -236,8 +236,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
ref MacroBlockDPlane pd = ref xd.Plane[plane];
ref Array2<short> dequant = ref pd.SegDequant[segId];
int eob;
Span<sbyte> a = pd.AboveContext.ToSpan().Slice(x);
Span<sbyte> l = pd.LeftContext.ToSpan().Slice(y);
Span<sbyte> a = pd.AboveContext.AsSpan().Slice(x);
Span<sbyte> l = pd.LeftContext.AsSpan().Slice(y);
int ctx;
int ctxShiftA = 0;
int ctxShiftL = 0;
@ -250,7 +250,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
eob = DecodeCoefs(
ref xd,
GetPlaneType(plane),
pd.DqCoeff.ToSpan(),
pd.DqCoeff.AsSpan(),
txSize,
ref dequant,
ctx,
@ -266,7 +266,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
eob = DecodeCoefs(
ref xd,
GetPlaneType(plane),
pd.DqCoeff.ToSpan(),
pd.DqCoeff.AsSpan(),
txSize,
ref dequant,
ctx,
@ -283,7 +283,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
eob = DecodeCoefs(
ref xd,
GetPlaneType(plane),
pd.DqCoeff.ToSpan(),
pd.DqCoeff.AsSpan(),
txSize,
ref dequant,
ctx,
@ -303,7 +303,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
eob = DecodeCoefs(
ref xd,
GetPlaneType(plane),
pd.DqCoeff.ToSpan(),
pd.DqCoeff.AsSpan(),
txSize,
ref dequant,
ctx,

View file

@ -50,7 +50,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
private void Fill()
{
ReadOnlySpan<byte> buffer = _buffer.ToSpan();
ReadOnlySpan<byte> buffer = _buffer.AsSpan();
ReadOnlySpan<byte> bufferStart = buffer;
ulong value = Value;
int count = Count;

View file

@ -359,8 +359,8 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
blockInsideLimit = 1;
}
lfi.Lfthr[lvl].Lim.ToSpan().Fill((byte)blockInsideLimit);
lfi.Lfthr[lvl].Mblim.ToSpan().Fill((byte)(2 * (lvl + 2) + blockInsideLimit));
lfi.Lfthr[lvl].Lim.AsSpan().Fill((byte)blockInsideLimit);
lfi.Lfthr[lvl].Mblim.AsSpan().Fill((byte)(2 * (lvl + 2) + blockInsideLimit));
}
}
@ -395,7 +395,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
{
// We could get rid of this if we assume that deltas are set to
// zero when not in use; encoder always uses deltas
MemoryMarshal.Cast<Array2<byte>, byte>(lfi.Lvl[segId].ToSpan()).Fill((byte)lvlSeg);
MemoryMarshal.Cast<Array2<byte>, byte>(lfi.Lvl[segId].AsSpan()).Fill((byte)lvlSeg);
}
else
{