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 blockRow = block.Slice(inputOffset, outputPixelsX * 4); - Span outputRow = outputBuffer.Slice(outputOffset); + Span 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 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 weightsList = weights.List; Span 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: - { - result = d switch - { - 0 => 0, - 1 => 32, - 2 => 63, - _ => 0 - }; + d = intEncoded.TritValue; + Debug.Assert(d < 3); - break; + switch (bitLength) + { + case 0: + { + result = d switch + { + 0 => 0, + 1 => 32, + 2 => 63, + _ => 0 + }; + + break; + } + + case 1: + { + c = 50; + break; + } + + case 2: + { + c = 23; + int b2 = (bitValue >> 1) & 1; + b = (b2 << 6) | (b2 << 2) | b2; + + break; + } + + case 3: + { + c = 11; + int cb = (bitValue >> 1) & 3; + b = (cb << 5) | cb; + + break; + } + + default: + throw new AstcDecoderException("Invalid trit encoding for texel weight."); } - case 1: - { - c = 50; - break; - } - - case 2: - { - c = 23; - int b2 = (bitValue >> 1) & 1; - b = (b2 << 6) | (b2 << 2) | b2; - - break; - } - - case 3: - { - c = 11; - int cb = (bitValue >> 1) & 3; - b = (cb << 5) | cb; - - break; - } - - 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: - { - result = d switch - { - 0 => 0, - 1 => 16, - 2 => 32, - 3 => 47, - 4 => 63, - _ => 0 - }; + d = intEncoded.QuintValue; + Debug.Assert(d < 5); - break; + switch (bitLength) + { + case 0: + { + result = d switch + { + 0 => 0, + 1 => 16, + 2 => 32, + 3 => 47, + 4 => 63, + _ => 0 + }; + + break; + } + + case 1: + { + c = 28; + + break; + } + + case 2: + { + c = 13; + int b2 = (bitValue >> 1) & 1; + b = (b2 << 6) | (b2 << 1); + + break; + } + + default: + throw new AstcDecoderException("Invalid quint encoding for texel weight."); } - case 1: - { - c = 28; - - break; - } - - case 2: - { - c = 13; - int b2 = (bitValue >> 1) & 1; - b = (b2 << 6) | (b2 << 1); - - break; - } - - 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 val = ReadUintColorValues(2, colorValues, ref colorValuesPosition); + { + Span 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 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 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 val = ReadUintColorValues(4, colorValues, ref colorValuesPosition); + { + Span 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 val = ReadIntColorValues(4, colorValues, ref colorValuesPosition); + { + Span 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 val = ReadUintColorValues(4, colorValues, ref colorValuesPosition); + { + Span 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 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 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 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]); - - 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]); - } + Span val = ReadIntColorValues(6, colorValues, ref colorValuesPosition); - endPoints[0].ClampByte(); - endPoints[1].ClampByte(); + Bits.BitTransferSigned(ref val[1], ref val[0]); + Bits.BitTransferSigned(ref val[3], ref val[2]); + Bits.BitTransferSigned(ref val[5], ref val[4]); - break; - } + 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(); + + break; + } case 10: - { - Span val = ReadUintColorValues(6, colorValues, ref colorValuesPosition); + { + Span 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 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 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 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]); - - 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]); - } + Span val = ReadIntColorValues(8, colorValues, ref colorValuesPosition); - endPoints[0].ClampByte(); - endPoints[1].ClampByte(); + 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]); - break; - } + 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(); + + 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; + d = intEncoded.TritValue; - break; + 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; + } + + + 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 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."); + break; } - break; - } - case IntegerEncoded.EIntegerEncoding.Quint: - { - d = intEncoded.QuintValue; - - switch (bitLength) { - case 1: + d = intEncoded.QuintValue; + + switch (bitLength) { - c = 113; + case 1: + { + c = 113; - break; + 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 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."); + 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 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; + } } } } diff --git a/src/Ryujinx.Graphics.Texture/BC6Decoder.cs b/src/Ryujinx.Graphics.Texture/BC6Decoder.cs index 819bf022..f761a422 100644 --- a/src/Ryujinx.Graphics.Texture/BC6Decoder.cs +++ b/src/Ryujinx.Graphics.Texture/BC6Decoder.cs @@ -27,7 +27,7 @@ namespace Ryujinx.Graphics.Texture int x2 = x * 4; int bw = Math.Min(4, width - x2); - DecodeBlock(blocks[y * wInBlocks + x], output64.Slice(y2 * width + x2), bw, bh, width, signed); + DecodeBlock(blocks[y * wInBlocks + x], output64[(y2 * width + x2)..], bw, bh, width, signed); } } } diff --git a/src/Ryujinx.Graphics.Texture/BC7Decoder.cs b/src/Ryujinx.Graphics.Texture/BC7Decoder.cs index b865a559..c1c70429 100644 --- a/src/Ryujinx.Graphics.Texture/BC7Decoder.cs +++ b/src/Ryujinx.Graphics.Texture/BC7Decoder.cs @@ -27,7 +27,7 @@ namespace Ryujinx.Graphics.Texture int x2 = x * 4; int bw = Math.Min(4, width - x2); - DecodeBlock(blocks[y * wInBlocks + x], output32.Slice(y2 * width + x2), bw, bh, width); + DecodeBlock(blocks[y * wInBlocks + x], output32[(y2 * width + x2)..], bw, bh, width); } } } @@ -177,9 +177,18 @@ namespace Ryujinx.Graphics.Texture switch (rotation) { - case 1: color.A = color.R; color.R = a; break; - case 2: color.A = color.G; color.G = a; break; - case 3: color.A = color.B; color.B = a; break; + case 1: + color.A = color.R; + color.R = a; + break; + case 2: + color.A = color.G; + color.G = a; + break; + case 3: + color.A = color.B; + color.B = a; + break; } } diff --git a/src/Ryujinx.Graphics.Texture/BCnDecoder.cs b/src/Ryujinx.Graphics.Texture/BCnDecoder.cs index b21fa4d1..2d68ca34 100644 --- a/src/Ryujinx.Graphics.Texture/BCnDecoder.cs +++ b/src/Ryujinx.Graphics.Texture/BCnDecoder.cs @@ -54,10 +54,10 @@ namespace Ryujinx.Graphics.Texture if (copyHeight == 4) { - outputLine0 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs)); - outputLine1 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs + width)); - outputLine2 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs + width * 2)); - outputLine3 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs + width * 3)); + outputLine0 = MemoryMarshal.Cast>(outputAsUint[lineBaseOOffs..]); + outputLine1 = MemoryMarshal.Cast>(outputAsUint[(lineBaseOOffs + width)..]); + outputLine2 = MemoryMarshal.Cast>(outputAsUint[(lineBaseOOffs + width * 2)..]); + outputLine3 = MemoryMarshal.Cast>(outputAsUint[(lineBaseOOffs + width * 3)..]); } for (int x = 0; x < w; x++) @@ -84,7 +84,7 @@ namespace Ryujinx.Graphics.Texture } } - data = data.Slice(8); + data = data[8..]; } } @@ -142,10 +142,10 @@ namespace Ryujinx.Graphics.Texture if (copyHeight == 4) { - outputLine0 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs)); - outputLine1 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs + width)); - outputLine2 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs + width * 2)); - outputLine3 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs + width * 3)); + outputLine0 = MemoryMarshal.Cast>(outputAsUint[lineBaseOOffs..]); + outputLine1 = MemoryMarshal.Cast>(outputAsUint[(lineBaseOOffs + width)..]); + outputLine2 = MemoryMarshal.Cast>(outputAsUint[(lineBaseOOffs + width * 2)..]); + outputLine3 = MemoryMarshal.Cast>(outputAsUint[(lineBaseOOffs + width * 3)..]); } for (int x = 0; x < w; x++) @@ -153,7 +153,7 @@ namespace Ryujinx.Graphics.Texture int baseX = x * BlockWidth; int copyWidth = Math.Min(BlockWidth, width - baseX); - BC23DecodeTileRgb(tile, data.Slice(8)); + BC23DecodeTileRgb(tile, data[8..]); ulong block = BinaryPrimitives.ReadUInt64LittleEndian(data); @@ -179,7 +179,7 @@ namespace Ryujinx.Graphics.Texture } } - data = data.Slice(16); + data = data[16..]; } } @@ -238,10 +238,10 @@ namespace Ryujinx.Graphics.Texture if (copyHeight == 4) { - outputLine0 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs)); - outputLine1 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs + width)); - outputLine2 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs + width * 2)); - outputLine3 = MemoryMarshal.Cast>(outputAsUint.Slice(lineBaseOOffs + width * 3)); + outputLine0 = MemoryMarshal.Cast>(outputAsUint[lineBaseOOffs..]); + outputLine1 = MemoryMarshal.Cast>(outputAsUint[(lineBaseOOffs + width)..]); + outputLine2 = MemoryMarshal.Cast>(outputAsUint[(lineBaseOOffs + width * 2)..]); + outputLine3 = MemoryMarshal.Cast>(outputAsUint[(lineBaseOOffs + width * 3)..]); } for (int x = 0; x < w; x++) @@ -249,7 +249,7 @@ namespace Ryujinx.Graphics.Texture int baseX = x * BlockWidth; int copyWidth = Math.Min(BlockWidth, width - baseX); - BC23DecodeTileRgb(tile, data.Slice(8)); + BC23DecodeTileRgb(tile, data[8..]); ulong block = BinaryPrimitives.ReadUInt64LittleEndian(data); @@ -276,7 +276,7 @@ namespace Ryujinx.Graphics.Texture } } - data = data.Slice(16); + data = data[16..]; } } @@ -305,7 +305,7 @@ namespace Ryujinx.Graphics.Texture int alignedWidth = BitUtils.AlignUp(width, 4); byte[] output = new byte[size]; - Span outputSpan = new Span(output); + Span outputSpan = new(output); ReadOnlySpan data64 = MemoryMarshal.Cast(data); @@ -338,10 +338,10 @@ namespace Ryujinx.Graphics.Texture if (copyHeight == 4) { - outputLine0 = MemoryMarshal.Cast(outputSpan.Slice(lineBaseOOffs)); - outputLine1 = MemoryMarshal.Cast(outputSpan.Slice(lineBaseOOffs + alignedWidth)); - outputLine2 = MemoryMarshal.Cast(outputSpan.Slice(lineBaseOOffs + alignedWidth * 2)); - outputLine3 = MemoryMarshal.Cast(outputSpan.Slice(lineBaseOOffs + alignedWidth * 3)); + outputLine0 = MemoryMarshal.Cast(outputSpan[lineBaseOOffs..]); + outputLine1 = MemoryMarshal.Cast(outputSpan[(lineBaseOOffs + alignedWidth)..]); + outputLine2 = MemoryMarshal.Cast(outputSpan[(lineBaseOOffs + alignedWidth * 2)..]); + outputLine3 = MemoryMarshal.Cast(outputSpan[(lineBaseOOffs + alignedWidth * 3)..]); } for (int x = 0; x < w; x++) @@ -382,7 +382,7 @@ namespace Ryujinx.Graphics.Texture } } - data64 = data64.Slice(1); + data64 = data64[1..]; } } @@ -450,10 +450,10 @@ namespace Ryujinx.Graphics.Texture if (copyHeight == 4) { - outputLine0 = MemoryMarshal.Cast(outputAsUshort.Slice(lineBaseOOffs)); - outputLine1 = MemoryMarshal.Cast(outputAsUshort.Slice(lineBaseOOffs + alignedWidth)); - outputLine2 = MemoryMarshal.Cast(outputAsUshort.Slice(lineBaseOOffs + alignedWidth * 2)); - outputLine3 = MemoryMarshal.Cast(outputAsUshort.Slice(lineBaseOOffs + alignedWidth * 3)); + outputLine0 = MemoryMarshal.Cast(outputAsUshort[lineBaseOOffs..]); + outputLine1 = MemoryMarshal.Cast(outputAsUshort[(lineBaseOOffs + alignedWidth)..]); + outputLine2 = MemoryMarshal.Cast(outputAsUshort[(lineBaseOOffs + alignedWidth * 2)..]); + outputLine3 = MemoryMarshal.Cast(outputAsUshort[(lineBaseOOffs + alignedWidth * 3)..]); } for (int x = 0; x < w; x++) @@ -507,7 +507,7 @@ namespace Ryujinx.Graphics.Texture } } - data64 = data64.Slice(2); + data64 = data64[2..]; } } @@ -548,7 +548,7 @@ namespace Ryujinx.Graphics.Texture { for (int z = 0; z < depth; z++) { - BC6Decoder.Decode(output.AsSpan().Slice(outputOffset), data.Slice(inputOffset), width, height, signed); + BC6Decoder.Decode(output.AsSpan()[outputOffset..], data[inputOffset..], width, height, signed); inputOffset += w * h * 16; outputOffset += width * height * 8; @@ -586,7 +586,7 @@ namespace Ryujinx.Graphics.Texture { for (int z = 0; z < depth; z++) { - BC7Decoder.Decode(output.AsSpan().Slice(outputOffset), data.Slice(inputOffset), width, height); + BC7Decoder.Decode(output.AsSpan()[outputOffset..], data[inputOffset..], width, height); inputOffset += w * h * 16; outputOffset += width * height * 4; @@ -813,7 +813,7 @@ namespace Ryujinx.Graphics.Texture { Span outputAsUint = MemoryMarshal.Cast(output); - uint indices = BinaryPrimitives.ReadUInt32LittleEndian(input.Slice(4)); + uint indices = BinaryPrimitives.ReadUInt32LittleEndian(input[4..]); for (int i = 0; i < BlockWidth * BlockHeight; i++, indices >>= 2) { @@ -891,4 +891,4 @@ namespace Ryujinx.Graphics.Texture return r | (g & 0xff00) | (b & 0xff0000); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/BCnEncoder.cs b/src/Ryujinx.Graphics.Texture/BCnEncoder.cs index 02b79c1b..8103990f 100644 --- a/src/Ryujinx.Graphics.Texture/BCnEncoder.cs +++ b/src/Ryujinx.Graphics.Texture/BCnEncoder.cs @@ -28,8 +28,6 @@ namespace Ryujinx.Graphics.Texture for (int l = 0; l < levels; l++) { - int rgba8Size = width * height * depth * layers * 4; - int w = BitUtils.DivRoundUp(width, BlockWidth); int h = BitUtils.DivRoundUp(height, BlockHeight); @@ -38,8 +36,8 @@ namespace Ryujinx.Graphics.Texture for (int z = 0; z < depth; z++) { BC7Encoder.Encode( - output.AsMemory().Slice(imageBaseOOffs), - data.AsMemory().Slice(imageBaseIOffs), + output.AsMemory()[imageBaseOOffs..], + data.AsMemory()[imageBaseIOffs..], width, height, EncodeMode.Fast | EncodeMode.Multithreaded); @@ -57,4 +55,4 @@ namespace Ryujinx.Graphics.Texture return output; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/BlockLinearConstants.cs b/src/Ryujinx.Graphics.Texture/BlockLinearConstants.cs index d95691cf..ad0dda85 100644 --- a/src/Ryujinx.Graphics.Texture/BlockLinearConstants.cs +++ b/src/Ryujinx.Graphics.Texture/BlockLinearConstants.cs @@ -7,4 +7,4 @@ namespace Ryujinx.Graphics.Texture public const int GobSize = GobStride * GobHeight; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/BlockLinearLayout.cs b/src/Ryujinx.Graphics.Texture/BlockLinearLayout.cs index e098e959..06d984ac 100644 --- a/src/Ryujinx.Graphics.Texture/BlockLinearLayout.cs +++ b/src/Ryujinx.Graphics.Texture/BlockLinearLayout.cs @@ -15,24 +15,24 @@ namespace Ryujinx.Graphics.Texture public RobAndSliceSizes(int robSize, int sliceSize) { - RobSize = robSize; + RobSize = robSize; SliceSize = sliceSize; } } - private int _texBpp; + private readonly int _texBpp; - private int _bhMask; - private int _bdMask; + private readonly int _bhMask; + private readonly int _bdMask; - private int _bhShift; - private int _bdShift; - private int _bppShift; + private readonly int _bhShift; + private readonly int _bdShift; + private readonly int _bppShift; - private int _xShift; + private readonly int _xShift; - private int _robSize; - private int _sliceSize; + private readonly int _robSize; + private readonly int _sliceSize; // Variables for built in iteration. private int _yPart; @@ -60,7 +60,7 @@ namespace Ryujinx.Graphics.Texture RobAndSliceSizes rsSizes = GetRobAndSliceSizes(width, height, gobBlocksInY, gobBlocksInZ); - _robSize = rsSizes.RobSize; + _robSize = rsSizes.RobSize; _sliceSize = rsSizes.SliceSize; } @@ -192,4 +192,4 @@ namespace Ryujinx.Graphics.Texture return offset + _yzPart; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/Bpp12Pixel.cs b/src/Ryujinx.Graphics.Texture/Bpp12Pixel.cs index 5a38259e..6e2cb8a7 100644 --- a/src/Ryujinx.Graphics.Texture/Bpp12Pixel.cs +++ b/src/Ryujinx.Graphics.Texture/Bpp12Pixel.cs @@ -3,9 +3,9 @@ namespace Ryujinx.Graphics.Texture { [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 12)] - public struct Bpp12Pixel + public readonly struct Bpp12Pixel { - private ulong _elem1; - private uint _elem2; + private readonly ulong _elem1; + private readonly uint _elem2; } } diff --git a/src/Ryujinx.Graphics.Texture/Encoders/BC7Encoder.cs b/src/Ryujinx.Graphics.Texture/Encoders/BC7Encoder.cs index 35d36bce..d0d1666a 100644 --- a/src/Ryujinx.Graphics.Texture/Encoders/BC7Encoder.cs +++ b/src/Ryujinx.Graphics.Texture/Encoders/BC7Encoder.cs @@ -119,12 +119,12 @@ namespace Ryujinx.Graphics.Texture.Encoders { uint c = tile[i]; - if (!uniqueRGB.Slice(0, uniqueRGBCount).Contains(c & rgbMask)) + if (!uniqueRGB[..uniqueRGBCount].Contains(c & rgbMask)) { uniqueRGB[uniqueRGBCount++] = c & rgbMask; } - if (!uniqueAlpha.Slice(0, uniqueAlphaCount).Contains(c & alphaMask)) + if (!uniqueAlpha[..uniqueAlphaCount].Contains(c & alphaMask)) { uniqueAlpha[uniqueAlphaCount++] = c & alphaMask; } @@ -356,7 +356,7 @@ namespace Ryujinx.Graphics.Texture.Encoders bool alphaSwapSubset = alphaIndices[0] >= (alphaIndexCount >> 1); - Block block = new Block(); + Block block = new(); int offset = 0; @@ -591,7 +591,7 @@ namespace Ryujinx.Graphics.Texture.Encoders RgbaColor32 e132 = RgbaColor8.FromUInt32(c1).GetColor32(); palette[0] = e032; - palette[palette.Length - 1] = e132; + palette[^1] = e132; for (int i = 1; i < palette.Length - 1; i++) { @@ -888,7 +888,7 @@ namespace Ryujinx.Graphics.Texture.Encoders int distRange = Math.Max(1, maxDist - minDist); - RgbaColor32 nV = new RgbaColor32(n); + RgbaColor32 nV = new(n); int bestErrorSum = int.MaxValue; RgbaColor8 bestE0 = default; @@ -922,8 +922,8 @@ namespace Ryujinx.Graphics.Texture.Encoders for (int start = 0; start < numInterpolatedColors - maxIndex; start++) { - RgbaColor32 sumY = new RgbaColor32(0); - RgbaColor32 sumXY = new RgbaColor32(0); + RgbaColor32 sumY = new(0); + RgbaColor32 sumXY = new(0); for (int i = 0; i < indices.Length; i++) { @@ -933,8 +933,8 @@ namespace Ryujinx.Graphics.Texture.Encoders sumXY += new RgbaColor32(start + indices[i]) * y; } - RgbaColor32 sumXV = new RgbaColor32(sumX); - RgbaColor32 sumXXV = new RgbaColor32(sumXX); + RgbaColor32 sumXV = new(sumX); + RgbaColor32 sumXXV = new(sumXX); RgbaColor32 m = RgbaColor32.DivideGuarded((nV * sumXY - sumXV * sumY) << 6, nV * sumXXV - sumXV * sumXV, 0); RgbaColor32 b = ((sumY << 6) - m * sumXV) / nV; diff --git a/src/Ryujinx.Graphics.Texture/LayoutConverter.cs b/src/Ryujinx.Graphics.Texture/LayoutConverter.cs index 503985c9..0f7c304e 100644 --- a/src/Ryujinx.Graphics.Texture/LayoutConverter.cs +++ b/src/Ryujinx.Graphics.Texture/LayoutConverter.cs @@ -31,7 +31,7 @@ namespace Ryujinx.Graphics.Texture int wAligned = BitUtils.AlignUp(width, alignment); - BlockLinearLayout layoutConverter = new BlockLinearLayout(wAligned, height, gobBlocksInY, 1, bytesPerPixel); + BlockLinearLayout layoutConverter = new(wAligned, height, gobBlocksInY, 1, bytesPerPixel); unsafe bool Convert(Span output, ReadOnlySpan data) where T : unmanaged { @@ -126,14 +126,14 @@ namespace Ryujinx.Graphics.Texture int mipGobBlocksInY = gobBlocksInY; int mipGobBlocksInZ = gobBlocksInZ; - int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX; + int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX; int gobHeight = gobBlocksInY * GobHeight; for (int level = 0; level < levels; level++) { - int w = Math.Max(1, width >> level); + int w = Math.Max(1, width >> level); int h = Math.Max(1, height >> level); - int d = Math.Max(1, depth >> level); + int d = Math.Max(1, depth >> level); w = BitUtils.DivRoundUp(w, blockWidth); h = BitUtils.DivRoundUp(h, blockHeight); @@ -166,7 +166,7 @@ namespace Ryujinx.Graphics.Texture int wAligned = BitUtils.AlignUp(w, alignment); - BlockLinearLayout layoutConverter = new BlockLinearLayout( + BlockLinearLayout layoutConverter = new( wAligned, h, mipGobBlocksInY, @@ -256,7 +256,7 @@ namespace Ryujinx.Graphics.Texture int bytesPerPixel, ReadOnlySpan data) { - int w = BitUtils.DivRoundUp(width, blockWidth); + int w = BitUtils.DivRoundUp(width, blockWidth); int h = BitUtils.DivRoundUp(height, blockHeight); int outStride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment); @@ -301,7 +301,7 @@ namespace Ryujinx.Graphics.Texture int wAligned = BitUtils.AlignUp(width, alignment); - BlockLinearLayout layoutConverter = new BlockLinearLayout(wAligned, height, gobBlocksInY, 1, bytesPerPixel); + BlockLinearLayout layoutConverter = new(wAligned, height, gobBlocksInY, 1, bytesPerPixel); unsafe bool Convert(Span output, ReadOnlySpan data) where T : unmanaged { @@ -390,14 +390,14 @@ namespace Ryujinx.Graphics.Texture int mipGobBlocksInY = gobBlocksInY; int mipGobBlocksInZ = gobBlocksInZ; - int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX; + int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX; int gobHeight = gobBlocksInY * GobHeight; for (int level = 0; level < levels; level++) { - int w = Math.Max(1, width >> level); + int w = Math.Max(1, width >> level); int h = Math.Max(1, height >> level); - int d = Math.Max(1, depth >> level); + int d = Math.Max(1, depth >> level); w = BitUtils.DivRoundUp(w, blockWidth); h = BitUtils.DivRoundUp(h, blockHeight); @@ -430,7 +430,7 @@ namespace Ryujinx.Graphics.Texture int wAligned = BitUtils.AlignUp(w, alignment); - BlockLinearLayout layoutConverter = new BlockLinearLayout( + BlockLinearLayout layoutConverter = new( wAligned, h, mipGobBlocksInY, @@ -521,7 +521,7 @@ namespace Ryujinx.Graphics.Texture int bytesPerPixel, ReadOnlySpan data) { - int w = BitUtils.DivRoundUp(width, blockWidth); + int w = BitUtils.DivRoundUp(width, blockWidth); int h = BitUtils.DivRoundUp(height, blockHeight); int inStride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment); @@ -573,9 +573,9 @@ namespace Ryujinx.Graphics.Texture for (int level = 0; level < levels; level++) { - int w = Math.Max(1, width >> level); + int w = Math.Max(1, width >> level); int h = Math.Max(1, height >> level); - int d = Math.Max(1, depth >> level); + int d = Math.Max(1, depth >> level); w = BitUtils.DivRoundUp(w, blockWidth); h = BitUtils.DivRoundUp(h, blockHeight); @@ -588,4 +588,4 @@ namespace Ryujinx.Graphics.Texture return layerSize * layers; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/OffsetCalculator.cs b/src/Ryujinx.Graphics.Texture/OffsetCalculator.cs index d7472e2f..48d36cdf 100644 --- a/src/Ryujinx.Graphics.Texture/OffsetCalculator.cs +++ b/src/Ryujinx.Graphics.Texture/OffsetCalculator.cs @@ -7,30 +7,30 @@ namespace Ryujinx.Graphics.Texture { public class OffsetCalculator { - private int _width; - private int _height; - private int _stride; - private bool _isLinear; - private int _bytesPerPixel; + private readonly int _width; + private readonly int _height; + private readonly int _stride; + private readonly bool _isLinear; + private readonly int _bytesPerPixel; - private BlockLinearLayout _layoutConverter; + private readonly BlockLinearLayout _layoutConverter; // Variables for built in iteration. private int _yPart; public OffsetCalculator( - int width, - int height, - int stride, + int width, + int height, + int stride, bool isLinear, - int gobBlocksInY, - int gobBlocksInZ, - int bytesPerPixel) + int gobBlocksInY, + int gobBlocksInZ, + int bytesPerPixel) { - _width = width; - _height = height; - _stride = stride; - _isLinear = isLinear; + _width = width; + _height = height; + _stride = stride; + _isLinear = isLinear; _bytesPerPixel = bytesPerPixel; int wAlignment = GobStride / bytesPerPixel; @@ -138,4 +138,4 @@ namespace Ryujinx.Graphics.Texture } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/PixelConverter.cs b/src/Ryujinx.Graphics.Texture/PixelConverter.cs index add25cd3..7955aed3 100644 --- a/src/Ryujinx.Graphics.Texture/PixelConverter.cs +++ b/src/Ryujinx.Graphics.Texture/PixelConverter.cs @@ -87,9 +87,9 @@ namespace Ryujinx.Graphics.Texture { uint packed = inputSpan[offset++]; - uint outputPacked = 0xff000000; - outputPacked |= (packed << 3) & 0x000000f8; - outputPacked |= (packed << 8) & 0x00f80000; + uint outputPacked = 0xff000000; + outputPacked |= (packed << 3) & 0x000000f8; + outputPacked |= (packed << 8) & 0x00f80000; // Replicate 5 bit components. outputPacked |= (outputPacked >> 5) & 0x00070007; @@ -126,10 +126,10 @@ namespace Ryujinx.Graphics.Texture uint a = forceAlpha ? 1 : (packed >> 15); - uint outputPacked = a * 0xff000000; - outputPacked |= (packed << 3) & 0x000000f8; - outputPacked |= (packed << 6) & 0x0000f800; - outputPacked |= (packed << 9) & 0x00f80000; + uint outputPacked = a * 0xff000000; + outputPacked |= (packed << 3) & 0x000000f8; + outputPacked |= (packed << 6) & 0x0000f800; + outputPacked |= (packed << 9) & 0x00f80000; // Replicate 5 bit components. outputPacked |= (outputPacked >> 5) & 0x00070707; @@ -198,10 +198,10 @@ namespace Ryujinx.Graphics.Texture { uint packed = inputSpan[offset++]; - uint outputPacked = packed & 0x0000000f; - outputPacked |= (packed << 4) & 0x00000f00; - outputPacked |= (packed << 8) & 0x000f0000; - outputPacked |= (packed << 12) & 0x0f000000; + uint outputPacked = packed & 0x0000000f; + outputPacked |= (packed << 4) & 0x00000f00; + outputPacked |= (packed << 8) & 0x000f0000; + outputPacked |= (packed << 12) & 0x0f000000; outputSpan[outOffset++] = outputPacked * 0x11; } diff --git a/src/Ryujinx.Graphics.Texture/Size.cs b/src/Ryujinx.Graphics.Texture/Size.cs index 21c45b38..78d3cb57 100644 --- a/src/Ryujinx.Graphics.Texture/Size.cs +++ b/src/Ryujinx.Graphics.Texture/Size.cs @@ -2,15 +2,15 @@ namespace Ryujinx.Graphics.Texture { public readonly struct Size { - public int Width { get; } + public int Width { get; } public int Height { get; } - public int Depth { get; } + public int Depth { get; } public Size(int width, int height, int depth) { - Width = width; + Width = width; Height = height; - Depth = depth; + Depth = depth; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/SizeCalculator.cs b/src/Ryujinx.Graphics.Texture/SizeCalculator.cs index 0120bd7a..7fe89e7e 100644 --- a/src/Ryujinx.Graphics.Texture/SizeCalculator.cs +++ b/src/Ryujinx.Graphics.Texture/SizeCalculator.cs @@ -1,6 +1,5 @@ using Ryujinx.Common; using System; - using static Ryujinx.Graphics.Texture.BlockLinearConstants; namespace Ryujinx.Graphics.Texture @@ -48,16 +47,16 @@ namespace Ryujinx.Graphics.Texture int mipGobBlocksInY = gobBlocksInY; int mipGobBlocksInZ = gobBlocksInZ; - int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX; + int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX; int gobHeight = gobBlocksInY * GobHeight; int depthLevelOffset = 0; for (int level = 0; level < levels; level++) { - int w = Math.Max(1, width >> level); + int w = Math.Max(1, width >> level); int h = Math.Max(1, height >> level); - int d = Math.Max(1, depth >> level); + int d = Math.Max(1, depth >> level); w = BitUtils.DivRoundUp(w, blockWidth); h = BitUtils.DivRoundUp(h, blockHeight); @@ -104,7 +103,7 @@ namespace Ryujinx.Graphics.Texture for (int z = 0; z < d; z++) { - int zLow = z & mask; + int zLow = z & mask; int zHigh = z & ~mask; allOffsets[z + depthLevelOffset] = baseOffset + zLow * gobSize + zHigh * sliceSize; @@ -159,7 +158,7 @@ namespace Ryujinx.Graphics.Texture { for (int layer = 0; layer < layers; layer++) { - int baseIndex = layer * levels; + int baseIndex = layer * levels; int baseOffset = layer * layerSize; for (int level = 0; level < levels; level++) @@ -234,10 +233,10 @@ namespace Ryujinx.Graphics.Texture int gobBlocksInZ, int gobBlocksInTileX) { - width = BitUtils.DivRoundUp(width, blockWidth); + width = BitUtils.DivRoundUp(width, blockWidth); height = BitUtils.DivRoundUp(height, blockHeight); - int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX; + int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX; int gobHeight = gobBlocksInY * GobHeight; int alignment = gobWidth; @@ -251,11 +250,11 @@ namespace Ryujinx.Graphics.Texture (gobBlocksInY, gobBlocksInZ) = GetMipGobBlockSizes(height, depth, 1, gobBlocksInY, gobBlocksInZ); int blockOfGobsHeight = gobBlocksInY * GobHeight; - int blockOfGobsDepth = gobBlocksInZ; + int blockOfGobsDepth = gobBlocksInZ; - width = BitUtils.AlignUp(width, alignment); + width = BitUtils.AlignUp(width, alignment); height = BitUtils.AlignUp(height, blockOfGobsHeight); - depth = BitUtils.AlignUp(depth, blockOfGobsDepth); + depth = BitUtils.AlignUp(depth, blockOfGobsDepth); return new Size(width, height, depth); } @@ -267,7 +266,7 @@ namespace Ryujinx.Graphics.Texture int blockHeight, int bytesPerPixel) { - width = BitUtils.DivRoundUp(width, blockWidth); + width = BitUtils.DivRoundUp(width, blockWidth); height = BitUtils.DivRoundUp(height, blockHeight); int widthAlignment = StrideAlignment / bytesPerPixel; @@ -300,4 +299,4 @@ namespace Ryujinx.Graphics.Texture return (gobBlocksInY, gobBlocksInZ); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/SizeInfo.cs b/src/Ryujinx.Graphics.Texture/SizeInfo.cs index eb573728..3bec1203 100644 --- a/src/Ryujinx.Graphics.Texture/SizeInfo.cs +++ b/src/Ryujinx.Graphics.Texture/SizeInfo.cs @@ -20,14 +20,14 @@ namespace Ryujinx.Graphics.Texture public SizeInfo(int size) { _mipOffsets = new int[] { 0 }; - AllOffsets = new int[] { 0 }; - SliceSizes = new int[] { size }; - LevelSizes = new int[] { size }; - _depth = 1; - _levels = 1; - LayerSize = size; - TotalSize = size; - _is3D = false; + AllOffsets = new int[] { 0 }; + SliceSizes = new int[] { size }; + LevelSizes = new int[] { size }; + _depth = 1; + _levels = 1; + LayerSize = size; + TotalSize = size; + _is3D = false; } internal SizeInfo( @@ -35,21 +35,21 @@ namespace Ryujinx.Graphics.Texture int[] allOffsets, int[] sliceSizes, int[] levelSizes, - int depth, - int levels, - int layerSize, - int totalSize, - bool is3D) + int depth, + int levels, + int layerSize, + int totalSize, + bool is3D) { _mipOffsets = mipOffsets; - AllOffsets = allOffsets; - SliceSizes = sliceSizes; - LevelSizes = levelSizes; - _depth = depth; - _levels = levels; - LayerSize = layerSize; - TotalSize = totalSize; - _is3D = is3D; + AllOffsets = allOffsets; + SliceSizes = sliceSizes; + LevelSizes = levelSizes; + _depth = depth; + _levels = levels; + LayerSize = layerSize; + TotalSize = totalSize; + _is3D = is3D; } public int GetMipOffset(int level) @@ -116,4 +116,4 @@ namespace Ryujinx.Graphics.Texture } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/Utils/BC67Utils.cs b/src/Ryujinx.Graphics.Texture/Utils/BC67Utils.cs index e6c3f6e7..3f69cb4c 100644 --- a/src/Ryujinx.Graphics.Texture/Utils/BC67Utils.cs +++ b/src/Ryujinx.Graphics.Texture/Utils/BC67Utils.cs @@ -8,8 +8,8 @@ namespace Ryujinx.Graphics.Texture.Utils { static class BC67Utils { - private static byte[][] _quantizationLut; - private static byte[][] _quantizationLutNoPBit; + private static readonly byte[][] _quantizationLut; + private static readonly byte[][] _quantizationLutNoPBit; static BC67Utils() { @@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Texture.Utils } else { - RgbaColor8 minColor = new RgbaColor8(255, 255, 255, 255); + RgbaColor8 minColor = new(255, 255, 255, 255); RgbaColor8 maxColor = default; for (int i = 0; i < tile.Length; i++) @@ -1176,8 +1176,8 @@ namespace Ryujinx.Graphics.Texture.Utils int weight = (((weightIndex << 7) / ((1 << indexBitCount) - 1)) + 1) >> 1; - RgbaColor32 weightV = new RgbaColor32(weight); - RgbaColor32 invWeightV = new RgbaColor32(64 - weight); + RgbaColor32 weightV = new(weight); + RgbaColor32 invWeightV = new(64 - weight); return (color1 * invWeightV + color2 * weightV + new RgbaColor32(32)) >> 6; } @@ -1197,8 +1197,10 @@ namespace Ryujinx.Graphics.Texture.Utils int colorWeight = BC67Tables.Weights[colorIndexBitCount - 2][colorWeightIndex]; int alphaWeight = BC67Tables.Weights[alphaIndexBitCount - 2][alphaWeightIndex]; - RgbaColor32 weightV = new RgbaColor32(colorWeight); - weightV.A = alphaWeight; + RgbaColor32 weightV = new(colorWeight) + { + A = alphaWeight + }; RgbaColor32 invWeightV = new RgbaColor32(64) - weightV; return (color1 * invWeightV + color2 * weightV + new RgbaColor32(32)) >> 6; diff --git a/src/Ryujinx.Graphics.Texture/Utils/BC7ModeInfo.cs b/src/Ryujinx.Graphics.Texture/Utils/BC7ModeInfo.cs index 687df22c..91236f1b 100644 --- a/src/Ryujinx.Graphics.Texture/Utils/BC7ModeInfo.cs +++ b/src/Ryujinx.Graphics.Texture/Utils/BC7ModeInfo.cs @@ -34,4 +34,4 @@ namespace Ryujinx.Graphics.Texture.Utils AlphaDepth = alphaDepth; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/Utils/Block.cs b/src/Ryujinx.Graphics.Texture/Utils/Block.cs index a8bae077..3a1d50cd 100644 --- a/src/Ryujinx.Graphics.Texture/Utils/Block.cs +++ b/src/Ryujinx.Graphics.Texture/Utils/Block.cs @@ -25,7 +25,7 @@ namespace Ryujinx.Graphics.Texture.Utils offset += bits; } - public ulong Decode(ref int offset, int bits) + public readonly ulong Decode(ref int offset, int bits) { ulong value; ulong mask = bits == 64 ? ulong.MaxValue : (1UL << bits) - 1; @@ -52,4 +52,4 @@ namespace Ryujinx.Graphics.Texture.Utils return value; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Texture/Utils/RgbaColor32.cs b/src/Ryujinx.Graphics.Texture/Utils/RgbaColor32.cs index 582044d9..de7c9262 100644 --- a/src/Ryujinx.Graphics.Texture/Utils/RgbaColor32.cs +++ b/src/Ryujinx.Graphics.Texture/Utils/RgbaColor32.cs @@ -11,25 +11,25 @@ namespace Ryujinx.Graphics.Texture.Utils public int R { - get => _color.GetElement(0); + readonly get => _color.GetElement(0); set => _color = _color.WithElement(0, value); } public int G { - get => _color.GetElement(1); + readonly get => _color.GetElement(1); set => _color = _color.WithElement(1, value); } public int B { - get => _color.GetElement(2); + readonly get => _color.GetElement(2); set => _color = _color.WithElement(2, value); } public int A { - get => _color.GetElement(3); + readonly get => _color.GetElement(3); set => _color = _color.WithElement(3, value); } @@ -180,7 +180,7 @@ namespace Ryujinx.Graphics.Texture.Utils } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RgbaColor8 GetColor8() + public readonly RgbaColor8 GetColor8() { if (Sse41.IsSupported) { @@ -211,17 +211,17 @@ namespace Ryujinx.Graphics.Texture.Utils return (byte)Math.Clamp(value, 0, 255); } - public override int GetHashCode() + public readonly override int GetHashCode() { return HashCode.Combine(R, G, B, A); } - public override bool Equals(object obj) + public readonly override bool Equals(object obj) { return obj is RgbaColor32 other && Equals(other); } - public bool Equals(RgbaColor32 other) + public readonly bool Equals(RgbaColor32 other) { return _color.Equals(other._color); } diff --git a/src/Ryujinx.Graphics.Texture/Utils/RgbaColor8.cs b/src/Ryujinx.Graphics.Texture/Utils/RgbaColor8.cs index 0edf1cce..401bec38 100644 --- a/src/Ryujinx.Graphics.Texture/Utils/RgbaColor8.cs +++ b/src/Ryujinx.Graphics.Texture/Utils/RgbaColor8.cs @@ -54,22 +54,22 @@ namespace Ryujinx.Graphics.Texture.Utils return Unsafe.As(ref this); } - public override int GetHashCode() + public readonly override int GetHashCode() { return HashCode.Combine(R, G, B, A); } - public override bool Equals(object obj) + public readonly override bool Equals(object obj) { return obj is RgbaColor8 other && Equals(other); } - public bool Equals(RgbaColor8 other) + public readonly bool Equals(RgbaColor8 other) { return R == other.R && G == other.G && B == other.B && A == other.A; } - public byte GetComponent(int index) + public readonly byte GetComponent(int index) { return index switch {