2020-07-12 05:07:01 +02: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-29 00:43:40 +02:00
|
|
|
|
public unsafe 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-09-29 00:43:40 +02:00
|
|
|
|
Decoder decoder = context.GetDecoder();
|
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))
|
|
|
|
|
{
|
|
|
|
|
SurfaceWriter.Write(rm.Gmm, outputSurface, lumaOffset, chromaOffset);
|
2020-07-12 05:07:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rm.Cache.Put(outputSurface);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|