2021-10-12 22:55:57 +02:00
|
|
|
|
using Ryujinx.Graphics.Nvdec.FFmpeg.H264;
|
2020-07-12 05:07:01 +02:00
|
|
|
|
using Ryujinx.Graphics.Nvdec.Image;
|
|
|
|
|
using Ryujinx.Graphics.Nvdec.Types.H264;
|
|
|
|
|
using Ryujinx.Graphics.Video;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Nvdec
|
|
|
|
|
{
|
|
|
|
|
static class H264Decoder
|
|
|
|
|
{
|
|
|
|
|
private const int MbSizeInPixels = 16;
|
|
|
|
|
|
2021-10-12 22:55:57 +02:00
|
|
|
|
public static void Decode(NvdecDecoderContext context, ResourceManager rm, ref NvdecRegisters state)
|
2020-07-12 05:07:01 +02:00
|
|
|
|
{
|
|
|
|
|
PictureInfo pictureInfo = rm.Gmm.DeviceRead<PictureInfo>(state.SetPictureInfoOffset);
|
|
|
|
|
H264PictureInfo info = pictureInfo.Convert();
|
|
|
|
|
|
|
|
|
|
ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetBitstreamOffset, (int)pictureInfo.BitstreamSize);
|
|
|
|
|
|
|
|
|
|
int width = (int)pictureInfo.PicWidthInMbs * MbSizeInPixels;
|
|
|
|
|
int height = (int)pictureInfo.PicHeightInMbs * MbSizeInPixels;
|
|
|
|
|
|
2021-09-29 00:43:40 +02:00
|
|
|
|
int surfaceIndex = (int)pictureInfo.OutputSurfaceIndex;
|
2020-07-12 05:07:01 +02:00
|
|
|
|
|
2021-09-29 00:43:40 +02:00
|
|
|
|
uint lumaOffset = state.SetSurfaceLumaOffset[surfaceIndex];
|
|
|
|
|
uint chromaOffset = state.SetSurfaceChromaOffset[surfaceIndex];
|
2020-07-12 05:07:01 +02:00
|
|
|
|
|
2021-10-12 22:55:57 +02:00
|
|
|
|
Decoder decoder = context.GetH264Decoder();
|
2020-07-12 05:07:01 +02:00
|
|
|
|
|
2021-09-29 00:43:40 +02:00
|
|
|
|
ISurface outputSurface = rm.Cache.Get(decoder, 0, 0, width, height);
|
2020-07-12 05:07:01 +02:00
|
|
|
|
|
2021-09-29 00:43:40 +02:00
|
|
|
|
if (decoder.Decode(ref info, outputSurface, bitstream))
|
|
|
|
|
{
|
2022-03-23 21:09:32 +01:00
|
|
|
|
if (outputSurface.Field == FrameField.Progressive)
|
|
|
|
|
{
|
|
|
|
|
SurfaceWriter.Write(
|
|
|
|
|
rm.Gmm,
|
|
|
|
|
outputSurface,
|
|
|
|
|
lumaOffset + pictureInfo.LumaFrameOffset,
|
|
|
|
|
chromaOffset + pictureInfo.ChromaFrameOffset);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SurfaceWriter.WriteInterlaced(
|
|
|
|
|
rm.Gmm,
|
|
|
|
|
outputSurface,
|
|
|
|
|
lumaOffset + pictureInfo.LumaTopFieldOffset,
|
|
|
|
|
chromaOffset + pictureInfo.ChromaTopFieldOffset,
|
|
|
|
|
lumaOffset + pictureInfo.LumaBottomFieldOffset,
|
|
|
|
|
chromaOffset + pictureInfo.ChromaBottomFieldOffset);
|
|
|
|
|
}
|
2020-07-12 05:07:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rm.Cache.Put(outputSurface);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|