From 33cb66370bc45f3edc1a9ee1948bc66acb546655 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sun, 3 Mar 2019 13:13:55 -0600 Subject: [PATCH] Renaming part 6 --- Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs | 2 +- .../Graphics3d/Texture/ASTCDecoder.cs | 1060 ++++++++--------- .../Graphics3d/Texture/ASTCPixel.cs | 86 +- .../Graphics3d/Texture/BitArrayStream.cs | 90 +- .../Graphics3d/Texture/BlockLinearSwizzle.cs | 180 +-- .../Graphics3d/Texture/ISwizzle.cs | 8 +- .../Graphics3d/Texture/ImageUtils.cs | 312 ++--- .../Graphics3d/Texture/IntegerEncoded.cs | 194 +-- .../Graphics3d/Texture/LinearSwizzle.cs | 34 +- .../Graphics3d/Texture/TextureFactory.cs | 188 +-- .../Graphics3d/Texture/TextureHelper.cs | 46 +- .../Graphics3d/Texture/TextureSwizzle.cs | 2 +- 12 files changed, 1101 insertions(+), 1101 deletions(-) diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs index 326d765cef..767dbd2d85 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs @@ -190,7 +190,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL int textureBlockHeight = ImageUtils.GetBlockHeight(image.Format); int textureBlockDepth = ImageUtils.GetBlockDepth(image.Format); - data = ASTCDecoder.DecodeToRGBA8888( + data = AstcDecoder.DecodeToRGBA8888( data, textureBlockWidth, textureBlockHeight, diff --git a/Ryujinx.Graphics/Graphics3d/Texture/ASTCDecoder.cs b/Ryujinx.Graphics/Graphics3d/Texture/ASTCDecoder.cs index 580a693521..12b53759c2 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/ASTCDecoder.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/ASTCDecoder.cs @@ -6,13 +6,13 @@ using System.IO; namespace Ryujinx.Graphics.Texture { - public class ASTCDecoderException : Exception + public class AstcDecoderException : Exception { - public ASTCDecoderException(string ExMsg) : base(ExMsg) { } + public AstcDecoderException(string exMsg) : base(exMsg) { } } //https://github.com/GammaUNC/FasTC/blob/master/ASTCEncoder/src/Decompressor.cpp - public static class ASTCDecoder + public static class AstcDecoder { struct TexelWeightParams { @@ -21,424 +21,424 @@ namespace Ryujinx.Graphics.Texture public bool DualPlane; public int MaxWeight; public bool Error; - public bool VoidExtentLDR; - public bool VoidExtentHDR; + public bool VoidExtentLdr; + public bool VoidExtentHdr; public int GetPackedBitSize() { // How many indices do we have? - int Indices = Height * Width; + int indices = Height * Width; if (DualPlane) { - Indices *= 2; + indices *= 2; } - IntegerEncoded IntEncoded = IntegerEncoded.CreateEncoding(MaxWeight); + IntegerEncoded intEncoded = IntegerEncoded.CreateEncoding(MaxWeight); - return IntEncoded.GetBitLength(Indices); + return intEncoded.GetBitLength(indices); } public int GetNumWeightValues() { - int Ret = Width * Height; + int ret = Width * Height; if (DualPlane) { - Ret *= 2; + ret *= 2; } - return Ret; + return ret; } } public static byte[] DecodeToRGBA8888( - byte[] InputBuffer, - int BlockX, - int BlockY, - int BlockZ, - int X, - int Y, - int Z) + byte[] inputBuffer, + int blockX, + int blockY, + int blockZ, + int x, + int y, + int z) { - using (MemoryStream InputStream = new MemoryStream(InputBuffer)) + using (MemoryStream inputStream = new MemoryStream(inputBuffer)) { - BinaryReader BinReader = new BinaryReader(InputStream); + BinaryReader binReader = new BinaryReader(inputStream); - if (BlockX > 12 || BlockY > 12) + if (blockX > 12 || blockY > 12) { - throw new ASTCDecoderException("Block size unsupported!"); + throw new AstcDecoderException("Block size unsupported!"); } - if (BlockZ != 1 || Z != 1) + if (blockZ != 1 || z != 1) { // TODO: Support 3D textures? - throw new ASTCDecoderException("3D compressed textures unsupported!"); + throw new AstcDecoderException("3D compressed textures unsupported!"); } - using (MemoryStream OutputStream = new MemoryStream()) + using (MemoryStream outputStream = new MemoryStream()) { - int BlockIndex = 0; + int blockIndex = 0; - for (int j = 0; j < Y; j += BlockY) + for (int j = 0; j < y; j += blockY) { - for (int i = 0; i < X; i += BlockX) + for (int i = 0; i < x; i += blockX) { - int[] DecompressedData = new int[144]; + int[] decompressedData = new int[144]; - DecompressBlock(BinReader.ReadBytes(0x10), DecompressedData, BlockX, BlockY); + DecompressBlock(binReader.ReadBytes(0x10), decompressedData, blockX, blockY); - int DecompressedWidth = Math.Min(BlockX, X - i); - int DecompressedHeight = Math.Min(BlockY, Y - j); - int BaseOffsets = (j * X + i) * 4; + int decompressedWidth = Math.Min(blockX, x - i); + int decompressedHeight = Math.Min(blockY, y - j); + int baseOffsets = (j * x + i) * 4; - for (int jj = 0; jj < DecompressedHeight; jj++) + for (int jj = 0; jj < decompressedHeight; jj++) { - OutputStream.Seek(BaseOffsets + jj * X * 4, SeekOrigin.Begin); + outputStream.Seek(baseOffsets + jj * x * 4, SeekOrigin.Begin); - byte[] OutputBuffer = new byte[DecompressedData.Length * sizeof(int)]; - Buffer.BlockCopy(DecompressedData, 0, OutputBuffer, 0, OutputBuffer.Length); + byte[] outputBuffer = new byte[decompressedData.Length * sizeof(int)]; + Buffer.BlockCopy(decompressedData, 0, outputBuffer, 0, outputBuffer.Length); - OutputStream.Write(OutputBuffer, jj * BlockX * 4, DecompressedWidth * 4); + outputStream.Write(outputBuffer, jj * blockX * 4, decompressedWidth * 4); } - BlockIndex++; + blockIndex++; } } - return OutputStream.ToArray(); + return outputStream.ToArray(); } } } public static bool DecompressBlock( - byte[] InputBuffer, - int[] OutputBuffer, - int BlockWidth, - int BlockHeight) + byte[] inputBuffer, + int[] outputBuffer, + int blockWidth, + int blockHeight) { - BitArrayStream BitStream = new BitArrayStream(new BitArray(InputBuffer)); - TexelWeightParams TexelParams = DecodeBlockInfo(BitStream); + BitArrayStream bitStream = new BitArrayStream(new BitArray(inputBuffer)); + TexelWeightParams texelParams = DecodeBlockInfo(bitStream); - if (TexelParams.Error) + if (texelParams.Error) { - throw new ASTCDecoderException("Invalid block mode"); + throw new AstcDecoderException("Invalid block mode"); } - if (TexelParams.VoidExtentLDR) + if (texelParams.VoidExtentLdr) { - FillVoidExtentLDR(BitStream, OutputBuffer, BlockWidth, BlockHeight); + FillVoidExtentLdr(bitStream, outputBuffer, blockWidth, blockHeight); return true; } - if (TexelParams.VoidExtentHDR) + if (texelParams.VoidExtentHdr) { - throw new ASTCDecoderException("HDR void extent blocks are unsupported!"); + throw new AstcDecoderException("HDR void extent blocks are unsupported!"); } - if (TexelParams.Width > BlockWidth) + if (texelParams.Width > blockWidth) { - throw new ASTCDecoderException("Texel weight grid width should be smaller than block width"); + throw new AstcDecoderException("Texel weight grid width should be smaller than block width"); } - if (TexelParams.Height > BlockHeight) + if (texelParams.Height > blockHeight) { - throw new ASTCDecoderException("Texel weight grid height should be smaller than block height"); + throw new AstcDecoderException("Texel weight grid height should be smaller than block height"); } // Read num partitions - int NumberPartitions = BitStream.ReadBits(2) + 1; - Debug.Assert(NumberPartitions <= 4); + int numberPartitions = bitStream.ReadBits(2) + 1; + Debug.Assert(numberPartitions <= 4); - if (NumberPartitions == 4 && TexelParams.DualPlane) + if (numberPartitions == 4 && texelParams.DualPlane) { - throw new ASTCDecoderException("Dual plane mode is incompatible with four partition blocks"); + throw new AstcDecoderException("Dual plane mode is incompatible with four partition blocks"); } // Based on the number of partitions, read the color endpoint mode for // each partition. // Determine partitions, partition index, and color endpoint modes - int PlaneIndices = -1; - int PartitionIndex; - uint[] ColorEndpointMode = { 0, 0, 0, 0 }; + int planeIndices = -1; + int partitionIndex; + uint[] colorEndpointMode = { 0, 0, 0, 0 }; - BitArrayStream ColorEndpointStream = new BitArrayStream(new BitArray(16 * 8)); + BitArrayStream colorEndpointStream = new BitArrayStream(new BitArray(16 * 8)); // Read extra config data... - uint BaseColorEndpointMode = 0; + uint baseColorEndpointMode = 0; - if (NumberPartitions == 1) + if (numberPartitions == 1) { - ColorEndpointMode[0] = (uint)BitStream.ReadBits(4); - PartitionIndex = 0; + colorEndpointMode[0] = (uint)bitStream.ReadBits(4); + partitionIndex = 0; } else { - PartitionIndex = BitStream.ReadBits(10); - BaseColorEndpointMode = (uint)BitStream.ReadBits(6); + partitionIndex = bitStream.ReadBits(10); + baseColorEndpointMode = (uint)bitStream.ReadBits(6); } - uint BaseMode = (BaseColorEndpointMode & 3); + uint baseMode = (baseColorEndpointMode & 3); // Remaining bits are color endpoint data... - int NumberWeightBits = TexelParams.GetPackedBitSize(); - int RemainingBits = 128 - NumberWeightBits - BitStream.Position; + int numberWeightBits = texelParams.GetPackedBitSize(); + int remainingBits = 128 - numberWeightBits - bitStream.Position; // Consider extra bits prior to texel data... - uint ExtraColorEndpointModeBits = 0; + uint extraColorEndpointModeBits = 0; - if (BaseMode != 0) + if (baseMode != 0) { - switch (NumberPartitions) + switch (numberPartitions) { - case 2: ExtraColorEndpointModeBits += 2; break; - case 3: ExtraColorEndpointModeBits += 5; break; - case 4: ExtraColorEndpointModeBits += 8; break; + case 2: extraColorEndpointModeBits += 2; break; + case 3: extraColorEndpointModeBits += 5; break; + case 4: extraColorEndpointModeBits += 8; break; default: Debug.Assert(false); break; } } - RemainingBits -= (int)ExtraColorEndpointModeBits; + remainingBits -= (int)extraColorEndpointModeBits; // Do we have a dual plane situation? - int PlaneSelectorBits = 0; + int planeSelectorBits = 0; - if (TexelParams.DualPlane) + if (texelParams.DualPlane) { - PlaneSelectorBits = 2; + planeSelectorBits = 2; } - RemainingBits -= PlaneSelectorBits; + remainingBits -= planeSelectorBits; // Read color data... - int ColorDataBits = RemainingBits; + int colorDataBits = remainingBits; - while (RemainingBits > 0) + while (remainingBits > 0) { - int NumberBits = Math.Min(RemainingBits, 8); - int Bits = BitStream.ReadBits(NumberBits); - ColorEndpointStream.WriteBits(Bits, NumberBits); - RemainingBits -= 8; + int numberBits = Math.Min(remainingBits, 8); + int bits = bitStream.ReadBits(numberBits); + colorEndpointStream.WriteBits(bits, numberBits); + remainingBits -= 8; } // Read the plane selection bits - PlaneIndices = BitStream.ReadBits(PlaneSelectorBits); + planeIndices = bitStream.ReadBits(planeSelectorBits); // Read the rest of the CEM - if (BaseMode != 0) + if (baseMode != 0) { - uint ExtraColorEndpointMode = (uint)BitStream.ReadBits((int)ExtraColorEndpointModeBits); - uint TempColorEndpointMode = (ExtraColorEndpointMode << 6) | BaseColorEndpointMode; - TempColorEndpointMode >>= 2; + uint extraColorEndpointMode = (uint)bitStream.ReadBits((int)extraColorEndpointModeBits); + uint tempColorEndpointMode = (extraColorEndpointMode << 6) | baseColorEndpointMode; + tempColorEndpointMode >>= 2; - bool[] C = new bool[4]; + bool[] c = new bool[4]; - for (int i = 0; i < NumberPartitions; i++) + for (int i = 0; i < numberPartitions; i++) { - C[i] = (TempColorEndpointMode & 1) != 0; - TempColorEndpointMode >>= 1; + c[i] = (tempColorEndpointMode & 1) != 0; + tempColorEndpointMode >>= 1; } - byte[] M = new byte[4]; + byte[] m = new byte[4]; - for (int i = 0; i < NumberPartitions; i++) + for (int i = 0; i < numberPartitions; i++) { - M[i] = (byte)(TempColorEndpointMode & 3); - TempColorEndpointMode >>= 2; - Debug.Assert(M[i] <= 3); + m[i] = (byte)(tempColorEndpointMode & 3); + tempColorEndpointMode >>= 2; + Debug.Assert(m[i] <= 3); } - for (int i = 0; i < NumberPartitions; i++) + for (int i = 0; i < numberPartitions; i++) { - ColorEndpointMode[i] = BaseMode; - if (!(C[i])) ColorEndpointMode[i] -= 1; - ColorEndpointMode[i] <<= 2; - ColorEndpointMode[i] |= M[i]; + colorEndpointMode[i] = baseMode; + if (!(c[i])) colorEndpointMode[i] -= 1; + colorEndpointMode[i] <<= 2; + colorEndpointMode[i] |= m[i]; } } - else if (NumberPartitions > 1) + else if (numberPartitions > 1) { - uint TempColorEndpointMode = BaseColorEndpointMode >> 2; + uint tempColorEndpointMode = baseColorEndpointMode >> 2; - for (uint i = 0; i < NumberPartitions; i++) + for (uint i = 0; i < numberPartitions; i++) { - ColorEndpointMode[i] = TempColorEndpointMode; + colorEndpointMode[i] = tempColorEndpointMode; } } // Make sure everything up till here is sane. - for (int i = 0; i < NumberPartitions; i++) + for (int i = 0; i < numberPartitions; i++) { - Debug.Assert(ColorEndpointMode[i] < 16); + Debug.Assert(colorEndpointMode[i] < 16); } - Debug.Assert(BitStream.Position + TexelParams.GetPackedBitSize() == 128); + Debug.Assert(bitStream.Position + texelParams.GetPackedBitSize() == 128); // Decode both color data and texel weight data - int[] ColorValues = new int[32]; // Four values * two endpoints * four maximum partitions - DecodeColorValues(ColorValues, ColorEndpointStream.ToByteArray(), ColorEndpointMode, NumberPartitions, ColorDataBits); + int[] colorValues = new int[32]; // Four values * two endpoints * four maximum partitions + DecodeColorValues(colorValues, colorEndpointStream.ToByteArray(), colorEndpointMode, numberPartitions, colorDataBits); - ASTCPixel[][] EndPoints = new ASTCPixel[4][]; - EndPoints[0] = new ASTCPixel[2]; - EndPoints[1] = new ASTCPixel[2]; - EndPoints[2] = new ASTCPixel[2]; - EndPoints[3] = new ASTCPixel[2]; + AstcPixel[][] endPoints = new AstcPixel[4][]; + endPoints[0] = new AstcPixel[2]; + endPoints[1] = new AstcPixel[2]; + endPoints[2] = new AstcPixel[2]; + endPoints[3] = new AstcPixel[2]; - int ColorValuesPosition = 0; + int colorValuesPosition = 0; - for (int i = 0; i < NumberPartitions; i++) + for (int i = 0; i < numberPartitions; i++) { - ComputeEndpoints(EndPoints[i], ColorValues, ColorEndpointMode[i], ref ColorValuesPosition); + ComputeEndpoints(endPoints[i], colorValues, colorEndpointMode[i], ref colorValuesPosition); } // Read the texel weight data. - byte[] TexelWeightData = (byte[])InputBuffer.Clone(); + byte[] texelWeightData = (byte[])inputBuffer.Clone(); // Reverse everything for (int i = 0; i < 8; i++) { - byte a = ReverseByte(TexelWeightData[i]); - byte b = ReverseByte(TexelWeightData[15 - i]); + byte a = ReverseByte(texelWeightData[i]); + byte b = ReverseByte(texelWeightData[15 - i]); - TexelWeightData[i] = b; - TexelWeightData[15 - i] = a; + texelWeightData[i] = b; + texelWeightData[15 - i] = a; } // Make sure that higher non-texel bits are set to zero - int ClearByteStart = (TexelParams.GetPackedBitSize() >> 3) + 1; - TexelWeightData[ClearByteStart - 1] &= (byte)((1 << (TexelParams.GetPackedBitSize() % 8)) - 1); + int clearByteStart = (texelParams.GetPackedBitSize() >> 3) + 1; + texelWeightData[clearByteStart - 1] &= (byte)((1 << (texelParams.GetPackedBitSize() % 8)) - 1); - int cLen = 16 - ClearByteStart; - for (int i = ClearByteStart; i < ClearByteStart + cLen; i++) TexelWeightData[i] = 0; + int cLen = 16 - clearByteStart; + for (int i = clearByteStart; i < clearByteStart + cLen; i++) texelWeightData[i] = 0; - List TexelWeightValues = new List(); - BitArrayStream WeightBitStream = new BitArrayStream(new BitArray(TexelWeightData)); + List texelWeightValues = new List(); + BitArrayStream weightBitStream = new BitArrayStream(new BitArray(texelWeightData)); - IntegerEncoded.DecodeIntegerSequence(TexelWeightValues, WeightBitStream, TexelParams.MaxWeight, TexelParams.GetNumWeightValues()); + IntegerEncoded.DecodeIntegerSequence(texelWeightValues, weightBitStream, texelParams.MaxWeight, texelParams.GetNumWeightValues()); // Blocks can be at most 12x12, so we can have as many as 144 weights - int[][] Weights = new int[2][]; - Weights[0] = new int[144]; - Weights[1] = new int[144]; + int[][] weights = new int[2][]; + weights[0] = new int[144]; + weights[1] = new int[144]; - UnquantizeTexelWeights(Weights, TexelWeightValues, TexelParams, BlockWidth, BlockHeight); + UnquantizeTexelWeights(weights, texelWeightValues, texelParams, blockWidth, blockHeight); // Now that we have endpoints and weights, we can interpolate and generate // the proper decoding... - for (int j = 0; j < BlockHeight; j++) + for (int j = 0; j < blockHeight; j++) { - for (int i = 0; i < BlockWidth; i++) + for (int i = 0; i < blockWidth; i++) { - int Partition = Select2DPartition(PartitionIndex, i, j, NumberPartitions, ((BlockHeight * BlockWidth) < 32)); - Debug.Assert(Partition < NumberPartitions); + int partition = Select2DPartition(partitionIndex, i, j, numberPartitions, ((blockHeight * blockWidth) < 32)); + Debug.Assert(partition < numberPartitions); - ASTCPixel Pixel = new ASTCPixel(0, 0, 0, 0); - for (int Component = 0; Component < 4; Component++) + AstcPixel pixel = new AstcPixel(0, 0, 0, 0); + for (int component = 0; component < 4; component++) { - int Component0 = EndPoints[Partition][0].GetComponent(Component); - Component0 = BitArrayStream.Replicate(Component0, 8, 16); - int Component1 = EndPoints[Partition][1].GetComponent(Component); - Component1 = BitArrayStream.Replicate(Component1, 8, 16); + int component0 = endPoints[partition][0].GetComponent(component); + component0 = BitArrayStream.Replicate(component0, 8, 16); + int component1 = endPoints[partition][1].GetComponent(component); + component1 = BitArrayStream.Replicate(component1, 8, 16); - int Plane = 0; + int plane = 0; - if (TexelParams.DualPlane && (((PlaneIndices + 1) & 3) == Component)) + if (texelParams.DualPlane && (((planeIndices + 1) & 3) == component)) { - Plane = 1; + plane = 1; } - int Weight = Weights[Plane][j * BlockWidth + i]; - int FinalComponent = (Component0 * (64 - Weight) + Component1 * Weight + 32) / 64; + int weight = weights[plane][j * blockWidth + i]; + int finalComponent = (component0 * (64 - weight) + component1 * weight + 32) / 64; - if (FinalComponent == 65535) + if (finalComponent == 65535) { - Pixel.SetComponent(Component, 255); + pixel.SetComponent(component, 255); } else { - double FinalComponentFloat = FinalComponent; - Pixel.SetComponent(Component, (int)(255.0 * (FinalComponentFloat / 65536.0) + 0.5)); + double finalComponentFloat = finalComponent; + pixel.SetComponent(component, (int)(255.0 * (finalComponentFloat / 65536.0) + 0.5)); } } - OutputBuffer[j * BlockWidth + i] = Pixel.Pack(); + outputBuffer[j * blockWidth + i] = pixel.Pack(); } } return true; } - private static int Select2DPartition(int Seed, int X, int Y, int PartitionCount, bool IsSmallBlock) + private static int Select2DPartition(int seed, int x, int y, int partitionCount, bool isSmallBlock) { - return SelectPartition(Seed, X, Y, 0, PartitionCount, IsSmallBlock); + return SelectPartition(seed, x, y, 0, partitionCount, isSmallBlock); } - private static int SelectPartition(int Seed, int X, int Y, int Z, int PartitionCount, bool IsSmallBlock) + private static int SelectPartition(int seed, int x, int y, int z, int partitionCount, bool isSmallBlock) { - if (PartitionCount == 1) + if (partitionCount == 1) { return 0; } - if (IsSmallBlock) + if (isSmallBlock) { - X <<= 1; - Y <<= 1; - Z <<= 1; + x <<= 1; + y <<= 1; + z <<= 1; } - Seed += (PartitionCount - 1) * 1024; + seed += (partitionCount - 1) * 1024; - int RightNum = Hash52((uint)Seed); - byte Seed01 = (byte)(RightNum & 0xF); - byte Seed02 = (byte)((RightNum >> 4) & 0xF); - byte Seed03 = (byte)((RightNum >> 8) & 0xF); - byte Seed04 = (byte)((RightNum >> 12) & 0xF); - byte Seed05 = (byte)((RightNum >> 16) & 0xF); - byte Seed06 = (byte)((RightNum >> 20) & 0xF); - byte Seed07 = (byte)((RightNum >> 24) & 0xF); - byte Seed08 = (byte)((RightNum >> 28) & 0xF); - byte Seed09 = (byte)((RightNum >> 18) & 0xF); - byte Seed10 = (byte)((RightNum >> 22) & 0xF); - byte Seed11 = (byte)((RightNum >> 26) & 0xF); - byte Seed12 = (byte)(((RightNum >> 30) | (RightNum << 2)) & 0xF); + int rightNum = Hash52((uint)seed); + byte seed01 = (byte)(rightNum & 0xF); + byte seed02 = (byte)((rightNum >> 4) & 0xF); + byte seed03 = (byte)((rightNum >> 8) & 0xF); + byte seed04 = (byte)((rightNum >> 12) & 0xF); + byte seed05 = (byte)((rightNum >> 16) & 0xF); + byte seed06 = (byte)((rightNum >> 20) & 0xF); + byte seed07 = (byte)((rightNum >> 24) & 0xF); + byte seed08 = (byte)((rightNum >> 28) & 0xF); + byte seed09 = (byte)((rightNum >> 18) & 0xF); + byte seed10 = (byte)((rightNum >> 22) & 0xF); + 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; + int seedHash1, seedHash2, seedHash3; - if ((Seed & 1) != 0) + if ((seed & 1) != 0) { - SeedHash1 = (Seed & 2) != 0 ? 4 : 5; - SeedHash2 = (PartitionCount == 3) ? 6 : 5; + seedHash1 = (seed & 2) != 0 ? 4 : 5; + seedHash2 = (partitionCount == 3) ? 6 : 5; } else { - SeedHash1 = (PartitionCount == 3) ? 6 : 5; - SeedHash2 = (Seed & 2) != 0 ? 4 : 5; + seedHash1 = (partitionCount == 3) ? 6 : 5; + seedHash2 = (seed & 2) != 0 ? 4 : 5; } - SeedHash3 = (Seed & 0x10) != 0 ? SeedHash1 : SeedHash2; + 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); + 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; - 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; @@ -446,62 +446,62 @@ namespace Ryujinx.Graphics.Texture return 3; } - static int Hash52(uint Val) + 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; + return (int)val; } static void UnquantizeTexelWeights( - int[][] OutputBuffer, - List Weights, - TexelWeightParams TexelParams, - int BlockWidth, - int BlockHeight) + int[][] outputBuffer, + List weights, + TexelWeightParams texelParams, + int blockWidth, + int blockHeight) { - int WeightIndices = 0; - int[][] Unquantized = new int[2][]; - Unquantized[0] = new int[144]; - Unquantized[1] = new int[144]; + int weightIndices = 0; + int[][] unquantized = new int[2][]; + unquantized[0] = new int[144]; + unquantized[1] = new int[144]; - for (int i = 0; i < Weights.Count; i++) + for (int i = 0; i < weights.Count; i++) { - Unquantized[0][WeightIndices] = UnquantizeTexelWeight(Weights[i]); + unquantized[0][weightIndices] = UnquantizeTexelWeight(weights[i]); - if (TexelParams.DualPlane) + if (texelParams.DualPlane) { i++; - Unquantized[1][WeightIndices] = UnquantizeTexelWeight(Weights[i]); + unquantized[1][weightIndices] = UnquantizeTexelWeight(weights[i]); - if (i == Weights.Count) + if (i == weights.Count) { break; } } - if (++WeightIndices >= (TexelParams.Width * TexelParams.Height)) break; + if (++weightIndices >= (texelParams.Width * texelParams.Height)) break; } // Do infill if necessary (Section C.2.18) ... - int Ds = (1024 + (BlockWidth / 2)) / (BlockWidth - 1); - int Dt = (1024 + (BlockHeight / 2)) / (BlockHeight - 1); + int ds = (1024 + (blockWidth / 2)) / (blockWidth - 1); + int dt = (1024 + (blockHeight / 2)) / (blockHeight - 1); - int PlaneScale = TexelParams.DualPlane ? 2 : 1; + int planeScale = texelParams.DualPlane ? 2 : 1; - for (int Plane = 0; Plane < PlaneScale; Plane++) + for (int plane = 0; plane < planeScale; plane++) { - for (int t = 0; t < BlockHeight; t++) + for (int t = 0; t < blockHeight; t++) { - for (int s = 0; s < BlockWidth; s++) + for (int s = 0; s < blockWidth; s++) { - int cs = Ds * s; - int ct = Dt * t; + int cs = ds * s; + int ct = dt * t; - int gs = (cs * (TexelParams.Width - 1) + 32) >> 6; - int gt = (ct * (TexelParams.Height - 1) + 32) >> 6; + int gs = (cs * (texelParams.Width - 1) + 32) >> 6; + int gt = (ct * (texelParams.Height - 1) + 32) >> 6; int js = gs >> 4; int fs = gs & 0xF; @@ -514,96 +514,96 @@ namespace Ryujinx.Graphics.Texture int w01 = fs - w11; int w00 = 16 - fs - ft + w11; - int v0 = js + jt * TexelParams.Width; + int v0 = js + jt * texelParams.Width; int p00 = 0; int p01 = 0; int p10 = 0; int p11 = 0; - if (v0 < (TexelParams.Width * TexelParams.Height)) + if (v0 < (texelParams.Width * texelParams.Height)) { - p00 = Unquantized[Plane][v0]; + p00 = unquantized[plane][v0]; } - if (v0 + 1 < (TexelParams.Width * TexelParams.Height)) + if (v0 + 1 < (texelParams.Width * texelParams.Height)) { - p01 = Unquantized[Plane][v0 + 1]; + p01 = unquantized[plane][v0 + 1]; } - if (v0 + TexelParams.Width < (TexelParams.Width * TexelParams.Height)) + if (v0 + texelParams.Width < (texelParams.Width * texelParams.Height)) { - p10 = Unquantized[Plane][v0 + TexelParams.Width]; + p10 = unquantized[plane][v0 + texelParams.Width]; } - if (v0 + TexelParams.Width + 1 < (TexelParams.Width * TexelParams.Height)) + if (v0 + texelParams.Width + 1 < (texelParams.Width * texelParams.Height)) { - p11 = Unquantized[Plane][v0 + TexelParams.Width + 1]; + p11 = unquantized[plane][v0 + texelParams.Width + 1]; } - OutputBuffer[Plane][t * BlockWidth + s] = (p00 * w00 + p01 * w01 + p10 * w10 + p11 * w11 + 8) >> 4; + outputBuffer[plane][t * blockWidth + s] = (p00 * w00 + p01 * w01 + p10 * w10 + p11 * w11 + 8) >> 4; } } } } - static int UnquantizeTexelWeight(IntegerEncoded IntEncoded) + static int UnquantizeTexelWeight(IntegerEncoded intEncoded) { - int BitValue = IntEncoded.BitValue; - int BitLength = IntEncoded.NumberBits; + int bitValue = intEncoded.BitValue; + int bitLength = intEncoded.NumberBits; - int A = BitArrayStream.Replicate(BitValue & 1, 1, 7); - int B = 0, C = 0, D = 0; + int a = BitArrayStream.Replicate(bitValue & 1, 1, 7); + int b = 0, c = 0, d = 0; - int Result = 0; + int result = 0; - switch (IntEncoded.GetEncoding()) + switch (intEncoded.GetEncoding()) { case IntegerEncoded.EIntegerEncoding.JustBits: - Result = BitArrayStream.Replicate(BitValue, BitLength, 6); + result = BitArrayStream.Replicate(bitValue, bitLength, 6); break; case IntegerEncoded.EIntegerEncoding.Trit: { - D = IntEncoded.TritValue; - Debug.Assert(D < 3); + d = intEncoded.TritValue; + Debug.Assert(d < 3); - switch (BitLength) + switch (bitLength) { case 0: { - int[] Results = { 0, 32, 63 }; - Result = Results[D]; + int[] results = { 0, 32, 63 }; + result = results[d]; break; } case 1: { - C = 50; + c = 50; break; } case 2: { - C = 23; - int b2 = (BitValue >> 1) & 1; - B = (b2 << 6) | (b2 << 2) | b2; + 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; + c = 11; + int cb = (bitValue >> 1) & 3; + b = (cb << 5) | cb; break; } default: - throw new ASTCDecoderException("Invalid trit encoding for texel weight"); + throw new AstcDecoderException("Invalid trit encoding for texel weight"); } break; @@ -611,60 +611,60 @@ namespace Ryujinx.Graphics.Texture case IntegerEncoded.EIntegerEncoding.Quint: { - D = IntEncoded.QuintValue; - Debug.Assert(D < 5); + d = intEncoded.QuintValue; + Debug.Assert(d < 5); - switch (BitLength) + switch (bitLength) { case 0: { - int[] Results = { 0, 16, 32, 47, 63 }; - Result = Results[D]; + int[] results = { 0, 16, 32, 47, 63 }; + result = results[d]; break; } case 1: { - C = 28; + c = 28; break; } case 2: { - C = 13; - int b2 = (BitValue >> 1) & 1; - B = (b2 << 6) | (b2 << 1); + c = 13; + int b2 = (bitValue >> 1) & 1; + b = (b2 << 6) | (b2 << 1); break; } default: - throw new ASTCDecoderException("Invalid quint encoding for texel weight"); + throw new AstcDecoderException("Invalid quint encoding for texel weight"); } break; } } - if (IntEncoded.GetEncoding() != IntegerEncoded.EIntegerEncoding.JustBits && BitLength > 0) + if (intEncoded.GetEncoding() != IntegerEncoded.EIntegerEncoding.JustBits && bitLength > 0) { // Decode the value... - Result = D * C + B; - Result ^= A; - Result = (A & 0x20) | (Result >> 2); + result = d * c + b; + result ^= a; + result = (a & 0x20) | (result >> 2); } - Debug.Assert(Result < 64); + Debug.Assert(result < 64); // Change from [0,63] to [0,64] - if (Result > 32) + if (result > 32) { - Result += 1; + result += 1; } - return Result; + return result; } static byte ReverseByte(byte b) @@ -673,44 +673,44 @@ namespace Ryujinx.Graphics.Texture return (byte)((((b) * 0x80200802L) & 0x0884422110L) * 0x0101010101L >> 32); } - static uint[] ReadUintColorValues(int Number, int[] ColorValues, ref int ColorValuesPosition) + static uint[] ReadUintColorValues(int number, int[] colorValues, ref int colorValuesPosition) { - uint[] Ret = new uint[Number]; + uint[] ret = new uint[number]; - for (int i = 0; i < Number; i++) + for (int i = 0; i < number; i++) { - Ret[i] = (uint)ColorValues[ColorValuesPosition++]; + ret[i] = (uint)colorValues[colorValuesPosition++]; } - return Ret; + return ret; } - static int[] ReadIntColorValues(int Number, int[] ColorValues, ref int ColorValuesPosition) + static int[] ReadIntColorValues(int number, int[] colorValues, ref int colorValuesPosition) { - int[] Ret = new int[Number]; + int[] ret = new int[number]; - for (int i = 0; i < Number; i++) + for (int i = 0; i < number; i++) { - Ret[i] = ColorValues[ColorValuesPosition++]; + ret[i] = colorValues[colorValuesPosition++]; } - return Ret; + return ret; } static void ComputeEndpoints( - ASTCPixel[] EndPoints, - int[] ColorValues, - uint ColorEndpointMode, - ref int ColorValuesPosition) + AstcPixel[] endPoints, + int[] colorValues, + uint colorEndpointMode, + ref int colorValuesPosition) { - switch (ColorEndpointMode) + switch (colorEndpointMode) { case 0: { - uint[] Val = ReadUintColorValues(2, ColorValues, ref ColorValuesPosition); + uint[] val = ReadUintColorValues(2, colorValues, ref colorValuesPosition); - EndPoints[0] = new ASTCPixel(0xFF, (short)Val[0], (short)Val[0], (short)Val[0]); - EndPoints[1] = new ASTCPixel(0xFF, (short)Val[1], (short)Val[1], (short)Val[1]); + endPoints[0] = new AstcPixel(0xFF, (short)val[0], (short)val[0], (short)val[0]); + endPoints[1] = new AstcPixel(0xFF, (short)val[1], (short)val[1], (short)val[1]); break; } @@ -718,65 +718,65 @@ namespace Ryujinx.Graphics.Texture case 1: { - uint[] Val = ReadUintColorValues(2, ColorValues, ref ColorValuesPosition); - int L0 = (int)((Val[0] >> 2) | (Val[1] & 0xC0)); - int L1 = (int)Math.Max(L0 + (Val[1] & 0x3F), 0xFFU); + uint[] val = ReadUintColorValues(2, colorValues, ref colorValuesPosition); + int l0 = (int)((val[0] >> 2) | (val[1] & 0xC0)); + int l1 = (int)Math.Max(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; } case 4: { - uint[] Val = ReadUintColorValues(4, ColorValues, ref ColorValuesPosition); + uint[] val = ReadUintColorValues(4, colorValues, ref colorValuesPosition); - EndPoints[0] = new ASTCPixel((short)Val[2], (short)Val[0], (short)Val[0], (short)Val[0]); - EndPoints[1] = new ASTCPixel((short)Val[3], (short)Val[1], (short)Val[1], (short)Val[1]); + endPoints[0] = new AstcPixel((short)val[2], (short)val[0], (short)val[0], (short)val[0]); + endPoints[1] = new AstcPixel((short)val[3], (short)val[1], (short)val[1], (short)val[1]); break; } case 5: { - int[] Val = ReadIntColorValues(4, ColorValues, ref ColorValuesPosition); + int[] val = ReadIntColorValues(4, colorValues, ref colorValuesPosition); - BitArrayStream.BitTransferSigned(ref Val[1], ref Val[0]); - BitArrayStream.BitTransferSigned(ref Val[3], ref Val[2]); + BitArrayStream.BitTransferSigned(ref val[1], ref val[0]); + BitArrayStream.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; } case 6: { - uint[] Val = ReadUintColorValues(4, ColorValues, ref ColorValuesPosition); + uint[] val = ReadUintColorValues(4, colorValues, ref colorValuesPosition); - EndPoints[0] = new ASTCPixel(0xFF, (short)(Val[0] * Val[3] >> 8), (short)(Val[1] * Val[3] >> 8), (short)(Val[2] * Val[3] >> 8)); - EndPoints[1] = new ASTCPixel(0xFF, (short)Val[0], (short)Val[1], (short)Val[2]); + endPoints[0] = new AstcPixel(0xFF, (short)(val[0] * val[3] >> 8), (short)(val[1] * val[3] >> 8), (short)(val[2] * val[3] >> 8)); + endPoints[1] = new AstcPixel(0xFF, (short)val[0], (short)val[1], (short)val[2]); break; } case 8: { - uint[] Val = ReadUintColorValues(6, ColorValues, ref ColorValuesPosition); + uint[] val = ReadUintColorValues(6, colorValues, ref colorValuesPosition); - if (Val[1] + Val[3] + Val[5] >= Val[0] + Val[2] + Val[4]) + 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]); + 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]); + 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; @@ -784,52 +784,52 @@ namespace Ryujinx.Graphics.Texture case 9: { - int[] Val = ReadIntColorValues(6, ColorValues, ref ColorValuesPosition); + int[] val = ReadIntColorValues(6, colorValues, ref colorValuesPosition); - BitArrayStream.BitTransferSigned(ref Val[1], ref Val[0]); - BitArrayStream.BitTransferSigned(ref Val[3], ref Val[2]); - BitArrayStream.BitTransferSigned(ref Val[5], ref Val[4]); + BitArrayStream.BitTransferSigned(ref val[1], ref val[0]); + BitArrayStream.BitTransferSigned(ref val[3], ref val[2]); + BitArrayStream.BitTransferSigned(ref val[5], ref val[4]); - if (Val[1] + Val[3] + Val[5] >= 0) + 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])); + 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] = AstcPixel.BlueContract(0xFF, val[0] + val[1], val[2] + val[3], val[4] + val[5]); + endPoints[1] = AstcPixel.BlueContract(0xFF, val[0], val[2], val[4]); } - EndPoints[0].ClampByte(); - EndPoints[1].ClampByte(); + endPoints[0].ClampByte(); + endPoints[1].ClampByte(); break; } case 10: { - uint[] Val = ReadUintColorValues(6, ColorValues, ref ColorValuesPosition); + uint[] val = ReadUintColorValues(6, colorValues, ref colorValuesPosition); - EndPoints[0] = new ASTCPixel((short)Val[4], (short)(Val[0] * Val[3] >> 8), (short)(Val[1] * Val[3] >> 8), (short)(Val[2] * Val[3] >> 8)); - EndPoints[1] = new ASTCPixel((short)Val[5], (short)Val[0], (short)Val[1], (short)Val[2]); + endPoints[0] = new AstcPixel((short)val[4], (short)(val[0] * val[3] >> 8), (short)(val[1] * val[3] >> 8), (short)(val[2] * val[3] >> 8)); + endPoints[1] = new AstcPixel((short)val[5], (short)val[0], (short)val[1], (short)val[2]); break; } case 12: { - uint[] Val = ReadUintColorValues(8, ColorValues, ref ColorValuesPosition); + uint[] val = ReadUintColorValues(8, colorValues, ref colorValuesPosition); - if (Val[1] + Val[3] + Val[5] >= Val[0] + Val[2] + Val[4]) + 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]); + 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]); + 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; @@ -837,136 +837,136 @@ namespace Ryujinx.Graphics.Texture case 13: { - int[] Val = ReadIntColorValues(8, ColorValues, ref ColorValuesPosition); + int[] val = ReadIntColorValues(8, colorValues, ref colorValuesPosition); - BitArrayStream.BitTransferSigned(ref Val[1], ref Val[0]); - BitArrayStream.BitTransferSigned(ref Val[3], ref Val[2]); - BitArrayStream.BitTransferSigned(ref Val[5], ref Val[4]); - BitArrayStream.BitTransferSigned(ref Val[7], ref Val[6]); + BitArrayStream.BitTransferSigned(ref val[1], ref val[0]); + BitArrayStream.BitTransferSigned(ref val[3], ref val[2]); + BitArrayStream.BitTransferSigned(ref val[5], ref val[4]); + BitArrayStream.BitTransferSigned(ref val[7], ref val[6]); - if (Val[1] + Val[3] + Val[5] >= 0) + 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])); + 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] = AstcPixel.BlueContract(val[6] + val[7], val[0] + val[1], val[2] + val[3], val[4] + val[5]); + endPoints[1] = AstcPixel.BlueContract(val[6], val[0], val[2], val[4]); } - EndPoints[0].ClampByte(); - EndPoints[1].ClampByte(); + endPoints[0].ClampByte(); + endPoints[1].ClampByte(); break; } default: - throw new ASTCDecoderException("Unsupported color endpoint mode (is it HDR?)"); + throw new AstcDecoderException("Unsupported color endpoint mode (is it HDR?)"); } } static void DecodeColorValues( - int[] OutputValues, - byte[] InputData, - uint[] Modes, - int NumberPartitions, - int NumberBitsForColorData) + int[] outputValues, + byte[] inputData, + uint[] modes, + int numberPartitions, + int numberBitsForColorData) { // First figure out how many color values we have - int NumberValues = 0; + int numberValues = 0; - for (int i = 0; i < NumberPartitions; i++) + for (int i = 0; i < numberPartitions; i++) { - NumberValues += (int)((Modes[i] >> 2) + 1) << 1; + numberValues += (int)((modes[i] >> 2) + 1) << 1; } // Then based on the number of values and the remaining number of bits, // figure out the max value for each of them... - int Range = 256; + int range = 256; - while (--Range > 0) + while (--range > 0) { - IntegerEncoded IntEncoded = IntegerEncoded.CreateEncoding(Range); - int BitLength = IntEncoded.GetBitLength(NumberValues); + IntegerEncoded intEncoded = IntegerEncoded.CreateEncoding(range); + int bitLength = intEncoded.GetBitLength(numberValues); - if (BitLength <= NumberBitsForColorData) + if (bitLength <= numberBitsForColorData) { // Find the smallest possible range that matches the given encoding - while (--Range > 0) + while (--range > 0) { - IntegerEncoded NewIntEncoded = IntegerEncoded.CreateEncoding(Range); - if (!NewIntEncoded.MatchesEncoding(IntEncoded)) + IntegerEncoded newIntEncoded = IntegerEncoded.CreateEncoding(range); + if (!newIntEncoded.MatchesEncoding(intEncoded)) { break; } } // Return to last matching range. - Range++; + range++; break; } } // We now have enough to decode our integer sequence. - List IntegerEncodedSequence = new List(); - BitArrayStream ColorBitStream = new BitArrayStream(new BitArray(InputData)); + List integerEncodedSequence = new List(); + BitArrayStream colorBitStream = new BitArrayStream(new BitArray(inputData)); - IntegerEncoded.DecodeIntegerSequence(IntegerEncodedSequence, ColorBitStream, Range, NumberValues); + IntegerEncoded.DecodeIntegerSequence(integerEncodedSequence, colorBitStream, range, numberValues); // Once we have the decoded values, we need to dequantize them to the 0-255 range // This procedure is outlined in ASTC spec C.2.13 - int OutputIndices = 0; + int outputIndices = 0; - foreach (IntegerEncoded IntEncoded in IntegerEncodedSequence) + foreach (IntegerEncoded intEncoded in integerEncodedSequence) { - int BitLength = IntEncoded.NumberBits; - int BitValue = IntEncoded.BitValue; + int bitLength = intEncoded.NumberBits; + int bitValue = intEncoded.BitValue; - Debug.Assert(BitLength >= 1); + Debug.Assert(bitLength >= 1); - int A = 0, B = 0, C = 0, D = 0; + int a = 0, b = 0, c = 0, d = 0; // A is just the lsb replicated 9 times. - A = BitArrayStream.Replicate(BitValue & 1, 1, 9); + a = BitArrayStream.Replicate(bitValue & 1, 1, 9); - switch (IntEncoded.GetEncoding()) + switch (intEncoded.GetEncoding()) { case IntegerEncoded.EIntegerEncoding.JustBits: { - OutputValues[OutputIndices++] = BitArrayStream.Replicate(BitValue, BitLength, 8); + outputValues[outputIndices++] = BitArrayStream.Replicate(bitValue, bitLength, 8); break; } case IntegerEncoded.EIntegerEncoding.Trit: { - D = IntEncoded.TritValue; + d = intEncoded.TritValue; - switch (BitLength) + switch (bitLength) { case 1: { - C = 204; + c = 204; break; } case 2: { - C = 93; + c = 93; // B = b000b0bb0 - int b2 = (BitValue >> 1) & 1; - B = (b2 << 8) | (b2 << 4) | (b2 << 2) | (b2 << 1); + int b2 = (bitValue >> 1) & 1; + b = (b2 << 8) | (b2 << 4) | (b2 << 2) | (b2 << 1); break; } case 3: { - C = 44; + c = 44; // B = cb000cbcb - int cb = (BitValue >> 1) & 3; - B = (cb << 7) | (cb << 2) | cb; + int cb = (bitValue >> 1) & 3; + b = (cb << 7) | (cb << 2) | cb; break; } @@ -974,36 +974,36 @@ namespace Ryujinx.Graphics.Texture case 4: { - C = 22; + c = 22; // B = dcb000dcb - int dcb = (BitValue >> 1) & 7; - B = (dcb << 6) | dcb; + int dcb = (bitValue >> 1) & 7; + b = (dcb << 6) | dcb; break; } case 5: { - C = 11; + c = 11; // B = edcb000ed - int edcb = (BitValue >> 1) & 0xF; - B = (edcb << 5) | (edcb >> 2); + int edcb = (bitValue >> 1) & 0xF; + b = (edcb << 5) | (edcb >> 2); break; } case 6: { - C = 5; + c = 5; // B = fedcb000f - int fedcb = (BitValue >> 1) & 0x1F; - B = (fedcb << 4) | (fedcb >> 4); + int fedcb = (bitValue >> 1) & 0x1F; + b = (fedcb << 4) | (fedcb >> 4); break; } default: - throw new ASTCDecoderException("Unsupported trit encoding for color values!"); + throw new AstcDecoderException("Unsupported trit encoding for color values!"); } break; @@ -1011,375 +1011,375 @@ namespace Ryujinx.Graphics.Texture case IntegerEncoded.EIntegerEncoding.Quint: { - D = IntEncoded.QuintValue; + d = intEncoded.QuintValue; - switch (BitLength) + switch (bitLength) { case 1: { - C = 113; + c = 113; break; } case 2: { - C = 54; + c = 54; // B = b0000bb00 - int b2 = (BitValue >> 1) & 1; - B = (b2 << 8) | (b2 << 3) | (b2 << 2); + int b2 = (bitValue >> 1) & 1; + b = (b2 << 8) | (b2 << 3) | (b2 << 2); break; } case 3: { - C = 26; + c = 26; // B = cb0000cbc - int cb = (BitValue >> 1) & 3; - B = (cb << 7) | (cb << 1) | (cb >> 1); + int cb = (bitValue >> 1) & 3; + b = (cb << 7) | (cb << 1) | (cb >> 1); break; } case 4: { - C = 13; + c = 13; // B = dcb0000dc - int dcb = (BitValue >> 1) & 7; - B = (dcb << 6) | (dcb >> 1); + int dcb = (bitValue >> 1) & 7; + b = (dcb << 6) | (dcb >> 1); break; } case 5: { - C = 6; + c = 6; // B = edcb0000e - int edcb = (BitValue >> 1) & 0xF; - B = (edcb << 5) | (edcb >> 3); + int edcb = (bitValue >> 1) & 0xF; + b = (edcb << 5) | (edcb >> 3); break; } default: - throw new ASTCDecoderException("Unsupported quint encoding for color values!"); + throw new AstcDecoderException("Unsupported quint encoding for color values!"); } break; } } - if (IntEncoded.GetEncoding() != IntegerEncoded.EIntegerEncoding.JustBits) + if (intEncoded.GetEncoding() != IntegerEncoded.EIntegerEncoding.JustBits) { - int T = D * C + B; - T ^= A; - T = (A & 0x80) | (T >> 2); + int T = d * c + b; + T ^= a; + T = (a & 0x80) | (T >> 2); - OutputValues[OutputIndices++] = T; + outputValues[outputIndices++] = T; } } // Make sure that each of our values is in the proper range... - for (int i = 0; i < NumberValues; i++) + for (int i = 0; i < numberValues; i++) { - Debug.Assert(OutputValues[i] <= 255); + Debug.Assert(outputValues[i] <= 255); } } - static void FillVoidExtentLDR(BitArrayStream BitStream, int[] OutputBuffer, int BlockWidth, int BlockHeight) + static void FillVoidExtentLdr(BitArrayStream bitStream, int[] outputBuffer, int blockWidth, int blockHeight) { // Don't actually care about the void extent, just read the bits... for (int i = 0; i < 4; ++i) { - BitStream.ReadBits(13); + bitStream.ReadBits(13); } // Decode the RGBA components and renormalize them to the range [0, 255] - ushort R = (ushort)BitStream.ReadBits(16); - ushort G = (ushort)BitStream.ReadBits(16); - ushort B = (ushort)BitStream.ReadBits(16); - ushort A = (ushort)BitStream.ReadBits(16); + ushort r = (ushort)bitStream.ReadBits(16); + ushort g = (ushort)bitStream.ReadBits(16); + ushort b = (ushort)bitStream.ReadBits(16); + ushort a = (ushort)bitStream.ReadBits(16); - int RGBA = (R >> 8) | (G & 0xFF00) | ((B) & 0xFF00) << 8 | ((A) & 0xFF00) << 16; + int rgba = (r >> 8) | (g & 0xFF00) | ((b) & 0xFF00) << 8 | ((a) & 0xFF00) << 16; - for (int j = 0; j < BlockHeight; j++) + for (int j = 0; j < blockHeight; j++) { - for (int i = 0; i < BlockWidth; i++) + for (int i = 0; i < blockWidth; i++) { - OutputBuffer[j * BlockWidth + i] = RGBA; + outputBuffer[j * blockWidth + i] = rgba; } } } - static TexelWeightParams DecodeBlockInfo(BitArrayStream BitStream) + static TexelWeightParams DecodeBlockInfo(BitArrayStream bitStream) { - TexelWeightParams TexelParams = new TexelWeightParams(); + TexelWeightParams texelParams = new TexelWeightParams(); // Read the entire block mode all at once - ushort ModeBits = (ushort)BitStream.ReadBits(11); + ushort modeBits = (ushort)bitStream.ReadBits(11); // Does this match the void extent block mode? - if ((ModeBits & 0x01FF) == 0x1FC) + if ((modeBits & 0x01FF) == 0x1FC) { - if ((ModeBits & 0x200) != 0) + if ((modeBits & 0x200) != 0) { - TexelParams.VoidExtentHDR = true; + texelParams.VoidExtentHdr = true; } else { - TexelParams.VoidExtentLDR = true; + texelParams.VoidExtentLdr = true; } // Next two bits must be one. - if ((ModeBits & 0x400) == 0 || BitStream.ReadBits(1) == 0) + if ((modeBits & 0x400) == 0 || bitStream.ReadBits(1) == 0) { - TexelParams.Error = true; + texelParams.Error = true; } - return TexelParams; + return texelParams; } // First check if the last four bits are zero - if ((ModeBits & 0xF) == 0) + if ((modeBits & 0xF) == 0) { - TexelParams.Error = true; - return TexelParams; + texelParams.Error = true; + return texelParams; } // If the last two bits are zero, then if bits // [6-8] are all ones, this is also reserved. - if ((ModeBits & 0x3) == 0 && (ModeBits & 0x1C0) == 0x1C0) + if ((modeBits & 0x3) == 0 && (modeBits & 0x1C0) == 0x1C0) { - TexelParams.Error = true; + texelParams.Error = true; - return TexelParams; + return texelParams; } // Otherwise, there is no error... Figure out the layout // of the block mode. Layout is determined by a number // between 0 and 9 corresponding to table C.2.8 of the // ASTC spec. - int Layout = 0; + int layout = 0; - if ((ModeBits & 0x1) != 0 || (ModeBits & 0x2) != 0) + if ((modeBits & 0x1) != 0 || (modeBits & 0x2) != 0) { // layout is in [0-4] - if ((ModeBits & 0x8) != 0) + if ((modeBits & 0x8) != 0) { // layout is in [2-4] - if ((ModeBits & 0x4) != 0) + if ((modeBits & 0x4) != 0) { // layout is in [3-4] - if ((ModeBits & 0x100) != 0) + if ((modeBits & 0x100) != 0) { - Layout = 4; + layout = 4; } else { - Layout = 3; + layout = 3; } } else { - Layout = 2; + layout = 2; } } else { // layout is in [0-1] - if ((ModeBits & 0x4) != 0) + if ((modeBits & 0x4) != 0) { - Layout = 1; + layout = 1; } else { - Layout = 0; + layout = 0; } } } else { // layout is in [5-9] - if ((ModeBits & 0x100) != 0) + if ((modeBits & 0x100) != 0) { // layout is in [7-9] - if ((ModeBits & 0x80) != 0) + if ((modeBits & 0x80) != 0) { // layout is in [7-8] - Debug.Assert((ModeBits & 0x40) == 0); + Debug.Assert((modeBits & 0x40) == 0); - if ((ModeBits & 0x20) != 0) + if ((modeBits & 0x20) != 0) { - Layout = 8; + layout = 8; } else { - Layout = 7; + layout = 7; } } else { - Layout = 9; + layout = 9; } } else { // layout is in [5-6] - if ((ModeBits & 0x80) != 0) + if ((modeBits & 0x80) != 0) { - Layout = 6; + layout = 6; } else { - Layout = 5; + layout = 5; } } } - Debug.Assert(Layout < 10); + Debug.Assert(layout < 10); // Determine R - int R = (ModeBits >> 4) & 1; - if (Layout < 5) + int r = (modeBits >> 4) & 1; + if (layout < 5) { - R |= (ModeBits & 0x3) << 1; + r |= (modeBits & 0x3) << 1; } else { - R |= (ModeBits & 0xC) >> 1; + r |= (modeBits & 0xC) >> 1; } - Debug.Assert(2 <= R && R <= 7); + Debug.Assert(2 <= r && r <= 7); // Determine width & height - switch (Layout) + 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; } 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; } 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; } 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; } 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; } 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; } 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; } case 7: { - TexelParams.Width = 6; - TexelParams.Height = 10; + texelParams.Width = 6; + texelParams.Height = 10; break; } case 8: { - TexelParams.Width = 10; - TexelParams.Height = 6; + 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; } default: //Don't know this layout... - TexelParams.Error = true; + texelParams.Error = true; break; } // Determine whether or not we're using dual planes // and/or high precision layouts. - bool D = ((Layout != 9) && ((ModeBits & 0x400) != 0)); - bool H = (Layout != 9) && ((ModeBits & 0x200) != 0); + bool d = ((layout != 9) && ((modeBits & 0x400) != 0)); + bool h = (layout != 9) && ((modeBits & 0x200) != 0); - if (H) + if (h) { - int[] MaxWeights = { 9, 11, 15, 19, 23, 31 }; - TexelParams.MaxWeight = MaxWeights[R - 2]; + int[] maxWeights = { 9, 11, 15, 19, 23, 31 }; + texelParams.MaxWeight = maxWeights[r - 2]; } else { - int[] MaxWeights = { 1, 2, 3, 4, 5, 7 }; - TexelParams.MaxWeight = MaxWeights[R - 2]; + int[] maxWeights = { 1, 2, 3, 4, 5, 7 }; + texelParams.MaxWeight = maxWeights[r - 2]; } - TexelParams.DualPlane = D; + texelParams.DualPlane = d; - return TexelParams; + return texelParams; } } } diff --git a/Ryujinx.Graphics/Graphics3d/Texture/ASTCPixel.cs b/Ryujinx.Graphics/Graphics3d/Texture/ASTCPixel.cs index c43eaf9380..cd30accab3 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/ASTCPixel.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/ASTCPixel.cs @@ -3,24 +3,24 @@ using System.Diagnostics; namespace Ryujinx.Graphics.Texture { - class ASTCPixel + class AstcPixel { public short R { get; set; } public short G { get; set; } public short B { get; set; } public short A { get; set; } - byte[] BitDepth = new byte[4]; + byte[] _bitDepth = new byte[4]; - public ASTCPixel(short _A, short _R, short _G, short _B) + public AstcPixel(short a, short r, short g, short b) { - A = _A; - R = _R; - G = _G; - B = _B; + A = a; + R = r; + G = g; + B = b; for (int i = 0; i < 4; i++) - BitDepth[i] = 8; + _bitDepth[i] = 8; } public void ClampByte() @@ -31,9 +31,9 @@ namespace Ryujinx.Graphics.Texture A = Math.Min(Math.Max(A, (short)0), (short)255); } - public short GetComponent(int Index) + public short GetComponent(int index) { - switch(Index) + switch(index) { case 0: return A; case 1: return R; @@ -44,92 +44,92 @@ namespace Ryujinx.Graphics.Texture return 0; } - public void SetComponent(int Index, int Value) + public void SetComponent(int index, int value) { - switch (Index) + switch (index) { case 0: - A = (short)Value; + A = (short)value; break; case 1: - R = (short)Value; + R = (short)value; break; case 2: - G = (short)Value; + G = (short)value; break; case 3: - B = (short)Value; + B = (short)value; break; } } - public void ChangeBitDepth(byte[] Depth) + public void ChangeBitDepth(byte[] depth) { for(int i = 0; i< 4; i++) { - int Value = ChangeBitDepth(GetComponent(i), BitDepth[i], Depth[i]); + int value = ChangeBitDepth(GetComponent(i), _bitDepth[i], depth[i]); - SetComponent(i, Value); - BitDepth[i] = Depth[i]; + SetComponent(i, value); + _bitDepth[i] = depth[i]; } } - short ChangeBitDepth(short Value, byte OldDepth, byte NewDepth) + short ChangeBitDepth(short value, byte oldDepth, byte newDepth) { - Debug.Assert(NewDepth <= 8); - Debug.Assert(OldDepth <= 8); + Debug.Assert(newDepth <= 8); + Debug.Assert(oldDepth <= 8); - if (OldDepth == NewDepth) + if (oldDepth == newDepth) { // Do nothing - return Value; + return value; } - else if (OldDepth == 0 && NewDepth != 0) + else if (oldDepth == 0 && newDepth != 0) { - return (short)((1 << NewDepth) - 1); + return (short)((1 << newDepth) - 1); } - else if (NewDepth > OldDepth) + else if (newDepth > oldDepth) { - return (short)BitArrayStream.Replicate(Value, OldDepth, NewDepth); + return (short)BitArrayStream.Replicate(value, oldDepth, newDepth); } else { // oldDepth > newDepth - if (NewDepth == 0) + if (newDepth == 0) { return 0xFF; } else { - byte BitsWasted = (byte)(OldDepth - NewDepth); - short TempValue = Value; + byte bitsWasted = (byte)(oldDepth - newDepth); + short tempValue = value; - TempValue = (short)((TempValue + (1 << (BitsWasted - 1))) >> BitsWasted); - TempValue = Math.Min(Math.Max((short)0, TempValue), (short)((1 << NewDepth) - 1)); + tempValue = (short)((tempValue + (1 << (bitsWasted - 1))) >> bitsWasted); + tempValue = Math.Min(Math.Max((short)0, tempValue), (short)((1 << newDepth) - 1)); - return (byte)(TempValue); + return (byte)(tempValue); } } } public int Pack() { - ASTCPixel NewPixel = new ASTCPixel(A, R, G, B); + AstcPixel newPixel = new AstcPixel(A, R, G, B); byte[] eightBitDepth = { 8, 8, 8, 8 }; - NewPixel.ChangeBitDepth(eightBitDepth); + newPixel.ChangeBitDepth(eightBitDepth); - return (byte)NewPixel.A << 24 | - (byte)NewPixel.B << 16 | - (byte)NewPixel.G << 8 | - (byte)NewPixel.R << 0; + return (byte)newPixel.A << 24 | + (byte)newPixel.B << 16 | + (byte)newPixel.G << 8 | + (byte)newPixel.R << 0; } // Adds more precision to the blue channel as described // in C.2.14 - public static ASTCPixel BlueContract(int a, int r, int g, int b) + public static AstcPixel BlueContract(int a, int r, int g, int b) { - return new ASTCPixel((short)(a), + return new AstcPixel((short)(a), (short)((r + b) >> 1), (short)((g + b) >> 1), (short)(b)); diff --git a/Ryujinx.Graphics/Graphics3d/Texture/BitArrayStream.cs b/Ryujinx.Graphics/Graphics3d/Texture/BitArrayStream.cs index 2a8ed09105..24069d722b 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/BitArrayStream.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/BitArrayStream.cs @@ -9,103 +9,103 @@ namespace Ryujinx.Graphics.Texture public int Position { get; private set; } - public BitArrayStream(BitArray BitArray) + public BitArrayStream(BitArray bitArray) { - BitsArray = BitArray; + BitsArray = bitArray; Position = 0; } - public short ReadBits(int Length) + public short ReadBits(int length) { - int RetValue = 0; - for (int i = Position; i < Position + Length; i++) + int retValue = 0; + for (int i = Position; i < Position + length; i++) { if (BitsArray[i]) { - RetValue |= 1 << (i - Position); + retValue |= 1 << (i - Position); } } - Position += Length; - return (short)RetValue; + Position += length; + return (short)retValue; } - public int ReadBits(int Start, int End) + public int ReadBits(int start, int end) { - int RetValue = 0; - for (int i = Start; i <= End; i++) + int retValue = 0; + for (int i = start; i <= end; i++) { if (BitsArray[i]) { - RetValue |= 1 << (i - Start); + retValue |= 1 << (i - start); } } - return RetValue; + return retValue; } - public int ReadBit(int Index) + public int ReadBit(int index) { - return Convert.ToInt32(BitsArray[Index]); + return Convert.ToInt32(BitsArray[index]); } - public void WriteBits(int Value, int Length) + public void WriteBits(int value, int length) { - for (int i = Position; i < Position + Length; i++) + for (int i = Position; i < Position + length; i++) { - BitsArray[i] = ((Value >> (i - Position)) & 1) != 0; + BitsArray[i] = ((value >> (i - Position)) & 1) != 0; } - Position += Length; + Position += length; } public byte[] ToByteArray() { - byte[] RetArray = new byte[(BitsArray.Length + 7) / 8]; - BitsArray.CopyTo(RetArray, 0); - return RetArray; + byte[] retArray = new byte[(BitsArray.Length + 7) / 8]; + BitsArray.CopyTo(retArray, 0); + return retArray; } - 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 (ToBit == 0) return 0; + if (numberBits == 0) return 0; + if (toBit == 0) return 0; - int TempValue = Value & ((1 << NumberBits) - 1); - int RetValue = TempValue; - int ResLength = NumberBits; + int tempValue = value & ((1 << numberBits) - 1); + int retValue = tempValue; + int resLength = numberBits; - while (ResLength < ToBit) + while (resLength < toBit) { - int Comp = 0; - if (NumberBits > ToBit - ResLength) + int comp = 0; + if (numberBits > toBit - resLength) { - int NewShift = ToBit - ResLength; - Comp = NumberBits - NewShift; - NumberBits = NewShift; + int newShift = toBit - resLength; + comp = numberBits - newShift; + numberBits = newShift; } - RetValue <<= NumberBits; - RetValue |= TempValue >> Comp; - ResLength += NumberBits; + retValue <<= numberBits; + retValue |= tempValue >> comp; + resLength += numberBits; } - return RetValue; + return retValue; } - public static int PopCnt(int Number) + public static int PopCnt(int number) { - int Counter; - for (Counter = 0; Number != 0; Counter++) + int counter; + for (counter = 0; number != 0; counter++) { - Number &= Number - 1; + number &= number - 1; } - return Counter; + return counter; } public static void Swap(ref T lhs, ref T rhs) { - T Temp = lhs; + T temp = lhs; lhs = rhs; - rhs = Temp; + rhs = temp; } // Transfers a bit as described in C.2.14 diff --git a/Ryujinx.Graphics/Graphics3d/Texture/BlockLinearSwizzle.cs b/Ryujinx.Graphics/Graphics3d/Texture/BlockLinearSwizzle.cs index 1be0644283..789e29c1a3 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/BlockLinearSwizzle.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/BlockLinearSwizzle.cs @@ -10,98 +10,98 @@ namespace Ryujinx.Graphics.Texture private const int GobSize = GobWidth * GobHeight; - private int TexWidth; - private int TexHeight; - private int TexDepth; - private int TexGobBlockHeight; - private int TexGobBlockDepth; - private int TexBpp; + private int _texWidth; + private int _texHeight; + private int _texDepth; + private int _texGobBlockHeight; + private int _texGobBlockDepth; + private int _texBpp; - private int BhMask; - private int BdMask; + private int _bhMask; + private int _bdMask; - private int BhShift; - private int BdShift; - private int BppShift; + private int _bhShift; + private int _bdShift; + private int _bppShift; - private int XShift; + private int _xShift; - private int RobSize; - private int SliceSize; + private int _robSize; + private int _sliceSize; - private int BaseOffset; + private int _baseOffset; public BlockLinearSwizzle( - int Width, - int Height, - int Depth, - int GobBlockHeight, - int GobBlockDepth, - int Bpp) + int width, + int height, + int depth, + int gobBlockHeight, + int gobBlockDepth, + int bpp) { - TexWidth = Width; - TexHeight = Height; - TexDepth = Depth; - TexGobBlockHeight = GobBlockHeight; - TexGobBlockDepth = GobBlockDepth; - TexBpp = Bpp; + _texWidth = width; + _texHeight = height; + _texDepth = depth; + _texGobBlockHeight = gobBlockHeight; + _texGobBlockDepth = gobBlockDepth; + _texBpp = bpp; - BppShift = BitUtils.CountTrailingZeros32(Bpp); + _bppShift = BitUtils.CountTrailingZeros32(bpp); SetMipLevel(0); } - public void SetMipLevel(int Level) + public void SetMipLevel(int level) { - BaseOffset = GetMipOffset(Level); + _baseOffset = GetMipOffset(level); - int Width = Math.Max(1, TexWidth >> Level); - int Height = Math.Max(1, TexHeight >> Level); - int Depth = Math.Max(1, TexDepth >> Level); + int width = Math.Max(1, _texWidth >> level); + int height = Math.Max(1, _texHeight >> level); + int depth = Math.Max(1, _texDepth >> level); - GobBlockSizes GbSizes = AdjustGobBlockSizes(Height, Depth); + GobBlockSizes gbSizes = AdjustGobBlockSizes(height, depth); - BhMask = GbSizes.Height - 1; - BdMask = GbSizes.Depth - 1; + _bhMask = gbSizes.Height - 1; + _bdMask = gbSizes.Depth - 1; - BhShift = BitUtils.CountTrailingZeros32(GbSizes.Height); - BdShift = BitUtils.CountTrailingZeros32(GbSizes.Depth); + _bhShift = BitUtils.CountTrailingZeros32(gbSizes.Height); + _bdShift = BitUtils.CountTrailingZeros32(gbSizes.Depth); - XShift = BitUtils.CountTrailingZeros32(GobSize * GbSizes.Height * GbSizes.Depth); + _xShift = BitUtils.CountTrailingZeros32(GobSize * gbSizes.Height * gbSizes.Depth); - RobAndSliceSizes GsSizes = GetRobAndSliceSizes(Width, Height, GbSizes); + RobAndSliceSizes gsSizes = GetRobAndSliceSizes(width, height, gbSizes); - RobSize = GsSizes.RobSize; - SliceSize = GsSizes.SliceSize; + _robSize = gsSizes.RobSize; + _sliceSize = gsSizes.SliceSize; } - public int GetImageSize(int MipsCount) + public int GetImageSize(int mipsCount) { - int Size = GetMipOffset(MipsCount); + int size = GetMipOffset(mipsCount); - Size = (Size + 0x1fff) & ~0x1fff; + size = (size + 0x1fff) & ~0x1fff; - return Size; + return size; } - public int GetMipOffset(int Level) + public int GetMipOffset(int level) { - int TotalSize = 0; + int totalSize = 0; - for (int Index = 0; Index < Level; Index++) + for (int index = 0; index < level; index++) { - int Width = Math.Max(1, TexWidth >> Index); - int Height = Math.Max(1, TexHeight >> Index); - int Depth = Math.Max(1, TexDepth >> Index); + int width = Math.Max(1, _texWidth >> index); + int height = Math.Max(1, _texHeight >> index); + int depth = Math.Max(1, _texDepth >> index); - GobBlockSizes GbSizes = AdjustGobBlockSizes(Height, Depth); + GobBlockSizes gbSizes = AdjustGobBlockSizes(height, depth); - RobAndSliceSizes RsSizes = GetRobAndSliceSizes(Width, Height, GbSizes); + RobAndSliceSizes rsSizes = GetRobAndSliceSizes(width, height, gbSizes); - TotalSize += BitUtils.DivRoundUp(Depth, GbSizes.Depth) * RsSizes.SliceSize; + totalSize += BitUtils.DivRoundUp(depth, gbSizes.Depth) * rsSizes.SliceSize; } - return TotalSize; + return totalSize; } private struct GobBlockSizes @@ -109,32 +109,32 @@ namespace Ryujinx.Graphics.Texture public int Height; public int Depth; - public GobBlockSizes(int GobBlockHeight, int GobBlockDepth) + public GobBlockSizes(int gobBlockHeight, int gobBlockDepth) { - this.Height = GobBlockHeight; - this.Depth = GobBlockDepth; + this.Height = gobBlockHeight; + this.Depth = gobBlockDepth; } } - private GobBlockSizes AdjustGobBlockSizes(int Height, int Depth) + private GobBlockSizes AdjustGobBlockSizes(int height, int depth) { - int GobBlockHeight = TexGobBlockHeight; - int GobBlockDepth = TexGobBlockDepth; + int gobBlockHeight = _texGobBlockHeight; + int gobBlockDepth = _texGobBlockDepth; - int Pow2Height = BitUtils.Pow2RoundUp(Height); - int Pow2Depth = BitUtils.Pow2RoundUp(Depth); + int pow2Height = BitUtils.Pow2RoundUp(height); + int pow2Depth = BitUtils.Pow2RoundUp(depth); - while (GobBlockHeight * GobHeight > Pow2Height && GobBlockHeight > 1) + while (gobBlockHeight * GobHeight > pow2Height && gobBlockHeight > 1) { - GobBlockHeight >>= 1; + gobBlockHeight >>= 1; } - while (GobBlockDepth > Pow2Depth && GobBlockDepth > 1) + while (gobBlockDepth > pow2Depth && gobBlockDepth > 1) { - GobBlockDepth >>= 1; + gobBlockDepth >>= 1; } - return new GobBlockSizes(GobBlockHeight, GobBlockDepth); + return new GobBlockSizes(gobBlockHeight, gobBlockDepth); } private struct RobAndSliceSizes @@ -142,45 +142,45 @@ namespace Ryujinx.Graphics.Texture public int RobSize; public int SliceSize; - public RobAndSliceSizes(int RobSize, int SliceSize) + public RobAndSliceSizes(int robSize, int sliceSize) { - this.RobSize = RobSize; - this.SliceSize = SliceSize; + this.RobSize = robSize; + this.SliceSize = sliceSize; } } - private RobAndSliceSizes GetRobAndSliceSizes(int Width, int Height, GobBlockSizes GbSizes) + private RobAndSliceSizes GetRobAndSliceSizes(int width, int height, GobBlockSizes gbSizes) { - int WidthInGobs = BitUtils.DivRoundUp(Width * TexBpp, GobWidth); + int widthInGobs = BitUtils.DivRoundUp(width * _texBpp, GobWidth); - int RobSize = GobSize * GbSizes.Height * GbSizes.Depth * WidthInGobs; + int robSize = GobSize * gbSizes.Height * gbSizes.Depth * widthInGobs; - int SliceSize = BitUtils.DivRoundUp(Height, GbSizes.Height * GobHeight) * RobSize; + int sliceSize = BitUtils.DivRoundUp(height, gbSizes.Height * GobHeight) * robSize; - return new RobAndSliceSizes(RobSize, SliceSize); + return new RobAndSliceSizes(robSize, sliceSize); } - public int GetSwizzleOffset(int X, int Y, int Z) + public int GetSwizzleOffset(int x, int y, int z) { - X <<= BppShift; + x <<= _bppShift; - int YH = Y / GobHeight; + int yh = y / GobHeight; - int Position = (Z >> BdShift) * SliceSize + (YH >> BhShift) * RobSize; + int position = (z >> _bdShift) * _sliceSize + (yh >> _bhShift) * _robSize; - Position += (X / GobWidth) << XShift; + position += (x / GobWidth) << _xShift; - Position += (YH & BhMask) * GobSize; + position += (yh & _bhMask) * GobSize; - Position += ((Z & BdMask) * GobSize) << BhShift; + position += ((z & _bdMask) * GobSize) << _bhShift; - Position += ((X & 0x3f) >> 5) << 8; - Position += ((Y & 0x07) >> 1) << 6; - Position += ((X & 0x1f) >> 4) << 5; - Position += ((Y & 0x01) >> 0) << 4; - Position += ((X & 0x0f) >> 0) << 0; + position += ((x & 0x3f) >> 5) << 8; + position += ((y & 0x07) >> 1) << 6; + position += ((x & 0x1f) >> 4) << 5; + position += ((y & 0x01) >> 0) << 4; + position += ((x & 0x0f) >> 0) << 0; - return BaseOffset + Position; + return _baseOffset + position; } } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/Texture/ISwizzle.cs b/Ryujinx.Graphics/Graphics3d/Texture/ISwizzle.cs index 2e0e8aedd4..fae3eada87 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/ISwizzle.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/ISwizzle.cs @@ -2,12 +2,12 @@ namespace Ryujinx.Graphics.Texture { interface ISwizzle { - int GetSwizzleOffset(int X, int Y, int Z); + int GetSwizzleOffset(int x, int y, int z); - void SetMipLevel(int Level); + void SetMipLevel(int level); - int GetMipOffset(int Level); + int GetMipOffset(int level); - int GetImageSize(int MipsCount); + int GetImageSize(int mipsCount); } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs b/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs index c4208935c3..84b979e7ca 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs @@ -29,13 +29,13 @@ namespace Ryujinx.Graphics.Texture public TargetBuffer Target { get; private set; } - public ImageDescriptor(int BytesPerPixel, int BlockWidth, int BlockHeight, int BlockDepth, TargetBuffer Target) + public ImageDescriptor(int bytesPerPixel, int blockWidth, int blockHeight, int blockDepth, TargetBuffer target) { - this.BytesPerPixel = BytesPerPixel; - this.BlockWidth = BlockWidth; - this.BlockHeight = BlockHeight; - this.BlockDepth = BlockDepth; - this.Target = Target; + this.BytesPerPixel = bytesPerPixel; + this.BlockWidth = blockWidth; + this.BlockHeight = blockHeight; + this.BlockDepth = blockDepth; + this.Target = target; } } @@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Texture private const GalImageFormat Float = GalImageFormat.Float; private const GalImageFormat Srgb = GalImageFormat.Srgb; - private static readonly Dictionary s_TextureTable = + private static readonly Dictionary TextureTable = new Dictionary() { { GalTextureFormat.RGBA32, GalImageFormat.RGBA32 | Sint | Uint | Float }, @@ -93,7 +93,7 @@ namespace Ryujinx.Graphics.Texture { GalTextureFormat.Astc2D10x6, GalImageFormat.Astc2D10x6 | Unorm | Srgb } }; - private static readonly Dictionary s_ImageTable = + private static readonly Dictionary ImageTable = new Dictionary() { { GalImageFormat.RGBA32, new ImageDescriptor(16, 1, 1, 1, TargetBuffer.Color) }, @@ -145,38 +145,38 @@ namespace Ryujinx.Graphics.Texture }; public static GalImageFormat ConvertTexture( - GalTextureFormat Format, - GalTextureType RType, - GalTextureType GType, - GalTextureType BType, - GalTextureType AType, - bool ConvSrgb) + GalTextureFormat format, + GalTextureType rType, + GalTextureType gType, + GalTextureType bType, + GalTextureType aType, + bool convSrgb) { - if (!s_TextureTable.TryGetValue(Format, out GalImageFormat ImageFormat)) + if (!TextureTable.TryGetValue(format, out GalImageFormat imageFormat)) { - throw new NotImplementedException($"Format 0x{((int)Format):x} not implemented!"); + throw new NotImplementedException($"Format 0x{((int)format):x} not implemented!"); } - if (!HasDepth(ImageFormat) && (RType != GType || RType != BType || RType != AType)) + if (!HasDepth(imageFormat) && (rType != gType || rType != bType || rType != aType)) { throw new NotImplementedException($"Per component types are not implemented!"); } - GalImageFormat FormatType = ConvSrgb ? Srgb : GetFormatType(RType); + GalImageFormat formatType = convSrgb ? Srgb : GetFormatType(rType); - GalImageFormat CombinedFormat = (ImageFormat & GalImageFormat.FormatMask) | FormatType; + GalImageFormat combinedFormat = (imageFormat & GalImageFormat.FormatMask) | formatType; - if (!ImageFormat.HasFlag(FormatType)) + if (!imageFormat.HasFlag(formatType)) { - throw new NotImplementedException($"Format \"{CombinedFormat}\" not implemented!"); + throw new NotImplementedException($"Format \"{combinedFormat}\" not implemented!"); } - return CombinedFormat; + return combinedFormat; } - public static GalImageFormat ConvertSurface(GalSurfaceFormat Format) + public static GalImageFormat ConvertSurface(GalSurfaceFormat format) { - switch (Format) + switch (format) { case GalSurfaceFormat.RGBA32Float: return GalImageFormat.RGBA32 | Float; case GalSurfaceFormat.RGBA32Uint: return GalImageFormat.RGBA32 | Uint; @@ -210,12 +210,12 @@ namespace Ryujinx.Graphics.Texture case GalSurfaceFormat.RGBX8Unorm: return GalImageFormat.RGBX8 | Unorm; } - throw new NotImplementedException(Format.ToString()); + throw new NotImplementedException(format.ToString()); } - public static GalImageFormat ConvertZeta(GalZetaFormat Format) + public static GalImageFormat ConvertZeta(GalZetaFormat format) { - switch (Format) + switch (format) { case GalZetaFormat.D32Float: return GalImageFormat.D32 | Float; case GalZetaFormat.S8D24Unorm: return GalImageFormat.D24S8 | Unorm; @@ -225,268 +225,268 @@ namespace Ryujinx.Graphics.Texture case GalZetaFormat.D32S8X24Float: return GalImageFormat.D32S8 | Float; } - throw new NotImplementedException(Format.ToString()); + throw new NotImplementedException(format.ToString()); } - public static byte[] ReadTexture(IMemory Memory, GalImage Image, long Position) + public static byte[] ReadTexture(IMemory memory, GalImage image, long position) { - MemoryManager CpuMemory; + MemoryManager cpuMemory; - if (Memory is NvGpuVmm Vmm) + if (memory is NvGpuVmm vmm) { - CpuMemory = Vmm.Memory; + cpuMemory = vmm.Memory; } else { - CpuMemory = (MemoryManager)Memory; + cpuMemory = (MemoryManager)memory; } - ISwizzle Swizzle = TextureHelper.GetSwizzle(Image); + ISwizzle swizzle = TextureHelper.GetSwizzle(image); - ImageDescriptor Desc = GetImageDescriptor(Image.Format); + ImageDescriptor desc = GetImageDescriptor(image.Format); - (int Width, int Height, int Depth) = GetImageSizeInBlocks(Image); + (int width, int height, int depth) = GetImageSizeInBlocks(image); - int BytesPerPixel = Desc.BytesPerPixel; + int bytesPerPixel = desc.BytesPerPixel; //Note: Each row of the texture needs to be aligned to 4 bytes. - int Pitch = (Width * BytesPerPixel + 3) & ~3; + int pitch = (width * bytesPerPixel + 3) & ~3; - int DataLayerSize = Height * Pitch * Depth; - byte[] Data = new byte[DataLayerSize * Image.LayerCount]; + int dataLayerSize = height * pitch * depth; + byte[] data = new byte[dataLayerSize * image.LayerCount]; - int TargetMipLevel = Image.MaxMipmapLevel <= 1 ? 1 : Image.MaxMipmapLevel - 1; - int LayerOffset = ImageUtils.GetLayerOffset(Image, TargetMipLevel); + int targetMipLevel = image.MaxMipmapLevel <= 1 ? 1 : image.MaxMipmapLevel - 1; + int layerOffset = ImageUtils.GetLayerOffset(image, targetMipLevel); - for (int Layer = 0; Layer < Image.LayerCount; Layer++) + for (int layer = 0; layer < image.LayerCount; layer++) { - for (int Z = 0; Z < Depth; Z++) + for (int z = 0; z < depth; z++) { - for (int Y = 0; Y < Height; Y++) + for (int y = 0; y < height; y++) { - int OutOffs = (DataLayerSize * Layer) + Y * Pitch + (Z * Width * Height * BytesPerPixel); + int outOffs = (dataLayerSize * layer) + y * pitch + (z * width * height * bytesPerPixel); - for (int X = 0; X < Width; X++) + for (int x = 0; x < width; x++) { - long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y, Z); + long offset = (uint)swizzle.GetSwizzleOffset(x, y, z); - CpuMemory.ReadBytes(Position + (LayerOffset * Layer) + Offset, Data, OutOffs, BytesPerPixel); + cpuMemory.ReadBytes(position + (layerOffset * layer) + offset, data, outOffs, bytesPerPixel); - OutOffs += BytesPerPixel; + outOffs += bytesPerPixel; } } } } - return Data; + return data; } - public static void WriteTexture(NvGpuVmm Vmm, GalImage Image, long Position, byte[] Data) + public static void WriteTexture(NvGpuVmm vmm, GalImage image, long position, byte[] data) { - ISwizzle Swizzle = TextureHelper.GetSwizzle(Image); + ISwizzle swizzle = TextureHelper.GetSwizzle(image); - ImageDescriptor Desc = GetImageDescriptor(Image.Format); + ImageDescriptor desc = GetImageDescriptor(image.Format); - (int Width, int Height, int Depth) = ImageUtils.GetImageSizeInBlocks(Image); + (int width, int height, int depth) = ImageUtils.GetImageSizeInBlocks(image); - int BytesPerPixel = Desc.BytesPerPixel; + int bytesPerPixel = desc.BytesPerPixel; - int InOffs = 0; + int inOffs = 0; - for (int Z = 0; Z < Depth; Z++) - for (int Y = 0; Y < Height; Y++) - for (int X = 0; X < Width; X++) + for (int z = 0; z < depth; z++) + for (int y = 0; y < height; y++) + for (int x = 0; x < width; x++) { - long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y, Z); + long offset = (uint)swizzle.GetSwizzleOffset(x, y, z); - Vmm.Memory.WriteBytes(Position + Offset, Data, InOffs, BytesPerPixel); + vmm.Memory.WriteBytes(position + offset, data, inOffs, bytesPerPixel); - InOffs += BytesPerPixel; + inOffs += bytesPerPixel; } } // TODO: Support non 2D public static bool CopyTexture( - NvGpuVmm Vmm, - GalImage SrcImage, - GalImage DstImage, - long SrcAddress, - long DstAddress, - int SrcX, - int SrcY, - int DstX, - int DstY, - int Width, - int Height) + NvGpuVmm vmm, + GalImage srcImage, + GalImage dstImage, + long srcAddress, + long dstAddress, + int srcX, + int srcY, + int dstX, + int dstY, + int width, + int height) { - ISwizzle SrcSwizzle = TextureHelper.GetSwizzle(SrcImage); - ISwizzle DstSwizzle = TextureHelper.GetSwizzle(DstImage); + ISwizzle srcSwizzle = TextureHelper.GetSwizzle(srcImage); + ISwizzle dstSwizzle = TextureHelper.GetSwizzle(dstImage); - ImageDescriptor Desc = GetImageDescriptor(SrcImage.Format); + ImageDescriptor desc = GetImageDescriptor(srcImage.Format); - if (GetImageDescriptor(DstImage.Format).BytesPerPixel != Desc.BytesPerPixel) + if (GetImageDescriptor(dstImage.Format).BytesPerPixel != desc.BytesPerPixel) { return false; } - int BytesPerPixel = Desc.BytesPerPixel; + int bytesPerPixel = desc.BytesPerPixel; - for (int Y = 0; Y < Height; Y++) - for (int X = 0; X < Width; X++) + for (int y = 0; y < height; y++) + for (int x = 0; x < width; x++) { - long SrcOffset = (uint)SrcSwizzle.GetSwizzleOffset(SrcX + X, SrcY + Y, 0); - long DstOffset = (uint)DstSwizzle.GetSwizzleOffset(DstX + X, DstY + Y, 0); + long srcOffset = (uint)srcSwizzle.GetSwizzleOffset(srcX + x, srcY + y, 0); + long dstOffset = (uint)dstSwizzle.GetSwizzleOffset(dstX + x, dstY + y, 0); - byte[] Texel = Vmm.ReadBytes(SrcAddress + SrcOffset, BytesPerPixel); + byte[] texel = vmm.ReadBytes(srcAddress + srcOffset, bytesPerPixel); - Vmm.WriteBytes(DstAddress + DstOffset, Texel); + vmm.WriteBytes(dstAddress + dstOffset, texel); } return true; } - public static int GetSize(GalImage Image) + public static int GetSize(GalImage image) { - ImageDescriptor Desc = GetImageDescriptor(Image.Format); + ImageDescriptor desc = GetImageDescriptor(image.Format); - int ComponentCount = GetCoordsCountTextureTarget(Image.TextureTarget); + int componentCount = GetCoordsCountTextureTarget(image.TextureTarget); - if (IsArray(Image.TextureTarget)) - ComponentCount--; + if (IsArray(image.TextureTarget)) + componentCount--; - int Width = DivRoundUp(Image.Width, Desc.BlockWidth); - int Height = DivRoundUp(Image.Height, Desc.BlockHeight); - int Depth = DivRoundUp(Image.Depth, Desc.BlockDepth); + int width = DivRoundUp(image.Width, desc.BlockWidth); + int height = DivRoundUp(image.Height, desc.BlockHeight); + int depth = DivRoundUp(image.Depth, desc.BlockDepth); - switch (ComponentCount) + switch (componentCount) { case 1: - return Desc.BytesPerPixel * Width * Image.LayerCount; + return desc.BytesPerPixel * width * image.LayerCount; case 2: - return Desc.BytesPerPixel * Width * Height * Image.LayerCount; + return desc.BytesPerPixel * width * height * image.LayerCount; case 3: - return Desc.BytesPerPixel * Width * Height * Depth * Image.LayerCount; + return desc.BytesPerPixel * width * height * depth * image.LayerCount; default: - throw new InvalidOperationException($"Invalid component count: {ComponentCount}"); + throw new InvalidOperationException($"Invalid component count: {componentCount}"); } } - public static int GetGpuSize(GalImage Image, bool forcePitch = false) + public static int GetGpuSize(GalImage image, bool forcePitch = false) { - return TextureHelper.GetSwizzle(Image).GetImageSize(Image.MaxMipmapLevel) * Image.LayerCount; + return TextureHelper.GetSwizzle(image).GetImageSize(image.MaxMipmapLevel) * image.LayerCount; } - public static int GetLayerOffset(GalImage Image, int MipLevel) + public static int GetLayerOffset(GalImage image, int mipLevel) { - if (MipLevel <= 0) + if (mipLevel <= 0) { - MipLevel = 1; + mipLevel = 1; } - return TextureHelper.GetSwizzle(Image).GetMipOffset(MipLevel); + return TextureHelper.GetSwizzle(image).GetMipOffset(mipLevel); } - public static int GetPitch(GalImageFormat Format, int Width) + public static int GetPitch(GalImageFormat format, int width) { - ImageDescriptor Desc = GetImageDescriptor(Format); + ImageDescriptor desc = GetImageDescriptor(format); - int Pitch = Desc.BytesPerPixel * DivRoundUp(Width, Desc.BlockWidth); + int pitch = desc.BytesPerPixel * DivRoundUp(width, desc.BlockWidth); - Pitch = (Pitch + 0x1f) & ~0x1f; + pitch = (pitch + 0x1f) & ~0x1f; - return Pitch; + return pitch; } - public static int GetBlockWidth(GalImageFormat Format) + public static int GetBlockWidth(GalImageFormat format) { - return GetImageDescriptor(Format).BlockWidth; + return GetImageDescriptor(format).BlockWidth; } - public static int GetBlockHeight(GalImageFormat Format) + public static int GetBlockHeight(GalImageFormat format) { - return GetImageDescriptor(Format).BlockHeight; + return GetImageDescriptor(format).BlockHeight; } - public static int GetBlockDepth(GalImageFormat Format) + public static int GetBlockDepth(GalImageFormat format) { - return GetImageDescriptor(Format).BlockDepth; + return GetImageDescriptor(format).BlockDepth; } - public static int GetAlignedWidth(GalImage Image) + public static int GetAlignedWidth(GalImage image) { - ImageDescriptor Desc = GetImageDescriptor(Image.Format); + ImageDescriptor desc = GetImageDescriptor(image.Format); - int AlignMask; + int alignMask; - if (Image.Layout == GalMemoryLayout.BlockLinear) + if (image.Layout == GalMemoryLayout.BlockLinear) { - AlignMask = Image.TileWidth * (64 / Desc.BytesPerPixel) - 1; + alignMask = image.TileWidth * (64 / desc.BytesPerPixel) - 1; } else { - AlignMask = (32 / Desc.BytesPerPixel) - 1; + alignMask = (32 / desc.BytesPerPixel) - 1; } - return (Image.Width + AlignMask) & ~AlignMask; + return (image.Width + alignMask) & ~alignMask; } - public static (int Width, int Height, int Depth) GetImageSizeInBlocks(GalImage Image) + public static (int Width, int Height, int Depth) GetImageSizeInBlocks(GalImage image) { - ImageDescriptor Desc = GetImageDescriptor(Image.Format); + ImageDescriptor desc = GetImageDescriptor(image.Format); - return (DivRoundUp(Image.Width, Desc.BlockWidth), - DivRoundUp(Image.Height, Desc.BlockHeight), - DivRoundUp(Image.Depth, Desc.BlockDepth)); + return (DivRoundUp(image.Width, desc.BlockWidth), + DivRoundUp(image.Height, desc.BlockHeight), + DivRoundUp(image.Depth, desc.BlockDepth)); } - public static int GetBytesPerPixel(GalImageFormat Format) + public static int GetBytesPerPixel(GalImageFormat format) { - return GetImageDescriptor(Format).BytesPerPixel; + return GetImageDescriptor(format).BytesPerPixel; } - private static int DivRoundUp(int LHS, int RHS) + private static int DivRoundUp(int lhs, int rhs) { - return (LHS + (RHS - 1)) / RHS; + return (lhs + (rhs - 1)) / rhs; } - public static bool HasColor(GalImageFormat Format) + public static bool HasColor(GalImageFormat format) { - return (GetImageDescriptor(Format).Target & TargetBuffer.Color) != 0; + return (GetImageDescriptor(format).Target & TargetBuffer.Color) != 0; } - public static bool HasDepth(GalImageFormat Format) + public static bool HasDepth(GalImageFormat format) { - return (GetImageDescriptor(Format).Target & TargetBuffer.Depth) != 0; + return (GetImageDescriptor(format).Target & TargetBuffer.Depth) != 0; } - public static bool HasStencil(GalImageFormat Format) + public static bool HasStencil(GalImageFormat format) { - return (GetImageDescriptor(Format).Target & TargetBuffer.Stencil) != 0; + return (GetImageDescriptor(format).Target & TargetBuffer.Stencil) != 0; } - public static bool IsCompressed(GalImageFormat Format) + public static bool IsCompressed(GalImageFormat format) { - ImageDescriptor Desc = GetImageDescriptor(Format); + ImageDescriptor desc = GetImageDescriptor(format); - return (Desc.BlockWidth | Desc.BlockHeight) != 1; + return (desc.BlockWidth | desc.BlockHeight) != 1; } - private static ImageDescriptor GetImageDescriptor(GalImageFormat Format) + private static ImageDescriptor GetImageDescriptor(GalImageFormat format) { - GalImageFormat PixelFormat = Format & GalImageFormat.FormatMask; + GalImageFormat pixelFormat = format & GalImageFormat.FormatMask; - if (s_ImageTable.TryGetValue(PixelFormat, out ImageDescriptor Descriptor)) + if (ImageTable.TryGetValue(pixelFormat, out ImageDescriptor descriptor)) { - return Descriptor; + return descriptor; } - throw new NotImplementedException($"Format \"{PixelFormat}\" not implemented!"); + throw new NotImplementedException($"Format \"{pixelFormat}\" not implemented!"); } - private static GalImageFormat GetFormatType(GalTextureType Type) + private static GalImageFormat GetFormatType(GalTextureType type) { - switch (Type) + switch (type) { case GalTextureType.Snorm: return Snorm; case GalTextureType.Unorm: return Unorm; @@ -494,13 +494,13 @@ namespace Ryujinx.Graphics.Texture case GalTextureType.Uint: return Uint; case GalTextureType.Float: return Float; - default: throw new NotImplementedException(((int)Type).ToString()); + default: throw new NotImplementedException(((int)type).ToString()); } } - public static TextureTarget GetTextureTarget(GalTextureTarget GalTextureTarget) + public static TextureTarget GetTextureTarget(GalTextureTarget galTextureTarget) { - switch (GalTextureTarget) + switch (galTextureTarget) { case GalTextureTarget.OneD: return TextureTarget.Texture1D; @@ -520,13 +520,13 @@ namespace Ryujinx.Graphics.Texture case GalTextureTarget.CubeArray: return TextureTarget.TextureCubeMapArray; default: - throw new NotSupportedException($"Texture target {GalTextureTarget} currently not supported!"); + throw new NotSupportedException($"Texture target {galTextureTarget} currently not supported!"); } } - public static bool IsArray(GalTextureTarget TextureTarget) + public static bool IsArray(GalTextureTarget textureTarget) { - switch (TextureTarget) + switch (textureTarget) { case GalTextureTarget.OneDArray: case GalTextureTarget.TwoDArray: @@ -537,9 +537,9 @@ namespace Ryujinx.Graphics.Texture } } - public static int GetCoordsCountTextureTarget(GalTextureTarget TextureTarget) + public static int GetCoordsCountTextureTarget(GalTextureTarget textureTarget) { - switch (TextureTarget) + switch (textureTarget) { case GalTextureTarget.OneD: return 1; @@ -555,7 +555,7 @@ namespace Ryujinx.Graphics.Texture case GalTextureTarget.CubeArray: return 4; default: - throw new NotImplementedException($"TextureTarget.{TextureTarget} not implemented yet."); + throw new NotImplementedException($"TextureTarget.{textureTarget} not implemented yet."); } } } diff --git a/Ryujinx.Graphics/Graphics3d/Texture/IntegerEncoded.cs b/Ryujinx.Graphics/Graphics3d/Texture/IntegerEncoded.cs index cc9f2dc3ff..2fd4965082 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/IntegerEncoded.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/IntegerEncoded.cs @@ -12,81 +12,81 @@ namespace Ryujinx.Graphics.Texture Trit } - EIntegerEncoding Encoding; + EIntegerEncoding _encoding; public int NumberBits { get; private set; } public int BitValue { get; private set; } public int TritValue { get; private set; } public int QuintValue { get; private set; } - public IntegerEncoded(EIntegerEncoding _Encoding, int NumBits) + public IntegerEncoded(EIntegerEncoding encoding, int numBits) { - Encoding = _Encoding; - NumberBits = NumBits; + _encoding = encoding; + NumberBits = numBits; BitValue = 0; TritValue = 0; QuintValue = 0; } - public bool MatchesEncoding(IntegerEncoded Other) + public bool MatchesEncoding(IntegerEncoded other) { - return Encoding == Other.Encoding && NumberBits == Other.NumberBits; + return _encoding == other._encoding && NumberBits == other.NumberBits; } public EIntegerEncoding GetEncoding() { - return Encoding; + return _encoding; } - public int GetBitLength(int NumberVals) + public int GetBitLength(int numberVals) { - int TotalBits = NumberBits * NumberVals; - if (Encoding == EIntegerEncoding.Trit) + int totalBits = NumberBits * numberVals; + if (_encoding == EIntegerEncoding.Trit) { - TotalBits += (NumberVals * 8 + 4) / 5; + totalBits += (numberVals * 8 + 4) / 5; } - else if (Encoding == EIntegerEncoding.Quint) + else if (_encoding == EIntegerEncoding.Quint) { - TotalBits += (NumberVals * 7 + 2) / 3; + totalBits += (numberVals * 7 + 2) / 3; } - return TotalBits; + return totalBits; } - public static IntegerEncoded CreateEncoding(int MaxVal) + public static IntegerEncoded CreateEncoding(int maxVal) { - while (MaxVal > 0) + while (maxVal > 0) { - int Check = MaxVal + 1; + int check = maxVal + 1; // Is maxVal a power of two? - if ((Check & (Check - 1)) == 0) + if ((check & (check - 1)) == 0) { - return new IntegerEncoded(EIntegerEncoding.JustBits, BitArrayStream.PopCnt(MaxVal)); + return new IntegerEncoded(EIntegerEncoding.JustBits, BitArrayStream.PopCnt(maxVal)); } // Is maxVal of the type 3*2^n - 1? - if ((Check % 3 == 0) && ((Check / 3) & ((Check / 3) - 1)) == 0) + if ((check % 3 == 0) && ((check / 3) & ((check / 3) - 1)) == 0) { - return new IntegerEncoded(EIntegerEncoding.Trit, BitArrayStream.PopCnt(Check / 3 - 1)); + return new IntegerEncoded(EIntegerEncoding.Trit, BitArrayStream.PopCnt(check / 3 - 1)); } // Is maxVal of the type 5*2^n - 1? - if ((Check % 5 == 0) && ((Check / 5) & ((Check / 5) - 1)) == 0) + if ((check % 5 == 0) && ((check / 5) & ((check / 5) - 1)) == 0) { - return new IntegerEncoded(EIntegerEncoding.Quint, BitArrayStream.PopCnt(Check / 5 - 1)); + return new IntegerEncoded(EIntegerEncoding.Quint, BitArrayStream.PopCnt(check / 5 - 1)); } // Apparently it can't be represented with a bounded integer sequence... // just iterate. - MaxVal--; + maxVal--; } return new IntegerEncoded(EIntegerEncoding.JustBits, 0); } public static void DecodeTritBlock( - BitArrayStream BitStream, - List ListIntegerEncoded, - int NumberBitsPerValue) + BitArrayStream bitStream, + List listIntegerEncoded, + int numberBitsPerValue) { // Implement the algorithm in section C.2.12 int[] m = new int[5]; @@ -95,170 +95,170 @@ namespace Ryujinx.Graphics.Texture // Read the trit encoded block according to // table C.2.14 - m[0] = BitStream.ReadBits(NumberBitsPerValue); - T = BitStream.ReadBits(2); - m[1] = BitStream.ReadBits(NumberBitsPerValue); - T |= BitStream.ReadBits(2) << 2; - m[2] = BitStream.ReadBits(NumberBitsPerValue); - T |= BitStream.ReadBits(1) << 4; - m[3] = BitStream.ReadBits(NumberBitsPerValue); - T |= BitStream.ReadBits(2) << 5; - m[4] = BitStream.ReadBits(NumberBitsPerValue); - T |= BitStream.ReadBits(1) << 7; + m[0] = bitStream.ReadBits(numberBitsPerValue); + T = bitStream.ReadBits(2); + m[1] = bitStream.ReadBits(numberBitsPerValue); + T |= bitStream.ReadBits(2) << 2; + m[2] = bitStream.ReadBits(numberBitsPerValue); + T |= bitStream.ReadBits(1) << 4; + m[3] = bitStream.ReadBits(numberBitsPerValue); + T |= bitStream.ReadBits(2) << 5; + m[4] = bitStream.ReadBits(numberBitsPerValue); + T |= bitStream.ReadBits(1) << 7; - int C = 0; + int c = 0; - BitArrayStream Tb = new BitArrayStream(new BitArray(new int[] { T })); - if (Tb.ReadBits(2, 4) == 7) + BitArrayStream tb = new BitArrayStream(new BitArray(new int[] { T })); + if (tb.ReadBits(2, 4) == 7) { - C = (Tb.ReadBits(5, 7) << 2) | Tb.ReadBits(0, 1); + c = (tb.ReadBits(5, 7) << 2) | tb.ReadBits(0, 1); t[4] = t[3] = 2; } else { - C = Tb.ReadBits(0, 4); - if (Tb.ReadBits(5, 6) == 3) + c = tb.ReadBits(0, 4); + if (tb.ReadBits(5, 6) == 3) { t[4] = 2; - t[3] = Tb.ReadBit(7); + t[3] = tb.ReadBit(7); } else { - t[4] = Tb.ReadBit(7); - t[3] = Tb.ReadBits(5, 6); + t[4] = tb.ReadBit(7); + t[3] = tb.ReadBits(5, 6); } } - BitArrayStream Cb = new BitArrayStream(new BitArray(new int[] { C })); - if (Cb.ReadBits(0, 1) == 3) + BitArrayStream cb = new BitArrayStream(new BitArray(new int[] { c })); + if (cb.ReadBits(0, 1) == 3) { t[2] = 2; - t[1] = Cb.ReadBit(4); - t[0] = (Cb.ReadBit(3) << 1) | (Cb.ReadBit(2) & ~Cb.ReadBit(3)); + t[1] = cb.ReadBit(4); + t[0] = (cb.ReadBit(3) << 1) | (cb.ReadBit(2) & ~cb.ReadBit(3)); } - else if (Cb.ReadBits(2, 3) == 3) + else if (cb.ReadBits(2, 3) == 3) { t[2] = 2; t[1] = 2; - t[0] = Cb.ReadBits(0, 1); + t[0] = cb.ReadBits(0, 1); } else { - t[2] = Cb.ReadBit(4); - t[1] = Cb.ReadBits(2, 3); - t[0] = (Cb.ReadBit(1) << 1) | (Cb.ReadBit(0) & ~Cb.ReadBit(1)); + t[2] = cb.ReadBit(4); + t[1] = cb.ReadBits(2, 3); + t[0] = (cb.ReadBit(1) << 1) | (cb.ReadBit(0) & ~cb.ReadBit(1)); } for (int i = 0; i < 5; i++) { - IntegerEncoded IntEncoded = new IntegerEncoded(EIntegerEncoding.Trit, NumberBitsPerValue) + IntegerEncoded intEncoded = new IntegerEncoded(EIntegerEncoding.Trit, numberBitsPerValue) { BitValue = m[i], TritValue = t[i] }; - ListIntegerEncoded.Add(IntEncoded); + listIntegerEncoded.Add(intEncoded); } } public static void DecodeQuintBlock( - BitArrayStream BitStream, - List ListIntegerEncoded, - int NumberBitsPerValue) + BitArrayStream bitStream, + List listIntegerEncoded, + int numberBitsPerValue) { // Implement the algorithm in section C.2.12 int[] m = new int[3]; int[] qa = new int[3]; - int Q; + int q; // Read the trit encoded block according to // table C.2.15 - m[0] = BitStream.ReadBits(NumberBitsPerValue); - Q = BitStream.ReadBits(3); - m[1] = BitStream.ReadBits(NumberBitsPerValue); - Q |= BitStream.ReadBits(2) << 3; - m[2] = BitStream.ReadBits(NumberBitsPerValue); - Q |= BitStream.ReadBits(2) << 5; + m[0] = bitStream.ReadBits(numberBitsPerValue); + q = bitStream.ReadBits(3); + m[1] = bitStream.ReadBits(numberBitsPerValue); + q |= bitStream.ReadBits(2) << 3; + m[2] = bitStream.ReadBits(numberBitsPerValue); + q |= bitStream.ReadBits(2) << 5; - BitArrayStream Qb = new BitArrayStream(new BitArray(new int[] { Q })); - if (Qb.ReadBits(1, 2) == 3 && Qb.ReadBits(5, 6) == 0) + BitArrayStream qb = new BitArrayStream(new BitArray(new int[] { q })); + if (qb.ReadBits(1, 2) == 3 && qb.ReadBits(5, 6) == 0) { qa[0] = qa[1] = 4; - qa[2] = (Qb.ReadBit(0) << 2) | ((Qb.ReadBit(4) & ~Qb.ReadBit(0)) << 1) | (Qb.ReadBit(3) & ~Qb.ReadBit(0)); + qa[2] = (qb.ReadBit(0) << 2) | ((qb.ReadBit(4) & ~qb.ReadBit(0)) << 1) | (qb.ReadBit(3) & ~qb.ReadBit(0)); } else { - int C = 0; - if (Qb.ReadBits(1, 2) == 3) + int c = 0; + if (qb.ReadBits(1, 2) == 3) { qa[2] = 4; - C = (Qb.ReadBits(3, 4) << 3) | ((~Qb.ReadBits(5, 6) & 3) << 1) | Qb.ReadBit(0); + c = (qb.ReadBits(3, 4) << 3) | ((~qb.ReadBits(5, 6) & 3) << 1) | qb.ReadBit(0); } else { - qa[2] = Qb.ReadBits(5, 6); - C = Qb.ReadBits(0, 4); + qa[2] = qb.ReadBits(5, 6); + c = qb.ReadBits(0, 4); } - BitArrayStream Cb = new BitArrayStream(new BitArray(new int[] { C })); - if (Cb.ReadBits(0, 2) == 5) + BitArrayStream cb = new BitArrayStream(new BitArray(new int[] { c })); + if (cb.ReadBits(0, 2) == 5) { qa[1] = 4; - qa[0] = Cb.ReadBits(3, 4); + qa[0] = cb.ReadBits(3, 4); } else { - qa[1] = Cb.ReadBits(3, 4); - qa[0] = Cb.ReadBits(0, 2); + qa[1] = cb.ReadBits(3, 4); + qa[0] = cb.ReadBits(0, 2); } } for (int i = 0; i < 3; i++) { - IntegerEncoded IntEncoded = new IntegerEncoded(EIntegerEncoding.Quint, NumberBitsPerValue) + IntegerEncoded intEncoded = new IntegerEncoded(EIntegerEncoding.Quint, numberBitsPerValue) { BitValue = m[i], QuintValue = qa[i] }; - ListIntegerEncoded.Add(IntEncoded); + listIntegerEncoded.Add(intEncoded); } } public static void DecodeIntegerSequence( - List DecodeIntegerSequence, - BitArrayStream BitStream, - int MaxRange, - int NumberValues) + List decodeIntegerSequence, + BitArrayStream bitStream, + int maxRange, + int numberValues) { // Determine encoding parameters - IntegerEncoded IntEncoded = CreateEncoding(MaxRange); + IntegerEncoded intEncoded = CreateEncoding(maxRange); // Start decoding - int NumberValuesDecoded = 0; - while (NumberValuesDecoded < NumberValues) + int numberValuesDecoded = 0; + while (numberValuesDecoded < numberValues) { - switch (IntEncoded.GetEncoding()) + switch (intEncoded.GetEncoding()) { case EIntegerEncoding.Quint: { - DecodeQuintBlock(BitStream, DecodeIntegerSequence, IntEncoded.NumberBits); - NumberValuesDecoded += 3; + DecodeQuintBlock(bitStream, decodeIntegerSequence, intEncoded.NumberBits); + numberValuesDecoded += 3; break; } case EIntegerEncoding.Trit: { - DecodeTritBlock(BitStream, DecodeIntegerSequence, IntEncoded.NumberBits); - NumberValuesDecoded += 5; + DecodeTritBlock(bitStream, decodeIntegerSequence, intEncoded.NumberBits); + numberValuesDecoded += 5; break; } case EIntegerEncoding.JustBits: { - IntEncoded.BitValue = BitStream.ReadBits(IntEncoded.NumberBits); - DecodeIntegerSequence.Add(IntEncoded); - NumberValuesDecoded++; + intEncoded.BitValue = bitStream.ReadBits(intEncoded.NumberBits); + decodeIntegerSequence.Add(intEncoded); + numberValuesDecoded++; break; } diff --git a/Ryujinx.Graphics/Graphics3d/Texture/LinearSwizzle.cs b/Ryujinx.Graphics/Graphics3d/Texture/LinearSwizzle.cs index e6509baa6a..7ce0d399aa 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/LinearSwizzle.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/LinearSwizzle.cs @@ -4,42 +4,42 @@ namespace Ryujinx.Graphics.Texture { class LinearSwizzle : ISwizzle { - private int Pitch; - private int Bpp; + private int _pitch; + private int _bpp; - private int SliceSize; + private int _sliceSize; - public LinearSwizzle(int Pitch, int Bpp, int Width, int Height) + public LinearSwizzle(int pitch, int bpp, int width, int height) { - this.Pitch = Pitch; - this.Bpp = Bpp; - SliceSize = Width * Height * Bpp; + this._pitch = pitch; + this._bpp = bpp; + _sliceSize = width * height * bpp; } - public void SetMipLevel(int Level) + public void SetMipLevel(int level) { throw new NotImplementedException(); } - public int GetMipOffset(int Level) + public int GetMipOffset(int level) { - if (Level == 1) - return SliceSize; + if (level == 1) + return _sliceSize; throw new NotImplementedException(); } - public int GetImageSize(int MipsCount) + public int GetImageSize(int mipsCount) { - int Size = GetMipOffset(MipsCount); + int size = GetMipOffset(mipsCount); - Size = (Size + 0x1fff) & ~0x1fff; + size = (size + 0x1fff) & ~0x1fff; - return Size; + return size; } - public int GetSwizzleOffset(int X, int Y, int Z) + public int GetSwizzleOffset(int x, int y, int z) { - return Z * SliceSize + X * Bpp + Y * Pitch; + return z * _sliceSize + x * _bpp + y * _pitch; } } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/Texture/TextureFactory.cs b/Ryujinx.Graphics/Graphics3d/Texture/TextureFactory.cs index a2ce86f56d..28c9050253 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/TextureFactory.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/TextureFactory.cs @@ -6,161 +6,161 @@ namespace Ryujinx.Graphics.Texture { static class TextureFactory { - public static GalImage MakeTexture(NvGpuVmm Vmm, long TicPosition) + public static GalImage MakeTexture(NvGpuVmm vmm, long ticPosition) { - int[] Tic = ReadWords(Vmm, TicPosition, 8); + int[] tic = ReadWords(vmm, ticPosition, 8); - GalImageFormat Format = GetImageFormat(Tic); + GalImageFormat format = GetImageFormat(tic); - GalTextureTarget TextureTarget = (GalTextureTarget)((Tic[4] >> 23) & 0xF); + GalTextureTarget textureTarget = (GalTextureTarget)((tic[4] >> 23) & 0xF); - GalTextureSource XSource = (GalTextureSource)((Tic[0] >> 19) & 7); - GalTextureSource YSource = (GalTextureSource)((Tic[0] >> 22) & 7); - GalTextureSource ZSource = (GalTextureSource)((Tic[0] >> 25) & 7); - GalTextureSource WSource = (GalTextureSource)((Tic[0] >> 28) & 7); + GalTextureSource xSource = (GalTextureSource)((tic[0] >> 19) & 7); + GalTextureSource ySource = (GalTextureSource)((tic[0] >> 22) & 7); + GalTextureSource zSource = (GalTextureSource)((tic[0] >> 25) & 7); + GalTextureSource wSource = (GalTextureSource)((tic[0] >> 28) & 7); - TextureSwizzle Swizzle = (TextureSwizzle)((Tic[2] >> 21) & 7); + TextureSwizzle swizzle = (TextureSwizzle)((tic[2] >> 21) & 7); - int MaxMipmapLevel = (Tic[3] >> 28) & 0xF + 1; + int maxMipmapLevel = (tic[3] >> 28) & 0xF + 1; - GalMemoryLayout Layout; + GalMemoryLayout layout; - if (Swizzle == TextureSwizzle.BlockLinear || - Swizzle == TextureSwizzle.BlockLinearColorKey) + if (swizzle == TextureSwizzle.BlockLinear || + swizzle == TextureSwizzle.BlockLinearColorKey) { - Layout = GalMemoryLayout.BlockLinear; + layout = GalMemoryLayout.BlockLinear; } else { - Layout = GalMemoryLayout.Pitch; + layout = GalMemoryLayout.Pitch; } - int GobBlockHeightLog2 = (Tic[3] >> 3) & 7; - int GobBlockDepthLog2 = (Tic[3] >> 6) & 7; - int TileWidthLog2 = (Tic[3] >> 10) & 7; + int gobBlockHeightLog2 = (tic[3] >> 3) & 7; + int gobBlockDepthLog2 = (tic[3] >> 6) & 7; + int tileWidthLog2 = (tic[3] >> 10) & 7; - int GobBlockHeight = 1 << GobBlockHeightLog2; - int GobBlockDepth = 1 << GobBlockDepthLog2; - int TileWidth = 1 << TileWidthLog2; + int gobBlockHeight = 1 << gobBlockHeightLog2; + int gobBlockDepth = 1 << gobBlockDepthLog2; + int tileWidth = 1 << tileWidthLog2; - int Width = ((Tic[4] >> 0) & 0xffff) + 1; - int Height = ((Tic[5] >> 0) & 0xffff) + 1; - int Depth = ((Tic[5] >> 16) & 0x3fff) + 1; + int width = ((tic[4] >> 0) & 0xffff) + 1; + int height = ((tic[5] >> 0) & 0xffff) + 1; + int depth = ((tic[5] >> 16) & 0x3fff) + 1; - int LayoutCount = 1; + int layoutCount = 1; // TODO: check this - if (ImageUtils.IsArray(TextureTarget)) + if (ImageUtils.IsArray(textureTarget)) { - LayoutCount = Depth; - Depth = 1; + layoutCount = depth; + depth = 1; } - if (TextureTarget == GalTextureTarget.OneD) + if (textureTarget == GalTextureTarget.OneD) { - Height = 1; + height = 1; } - if (TextureTarget == GalTextureTarget.TwoD || TextureTarget == GalTextureTarget.OneD) + if (textureTarget == GalTextureTarget.TwoD || textureTarget == GalTextureTarget.OneD) { - Depth = 1; + depth = 1; } - else if (TextureTarget == GalTextureTarget.CubeMap) + else if (textureTarget == GalTextureTarget.CubeMap) { // FIXME: This is a bit hacky but I guess it's fine for now - LayoutCount = 6; - Depth = 1; + layoutCount = 6; + depth = 1; } - else if (TextureTarget == GalTextureTarget.CubeArray) + else if (textureTarget == GalTextureTarget.CubeArray) { // FIXME: This is a really really hacky but I guess it's fine for now - LayoutCount *= 6; - Depth = 1; + layoutCount *= 6; + depth = 1; } - GalImage Image = new GalImage( - Width, - Height, - Depth, - LayoutCount, - TileWidth, - GobBlockHeight, - GobBlockDepth, - Layout, - Format, - TextureTarget, - MaxMipmapLevel, - XSource, - YSource, - ZSource, - WSource); + GalImage image = new GalImage( + width, + height, + depth, + layoutCount, + tileWidth, + gobBlockHeight, + gobBlockDepth, + layout, + format, + textureTarget, + maxMipmapLevel, + xSource, + ySource, + zSource, + wSource); - if (Layout == GalMemoryLayout.Pitch) + if (layout == GalMemoryLayout.Pitch) { - Image.Pitch = (Tic[3] & 0xffff) << 5; + image.Pitch = (tic[3] & 0xffff) << 5; } - return Image; + return image; } - public static GalTextureSampler MakeSampler(NvGpu Gpu, NvGpuVmm Vmm, long TscPosition) + public static GalTextureSampler MakeSampler(NvGpu gpu, NvGpuVmm vmm, long tscPosition) { - int[] Tsc = ReadWords(Vmm, TscPosition, 8); + int[] tsc = ReadWords(vmm, tscPosition, 8); - GalTextureWrap AddressU = (GalTextureWrap)((Tsc[0] >> 0) & 7); - GalTextureWrap AddressV = (GalTextureWrap)((Tsc[0] >> 3) & 7); - GalTextureWrap AddressP = (GalTextureWrap)((Tsc[0] >> 6) & 7); + GalTextureWrap addressU = (GalTextureWrap)((tsc[0] >> 0) & 7); + GalTextureWrap addressV = (GalTextureWrap)((tsc[0] >> 3) & 7); + GalTextureWrap addressP = (GalTextureWrap)((tsc[0] >> 6) & 7); - bool DepthCompare = ((Tsc[0] >> 9) & 1) == 1; + bool depthCompare = ((tsc[0] >> 9) & 1) == 1; - DepthCompareFunc DepthCompareFunc = (DepthCompareFunc)((Tsc[0] >> 10) & 7); + DepthCompareFunc depthCompareFunc = (DepthCompareFunc)((tsc[0] >> 10) & 7); - GalTextureFilter MagFilter = (GalTextureFilter) ((Tsc[1] >> 0) & 3); - GalTextureFilter MinFilter = (GalTextureFilter) ((Tsc[1] >> 4) & 3); - GalTextureMipFilter MipFilter = (GalTextureMipFilter)((Tsc[1] >> 6) & 3); + GalTextureFilter magFilter = (GalTextureFilter) ((tsc[1] >> 0) & 3); + GalTextureFilter minFilter = (GalTextureFilter) ((tsc[1] >> 4) & 3); + GalTextureMipFilter mipFilter = (GalTextureMipFilter)((tsc[1] >> 6) & 3); - GalColorF BorderColor = new GalColorF( - BitConverter.Int32BitsToSingle(Tsc[4]), - BitConverter.Int32BitsToSingle(Tsc[5]), - BitConverter.Int32BitsToSingle(Tsc[6]), - BitConverter.Int32BitsToSingle(Tsc[7])); + GalColorF borderColor = new GalColorF( + BitConverter.Int32BitsToSingle(tsc[4]), + BitConverter.Int32BitsToSingle(tsc[5]), + BitConverter.Int32BitsToSingle(tsc[6]), + BitConverter.Int32BitsToSingle(tsc[7])); return new GalTextureSampler( - AddressU, - AddressV, - AddressP, - MinFilter, - MagFilter, - MipFilter, - BorderColor, - DepthCompare, - DepthCompareFunc); + addressU, + addressV, + addressP, + minFilter, + magFilter, + mipFilter, + borderColor, + depthCompare, + depthCompareFunc); } - private static GalImageFormat GetImageFormat(int[] Tic) + private static GalImageFormat GetImageFormat(int[] tic) { - GalTextureType RType = (GalTextureType)((Tic[0] >> 7) & 7); - GalTextureType GType = (GalTextureType)((Tic[0] >> 10) & 7); - GalTextureType BType = (GalTextureType)((Tic[0] >> 13) & 7); - GalTextureType AType = (GalTextureType)((Tic[0] >> 16) & 7); + GalTextureType rType = (GalTextureType)((tic[0] >> 7) & 7); + GalTextureType gType = (GalTextureType)((tic[0] >> 10) & 7); + GalTextureType bType = (GalTextureType)((tic[0] >> 13) & 7); + GalTextureType aType = (GalTextureType)((tic[0] >> 16) & 7); - GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f); + GalTextureFormat format = (GalTextureFormat)(tic[0] & 0x7f); - bool ConvSrgb = ((Tic[4] >> 22) & 1) != 0; + bool convSrgb = ((tic[4] >> 22) & 1) != 0; - return ImageUtils.ConvertTexture(Format, RType, GType, BType, AType, ConvSrgb); + return ImageUtils.ConvertTexture(format, rType, gType, bType, aType, convSrgb); } - private static int[] ReadWords(NvGpuVmm Vmm, long Position, int Count) + private static int[] ReadWords(NvGpuVmm vmm, long position, int count) { - int[] Words = new int[Count]; + int[] words = new int[count]; - for (int Index = 0; Index < Count; Index++, Position += 4) + for (int index = 0; index < count; index++, position += 4) { - Words[Index] = Vmm.ReadInt32(Position); + words[index] = vmm.ReadInt32(position); } - return Words; + return words; } } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Graphics3d/Texture/TextureHelper.cs b/Ryujinx.Graphics/Graphics3d/Texture/TextureHelper.cs index 33ccb0aa51..1de81008ee 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/TextureHelper.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/TextureHelper.cs @@ -7,47 +7,47 @@ namespace Ryujinx.Graphics.Texture { static class TextureHelper { - public static ISwizzle GetSwizzle(GalImage Image) + public static ISwizzle GetSwizzle(GalImage image) { - int BlockWidth = ImageUtils.GetBlockWidth (Image.Format); - int BlockHeight = ImageUtils.GetBlockHeight (Image.Format); - int BlockDepth = ImageUtils.GetBlockDepth (Image.Format); - int BytesPerPixel = ImageUtils.GetBytesPerPixel(Image.Format); + int blockWidth = ImageUtils.GetBlockWidth (image.Format); + int blockHeight = ImageUtils.GetBlockHeight (image.Format); + int blockDepth = ImageUtils.GetBlockDepth (image.Format); + int bytesPerPixel = ImageUtils.GetBytesPerPixel(image.Format); - int Width = BitUtils.DivRoundUp(Image.Width, BlockWidth); - int Height = BitUtils.DivRoundUp(Image.Height, BlockHeight); - int Depth = BitUtils.DivRoundUp(Image.Depth, BlockDepth); + int width = BitUtils.DivRoundUp(image.Width, blockWidth); + int height = BitUtils.DivRoundUp(image.Height, blockHeight); + int depth = BitUtils.DivRoundUp(image.Depth, blockDepth); - if (Image.Layout == GalMemoryLayout.BlockLinear) + if (image.Layout == GalMemoryLayout.BlockLinear) { - int AlignMask = Image.TileWidth * (64 / BytesPerPixel) - 1; + int alignMask = image.TileWidth * (64 / bytesPerPixel) - 1; - Width = (Width + AlignMask) & ~AlignMask; + width = (width + alignMask) & ~alignMask; return new BlockLinearSwizzle( - Width, - Height, - Depth, - Image.GobBlockHeight, - Image.GobBlockDepth, - BytesPerPixel); + width, + height, + depth, + image.GobBlockHeight, + image.GobBlockDepth, + bytesPerPixel); } else { - return new LinearSwizzle(Image.Pitch, BytesPerPixel, Width, Height); + return new LinearSwizzle(image.Pitch, bytesPerPixel, width, height); } } public static (MemoryManager Memory, long Position) GetMemoryAndPosition( - IMemory Memory, - long Position) + IMemory memory, + long position) { - if (Memory is NvGpuVmm Vmm) + if (memory is NvGpuVmm vmm) { - return (Vmm.Memory, Vmm.GetPhysicalAddress(Position)); + return (vmm.Memory, vmm.GetPhysicalAddress(position)); } - return ((MemoryManager)Memory, Position); + return ((MemoryManager)memory, position); } } } diff --git a/Ryujinx.Graphics/Graphics3d/Texture/TextureSwizzle.cs b/Ryujinx.Graphics/Graphics3d/Texture/TextureSwizzle.cs index c67a5367ec..2cc426ab9d 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/TextureSwizzle.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/TextureSwizzle.cs @@ -2,7 +2,7 @@ namespace Ryujinx.Graphics.Texture { public enum TextureSwizzle { - _1dBuffer = 0, + _1DBuffer = 0, PitchColorKey = 1, Pitch = 2, BlockLinear = 3,