From ce1d5be212e6f71a7ca32c3bd7b48e32d9f51b9a Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sat, 8 Sep 2018 14:51:50 -0300 Subject: Move GPU emulation from Ryujinx.HLE to Ryujinx.Graphics and misc changes (#402) * Move GPU LLE emulation from HLE to Graphics * Graphics: Move Gal/Texture to Texture * Remove Engines/ directory and namespace * Use tables for image formats * Abstract OpCode decoding * Simplify image table * Do not leak Read* symbols in TextureReader * Fixups * Rename IGalFrameBuffer -> IGalRenderTarget * Remove MaxBpp hardcoded value * Change yet again texture data and add G8R8 flipping * Rename GalFrameBufferFormat to GalSurfaceFormat * Unident EnsureSetup in ImageHandler * Add IsCompressed * Address some feedback --- Ryujinx.Graphics/Texture/BitArrayStream.cs | 121 +++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Ryujinx.Graphics/Texture/BitArrayStream.cs (limited to 'Ryujinx.Graphics/Texture/BitArrayStream.cs') diff --git a/Ryujinx.Graphics/Texture/BitArrayStream.cs b/Ryujinx.Graphics/Texture/BitArrayStream.cs new file mode 100644 index 00000000..2a8ed091 --- /dev/null +++ b/Ryujinx.Graphics/Texture/BitArrayStream.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections; + +namespace Ryujinx.Graphics.Texture +{ + public class BitArrayStream + { + public BitArray BitsArray; + + public int Position { get; private set; } + + public BitArrayStream(BitArray BitArray) + { + BitsArray = BitArray; + Position = 0; + } + + public short ReadBits(int Length) + { + int RetValue = 0; + for (int i = Position; i < Position + Length; i++) + { + if (BitsArray[i]) + { + RetValue |= 1 << (i - Position); + } + } + + Position += Length; + return (short)RetValue; + } + + public int ReadBits(int Start, int End) + { + int RetValue = 0; + for (int i = Start; i <= End; i++) + { + if (BitsArray[i]) + { + RetValue |= 1 << (i - Start); + } + } + + return RetValue; + } + + public int ReadBit(int Index) + { + return Convert.ToInt32(BitsArray[Index]); + } + + public void WriteBits(int Value, int Length) + { + for (int i = Position; i < Position + Length; i++) + { + BitsArray[i] = ((Value >> (i - Position)) & 1) != 0; + } + + Position += Length; + } + + public byte[] ToByteArray() + { + byte[] RetArray = new byte[(BitsArray.Length + 7) / 8]; + BitsArray.CopyTo(RetArray, 0); + return RetArray; + } + + public static int Replicate(int Value, int NumberBits, int ToBit) + { + if (NumberBits == 0) return 0; + if (ToBit == 0) return 0; + + int TempValue = Value & ((1 << NumberBits) - 1); + int RetValue = TempValue; + int ResLength = NumberBits; + + while (ResLength < ToBit) + { + int Comp = 0; + if (NumberBits > ToBit - ResLength) + { + int NewShift = ToBit - ResLength; + Comp = NumberBits - NewShift; + NumberBits = NewShift; + } + RetValue <<= NumberBits; + RetValue |= TempValue >> Comp; + ResLength += NumberBits; + } + return RetValue; + } + + public static int PopCnt(int Number) + { + int Counter; + for (Counter = 0; Number != 0; Counter++) + { + Number &= Number - 1; + } + return Counter; + } + + public static void Swap(ref T lhs, ref T rhs) + { + T Temp = lhs; + lhs = rhs; + rhs = Temp; + } + + // Transfers a bit as described in C.2.14 + public static void BitTransferSigned(ref int a, ref int b) + { + b >>= 1; + b |= a & 0x80; + a >>= 1; + a &= 0x3F; + if ((a & 0x20) != 0) a -= 0x40; + } + } +} -- cgit v1.2.3