Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
using Ryujinx.Common.Memory;
|
2020-07-12 00:07:01 -03:00
|
|
|
|
using Ryujinx.Graphics.Nvdec.Vp9.Common;
|
|
|
|
|
|
using Ryujinx.Graphics.Nvdec.Vp9.Types;
|
|
|
|
|
|
using Ryujinx.Graphics.Video;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Nvdec.Vp9
|
|
|
|
|
|
{
|
2020-08-20 00:07:04 -03:00
|
|
|
|
public sealed class Decoder : IVp9Decoder
|
2020-07-12 00:07:01 -03:00
|
|
|
|
{
|
|
|
|
|
|
public bool IsHardwareAccelerated => false;
|
|
|
|
|
|
|
2023-06-28 09:26:39 +02:00
|
|
|
|
private readonly MemoryAllocator _allocator = new();
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
public ISurface CreateSurface(int width, int height)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Surface(width, height);
|
|
|
|
|
|
}
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
2025-02-18 21:33:07 -06:00
|
|
|
|
private static ReadOnlySpan<byte> LiteralToFilter =>
|
|
|
|
|
|
[
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
Constants.EightTapSmooth, Constants.EightTap, Constants.EightTapSharp, Constants.Bilinear
|
2025-02-18 21:33:07 -06:00
|
|
|
|
];
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
|
|
|
|
|
public unsafe bool Decode(
|
|
|
|
|
|
ref Vp9PictureInfo pictureInfo,
|
|
|
|
|
|
ISurface output,
|
|
|
|
|
|
ReadOnlySpan<byte> bitstream,
|
|
|
|
|
|
ReadOnlySpan<Vp9MvRef> mvsIn,
|
|
|
|
|
|
Span<Vp9MvRef> mvsOut)
|
|
|
|
|
|
{
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
Vp9Common cm = new();
|
|
|
|
|
|
|
|
|
|
|
|
cm.FrameType = pictureInfo.IsKeyFrame ? FrameType.KeyFrame : FrameType.InterFrame;
|
|
|
|
|
|
cm.IntraOnly = pictureInfo.IntraOnly;
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
cm.Width = output.Width;
|
|
|
|
|
|
cm.Height = output.Height;
|
|
|
|
|
|
cm.SubsamplingX = 1;
|
|
|
|
|
|
cm.SubsamplingY = 1;
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
cm.UsePrevFrameMvs = pictureInfo.UsePrevInFindMvRefs;
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
cm.RefFrameSignBias = pictureInfo.RefFrameSignBias;
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
cm.BaseQindex = pictureInfo.BaseQIndex;
|
|
|
|
|
|
cm.YDcDeltaQ = pictureInfo.YDcDeltaQ;
|
|
|
|
|
|
cm.UvAcDeltaQ = pictureInfo.UvAcDeltaQ;
|
|
|
|
|
|
cm.UvDcDeltaQ = pictureInfo.UvDcDeltaQ;
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
|
|
|
|
|
cm.Mb.Lossless = pictureInfo.Lossless;
|
2020-08-20 00:07:04 -03:00
|
|
|
|
cm.Mb.Bd = 8;
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
|
|
|
|
|
cm.TxMode = (TxMode)pictureInfo.TransformMode;
|
|
|
|
|
|
|
|
|
|
|
|
cm.AllowHighPrecisionMv = pictureInfo.AllowHighPrecisionMv;
|
|
|
|
|
|
|
|
|
|
|
|
cm.InterpFilter = (byte)pictureInfo.InterpFilter;
|
|
|
|
|
|
|
|
|
|
|
|
if (cm.InterpFilter != Constants.Switchable)
|
|
|
|
|
|
{
|
|
|
|
|
|
cm.InterpFilter = LiteralToFilter[cm.InterpFilter];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cm.ReferenceMode = (ReferenceMode)pictureInfo.ReferenceMode;
|
|
|
|
|
|
|
|
|
|
|
|
cm.CompFixedRef = pictureInfo.CompFixedRef;
|
|
|
|
|
|
cm.CompVarRef = pictureInfo.CompVarRef;
|
|
|
|
|
|
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
cm.BitDepth = BitDepth.Bits8;
|
|
|
|
|
|
|
2020-07-12 00:07:01 -03:00
|
|
|
|
cm.Log2TileCols = pictureInfo.Log2TileCols;
|
|
|
|
|
|
cm.Log2TileRows = pictureInfo.Log2TileRows;
|
|
|
|
|
|
|
|
|
|
|
|
cm.Seg.Enabled = pictureInfo.SegmentEnabled;
|
|
|
|
|
|
cm.Seg.UpdateMap = pictureInfo.SegmentMapUpdate;
|
|
|
|
|
|
cm.Seg.TemporalUpdate = pictureInfo.SegmentMapTemporalUpdate;
|
|
|
|
|
|
cm.Seg.AbsDelta = (byte)pictureInfo.SegmentAbsDelta;
|
|
|
|
|
|
cm.Seg.FeatureMask = pictureInfo.SegmentFeatureEnable;
|
|
|
|
|
|
cm.Seg.FeatureData = pictureInfo.SegmentFeatureData;
|
|
|
|
|
|
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
cm.Lf.FilterLevel = pictureInfo.LoopFilterLevel;
|
|
|
|
|
|
cm.Lf.SharpnessLevel = pictureInfo.LoopFilterSharpnessLevel;
|
2020-07-12 00:07:01 -03:00
|
|
|
|
cm.Lf.ModeRefDeltaEnabled = pictureInfo.ModeRefDeltaEnabled;
|
|
|
|
|
|
cm.Lf.RefDeltas = pictureInfo.RefDeltas;
|
|
|
|
|
|
cm.Lf.ModeDeltas = pictureInfo.ModeDeltas;
|
|
|
|
|
|
|
|
|
|
|
|
cm.Fc = new Ptr<Vp9EntropyProbs>(ref pictureInfo.Entropy);
|
|
|
|
|
|
cm.Counts = new Ptr<Vp9BackwardUpdates>(ref pictureInfo.BackwardUpdateCounts);
|
|
|
|
|
|
|
|
|
|
|
|
cm.FrameRefs[0].Buf = (Surface)pictureInfo.LastReference;
|
|
|
|
|
|
cm.FrameRefs[1].Buf = (Surface)pictureInfo.GoldenReference;
|
|
|
|
|
|
cm.FrameRefs[2].Buf = (Surface)pictureInfo.AltReference;
|
|
|
|
|
|
cm.Mb.CurBuf = (Surface)output;
|
|
|
|
|
|
|
|
|
|
|
|
cm.Mb.SetupBlockPlanes(1, 1);
|
|
|
|
|
|
|
2021-02-10 21:54:42 -03:00
|
|
|
|
int tileCols = 1 << pictureInfo.Log2TileCols;
|
|
|
|
|
|
int tileRows = 1 << pictureInfo.Log2TileRows;
|
|
|
|
|
|
|
|
|
|
|
|
// Video usually have only 4 columns, so more threads won't make a difference for those.
|
|
|
|
|
|
// Try to not take all CPU cores for video decoding.
|
|
|
|
|
|
int maxThreads = Math.Min(4, Environment.ProcessorCount / 2);
|
|
|
|
|
|
|
|
|
|
|
|
cm.AllocTileWorkerData(_allocator, tileCols, tileRows, maxThreads);
|
2020-07-12 00:07:01 -03:00
|
|
|
|
cm.AllocContextBuffers(_allocator, output.Width, output.Height);
|
|
|
|
|
|
cm.InitContextBuffers();
|
|
|
|
|
|
cm.SetupSegmentationDequant();
|
|
|
|
|
|
cm.SetupScaleFactors();
|
|
|
|
|
|
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
cm.SetMvs(mvsIn);
|
|
|
|
|
|
|
|
|
|
|
|
if (cm.Lf.FilterLevel != 0 && cm.SkipLoopFilter == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LoopFilter.LoopFilterFrameInit(ref cm, cm.Lf.FilterLevel);
|
|
|
|
|
|
}
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
|
|
|
|
|
fixed (byte* dataPtr = bitstream)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2021-02-10 21:54:42 -03:00
|
|
|
|
if (maxThreads > 1 && tileRows == 1 && tileCols > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
DecodeFrame.DecodeTilesMt(ref cm, new ArrayPtr<byte>(dataPtr, bitstream.Length), maxThreads);
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
|
|
|
|
|
|
LoopFilter.LoopFilterFrameMt(
|
|
|
|
|
|
ref cm.Mb.CurBuf,
|
|
|
|
|
|
ref cm,
|
|
|
|
|
|
ref cm.Mb,
|
|
|
|
|
|
cm.Lf.FilterLevel,
|
|
|
|
|
|
false,
|
|
|
|
|
|
false,
|
|
|
|
|
|
maxThreads);
|
2021-02-10 21:54:42 -03:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DecodeFrame.DecodeTiles(ref cm, new ArrayPtr<byte>(dataPtr, bitstream.Length));
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
|
|
|
|
|
|
LoopFilter.LoopFilterFrame(
|
|
|
|
|
|
ref cm.Mb.CurBuf,
|
|
|
|
|
|
ref cm,
|
|
|
|
|
|
ref cm.Mb,
|
|
|
|
|
|
cm.Lf.FilterLevel,
|
|
|
|
|
|
false,
|
|
|
|
|
|
false);
|
2021-02-10 21:54:42 -03:00
|
|
|
|
}
|
2020-07-12 00:07:01 -03:00
|
|
|
|
}
|
|
|
|
|
|
catch (InternalErrorException)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
cm.GetMvs(mvsOut);
|
2020-07-12 00:07:01 -03:00
|
|
|
|
|
|
|
|
|
|
cm.FreeTileWorkerData(_allocator);
|
|
|
|
|
|
cm.FreeContextBuffers(_allocator);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
public void Dispose()
|
2020-07-12 00:07:01 -03:00
|
|
|
|
{
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
_allocator.Dispose();
|
2020-07-12 00:07:01 -03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
Implement VP9 loop filtering (#550)
Unmerged PR from OG Ryujinx (#4367). From @gdkchan:
> The main goal of this change is porting the loop filtering from
libvpx, which should fix the block artifacts on some VP9 videos on games
using NVDEC to decode them. In addition to that, there are two other
changes:
>
> - The remaining decoder code required to decode a VP9 video (with
headers included) has been added. That was done because it's much better
to test the decoder standalone with a video file. I decided to keep that
code on the emulator, even if some of it is unused, since it makes
standalone testing easier in the future too, and we can include unit
tests with video files.
> - Large refactoring of both new and existing code to conform with our
conding [sic] styles, done by @TSRBerry (thanks!) Some of it has been
automated.
>
> Since we had no loop filtering before, this change will make video
decoding slower. That may cause frame drop etc if the decoder is not
fast enough in some games. I plan to optimize the decoder more in the
future to make up for that, but if possible I'd prefer to not do it as
part of this PR, but if the perf loss is too severe I might consider.
>
> This will need to be tested on games that had the block artifacts, it
would be nice to confirm if they match hardware now, and get some
before/after screenshots etc.
Comment from @Bjorn29512:
> Significantly improves the block artifacts in FE: Engage.
>
> Before:
>

>
> After:
>

---------
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
2025-02-18 20:59:36 -06:00
|
|
|
|
}
|