From c1372ed775e11aa4759fd3460f2e01d16372205a Mon Sep 17 00:00:00 2001 From: Berkan Diler Date: Fri, 18 Nov 2022 04:10:44 +0100 Subject: [PATCH] Use ReadOnlySpan compiler optimization in more places (#3853) * Use ReadOnlySpan compiler optimization in more places * Revert changes in ShaderBinaries.cs * Remove unused using; * Use ReadOnlySpan compiler optimization in more places --- ARMeilleure/Common/BitUtils.cs | 8 ++------ Ryujinx.Graphics.Nvdec.Vp9/Detokenize.cs | 2 +- Ryujinx.Graphics.Nvdec.Vp9/Luts.cs | 26 +++++++++++------------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/ARMeilleure/Common/BitUtils.cs b/ARMeilleure/Common/BitUtils.cs index 51160eff0..e7697ff31 100644 --- a/ARMeilleure/Common/BitUtils.cs +++ b/ARMeilleure/Common/BitUtils.cs @@ -1,15 +1,11 @@ +using System; using System.Numerics; namespace ARMeilleure.Common { static class BitUtils { - private static readonly sbyte[] HbsNibbleLut; - - static BitUtils() - { - HbsNibbleLut = new sbyte[] { -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 }; - } + private static ReadOnlySpan HbsNibbleLut => new sbyte[] { -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 }; public static long FillWithOnes(int bits) { diff --git a/Ryujinx.Graphics.Nvdec.Vp9/Detokenize.cs b/Ryujinx.Graphics.Nvdec.Vp9/Detokenize.cs index bde774c8e..52b1b3dc4 100644 --- a/Ryujinx.Graphics.Nvdec.Vp9/Detokenize.cs +++ b/Ryujinx.Graphics.Nvdec.Vp9/Detokenize.cs @@ -63,7 +63,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9 short dqv = dq[0]; ReadOnlySpan cat6Prob = (xd.Bd == 12) ? Luts.Vp9Cat6ProbHigh12 - : (xd.Bd == 10) ? new ReadOnlySpan(Luts.Vp9Cat6ProbHigh12).Slice(2) : Luts.Vp9Cat6Prob; + : (xd.Bd == 10) ? Luts.Vp9Cat6ProbHigh12.Slice(2) : Luts.Vp9Cat6Prob; int cat6Bits = (xd.Bd == 12) ? 18 : (xd.Bd == 10) ? 16 : 14; // Keep value, range, and count as locals. The compiler produces better // results with the locals than using r directly. diff --git a/Ryujinx.Graphics.Nvdec.Vp9/Luts.cs b/Ryujinx.Graphics.Nvdec.Vp9/Luts.cs index f703d214f..140181ef8 100644 --- a/Ryujinx.Graphics.Nvdec.Vp9/Luts.cs +++ b/Ryujinx.Graphics.Nvdec.Vp9/Luts.cs @@ -1,14 +1,12 @@ using Ryujinx.Common.Memory; using Ryujinx.Graphics.Nvdec.Vp9.Types; +using System; namespace Ryujinx.Graphics.Nvdec.Vp9 { internal static class Luts { - public static readonly byte[] SizeGroupLookup = new byte[] - { - 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3 - }; + public static ReadOnlySpan SizeGroupLookup => new byte[] { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3 }; public static readonly BlockSize[][] SubsizeLookup = new BlockSize[][] { @@ -1070,18 +1068,18 @@ namespace Ryujinx.Graphics.Nvdec.Vp9 -(sbyte)MvClassType.MvClass10, }; - public static readonly sbyte[] Vp9MvFPTree = new sbyte[] { -0, 2, -1, 4, -2, -3 }; + public static ReadOnlySpan Vp9MvFPTree => new sbyte[] { -0, 2, -1, 4, -2, -3 }; // Entropy - public static readonly byte[] Vp9Cat1Prob = new byte[] { 159 }; - public static readonly byte[] Vp9Cat2Prob = new byte[] { 165, 145 }; - public static readonly byte[] Vp9Cat3Prob = new byte[] { 173, 148, 140 }; - public static readonly byte[] Vp9Cat4Prob = new byte[] { 176, 155, 140, 135 }; - public static readonly byte[] Vp9Cat5Prob = new byte[] { 180, 157, 141, 134, 130 }; - public static readonly byte[] Vp9Cat6Prob = new byte[] { 254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129 }; + public static ReadOnlySpan Vp9Cat1Prob => new byte[] { 159 }; + public static ReadOnlySpan Vp9Cat2Prob => new byte[] { 165, 145 }; + public static ReadOnlySpan Vp9Cat3Prob => new byte[] { 173, 148, 140 }; + public static ReadOnlySpan Vp9Cat4Prob => new byte[] { 176, 155, 140, 135 }; + public static ReadOnlySpan Vp9Cat5Prob => new byte[] { 180, 157, 141, 134, 130 }; + public static ReadOnlySpan Vp9Cat6Prob => new byte[] { 254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129 }; - public static readonly byte[] Vp9Cat6ProbHigh12 = new byte[] + public static ReadOnlySpan Vp9Cat6ProbHigh12 => new byte[] { 255, 255, 255, 255, 254, 254, 54, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129 }; @@ -1131,12 +1129,12 @@ namespace Ryujinx.Graphics.Nvdec.Vp9 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, }; - private static readonly byte[] Vp9CoefbandTrans4X4 = new byte[] + private static ReadOnlySpan Vp9CoefbandTrans4X4 => new byte[] { 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, }; - public static byte[] get_band_translate(TxSize txSize) + public static ReadOnlySpan get_band_translate(TxSize txSize) { return txSize == TxSize.Tx4x4 ? Vp9CoefbandTrans4X4 : Vp9CoefbandTrans8X8Plus; }