Ejemplo n.º 1
0
        public static byte[] ReadTexture(IMemory Memory, GalImage Image, long Position)
        {
            MemoryManager CpuMemory;

            if (Memory is NvGpuVmm Vmm)
            {
                CpuMemory = Vmm.Memory;
            }
            else
            {
                CpuMemory = (MemoryManager)Memory;
            }

            ISwizzle Swizzle = TextureHelper.GetSwizzle(Image);

            ImageDescriptor Desc = GetImageDescriptor(Image.Format);

            (int Width, int Height) = GetImageSizeInBlocks(Image);

            int BytesPerPixel = Desc.BytesPerPixel;

            //Note: Each row of the texture needs to be aligned to 4 bytes.
            int Pitch = (Width * BytesPerPixel + 3) & ~3;

            byte[] Data = new byte[Height * Pitch];

            for (int Y = 0; Y < Height; Y++)
            {
                int OutOffs = Y * Pitch;

                for (int X = 0; X < Width; X++)
                {
                    long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);

                    CpuMemory.ReadBytes(Position + Offset, Data, OutOffs, BytesPerPixel);

                    OutOffs += BytesPerPixel;
                }
            }

            return(Data);
        }
Ejemplo n.º 2
0
        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)
        {
            ISwizzle SrcSwizzle = TextureHelper.GetSwizzle(SrcImage);
            ISwizzle DstSwizzle = TextureHelper.GetSwizzle(DstImage);

            ImageDescriptor Desc = GetImageDescriptor(SrcImage.Format);

            if (GetImageDescriptor(DstImage.Format).BytesPerPixel != Desc.BytesPerPixel)
            {
                return(false);
            }

            int BytesPerPixel = Desc.BytesPerPixel;

            for (int Y = 0; Y < Height; Y++)
            {
                for (int X = 0; X < Width; X++)
                {
                    long SrcOffset = (uint)SrcSwizzle.GetSwizzleOffset(SrcX + X, SrcY + Y);
                    long DstOffset = (uint)DstSwizzle.GetSwizzleOffset(DstX + X, DstY + Y);

                    byte[] Texel = Vmm.ReadBytes(SrcAddress + SrcOffset, BytesPerPixel);

                    Vmm.WriteBytes(DstAddress + DstOffset, Texel);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        // 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)
        {
            ISwizzle srcSwizzle = TextureHelper.GetSwizzle(srcImage);
            ISwizzle dstSwizzle = TextureHelper.GetSwizzle(dstImage);

            ImageDescriptor desc = GetImageDescriptor(srcImage.Format);

            if (GetImageDescriptor(dstImage.Format).BytesPerPixel != desc.BytesPerPixel)
            {
                return(false);
            }

            int bytesPerPixel = desc.BytesPerPixel;

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

                    byte[] texel = vmm.ReadBytes(srcAddress + srcOffset, bytesPerPixel);

                    vmm.WriteBytes(dstAddress + dstOffset, texel);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        public static byte[] ReadTexture(IAMemory Memory, GalImage Image, long Position)
        {
            AMemory CpuMemory;

            if (Memory is NvGpuVmm Vmm)
            {
                CpuMemory = Vmm.Memory;
            }
            else
            {
                CpuMemory = (AMemory)Memory;
            }

            ISwizzle Swizzle = TextureHelper.GetSwizzle(Image);

            ImageDescriptor Desc = GetImageDescriptor(Image.Format);

            (int Width, int Height) = GetImageSizeInBlocks(Image);

            int BytesPerPixel = Desc.BytesPerPixel;

            int OutOffs = 0;

            byte[] Data = new byte[Width * Height * BytesPerPixel];

            for (int Y = 0; Y < Height; Y++)
            {
                for (int X = 0; X < Width; X++)
                {
                    long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);

                    CpuMemory.ReadBytes(Position + Offset, Data, OutOffs, BytesPerPixel);

                    OutOffs += BytesPerPixel;
                }
            }

            return(Data);
        }
Ejemplo n.º 5
0
        public static void WriteTexture(NvGpuVmm Vmm, GalImage Image, long Position, byte[] Data)
        {
            ISwizzle Swizzle = TextureHelper.GetSwizzle(Image);

            ImageDescriptor Desc = GetImageDescriptor(Image.Format);

            (int Width, int Height) = ImageUtils.GetImageSizeInBlocks(Image);

            int BytesPerPixel = Desc.BytesPerPixel;

            int InOffs = 0;

            for (int Y = 0; Y < Height; Y++)
            {
                for (int X = 0; X < Width; X++)
                {
                    long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);

                    Vmm.Memory.WriteBytes(Position + Offset, Data, InOffs, BytesPerPixel);

                    InOffs += BytesPerPixel;
                }
            }
        }
Ejemplo n.º 6
0
 public static int GetGpuSize(GalImage image, bool forcePitch = false)
 {
     return(TextureHelper.GetSwizzle(image).GetImageSize(image.MaxMipmapLevel) * image.LayerCount);
 }