From c465d771dd099b0ffbb0792b3e74148e01259f19 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 10 Feb 2021 21:54:42 -0300 Subject: Enable multithreaded VP9 decoding (#2009) * Enable multithreaded VP9 decoding * Limit the number of threads used for video decoding --- Ryujinx.Graphics.Nvdec.Vp9/Decoder.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'Ryujinx.Graphics.Nvdec.Vp9/Decoder.cs') diff --git a/Ryujinx.Graphics.Nvdec.Vp9/Decoder.cs b/Ryujinx.Graphics.Nvdec.Vp9/Decoder.cs index ff4221ac..f82ca761 100644 --- a/Ryujinx.Graphics.Nvdec.Vp9/Decoder.cs +++ b/Ryujinx.Graphics.Nvdec.Vp9/Decoder.cs @@ -92,7 +92,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9 cm.Mb.SetupBlockPlanes(1, 1); - cm.AllocTileWorkerData(_allocator, 1 << pictureInfo.Log2TileCols, 1 << pictureInfo.Log2TileRows); + 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); cm.AllocContextBuffers(_allocator, output.Width, output.Height); cm.InitContextBuffers(); cm.SetupSegmentationDequant(); @@ -104,7 +111,14 @@ namespace Ryujinx.Graphics.Nvdec.Vp9 { try { - DecodeFrame.DecodeTiles(ref cm, new ArrayPtr(dataPtr, bitstream.Length)); + if (maxThreads > 1 && tileRows == 1 && tileCols > 1) + { + DecodeFrame.DecodeTilesMt(ref cm, new ArrayPtr(dataPtr, bitstream.Length), maxThreads); + } + else + { + DecodeFrame.DecodeTiles(ref cm, new ArrayPtr(dataPtr, bitstream.Length)); + } } catch (InternalErrorException) { -- cgit v1.2.3