aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Texture/Astc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.Graphics.Texture/Astc')
-rw-r--r--src/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs908
-rw-r--r--src/Ryujinx.Graphics.Texture/Astc/AstcDecoderException.cs2
-rw-r--r--src/Ryujinx.Graphics.Texture/Astc/AstcPixel.cs2
-rw-r--r--src/Ryujinx.Graphics.Texture/Astc/BitStream128.cs9
-rw-r--r--src/Ryujinx.Graphics.Texture/Astc/Bits.cs16
-rw-r--r--src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs54
6 files changed, 547 insertions, 444 deletions
diff --git a/src/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs b/src/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs
index 80683d17..6f633e4a 100644
--- a/src/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs
+++ b/src/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs
@@ -94,8 +94,8 @@ namespace Ryujinx.Graphics.Texture.Astc
public int StartBlock { get; set; }
public int OutputByteOffset { get; set; }
- public int TotalBlockCount => BlockCountX * BlockCountY * ImageSizeZ;
- public int PixelCount => ImageSizeX * ImageSizeY * ImageSizeZ;
+ public readonly int TotalBlockCount => BlockCountX * BlockCountY * ImageSizeZ;
+ public readonly int PixelCount => ImageSizeX * ImageSizeY * ImageSizeZ;
}
public static int QueryDecompressedSize(int sizeX, int sizeY, int sizeZ, int levelCount, int layerCount)
@@ -133,7 +133,7 @@ namespace Ryujinx.Graphics.Texture.Astc
AstcLevel levelInfo = GetLevelInfo(index);
- WriteDecompressedBlock(decompressedBytes, OutputBuffer.Span.Slice(levelInfo.OutputByteOffset),
+ WriteDecompressedBlock(decompressedBytes, OutputBuffer.Span[levelInfo.OutputByteOffset..],
index - levelInfo.StartBlock, levelInfo);
}
@@ -171,7 +171,7 @@ namespace Ryujinx.Graphics.Texture.Astc
for (int i = 0; i < outputPixelsY; i++)
{
ReadOnlySpan<byte> blockRow = block.Slice(inputOffset, outputPixelsX * 4);
- Span<byte> outputRow = outputBuffer.Slice(outputOffset);
+ Span<byte> outputRow = outputBuffer[outputOffset..];
blockRow.CopyTo(outputRow);
inputOffset += BlockSizeX * 4;
@@ -189,7 +189,7 @@ namespace Ryujinx.Graphics.Texture.Astc
public bool VoidExtentLdr;
public bool VoidExtentHdr;
- public int GetPackedBitSize()
+ public readonly int GetPackedBitSize()
{
// How many indices do we have?
int indices = Height * Width;
@@ -204,7 +204,7 @@ namespace Ryujinx.Graphics.Texture.Astc
return intEncoded.GetBitLength(indices);
}
- public int GetNumWeightValues()
+ public readonly int GetNumWeightValues()
{
int ret = Width * Height;
@@ -230,7 +230,7 @@ namespace Ryujinx.Graphics.Texture.Astc
{
byte[] output = new byte[QueryDecompressedSize(width, height, depth, levels, layers)];
- AstcDecoder decoder = new AstcDecoder(data, output, blockWidth, blockHeight, width, height, depth, levels, layers);
+ AstcDecoder decoder = new(data, output, blockWidth, blockHeight, width, height, depth, levels, layers);
for (int i = 0; i < decoder.TotalBlockCount; i++)
{
@@ -253,7 +253,7 @@ namespace Ryujinx.Graphics.Texture.Astc
int levels,
int layers)
{
- AstcDecoder decoder = new AstcDecoder(data, outputBuffer, blockWidth, blockHeight, width, height, depth, levels, layers);
+ AstcDecoder decoder = new(data, outputBuffer, blockWidth, blockHeight, width, height, depth, levels, layers);
for (int i = 0; i < decoder.TotalBlockCount; i++)
{
@@ -274,7 +274,7 @@ namespace Ryujinx.Graphics.Texture.Astc
int levels,
int layers)
{
- AstcDecoder decoder = new AstcDecoder(data, outputBuffer, blockWidth, blockHeight, width, height, depth, levels, layers);
+ AstcDecoder decoder = new(data, outputBuffer, blockWidth, blockHeight, width, height, depth, levels, layers);
// Lazy parallelism
Enumerable.Range(0, decoder.TotalBlockCount).AsParallel().ForAll(x => decoder.ProcessBlock(x));
@@ -295,7 +295,7 @@ namespace Ryujinx.Graphics.Texture.Astc
{
byte[] output = new byte[QueryDecompressedSize(width, height, depth, levels, layers)];
- AstcDecoder decoder = new AstcDecoder(data, output, blockWidth, blockHeight, width, height, depth, levels, layers);
+ AstcDecoder decoder = new(data, output, blockWidth, blockHeight, width, height, depth, levels, layers);
Enumerable.Range(0, decoder.TotalBlockCount).AsParallel().ForAll(x => decoder.ProcessBlock(x));
@@ -310,7 +310,7 @@ namespace Ryujinx.Graphics.Texture.Astc
int blockWidth,
int blockHeight)
{
- BitStream128 bitStream = new BitStream128(inputBlock);
+ BitStream128 bitStream = new(inputBlock);
DecodeBlockInfo(ref bitStream, out TexelWeightParams texelParams);
@@ -359,7 +359,7 @@ namespace Ryujinx.Graphics.Texture.Astc
Span<uint> colorEndpointMode = stackalloc uint[4];
- BitStream128 colorEndpointStream = new BitStream128();
+ BitStream128 colorEndpointStream = new();
// Read extra config data...
uint baseColorEndpointMode = 0;
@@ -388,10 +388,18 @@ namespace Ryujinx.Graphics.Texture.Astc
{
switch (numberPartitions)
{
- case 2: extraColorEndpointModeBits += 2; break;
- case 3: extraColorEndpointModeBits += 5; break;
- case 4: extraColorEndpointModeBits += 8; break;
- default: Debug.Assert(false); break;
+ case 2:
+ extraColorEndpointModeBits += 2;
+ break;
+ case 3:
+ extraColorEndpointModeBits += 5;
+ break;
+ case 4:
+ extraColorEndpointModeBits += 8;
+ break;
+ default:
+ Debug.Assert(false);
+ break;
}
}
@@ -448,7 +456,12 @@ namespace Ryujinx.Graphics.Texture.Astc
for (int i = 0; i < numberPartitions; i++)
{
colorEndpointMode[i] = baseMode;
- if (!(c[i])) colorEndpointMode[i] -= 1;
+
+ if (!(c[i]))
+ {
+ colorEndpointMode[i] -= 1;
+ }
+
colorEndpointMode[i] <<= 2;
colorEndpointMode[i] |= m[i];
}
@@ -475,7 +488,12 @@ namespace Ryujinx.Graphics.Texture.Astc
DecodeColorValues(colorValues, ref colorEndpointStream, colorEndpointMode, numberPartitions, colorDataBits);
EndPointSet endPoints;
- unsafe { _ = &endPoints; } // Skip struct initialization
+
+ unsafe
+ {
+ // Skip struct initialization
+ _ = &endPoints;
+ }
int colorValuesPosition = 0;
@@ -502,19 +520,33 @@ namespace Ryujinx.Graphics.Texture.Astc
texelWeightData[clearByteStart - 1] &= (byte)((1 << (texelParams.GetPackedBitSize() % 8)) - 1);
int cLen = 16 - clearByteStart;
- for (int i = clearByteStart; i < clearByteStart + cLen; i++) texelWeightData[i] = 0;
+ for (int i = clearByteStart; i < clearByteStart + cLen; i++)
+ {
+ texelWeightData[i] = 0;
+ }
IntegerSequence texelWeightValues;
- unsafe { _ = &texelWeightValues; } // Skip struct initialization
+
+ unsafe
+ {
+ // Skip struct initialization
+ _ = &texelWeightValues;
+ }
+
texelWeightValues.Reset();
- BitStream128 weightBitStream = new BitStream128(texelWeightData);
+ BitStream128 weightBitStream = new(texelWeightData);
IntegerEncoded.DecodeIntegerSequence(ref texelWeightValues, ref weightBitStream, texelParams.MaxWeight, texelParams.GetNumWeightValues());
// Blocks can be at most 12x12, so we can have as many as 144 weights
Weights weights;
- unsafe { _ = &weights; } // Skip struct initialization
+
+ unsafe
+ {
+ // Skip struct initialization
+ _ = &weights;
+ }
UnquantizeTexelWeights(ref weights, ref texelWeightValues, ref texelParams, blockWidth, blockHeight);
@@ -529,7 +561,7 @@ namespace Ryujinx.Graphics.Texture.Astc
int partition = Select2dPartition(partitionIndex, i, j, numberPartitions, ((blockHeight * blockWidth) < 32));
Debug.Assert(partition < numberPartitions);
- AstcPixel pixel = new AstcPixel();
+ AstcPixel pixel = new();
for (int component = 0; component < 4; component++)
{
int component0 = endPoints.Get(partition)[0].GetComponent(component);
@@ -579,7 +611,7 @@ namespace Ryujinx.Graphics.Texture.Astc
{
if ((uint)index >= Count)
{
- throw new ArgumentOutOfRangeException();
+ throw new ArgumentOutOfRangeException(nameof(index), index, null);
}
ref int start = ref Unsafe.Add(ref _start, index * 144);
@@ -632,12 +664,18 @@ namespace Ryujinx.Graphics.Texture.Astc
byte seed11 = (byte)((rightNum >> 26) & 0xF);
byte seed12 = (byte)(((rightNum >> 30) | (rightNum << 2)) & 0xF);
- seed01 *= seed01; seed02 *= seed02;
- seed03 *= seed03; seed04 *= seed04;
- seed05 *= seed05; seed06 *= seed06;
- seed07 *= seed07; seed08 *= seed08;
- seed09 *= seed09; seed10 *= seed10;
- seed11 *= seed11; seed12 *= seed12;
+ seed01 *= seed01;
+ seed02 *= seed02;
+ seed03 *= seed03;
+ seed04 *= seed04;
+ seed05 *= seed05;
+ seed06 *= seed06;
+ seed07 *= seed07;
+ seed08 *= seed08;
+ seed09 *= seed09;
+ seed10 *= seed10;
+ seed11 *= seed11;
+ seed12 *= seed12;
int seedHash1, seedHash2, seedHash3;
@@ -654,31 +692,67 @@ namespace Ryujinx.Graphics.Texture.Astc
seedHash3 = (seed & 0x10) != 0 ? seedHash1 : seedHash2;
- seed01 >>= seedHash1; seed02 >>= seedHash2; seed03 >>= seedHash1; seed04 >>= seedHash2;
- seed05 >>= seedHash1; seed06 >>= seedHash2; seed07 >>= seedHash1; seed08 >>= seedHash2;
- seed09 >>= seedHash3; seed10 >>= seedHash3; seed11 >>= seedHash3; seed12 >>= seedHash3;
+ seed01 >>= seedHash1;
+ seed02 >>= seedHash2;
+ seed03 >>= seedHash1;
+ seed04 >>= seedHash2;
+ seed05 >>= seedHash1;
+ seed06 >>= seedHash2;
+ seed07 >>= seedHash1;
+ seed08 >>= seedHash2;
+ seed09 >>= seedHash3;
+ seed10 >>= seedHash3;
+ seed11 >>= seedHash3;
+ seed12 >>= seedHash3;
int a = seed01 * x + seed02 * y + seed11 * z + (rightNum >> 14);
int b = seed03 * x + seed04 * y + seed12 * z + (rightNum >> 10);
int c = seed05 * x + seed06 * y + seed09 * z + (rightNum >> 6);
int d = seed07 * x + seed08 * y + seed10 * z + (rightNum >> 2);
- a &= 0x3F; b &= 0x3F; c &= 0x3F; d &= 0x3F;
+ a &= 0x3F;
+ b &= 0x3F;
+ c &= 0x3F;
+ d &= 0x3F;
- if (partitionCount < 4) d = 0;
- if (partitionCount < 3) c = 0;
+ if (partitionCount < 4)
+ {
+ d = 0;
+ }
+
+ if (partitionCount < 3)
+ {
+ c = 0;
+ }
+
+ if (a >= b && a >= c && a >= d)
+ {
+ return 0;
+ }
+ else if (b >= c && b >= d)
+ {
+ return 1;
+ }
+ else if (c >= d)
+ {
+ return 2;
+ }
- if (a >= b && a >= c && a >= d) return 0;
- else if (b >= c && b >= d) return 1;
- else if (c >= d) return 2;
return 3;
}
static int Hash52(uint val)
{
- val ^= val >> 15; val -= val << 17; val += val << 7; val += val << 4;
- val ^= val >> 5; val += val << 16; val ^= val >> 7; val ^= val >> 3;
- val ^= val << 6; val ^= val >> 17;
+ val ^= val >> 15;
+ val -= val << 17;
+ val += val << 7;
+ val += val << 4;
+ val ^= val >> 5;
+ val += val << 16;
+ val ^= val >> 7;
+ val ^= val >> 3;
+ val ^= val << 6;
+ val ^= val >> 17;
return (int)val;
}
@@ -692,7 +766,12 @@ namespace Ryujinx.Graphics.Texture.Astc
{
int weightIndices = 0;
Weights unquantized;
- unsafe { _ = &unquantized; } // Skip struct initialization
+
+ unsafe
+ {
+ // Skip struct initialization
+ _ = &unquantized;
+ }
Span<IntegerEncoded> weightsList = weights.List;
Span<int> unquantized0 = unquantized[0];
@@ -713,7 +792,10 @@ namespace Ryujinx.Graphics.Texture.Astc
}
}
- if (++weightIndices >= texelParams.Width * texelParams.Height) break;
+ if (++weightIndices >= texelParams.Width * texelParams.Height)
+ {
+ break;
+ }
}
// Do infill if necessary (Section C.2.18) ...
@@ -794,100 +876,100 @@ namespace Ryujinx.Graphics.Texture.Astc
break;
case IntegerEncoded.EIntegerEncoding.Trit:
- {
- d = intEncoded.TritValue;
- Debug.Assert(d < 3);
-
- switch (bitLength)
{
- case 0:
+ d = intEncoded.TritValue;
+ Debug.Assert(d < 3);
+
+ switch (bitLength)
{
- result = d switch
- {
- 0 => 0,
- 1 => 32,
- 2 => 63,
- _ => 0
- };
+ case 0:
+ {
+ result = d switch
+ {
+ 0 => 0,
+ 1 => 32,
+ 2 => 63,
+ _ => 0
+ };
+
+ break;
+ }
- break;
- }
+ case 1:
+ {
+ c = 50;
+ break;
+ }
- case 1:
- {
- c = 50;
- break;
- }
+ case 2:
+ {
+ c = 23;
+ int b2 = (bitValue >> 1) & 1;
+ b = (b2 << 6) | (b2 << 2) | b2;
- case 2:
- {
- c = 23;
- int b2 = (bitValue >> 1) & 1;
- b = (b2 << 6) | (b2 << 2) | b2;
+ break;
+ }
- break;
- }
+ case 3:
+ {
+ c = 11;
+ int cb = (bitValue >> 1) & 3;
+ b = (cb << 5) | cb;
- case 3:
- {
- c = 11;
- int cb = (bitValue >> 1) & 3;
- b = (cb << 5) | cb;
+ break;
+ }
- break;
+ default:
+ throw new AstcDecoderException("Invalid trit encoding for texel weight.");
}
- default:
- throw new AstcDecoderException("Invalid trit encoding for texel weight.");
+ break;
}
- break;
- }
-
case IntegerEncoded.EIntegerEncoding.Quint:
- {
- d = intEncoded.QuintValue;
- Debug.Assert(d < 5);
-
- switch (bitLength)
{
- case 0:
+ d = intEncoded.QuintValue;
+ Debug.Assert(d < 5);
+
+ switch (bitLength)
{
- result = d switch
- {
- 0 => 0,
- 1 => 16,
- 2 => 32,
- 3 => 47,
- 4 => 63,
- _ => 0
- };
+ case 0:
+ {
+ result = d switch
+ {
+ 0 => 0,
+ 1 => 16,
+ 2 => 32,
+ 3 => 47,
+ 4 => 63,
+ _ => 0
+ };
+
+ break;
+ }
- break;
- }
+ case 1:
+ {
+ c = 28;
- case 1:
- {
- c = 28;
+ break;
+ }
- break;
- }
+ case 2:
+ {
+ c = 13;
+ int b2 = (bitValue >> 1) & 1;
+ b = (b2 << 6) | (b2 << 1);
- case 2:
- {
- c = 13;
- int b2 = (bitValue >> 1) & 1;
- b = (b2 << 6) | (b2 << 1);
+ break;
+ }
- break;
+ default:
+ throw new AstcDecoderException("Invalid quint encoding for texel weight.");
}
- default:
- throw new AstcDecoderException("Invalid quint encoding for texel weight.");
+ break;
}
-
- break;
- }
}
if (intEncoded.GetEncoding() != IntegerEncoded.EIntegerEncoding.JustBits && bitLength > 0)
@@ -942,160 +1024,160 @@ namespace Ryujinx.Graphics.Texture.Astc
switch (colorEndpointMode)
{
case 0:
- {
- Span<uint> val = ReadUintColorValues(2, colorValues, ref colorValuesPosition);
+ {
+ Span<uint> val = ReadUintColorValues(2, colorValues, ref colorValuesPosition);
- endPoints[0] = new AstcPixel(0xFF, (short)val[0], (short)val[0], (short)val[0]);
- endPoints[1] = new AstcPixel(0xFF, (short)val[1], (short)val[1], (short)val[1]);
+ endPoints[0] = new AstcPixel(0xFF, (short)val[0], (short)val[0], (short)val[0]);
+ endPoints[1] = new AstcPixel(0xFF, (short)val[1], (short)val[1], (short)val[1]);
- break;
- }
+ break;
+ }
case 1:
- {
- Span<uint> val = ReadUintColorValues(2, colorValues, ref colorValuesPosition);
- int l0 = (int)((val[0] >> 2) | (val[1] & 0xC0));
- int l1 = (int)Math.Min(l0 + (val[1] & 0x3F), 0xFFU);
+ {
+ Span<uint> val = ReadUintColorValues(2, colorValues, ref colorValuesPosition);
+ int l0 = (int)((val[0] >> 2) | (val[1] & 0xC0));
+ int l1 = (int)Math.Min(l0 + (val[1] & 0x3F), 0xFFU);
- endPoints[0] = new AstcPixel(0xFF, (short)l0, (short)l0, (short)l0);
- endPoints[1] = new AstcPixel(0xFF, (short)l1, (short)l1, (short)l1);
+ endPoints[0] = new AstcPixel(0xFF, (short)l0, (short)l0, (short)l0);
+ endPoints[1] = new AstcPixel(0xFF, (short)l1, (short)l1, (short)l1);
- break;
- }
+ break;
+ }
case 4:
- {
- Span<uint> val = ReadUintColorValues(4, colorValues, ref colorValuesPosition);
+ {
+ Span<uint> val = ReadUintColorValues(4, colorValues, ref colorValuesPosition);
- endPoints[0] = new AstcPixel((short)val[2], (short)val[0], (short)val[0], (short)val[0]);
- endPoints[1] = new AstcPixel((short)val[3], (short)val[1], (short)val[1], (short)val[1]);
+ endPoints[0] = new AstcPixel((short)val[2], (short)val[0], (short)val[0], (short)val[0]);
+ endPoints[1] = new AstcPixel((short)val[3], (short)val[1], (short)val[1], (short)val[1]);
- break;
- }
+ break;
+ }
case 5:
- {
- Span<int> val = ReadIntColorValues(4, colorValues, ref colorValuesPosition);
+ {
+ Span<int> val = ReadIntColorValues(4, colorValues, ref colorValuesPosition);
- Bits.BitTransferSigned(ref val[1], ref val[0]);
- Bits.BitTransferSigned(ref val[3], ref val[2]);
+ Bits.BitTransferSigned(ref val[1], ref val[0]);
+ Bits.BitTransferSigned(ref val[3], ref val[2]);
- endPoints[0] = new AstcPixel((short)val[2], (short)val[0], (short)val[0], (short)val[0]);
- endPoints[1] = new AstcPixel((short)(val[2] + val[3]), (short)(val[0] + val[1]), (short)(val[0] + val[1]), (short)(val[0] + val[1]));
+ endPoints[0] = new AstcPixel((short)val[2], (short)val[0], (short)val[0], (short)val[0]);
+ endPoints[1] = new AstcPixel((short)(val[2] + val[3]), (short)(val[0] + val[1]), (short)(val[0] + val[1]), (short)(val[0] + val[1]));
- endPoints[0].ClampByte();
- endPoints[1].ClampByte();
+ endPoints[0].ClampByte();
+ endPoints[1].ClampByte();
- break;
- }
+ break;
+ }
case 6:
- {
- Span<uint> val = ReadUintColorValues(4, colorValues, ref colorValuesPosition);
+ {
+ Span<uint> val = ReadUintColorValues(4, colorValues, ref colorValuesPosition);
- endPoints[0] = new AstcPixel(0xFF, (short)(val[0] * val[3] >> 8), (short)(val[1] * val[3] >> 8), (short)(val[2] * val[3] >> 8));
- endPoints[1] = new AstcPixel(0xFF, (short)val[0], (short)val[1], (short)val[2]);
+ endPoints[0] = new AstcPixel(0xFF, (short)(val[0] * val[3] >> 8), (short)(val[1] * val[3] >> 8), (short)(val[2] * val[3] >> 8));
+ endPoints[1] = new AstcPixel(0xFF, (short)val[0], (short)val[1], (short)val[2]);
- break;
- }
+ break;
+ }
case 8:
- {
- Span<uint> val = ReadUintColorValues(6, colorValues, ref colorValuesPosition);
-
- if (val[1] + val[3] + val[5] >= val[0] + val[2] + val[4])
- {
- endPoints[0] = new AstcPixel(0xFF, (short)val[0], (short)val[2], (short)val[4]);
- endPoints[1] = new AstcPixel(0xFF, (short)val[1], (short)val[3], (short)val[5]);
- }
- else
{
- endPoints[0] = AstcPixel.BlueContract(0xFF, (short)val[1], (short)val[3], (short)val[5]);
- endPoints[1] = AstcPixel.BlueContract(0xFF, (short)val[0], (short)val[2], (short)val[4]);
- }
+ Span<uint> val = ReadUintColorValues(6, colorValues, ref colorValuesPosition);
- break;
- }
+ if (val[1] + val[3] + val[5] >= val[0] + val[2] + val[4])
+ {
+ endPoints[0] = new AstcPixel(0xFF, (short)val[0], (short)val[2], (short)val[4]);
+ endPoints[1] = new AstcPixel(0xFF, (short)val[1], (short)val[3], (short)val[5]);
+ }
+ else
+ {
+ endPoints[0] = AstcPixel.BlueContract(0xFF, (short)val[1], (short)val[3], (short)val[5]);
+ endPoints[1] = AstcPixel.BlueContract(0xFF, (short)val[0], (short)val[2], (short)val[4]);
+ }
+
+ break;
+ }
case 9:
- {
- Span<int> val = ReadIntColorValues(6, colorValues, ref colorValuesPosition);
+ {
+ Span<int> val = ReadIntColorValues(6, colorValues, ref colorValuesPosition);
- Bits.BitTransferSigned(ref val[1], ref val[0]);
- Bits.BitTransferSigned(ref val[3], ref val[2]);
- Bits.BitTransferSigned(ref val[5], ref val[4]);
+ Bits.BitTransferSigned(ref val[1], ref val[0]);
+ Bits.BitTransferSigned(ref val[3], ref val[2]);
+ Bits.BitTransferSigned(ref val[5], ref val[4]);
- if (val[1] + val[3] + val[5] >= 0)
- {
- endPoints[0] = new AstcPixel(0xFF, (short)val[0], (short)val[2], (short)val[4]);
- endPoints[1] = new AstcPixel(0xFF, (short)(val[0] + val[1]), (short)(val[2] + val[3]), (short)(val[4] + val[5]));
- }
- else
- {
- endPoints[0] = AstcPixel.BlueContract(0xFF, val[0] + val[1], val[2] + val[3], val[4] + val[5]);
- endPoints[1] = AstcPixel.BlueContract(0xFF, val[0], val[2], val[4]);
- }
+ if (val[1] + val[3] + val[5] >= 0)
+ {
+ endPoints[0] = new AstcPixel(0xFF, (short)val[0], (short)val[2], (short)val[4]);
+ endPoints[1] = new AstcPixel(0xFF, (short)(val[0] + val[1]), (short)(val[2] + val[3]), (short)(val[4] + val[5]));
+ }
+ else
+ {
+ endPoints[0] = AstcPixel.BlueContract(0xFF, val[0] + val[1], val[2] + val[3], val[4] + val[5]);
+ endPoints[1] = AstcPixel.BlueContract(0xFF, val[0], val[2], val[4]);
+ }
- endPoints[0].ClampByte();
- endPoints[1].ClampByte();
+ endPoints[0].ClampByte();
+ endPoints[1].ClampByte();
- break;
- }
+ break;
+ }
case 10:
- {
- Span<uint> val = ReadUintColorValues(6, colorValues, ref colorValuesPosition);
+ {
+ Span<uint> val = ReadUintColorValues(6, colorValues, ref colorValuesPosition);
- endPoints[0] = new AstcPixel((short)val[4], (short)(val[0] * val[3] >> 8), (short)(val[1] * val[3] >> 8), (short)(val[2] * val[3] >> 8));
- endPoints[1] = new AstcPixel((short)val[5], (short)val[0], (short)val[1], (short)val[2]);
+ endPoints[0] = new AstcPixel((short)val[4], (short)(val[0] * val[3] >> 8), (short)(val[1] * val[3] >> 8), (short)(val[2] * val[3] >> 8));
+ endPoints[1] = new AstcPixel((short)val[5], (short)val[0], (short)val[1], (short)val[2]);
- break;
- }
+ break;
+ }
case 12:
- {
- Span<uint> val = ReadUintColorValues(8, colorValues, ref colorValuesPosition);
-
- if (val[1] + val[3] + val[5] >= val[0] + val[2] + val[4])
{
- endPoints[0] = new AstcPixel((short)val[6], (short)val[0], (short)val[2], (short)val[4]);
- endPoints[1] = new AstcPixel((short)val[7], (short)val[1], (short)val[3], (short)val[5]);
- }
- else
- {
- endPoints[0] = AstcPixel.BlueContract((short)val[7], (short)val[1], (short)val[3], (short)val[5]);
- endPoints[1] = AstcPixel.BlueContract((short)val[6], (short)val[0], (short)val[2], (short)val[4]);
- }
+ Span<uint> val = ReadUintColorValues(8, colorValues, ref colorValuesPosition);
- break;
- }
+ if (val[1] + val[3] + val[5] >= val[0] + val[2] + val[4])
+ {
+ endPoints[0] = new AstcPixel((short)val[6], (short)val[0], (short)val[2], (short)val[4]);
+ endPoints[1] = new AstcPixel((short)val[7], (short)val[1], (short)val[3], (short)val[5]);
+ }
+ else
+ {
+ endPoints[0] = AstcPixel.BlueContract((short)val[7], (short)val[1], (short)val[3], (short)val[5]);
+ endPoints[1] = AstcPixel.BlueContract((short)val[6], (short)val[0], (short)val[2], (short)val[4]);
+ }
+
+ break;
+ }
case 13:
- {
- Span<int> val = ReadIntColorValues(8, colorValues, ref colorValuesPosition);
+ {
+ Span<int> val = ReadIntColorValues(8, colorValues, ref colorValuesPosition);
- Bits.BitTransferSigned(ref val[1], ref val[0]);
- Bits.BitTransferSigned(ref val[3], ref val[2]);
- Bits.BitTransferSigned(ref val[5], ref val[4]);
- Bits.BitTransferSigned(ref val[7], ref val[6]);
+ Bits.BitTransferSigned(ref val[1], ref val[0]);
+ Bits.BitTransferSigned(ref val[3], ref val[2]);
+ Bits.BitTransferSigned(ref val[5], ref val[4]);
+ Bits.BitTransferSigned(ref val[7], ref val[6]);
- if (val[1] + val[3] + val[5] >= 0)
- {
- endPoints[0] = new AstcPixel((short)val[6], (short)val[0], (short)val[2], (short)val[4]);
- endPoints[1] = new AstcPixel((short)(val[7] + val[6]), (short)(val[0] + val[1]), (short)(val[2] + val[3]), (short)(val[4] + val[5]));
- }
- else
- {
- endPoints[0] = AstcPixel.BlueContract(val[6] + val[7], val[0] + val[1], val[2] + val[3], val[4] + val[5]);
- endPoints[1] = AstcPixel.BlueContract(val[6], val[0], val[2], val[4]);
- }
+ if (val[1] + val[3] + val[5] >= 0)
+ {
+ endPoints[0] = new AstcPixel((short)val[6], (short)val[0], (short)val[2], (short)val[4]);
+ endPoints[1] = new AstcPixel((short)(val[7] + val[6]), (short)(val[0] + val[1]), (short)(val[2] + val[3]), (short)(val[4] + val[5]));
+ }
+ else
+ {
+ endPoints[0] = AstcPixel.BlueContract(val[6] + val[7], val[0] + val[1], val[2] + val[3], val[4] + val[5]);
+ endPoints[1] = AstcPixel.BlueContract(val[6], val[0], val[2], val[4]);
+ }
- endPoints[0].ClampByte();
- endPoints[1].ClampByte();
+ endPoints[0].ClampByte();
+ endPoints[1].ClampByte();
- break;
- }
+ break;
+ }
default:
throw new AstcDecoderException("Unsupported color endpoint mode (is it HDR?)");
@@ -1146,7 +1228,13 @@ namespace Ryujinx.Graphics.Texture.Astc
// We now have enough to decode our integer sequence.
IntegerSequence integerEncodedSequence;
- unsafe { _ = &integerEncodedSequence; } // Skip struct initialization
+
+ unsafe
+ {
+ // Skip struct initialization
+ _ = &integerEncodedSequence;
+ }
+
integerEncodedSequence.Reset();
IntegerEncoded.DecodeIntegerSequence(ref integerEncodedSequence, ref colorBitStream, range, numberValues);
@@ -1162,148 +1250,148 @@ namespace Ryujinx.Graphics.Texture.Astc
Debug.Assert(bitLength >= 1);
- int a = 0, b = 0, c = 0, d = 0;
+ int b = 0, c = 0, d = 0;
// A is just the lsb replicated 9 times.
- a = Bits.Replicate(bitValue & 1, 1, 9);
+ int a = Bits.Replicate(bitValue & 1, 1, 9);
switch (intEncoded.GetEncoding())
{
case IntegerEncoded.EIntegerEncoding.JustBits:
- {
- outputValues[outputIndices++] = Bits.Replicate(bitValue, bitLength, 8);
+ {
+ outputValues[outputIndices++] = Bits.Replicate(bitValue, bitLength, 8);
- break;
- }
+ break;
+ }
case IntegerEncoded.EIntegerEncoding.Trit:
- {
- d = intEncoded.TritValue;
-
- switch (bitLength)
{
- case 1:
- {
- c = 204;
-
- break;
- }
-
- case 2:
- {
- c = 93;
- // B = b000b0bb0
- int b2 = (bitValue >> 1) & 1;
- b = (b2 << 8) | (b2 << 4) | (b2 << 2) | (b2 << 1);
-
- break;
- }
-
- case 3:
- {
- c = 44;
- // B = cb000cbcb
- int cb = (bitValue >> 1) & 3;
- b = (cb << 7) | (cb << 2) | cb;
-
- break;
- }
-
+ d = intEncoded.TritValue;
- case 4:
+ switch (bitLength)
{
- c = 22;
- // B = dcb000dcb
- int dcb = (bitValue >> 1) & 7;
- b = (dcb << 6) | dcb;
-
- break;
- }
-
- case 5:
- {
- c = 11;
- // B = edcb000ed
- int edcb = (bitValue >> 1) & 0xF;
- b = (edcb << 5) | (edcb >> 2);
-
- break;
+ case 1:
+ {
+ c = 204;
+
+ break;
+ }
+
+ case 2:
+ {
+ c = 93;
+ // B = b000b0bb0
+ int b2 = (bitValue >> 1) & 1;
+ b = (b2 << 8) | (b2 << 4) | (b2 << 2) | (b2 << 1);
+
+ break;
+ }
+
+ case 3:
+ {
+ c = 44;
+ // B = cb000cbcb
+ int cb = (bitValue >> 1) & 3;
+ b = (cb << 7) | (cb << 2) | cb;
+
+ break;
+ }
+
+
+ case 4:
+ {
+ c = 22;
+ // B = dcb000dcb
+ int dcb = (bitValue >> 1) & 7;
+ b = (dcb << 6) | dcb;
+
+ break;
+ }
+
+ case 5:
+ {
+ c = 11;
+ // B = edcb000ed
+ int edcb = (bitValue >> 1) & 0xF;
+ b = (edcb << 5) | (edcb >> 2);
+
+ break;
+ }
+
+ case 6:
+ {
+ c = 5;
+ // B = fedcb000f
+ int fedcb = (bitValue >> 1) & 0x1F;
+ b = (fedcb << 4) | (fedcb >> 4);
+
+ break;
+ }
+
+ default:
+ throw new AstcDecoderException("Unsupported trit encoding for color values.");
}
- case 6:
- {
- c = 5;
- // B = fedcb000f
- int fedcb = (bitValue >> 1) & 0x1F;
- b = (fedcb << 4) | (fedcb >> 4);
-
- break;
- }
-
- default:
- throw new AstcDecoderException("Unsupported trit encoding for color values.");
+ break;
}
- break;
- }
-
case IntegerEncoded.EIntegerEncoding.Quint:
- {
- d = intEncoded.QuintValue;
-
- switch (bitLength)
{
- case 1:
- {
- c = 113;
+ d = intEncoded.QuintValue;
- break;
- }
-
- case 2:
+ switch (bitLength)
{
- c = 54;
- // B = b0000bb00
- int b2 = (bitValue >> 1) & 1;
- b = (b2 << 8) | (b2 << 3) | (b2 << 2);
-
- break;
+ case 1:
+ {
+ c = 113;
+
+ break;
+ }
+
+ case 2:
+ {
+ c = 54;
+ // B = b0000bb00
+ int b2 = (bitValue >> 1) & 1;
+ b = (b2 << 8) | (b2 << 3) | (b2 << 2);
+
+ break;
+ }
+
+ case 3:
+ {
+ c = 26;
+ // B = cb0000cbc
+ int cb = (bitValue >> 1) & 3;
+ b = (cb << 7) | (cb << 1) | (cb >> 1);
+
+ break;
+ }
+
+ case 4:
+ {
+ c = 13;
+ // B = dcb0000dc
+ int dcb = (bitValue >> 1) & 7;
+ b = (dcb << 6) | (dcb >> 1);
+
+ break;
+ }
+
+ case 5:
+ {
+ c = 6;
+ // B = edcb0000e
+ int edcb = (bitValue >> 1) & 0xF;
+ b = (edcb << 5) | (edcb >> 3);
+
+ break;
+ }
+
+ default:
+ throw new AstcDecoderException("Unsupported quint encoding for color values.");
}
-
- case 3:
- {
- c = 26;
- // B = cb0000cbc
- int cb = (bitValue >> 1) & 3;
- b = (cb << 7) | (cb << 1) | (cb >> 1);
-
- break;
- }
-
- case 4:
- {
- c = 13;
- // B = dcb0000dc
- int dcb = (bitValue >> 1) & 7;
- b = (dcb << 6) | (dcb >> 1);
-
- break;
- }
-
- case 5:
- {
- c = 6;
- // B = edcb0000e
- int edcb = (bitValue >> 1) & 0xF;
- b = (edcb << 5) | (edcb >> 3);
-
- break;
- }
-
- default:
- throw new AstcDecoderException("Unsupported quint encoding for color values.");
+ break;
}
- break;
- }
}
if (intEncoded.GetEncoding() != IntegerEncoded.EIntegerEncoding.JustBits)
@@ -1493,105 +1581,105 @@ namespace Ryujinx.Graphics.Texture.Astc
switch (layout)
{
case 0:
- {
- int a = (modeBits >> 5) & 0x3;
- int b = (modeBits >> 7) & 0x3;
+ {
+ int a = (modeBits >> 5) & 0x3;
+ int b = (modeBits >> 7) & 0x3;
- texelParams.Width = b + 4;
- texelParams.Height = a + 2;
+ texelParams.Width = b + 4;
+ texelParams.Height = a + 2;
- break;
- }
+ break;
+ }
case 1:
- {
- int a = (modeBits >> 5) & 0x3;
- int b = (modeBits >> 7) & 0x3;
+ {
+ int a = (modeBits >> 5) & 0x3;
+ int b = (modeBits >> 7) & 0x3;
- texelParams.Width = b + 8;
- texelParams.Height = a + 2;
+ texelParams.Width = b + 8;
+ texelParams.Height = a + 2;
- break;
- }
+ break;
+ }
case 2:
- {
- int a = (modeBits >> 5) & 0x3;
- int b = (modeBits >> 7) & 0x3;
+ {
+ int a = (modeBits >> 5) & 0x3;
+ int b = (modeBits >> 7) & 0x3;
- texelParams.Width = a + 2;
- texelParams.Height = b + 8;
+ texelParams.Width = a + 2;
+ texelParams.Height = b + 8;
- break;
- }
+ break;
+ }
case 3:
- {
- int a = (modeBits >> 5) & 0x3;
- int b = (modeBits >> 7) & 0x1;
+ {
+ int a = (modeBits >> 5) & 0x3;
+ int b = (modeBits >> 7) & 0x1;
- texelParams.Width = a + 2;
- texelParams.Height = b + 6;
+ texelParams.Width = a + 2;
+ texelParams.Height = b + 6;
- break;
- }
+ break;
+ }
case 4:
- {
- int a = (modeBits >> 5) & 0x3;
- int b = (modeBits >> 7) & 0x1;
+ {
+ int a = (modeBits >> 5) & 0x3;
+ int b = (modeBits >> 7) & 0x1;
- texelParams.Width = b + 2;
- texelParams.Height = a + 2;
+ texelParams.Width = b + 2;
+ texelParams.Height = a + 2;
- break;
- }
+ break;
+ }
case 5:
- {
- int a = (modeBits >> 5) & 0x3;
+ {
+ int a = (modeBits >> 5) & 0x3;
- texelParams.Width = 12;
- texelParams.Height = a + 2;
+ texelParams.Width = 12;
+ texelParams.Height = a + 2;
- break;
- }
+ break;
+ }
case 6:
- {
- int a = (modeBits >> 5) & 0x3;
+ {
+ int a = (modeBits >> 5) & 0x3;
- texelParams.Width = a + 2;
- texelParams.Height = 12;
+ texelParams.Width = a + 2;
+ texelParams.Height = 12;
- break;
- }
+ break;
+ }
case 7:
- {
- texelParams.Width = 6;
- texelParams.Height = 10;
+ {
+ texelParams.Width = 6;
+ texelParams.Height = 10;
- break;
- }
+ break;
+ }
case 8:
- {
- texelParams.Width = 10;
- texelParams.Height = 6;
- break;
- }
+ {
+ texelParams.Width = 10;
+ texelParams.Height = 6;
+ break;
+ }
case 9:
- {
- int a = (modeBits >> 5) & 0x3;
- int b = (modeBits >> 9) & 0x3;
+ {
+ int a = (modeBits >> 5) & 0x3;
+ int b = (modeBits >> 9) & 0x3;
- texelParams.Width = a + 6;
- texelParams.Height = b + 6;
+ texelParams.Width = a + 6;
+ texelParams.Height = b + 6;
- break;
- }
+ break;
+ }
default:
// Don't know this layout...
diff --git a/src/Ryujinx.Graphics.Texture/Astc/AstcDecoderException.cs b/src/Ryujinx.Graphics.Texture/Astc/AstcDecoderException.cs
index fdc48267..9ff3ddb2 100644
--- a/src/Ryujinx.Graphics.Texture/Astc/AstcDecoderException.cs
+++ b/src/Ryujinx.Graphics.Texture/Astc/AstcDecoderException.cs
@@ -6,4 +6,4 @@ namespace Ryujinx.Graphics.Texture.Astc
{
public AstcDecoderException(string exMsg) : base(exMsg) { }
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Texture/Astc/AstcPixel.cs b/src/Ryujinx.Graphics.Texture/Astc/AstcPixel.cs
index 13197714..e6ca1035 100644
--- a/src/Ryujinx.Graphics.Texture/Astc/AstcPixel.cs
+++ b/src/Ryujinx.Graphics.Texture/Astc/AstcPixel.cs
@@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.Texture.Astc
Components[index] = (short)value;
}
- public int Pack()
+ public readonly int Pack()
{
return A << 24 |
B << 16 |
diff --git a/src/Ryujinx.Graphics.Texture/Astc/BitStream128.cs b/src/Ryujinx.Graphics.Texture/Astc/BitStream128.cs
index 3bf9769f..f98a714d 100644
--- a/src/Ryujinx.Graphics.Texture/Astc/BitStream128.cs
+++ b/src/Ryujinx.Graphics.Texture/Astc/BitStream128.cs
@@ -6,7 +6,9 @@ namespace Ryujinx.Graphics.Texture.Astc
{
public struct BitStream128
{
+#pragma warning disable IDE0044 // Make field readonly
private Buffer16 _data;
+#pragma warning restore IDE0044
public int BitsLeft { get; set; }
public BitStream128(Buffer16 data)
@@ -42,7 +44,10 @@ namespace Ryujinx.Graphics.Texture.Astc
{
Debug.Assert(bitCount < 32);
- if (bitCount == 0) return;
+ if (bitCount == 0)
+ {
+ return;
+ }
ulong maskedValue = (uint)(value & ((1 << bitCount) - 1));
@@ -69,4 +74,4 @@ namespace Ryujinx.Graphics.Texture.Astc
BitsLeft += bitCount;
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Texture/Astc/Bits.cs b/src/Ryujinx.Graphics.Texture/Astc/Bits.cs
index b140a20a..91652bf1 100644
--- a/src/Ryujinx.Graphics.Texture/Astc/Bits.cs
+++ b/src/Ryujinx.Graphics.Texture/Astc/Bits.cs
@@ -29,8 +29,15 @@
public static int Replicate(int value, int numberBits, int toBit)
{
- if (numberBits == 0) return 0;
- if (toBit == 0) return 0;
+ if (numberBits == 0)
+ {
+ return 0;
+ }
+
+ if (toBit == 0)
+ {
+ return 0;
+ }
int tempValue = value & ((1 << numberBits) - 1);
int retValue = tempValue;
@@ -60,7 +67,10 @@
b |= a & 0x80;
a >>= 1;
a &= 0x3F;
- if ((a & 0x20) != 0) a -= 0x40;
+ if ((a & 0x20) != 0)
+ {
+ a -= 0x40;
+ }
}
}
}
diff --git a/src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs b/src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs
index 065de46b..56e78cc3 100644
--- a/src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs
+++ b/src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs
@@ -6,7 +6,7 @@ namespace Ryujinx.Graphics.Texture.Astc
internal struct IntegerEncoded
{
internal const int StructSize = 8;
- private static readonly IntegerEncoded[] Encodings;
+ private static readonly IntegerEncoded[] _encodings;
public enum EIntegerEncoding : byte
{
@@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Texture.Astc
Trit
}
- EIntegerEncoding _encoding;
+ readonly EIntegerEncoding _encoding;
public byte NumberBits { get; private set; }
public byte TritValue { get; private set; }
public byte QuintValue { get; private set; }
@@ -23,11 +23,11 @@ namespace Ryujinx.Graphics.Texture.Astc
static IntegerEncoded()
{
- Encodings = new IntegerEncoded[0x100];
+ _encodings = new IntegerEncoded[0x100];
- for (int i = 0; i < Encodings.Length; i++)
+ for (int i = 0; i < _encodings.Length; i++)
{
- Encodings[i] = CreateEncodingCalc(i);
+ _encodings[i] = CreateEncodingCalc(i);
}
}
@@ -40,17 +40,17 @@ namespace Ryujinx.Graphics.Texture.Astc
QuintValue = 0;
}
- public bool MatchesEncoding(IntegerEncoded other)
+ public readonly bool MatchesEncoding(IntegerEncoded other)
{
return _encoding == other._encoding && NumberBits == other.NumberBits;
}
- public EIntegerEncoding GetEncoding()
+ public readonly EIntegerEncoding GetEncoding()
{
return _encoding;
}
- public int GetBitLength(int numberVals)
+ public readonly int GetBitLength(int numberVals)
{
int totalBits = NumberBits * numberVals;
if (_encoding == EIntegerEncoding.Trit)
@@ -66,7 +66,7 @@ namespace Ryujinx.Graphics.Texture.Astc
public static IntegerEncoded CreateEncoding(int maxVal)
{
- return Encodings[maxVal];
+ return _encodings[maxVal];
}
private static IntegerEncoded CreateEncodingCalc(int maxVal)
@@ -122,7 +122,7 @@ namespace Ryujinx.Graphics.Texture.Astc
ReadOnlySpan<byte> encodings = GetTritEncoding(encoded);
- IntegerEncoded intEncoded = new IntegerEncoded(EIntegerEncoding.Trit, numberBitsPerValue);
+ IntegerEncoded intEncoded = new(EIntegerEncoding.Trit, numberBitsPerValue);
for (int i = 0; i < 5; i++)
{
@@ -159,7 +159,7 @@ namespace Ryujinx.Graphics.Texture.Astc
for (int i = 0; i < 3; i++)
{
- IntegerEncoded intEncoded = new IntegerEncoded(EIntegerEncoding.Quint, numberBitsPerValue)
+ IntegerEncoded intEncoded = new(EIntegerEncoding.Quint, numberBitsPerValue)
{
BitValue = m[i],
QuintValue = encodings[i]
@@ -185,29 +185,29 @@ namespace Ryujinx.Graphics.Texture.Astc
switch (intEncoded.GetEncoding())
{
case EIntegerEncoding.Quint:
- {
- DecodeQuintBlock(ref bitStream, ref decodeIntegerSequence, intEncoded.NumberBits);
- numberValuesDecoded += 3;
+ {
+ DecodeQuintBlock(ref bitStream, ref decodeIntegerSequence, intEncoded.NumberBits);
+ numberValuesDecoded += 3;
- break;
- }
+ break;
+ }
case EIntegerEncoding.Trit:
- {
- DecodeTritBlock(ref bitStream, ref decodeIntegerSequence, intEncoded.NumberBits);
- numberValuesDecoded += 5;
+ {
+ DecodeTritBlock(ref bitStream, ref decodeIntegerSequence, intEncoded.NumberBits);
+ numberValuesDecoded += 5;
- break;
- }
+ break;
+ }
case EIntegerEncoding.JustBits:
- {
- intEncoded.BitValue = bitStream.ReadBits(intEncoded.NumberBits);
- decodeIntegerSequence.Add(ref intEncoded);
- numberValuesDecoded++;
+ {
+ intEncoded.BitValue = bitStream.ReadBits(intEncoded.NumberBits);
+ decodeIntegerSequence.Add(ref intEncoded);
+ numberValuesDecoded++;
- break;
- }
+ break;
+ }
}
}
}