0
0
Fork 0
mirror of https://github.com/ryujinx-mirror/ryujinx.git synced 2024-12-23 01:05:49 +00:00

misc: Use official names for NVDEC registers (#4192)

* misc: Uses official names for NVDEC registers

* Address gdkchan's comment

* Address comments
This commit is contained in:
Mary-nyan 2023-01-02 15:48:46 +01:00 committed by GitHub
parent b6614c6ad5
commit 09c9686498
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 80 additions and 76 deletions

View file

@ -106,7 +106,7 @@ namespace Ryujinx.Graphics.Host1x
private void Method1(int data) private void Method1(int data)
{ {
_commandQueue.Add(new MethodCallAction(_currentContextId, (int)_state.State.Method0 * 4, data)); _commandQueue.Add(new MethodCallAction(_currentContextId, (int)_state.State.Method0 * sizeof(uint), data));
} }
private void Process(CommandAction cmdAction) private void Process(CommandAction cmdAction)

View file

@ -1,6 +1,6 @@
namespace Ryujinx.Graphics.Nvdec namespace Ryujinx.Graphics.Nvdec
{ {
public enum CodecId public enum ApplicationId
{ {
Mpeg = 1, Mpeg = 1,
Vc1 = 2, Vc1 = 2,
@ -8,6 +8,7 @@
Mpeg4 = 4, Mpeg4 = 4,
Vp8 = 5, Vp8 = 5,
Hevc = 7, Hevc = 7,
Vp9 = 9 Vp9 = 9,
HevcParser = 12,
} }
} }

View file

@ -1,16 +0,0 @@
namespace Ryujinx.Graphics.Nvdec
{
public readonly struct FrameDecodedEventArgs
{
public CodecId CodecId { get; }
public uint LumaOffset { get; }
public uint ChromaOffset { get; }
internal FrameDecodedEventArgs(CodecId codecId, uint lumaOffset, uint chromaOffset)
{
CodecId = codecId;
LumaOffset = lumaOffset;
ChromaOffset = chromaOffset;
}
}
}

View file

@ -12,18 +12,18 @@ namespace Ryujinx.Graphics.Nvdec
public static void Decode(NvdecDecoderContext context, ResourceManager rm, ref NvdecRegisters state) public static void Decode(NvdecDecoderContext context, ResourceManager rm, ref NvdecRegisters state)
{ {
PictureInfo pictureInfo = rm.Gmm.DeviceRead<PictureInfo>(state.SetPictureInfoOffset); PictureInfo pictureInfo = rm.Gmm.DeviceRead<PictureInfo>(state.SetDrvPicSetupOffset);
H264PictureInfo info = pictureInfo.Convert(); H264PictureInfo info = pictureInfo.Convert();
ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetBitstreamOffset, (int)pictureInfo.BitstreamSize); ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetInBufBaseOffset, (int)pictureInfo.BitstreamSize);
int width = (int)pictureInfo.PicWidthInMbs * MbSizeInPixels; int width = (int)pictureInfo.PicWidthInMbs * MbSizeInPixels;
int height = (int)pictureInfo.PicHeightInMbs * MbSizeInPixels; int height = (int)pictureInfo.PicHeightInMbs * MbSizeInPixels;
int surfaceIndex = (int)pictureInfo.OutputSurfaceIndex; int surfaceIndex = (int)pictureInfo.OutputSurfaceIndex;
uint lumaOffset = state.SetSurfaceLumaOffset[surfaceIndex]; uint lumaOffset = state.SetPictureLumaOffset[surfaceIndex];
uint chromaOffset = state.SetSurfaceChromaOffset[surfaceIndex]; uint chromaOffset = state.SetPictureChromaOffset[surfaceIndex];
Decoder decoder = context.GetH264Decoder(); Decoder decoder = context.GetH264Decoder();

View file

@ -58,24 +58,24 @@ namespace Ryujinx.Graphics.Nvdec
private void Execute(int data) private void Execute(int data)
{ {
Decode((CodecId)_state.State.SetCodecID); Decode((ApplicationId)_state.State.SetApplicationId);
} }
private void Decode(CodecId codecId) private void Decode(ApplicationId applicationId)
{ {
switch (codecId) switch (applicationId)
{ {
case CodecId.H264: case ApplicationId.H264:
H264Decoder.Decode(_currentContext, _rm, ref _state.State); H264Decoder.Decode(_currentContext, _rm, ref _state.State);
break; break;
case CodecId.Vp8: case ApplicationId.Vp8:
Vp8Decoder.Decode(_currentContext, _rm, ref _state.State); Vp8Decoder.Decode(_currentContext, _rm, ref _state.State);
break; break;
case CodecId.Vp9: case ApplicationId.Vp9:
Vp9Decoder.Decode(_rm, ref _state.State); Vp9Decoder.Decode(_rm, ref _state.State);
break; break;
default: default:
Logger.Error?.Print(LogClass.Nvdec, $"Unsupported codec \"{codecId}\"."); Logger.Error?.Print(LogClass.Nvdec, $"Unsupported codec \"{applicationId}\".");
break; break;
} }
} }

View file

@ -2,43 +2,62 @@
namespace Ryujinx.Graphics.Nvdec namespace Ryujinx.Graphics.Nvdec
{ {
// Note: Most of those names are not official.
struct NvdecRegisters struct NvdecRegisters
{ {
#pragma warning disable CS0649 #pragma warning disable CS0649
public Array64<uint> Reserved0; public Array64<uint> Reserved0;
public Array64<uint> Reserved100; public uint Nop;
public uint SetCodecID; public Array63<uint> Reserved104;
public Array63<uint> Reserved204; public uint SetApplicationId;
public uint SetWatchdogTimer;
public Array14<uint> Reserved208;
public uint SemaphoreA;
public uint SemaphoreB;
public uint SemaphoreC;
public uint CtxSaveArea;
public Array44<uint> Reserved254;
public uint Execute; public uint Execute;
public Array63<uint> Reserved304; public uint SemaphoreD;
public uint SetPlatformID; public Array62<uint> Reserved308;
public uint SetPictureInfoOffset; public uint SetControlParams;
public uint SetBitstreamOffset; public uint SetDrvPicSetupOffset;
public uint SetFrameNumber; public uint SetInBufBaseOffset;
public uint SetH264SliceDataOffsetsOffset; // Also used by VC1 public uint SetPictureIndex;
public uint SetH264MvDumpOffset; // Also used by VC1 public uint SetSliceOffsetsBufOffset; // Also used by VC1
public uint Unknown418; // Used by VC1 public uint SetColocDataOffset; // Also used by VC1
public uint Unknown41C; public uint SetHistoryOffset; // Used by VC1
public uint Unknown420; // Used by VC1 public uint SetDisplayBufSize;
public uint SetFrameStatsOffset; public uint SetHistogramOffset; // Used by VC1
public uint SetH264LastSurfaceLumaOffset; public uint SetNvDecStatusOffset;
public uint SetH264LastSurfaceChromaOffset; public uint SetDisplayBufLumaOffset;
public Array17<uint> SetSurfaceLumaOffset; public uint SetDisplayBufChromaOffset;
public Array17<uint> SetSurfaceChromaOffset; public Array17<uint> SetPictureLumaOffset;
public uint Unknown4B8; public Array17<uint> SetPictureChromaOffset;
public uint Unknown4BC; public uint SetPicScratchBufOffset;
public uint SetExternalMvBufferOffset;
public uint SetCryptoData0Offset; public uint SetCryptoData0Offset;
public uint SetCryptoData1Offset; public uint SetCryptoData1Offset;
public Array62<uint> Unknown4C8; public Array14<uint> Unknown4C8;
public uint SetVp9EntropyProbsOffset; public uint H264SetMbHistBufOffset;
public uint SetVp9BackwardUpdatesOffset; public Array15<uint> Unknown504;
public uint SetVp9LastFrameSegMapOffset; public uint Vp8SetProbDataOffset;
public uint SetVp9CurrFrameSegMapOffset; public uint Vp8SetHeaderPartitionBufBaseOffset;
public uint Unknown5D0; public Array14<uint> Unknown548;
public uint SetVp9LastFrameMvsOffset; public uint HevcSetScalingListOffset;
public uint SetVp9CurrFrameMvsOffset; public uint HevcSetTileSizesOffset;
public uint Unknown5DC; public uint HevcSetFilterBufferOffset;
public uint HevcSetSaoBufferOffset;
public uint HevcSetSliceInfoBufferOffset;
public uint HevcSetSliceGroupIndex;
public Array10<uint> Unknown598;
public uint Vp9SetProbTabBufOffset;
public uint Vp9SetCtxCounterBufOffset;
public uint Vp9SetSegmentReadBufOffset;
public uint Vp9SetSegmentWriteBufOffset;
public uint Vp9SetTileSizeBufOffset;
public uint Vp9SetColMvWriteBufOffset;
public uint Vp9SetColMvReadBufOffset;
public uint Vp9SetFilterBufferOffset;
#pragma warning restore CS0649 #pragma warning restore CS0649
} }
} }

View file

@ -10,8 +10,8 @@ namespace Ryujinx.Graphics.Nvdec
{ {
public static void Decode(NvdecDecoderContext context, ResourceManager rm, ref NvdecRegisters state) public static void Decode(NvdecDecoderContext context, ResourceManager rm, ref NvdecRegisters state)
{ {
PictureInfo pictureInfo = rm.Gmm.DeviceRead<PictureInfo>(state.SetPictureInfoOffset); PictureInfo pictureInfo = rm.Gmm.DeviceRead<PictureInfo>(state.SetDrvPicSetupOffset);
ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetBitstreamOffset, (int)pictureInfo.VLDBufferSize); ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetInBufBaseOffset, (int)pictureInfo.VLDBufferSize);
Decoder decoder = context.GetVp8Decoder(); Decoder decoder = context.GetVp8Decoder();
@ -19,8 +19,8 @@ namespace Ryujinx.Graphics.Nvdec
Vp8PictureInfo info = pictureInfo.Convert(); Vp8PictureInfo info = pictureInfo.Convert();
uint lumaOffset = state.SetSurfaceLumaOffset[3]; uint lumaOffset = state.SetPictureLumaOffset[3];
uint chromaOffset = state.SetSurfaceChromaOffset[3]; uint chromaOffset = state.SetPictureChromaOffset[3];
if (decoder.Decode(ref info, outputSurface, bitstream)) if (decoder.Decode(ref info, outputSurface, bitstream))
{ {

View file

@ -17,18 +17,18 @@ namespace Ryujinx.Graphics.Nvdec
public unsafe static void Decode(ResourceManager rm, ref NvdecRegisters state) public unsafe static void Decode(ResourceManager rm, ref NvdecRegisters state)
{ {
PictureInfo pictureInfo = rm.Gmm.DeviceRead<PictureInfo>(state.SetPictureInfoOffset); PictureInfo pictureInfo = rm.Gmm.DeviceRead<PictureInfo>(state.SetDrvPicSetupOffset);
EntropyProbs entropy = rm.Gmm.DeviceRead<EntropyProbs>(state.SetVp9EntropyProbsOffset); EntropyProbs entropy = rm.Gmm.DeviceRead<EntropyProbs>(state.Vp9SetProbTabBufOffset);
ISurface Rent(uint lumaOffset, uint chromaOffset, FrameSize size) ISurface Rent(uint lumaOffset, uint chromaOffset, FrameSize size)
{ {
return rm.Cache.Get(_decoder, lumaOffset, chromaOffset, size.Width, size.Height); return rm.Cache.Get(_decoder, lumaOffset, chromaOffset, size.Width, size.Height);
} }
ISurface lastSurface = Rent(state.SetSurfaceLumaOffset[0], state.SetSurfaceChromaOffset[0], pictureInfo.LastFrameSize); ISurface lastSurface = Rent(state.SetPictureLumaOffset[0], state.SetPictureChromaOffset[0], pictureInfo.LastFrameSize);
ISurface goldenSurface = Rent(state.SetSurfaceLumaOffset[1], state.SetSurfaceChromaOffset[1], pictureInfo.GoldenFrameSize); ISurface goldenSurface = Rent(state.SetPictureLumaOffset[1], state.SetPictureChromaOffset[1], pictureInfo.GoldenFrameSize);
ISurface altSurface = Rent(state.SetSurfaceLumaOffset[2], state.SetSurfaceChromaOffset[2], pictureInfo.AltFrameSize); ISurface altSurface = Rent(state.SetPictureLumaOffset[2], state.SetPictureChromaOffset[2], pictureInfo.AltFrameSize);
ISurface currentSurface = Rent(state.SetSurfaceLumaOffset[3], state.SetSurfaceChromaOffset[3], pictureInfo.CurrentFrameSize); ISurface currentSurface = Rent(state.SetPictureLumaOffset[3], state.SetPictureChromaOffset[3], pictureInfo.CurrentFrameSize);
Vp9PictureInfo info = pictureInfo.Convert(); Vp9PictureInfo info = pictureInfo.Convert();
@ -38,31 +38,31 @@ namespace Ryujinx.Graphics.Nvdec
entropy.Convert(ref info.Entropy); entropy.Convert(ref info.Entropy);
ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetBitstreamOffset, (int)pictureInfo.BitstreamSize); ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetInBufBaseOffset, (int)pictureInfo.BitstreamSize);
ReadOnlySpan<Vp9MvRef> mvsIn = ReadOnlySpan<Vp9MvRef>.Empty; ReadOnlySpan<Vp9MvRef> mvsIn = ReadOnlySpan<Vp9MvRef>.Empty;
if (info.UsePrevInFindMvRefs) if (info.UsePrevInFindMvRefs)
{ {
mvsIn = GetMvsInput(rm.Gmm, pictureInfo.CurrentFrameSize, state.SetVp9LastFrameMvsOffset); mvsIn = GetMvsInput(rm.Gmm, pictureInfo.CurrentFrameSize, state.Vp9SetColMvReadBufOffset);
} }
int miCols = BitUtils.DivRoundUp(pictureInfo.CurrentFrameSize.Width, 8); int miCols = BitUtils.DivRoundUp(pictureInfo.CurrentFrameSize.Width, 8);
int miRows = BitUtils.DivRoundUp(pictureInfo.CurrentFrameSize.Height, 8); int miRows = BitUtils.DivRoundUp(pictureInfo.CurrentFrameSize.Height, 8);
using var mvsRegion = rm.Gmm.GetWritableRegion(ExtendOffset(state.SetVp9CurrFrameMvsOffset), miRows * miCols * 16); using var mvsRegion = rm.Gmm.GetWritableRegion(ExtendOffset(state.Vp9SetColMvWriteBufOffset), miRows * miCols * 16);
Span<Vp9MvRef> mvsOut = MemoryMarshal.Cast<byte, Vp9MvRef>(mvsRegion.Memory.Span); Span<Vp9MvRef> mvsOut = MemoryMarshal.Cast<byte, Vp9MvRef>(mvsRegion.Memory.Span);
uint lumaOffset = state.SetSurfaceLumaOffset[3]; uint lumaOffset = state.SetPictureLumaOffset[3];
uint chromaOffset = state.SetSurfaceChromaOffset[3]; uint chromaOffset = state.SetPictureChromaOffset[3];
if (_decoder.Decode(ref info, currentSurface, bitstream, mvsIn, mvsOut)) if (_decoder.Decode(ref info, currentSurface, bitstream, mvsIn, mvsOut))
{ {
SurfaceWriter.Write(rm.Gmm, currentSurface, lumaOffset, chromaOffset); SurfaceWriter.Write(rm.Gmm, currentSurface, lumaOffset, chromaOffset);
} }
WriteBackwardUpdates(rm.Gmm, state.SetVp9BackwardUpdatesOffset, ref info.BackwardUpdateCounts); WriteBackwardUpdates(rm.Gmm, state.Vp9SetCtxCounterBufOffset, ref info.BackwardUpdateCounts);
rm.Cache.Put(lastSurface); rm.Cache.Put(lastSurface);
rm.Cache.Put(goldenSurface); rm.Cache.Put(goldenSurface);