Renaming part 8

This commit is contained in:
Alex Barney 2019-03-03 13:34:41 -06:00
parent 171bc34d2e
commit e7e11ef741
12 changed files with 787 additions and 787 deletions

View file

@ -280,14 +280,14 @@ namespace Ryujinx.Graphics.Gal.Shader
{
TextureTarget target = ImageUtils.GetTextureTarget(declInfo.TextureTarget);
_sb.AppendLine($"// {declInfo.TextureSuffix}");
_sb.AppendLine("uniform " + GetSamplerType(target, (declInfo.TextureSuffix & TextureInstructionSuffix.DC) != 0) + " " + declInfo.Name + ";");
_sb.AppendLine("uniform " + GetSamplerType(target, (declInfo.TextureSuffix & TextureInstructionSuffix.Dc) != 0) + " " + declInfo.Name + ";");
}
foreach (ShaderDeclInfo declInfo in _decl.Textures.Values.OrderBy(DeclKeySelector))
{
TextureTarget target = ImageUtils.GetTextureTarget(declInfo.TextureTarget);
_sb.AppendLine($"// {declInfo.TextureSuffix}");
_sb.AppendLine("uniform " + GetSamplerType(target, (declInfo.TextureSuffix & TextureInstructionSuffix.DC) != 0) + " " + declInfo.Name + ";");
_sb.AppendLine("uniform " + GetSamplerType(target, (declInfo.TextureSuffix & TextureInstructionSuffix.Dc) != 0) + " " + declInfo.Name + ";");
}
}
@ -1341,7 +1341,7 @@ namespace Ryujinx.Graphics.Gal.Shader
{
ShaderIrMetaTex meta = (ShaderIrMetaTex)op.MetaData;
bool hasDepth = (meta.TextureInstructionSuffix & TextureInstructionSuffix.DC) != 0;
bool hasDepth = (meta.TextureInstructionSuffix & TextureInstructionSuffix.Dc) != 0;
int coords = ImageUtils.GetCoordsCountTextureTarget(meta.TextureTarget);
@ -1436,7 +1436,7 @@ namespace Ryujinx.Graphics.Gal.Shader
string comp = meta.Component.ToString();
if ((suffix & TextureInstructionSuffix.DC) != 0)
if ((suffix & TextureInstructionSuffix.Dc) != 0)
{
comp = GetOperExpr(op, meta.DepthCompare);
}
@ -1445,7 +1445,7 @@ namespace Ryujinx.Graphics.Gal.Shader
{
string offset = GetTextureOffset(meta, "floatBitsToInt((" + GetOperExpr(op, meta.Offset) + "))", 8, 0x3F);
if ((suffix & TextureInstructionSuffix.DC) != 0)
if ((suffix & TextureInstructionSuffix.Dc) != 0)
{
return "textureGatherOffset(" + sampler + ", " + coords + ", " + comp + ", " + offset + ")" + chString;
}
@ -1453,7 +1453,7 @@ namespace Ryujinx.Graphics.Gal.Shader
return "textureGatherOffset(" + sampler + ", " + coords + ", " + offset + ", " + comp + ")" + chString;
}
// TODO: Support PTP
else if ((suffix & TextureInstructionSuffix.PTP) != 0)
else if ((suffix & TextureInstructionSuffix.Ptp) != 0)
{
throw new NotImplementedException();
}
@ -1470,13 +1470,13 @@ namespace Ryujinx.Graphics.Gal.Shader
string chString = "." + ch;
if ((suffix & TextureInstructionSuffix.DC) != 0)
if ((suffix & TextureInstructionSuffix.Dc) != 0)
{
chString = "";
}
// TODO: Support LBA and LLA
if ((suffix & TextureInstructionSuffix.LZ) != 0)
if ((suffix & TextureInstructionSuffix.Lz) != 0)
{
if ((suffix & TextureInstructionSuffix.AOffI) != 0 && _isNvidiaDriver)
{
@ -1487,7 +1487,7 @@ namespace Ryujinx.Graphics.Gal.Shader
return "textureLod(" + sampler + ", " + coords + ", 0.0)" + chString;
}
else if ((suffix & TextureInstructionSuffix.LB) != 0)
else if ((suffix & TextureInstructionSuffix.Lb) != 0)
{
if ((suffix & TextureInstructionSuffix.AOffI) != 0 && _isNvidiaDriver)
{
@ -1498,7 +1498,7 @@ namespace Ryujinx.Graphics.Gal.Shader
return "texture(" + sampler + ", " + coords + ", " + GetOperExpr(op, meta.LevelOfDetail) + ")" + chString;
}
else if ((suffix & TextureInstructionSuffix.LL) != 0)
else if ((suffix & TextureInstructionSuffix.Ll) != 0)
{
if ((suffix & TextureInstructionSuffix.AOffI) != 0 && _isNvidiaDriver)
{

View file

@ -212,19 +212,19 @@ namespace Ryujinx.Graphics.Gal.Shader
suffix = TextureInstructionSuffix.None;
break;
case 0x8:
suffix = TextureInstructionSuffix.LZ;
suffix = TextureInstructionSuffix.Lz;
break;
case 0x10:
suffix = TextureInstructionSuffix.LB;
suffix = TextureInstructionSuffix.Lb;
break;
case 0x18:
suffix = TextureInstructionSuffix.LL;
suffix = TextureInstructionSuffix.Ll;
break;
case 0x30:
suffix = TextureInstructionSuffix.LBA;
suffix = TextureInstructionSuffix.Lba;
break;
case 0x38:
suffix = TextureInstructionSuffix.LLA;
suffix = TextureInstructionSuffix.Lla;
break;
default:
throw new InvalidOperationException($"Invalid Suffix for TEX instruction {rawSuffix}");
@ -250,19 +250,19 @@ namespace Ryujinx.Graphics.Gal.Shader
suffix = TextureInstructionSuffix.None;
break;
case 0x2:
suffix = TextureInstructionSuffix.LZ;
suffix = TextureInstructionSuffix.Lz;
break;
case 0x4:
suffix = TextureInstructionSuffix.LB;
suffix = TextureInstructionSuffix.Lb;
break;
case 0x6:
suffix = TextureInstructionSuffix.LL;
suffix = TextureInstructionSuffix.Ll;
break;
case 0xc:
suffix = TextureInstructionSuffix.LBA;
suffix = TextureInstructionSuffix.Lba;
break;
case 0xe:
suffix = TextureInstructionSuffix.LLA;
suffix = TextureInstructionSuffix.Lla;
break;
default:
throw new InvalidOperationException($"Invalid Suffix for TEX.B instruction {rawSuffix}");
@ -286,7 +286,7 @@ namespace Ryujinx.Graphics.Gal.Shader
if (hasDepthCompare)
{
textureInstructionSuffix |= TextureInstructionSuffix.DC;
textureInstructionSuffix |= TextureInstructionSuffix.Dc;
}
ShaderIrOperGpr[] coords = new ShaderIrOperGpr[ImageUtils.GetCoordsCountTextureTarget(textureTarget)];
@ -326,10 +326,10 @@ namespace Ryujinx.Graphics.Gal.Shader
// TODO: determine first argument when TEX.B is used
int operBIndex = gprHandle ? 1 : 0;
if ((textureInstructionSuffix & TextureInstructionSuffix.LL) != 0 ||
(textureInstructionSuffix & TextureInstructionSuffix.LB) != 0 ||
(textureInstructionSuffix & TextureInstructionSuffix.LBA) != 0 ||
(textureInstructionSuffix & TextureInstructionSuffix.LLA) != 0)
if ((textureInstructionSuffix & TextureInstructionSuffix.Ll) != 0 ||
(textureInstructionSuffix & TextureInstructionSuffix.Lb) != 0 ||
(textureInstructionSuffix & TextureInstructionSuffix.Lba) != 0 ||
(textureInstructionSuffix & TextureInstructionSuffix.Lla) != 0)
{
levelOfDetail = opCode.Gpr20();
levelOfDetail.Index += operBIndex;
@ -345,7 +345,7 @@ namespace Ryujinx.Graphics.Gal.Shader
operBIndex++;
}
if ((textureInstructionSuffix & TextureInstructionSuffix.DC) != 0)
if ((textureInstructionSuffix & TextureInstructionSuffix.Dc) != 0)
{
depthCompare = opCode.Gpr20();
depthCompare.Index += operBIndex;
@ -405,14 +405,14 @@ namespace Ryujinx.Graphics.Gal.Shader
case 0x4:
case 0x10:
case 0x16:
suffix = TextureInstructionSuffix.LZ;
suffix = TextureInstructionSuffix.Lz;
break;
case 0x6:
case 0x1a:
suffix = TextureInstructionSuffix.LL;
suffix = TextureInstructionSuffix.Ll;
break;
case 0x8:
suffix = TextureInstructionSuffix.DC;
suffix = TextureInstructionSuffix.Dc;
break;
case 0x2:
case 0xe:
@ -421,11 +421,11 @@ namespace Ryujinx.Graphics.Gal.Shader
suffix = TextureInstructionSuffix.None;
break;
case 0xa:
suffix = TextureInstructionSuffix.LL | TextureInstructionSuffix.DC;
suffix = TextureInstructionSuffix.Ll | TextureInstructionSuffix.Dc;
break;
case 0xc:
case 0x12:
suffix = TextureInstructionSuffix.LZ | TextureInstructionSuffix.DC;
suffix = TextureInstructionSuffix.Lz | TextureInstructionSuffix.Dc;
break;
default:
throw new InvalidOperationException($"Invalid Suffix for TEXS instruction {rawSuffix}");
@ -447,21 +447,21 @@ namespace Ryujinx.Graphics.Gal.Shader
case 0:
case 0x4:
case 0x8:
suffix = TextureInstructionSuffix.LZ | TextureInstructionSuffix.AOffI;
suffix = TextureInstructionSuffix.Lz | TextureInstructionSuffix.AOffI;
break;
case 0xc:
suffix = TextureInstructionSuffix.LZ | TextureInstructionSuffix.MZ;
suffix = TextureInstructionSuffix.Lz | TextureInstructionSuffix.Mz;
break;
case 0xe:
case 0x10:
suffix = TextureInstructionSuffix.LZ;
suffix = TextureInstructionSuffix.Lz;
break;
case 0x2:
case 0xa:
suffix = TextureInstructionSuffix.LL;
suffix = TextureInstructionSuffix.Ll;
break;
case 0x18:
suffix = TextureInstructionSuffix.LL | TextureInstructionSuffix.AOffI;
suffix = TextureInstructionSuffix.Ll | TextureInstructionSuffix.AOffI;
break;
default:
throw new InvalidOperationException($"Invalid Suffix for TLDS instruction {rawSuffix}");
@ -487,7 +487,7 @@ namespace Ryujinx.Graphics.Gal.Shader
suffix = TextureInstructionSuffix.AOffI;
break;
case 0x8:
suffix = TextureInstructionSuffix.PTP;
suffix = TextureInstructionSuffix.Ptp;
break;
default:
throw new InvalidOperationException($"Invalid Suffix for TLD4 instruction {rawSuffix}");
@ -502,7 +502,7 @@ namespace Ryujinx.Graphics.Gal.Shader
if (isShadow)
{
suffix |= TextureInstructionSuffix.DC;
suffix |= TextureInstructionSuffix.Dc;
}
EmitTld4(block, opCode, textureTarget, suffix, chMask, opCode.Read(0x38, 0x3), false);
@ -522,7 +522,7 @@ namespace Ryujinx.Graphics.Gal.Shader
if (isShadow)
{
suffix |= TextureInstructionSuffix.DC;
suffix |= TextureInstructionSuffix.Dc;
}
// TLD4S seems to only support 2D textures with RGBA mask?
@ -598,7 +598,7 @@ namespace Ryujinx.Graphics.Gal.Shader
// Encoding of TEXS/TLDS is a bit special and change for 2d textures
// NOTE: OperA seems to hold at best two args.
// On 2D textures, if no suffix need an additional values, Y is stored in OperB, otherwise coords are in OperA and the additional values is in OperB.
if (textureInstructionSuffix != TextureInstructionSuffix.None && textureInstructionSuffix != TextureInstructionSuffix.LZ && textureTarget == GalTextureTarget.TwoD)
if (textureInstructionSuffix != TextureInstructionSuffix.None && textureInstructionSuffix != TextureInstructionSuffix.Lz && textureTarget == GalTextureTarget.TwoD)
{
coords[coords.Length - coordStartIndex - 1] = opCode.Gpr8();
coords[coords.Length - coordStartIndex - 1].Index += coords.Length - coordStartIndex - 1;
@ -606,7 +606,7 @@ namespace Ryujinx.Graphics.Gal.Shader
}
// TODO: Find what MZ does and what changes about the encoding (Maybe Multisample?)
if ((textureInstructionSuffix & TextureInstructionSuffix.LL) != 0)
if ((textureInstructionSuffix & TextureInstructionSuffix.Ll) != 0)
{
levelOfDetail = opCode.Gpr20();
levelOfDetail.Index += operBIndex;
@ -620,7 +620,7 @@ namespace Ryujinx.Graphics.Gal.Shader
operBIndex++;
}
if ((textureInstructionSuffix & TextureInstructionSuffix.DC) != 0)
if ((textureInstructionSuffix & TextureInstructionSuffix.Dc) != 0)
{
depthCompare = opCode.Gpr20();
depthCompare.Index += operBIndex;
@ -815,7 +815,7 @@ namespace Ryujinx.Graphics.Gal.Shader
operBIndex++;
}
if ((textureInstructionSuffix & TextureInstructionSuffix.DC) != 0)
if ((textureInstructionSuffix & TextureInstructionSuffix.Dc) != 0)
{
depthCompare = opCode.Gpr20();
depthCompare.Index += operBIndex;

View file

@ -6,14 +6,14 @@ namespace Ryujinx.Graphics.Texture
public enum TextureInstructionSuffix
{
None = 0x00, // No Modifier
LZ = 0x02, // Load LOD Zero
LB = 0x08, // Load Bias
LL = 0x10, // Load LOD
LBA = 0x20, // Load Bias with OperA? Auto?
LLA = 0x40, // Load LOD with OperA? Auto?
DC = 0x80, // Depth Compare
Lz = 0x02, // Load LOD Zero
Lb = 0x08, // Load Bias
Ll = 0x10, // Load LOD
Lba = 0x20, // Load Bias with OperA? Auto?
Lla = 0x40, // Load LOD with OperA? Auto?
Dc = 0x80, // Depth Compare
AOffI = 0x100, // Offset
MZ = 0x200, // Multisample Zero?
PTP = 0x400 // ???
Mz = 0x200, // Multisample Zero?
Ptp = 0x400 // ???
}
}

View file

@ -6,69 +6,69 @@ namespace Ryujinx.Graphics.VDec
{
private const int BufferSize = 8;
private Stream BaseStream;
private Stream _baseStream;
private int Buffer;
private int BufferPos;
private int _buffer;
private int _bufferPos;
public BitStreamWriter(Stream BaseStream)
public BitStreamWriter(Stream baseStream)
{
this.BaseStream = BaseStream;
_baseStream = baseStream;
}
public void WriteBit(bool Value)
public void WriteBit(bool value)
{
WriteBits(Value ? 1 : 0, 1);
WriteBits(value ? 1 : 0, 1);
}
public void WriteBits(int Value, int ValueSize)
public void WriteBits(int value, int valueSize)
{
int ValuePos = 0;
int valuePos = 0;
int Remaining = ValueSize;
int remaining = valueSize;
while (Remaining > 0)
while (remaining > 0)
{
int CopySize = Remaining;
int copySize = remaining;
int Free = GetFreeBufferBits();
int free = GetFreeBufferBits();
if (CopySize > Free)
if (copySize > free)
{
CopySize = Free;
copySize = free;
}
int Mask = (1 << CopySize) - 1;
int mask = (1 << copySize) - 1;
int SrcShift = (ValueSize - ValuePos) - CopySize;
int DstShift = (BufferSize - BufferPos) - CopySize;
int srcShift = (valueSize - valuePos) - copySize;
int dstShift = (BufferSize - _bufferPos) - copySize;
Buffer |= ((Value >> SrcShift) & Mask) << DstShift;
_buffer |= ((value >> srcShift) & mask) << dstShift;
ValuePos += CopySize;
BufferPos += CopySize;
Remaining -= CopySize;
valuePos += copySize;
_bufferPos += copySize;
remaining -= copySize;
}
}
private int GetFreeBufferBits()
{
if (BufferPos == BufferSize)
if (_bufferPos == BufferSize)
{
Flush();
}
return BufferSize - BufferPos;
return BufferSize - _bufferPos;
}
public void Flush()
{
if (BufferPos != 0)
if (_bufferPos != 0)
{
BaseStream.WriteByte((byte)Buffer);
_baseStream.WriteByte((byte)_buffer);
Buffer = 0;
BufferPos = 0;
_buffer = 0;
_bufferPos = 0;
}
}
}

View file

@ -4,14 +4,14 @@ namespace Ryujinx.Graphics.VDec
{
static class DecoderHelper
{
public static byte[] Combine(byte[] Arr0, byte[] Arr1)
public static byte[] Combine(byte[] arr0, byte[] arr1)
{
byte[] Output = new byte[Arr0.Length + Arr1.Length];
byte[] output = new byte[arr0.Length + arr1.Length];
Buffer.BlockCopy(Arr0, 0, Output, 0, Arr0.Length);
Buffer.BlockCopy(Arr1, 0, Output, Arr0.Length, Arr1.Length);
Buffer.BlockCopy(arr0, 0, output, 0, arr0.Length);
Buffer.BlockCopy(arr1, 0, output, arr0.Length, arr1.Length);
return Output;
return output;
}
}
}

View file

@ -6,13 +6,13 @@ namespace Ryujinx.Graphics.VDec
{
unsafe static class FFmpegWrapper
{
private static AVCodec* Codec;
private static AVCodecContext* Context;
private static AVFrame* Frame;
private static SwsContext* ScalerCtx;
private static AVCodec* _codec;
private static AVCodecContext* _context;
private static AVFrame* _frame;
private static SwsContext* _scalerCtx;
private static int ScalerWidth;
private static int ScalerHeight;
private static int _scalerWidth;
private static int _scalerHeight;
public static bool IsInitialized { get; private set; }
@ -26,42 +26,42 @@ namespace Ryujinx.Graphics.VDec
EnsureCodecInitialized(AVCodecID.AV_CODEC_ID_VP9);
}
private static void EnsureCodecInitialized(AVCodecID CodecId)
private static void EnsureCodecInitialized(AVCodecID codecId)
{
if (IsInitialized)
{
Uninitialize();
}
Codec = ffmpeg.avcodec_find_decoder(CodecId);
Context = ffmpeg.avcodec_alloc_context3(Codec);
Frame = ffmpeg.av_frame_alloc();
_codec = ffmpeg.avcodec_find_decoder(codecId);
_context = ffmpeg.avcodec_alloc_context3(_codec);
_frame = ffmpeg.av_frame_alloc();
ffmpeg.avcodec_open2(Context, Codec, null);
ffmpeg.avcodec_open2(_context, _codec, null);
IsInitialized = true;
}
public static int DecodeFrame(byte[] Data)
public static int DecodeFrame(byte[] data)
{
if (!IsInitialized)
{
throw new InvalidOperationException("Tried to use uninitialized codec!");
}
AVPacket Packet;
AVPacket packet;
ffmpeg.av_init_packet(&Packet);
ffmpeg.av_init_packet(&packet);
fixed (byte* Ptr = Data)
fixed (byte* ptr = data)
{
Packet.data = Ptr;
Packet.size = Data.Length;
packet.data = ptr;
packet.size = data.Length;
ffmpeg.avcodec_send_packet(Context, &Packet);
ffmpeg.avcodec_send_packet(_context, &packet);
}
return ffmpeg.avcodec_receive_frame(Context, Frame);
return ffmpeg.avcodec_receive_frame(_context, _frame);
}
public static FFmpegFrame GetFrame()
@ -71,18 +71,18 @@ namespace Ryujinx.Graphics.VDec
throw new InvalidOperationException("Tried to use uninitialized codec!");
}
AVFrame ManagedFrame = Marshal.PtrToStructure<AVFrame>((IntPtr)Frame);
AVFrame managedFrame = Marshal.PtrToStructure<AVFrame>((IntPtr)_frame);
byte*[] Data = ManagedFrame.data.ToArray();
byte*[] data = managedFrame.data.ToArray();
return new FFmpegFrame()
{
Width = ManagedFrame.width,
Height = ManagedFrame.height,
Width = managedFrame.width,
Height = managedFrame.height,
LumaPtr = Data[0],
ChromaBPtr = Data[1],
ChromaRPtr = Data[2]
LumaPtr = data[0],
ChromaBPtr = data[1],
ChromaRPtr = data[2]
};
}
@ -93,51 +93,51 @@ namespace Ryujinx.Graphics.VDec
throw new InvalidOperationException("Tried to use uninitialized codec!");
}
AVFrame ManagedFrame = Marshal.PtrToStructure<AVFrame>((IntPtr)Frame);
AVFrame managedFrame = Marshal.PtrToStructure<AVFrame>((IntPtr)_frame);
EnsureScalerSetup(ManagedFrame.width, ManagedFrame.height);
EnsureScalerSetup(managedFrame.width, managedFrame.height);
byte*[] Data = ManagedFrame.data.ToArray();
byte*[] data = managedFrame.data.ToArray();
int[] LineSizes = ManagedFrame.linesize.ToArray();
int[] lineSizes = managedFrame.linesize.ToArray();
byte[] Dst = new byte[ManagedFrame.width * ManagedFrame.height * 4];
byte[] dst = new byte[managedFrame.width * managedFrame.height * 4];
fixed (byte* Ptr = Dst)
fixed (byte* ptr = dst)
{
byte*[] DstData = new byte*[] { Ptr };
byte*[] dstData = new byte*[] { ptr };
int[] DstLineSizes = new int[] { ManagedFrame.width * 4 };
int[] dstLineSizes = new int[] { managedFrame.width * 4 };
ffmpeg.sws_scale(ScalerCtx, Data, LineSizes, 0, ManagedFrame.height, DstData, DstLineSizes);
ffmpeg.sws_scale(_scalerCtx, data, lineSizes, 0, managedFrame.height, dstData, dstLineSizes);
}
return new FFmpegFrame()
{
Width = ManagedFrame.width,
Height = ManagedFrame.height,
Width = managedFrame.width,
Height = managedFrame.height,
Data = Dst
Data = dst
};
}
private static void EnsureScalerSetup(int Width, int Height)
private static void EnsureScalerSetup(int width, int height)
{
if (Width == 0 || Height == 0)
if (width == 0 || height == 0)
{
return;
}
if (ScalerCtx == null || ScalerWidth != Width || ScalerHeight != Height)
if (_scalerCtx == null || _scalerWidth != width || _scalerHeight != height)
{
FreeScaler();
ScalerCtx = ffmpeg.sws_getContext(
Width, Height, AVPixelFormat.AV_PIX_FMT_YUV420P,
Width, Height, AVPixelFormat.AV_PIX_FMT_RGBA, 0, null, null, null);
_scalerCtx = ffmpeg.sws_getContext(
width, height, AVPixelFormat.AV_PIX_FMT_YUV420P,
width, height, AVPixelFormat.AV_PIX_FMT_RGBA, 0, null, null, null);
ScalerWidth = Width;
ScalerHeight = Height;
_scalerWidth = width;
_scalerHeight = height;
}
}
@ -145,9 +145,9 @@ namespace Ryujinx.Graphics.VDec
{
if (IsInitialized)
{
ffmpeg.av_frame_unref(Frame);
ffmpeg.av_free(Frame);
ffmpeg.avcodec_close(Context);
ffmpeg.av_frame_unref(_frame);
ffmpeg.av_free(_frame);
ffmpeg.avcodec_close(_context);
FreeScaler();
@ -157,11 +157,11 @@ namespace Ryujinx.Graphics.VDec
private static void FreeScaler()
{
if (ScalerCtx != null)
if (_scalerCtx != null)
{
ffmpeg.sws_freeContext(ScalerCtx);
ffmpeg.sws_freeContext(_scalerCtx);
ScalerCtx = null;
_scalerCtx = null;
}
}
}

View file

@ -4,21 +4,21 @@ namespace Ryujinx.Graphics.VDec
{
class H264BitStreamWriter : BitStreamWriter
{
public H264BitStreamWriter(Stream BaseStream) : base(BaseStream) { }
public H264BitStreamWriter(Stream baseStream) : base(baseStream) { }
public void WriteU(int Value, int ValueSize)
public void WriteU(int value, int valueSize)
{
WriteBits(Value, ValueSize);
WriteBits(value, valueSize);
}
public void WriteSe(int Value)
public void WriteSe(int value)
{
WriteExpGolombCodedInt(Value);
WriteExpGolombCodedInt(value);
}
public void WriteUe(int Value)
public void WriteUe(int value)
{
WriteExpGolombCodedUInt((uint)Value);
WriteExpGolombCodedUInt((uint)value);
}
public void End()
@ -28,52 +28,52 @@ namespace Ryujinx.Graphics.VDec
Flush();
}
private void WriteExpGolombCodedInt(int Value)
private void WriteExpGolombCodedInt(int value)
{
int Sign = Value <= 0 ? 0 : 1;
int sign = value <= 0 ? 0 : 1;
if (Value < 0)
if (value < 0)
{
Value = -Value;
value = -value;
}
Value = (Value << 1) - Sign;
value = (value << 1) - sign;
WriteExpGolombCodedUInt((uint)Value);
WriteExpGolombCodedUInt((uint)value);
}
private void WriteExpGolombCodedUInt(uint Value)
private void WriteExpGolombCodedUInt(uint value)
{
int Size = 32 - CountLeadingZeros((int)Value + 1);
int size = 32 - CountLeadingZeros((int)value + 1);
WriteBits(1, Size);
WriteBits(1, size);
Value -= (1u << (Size - 1)) - 1;
value -= (1u << (size - 1)) - 1;
WriteBits((int)Value, Size - 1);
WriteBits((int)value, size - 1);
}
private static readonly byte[] ClzNibbleTbl = { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
private static int CountLeadingZeros(int Value)
private static int CountLeadingZeros(int value)
{
if (Value == 0)
if (value == 0)
{
return 32;
}
int NibbleIdx = 32;
int PreCount, Count = 0;
int nibbleIdx = 32;
int preCount, count = 0;
do
{
NibbleIdx -= 4;
PreCount = ClzNibbleTbl[(Value >> NibbleIdx) & 0b1111];
Count += PreCount;
nibbleIdx -= 4;
preCount = ClzNibbleTbl[(value >> nibbleIdx) & 0b1111];
count += preCount;
}
while (PreCount == 4);
while (preCount == 4);
return Count;
return count;
}
}
}

View file

@ -4,195 +4,195 @@ namespace Ryujinx.Graphics.VDec
{
class H264Decoder
{
private int Log2MaxPicOrderCntLsbMinus4;
private bool DeltaPicOrderAlwaysZeroFlag;
private bool FrameMbsOnlyFlag;
private int PicWidthInMbs;
private int PicHeightInMapUnits;
private bool EntropyCodingModeFlag;
private bool BottomFieldPicOrderInFramePresentFlag;
private int NumRefIdxL0DefaultActiveMinus1;
private int NumRefIdxL1DefaultActiveMinus1;
private bool DeblockingFilterControlPresentFlag;
private bool RedundantPicCntPresentFlag;
private int _log2MaxPicOrderCntLsbMinus4;
private bool _deltaPicOrderAlwaysZeroFlag;
private bool _frameMbsOnlyFlag;
private int _picWidthInMbs;
private int _picHeightInMapUnits;
private bool _entropyCodingModeFlag;
private bool _bottomFieldPicOrderInFramePresentFlag;
private int _numRefIdxL0DefaultActiveMinus1;
private int _numRefIdxL1DefaultActiveMinus1;
private bool _deblockingFilterControlPresentFlag;
private bool _redundantPicCntPresentFlag;
private bool Transform8x8ModeFlag;
private bool MbAdaptiveFrameFieldFlag;
private bool _mbAdaptiveFrameFieldFlag;
private bool Direct8x8InferenceFlag;
private bool WeightedPredFlag;
private bool ConstrainedIntraPredFlag;
private bool FieldPicFlag;
private bool BottomFieldFlag;
private int Log2MaxFrameNumMinus4;
private int ChromaFormatIdc;
private int PicOrderCntType;
private int PicInitQpMinus26;
private int ChromaQpIndexOffset;
private int ChromaQpIndexOffset2;
private int WeightedBipredIdc;
private int FrameNumber;
private byte[] ScalingMatrix4;
private byte[] ScalingMatrix8;
private bool _weightedPredFlag;
private bool _constrainedIntraPredFlag;
private bool _fieldPicFlag;
private bool _bottomFieldFlag;
private int _log2MaxFrameNumMinus4;
private int _chromaFormatIdc;
private int _picOrderCntType;
private int _picInitQpMinus26;
private int _chromaQpIndexOffset;
private int _chromaQpIndexOffset2;
private int _weightedBipredIdc;
private int _frameNumber;
private byte[] _scalingMatrix4;
private byte[] _scalingMatrix8;
public void Decode(H264ParameterSets Params, H264Matrices Matrices, byte[] FrameData)
public void Decode(H264ParameterSets Params, H264Matrices matrices, byte[] frameData)
{
Log2MaxPicOrderCntLsbMinus4 = Params.Log2MaxPicOrderCntLsbMinus4;
DeltaPicOrderAlwaysZeroFlag = Params.DeltaPicOrderAlwaysZeroFlag;
FrameMbsOnlyFlag = Params.FrameMbsOnlyFlag;
PicWidthInMbs = Params.PicWidthInMbs;
PicHeightInMapUnits = Params.PicHeightInMapUnits;
EntropyCodingModeFlag = Params.EntropyCodingModeFlag;
BottomFieldPicOrderInFramePresentFlag = Params.BottomFieldPicOrderInFramePresentFlag;
NumRefIdxL0DefaultActiveMinus1 = Params.NumRefIdxL0DefaultActiveMinus1;
NumRefIdxL1DefaultActiveMinus1 = Params.NumRefIdxL1DefaultActiveMinus1;
DeblockingFilterControlPresentFlag = Params.DeblockingFilterControlPresentFlag;
RedundantPicCntPresentFlag = Params.RedundantPicCntPresentFlag;
_log2MaxPicOrderCntLsbMinus4 = Params.Log2MaxPicOrderCntLsbMinus4;
_deltaPicOrderAlwaysZeroFlag = Params.DeltaPicOrderAlwaysZeroFlag;
_frameMbsOnlyFlag = Params.FrameMbsOnlyFlag;
_picWidthInMbs = Params.PicWidthInMbs;
_picHeightInMapUnits = Params.PicHeightInMapUnits;
_entropyCodingModeFlag = Params.EntropyCodingModeFlag;
_bottomFieldPicOrderInFramePresentFlag = Params.BottomFieldPicOrderInFramePresentFlag;
_numRefIdxL0DefaultActiveMinus1 = Params.NumRefIdxL0DefaultActiveMinus1;
_numRefIdxL1DefaultActiveMinus1 = Params.NumRefIdxL1DefaultActiveMinus1;
_deblockingFilterControlPresentFlag = Params.DeblockingFilterControlPresentFlag;
_redundantPicCntPresentFlag = Params.RedundantPicCntPresentFlag;
Transform8x8ModeFlag = Params.Transform8x8ModeFlag;
MbAdaptiveFrameFieldFlag = ((Params.Flags >> 0) & 1) != 0;
_mbAdaptiveFrameFieldFlag = ((Params.Flags >> 0) & 1) != 0;
Direct8x8InferenceFlag = ((Params.Flags >> 1) & 1) != 0;
WeightedPredFlag = ((Params.Flags >> 2) & 1) != 0;
ConstrainedIntraPredFlag = ((Params.Flags >> 3) & 1) != 0;
FieldPicFlag = ((Params.Flags >> 5) & 1) != 0;
BottomFieldFlag = ((Params.Flags >> 6) & 1) != 0;
_weightedPredFlag = ((Params.Flags >> 2) & 1) != 0;
_constrainedIntraPredFlag = ((Params.Flags >> 3) & 1) != 0;
_fieldPicFlag = ((Params.Flags >> 5) & 1) != 0;
_bottomFieldFlag = ((Params.Flags >> 6) & 1) != 0;
Log2MaxFrameNumMinus4 = (int)(Params.Flags >> 8) & 0xf;
ChromaFormatIdc = (int)(Params.Flags >> 12) & 0x3;
PicOrderCntType = (int)(Params.Flags >> 14) & 0x3;
PicInitQpMinus26 = (int)(Params.Flags >> 16) & 0x3f;
ChromaQpIndexOffset = (int)(Params.Flags >> 22) & 0x1f;
ChromaQpIndexOffset2 = (int)(Params.Flags >> 27) & 0x1f;
WeightedBipredIdc = (int)(Params.Flags >> 32) & 0x3;
FrameNumber = (int)(Params.Flags >> 46) & 0x1ffff;
_log2MaxFrameNumMinus4 = (int)(Params.Flags >> 8) & 0xf;
_chromaFormatIdc = (int)(Params.Flags >> 12) & 0x3;
_picOrderCntType = (int)(Params.Flags >> 14) & 0x3;
_picInitQpMinus26 = (int)(Params.Flags >> 16) & 0x3f;
_chromaQpIndexOffset = (int)(Params.Flags >> 22) & 0x1f;
_chromaQpIndexOffset2 = (int)(Params.Flags >> 27) & 0x1f;
_weightedBipredIdc = (int)(Params.Flags >> 32) & 0x3;
_frameNumber = (int)(Params.Flags >> 46) & 0x1ffff;
PicInitQpMinus26 = (PicInitQpMinus26 << 26) >> 26;
ChromaQpIndexOffset = (ChromaQpIndexOffset << 27) >> 27;
ChromaQpIndexOffset2 = (ChromaQpIndexOffset2 << 27) >> 27;
_picInitQpMinus26 = (_picInitQpMinus26 << 26) >> 26;
_chromaQpIndexOffset = (_chromaQpIndexOffset << 27) >> 27;
_chromaQpIndexOffset2 = (_chromaQpIndexOffset2 << 27) >> 27;
ScalingMatrix4 = Matrices.ScalingMatrix4;
ScalingMatrix8 = Matrices.ScalingMatrix8;
_scalingMatrix4 = matrices.ScalingMatrix4;
_scalingMatrix8 = matrices.ScalingMatrix8;
if (FFmpegWrapper.IsInitialized)
{
FFmpegWrapper.DecodeFrame(FrameData);
FFmpegWrapper.DecodeFrame(frameData);
}
else
{
FFmpegWrapper.H264Initialize();
FFmpegWrapper.DecodeFrame(DecoderHelper.Combine(EncodeHeader(), FrameData));
FFmpegWrapper.DecodeFrame(DecoderHelper.Combine(EncodeHeader(), frameData));
}
}
private byte[] EncodeHeader()
{
using (MemoryStream Data = new MemoryStream())
using (MemoryStream data = new MemoryStream())
{
H264BitStreamWriter Writer = new H264BitStreamWriter(Data);
H264BitStreamWriter writer = new H264BitStreamWriter(data);
//Sequence Parameter Set.
Writer.WriteU(1, 24);
Writer.WriteU(0, 1);
Writer.WriteU(3, 2);
Writer.WriteU(7, 5);
Writer.WriteU(100, 8);
Writer.WriteU(0, 8);
Writer.WriteU(31, 8);
Writer.WriteUe(0);
Writer.WriteUe(ChromaFormatIdc);
writer.WriteU(1, 24);
writer.WriteU(0, 1);
writer.WriteU(3, 2);
writer.WriteU(7, 5);
writer.WriteU(100, 8);
writer.WriteU(0, 8);
writer.WriteU(31, 8);
writer.WriteUe(0);
writer.WriteUe(_chromaFormatIdc);
if (ChromaFormatIdc == 3)
if (_chromaFormatIdc == 3)
{
Writer.WriteBit(false);
writer.WriteBit(false);
}
Writer.WriteUe(0);
Writer.WriteUe(0);
Writer.WriteBit(false);
Writer.WriteBit(false); //Scaling matrix present flag
writer.WriteUe(0);
writer.WriteUe(0);
writer.WriteBit(false);
writer.WriteBit(false); //Scaling matrix present flag
Writer.WriteUe(Log2MaxFrameNumMinus4);
Writer.WriteUe(PicOrderCntType);
writer.WriteUe(_log2MaxFrameNumMinus4);
writer.WriteUe(_picOrderCntType);
if (PicOrderCntType == 0)
if (_picOrderCntType == 0)
{
Writer.WriteUe(Log2MaxPicOrderCntLsbMinus4);
writer.WriteUe(_log2MaxPicOrderCntLsbMinus4);
}
else if (PicOrderCntType == 1)
else if (_picOrderCntType == 1)
{
Writer.WriteBit(DeltaPicOrderAlwaysZeroFlag);
writer.WriteBit(_deltaPicOrderAlwaysZeroFlag);
Writer.WriteSe(0);
Writer.WriteSe(0);
Writer.WriteUe(0);
writer.WriteSe(0);
writer.WriteSe(0);
writer.WriteUe(0);
}
int PicHeightInMbs = PicHeightInMapUnits / (FrameMbsOnlyFlag ? 1 : 2);
int picHeightInMbs = _picHeightInMapUnits / (_frameMbsOnlyFlag ? 1 : 2);
Writer.WriteUe(16);
Writer.WriteBit(false);
Writer.WriteUe(PicWidthInMbs - 1);
Writer.WriteUe(PicHeightInMbs - 1);
Writer.WriteBit(FrameMbsOnlyFlag);
writer.WriteUe(16);
writer.WriteBit(false);
writer.WriteUe(_picWidthInMbs - 1);
writer.WriteUe(picHeightInMbs - 1);
writer.WriteBit(_frameMbsOnlyFlag);
if (!FrameMbsOnlyFlag)
if (!_frameMbsOnlyFlag)
{
Writer.WriteBit(MbAdaptiveFrameFieldFlag);
writer.WriteBit(_mbAdaptiveFrameFieldFlag);
}
Writer.WriteBit(Direct8x8InferenceFlag);
Writer.WriteBit(false); //Frame cropping flag
Writer.WriteBit(false); //VUI parameter present flag
writer.WriteBit(Direct8x8InferenceFlag);
writer.WriteBit(false); //Frame cropping flag
writer.WriteBit(false); //VUI parameter present flag
Writer.End();
writer.End();
//Picture Parameter Set.
Writer.WriteU(1, 24);
Writer.WriteU(0, 1);
Writer.WriteU(3, 2);
Writer.WriteU(8, 5);
writer.WriteU(1, 24);
writer.WriteU(0, 1);
writer.WriteU(3, 2);
writer.WriteU(8, 5);
Writer.WriteUe(0);
Writer.WriteUe(0);
writer.WriteUe(0);
writer.WriteUe(0);
Writer.WriteBit(EntropyCodingModeFlag);
Writer.WriteBit(false);
Writer.WriteUe(0);
Writer.WriteUe(NumRefIdxL0DefaultActiveMinus1);
Writer.WriteUe(NumRefIdxL1DefaultActiveMinus1);
Writer.WriteBit(WeightedPredFlag);
Writer.WriteU(WeightedBipredIdc, 2);
Writer.WriteSe(PicInitQpMinus26);
Writer.WriteSe(0);
Writer.WriteSe(ChromaQpIndexOffset);
Writer.WriteBit(DeblockingFilterControlPresentFlag);
Writer.WriteBit(ConstrainedIntraPredFlag);
Writer.WriteBit(RedundantPicCntPresentFlag);
Writer.WriteBit(Transform8x8ModeFlag);
writer.WriteBit(_entropyCodingModeFlag);
writer.WriteBit(false);
writer.WriteUe(0);
writer.WriteUe(_numRefIdxL0DefaultActiveMinus1);
writer.WriteUe(_numRefIdxL1DefaultActiveMinus1);
writer.WriteBit(_weightedPredFlag);
writer.WriteU(_weightedBipredIdc, 2);
writer.WriteSe(_picInitQpMinus26);
writer.WriteSe(0);
writer.WriteSe(_chromaQpIndexOffset);
writer.WriteBit(_deblockingFilterControlPresentFlag);
writer.WriteBit(_constrainedIntraPredFlag);
writer.WriteBit(_redundantPicCntPresentFlag);
writer.WriteBit(Transform8x8ModeFlag);
Writer.WriteBit(true);
writer.WriteBit(true);
for (int Index = 0; Index < 6; Index++)
for (int index = 0; index < 6; index++)
{
Writer.WriteBit(true);
writer.WriteBit(true);
WriteScalingList(Writer, ScalingMatrix4, Index * 16, 16);
WriteScalingList(writer, _scalingMatrix4, index * 16, 16);
}
if (Transform8x8ModeFlag)
{
for (int Index = 0; Index < 2; Index++)
for (int index = 0; index < 2; index++)
{
Writer.WriteBit(true);
writer.WriteBit(true);
WriteScalingList(Writer, ScalingMatrix8, Index * 64, 64);
WriteScalingList(writer, _scalingMatrix8, index * 64, 64);
}
}
Writer.WriteSe(ChromaQpIndexOffset2);
writer.WriteSe(_chromaQpIndexOffset2);
Writer.End();
writer.End();
return Data.ToArray();
return data.ToArray();
}
}
@ -217,21 +217,21 @@ namespace Ryujinx.Graphics.VDec
3 + 1 * 4, 3 + 2 * 4, 2 + 3 * 4, 3 + 3 * 4
};
private static void WriteScalingList(H264BitStreamWriter Writer, byte[] List, int Start, int Count)
private static void WriteScalingList(H264BitStreamWriter writer, byte[] list, int start, int count)
{
byte[] Scan = Count == 16 ? ZigZagScan : ZigZagDirect;
byte[] scan = count == 16 ? ZigZagScan : ZigZagDirect;
int LastScale = 8;
int lastScale = 8;
for (int Index = 0; Index < Count; Index++)
for (int index = 0; index < count; index++)
{
byte Value = List[Start + Scan[Index]];
byte value = list[start + scan[index]];
int DeltaScale = Value - LastScale;
int deltaScale = value - lastScale;
Writer.WriteSe(DeltaScale);
writer.WriteSe(deltaScale);
LastScale = Value;
lastScale = value;
}
}
}

View file

@ -9,124 +9,124 @@ namespace Ryujinx.Graphics.VDec
{
unsafe class VideoDecoder
{
private NvGpu Gpu;
private NvGpu _gpu;
private H264Decoder H264Decoder;
private Vp9Decoder Vp9Decoder;
private H264Decoder _h264Decoder;
private Vp9Decoder _vp9Decoder;
private VideoCodec CurrentVideoCodec;
private VideoCodec _currentVideoCodec;
private long DecoderContextAddress;
private long FrameDataAddress;
private long VpxCurrLumaAddress;
private long VpxRef0LumaAddress;
private long VpxRef1LumaAddress;
private long VpxRef2LumaAddress;
private long VpxCurrChromaAddress;
private long VpxRef0ChromaAddress;
private long VpxRef1ChromaAddress;
private long VpxRef2ChromaAddress;
private long VpxProbTablesAddress;
private long _decoderContextAddress;
private long _frameDataAddress;
private long _vpxCurrLumaAddress;
private long _vpxRef0LumaAddress;
private long _vpxRef1LumaAddress;
private long _vpxRef2LumaAddress;
private long _vpxCurrChromaAddress;
private long _vpxRef0ChromaAddress;
private long _vpxRef1ChromaAddress;
private long _vpxRef2ChromaAddress;
private long _vpxProbTablesAddress;
public VideoDecoder(NvGpu Gpu)
public VideoDecoder(NvGpu gpu)
{
this.Gpu = Gpu;
_gpu = gpu;
H264Decoder = new H264Decoder();
Vp9Decoder = new Vp9Decoder();
_h264Decoder = new H264Decoder();
_vp9Decoder = new Vp9Decoder();
}
public void Process(NvGpuVmm Vmm, int MethodOffset, int[] Arguments)
public void Process(NvGpuVmm vmm, int methodOffset, int[] arguments)
{
VideoDecoderMeth Method = (VideoDecoderMeth)MethodOffset;
VideoDecoderMeth method = (VideoDecoderMeth)methodOffset;
switch (Method)
switch (method)
{
case VideoDecoderMeth.SetVideoCodec: SetVideoCodec (Vmm, Arguments); break;
case VideoDecoderMeth.Execute: Execute (Vmm, Arguments); break;
case VideoDecoderMeth.SetDecoderCtxAddr: SetDecoderCtxAddr (Vmm, Arguments); break;
case VideoDecoderMeth.SetFrameDataAddr: SetFrameDataAddr (Vmm, Arguments); break;
case VideoDecoderMeth.SetVpxCurrLumaAddr: SetVpxCurrLumaAddr (Vmm, Arguments); break;
case VideoDecoderMeth.SetVpxRef0LumaAddr: SetVpxRef0LumaAddr (Vmm, Arguments); break;
case VideoDecoderMeth.SetVpxRef1LumaAddr: SetVpxRef1LumaAddr (Vmm, Arguments); break;
case VideoDecoderMeth.SetVpxRef2LumaAddr: SetVpxRef2LumaAddr (Vmm, Arguments); break;
case VideoDecoderMeth.SetVpxCurrChromaAddr: SetVpxCurrChromaAddr(Vmm, Arguments); break;
case VideoDecoderMeth.SetVpxRef0ChromaAddr: SetVpxRef0ChromaAddr(Vmm, Arguments); break;
case VideoDecoderMeth.SetVpxRef1ChromaAddr: SetVpxRef1ChromaAddr(Vmm, Arguments); break;
case VideoDecoderMeth.SetVpxRef2ChromaAddr: SetVpxRef2ChromaAddr(Vmm, Arguments); break;
case VideoDecoderMeth.SetVpxProbTablesAddr: SetVpxProbTablesAddr(Vmm, Arguments); break;
case VideoDecoderMeth.SetVideoCodec: SetVideoCodec (vmm, arguments); break;
case VideoDecoderMeth.Execute: Execute (vmm, arguments); break;
case VideoDecoderMeth.SetDecoderCtxAddr: SetDecoderCtxAddr (vmm, arguments); break;
case VideoDecoderMeth.SetFrameDataAddr: SetFrameDataAddr (vmm, arguments); break;
case VideoDecoderMeth.SetVpxCurrLumaAddr: SetVpxCurrLumaAddr (vmm, arguments); break;
case VideoDecoderMeth.SetVpxRef0LumaAddr: SetVpxRef0LumaAddr (vmm, arguments); break;
case VideoDecoderMeth.SetVpxRef1LumaAddr: SetVpxRef1LumaAddr (vmm, arguments); break;
case VideoDecoderMeth.SetVpxRef2LumaAddr: SetVpxRef2LumaAddr (vmm, arguments); break;
case VideoDecoderMeth.SetVpxCurrChromaAddr: SetVpxCurrChromaAddr(vmm, arguments); break;
case VideoDecoderMeth.SetVpxRef0ChromaAddr: SetVpxRef0ChromaAddr(vmm, arguments); break;
case VideoDecoderMeth.SetVpxRef1ChromaAddr: SetVpxRef1ChromaAddr(vmm, arguments); break;
case VideoDecoderMeth.SetVpxRef2ChromaAddr: SetVpxRef2ChromaAddr(vmm, arguments); break;
case VideoDecoderMeth.SetVpxProbTablesAddr: SetVpxProbTablesAddr(vmm, arguments); break;
}
}
private void SetVideoCodec(NvGpuVmm Vmm, int[] Arguments)
private void SetVideoCodec(NvGpuVmm vmm, int[] arguments)
{
CurrentVideoCodec = (VideoCodec)Arguments[0];
_currentVideoCodec = (VideoCodec)arguments[0];
}
private void Execute(NvGpuVmm Vmm, int[] Arguments)
private void Execute(NvGpuVmm vmm, int[] arguments)
{
if (CurrentVideoCodec == VideoCodec.H264)
if (_currentVideoCodec == VideoCodec.H264)
{
int FrameDataSize = Vmm.ReadInt32(DecoderContextAddress + 0x48);
int frameDataSize = vmm.ReadInt32(_decoderContextAddress + 0x48);
H264ParameterSets Params = MemoryHelper.Read<H264ParameterSets>(Vmm.Memory, Vmm.GetPhysicalAddress(DecoderContextAddress + 0x58));
H264ParameterSets Params = MemoryHelper.Read<H264ParameterSets>(vmm.Memory, vmm.GetPhysicalAddress(_decoderContextAddress + 0x58));
H264Matrices Matrices = new H264Matrices()
H264Matrices matrices = new H264Matrices()
{
ScalingMatrix4 = Vmm.ReadBytes(DecoderContextAddress + 0x1c0, 6 * 16),
ScalingMatrix8 = Vmm.ReadBytes(DecoderContextAddress + 0x220, 2 * 64)
ScalingMatrix4 = vmm.ReadBytes(_decoderContextAddress + 0x1c0, 6 * 16),
ScalingMatrix8 = vmm.ReadBytes(_decoderContextAddress + 0x220, 2 * 64)
};
byte[] FrameData = Vmm.ReadBytes(FrameDataAddress, FrameDataSize);
byte[] frameData = vmm.ReadBytes(_frameDataAddress, frameDataSize);
H264Decoder.Decode(Params, Matrices, FrameData);
_h264Decoder.Decode(Params, matrices, frameData);
}
else if (CurrentVideoCodec == VideoCodec.Vp9)
else if (_currentVideoCodec == VideoCodec.Vp9)
{
int FrameDataSize = Vmm.ReadInt32(DecoderContextAddress + 0x30);
int frameDataSize = vmm.ReadInt32(_decoderContextAddress + 0x30);
Vp9FrameKeys Keys = new Vp9FrameKeys()
Vp9FrameKeys keys = new Vp9FrameKeys()
{
CurrKey = Vmm.GetPhysicalAddress(VpxCurrLumaAddress),
Ref0Key = Vmm.GetPhysicalAddress(VpxRef0LumaAddress),
Ref1Key = Vmm.GetPhysicalAddress(VpxRef1LumaAddress),
Ref2Key = Vmm.GetPhysicalAddress(VpxRef2LumaAddress)
CurrKey = vmm.GetPhysicalAddress(_vpxCurrLumaAddress),
Ref0Key = vmm.GetPhysicalAddress(_vpxRef0LumaAddress),
Ref1Key = vmm.GetPhysicalAddress(_vpxRef1LumaAddress),
Ref2Key = vmm.GetPhysicalAddress(_vpxRef2LumaAddress)
};
Vp9FrameHeader Header = MemoryHelper.Read<Vp9FrameHeader>(Vmm.Memory, Vmm.GetPhysicalAddress(DecoderContextAddress + 0x48));
Vp9FrameHeader header = MemoryHelper.Read<Vp9FrameHeader>(vmm.Memory, vmm.GetPhysicalAddress(_decoderContextAddress + 0x48));
Vp9ProbabilityTables Probs = new Vp9ProbabilityTables()
Vp9ProbabilityTables probs = new Vp9ProbabilityTables()
{
SegmentationTreeProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x387, 0x7),
SegmentationPredProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x38e, 0x3),
Tx8x8Probs = Vmm.ReadBytes(VpxProbTablesAddress + 0x470, 0x2),
Tx16x16Probs = Vmm.ReadBytes(VpxProbTablesAddress + 0x472, 0x4),
Tx32x32Probs = Vmm.ReadBytes(VpxProbTablesAddress + 0x476, 0x6),
CoefProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x5a0, 0x900),
SkipProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x537, 0x3),
InterModeProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x400, 0x1c),
InterpFilterProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x52a, 0x8),
IsInterProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x41c, 0x4),
CompModeProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x532, 0x5),
SingleRefProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x580, 0xa),
CompRefProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x58a, 0x5),
YModeProbs0 = Vmm.ReadBytes(VpxProbTablesAddress + 0x480, 0x20),
YModeProbs1 = Vmm.ReadBytes(VpxProbTablesAddress + 0x47c, 0x4),
PartitionProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x4e0, 0x40),
MvJointProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x53b, 0x3),
MvSignProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x53e, 0x3),
MvClassProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x54c, 0x14),
MvClass0BitProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x540, 0x3),
MvBitsProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x56c, 0x14),
MvClass0FrProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x560, 0xc),
MvFrProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x542, 0x6),
MvClass0HpProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x548, 0x2),
MvHpProbs = Vmm.ReadBytes(VpxProbTablesAddress + 0x54a, 0x2)
SegmentationTreeProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x387, 0x7),
SegmentationPredProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x38e, 0x3),
Tx8x8Probs = vmm.ReadBytes(_vpxProbTablesAddress + 0x470, 0x2),
Tx16x16Probs = vmm.ReadBytes(_vpxProbTablesAddress + 0x472, 0x4),
Tx32x32Probs = vmm.ReadBytes(_vpxProbTablesAddress + 0x476, 0x6),
CoefProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x5a0, 0x900),
SkipProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x537, 0x3),
InterModeProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x400, 0x1c),
InterpFilterProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x52a, 0x8),
IsInterProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x41c, 0x4),
CompModeProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x532, 0x5),
SingleRefProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x580, 0xa),
CompRefProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x58a, 0x5),
YModeProbs0 = vmm.ReadBytes(_vpxProbTablesAddress + 0x480, 0x20),
YModeProbs1 = vmm.ReadBytes(_vpxProbTablesAddress + 0x47c, 0x4),
PartitionProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x4e0, 0x40),
MvJointProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x53b, 0x3),
MvSignProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x53e, 0x3),
MvClassProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x54c, 0x14),
MvClass0BitProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x540, 0x3),
MvBitsProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x56c, 0x14),
MvClass0FrProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x560, 0xc),
MvFrProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x542, 0x6),
MvClass0HpProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x548, 0x2),
MvHpProbs = vmm.ReadBytes(_vpxProbTablesAddress + 0x54a, 0x2)
};
byte[] FrameData = Vmm.ReadBytes(FrameDataAddress, FrameDataSize);
byte[] frameData = vmm.ReadBytes(_frameDataAddress, frameDataSize);
Vp9Decoder.Decode(Keys, Header, Probs, FrameData);
_vp9Decoder.Decode(keys, header, probs, frameData);
}
else
{
@ -134,148 +134,148 @@ namespace Ryujinx.Graphics.VDec
}
}
private void SetDecoderCtxAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetDecoderCtxAddr(NvGpuVmm vmm, int[] arguments)
{
DecoderContextAddress = GetAddress(Arguments);
_decoderContextAddress = GetAddress(arguments);
}
private void SetFrameDataAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetFrameDataAddr(NvGpuVmm vmm, int[] arguments)
{
FrameDataAddress = GetAddress(Arguments);
_frameDataAddress = GetAddress(arguments);
}
private void SetVpxCurrLumaAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetVpxCurrLumaAddr(NvGpuVmm vmm, int[] arguments)
{
VpxCurrLumaAddress = GetAddress(Arguments);
_vpxCurrLumaAddress = GetAddress(arguments);
}
private void SetVpxRef0LumaAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetVpxRef0LumaAddr(NvGpuVmm vmm, int[] arguments)
{
VpxRef0LumaAddress = GetAddress(Arguments);
_vpxRef0LumaAddress = GetAddress(arguments);
}
private void SetVpxRef1LumaAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetVpxRef1LumaAddr(NvGpuVmm vmm, int[] arguments)
{
VpxRef1LumaAddress = GetAddress(Arguments);
_vpxRef1LumaAddress = GetAddress(arguments);
}
private void SetVpxRef2LumaAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetVpxRef2LumaAddr(NvGpuVmm vmm, int[] arguments)
{
VpxRef2LumaAddress = GetAddress(Arguments);
_vpxRef2LumaAddress = GetAddress(arguments);
}
private void SetVpxCurrChromaAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetVpxCurrChromaAddr(NvGpuVmm vmm, int[] arguments)
{
VpxCurrChromaAddress = GetAddress(Arguments);
_vpxCurrChromaAddress = GetAddress(arguments);
}
private void SetVpxRef0ChromaAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetVpxRef0ChromaAddr(NvGpuVmm vmm, int[] arguments)
{
VpxRef0ChromaAddress = GetAddress(Arguments);
_vpxRef0ChromaAddress = GetAddress(arguments);
}
private void SetVpxRef1ChromaAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetVpxRef1ChromaAddr(NvGpuVmm vmm, int[] arguments)
{
VpxRef1ChromaAddress = GetAddress(Arguments);
_vpxRef1ChromaAddress = GetAddress(arguments);
}
private void SetVpxRef2ChromaAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetVpxRef2ChromaAddr(NvGpuVmm vmm, int[] arguments)
{
VpxRef2ChromaAddress = GetAddress(Arguments);
_vpxRef2ChromaAddress = GetAddress(arguments);
}
private void SetVpxProbTablesAddr(NvGpuVmm Vmm, int[] Arguments)
private void SetVpxProbTablesAddr(NvGpuVmm vmm, int[] arguments)
{
VpxProbTablesAddress = GetAddress(Arguments);
_vpxProbTablesAddress = GetAddress(arguments);
}
private static long GetAddress(int[] Arguments)
private static long GetAddress(int[] arguments)
{
return (long)(uint)Arguments[0] << 8;
return (long)(uint)arguments[0] << 8;
}
internal void CopyPlanes(NvGpuVmm Vmm, SurfaceOutputConfig OutputConfig)
internal void CopyPlanes(NvGpuVmm vmm, SurfaceOutputConfig outputConfig)
{
switch (OutputConfig.PixelFormat)
switch (outputConfig.PixelFormat)
{
case SurfacePixelFormat.RGBA8: CopyPlanesRgba8 (Vmm, OutputConfig); break;
case SurfacePixelFormat.YUV420P: CopyPlanesYuv420p(Vmm, OutputConfig); break;
case SurfacePixelFormat.RGBA8: CopyPlanesRgba8 (vmm, outputConfig); break;
case SurfacePixelFormat.YUV420P: CopyPlanesYuv420P(vmm, outputConfig); break;
default: ThrowUnimplementedPixelFormat(OutputConfig.PixelFormat); break;
default: ThrowUnimplementedPixelFormat(outputConfig.PixelFormat); break;
}
}
private void CopyPlanesRgba8(NvGpuVmm Vmm, SurfaceOutputConfig OutputConfig)
private void CopyPlanesRgba8(NvGpuVmm vmm, SurfaceOutputConfig outputConfig)
{
FFmpegFrame Frame = FFmpegWrapper.GetFrameRgba();
FFmpegFrame frame = FFmpegWrapper.GetFrameRgba();
if ((Frame.Width | Frame.Height) == 0)
if ((frame.Width | frame.Height) == 0)
{
return;
}
GalImage Image = new GalImage(
OutputConfig.SurfaceWidth,
OutputConfig.SurfaceHeight, 1, 1, 1,
OutputConfig.GobBlockHeight, 1,
GalImage image = new GalImage(
outputConfig.SurfaceWidth,
outputConfig.SurfaceHeight, 1, 1, 1,
outputConfig.GobBlockHeight, 1,
GalMemoryLayout.BlockLinear,
GalImageFormat.RGBA8 | GalImageFormat.Unorm,
GalTextureTarget.TwoD);
ImageUtils.WriteTexture(Vmm, Image, Vmm.GetPhysicalAddress(OutputConfig.SurfaceLumaAddress), Frame.Data);
ImageUtils.WriteTexture(vmm, image, vmm.GetPhysicalAddress(outputConfig.SurfaceLumaAddress), frame.Data);
}
private void CopyPlanesYuv420p(NvGpuVmm Vmm, SurfaceOutputConfig OutputConfig)
private void CopyPlanesYuv420P(NvGpuVmm vmm, SurfaceOutputConfig outputConfig)
{
FFmpegFrame Frame = FFmpegWrapper.GetFrame();
FFmpegFrame frame = FFmpegWrapper.GetFrame();
if ((Frame.Width | Frame.Height) == 0)
if ((frame.Width | frame.Height) == 0)
{
return;
}
int HalfSrcWidth = Frame.Width / 2;
int halfSrcWidth = frame.Width / 2;
int HalfWidth = Frame.Width / 2;
int HalfHeight = Frame.Height / 2;
int halfWidth = frame.Width / 2;
int halfHeight = frame.Height / 2;
int AlignedWidth = (OutputConfig.SurfaceWidth + 0xff) & ~0xff;
int alignedWidth = (outputConfig.SurfaceWidth + 0xff) & ~0xff;
for (int Y = 0; Y < Frame.Height; Y++)
for (int y = 0; y < frame.Height; y++)
{
int Src = Y * Frame.Width;
int Dst = Y * AlignedWidth;
int src = y * frame.Width;
int dst = y * alignedWidth;
int Size = Frame.Width;
int size = frame.Width;
for (int Offset = 0; Offset < Size; Offset++)
for (int offset = 0; offset < size; offset++)
{
Vmm.WriteByte(OutputConfig.SurfaceLumaAddress + Dst + Offset, *(Frame.LumaPtr + Src + Offset));
vmm.WriteByte(outputConfig.SurfaceLumaAddress + dst + offset, *(frame.LumaPtr + src + offset));
}
}
//Copy chroma data from both channels with interleaving.
for (int Y = 0; Y < HalfHeight; Y++)
for (int y = 0; y < halfHeight; y++)
{
int Src = Y * HalfSrcWidth;
int Dst = Y * AlignedWidth;
int src = y * halfSrcWidth;
int dst = y * alignedWidth;
for (int X = 0; X < HalfWidth; X++)
for (int x = 0; x < halfWidth; x++)
{
Vmm.WriteByte(OutputConfig.SurfaceChromaUAddress + Dst + X * 2 + 0, *(Frame.ChromaBPtr + Src + X));
Vmm.WriteByte(OutputConfig.SurfaceChromaUAddress + Dst + X * 2 + 1, *(Frame.ChromaRPtr + Src + X));
vmm.WriteByte(outputConfig.SurfaceChromaUAddress + dst + x * 2 + 0, *(frame.ChromaBPtr + src + x));
vmm.WriteByte(outputConfig.SurfaceChromaUAddress + dst + x * 2 + 1, *(frame.ChromaRPtr + src + x));
}
}
}
private void ThrowUnimplementedCodec()
{
throw new NotImplementedException("Codec \"" + CurrentVideoCodec + "\" is not supported!");
throw new NotImplementedException("Codec \"" + _currentVideoCodec + "\" is not supported!");
}
private void ThrowUnimplementedPixelFormat(SurfacePixelFormat PixelFormat)
private void ThrowUnimplementedPixelFormat(SurfacePixelFormat pixelFormat)
{
throw new NotImplementedException("Pixel format \"" + PixelFormat + "\" is not supported!");
throw new NotImplementedException("Pixel format \"" + pixelFormat + "\" is not supported!");
}
}
}

View file

@ -33,7 +33,7 @@ namespace Ryujinx.Graphics.VDec
private byte[] DefaultTx16x16Probs = new byte[] { 20, 152, 15, 101 };
private byte[] DefaultTx32x32Probs = new byte[] { 3, 136, 37, 5, 52, 13 };
private byte[] DefaultCoefProbs = new byte[]
private byte[] _defaultCoefProbs = new byte[]
{
195, 29, 183, 0, 84, 49, 136, 0, 8, 42, 71, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 31, 107, 169, 0, 35, 99, 159, 0,
@ -181,39 +181,39 @@ namespace Ryujinx.Graphics.VDec
1, 115, 166, 0, 1, 84, 121, 0, 1, 51, 67, 0, 1, 16, 6, 0
};
private byte[] DefaultSkipProbs = new byte[] { 192, 128, 64 };
private byte[] _defaultSkipProbs = new byte[] { 192, 128, 64 };
private byte[] DefaultInterModeProbs = new byte[]
private byte[] _defaultInterModeProbs = new byte[]
{
2, 173, 34, 0, 7, 145, 85, 0, 7, 166, 63, 0, 7, 94, 66, 0,
8, 64, 46, 0, 17, 81, 31, 0, 25, 29, 30, 0
};
private byte[] DefaultInterpFilterProbs = new byte[]
private byte[] _defaultInterpFilterProbs = new byte[]
{
235, 162, 36, 255, 34, 3, 149, 144
};
private byte[] DefaultIsInterProbs = new byte[] { 9, 102, 187, 225 };
private byte[] _defaultIsInterProbs = new byte[] { 9, 102, 187, 225 };
private byte[] DefaultCompModeProbs = new byte[] { 239, 183, 119, 96, 41 };
private byte[] _defaultCompModeProbs = new byte[] { 239, 183, 119, 96, 41 };
private byte[] DefaultSingleRefProbs = new byte[]
private byte[] _defaultSingleRefProbs = new byte[]
{
33, 16, 77, 74, 142, 142, 172, 170, 238, 247
};
private byte[] DefaultCompRefProbs = new byte[] { 50, 126, 123, 221, 226 };
private byte[] _defaultCompRefProbs = new byte[] { 50, 126, 123, 221, 226 };
private byte[] DefaultYModeProbs0 = new byte[]
private byte[] _defaultYModeProbs0 = new byte[]
{
65, 32, 18, 144, 162, 194, 41, 51, 132, 68, 18, 165, 217, 196, 45, 40,
173, 80, 19, 176, 240, 193, 64, 35, 221, 135, 38, 194, 248, 121, 96, 85
};
private byte[] DefaultYModeProbs1 = new byte[] { 98, 78, 46, 29 };
private byte[] _defaultYModeProbs1 = new byte[] { 98, 78, 46, 29 };
private byte[] DefaultPartitionProbs = new byte[]
private byte[] _defaultPartitionProbs = new byte[]
{
199, 122, 141, 0, 147, 63, 159, 0, 148, 133, 118, 0, 121, 104, 114, 0,
174, 73, 87, 0, 92, 41, 83, 0, 82, 99, 50, 0, 53, 39, 39, 0,
@ -221,184 +221,184 @@ namespace Ryujinx.Graphics.VDec
222, 34, 30, 0, 72, 16, 44, 0, 58, 32, 12, 0, 10, 7, 6, 0
};
private byte[] DefaultMvJointProbs = new byte[] { 32, 64, 96 };
private byte[] _defaultMvJointProbs = new byte[] { 32, 64, 96 };
private byte[] DefaultMvSignProbs = new byte[] { 128, 128 };
private byte[] _defaultMvSignProbs = new byte[] { 128, 128 };
private byte[] DefaultMvClassProbs = new byte[]
private byte[] _defaultMvClassProbs = new byte[]
{
224, 144, 192, 168, 192, 176, 192, 198, 198, 245, 216, 128, 176, 160, 176, 176,
192, 198, 198, 208
};
private byte[] DefaultMvClass0BitProbs = new byte[] { 216, 208 };
private byte[] _defaultMvClass0BitProbs = new byte[] { 216, 208 };
private byte[] DefaultMvBitsProbs = new byte[]
private byte[] _defaultMvBitsProbs = new byte[]
{
136, 140, 148, 160, 176, 192, 224, 234, 234, 240, 136, 140, 148, 160, 176, 192,
224, 234, 234, 240
};
private byte[] DefaultMvClass0FrProbs = new byte[]
private byte[] _defaultMvClass0FrProbs = new byte[]
{
128, 128, 64, 96, 112, 64, 128, 128, 64, 96, 112, 64
};
private byte[] DefaultMvFrProbs = new byte[] { 64, 96, 64, 64, 96, 64 };
private byte[] _defaultMvFrProbs = new byte[] { 64, 96, 64, 64, 96, 64 };
private byte[] DefaultMvClass0HpProbs = new byte[] { 160, 160 };
private byte[] _defaultMvClass0HpProbs = new byte[] { 160, 160 };
private byte[] DefaultMvHpProbs = new byte[] { 128, 128 };
private byte[] _defaultMvHpProbs = new byte[] { 128, 128 };
private sbyte[] LoopFilterRefDeltas;
private sbyte[] LoopFilterModeDeltas;
private sbyte[] _loopFilterRefDeltas;
private sbyte[] _loopFilterModeDeltas;
private LinkedList<int> FrameSlotByLastUse;
private LinkedList<int> _frameSlotByLastUse;
private Dictionary<long, LinkedListNode<int>> CachedRefFrames;
private Dictionary<long, LinkedListNode<int>> _cachedRefFrames;
public Vp9Decoder()
{
LoopFilterRefDeltas = new sbyte[4];
LoopFilterModeDeltas = new sbyte[2];
_loopFilterRefDeltas = new sbyte[4];
_loopFilterModeDeltas = new sbyte[2];
FrameSlotByLastUse = new LinkedList<int>();
_frameSlotByLastUse = new LinkedList<int>();
for (int Slot = 0; Slot < 8; Slot++)
for (int slot = 0; slot < 8; slot++)
{
FrameSlotByLastUse.AddFirst(Slot);
_frameSlotByLastUse.AddFirst(slot);
}
CachedRefFrames = new Dictionary<long, LinkedListNode<int>>();
_cachedRefFrames = new Dictionary<long, LinkedListNode<int>>();
}
public void Decode(
Vp9FrameKeys Keys,
Vp9FrameHeader Header,
Vp9ProbabilityTables Probs,
byte[] FrameData)
Vp9FrameKeys keys,
Vp9FrameHeader header,
Vp9ProbabilityTables probs,
byte[] frameData)
{
bool IsKeyFrame = ((Header.Flags >> 0) & 1) != 0;
bool LastIsKeyFrame = ((Header.Flags >> 1) & 1) != 0;
bool FrameSizeChanged = ((Header.Flags >> 2) & 1) != 0;
bool ErrorResilientMode = ((Header.Flags >> 3) & 1) != 0;
bool LastShowFrame = ((Header.Flags >> 4) & 1) != 0;
bool IsFrameIntra = ((Header.Flags >> 5) & 1) != 0;
bool isKeyFrame = ((header.Flags >> 0) & 1) != 0;
bool lastIsKeyFrame = ((header.Flags >> 1) & 1) != 0;
bool frameSizeChanged = ((header.Flags >> 2) & 1) != 0;
bool errorResilientMode = ((header.Flags >> 3) & 1) != 0;
bool lastShowFrame = ((header.Flags >> 4) & 1) != 0;
bool isFrameIntra = ((header.Flags >> 5) & 1) != 0;
bool ShowFrame = !IsFrameIntra;
bool showFrame = !isFrameIntra;
//Write compressed header.
byte[] CompressedHeaderData;
byte[] compressedHeaderData;
using (MemoryStream CompressedHeader = new MemoryStream())
using (MemoryStream compressedHeader = new MemoryStream())
{
VpxRangeEncoder Writer = new VpxRangeEncoder(CompressedHeader);
VpxRangeEncoder writer = new VpxRangeEncoder(compressedHeader);
if (!Header.Lossless)
if (!header.Lossless)
{
if ((uint)Header.TxMode >= 3)
if ((uint)header.TxMode >= 3)
{
Writer.Write(3, 2);
Writer.Write(Header.TxMode == 4);
writer.Write(3, 2);
writer.Write(header.TxMode == 4);
}
else
{
Writer.Write(Header.TxMode, 2);
writer.Write(header.TxMode, 2);
}
}
if (Header.TxMode == 4)
if (header.TxMode == 4)
{
WriteProbabilityUpdate(Writer, Probs.Tx8x8Probs, DefaultTx8x8Probs);
WriteProbabilityUpdate(Writer, Probs.Tx16x16Probs, DefaultTx16x16Probs);
WriteProbabilityUpdate(Writer, Probs.Tx32x32Probs, DefaultTx32x32Probs);
WriteProbabilityUpdate(writer, probs.Tx8x8Probs, DefaultTx8x8Probs);
WriteProbabilityUpdate(writer, probs.Tx16x16Probs, DefaultTx16x16Probs);
WriteProbabilityUpdate(writer, probs.Tx32x32Probs, DefaultTx32x32Probs);
}
WriteCoefProbabilityUpdate(Writer, Header.TxMode, Probs.CoefProbs, DefaultCoefProbs);
WriteCoefProbabilityUpdate(writer, header.TxMode, probs.CoefProbs, _defaultCoefProbs);
WriteProbabilityUpdate(Writer, Probs.SkipProbs, DefaultSkipProbs);
WriteProbabilityUpdate(writer, probs.SkipProbs, _defaultSkipProbs);
if (!IsFrameIntra)
if (!isFrameIntra)
{
WriteProbabilityUpdateAligned4(Writer, Probs.InterModeProbs, DefaultInterModeProbs);
WriteProbabilityUpdateAligned4(writer, probs.InterModeProbs, _defaultInterModeProbs);
if (Header.RawInterpolationFilter == 4)
if (header.RawInterpolationFilter == 4)
{
WriteProbabilityUpdate(Writer, Probs.InterpFilterProbs, DefaultInterpFilterProbs);
WriteProbabilityUpdate(writer, probs.InterpFilterProbs, _defaultInterpFilterProbs);
}
WriteProbabilityUpdate(Writer, Probs.IsInterProbs, DefaultIsInterProbs);
WriteProbabilityUpdate(writer, probs.IsInterProbs, _defaultIsInterProbs);
if ((Header.RefFrameSignBias[1] & 1) != (Header.RefFrameSignBias[2] & 1) ||
(Header.RefFrameSignBias[1] & 1) != (Header.RefFrameSignBias[3] & 1))
if ((header.RefFrameSignBias[1] & 1) != (header.RefFrameSignBias[2] & 1) ||
(header.RefFrameSignBias[1] & 1) != (header.RefFrameSignBias[3] & 1))
{
if ((uint)Header.CompPredMode >= 1)
if ((uint)header.CompPredMode >= 1)
{
Writer.Write(1, 1);
Writer.Write(Header.CompPredMode == 2);
writer.Write(1, 1);
writer.Write(header.CompPredMode == 2);
}
else
{
Writer.Write(0, 1);
writer.Write(0, 1);
}
}
if (Header.CompPredMode == 2)
if (header.CompPredMode == 2)
{
WriteProbabilityUpdate(Writer, Probs.CompModeProbs, DefaultCompModeProbs);
WriteProbabilityUpdate(writer, probs.CompModeProbs, _defaultCompModeProbs);
}
if (Header.CompPredMode != 1)
if (header.CompPredMode != 1)
{
WriteProbabilityUpdate(Writer, Probs.SingleRefProbs, DefaultSingleRefProbs);
WriteProbabilityUpdate(writer, probs.SingleRefProbs, _defaultSingleRefProbs);
}
if (Header.CompPredMode != 0)
if (header.CompPredMode != 0)
{
WriteProbabilityUpdate(Writer, Probs.CompRefProbs, DefaultCompRefProbs);
WriteProbabilityUpdate(writer, probs.CompRefProbs, _defaultCompRefProbs);
}
for (int Index = 0; Index < 4; Index++)
for (int index = 0; index < 4; index++)
{
int i = Index * 8;
int j = Index;
int i = index * 8;
int j = index;
WriteProbabilityUpdate(Writer, Probs.YModeProbs0[i + 0], DefaultYModeProbs0[i + 0]);
WriteProbabilityUpdate(Writer, Probs.YModeProbs0[i + 1], DefaultYModeProbs0[i + 1]);
WriteProbabilityUpdate(Writer, Probs.YModeProbs0[i + 2], DefaultYModeProbs0[i + 2]);
WriteProbabilityUpdate(Writer, Probs.YModeProbs0[i + 3], DefaultYModeProbs0[i + 3]);
WriteProbabilityUpdate(Writer, Probs.YModeProbs0[i + 4], DefaultYModeProbs0[i + 4]);
WriteProbabilityUpdate(Writer, Probs.YModeProbs0[i + 5], DefaultYModeProbs0[i + 5]);
WriteProbabilityUpdate(Writer, Probs.YModeProbs0[i + 6], DefaultYModeProbs0[i + 6]);
WriteProbabilityUpdate(Writer, Probs.YModeProbs0[i + 7], DefaultYModeProbs0[i + 7]);
WriteProbabilityUpdate(Writer, Probs.YModeProbs1[j + 0], DefaultYModeProbs1[j + 0]);
WriteProbabilityUpdate(writer, probs.YModeProbs0[i + 0], _defaultYModeProbs0[i + 0]);
WriteProbabilityUpdate(writer, probs.YModeProbs0[i + 1], _defaultYModeProbs0[i + 1]);
WriteProbabilityUpdate(writer, probs.YModeProbs0[i + 2], _defaultYModeProbs0[i + 2]);
WriteProbabilityUpdate(writer, probs.YModeProbs0[i + 3], _defaultYModeProbs0[i + 3]);
WriteProbabilityUpdate(writer, probs.YModeProbs0[i + 4], _defaultYModeProbs0[i + 4]);
WriteProbabilityUpdate(writer, probs.YModeProbs0[i + 5], _defaultYModeProbs0[i + 5]);
WriteProbabilityUpdate(writer, probs.YModeProbs0[i + 6], _defaultYModeProbs0[i + 6]);
WriteProbabilityUpdate(writer, probs.YModeProbs0[i + 7], _defaultYModeProbs0[i + 7]);
WriteProbabilityUpdate(writer, probs.YModeProbs1[j + 0], _defaultYModeProbs1[j + 0]);
}
WriteProbabilityUpdateAligned4(Writer, Probs.PartitionProbs, DefaultPartitionProbs);
WriteProbabilityUpdateAligned4(writer, probs.PartitionProbs, _defaultPartitionProbs);
for (int i = 0; i < 3; i++)
{
WriteMvProbabilityUpdate(Writer, Probs.MvJointProbs[i], DefaultMvJointProbs[i]);
WriteMvProbabilityUpdate(writer, probs.MvJointProbs[i], _defaultMvJointProbs[i]);
}
for (int i = 0; i < 2; i++)
{
WriteMvProbabilityUpdate(Writer, Probs.MvSignProbs[i], DefaultMvSignProbs[i]);
WriteMvProbabilityUpdate(writer, probs.MvSignProbs[i], _defaultMvSignProbs[i]);
for (int j = 0; j < 10; j++)
{
int Index = i * 10 + j;
int index = i * 10 + j;
WriteMvProbabilityUpdate(Writer, Probs.MvClassProbs[Index], DefaultMvClassProbs[Index]);
WriteMvProbabilityUpdate(writer, probs.MvClassProbs[index], _defaultMvClassProbs[index]);
}
WriteMvProbabilityUpdate(Writer, Probs.MvClass0BitProbs[i], DefaultMvClass0BitProbs[i]);
WriteMvProbabilityUpdate(writer, probs.MvClass0BitProbs[i], _defaultMvClass0BitProbs[i]);
for (int j = 0; j < 10; j++)
{
int Index = i * 10 + j;
int index = i * 10 + j;
WriteMvProbabilityUpdate(Writer, Probs.MvBitsProbs[Index], DefaultMvBitsProbs[Index]);
WriteMvProbabilityUpdate(writer, probs.MvBitsProbs[index], _defaultMvBitsProbs[index]);
}
}
@ -408,249 +408,249 @@ namespace Ryujinx.Graphics.VDec
{
for (int k = 0; k < 3; k++)
{
int Index = i * 2 * 3 + j * 3 + k;
int index = i * 2 * 3 + j * 3 + k;
WriteMvProbabilityUpdate(Writer, Probs.MvClass0FrProbs[Index], DefaultMvClass0FrProbs[Index]);
WriteMvProbabilityUpdate(writer, probs.MvClass0FrProbs[index], _defaultMvClass0FrProbs[index]);
}
}
for (int j = 0; j < 3; j++)
{
int Index = i * 3 + j;
int index = i * 3 + j;
WriteMvProbabilityUpdate(Writer, Probs.MvFrProbs[Index], DefaultMvFrProbs[Index]);
WriteMvProbabilityUpdate(writer, probs.MvFrProbs[index], _defaultMvFrProbs[index]);
}
}
if (Header.AllowHighPrecisionMv)
if (header.AllowHighPrecisionMv)
{
for (int Index = 0; Index < 2; Index++)
for (int index = 0; index < 2; index++)
{
WriteMvProbabilityUpdate(Writer, Probs.MvClass0HpProbs[Index], DefaultMvClass0HpProbs[Index]);
WriteMvProbabilityUpdate(Writer, Probs.MvHpProbs[Index], DefaultMvHpProbs[Index]);
WriteMvProbabilityUpdate(writer, probs.MvClass0HpProbs[index], _defaultMvClass0HpProbs[index]);
WriteMvProbabilityUpdate(writer, probs.MvHpProbs[index], _defaultMvHpProbs[index]);
}
}
}
Writer.End();
writer.End();
CompressedHeaderData = CompressedHeader.ToArray();
compressedHeaderData = compressedHeader.ToArray();
}
//Write uncompressed header.
using (MemoryStream EncodedHeader = new MemoryStream())
using (MemoryStream encodedHeader = new MemoryStream())
{
VpxBitStreamWriter Writer = new VpxBitStreamWriter(EncodedHeader);
VpxBitStreamWriter writer = new VpxBitStreamWriter(encodedHeader);
Writer.WriteU(2, 2); //Frame marker.
Writer.WriteU(0, 2); //Profile.
Writer.WriteBit(false); //Show existing frame.
Writer.WriteBit(!IsKeyFrame);
Writer.WriteBit(ShowFrame);
Writer.WriteBit(ErrorResilientMode);
writer.WriteU(2, 2); //Frame marker.
writer.WriteU(0, 2); //Profile.
writer.WriteBit(false); //Show existing frame.
writer.WriteBit(!isKeyFrame);
writer.WriteBit(showFrame);
writer.WriteBit(errorResilientMode);
if (IsKeyFrame)
if (isKeyFrame)
{
Writer.WriteU(FrameSyncCode, 24);
Writer.WriteU(0, 3); //Color space.
Writer.WriteU(0, 1); //Color range.
Writer.WriteU(Header.CurrentFrame.Width - 1, 16);
Writer.WriteU(Header.CurrentFrame.Height - 1, 16);
Writer.WriteBit(false); //Render and frame size different.
writer.WriteU(FrameSyncCode, 24);
writer.WriteU(0, 3); //Color space.
writer.WriteU(0, 1); //Color range.
writer.WriteU(header.CurrentFrame.Width - 1, 16);
writer.WriteU(header.CurrentFrame.Height - 1, 16);
writer.WriteBit(false); //Render and frame size different.
CachedRefFrames.Clear();
_cachedRefFrames.Clear();
//On key frames, all frame slots are set to the current frame,
//so the value of the selected slot doesn't really matter.
GetNewFrameSlot(Keys.CurrKey);
GetNewFrameSlot(keys.CurrKey);
}
else
{
if (!ShowFrame)
if (!showFrame)
{
Writer.WriteBit(IsFrameIntra);
writer.WriteBit(isFrameIntra);
}
if (!ErrorResilientMode)
if (!errorResilientMode)
{
Writer.WriteU(0, 2); //Reset frame context.
writer.WriteU(0, 2); //Reset frame context.
}
int RefreshFrameFlags = 1 << GetNewFrameSlot(Keys.CurrKey);
int refreshFrameFlags = 1 << GetNewFrameSlot(keys.CurrKey);
if (IsFrameIntra)
if (isFrameIntra)
{
Writer.WriteU(FrameSyncCode, 24);
Writer.WriteU(RefreshFrameFlags, 8);
Writer.WriteU(Header.CurrentFrame.Width - 1, 16);
Writer.WriteU(Header.CurrentFrame.Height - 1, 16);
Writer.WriteBit(false); //Render and frame size different.
writer.WriteU(FrameSyncCode, 24);
writer.WriteU(refreshFrameFlags, 8);
writer.WriteU(header.CurrentFrame.Width - 1, 16);
writer.WriteU(header.CurrentFrame.Height - 1, 16);
writer.WriteBit(false); //Render and frame size different.
}
else
{
Writer.WriteU(RefreshFrameFlags, 8);
writer.WriteU(refreshFrameFlags, 8);
int[] RefFrameIndex = new int[]
int[] refFrameIndex = new int[]
{
GetFrameSlot(Keys.Ref0Key),
GetFrameSlot(Keys.Ref1Key),
GetFrameSlot(Keys.Ref2Key)
GetFrameSlot(keys.Ref0Key),
GetFrameSlot(keys.Ref1Key),
GetFrameSlot(keys.Ref2Key)
};
byte[] RefFrameSignBias = Header.RefFrameSignBias;
byte[] refFrameSignBias = header.RefFrameSignBias;
for (int Index = 1; Index < 4; Index++)
for (int index = 1; index < 4; index++)
{
Writer.WriteU(RefFrameIndex[Index - 1], 3);
Writer.WriteU(RefFrameSignBias[Index], 1);
writer.WriteU(refFrameIndex[index - 1], 3);
writer.WriteU(refFrameSignBias[index], 1);
}
Writer.WriteBit(true); //Frame size with refs.
Writer.WriteBit(false); //Render and frame size different.
Writer.WriteBit(Header.AllowHighPrecisionMv);
Writer.WriteBit(Header.RawInterpolationFilter == 4);
writer.WriteBit(true); //Frame size with refs.
writer.WriteBit(false); //Render and frame size different.
writer.WriteBit(header.AllowHighPrecisionMv);
writer.WriteBit(header.RawInterpolationFilter == 4);
if (Header.RawInterpolationFilter != 4)
if (header.RawInterpolationFilter != 4)
{
Writer.WriteU(Header.RawInterpolationFilter, 2);
writer.WriteU(header.RawInterpolationFilter, 2);
}
}
}
if (!ErrorResilientMode)
if (!errorResilientMode)
{
Writer.WriteBit(false); //Refresh frame context.
Writer.WriteBit(true); //Frame parallel decoding mode.
writer.WriteBit(false); //Refresh frame context.
writer.WriteBit(true); //Frame parallel decoding mode.
}
Writer.WriteU(0, 2); //Frame context index.
writer.WriteU(0, 2); //Frame context index.
Writer.WriteU(Header.LoopFilterLevel, 6);
Writer.WriteU(Header.LoopFilterSharpness, 3);
Writer.WriteBit(Header.LoopFilterDeltaEnabled);
writer.WriteU(header.LoopFilterLevel, 6);
writer.WriteU(header.LoopFilterSharpness, 3);
writer.WriteBit(header.LoopFilterDeltaEnabled);
if (Header.LoopFilterDeltaEnabled)
if (header.LoopFilterDeltaEnabled)
{
bool[] UpdateLoopFilterRefDeltas = new bool[4];
bool[] UpdateLoopFilterModeDeltas = new bool[2];
bool[] updateLoopFilterRefDeltas = new bool[4];
bool[] updateLoopFilterModeDeltas = new bool[2];
bool LoopFilterDeltaUpdate = false;
bool loopFilterDeltaUpdate = false;
for (int Index = 0; Index < Header.LoopFilterRefDeltas.Length; Index++)
for (int index = 0; index < header.LoopFilterRefDeltas.Length; index++)
{
sbyte Old = LoopFilterRefDeltas[Index];
sbyte New = Header.LoopFilterRefDeltas[Index];
sbyte old = _loopFilterRefDeltas[index];
sbyte New = header.LoopFilterRefDeltas[index];
LoopFilterDeltaUpdate |= (UpdateLoopFilterRefDeltas[Index] = Old != New);
loopFilterDeltaUpdate |= (updateLoopFilterRefDeltas[index] = old != New);
}
for (int Index = 0; Index < Header.LoopFilterModeDeltas.Length; Index++)
for (int index = 0; index < header.LoopFilterModeDeltas.Length; index++)
{
sbyte Old = LoopFilterModeDeltas[Index];
sbyte New = Header.LoopFilterModeDeltas[Index];
sbyte old = _loopFilterModeDeltas[index];
sbyte New = header.LoopFilterModeDeltas[index];
LoopFilterDeltaUpdate |= (UpdateLoopFilterModeDeltas[Index] = Old != New);
loopFilterDeltaUpdate |= (updateLoopFilterModeDeltas[index] = old != New);
}
Writer.WriteBit(LoopFilterDeltaUpdate);
writer.WriteBit(loopFilterDeltaUpdate);
if (LoopFilterDeltaUpdate)
if (loopFilterDeltaUpdate)
{
for (int Index = 0; Index < Header.LoopFilterRefDeltas.Length; Index++)
for (int index = 0; index < header.LoopFilterRefDeltas.Length; index++)
{
Writer.WriteBit(UpdateLoopFilterRefDeltas[Index]);
writer.WriteBit(updateLoopFilterRefDeltas[index]);
if (UpdateLoopFilterRefDeltas[Index])
if (updateLoopFilterRefDeltas[index])
{
Writer.WriteS(Header.LoopFilterRefDeltas[Index], 6);
writer.WriteS(header.LoopFilterRefDeltas[index], 6);
}
}
for (int Index = 0; Index < Header.LoopFilterModeDeltas.Length; Index++)
for (int index = 0; index < header.LoopFilterModeDeltas.Length; index++)
{
Writer.WriteBit(UpdateLoopFilterModeDeltas[Index]);
writer.WriteBit(updateLoopFilterModeDeltas[index]);
if (UpdateLoopFilterModeDeltas[Index])
if (updateLoopFilterModeDeltas[index])
{
Writer.WriteS(Header.LoopFilterModeDeltas[Index], 6);
writer.WriteS(header.LoopFilterModeDeltas[index], 6);
}
}
}
}
Writer.WriteU(Header.BaseQIndex, 8);
writer.WriteU(header.BaseQIndex, 8);
Writer.WriteDeltaQ(Header.DeltaQYDc);
Writer.WriteDeltaQ(Header.DeltaQUvDc);
Writer.WriteDeltaQ(Header.DeltaQUvAc);
writer.WriteDeltaQ(header.DeltaQYDc);
writer.WriteDeltaQ(header.DeltaQUvDc);
writer.WriteDeltaQ(header.DeltaQUvAc);
Writer.WriteBit(false); //Segmentation enabled (TODO).
writer.WriteBit(false); //Segmentation enabled (TODO).
int MinTileColsLog2 = CalcMinLog2TileCols(Header.CurrentFrame.Width);
int MaxTileColsLog2 = CalcMaxLog2TileCols(Header.CurrentFrame.Width);
int minTileColsLog2 = CalcMinLog2TileCols(header.CurrentFrame.Width);
int maxTileColsLog2 = CalcMaxLog2TileCols(header.CurrentFrame.Width);
int TileColsLog2Diff = Header.TileColsLog2 - MinTileColsLog2;
int tileColsLog2Diff = header.TileColsLog2 - minTileColsLog2;
int TileColsLog2IncMask = (1 << TileColsLog2Diff) - 1;
int tileColsLog2IncMask = (1 << tileColsLog2Diff) - 1;
//If it's less than the maximum, we need to add an extra 0 on the bitstream
//to indicate that it should stop reading.
if (Header.TileColsLog2 < MaxTileColsLog2)
if (header.TileColsLog2 < maxTileColsLog2)
{
Writer.WriteU(TileColsLog2IncMask << 1, TileColsLog2Diff + 1);
writer.WriteU(tileColsLog2IncMask << 1, tileColsLog2Diff + 1);
}
else
{
Writer.WriteU(TileColsLog2IncMask, TileColsLog2Diff);
writer.WriteU(tileColsLog2IncMask, tileColsLog2Diff);
}
bool TileRowsLog2IsNonZero = Header.TileRowsLog2 != 0;
bool tileRowsLog2IsNonZero = header.TileRowsLog2 != 0;
Writer.WriteBit(TileRowsLog2IsNonZero);
writer.WriteBit(tileRowsLog2IsNonZero);
if (TileRowsLog2IsNonZero)
if (tileRowsLog2IsNonZero)
{
Writer.WriteBit(Header.TileRowsLog2 > 1);
writer.WriteBit(header.TileRowsLog2 > 1);
}
Writer.WriteU(CompressedHeaderData.Length, 16);
writer.WriteU(compressedHeaderData.Length, 16);
Writer.Flush();
writer.Flush();
EncodedHeader.Write(CompressedHeaderData, 0, CompressedHeaderData.Length);
encodedHeader.Write(compressedHeaderData, 0, compressedHeaderData.Length);
if (!FFmpegWrapper.IsInitialized)
{
FFmpegWrapper.Vp9Initialize();
}
FFmpegWrapper.DecodeFrame(DecoderHelper.Combine(EncodedHeader.ToArray(), FrameData));
FFmpegWrapper.DecodeFrame(DecoderHelper.Combine(encodedHeader.ToArray(), frameData));
}
LoopFilterRefDeltas = Header.LoopFilterRefDeltas;
LoopFilterModeDeltas = Header.LoopFilterModeDeltas;
_loopFilterRefDeltas = header.LoopFilterRefDeltas;
_loopFilterModeDeltas = header.LoopFilterModeDeltas;
}
private int GetNewFrameSlot(long Key)
private int GetNewFrameSlot(long key)
{
LinkedListNode<int> Node = FrameSlotByLastUse.Last;
LinkedListNode<int> node = _frameSlotByLastUse.Last;
FrameSlotByLastUse.RemoveLast();
FrameSlotByLastUse.AddFirst(Node);
_frameSlotByLastUse.RemoveLast();
_frameSlotByLastUse.AddFirst(node);
CachedRefFrames[Key] = Node;
_cachedRefFrames[key] = node;
return Node.Value;
return node.Value;
}
private int GetFrameSlot(long Key)
private int GetFrameSlot(long key)
{
if (CachedRefFrames.TryGetValue(Key, out LinkedListNode<int> Node))
if (_cachedRefFrames.TryGetValue(key, out LinkedListNode<int> node))
{
FrameSlotByLastUse.Remove(Node);
FrameSlotByLastUse.AddFirst(Node);
_frameSlotByLastUse.Remove(node);
_frameSlotByLastUse.AddFirst(node);
return Node.Value;
return node.Value;
}
//Reference frame was lost.
@ -658,53 +658,53 @@ namespace Ryujinx.Graphics.VDec
return 0;
}
private void WriteProbabilityUpdate(VpxRangeEncoder Writer, byte[] New, byte[] Old)
private void WriteProbabilityUpdate(VpxRangeEncoder writer, byte[] New, byte[] old)
{
for (int Offset = 0; Offset < New.Length; Offset++)
for (int offset = 0; offset < New.Length; offset++)
{
WriteProbabilityUpdate(Writer, New[Offset], Old[Offset]);
WriteProbabilityUpdate(writer, New[offset], old[offset]);
}
}
private void WriteCoefProbabilityUpdate(VpxRangeEncoder Writer, int TxMode, byte[] New, byte[] Old)
private void WriteCoefProbabilityUpdate(VpxRangeEncoder writer, int txMode, byte[] New, byte[] old)
{
//Note: There's 1 byte added on each packet for alignment,
//this byte is ignored when doing updates.
const int BlockBytes = 2 * 2 * 6 * 6 * 4;
const int blockBytes = 2 * 2 * 6 * 6 * 4;
bool NeedsUpdate(int BaseIndex)
bool NeedsUpdate(int baseIndex)
{
int Index = BaseIndex;
int index = baseIndex;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 6; k++)
for (int l = 0; l < 6; l++)
{
if (New[Index + 0] != Old[Index + 0] ||
New[Index + 1] != Old[Index + 1] ||
New[Index + 2] != Old[Index + 2])
if (New[index + 0] != old[index + 0] ||
New[index + 1] != old[index + 1] ||
New[index + 2] != old[index + 2])
{
return true;
}
Index += 4;
index += 4;
}
return false;
}
for (int BlockIndex = 0; BlockIndex < 4; BlockIndex++)
for (int blockIndex = 0; blockIndex < 4; blockIndex++)
{
int BaseIndex = BlockIndex * BlockBytes;
int baseIndex = blockIndex * blockBytes;
bool Update = NeedsUpdate(BaseIndex);
bool update = NeedsUpdate(baseIndex);
Writer.Write(Update);
writer.Write(update);
if (Update)
if (update)
{
int Index = BaseIndex;
int index = baseIndex;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
@ -713,167 +713,167 @@ namespace Ryujinx.Graphics.VDec
{
if (k != 0 || l < 3)
{
WriteProbabilityUpdate(Writer, New[Index + 0], Old[Index + 0]);
WriteProbabilityUpdate(Writer, New[Index + 1], Old[Index + 1]);
WriteProbabilityUpdate(Writer, New[Index + 2], Old[Index + 2]);
WriteProbabilityUpdate(writer, New[index + 0], old[index + 0]);
WriteProbabilityUpdate(writer, New[index + 1], old[index + 1]);
WriteProbabilityUpdate(writer, New[index + 2], old[index + 2]);
}
Index += 4;
index += 4;
}
}
if (BlockIndex == TxMode)
if (blockIndex == txMode)
{
break;
}
}
}
private void WriteProbabilityUpdateAligned4(VpxRangeEncoder Writer, byte[] New, byte[] Old)
private void WriteProbabilityUpdateAligned4(VpxRangeEncoder writer, byte[] New, byte[] old)
{
for (int Offset = 0; Offset < New.Length; Offset += 4)
for (int offset = 0; offset < New.Length; offset += 4)
{
WriteProbabilityUpdate(Writer, New[Offset + 0], Old[Offset + 0]);
WriteProbabilityUpdate(Writer, New[Offset + 1], Old[Offset + 1]);
WriteProbabilityUpdate(Writer, New[Offset + 2], Old[Offset + 2]);
WriteProbabilityUpdate(writer, New[offset + 0], old[offset + 0]);
WriteProbabilityUpdate(writer, New[offset + 1], old[offset + 1]);
WriteProbabilityUpdate(writer, New[offset + 2], old[offset + 2]);
}
}
private void WriteProbabilityUpdate(VpxRangeEncoder Writer, byte New, byte Old)
private void WriteProbabilityUpdate(VpxRangeEncoder writer, byte New, byte old)
{
bool Update = New != Old;
bool update = New != old;
Writer.Write(Update, DiffUpdateProbability);
writer.Write(update, DiffUpdateProbability);
if (Update)
if (update)
{
WriteProbabilityDelta(Writer, New, Old);
WriteProbabilityDelta(writer, New, old);
}
}
private void WriteProbabilityDelta(VpxRangeEncoder Writer, int New, int Old)
private void WriteProbabilityDelta(VpxRangeEncoder writer, int New, int old)
{
int Delta = RemapProbability(New, Old);
int delta = RemapProbability(New, old);
EncodeTermSubExp(Writer, Delta);
EncodeTermSubExp(writer, delta);
}
private int RemapProbability(int New, int Old)
private int RemapProbability(int New, int old)
{
New--;
Old--;
old--;
int Index;
int index;
if (Old * 2 <= 0xff)
if (old * 2 <= 0xff)
{
Index = RecenterNonNeg(New, Old) - 1;
index = RecenterNonNeg(New, old) - 1;
}
else
{
Index = RecenterNonNeg(0xff - 1 - New, 0xff - 1 - Old) - 1;
index = RecenterNonNeg(0xff - 1 - New, 0xff - 1 - old) - 1;
}
return MapLut[Index];
return MapLut[index];
}
private int RecenterNonNeg(int New, int Old)
private int RecenterNonNeg(int New, int old)
{
if (New > Old * 2)
if (New > old * 2)
{
return New;
}
else if (New >= Old)
else if (New >= old)
{
return (New - Old) * 2;
return (New - old) * 2;
}
else /* if (New < Old) */
{
return (Old - New) * 2 - 1;
return (old - New) * 2 - 1;
}
}
private void EncodeTermSubExp(VpxRangeEncoder Writer, int Value)
private void EncodeTermSubExp(VpxRangeEncoder writer, int value)
{
if (WriteLessThan(Writer, Value, 16))
if (WriteLessThan(writer, value, 16))
{
Writer.Write(Value, 4);
writer.Write(value, 4);
}
else if (WriteLessThan(Writer, Value, 32))
else if (WriteLessThan(writer, value, 32))
{
Writer.Write(Value - 16, 4);
writer.Write(value - 16, 4);
}
else if (WriteLessThan(Writer, Value, 64))
else if (WriteLessThan(writer, value, 64))
{
Writer.Write(Value - 32, 5);
writer.Write(value - 32, 5);
}
else
{
Value -= 64;
value -= 64;
const int Size = 8;
const int size = 8;
int Mask = (1 << Size) - 191;
int mask = (1 << size) - 191;
int Delta = Value - Mask;
int delta = value - mask;
if (Delta < 0)
if (delta < 0)
{
Writer.Write(Value, Size - 1);
writer.Write(value, size - 1);
}
else
{
Writer.Write(Delta / 2 + Mask, Size - 1);
Writer.Write(Delta & 1, 1);
writer.Write(delta / 2 + mask, size - 1);
writer.Write(delta & 1, 1);
}
}
}
private bool WriteLessThan(VpxRangeEncoder Writer, int Value, int Test)
private bool WriteLessThan(VpxRangeEncoder writer, int value, int test)
{
bool IsLessThan = Value < Test;
bool isLessThan = value < test;
Writer.Write(!IsLessThan);
writer.Write(!isLessThan);
return IsLessThan;
return isLessThan;
}
private void WriteMvProbabilityUpdate(VpxRangeEncoder Writer, byte New, byte Old)
private void WriteMvProbabilityUpdate(VpxRangeEncoder writer, byte New, byte old)
{
bool Update = New != Old;
bool update = New != old;
Writer.Write(Update, DiffUpdateProbability);
writer.Write(update, DiffUpdateProbability);
if (Update)
if (update)
{
Writer.Write(New >> 1, 7);
writer.Write(New >> 1, 7);
}
}
private static int CalcMinLog2TileCols(int FrameWidth)
private static int CalcMinLog2TileCols(int frameWidth)
{
int Sb64Cols = (FrameWidth + 63) / 64;
int MinLog2 = 0;
int sb64Cols = (frameWidth + 63) / 64;
int minLog2 = 0;
while ((64 << MinLog2) < Sb64Cols)
while ((64 << minLog2) < sb64Cols)
{
MinLog2++;
minLog2++;
}
return MinLog2;
return minLog2;
}
private static int CalcMaxLog2TileCols(int FrameWidth)
private static int CalcMaxLog2TileCols(int frameWidth)
{
int Sb64Cols = (FrameWidth + 63) / 64;
int MaxLog2 = 1;
int sb64Cols = (frameWidth + 63) / 64;
int maxLog2 = 1;
while ((Sb64Cols >> MaxLog2) >= 4)
while ((sb64Cols >> maxLog2) >= 4)
{
MaxLog2++;
maxLog2++;
}
return MaxLog2 - 1;
return maxLog2 - 1;
}
}
}

View file

@ -4,34 +4,34 @@ namespace Ryujinx.Graphics.VDec
{
class VpxBitStreamWriter : BitStreamWriter
{
public VpxBitStreamWriter(Stream BaseStream) : base(BaseStream) { }
public VpxBitStreamWriter(Stream baseStream) : base(baseStream) { }
public void WriteU(int Value, int ValueSize)
public void WriteU(int value, int valueSize)
{
WriteBits(Value, ValueSize);
WriteBits(value, valueSize);
}
public void WriteS(int Value, int ValueSize)
public void WriteS(int value, int valueSize)
{
bool Sign = Value < 0;
bool sign = value < 0;
if (Sign)
if (sign)
{
Value = -Value;
value = -value;
}
WriteBits((Value << 1) | (Sign ? 1 : 0), ValueSize + 1);
WriteBits((value << 1) | (sign ? 1 : 0), valueSize + 1);
}
public void WriteDeltaQ(int Value)
public void WriteDeltaQ(int value)
{
bool DeltaCoded = Value != 0;
bool deltaCoded = value != 0;
WriteBit(DeltaCoded);
WriteBit(deltaCoded);
if (DeltaCoded)
if (deltaCoded)
{
WriteBits(Value, 4);
WriteBits(value, 4);
}
}
}

View file

@ -26,106 +26,106 @@ namespace Ryujinx.Graphics.VDec
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
private Stream BaseStream;
private Stream _baseStream;
private uint LowValue;
private uint Range;
private int Count;
private uint _lowValue;
private uint _range;
private int _count;
public VpxRangeEncoder(Stream BaseStream)
public VpxRangeEncoder(Stream baseStream)
{
this.BaseStream = BaseStream;
_baseStream = baseStream;
Range = 0xff;
Count = -24;
_range = 0xff;
_count = -24;
Write(false);
}
public void WriteByte(byte Value)
public void WriteByte(byte value)
{
Write(Value, 8);
Write(value, 8);
}
public void Write(int Value, int ValueSize)
public void Write(int value, int valueSize)
{
for (int Bit = ValueSize - 1; Bit >= 0; Bit--)
for (int bit = valueSize - 1; bit >= 0; bit--)
{
Write(((Value >> Bit) & 1) != 0);
Write(((value >> bit) & 1) != 0);
}
}
public void Write(bool Bit)
public void Write(bool bit)
{
Write(Bit, HalfProbability);
Write(bit, HalfProbability);
}
public void Write(bool Bit, int Probability)
public void Write(bool bit, int probability)
{
uint Range = this.Range;
uint range = _range;
uint Split = 1 + (((Range - 1) * (uint)Probability) >> 8);
uint split = 1 + (((range - 1) * (uint)probability) >> 8);
Range = Split;
range = split;
if (Bit)
if (bit)
{
LowValue += Split;
Range = this.Range - Split;
_lowValue += split;
range = _range - split;
}
int Shift = NormLut[Range];
int shift = NormLut[range];
Range <<= Shift;
Count += Shift;
range <<= shift;
_count += shift;
if (Count >= 0)
if (_count >= 0)
{
int Offset = Shift - Count;
int offset = shift - _count;
if (((LowValue << (Offset - 1)) >> 31) != 0)
if (((_lowValue << (offset - 1)) >> 31) != 0)
{
long CurrentPos = BaseStream.Position;
long currentPos = _baseStream.Position;
BaseStream.Seek(-1, SeekOrigin.Current);
_baseStream.Seek(-1, SeekOrigin.Current);
while (BaseStream.Position >= 0 && PeekByte() == 0xff)
while (_baseStream.Position >= 0 && PeekByte() == 0xff)
{
BaseStream.WriteByte(0);
_baseStream.WriteByte(0);
BaseStream.Seek(-2, SeekOrigin.Current);
_baseStream.Seek(-2, SeekOrigin.Current);
}
BaseStream.WriteByte((byte)(PeekByte() + 1));
_baseStream.WriteByte((byte)(PeekByte() + 1));
BaseStream.Seek(CurrentPos, SeekOrigin.Begin);
_baseStream.Seek(currentPos, SeekOrigin.Begin);
}
BaseStream.WriteByte((byte)(LowValue >> (24 - Offset)));
_baseStream.WriteByte((byte)(_lowValue >> (24 - offset)));
LowValue <<= Offset;
Shift = Count;
LowValue &= 0xffffff;
Count -= 8;
_lowValue <<= offset;
shift = _count;
_lowValue &= 0xffffff;
_count -= 8;
}
LowValue <<= Shift;
_lowValue <<= shift;
this.Range = Range;
_range = range;
}
private byte PeekByte()
{
byte Value = (byte)BaseStream.ReadByte();
byte value = (byte)_baseStream.ReadByte();
BaseStream.Seek(-1, SeekOrigin.Current);
_baseStream.Seek(-1, SeekOrigin.Current);
return Value;
return value;
}
public void End()
{
for (int Index = 0; Index < 32; Index++)
for (int index = 0; index < 32; index++)
{
Write(false);
}