[Ryujinx.Graphics.Texture] Address dotnet-format issues (#5375)

* dotnet format style --severity info

Some changes were manually reverted.

* Restore a few unused methods and variables

* Silence dotnet format IDE0060 warnings

* Silence dotnet format IDE0059 warnings

* Address or silence dotnet format CA2208 warnings

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Format if-blocks correctly

* Add comments to disabled warnings

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Address IDE0251 warnings

* Silence IDE0060 in .editorconfig

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* First dotnet format pass

* Apply suggestions from code review

Co-authored-by: Ac_K <Acoustik666@gmail.com>

* Address review feedback

* Update src/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs

Co-authored-by: Ac_K <Acoustik666@gmail.com>

---------

Co-authored-by: Ac_K <Acoustik666@gmail.com>
This commit is contained in:
TSRBerry 2023-06-28 18:46:18 +02:00 committed by GitHub
parent fc20d9b925
commit cebfa54467
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 741 additions and 630 deletions

View file

@ -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) ...
@ -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,9 +1250,9 @@ 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())
{

View file

@ -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 |

View file

@ -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));

View file

@ -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;
}
}
}
}

View file

@ -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]

View file

@ -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);
}
}
}

View file

@ -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;
}
}

View file

@ -54,10 +54,10 @@ namespace Ryujinx.Graphics.Texture
if (copyHeight == 4)
{
outputLine0 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs));
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width));
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 2));
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 3));
outputLine0 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[lineBaseOOffs..]);
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width)..]);
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width * 2)..]);
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(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<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs));
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width));
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 2));
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 3));
outputLine0 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[lineBaseOOffs..]);
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width)..]);
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width * 2)..]);
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(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<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs));
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width));
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 2));
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 3));
outputLine0 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[lineBaseOOffs..]);
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width)..]);
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width * 2)..]);
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(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<byte> outputSpan = new Span<byte>(output);
Span<byte> outputSpan = new(output);
ReadOnlySpan<ulong> data64 = MemoryMarshal.Cast<byte, ulong>(data);
@ -338,10 +338,10 @@ namespace Ryujinx.Graphics.Texture
if (copyHeight == 4)
{
outputLine0 = MemoryMarshal.Cast<byte, uint>(outputSpan.Slice(lineBaseOOffs));
outputLine1 = MemoryMarshal.Cast<byte, uint>(outputSpan.Slice(lineBaseOOffs + alignedWidth));
outputLine2 = MemoryMarshal.Cast<byte, uint>(outputSpan.Slice(lineBaseOOffs + alignedWidth * 2));
outputLine3 = MemoryMarshal.Cast<byte, uint>(outputSpan.Slice(lineBaseOOffs + alignedWidth * 3));
outputLine0 = MemoryMarshal.Cast<byte, uint>(outputSpan[lineBaseOOffs..]);
outputLine1 = MemoryMarshal.Cast<byte, uint>(outputSpan[(lineBaseOOffs + alignedWidth)..]);
outputLine2 = MemoryMarshal.Cast<byte, uint>(outputSpan[(lineBaseOOffs + alignedWidth * 2)..]);
outputLine3 = MemoryMarshal.Cast<byte, uint>(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<ushort, ulong>(outputAsUshort.Slice(lineBaseOOffs));
outputLine1 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort.Slice(lineBaseOOffs + alignedWidth));
outputLine2 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort.Slice(lineBaseOOffs + alignedWidth * 2));
outputLine3 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort.Slice(lineBaseOOffs + alignedWidth * 3));
outputLine0 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort[lineBaseOOffs..]);
outputLine1 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort[(lineBaseOOffs + alignedWidth)..]);
outputLine2 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort[(lineBaseOOffs + alignedWidth * 2)..]);
outputLine3 = MemoryMarshal.Cast<ushort, ulong>(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<uint> outputAsUint = MemoryMarshal.Cast<byte, uint>(output);
uint indices = BinaryPrimitives.ReadUInt32LittleEndian(input.Slice(4));
uint indices = BinaryPrimitives.ReadUInt32LittleEndian(input[4..]);
for (int i = 0; i < BlockWidth * BlockHeight; i++, indices >>= 2)
{

View file

@ -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);

View file

@ -20,19 +20,19 @@ namespace Ryujinx.Graphics.Texture
}
}
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;

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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<T>(Span<byte> output, ReadOnlySpan<byte> data) where T : unmanaged
{
@ -166,7 +166,7 @@ namespace Ryujinx.Graphics.Texture
int wAligned = BitUtils.AlignUp(w, alignment);
BlockLinearLayout layoutConverter = new BlockLinearLayout(
BlockLinearLayout layoutConverter = new(
wAligned,
h,
mipGobBlocksInY,
@ -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<T>(Span<byte> output, ReadOnlySpan<byte> data) where T : unmanaged
{
@ -430,7 +430,7 @@ namespace Ryujinx.Graphics.Texture
int wAligned = BitUtils.AlignUp(w, alignment);
BlockLinearLayout layoutConverter = new BlockLinearLayout(
BlockLinearLayout layoutConverter = new(
wAligned,
h,
mipGobBlocksInY,

View file

@ -7,13 +7,13 @@ 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;

View file

@ -1,6 +1,5 @@
using Ryujinx.Common;
using System;
using static Ryujinx.Graphics.Texture.BlockLinearConstants;
namespace Ryujinx.Graphics.Texture

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -54,22 +54,22 @@ namespace Ryujinx.Graphics.Texture.Utils
return Unsafe.As<RgbaColor8, uint>(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
{