2020-07-11 20:07:01 -07:00
|
|
|
|
using Ryujinx.Graphics.Nvdec.H264;
|
|
|
|
|
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-09-28 15:43:40 -07:00
|
|
|
|
public unsafe static void Decode(NvdecDecoderContext context, ResourceManager rm, ref NvdecRegisters state)
|
2020-07-11 20:07:01 -07: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-28 15:43:40 -07:00
|
|
|
|
int surfaceIndex = (int)pictureInfo.OutputSurfaceIndex;
|
2020-07-11 20:07:01 -07:00
|
|
|
|
|
2021-09-28 15:43:40 -07:00
|
|
|
|
uint lumaOffset = state.SetSurfaceLumaOffset[surfaceIndex];
|
|
|
|
|
uint chromaOffset = state.SetSurfaceChromaOffset[surfaceIndex];
|
2020-07-11 20:07:01 -07:00
|
|
|
|
|
2021-09-28 15:43:40 -07:00
|
|
|
|
Decoder decoder = context.GetDecoder();
|
2020-07-11 20:07:01 -07:00
|
|
|
|
|
2021-09-28 15:43:40 -07:00
|
|
|
|
ISurface outputSurface = rm.Cache.Get(decoder, 0, 0, width, height);
|
2020-07-11 20:07:01 -07:00
|
|
|
|
|
2021-09-28 15:43:40 -07:00
|
|
|
|
if (decoder.Decode(ref info, outputSurface, bitstream))
|
|
|
|
|
{
|
|
|
|
|
SurfaceWriter.Write(rm.Gmm, outputSurface, lumaOffset, chromaOffset);
|
2020-07-11 20:07:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rm.Cache.Put(outputSurface);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|