Skip to content

Commit f8d17ad

Browse files
committed
Use ReadOnlySpan for constant data
1 parent f2772dc commit f8d17ad

6 files changed

Lines changed: 41 additions & 39 deletions

File tree

AssetRipper.TextureDecoder/Astc/AstcDecoder.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ private static ulong BitReverseU64(ulong d, int bits)
883883
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
884884
private static int GetBits(ReadOnlySpan<byte> input, int bit, int len)
885885
{
886-
ReadOnlySpan<byte> slice = input[(bit / 8)..];
886+
ReadOnlySpan<byte> slice = input[(bit / 8)..];
887887
int bitBuffer;
888888
if (slice.Length >= sizeof(int))
889889
{
@@ -894,7 +894,7 @@ private static int GetBits(ReadOnlySpan<byte> input, int bit, int len)
894894
Span<byte> temp = stackalloc byte[sizeof(int)];
895895
slice.CopyTo(temp);
896896
bitBuffer = BinaryPrimitives.ReadInt32LittleEndian(temp);
897-
}
897+
}
898898
return (bitBuffer >> (bit % 8)) & ((1 << len) - 1);
899899
}
900900

@@ -996,10 +996,12 @@ private static void SetEndpointBlueClamp(Span<int> endpoint, int r1, int g1, int
996996
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
997997
private static byte SelectColor(int v0, int v1, int weight)
998998
{
999-
return (byte)(((((v0 << 8 | v0) * (64 - weight) + (v1 << 8 | v1) * weight + 32) >> 6) * 255 + 32768) / 65536);
999+
const int SignAdjustment = short.MaxValue + 1;
1000+
const int MaxValue = ushort.MaxValue + 1;
1001+
return (byte)(((((v0 << 8 | v0) * (64 - weight) + (v1 << 8 | v1) * weight + 32) >> 6) * byte.MaxValue + SignAdjustment) / MaxValue);
10001002
}
10011003

1002-
private static readonly byte[] BitReverseTable =
1004+
private static ReadOnlySpan<byte> BitReverseTable =>
10031005
[
10041006
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
10051007
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
@@ -1019,30 +1021,30 @@ private static byte SelectColor(int v0, int v1, int weight)
10191021
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
10201022
];
10211023

1022-
private static readonly int[] WeightPrecTableA = [0, 0, 0, 3, 0, 5, 3, 0, 0, 0, 5, 3, 0, 5, 3, 0];
1023-
private static readonly int[] WeightPrecTableB = [0, 0, 1, 0, 2, 0, 1, 3, 0, 0, 1, 2, 4, 2, 3, 5];
1024+
private static ReadOnlySpan<int> WeightPrecTableA => [0, 0, 0, 3, 0, 5, 3, 0, 0, 0, 5, 3, 0, 5, 3, 0];
1025+
private static ReadOnlySpan<int> WeightPrecTableB => [0, 0, 1, 0, 2, 0, 1, 3, 0, 0, 1, 2, 4, 2, 3, 5];
10241026

1025-
private static readonly int[] CemTableA = [0, 3, 5, 0, 3, 5, 0, 3, 5, 0, 3, 5, 0, 3, 5, 0, 3, 0, 0];
1026-
private static readonly int[] CemTableB = [8, 6, 5, 7, 5, 4, 6, 4, 3, 5, 3, 2, 4, 2, 1, 3, 1, 2, 1];
1027+
private static ReadOnlySpan<int> CemTableA => [0, 3, 5, 0, 3, 5, 0, 3, 5, 0, 3, 5, 0, 3, 5, 0, 3, 0, 0];
1028+
private static ReadOnlySpan<int> CemTableB => [8, 6, 5, 7, 5, 4, 6, 4, 3, 5, 3, 2, 4, 2, 1, 3, 1, 2, 1];
10271029

1028-
private static readonly int[] DImt = [0, 2, 4, 5, 7];
1029-
private static readonly int[] DImq = [0, 3, 5];
1030-
private static readonly int[] DITritsTable =
1030+
private static ReadOnlySpan<int> DImt => [0, 2, 4, 5, 7];
1031+
private static ReadOnlySpan<int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, 3, 3, 4, 4,
10431045
];
10441046

1045-
private static readonly int[] DETritsTable = [0, 204, 93, 44, 22, 11, 5];
1046-
private static readonly int[] DEQuintsTable = [0, 113, 54, 26, 13, 6];
1047+
private static ReadOnlySpan<int> DETritsTable => [0, 204, 93, 44, 22, 11, 5];
1048+
private static ReadOnlySpan<int> DEQuintsTable => [0, 113, 54, 26, 13, 6];
10471049
}
10481050
}

AssetRipper.TextureDecoder/Bc/Bc6hTables.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ internal static class Bc6hTables
211211
]
212212
];
213213

214-
internal static int[] AWeight3 { get; } = [0, 9, 18, 27, 37, 46, 55, 64];
214+
internal static ReadOnlySpan<int> AWeight3 => [0, 9, 18, 27, 37, 46, 55, 64];
215215

216-
internal static int[] AWeight4 { get; } = [0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64];
216+
internal static ReadOnlySpan<int> AWeight4 => [0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64];
217217
}

AssetRipper.TextureDecoder/Bc/Bc7Tables.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,11 +789,11 @@ internal static class Bc7Tables
789789
]
790790
];
791791

792-
internal static int[] AWeight2 { get; } = [0, 21, 43, 64];
792+
internal static ReadOnlySpan<int> AWeight2 => [0, 21, 43, 64];
793793

794-
internal static int[] AWeight3 { get; } = [0, 9, 18, 27, 37, 46, 55, 64];
794+
internal static ReadOnlySpan<int> AWeight3 => [0, 9, 18, 27, 37, 46, 55, 64];
795795

796-
internal static int[] AWeight4 { get; } = [0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64];
796+
internal static ReadOnlySpan<int> AWeight4 => [0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64];
797797

798798
internal const byte bcdec_bc7_sModeHasPBits = 0b11001011;
799799
}

AssetRipper.TextureDecoder/Bc/BcHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,8 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
707707
// Determine weights tables
708708
int indexBits = (mode == 0 || mode == 1) ? 3 : ((mode == 6) ? 4 : 2);
709709
int indexBits2 = (mode == 4) ? 3 : ((mode == 5) ? 2 : 0);
710-
int[] weights = (indexBits == 2) ? Bc7Tables.AWeight2 : ((indexBits == 3) ? Bc7Tables.AWeight3 : Bc7Tables.AWeight4);
711-
int[] weights2 = (indexBits2 == 2) ? Bc7Tables.AWeight2 : Bc7Tables.AWeight3;
710+
ReadOnlySpan<int> weights = (indexBits == 2) ? Bc7Tables.AWeight2 : ((indexBits == 3) ? Bc7Tables.AWeight3 : Bc7Tables.AWeight4);
711+
ReadOnlySpan<int> weights2 = (indexBits2 == 2) ? Bc7Tables.AWeight2 : Bc7Tables.AWeight3;
712712

713713
// Quite inconvenient that indices aren't interleaved so we have to make 2 passes here
714714
// Pass #1: collecting color indices

AssetRipper.TextureDecoder/Etc/EtcDecoder.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ private static void DecodeEac11Block(Span<byte> output, int @base)
805805
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
806806
private static void DecodeEac11Block(Span<byte> output, int @base, int ti, int mul, ulong l)
807807
{
808-
ReadOnlySpan<sbyte> table = Etc2AlphaModTable.AsSpan(ti * 8, 8);
808+
ReadOnlySpan<sbyte> table = Etc2AlphaModTable.Slice(ti * 8, 8);
809809
for (int i = 0; i < 16; i++, l >>= 3)
810810
{
811811
int val = @base + mul * table[unchecked((int)(l & 0b111))];
@@ -849,14 +849,14 @@ private static ulong Get6SwapedBytes(ReadOnlySpan<byte> data)
849849
return data[7] | (uint)data[6] << 8 | (uint)data[5] << 16 | (uint)data[4] << 24 | (ulong)data[3] << 32 | (ulong)data[2] << 40;
850850
}
851851

852-
private static readonly byte[] WriteOrderTable = [0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15];
853-
private static readonly byte[] WriteOrderTableRev = [15, 11, 7, 3, 14, 10, 6, 2, 13, 9, 5, 1, 12, 8, 4, 0];
854-
private static readonly int[] Etc1SubblockTable =
852+
private static ReadOnlySpan<byte> WriteOrderTable => [0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15];
853+
private static ReadOnlySpan<byte> WriteOrderTableRev => [15, 11, 7, 3, 14, 10, 6, 2, 13, 9, 5, 1, 12, 8, 4, 0];
854+
private static ReadOnlySpan<int> Etc1SubblockTable =>
855855
[
856856
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
857857
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1,
858858
];
859-
private static readonly int[] Etc1ModifierTable =
859+
private static ReadOnlySpan<int> Etc1ModifierTable =>
860860
[
861861
2, 8, -2, -8,
862862
5, 17, -5, -17,
@@ -867,7 +867,7 @@ private static ulong Get6SwapedBytes(ReadOnlySpan<byte> data)
867867
33, 106, -33, -106,
868868
47, 183, -47, -183,
869869
];
870-
private static readonly int[] PunchthroughModifierTable =
870+
private static ReadOnlySpan<int> PunchthroughModifierTable =>
871871
[
872872
0, 8, 0, -8,
873873
0, 17, 0, -17,
@@ -878,8 +878,8 @@ private static ulong Get6SwapedBytes(ReadOnlySpan<byte> data)
878878
0, 106, 0, -106,
879879
0, 183, 0, -183,
880880
];
881-
private static readonly byte[] Etc2DistanceTable = [3, 6, 11, 16, 23, 32, 41, 64];
882-
private static readonly sbyte[] Etc2AlphaModTable =
881+
private static ReadOnlySpan<byte> Etc2DistanceTable => [3, 6, 11, 16, 23, 32, 41, 64];
882+
private static ReadOnlySpan<sbyte> Etc2AlphaModTable =>
883883
[
884884
-3, -6, -9, -15, 2, 5, 8, 14,
885885
-3, -7, -10, -13, 2, 6, 9, 12,
@@ -898,6 +898,6 @@ private static ulong Get6SwapedBytes(ReadOnlySpan<byte> data)
898898
-4, -6, -8, -9, 3, 5, 7, 8,
899899
-3, -5, -7, -9, 2, 4, 6, 8,
900900
];
901-
private static readonly uint[] PunchthroughMaskTable = [0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF];
901+
private static ReadOnlySpan<uint> PunchthroughMaskTable => [0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF];
902902
}
903903
}

AssetRipper.TextureDecoder/Pvrtc/PvrtcDecoder.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,36 +217,36 @@ private static void GetModulationValue(int x, int y, bool do2bitMode, ReadOnlySp
217217
int modVal;
218218
if (modulationModes[y * 16 + x] == 0)
219219
{
220-
modVal = m_repVals0[modulationVals[y * 16 + x]];
220+
modVal = RepVals0[modulationVals[y * 16 + x]];
221221
}
222222
else if (do2bitMode)
223223
{
224224
// if this is a stored value
225225
if (((x ^ y) & 1) == 0)
226226
{
227-
modVal = m_repVals0[modulationVals[y * 16 + x]];
227+
modVal = RepVals0[modulationVals[y * 16 + x]];
228228
}
229229
// else average from the neighbours if H&V interpolation..
230230
else if (modulationModes[y * 16 + x] == 1)
231231
{
232-
modVal = (m_repVals0[modulationVals[(y - 1) * 16 + x]] + m_repVals0[modulationVals[(y + 1) * 16 + x]] +
233-
m_repVals0[modulationVals[y * 16 + x - 1]] + m_repVals0[modulationVals[y * 16 + x + 1]] + 2) / 4;
232+
modVal = (RepVals0[modulationVals[(y - 1) * 16 + x]] + RepVals0[modulationVals[(y + 1) * 16 + x]] +
233+
RepVals0[modulationVals[y * 16 + x - 1]] + RepVals0[modulationVals[y * 16 + x + 1]] + 2) / 4;
234234
}
235235
// else if H-Only
236236
else if (modulationModes[y * 16 + x] == 2)
237237
{
238-
modVal = (m_repVals0[modulationVals[y * 16 + x - 1]] + m_repVals0[modulationVals[y * 16 + x + 1]] + 1) / 2;
238+
modVal = (RepVals0[modulationVals[y * 16 + x - 1]] + RepVals0[modulationVals[y * 16 + x + 1]] + 1) / 2;
239239
}
240240
// else it's V-Only
241241
else
242242
{
243-
modVal = (m_repVals0[modulationVals[(y - 1) * 16 + x]] + m_repVals0[modulationVals[(y + 1) * 16 + x]] + 1) / 2;
243+
modVal = (RepVals0[modulationVals[(y - 1) * 16 + x]] + RepVals0[modulationVals[(y + 1) * 16 + x]] + 1) / 2;
244244
}
245245
}
246246
// else it's 4BPP and PT encoding
247247
else
248248
{
249-
modVal = m_repVals1[modulationVals[y * 16 + x]];
249+
modVal = RepVals1[modulationVals[y * 16 + x]];
250250
doPT = modulationVals[y * 16 + x] == PTIndex;
251251
}
252252

@@ -487,7 +487,7 @@ private static int LimitCoord(int value, int size)
487487
private const int BlockX2bpp = 8;
488488
private const int BlockX4bpp = 4;
489489

490-
private static readonly int[] m_repVals0 = [0, 3, 5, 8];
491-
private static readonly int[] m_repVals1 = [0, 4, 4, 8];
490+
private static ReadOnlySpan<int> RepVals0 => [0, 3, 5, 8];
491+
private static ReadOnlySpan<int> RepVals1 => [0, 4, 4, 8];
492492
}
493493
}

0 commit comments

Comments
 (0)