[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:
parent
fc20d9b925
commit
cebfa54467
File diff suppressed because it is too large
Load Diff
@ -6,4 +6,4 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
{
|
{
|
||||||
public AstcDecoderException(string exMsg) : base(exMsg) { }
|
public AstcDecoderException(string exMsg) : base(exMsg) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
Components[index] = (short)value;
|
Components[index] = (short)value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Pack()
|
public readonly int Pack()
|
||||||
{
|
{
|
||||||
return A << 24 |
|
return A << 24 |
|
||||||
B << 16 |
|
B << 16 |
|
||||||
|
@ -6,7 +6,9 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
{
|
{
|
||||||
public struct BitStream128
|
public struct BitStream128
|
||||||
{
|
{
|
||||||
|
#pragma warning disable IDE0044 // Make field readonly
|
||||||
private Buffer16 _data;
|
private Buffer16 _data;
|
||||||
|
#pragma warning restore IDE0044
|
||||||
public int BitsLeft { get; set; }
|
public int BitsLeft { get; set; }
|
||||||
|
|
||||||
public BitStream128(Buffer16 data)
|
public BitStream128(Buffer16 data)
|
||||||
@ -42,7 +44,10 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
{
|
{
|
||||||
Debug.Assert(bitCount < 32);
|
Debug.Assert(bitCount < 32);
|
||||||
|
|
||||||
if (bitCount == 0) return;
|
if (bitCount == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ulong maskedValue = (uint)(value & ((1 << bitCount) - 1));
|
ulong maskedValue = (uint)(value & ((1 << bitCount) - 1));
|
||||||
|
|
||||||
@ -69,4 +74,4 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
BitsLeft += bitCount;
|
BitsLeft += bitCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,15 @@
|
|||||||
|
|
||||||
public static int Replicate(int value, int numberBits, int toBit)
|
public static int Replicate(int value, int numberBits, int toBit)
|
||||||
{
|
{
|
||||||
if (numberBits == 0) return 0;
|
if (numberBits == 0)
|
||||||
if (toBit == 0) return 0;
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toBit == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int tempValue = value & ((1 << numberBits) - 1);
|
int tempValue = value & ((1 << numberBits) - 1);
|
||||||
int retValue = tempValue;
|
int retValue = tempValue;
|
||||||
@ -60,7 +67,10 @@
|
|||||||
b |= a & 0x80;
|
b |= a & 0x80;
|
||||||
a >>= 1;
|
a >>= 1;
|
||||||
a &= 0x3F;
|
a &= 0x3F;
|
||||||
if ((a & 0x20) != 0) a -= 0x40;
|
if ((a & 0x20) != 0)
|
||||||
|
{
|
||||||
|
a -= 0x40;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
internal struct IntegerEncoded
|
internal struct IntegerEncoded
|
||||||
{
|
{
|
||||||
internal const int StructSize = 8;
|
internal const int StructSize = 8;
|
||||||
private static readonly IntegerEncoded[] Encodings;
|
private static readonly IntegerEncoded[] _encodings;
|
||||||
|
|
||||||
public enum EIntegerEncoding : byte
|
public enum EIntegerEncoding : byte
|
||||||
{
|
{
|
||||||
@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
Trit
|
Trit
|
||||||
}
|
}
|
||||||
|
|
||||||
EIntegerEncoding _encoding;
|
readonly EIntegerEncoding _encoding;
|
||||||
public byte NumberBits { get; private set; }
|
public byte NumberBits { get; private set; }
|
||||||
public byte TritValue { get; private set; }
|
public byte TritValue { get; private set; }
|
||||||
public byte QuintValue { get; private set; }
|
public byte QuintValue { get; private set; }
|
||||||
@ -23,11 +23,11 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
|
|
||||||
static IntegerEncoded()
|
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;
|
QuintValue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MatchesEncoding(IntegerEncoded other)
|
public readonly bool MatchesEncoding(IntegerEncoded other)
|
||||||
{
|
{
|
||||||
return _encoding == other._encoding && NumberBits == other.NumberBits;
|
return _encoding == other._encoding && NumberBits == other.NumberBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EIntegerEncoding GetEncoding()
|
public readonly EIntegerEncoding GetEncoding()
|
||||||
{
|
{
|
||||||
return _encoding;
|
return _encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetBitLength(int numberVals)
|
public readonly int GetBitLength(int numberVals)
|
||||||
{
|
{
|
||||||
int totalBits = NumberBits * numberVals;
|
int totalBits = NumberBits * numberVals;
|
||||||
if (_encoding == EIntegerEncoding.Trit)
|
if (_encoding == EIntegerEncoding.Trit)
|
||||||
@ -66,7 +66,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
|
|
||||||
public static IntegerEncoded CreateEncoding(int maxVal)
|
public static IntegerEncoded CreateEncoding(int maxVal)
|
||||||
{
|
{
|
||||||
return Encodings[maxVal];
|
return _encodings[maxVal];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IntegerEncoded CreateEncodingCalc(int maxVal)
|
private static IntegerEncoded CreateEncodingCalc(int maxVal)
|
||||||
@ -122,7 +122,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
|
|
||||||
ReadOnlySpan<byte> encodings = GetTritEncoding(encoded);
|
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++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
@ -159,7 +159,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
IntegerEncoded intEncoded = new IntegerEncoded(EIntegerEncoding.Quint, numberBitsPerValue)
|
IntegerEncoded intEncoded = new(EIntegerEncoding.Quint, numberBitsPerValue)
|
||||||
{
|
{
|
||||||
BitValue = m[i],
|
BitValue = m[i],
|
||||||
QuintValue = encodings[i]
|
QuintValue = encodings[i]
|
||||||
@ -185,29 +185,29 @@ namespace Ryujinx.Graphics.Texture.Astc
|
|||||||
switch (intEncoded.GetEncoding())
|
switch (intEncoded.GetEncoding())
|
||||||
{
|
{
|
||||||
case EIntegerEncoding.Quint:
|
case EIntegerEncoding.Quint:
|
||||||
{
|
{
|
||||||
DecodeQuintBlock(ref bitStream, ref decodeIntegerSequence, intEncoded.NumberBits);
|
DecodeQuintBlock(ref bitStream, ref decodeIntegerSequence, intEncoded.NumberBits);
|
||||||
numberValuesDecoded += 3;
|
numberValuesDecoded += 3;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EIntegerEncoding.Trit:
|
case EIntegerEncoding.Trit:
|
||||||
{
|
{
|
||||||
DecodeTritBlock(ref bitStream, ref decodeIntegerSequence, intEncoded.NumberBits);
|
DecodeTritBlock(ref bitStream, ref decodeIntegerSequence, intEncoded.NumberBits);
|
||||||
numberValuesDecoded += 5;
|
numberValuesDecoded += 5;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EIntegerEncoding.JustBits:
|
case EIntegerEncoding.JustBits:
|
||||||
{
|
{
|
||||||
intEncoded.BitValue = bitStream.ReadBits(intEncoded.NumberBits);
|
intEncoded.BitValue = bitStream.ReadBits(intEncoded.NumberBits);
|
||||||
decodeIntegerSequence.Add(ref intEncoded);
|
decodeIntegerSequence.Add(ref intEncoded);
|
||||||
numberValuesDecoded++;
|
numberValuesDecoded++;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int x2 = x * 4;
|
int x2 = x * 4;
|
||||||
int bw = Math.Min(4, width - x2);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int x2 = x * 4;
|
int x2 = x * 4;
|
||||||
int bw = Math.Min(4, width - x2);
|
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)
|
switch (rotation)
|
||||||
{
|
{
|
||||||
case 1: color.A = color.R; color.R = a; break;
|
case 1:
|
||||||
case 2: color.A = color.G; color.G = a; break;
|
color.A = color.R;
|
||||||
case 3: color.A = color.B; color.B = a; break;
|
color.R = a;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
color.A = color.G;
|
||||||
|
color.G = a;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
color.A = color.B;
|
||||||
|
color.B = a;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,10 +54,10 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
if (copyHeight == 4)
|
if (copyHeight == 4)
|
||||||
{
|
{
|
||||||
outputLine0 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs));
|
outputLine0 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[lineBaseOOffs..]);
|
||||||
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width));
|
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width)..]);
|
||||||
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 2));
|
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width * 2)..]);
|
||||||
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 3));
|
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width * 3)..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = 0; x < w; x++)
|
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)
|
if (copyHeight == 4)
|
||||||
{
|
{
|
||||||
outputLine0 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs));
|
outputLine0 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[lineBaseOOffs..]);
|
||||||
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width));
|
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width)..]);
|
||||||
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 2));
|
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width * 2)..]);
|
||||||
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 3));
|
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width * 3)..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = 0; x < w; x++)
|
for (int x = 0; x < w; x++)
|
||||||
@ -153,7 +153,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int baseX = x * BlockWidth;
|
int baseX = x * BlockWidth;
|
||||||
int copyWidth = Math.Min(BlockWidth, width - baseX);
|
int copyWidth = Math.Min(BlockWidth, width - baseX);
|
||||||
|
|
||||||
BC23DecodeTileRgb(tile, data.Slice(8));
|
BC23DecodeTileRgb(tile, data[8..]);
|
||||||
|
|
||||||
ulong block = BinaryPrimitives.ReadUInt64LittleEndian(data);
|
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)
|
if (copyHeight == 4)
|
||||||
{
|
{
|
||||||
outputLine0 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs));
|
outputLine0 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[lineBaseOOffs..]);
|
||||||
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width));
|
outputLine1 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width)..]);
|
||||||
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 2));
|
outputLine2 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width * 2)..]);
|
||||||
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint.Slice(lineBaseOOffs + width * 3));
|
outputLine3 = MemoryMarshal.Cast<uint, Vector128<byte>>(outputAsUint[(lineBaseOOffs + width * 3)..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = 0; x < w; x++)
|
for (int x = 0; x < w; x++)
|
||||||
@ -249,7 +249,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int baseX = x * BlockWidth;
|
int baseX = x * BlockWidth;
|
||||||
int copyWidth = Math.Min(BlockWidth, width - baseX);
|
int copyWidth = Math.Min(BlockWidth, width - baseX);
|
||||||
|
|
||||||
BC23DecodeTileRgb(tile, data.Slice(8));
|
BC23DecodeTileRgb(tile, data[8..]);
|
||||||
|
|
||||||
ulong block = BinaryPrimitives.ReadUInt64LittleEndian(data);
|
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);
|
int alignedWidth = BitUtils.AlignUp(width, 4);
|
||||||
|
|
||||||
byte[] output = new byte[size];
|
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);
|
ReadOnlySpan<ulong> data64 = MemoryMarshal.Cast<byte, ulong>(data);
|
||||||
|
|
||||||
@ -338,10 +338,10 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
if (copyHeight == 4)
|
if (copyHeight == 4)
|
||||||
{
|
{
|
||||||
outputLine0 = MemoryMarshal.Cast<byte, uint>(outputSpan.Slice(lineBaseOOffs));
|
outputLine0 = MemoryMarshal.Cast<byte, uint>(outputSpan[lineBaseOOffs..]);
|
||||||
outputLine1 = MemoryMarshal.Cast<byte, uint>(outputSpan.Slice(lineBaseOOffs + alignedWidth));
|
outputLine1 = MemoryMarshal.Cast<byte, uint>(outputSpan[(lineBaseOOffs + alignedWidth)..]);
|
||||||
outputLine2 = MemoryMarshal.Cast<byte, uint>(outputSpan.Slice(lineBaseOOffs + alignedWidth * 2));
|
outputLine2 = MemoryMarshal.Cast<byte, uint>(outputSpan[(lineBaseOOffs + alignedWidth * 2)..]);
|
||||||
outputLine3 = MemoryMarshal.Cast<byte, uint>(outputSpan.Slice(lineBaseOOffs + alignedWidth * 3));
|
outputLine3 = MemoryMarshal.Cast<byte, uint>(outputSpan[(lineBaseOOffs + alignedWidth * 3)..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = 0; x < w; x++)
|
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)
|
if (copyHeight == 4)
|
||||||
{
|
{
|
||||||
outputLine0 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort.Slice(lineBaseOOffs));
|
outputLine0 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort[lineBaseOOffs..]);
|
||||||
outputLine1 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort.Slice(lineBaseOOffs + alignedWidth));
|
outputLine1 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort[(lineBaseOOffs + alignedWidth)..]);
|
||||||
outputLine2 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort.Slice(lineBaseOOffs + alignedWidth * 2));
|
outputLine2 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort[(lineBaseOOffs + alignedWidth * 2)..]);
|
||||||
outputLine3 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort.Slice(lineBaseOOffs + alignedWidth * 3));
|
outputLine3 = MemoryMarshal.Cast<ushort, ulong>(outputAsUshort[(lineBaseOOffs + alignedWidth * 3)..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = 0; x < w; x++)
|
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++)
|
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;
|
inputOffset += w * h * 16;
|
||||||
outputOffset += width * height * 8;
|
outputOffset += width * height * 8;
|
||||||
@ -586,7 +586,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
{
|
{
|
||||||
for (int z = 0; z < depth; z++)
|
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;
|
inputOffset += w * h * 16;
|
||||||
outputOffset += width * height * 4;
|
outputOffset += width * height * 4;
|
||||||
@ -813,7 +813,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
{
|
{
|
||||||
Span<uint> outputAsUint = MemoryMarshal.Cast<byte, uint>(output);
|
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)
|
for (int i = 0; i < BlockWidth * BlockHeight; i++, indices >>= 2)
|
||||||
{
|
{
|
||||||
@ -891,4 +891,4 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return r | (g & 0xff00) | (b & 0xff0000);
|
return r | (g & 0xff00) | (b & 0xff0000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,6 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
for (int l = 0; l < levels; l++)
|
for (int l = 0; l < levels; l++)
|
||||||
{
|
{
|
||||||
int rgba8Size = width * height * depth * layers * 4;
|
|
||||||
|
|
||||||
int w = BitUtils.DivRoundUp(width, BlockWidth);
|
int w = BitUtils.DivRoundUp(width, BlockWidth);
|
||||||
int h = BitUtils.DivRoundUp(height, BlockHeight);
|
int h = BitUtils.DivRoundUp(height, BlockHeight);
|
||||||
|
|
||||||
@ -38,8 +36,8 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
for (int z = 0; z < depth; z++)
|
for (int z = 0; z < depth; z++)
|
||||||
{
|
{
|
||||||
BC7Encoder.Encode(
|
BC7Encoder.Encode(
|
||||||
output.AsMemory().Slice(imageBaseOOffs),
|
output.AsMemory()[imageBaseOOffs..],
|
||||||
data.AsMemory().Slice(imageBaseIOffs),
|
data.AsMemory()[imageBaseIOffs..],
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
EncodeMode.Fast | EncodeMode.Multithreaded);
|
EncodeMode.Fast | EncodeMode.Multithreaded);
|
||||||
@ -57,4 +55,4 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,4 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
public const int GobSize = GobStride * GobHeight;
|
public const int GobSize = GobStride * GobHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,24 +15,24 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
public RobAndSliceSizes(int robSize, int sliceSize)
|
public RobAndSliceSizes(int robSize, int sliceSize)
|
||||||
{
|
{
|
||||||
RobSize = robSize;
|
RobSize = robSize;
|
||||||
SliceSize = sliceSize;
|
SliceSize = sliceSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _texBpp;
|
private readonly int _texBpp;
|
||||||
|
|
||||||
private int _bhMask;
|
private readonly int _bhMask;
|
||||||
private int _bdMask;
|
private readonly int _bdMask;
|
||||||
|
|
||||||
private int _bhShift;
|
private readonly int _bhShift;
|
||||||
private int _bdShift;
|
private readonly int _bdShift;
|
||||||
private int _bppShift;
|
private readonly int _bppShift;
|
||||||
|
|
||||||
private int _xShift;
|
private readonly int _xShift;
|
||||||
|
|
||||||
private int _robSize;
|
private readonly int _robSize;
|
||||||
private int _sliceSize;
|
private readonly int _sliceSize;
|
||||||
|
|
||||||
// Variables for built in iteration.
|
// Variables for built in iteration.
|
||||||
private int _yPart;
|
private int _yPart;
|
||||||
@ -60,7 +60,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
RobAndSliceSizes rsSizes = GetRobAndSliceSizes(width, height, gobBlocksInY, gobBlocksInZ);
|
RobAndSliceSizes rsSizes = GetRobAndSliceSizes(width, height, gobBlocksInY, gobBlocksInZ);
|
||||||
|
|
||||||
_robSize = rsSizes.RobSize;
|
_robSize = rsSizes.RobSize;
|
||||||
_sliceSize = rsSizes.SliceSize;
|
_sliceSize = rsSizes.SliceSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,4 +192,4 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return offset + _yzPart;
|
return offset + _yzPart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
namespace Ryujinx.Graphics.Texture
|
namespace Ryujinx.Graphics.Texture
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 12)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 12)]
|
||||||
public struct Bpp12Pixel
|
public readonly struct Bpp12Pixel
|
||||||
{
|
{
|
||||||
private ulong _elem1;
|
private readonly ulong _elem1;
|
||||||
private uint _elem2;
|
private readonly uint _elem2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,12 +119,12 @@ namespace Ryujinx.Graphics.Texture.Encoders
|
|||||||
{
|
{
|
||||||
uint c = tile[i];
|
uint c = tile[i];
|
||||||
|
|
||||||
if (!uniqueRGB.Slice(0, uniqueRGBCount).Contains(c & rgbMask))
|
if (!uniqueRGB[..uniqueRGBCount].Contains(c & rgbMask))
|
||||||
{
|
{
|
||||||
uniqueRGB[uniqueRGBCount++] = c & rgbMask;
|
uniqueRGB[uniqueRGBCount++] = c & rgbMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!uniqueAlpha.Slice(0, uniqueAlphaCount).Contains(c & alphaMask))
|
if (!uniqueAlpha[..uniqueAlphaCount].Contains(c & alphaMask))
|
||||||
{
|
{
|
||||||
uniqueAlpha[uniqueAlphaCount++] = c & alphaMask;
|
uniqueAlpha[uniqueAlphaCount++] = c & alphaMask;
|
||||||
}
|
}
|
||||||
@ -356,7 +356,7 @@ namespace Ryujinx.Graphics.Texture.Encoders
|
|||||||
|
|
||||||
bool alphaSwapSubset = alphaIndices[0] >= (alphaIndexCount >> 1);
|
bool alphaSwapSubset = alphaIndices[0] >= (alphaIndexCount >> 1);
|
||||||
|
|
||||||
Block block = new Block();
|
Block block = new();
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
@ -591,7 +591,7 @@ namespace Ryujinx.Graphics.Texture.Encoders
|
|||||||
RgbaColor32 e132 = RgbaColor8.FromUInt32(c1).GetColor32();
|
RgbaColor32 e132 = RgbaColor8.FromUInt32(c1).GetColor32();
|
||||||
|
|
||||||
palette[0] = e032;
|
palette[0] = e032;
|
||||||
palette[palette.Length - 1] = e132;
|
palette[^1] = e132;
|
||||||
|
|
||||||
for (int i = 1; i < palette.Length - 1; i++)
|
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);
|
int distRange = Math.Max(1, maxDist - minDist);
|
||||||
|
|
||||||
RgbaColor32 nV = new RgbaColor32(n);
|
RgbaColor32 nV = new(n);
|
||||||
|
|
||||||
int bestErrorSum = int.MaxValue;
|
int bestErrorSum = int.MaxValue;
|
||||||
RgbaColor8 bestE0 = default;
|
RgbaColor8 bestE0 = default;
|
||||||
@ -922,8 +922,8 @@ namespace Ryujinx.Graphics.Texture.Encoders
|
|||||||
|
|
||||||
for (int start = 0; start < numInterpolatedColors - maxIndex; start++)
|
for (int start = 0; start < numInterpolatedColors - maxIndex; start++)
|
||||||
{
|
{
|
||||||
RgbaColor32 sumY = new RgbaColor32(0);
|
RgbaColor32 sumY = new(0);
|
||||||
RgbaColor32 sumXY = new RgbaColor32(0);
|
RgbaColor32 sumXY = new(0);
|
||||||
|
|
||||||
for (int i = 0; i < indices.Length; i++)
|
for (int i = 0; i < indices.Length; i++)
|
||||||
{
|
{
|
||||||
@ -933,8 +933,8 @@ namespace Ryujinx.Graphics.Texture.Encoders
|
|||||||
sumXY += new RgbaColor32(start + indices[i]) * y;
|
sumXY += new RgbaColor32(start + indices[i]) * y;
|
||||||
}
|
}
|
||||||
|
|
||||||
RgbaColor32 sumXV = new RgbaColor32(sumX);
|
RgbaColor32 sumXV = new(sumX);
|
||||||
RgbaColor32 sumXXV = new RgbaColor32(sumXX);
|
RgbaColor32 sumXXV = new(sumXX);
|
||||||
RgbaColor32 m = RgbaColor32.DivideGuarded((nV * sumXY - sumXV * sumY) << 6, nV * sumXXV - sumXV * sumXV, 0);
|
RgbaColor32 m = RgbaColor32.DivideGuarded((nV * sumXY - sumXV * sumY) << 6, nV * sumXXV - sumXV * sumXV, 0);
|
||||||
RgbaColor32 b = ((sumY << 6) - m * sumXV) / nV;
|
RgbaColor32 b = ((sumY << 6) - m * sumXV) / nV;
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
int wAligned = BitUtils.AlignUp(width, alignment);
|
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
|
unsafe bool Convert<T>(Span<byte> output, ReadOnlySpan<byte> data) where T : unmanaged
|
||||||
{
|
{
|
||||||
@ -126,14 +126,14 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int mipGobBlocksInY = gobBlocksInY;
|
int mipGobBlocksInY = gobBlocksInY;
|
||||||
int mipGobBlocksInZ = gobBlocksInZ;
|
int mipGobBlocksInZ = gobBlocksInZ;
|
||||||
|
|
||||||
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
||||||
int gobHeight = gobBlocksInY * GobHeight;
|
int gobHeight = gobBlocksInY * GobHeight;
|
||||||
|
|
||||||
for (int level = 0; level < levels; level++)
|
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 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);
|
w = BitUtils.DivRoundUp(w, blockWidth);
|
||||||
h = BitUtils.DivRoundUp(h, blockHeight);
|
h = BitUtils.DivRoundUp(h, blockHeight);
|
||||||
@ -166,7 +166,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
int wAligned = BitUtils.AlignUp(w, alignment);
|
int wAligned = BitUtils.AlignUp(w, alignment);
|
||||||
|
|
||||||
BlockLinearLayout layoutConverter = new BlockLinearLayout(
|
BlockLinearLayout layoutConverter = new(
|
||||||
wAligned,
|
wAligned,
|
||||||
h,
|
h,
|
||||||
mipGobBlocksInY,
|
mipGobBlocksInY,
|
||||||
@ -256,7 +256,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int bytesPerPixel,
|
int bytesPerPixel,
|
||||||
ReadOnlySpan<byte> data)
|
ReadOnlySpan<byte> data)
|
||||||
{
|
{
|
||||||
int w = BitUtils.DivRoundUp(width, blockWidth);
|
int w = BitUtils.DivRoundUp(width, blockWidth);
|
||||||
int h = BitUtils.DivRoundUp(height, blockHeight);
|
int h = BitUtils.DivRoundUp(height, blockHeight);
|
||||||
|
|
||||||
int outStride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment);
|
int outStride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment);
|
||||||
@ -301,7 +301,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
int wAligned = BitUtils.AlignUp(width, alignment);
|
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
|
unsafe bool Convert<T>(Span<byte> output, ReadOnlySpan<byte> data) where T : unmanaged
|
||||||
{
|
{
|
||||||
@ -390,14 +390,14 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int mipGobBlocksInY = gobBlocksInY;
|
int mipGobBlocksInY = gobBlocksInY;
|
||||||
int mipGobBlocksInZ = gobBlocksInZ;
|
int mipGobBlocksInZ = gobBlocksInZ;
|
||||||
|
|
||||||
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
||||||
int gobHeight = gobBlocksInY * GobHeight;
|
int gobHeight = gobBlocksInY * GobHeight;
|
||||||
|
|
||||||
for (int level = 0; level < levels; level++)
|
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 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);
|
w = BitUtils.DivRoundUp(w, blockWidth);
|
||||||
h = BitUtils.DivRoundUp(h, blockHeight);
|
h = BitUtils.DivRoundUp(h, blockHeight);
|
||||||
@ -430,7 +430,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
int wAligned = BitUtils.AlignUp(w, alignment);
|
int wAligned = BitUtils.AlignUp(w, alignment);
|
||||||
|
|
||||||
BlockLinearLayout layoutConverter = new BlockLinearLayout(
|
BlockLinearLayout layoutConverter = new(
|
||||||
wAligned,
|
wAligned,
|
||||||
h,
|
h,
|
||||||
mipGobBlocksInY,
|
mipGobBlocksInY,
|
||||||
@ -521,7 +521,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int bytesPerPixel,
|
int bytesPerPixel,
|
||||||
ReadOnlySpan<byte> data)
|
ReadOnlySpan<byte> data)
|
||||||
{
|
{
|
||||||
int w = BitUtils.DivRoundUp(width, blockWidth);
|
int w = BitUtils.DivRoundUp(width, blockWidth);
|
||||||
int h = BitUtils.DivRoundUp(height, blockHeight);
|
int h = BitUtils.DivRoundUp(height, blockHeight);
|
||||||
|
|
||||||
int inStride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment);
|
int inStride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment);
|
||||||
@ -573,9 +573,9 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
for (int level = 0; level < levels; level++)
|
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 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);
|
w = BitUtils.DivRoundUp(w, blockWidth);
|
||||||
h = BitUtils.DivRoundUp(h, blockHeight);
|
h = BitUtils.DivRoundUp(h, blockHeight);
|
||||||
@ -588,4 +588,4 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return layerSize * layers;
|
return layerSize * layers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,30 +7,30 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
{
|
{
|
||||||
public class OffsetCalculator
|
public class OffsetCalculator
|
||||||
{
|
{
|
||||||
private int _width;
|
private readonly int _width;
|
||||||
private int _height;
|
private readonly int _height;
|
||||||
private int _stride;
|
private readonly int _stride;
|
||||||
private bool _isLinear;
|
private readonly bool _isLinear;
|
||||||
private int _bytesPerPixel;
|
private readonly int _bytesPerPixel;
|
||||||
|
|
||||||
private BlockLinearLayout _layoutConverter;
|
private readonly BlockLinearLayout _layoutConverter;
|
||||||
|
|
||||||
// Variables for built in iteration.
|
// Variables for built in iteration.
|
||||||
private int _yPart;
|
private int _yPart;
|
||||||
|
|
||||||
public OffsetCalculator(
|
public OffsetCalculator(
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int stride,
|
int stride,
|
||||||
bool isLinear,
|
bool isLinear,
|
||||||
int gobBlocksInY,
|
int gobBlocksInY,
|
||||||
int gobBlocksInZ,
|
int gobBlocksInZ,
|
||||||
int bytesPerPixel)
|
int bytesPerPixel)
|
||||||
{
|
{
|
||||||
_width = width;
|
_width = width;
|
||||||
_height = height;
|
_height = height;
|
||||||
_stride = stride;
|
_stride = stride;
|
||||||
_isLinear = isLinear;
|
_isLinear = isLinear;
|
||||||
_bytesPerPixel = bytesPerPixel;
|
_bytesPerPixel = bytesPerPixel;
|
||||||
|
|
||||||
int wAlignment = GobStride / bytesPerPixel;
|
int wAlignment = GobStride / bytesPerPixel;
|
||||||
@ -138,4 +138,4 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,9 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
{
|
{
|
||||||
uint packed = inputSpan[offset++];
|
uint packed = inputSpan[offset++];
|
||||||
|
|
||||||
uint outputPacked = 0xff000000;
|
uint outputPacked = 0xff000000;
|
||||||
outputPacked |= (packed << 3) & 0x000000f8;
|
outputPacked |= (packed << 3) & 0x000000f8;
|
||||||
outputPacked |= (packed << 8) & 0x00f80000;
|
outputPacked |= (packed << 8) & 0x00f80000;
|
||||||
|
|
||||||
// Replicate 5 bit components.
|
// Replicate 5 bit components.
|
||||||
outputPacked |= (outputPacked >> 5) & 0x00070007;
|
outputPacked |= (outputPacked >> 5) & 0x00070007;
|
||||||
@ -126,10 +126,10 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
uint a = forceAlpha ? 1 : (packed >> 15);
|
uint a = forceAlpha ? 1 : (packed >> 15);
|
||||||
|
|
||||||
uint outputPacked = a * 0xff000000;
|
uint outputPacked = a * 0xff000000;
|
||||||
outputPacked |= (packed << 3) & 0x000000f8;
|
outputPacked |= (packed << 3) & 0x000000f8;
|
||||||
outputPacked |= (packed << 6) & 0x0000f800;
|
outputPacked |= (packed << 6) & 0x0000f800;
|
||||||
outputPacked |= (packed << 9) & 0x00f80000;
|
outputPacked |= (packed << 9) & 0x00f80000;
|
||||||
|
|
||||||
// Replicate 5 bit components.
|
// Replicate 5 bit components.
|
||||||
outputPacked |= (outputPacked >> 5) & 0x00070707;
|
outputPacked |= (outputPacked >> 5) & 0x00070707;
|
||||||
@ -198,10 +198,10 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
{
|
{
|
||||||
uint packed = inputSpan[offset++];
|
uint packed = inputSpan[offset++];
|
||||||
|
|
||||||
uint outputPacked = packed & 0x0000000f;
|
uint outputPacked = packed & 0x0000000f;
|
||||||
outputPacked |= (packed << 4) & 0x00000f00;
|
outputPacked |= (packed << 4) & 0x00000f00;
|
||||||
outputPacked |= (packed << 8) & 0x000f0000;
|
outputPacked |= (packed << 8) & 0x000f0000;
|
||||||
outputPacked |= (packed << 12) & 0x0f000000;
|
outputPacked |= (packed << 12) & 0x0f000000;
|
||||||
|
|
||||||
outputSpan[outOffset++] = outputPacked * 0x11;
|
outputSpan[outOffset++] = outputPacked * 0x11;
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,15 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
{
|
{
|
||||||
public readonly struct Size
|
public readonly struct Size
|
||||||
{
|
{
|
||||||
public int Width { get; }
|
public int Width { get; }
|
||||||
public int Height { get; }
|
public int Height { get; }
|
||||||
public int Depth { get; }
|
public int Depth { get; }
|
||||||
|
|
||||||
public Size(int width, int height, int depth)
|
public Size(int width, int height, int depth)
|
||||||
{
|
{
|
||||||
Width = width;
|
Width = width;
|
||||||
Height = height;
|
Height = height;
|
||||||
Depth = depth;
|
Depth = depth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using Ryujinx.Common;
|
using Ryujinx.Common;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using static Ryujinx.Graphics.Texture.BlockLinearConstants;
|
using static Ryujinx.Graphics.Texture.BlockLinearConstants;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Texture
|
namespace Ryujinx.Graphics.Texture
|
||||||
@ -48,16 +47,16 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int mipGobBlocksInY = gobBlocksInY;
|
int mipGobBlocksInY = gobBlocksInY;
|
||||||
int mipGobBlocksInZ = gobBlocksInZ;
|
int mipGobBlocksInZ = gobBlocksInZ;
|
||||||
|
|
||||||
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
||||||
int gobHeight = gobBlocksInY * GobHeight;
|
int gobHeight = gobBlocksInY * GobHeight;
|
||||||
|
|
||||||
int depthLevelOffset = 0;
|
int depthLevelOffset = 0;
|
||||||
|
|
||||||
for (int level = 0; level < levels; level++)
|
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 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);
|
w = BitUtils.DivRoundUp(w, blockWidth);
|
||||||
h = BitUtils.DivRoundUp(h, blockHeight);
|
h = BitUtils.DivRoundUp(h, blockHeight);
|
||||||
@ -104,7 +103,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
|
|
||||||
for (int z = 0; z < d; z++)
|
for (int z = 0; z < d; z++)
|
||||||
{
|
{
|
||||||
int zLow = z & mask;
|
int zLow = z & mask;
|
||||||
int zHigh = z & ~mask;
|
int zHigh = z & ~mask;
|
||||||
|
|
||||||
allOffsets[z + depthLevelOffset] = baseOffset + zLow * gobSize + zHigh * sliceSize;
|
allOffsets[z + depthLevelOffset] = baseOffset + zLow * gobSize + zHigh * sliceSize;
|
||||||
@ -159,7 +158,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
{
|
{
|
||||||
for (int layer = 0; layer < layers; layer++)
|
for (int layer = 0; layer < layers; layer++)
|
||||||
{
|
{
|
||||||
int baseIndex = layer * levels;
|
int baseIndex = layer * levels;
|
||||||
int baseOffset = layer * layerSize;
|
int baseOffset = layer * layerSize;
|
||||||
|
|
||||||
for (int level = 0; level < levels; level++)
|
for (int level = 0; level < levels; level++)
|
||||||
@ -234,10 +233,10 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int gobBlocksInZ,
|
int gobBlocksInZ,
|
||||||
int gobBlocksInTileX)
|
int gobBlocksInTileX)
|
||||||
{
|
{
|
||||||
width = BitUtils.DivRoundUp(width, blockWidth);
|
width = BitUtils.DivRoundUp(width, blockWidth);
|
||||||
height = BitUtils.DivRoundUp(height, blockHeight);
|
height = BitUtils.DivRoundUp(height, blockHeight);
|
||||||
|
|
||||||
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
||||||
int gobHeight = gobBlocksInY * GobHeight;
|
int gobHeight = gobBlocksInY * GobHeight;
|
||||||
|
|
||||||
int alignment = gobWidth;
|
int alignment = gobWidth;
|
||||||
@ -251,11 +250,11 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
(gobBlocksInY, gobBlocksInZ) = GetMipGobBlockSizes(height, depth, 1, gobBlocksInY, gobBlocksInZ);
|
(gobBlocksInY, gobBlocksInZ) = GetMipGobBlockSizes(height, depth, 1, gobBlocksInY, gobBlocksInZ);
|
||||||
|
|
||||||
int blockOfGobsHeight = gobBlocksInY * GobHeight;
|
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);
|
height = BitUtils.AlignUp(height, blockOfGobsHeight);
|
||||||
depth = BitUtils.AlignUp(depth, blockOfGobsDepth);
|
depth = BitUtils.AlignUp(depth, blockOfGobsDepth);
|
||||||
|
|
||||||
return new Size(width, height, depth);
|
return new Size(width, height, depth);
|
||||||
}
|
}
|
||||||
@ -267,7 +266,7 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int blockHeight,
|
int blockHeight,
|
||||||
int bytesPerPixel)
|
int bytesPerPixel)
|
||||||
{
|
{
|
||||||
width = BitUtils.DivRoundUp(width, blockWidth);
|
width = BitUtils.DivRoundUp(width, blockWidth);
|
||||||
height = BitUtils.DivRoundUp(height, blockHeight);
|
height = BitUtils.DivRoundUp(height, blockHeight);
|
||||||
|
|
||||||
int widthAlignment = StrideAlignment / bytesPerPixel;
|
int widthAlignment = StrideAlignment / bytesPerPixel;
|
||||||
@ -300,4 +299,4 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
return (gobBlocksInY, gobBlocksInZ);
|
return (gobBlocksInY, gobBlocksInZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,14 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
public SizeInfo(int size)
|
public SizeInfo(int size)
|
||||||
{
|
{
|
||||||
_mipOffsets = new int[] { 0 };
|
_mipOffsets = new int[] { 0 };
|
||||||
AllOffsets = new int[] { 0 };
|
AllOffsets = new int[] { 0 };
|
||||||
SliceSizes = new int[] { size };
|
SliceSizes = new int[] { size };
|
||||||
LevelSizes = new int[] { size };
|
LevelSizes = new int[] { size };
|
||||||
_depth = 1;
|
_depth = 1;
|
||||||
_levels = 1;
|
_levels = 1;
|
||||||
LayerSize = size;
|
LayerSize = size;
|
||||||
TotalSize = size;
|
TotalSize = size;
|
||||||
_is3D = false;
|
_is3D = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal SizeInfo(
|
internal SizeInfo(
|
||||||
@ -35,21 +35,21 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
int[] allOffsets,
|
int[] allOffsets,
|
||||||
int[] sliceSizes,
|
int[] sliceSizes,
|
||||||
int[] levelSizes,
|
int[] levelSizes,
|
||||||
int depth,
|
int depth,
|
||||||
int levels,
|
int levels,
|
||||||
int layerSize,
|
int layerSize,
|
||||||
int totalSize,
|
int totalSize,
|
||||||
bool is3D)
|
bool is3D)
|
||||||
{
|
{
|
||||||
_mipOffsets = mipOffsets;
|
_mipOffsets = mipOffsets;
|
||||||
AllOffsets = allOffsets;
|
AllOffsets = allOffsets;
|
||||||
SliceSizes = sliceSizes;
|
SliceSizes = sliceSizes;
|
||||||
LevelSizes = levelSizes;
|
LevelSizes = levelSizes;
|
||||||
_depth = depth;
|
_depth = depth;
|
||||||
_levels = levels;
|
_levels = levels;
|
||||||
LayerSize = layerSize;
|
LayerSize = layerSize;
|
||||||
TotalSize = totalSize;
|
TotalSize = totalSize;
|
||||||
_is3D = is3D;
|
_is3D = is3D;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetMipOffset(int level)
|
public int GetMipOffset(int level)
|
||||||
@ -116,4 +116,4 @@ namespace Ryujinx.Graphics.Texture
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ namespace Ryujinx.Graphics.Texture.Utils
|
|||||||
{
|
{
|
||||||
static class BC67Utils
|
static class BC67Utils
|
||||||
{
|
{
|
||||||
private static byte[][] _quantizationLut;
|
private static readonly byte[][] _quantizationLut;
|
||||||
private static byte[][] _quantizationLutNoPBit;
|
private static readonly byte[][] _quantizationLutNoPBit;
|
||||||
|
|
||||||
static BC67Utils()
|
static BC67Utils()
|
||||||
{
|
{
|
||||||
@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Texture.Utils
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RgbaColor8 minColor = new RgbaColor8(255, 255, 255, 255);
|
RgbaColor8 minColor = new(255, 255, 255, 255);
|
||||||
RgbaColor8 maxColor = default;
|
RgbaColor8 maxColor = default;
|
||||||
|
|
||||||
for (int i = 0; i < tile.Length; i++)
|
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;
|
int weight = (((weightIndex << 7) / ((1 << indexBitCount) - 1)) + 1) >> 1;
|
||||||
|
|
||||||
RgbaColor32 weightV = new RgbaColor32(weight);
|
RgbaColor32 weightV = new(weight);
|
||||||
RgbaColor32 invWeightV = new RgbaColor32(64 - weight);
|
RgbaColor32 invWeightV = new(64 - weight);
|
||||||
|
|
||||||
return (color1 * invWeightV + color2 * weightV + new RgbaColor32(32)) >> 6;
|
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 colorWeight = BC67Tables.Weights[colorIndexBitCount - 2][colorWeightIndex];
|
||||||
int alphaWeight = BC67Tables.Weights[alphaIndexBitCount - 2][alphaWeightIndex];
|
int alphaWeight = BC67Tables.Weights[alphaIndexBitCount - 2][alphaWeightIndex];
|
||||||
|
|
||||||
RgbaColor32 weightV = new RgbaColor32(colorWeight);
|
RgbaColor32 weightV = new(colorWeight)
|
||||||
weightV.A = alphaWeight;
|
{
|
||||||
|
A = alphaWeight
|
||||||
|
};
|
||||||
RgbaColor32 invWeightV = new RgbaColor32(64) - weightV;
|
RgbaColor32 invWeightV = new RgbaColor32(64) - weightV;
|
||||||
|
|
||||||
return (color1 * invWeightV + color2 * weightV + new RgbaColor32(32)) >> 6;
|
return (color1 * invWeightV + color2 * weightV + new RgbaColor32(32)) >> 6;
|
||||||
|
@ -34,4 +34,4 @@ namespace Ryujinx.Graphics.Texture.Utils
|
|||||||
AlphaDepth = alphaDepth;
|
AlphaDepth = alphaDepth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace Ryujinx.Graphics.Texture.Utils
|
|||||||
offset += bits;
|
offset += bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ulong Decode(ref int offset, int bits)
|
public readonly ulong Decode(ref int offset, int bits)
|
||||||
{
|
{
|
||||||
ulong value;
|
ulong value;
|
||||||
ulong mask = bits == 64 ? ulong.MaxValue : (1UL << bits) - 1;
|
ulong mask = bits == 64 ? ulong.MaxValue : (1UL << bits) - 1;
|
||||||
@ -52,4 +52,4 @@ namespace Ryujinx.Graphics.Texture.Utils
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,25 +11,25 @@ namespace Ryujinx.Graphics.Texture.Utils
|
|||||||
|
|
||||||
public int R
|
public int R
|
||||||
{
|
{
|
||||||
get => _color.GetElement(0);
|
readonly get => _color.GetElement(0);
|
||||||
set => _color = _color.WithElement(0, value);
|
set => _color = _color.WithElement(0, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int G
|
public int G
|
||||||
{
|
{
|
||||||
get => _color.GetElement(1);
|
readonly get => _color.GetElement(1);
|
||||||
set => _color = _color.WithElement(1, value);
|
set => _color = _color.WithElement(1, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int B
|
public int B
|
||||||
{
|
{
|
||||||
get => _color.GetElement(2);
|
readonly get => _color.GetElement(2);
|
||||||
set => _color = _color.WithElement(2, value);
|
set => _color = _color.WithElement(2, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int A
|
public int A
|
||||||
{
|
{
|
||||||
get => _color.GetElement(3);
|
readonly get => _color.GetElement(3);
|
||||||
set => _color = _color.WithElement(3, value);
|
set => _color = _color.WithElement(3, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ namespace Ryujinx.Graphics.Texture.Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public RgbaColor8 GetColor8()
|
public readonly RgbaColor8 GetColor8()
|
||||||
{
|
{
|
||||||
if (Sse41.IsSupported)
|
if (Sse41.IsSupported)
|
||||||
{
|
{
|
||||||
@ -211,17 +211,17 @@ namespace Ryujinx.Graphics.Texture.Utils
|
|||||||
return (byte)Math.Clamp(value, 0, 255);
|
return (byte)Math.Clamp(value, 0, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public readonly override int GetHashCode()
|
||||||
{
|
{
|
||||||
return HashCode.Combine(R, G, B, A);
|
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);
|
return obj is RgbaColor32 other && Equals(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(RgbaColor32 other)
|
public readonly bool Equals(RgbaColor32 other)
|
||||||
{
|
{
|
||||||
return _color.Equals(other._color);
|
return _color.Equals(other._color);
|
||||||
}
|
}
|
||||||
|
@ -54,22 +54,22 @@ namespace Ryujinx.Graphics.Texture.Utils
|
|||||||
return Unsafe.As<RgbaColor8, uint>(ref this);
|
return Unsafe.As<RgbaColor8, uint>(ref this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public readonly override int GetHashCode()
|
||||||
{
|
{
|
||||||
return HashCode.Combine(R, G, B, A);
|
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);
|
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;
|
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
|
return index switch
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user