public static byte[] GetTextureData(NvGpuVmm Vmm, long TicPosition) { int[] Tic = ReadWords(Vmm, TicPosition, 8); GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f); long TextureAddress = (uint)Tic[1]; TextureAddress |= (long)((ushort)Tic[2]) << 32; TextureSwizzle Swizzle = (TextureSwizzle)((Tic[2] >> 21) & 7); int Pitch = (Tic[3] & 0xffff) << 5; int BlockHeightLog2 = (Tic[3] >> 3) & 7; int BlockHeight = 1 << BlockHeightLog2; int Width = (Tic[4] & 0xffff) + 1; int Height = (Tic[5] & 0xffff) + 1; Texture Texture = new Texture( TextureAddress, Width, Height, Pitch, BlockHeight, Swizzle, Format); return(TextureReader.Read(Vmm, Texture)); }
/// <summary> /// /// </summary> /// <param name="name">The value for <see cref="Name"/></param> /// <param name="uvCoord">The value for <see cref="UvCoord"/></param> /// <param name="textureSwizzle">The value for <see cref="TextureSwizzle"/></param> public TextureRenderInfo(string name, UvCoord uvCoord = UvCoord.TexCoord0, TextureSwizzle textureSwizzle = TextureSwizzle.Rgb) { Name = name; UvCoord = uvCoord; TextureSwizzle = textureSwizzle; }
/// <summary> /// Specifies how a texture's channels map to color components. /// </summary> /// <param name="r">Channel for red component.</param> /// <param name="g">Channel for green component.</param> /// <param name="b">Channel for blue component.</param> /// <param name="a">Channel for alpha component.</param> /// <returns>This Builder, for chaining calls.</returns> public TextureBuilder WithSwizzle(TextureSwizzle r, TextureSwizzle g, TextureSwizzle b, TextureSwizzle a) { ThrowExceptionIfDisposed(); Native.TextureBuilder.Swizzle(NativePtr, (int)r, (int)g, (int)b, (int)a); return(this); }
private void TextureCopy(AMemory Memory, NsGpuPBEntry PBEntry) { CopyOperation Operation = (CopyOperation)ReadRegister(NvGpuEngine2dReg.CopyOperation); bool SrcLinear = ReadRegister(NvGpuEngine2dReg.SrcLinear) != 0; int SrcWidth = ReadRegister(NvGpuEngine2dReg.SrcWidth); int SrcHeight = ReadRegister(NvGpuEngine2dReg.SrcHeight); bool DstLinear = ReadRegister(NvGpuEngine2dReg.DstLinear) != 0; int DstWidth = ReadRegister(NvGpuEngine2dReg.DstWidth); int DstHeight = ReadRegister(NvGpuEngine2dReg.DstHeight); int DstPitch = ReadRegister(NvGpuEngine2dReg.DstPitch); int DstBlkDim = ReadRegister(NvGpuEngine2dReg.DstBlockDimensions); TextureSwizzle DstSwizzle = DstLinear ? TextureSwizzle.Pitch : TextureSwizzle.BlockLinear; int DstBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf); long Tag = MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress); TryGetCpuAddr(NvGpuEngine2dReg.SrcAddress, out long SrcAddress); TryGetCpuAddr(NvGpuEngine2dReg.DstAddress, out long DstAddress); bool IsFbTexture = Gpu.Engine3d.IsFrameBufferPosition(Tag); if (IsFbTexture && DstLinear) { DstSwizzle = TextureSwizzle.BlockLinear; } Texture DstTexture = new Texture( DstAddress, DstWidth, DstHeight, DstBlockHeight, DstBlockHeight, DstSwizzle, GalTextureFormat.A8B8G8R8); if (IsFbTexture) { Gpu.Renderer.GetFrameBufferData(Tag, (byte[] Buffer) => { CopyTexture(Memory, DstTexture, Buffer); }); } else { long Size = SrcWidth * SrcHeight * 4; byte[] Buffer = AMemoryHelper.ReadBytes(Memory, SrcAddress, Size); CopyTexture(Memory, DstTexture, Buffer); } }
public static GalImage MakeTexture(NvGpuVmm Vmm, long TicPosition) { int[] Tic = ReadWords(Vmm, TicPosition, 8); GalImageFormat Format = GetImageFormat(Tic); 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); GalMemoryLayout Layout; if (Swizzle == TextureSwizzle.BlockLinear || Swizzle == TextureSwizzle.BlockLinearColorKey) { Layout = GalMemoryLayout.BlockLinear; } else { Layout = GalMemoryLayout.Pitch; } int BlockHeightLog2 = (Tic[3] >> 3) & 7; int TileWidthLog2 = (Tic[3] >> 10) & 7; int BlockHeight = 1 << BlockHeightLog2; int TileWidth = 1 << TileWidthLog2; int Width = (Tic[4] & 0xffff) + 1; int Height = (Tic[5] & 0xffff) + 1; GalImage Image = new GalImage( Width, Height, TileWidth, BlockHeight, Layout, Format, XSource, YSource, ZSource, WSource); if (Layout == GalMemoryLayout.Pitch) { Image.Pitch = (Tic[3] & 0xffff) << 5; } return(Image); }
public static GalTexture MakeTexture(NvGpu Gpu, NvGpuVmm Vmm, long TicPosition) { int[] Tic = ReadWords(Vmm, TicPosition, 8); GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f); 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); long TextureAddress = (uint)Tic[1]; TextureAddress |= (long)((ushort)Tic[2]) << 32; TextureSwizzle Swizzle = (TextureSwizzle)((Tic[2] >> 21) & 7); int Pitch = (Tic[3] & 0xffff) << 5; int BlockHeightLog2 = (Tic[3] >> 3) & 7; int BlockHeight = 1 << BlockHeightLog2; int Width = (Tic[4] & 0xffff) + 1; int Height = (Tic[5] & 0xffff) + 1; Texture Texture = new Texture( TextureAddress, Width, Height, Pitch, BlockHeight, Swizzle, Format); byte[] Data = TextureReader.Read(Vmm, Texture); return(new GalTexture( Data, Width, Height, Format, XSource, YSource, ZSource, WSource)); }
public Texture( long Position, int Width, int Height, int Pitch, int BlockHeight, TextureSwizzle Swizzle, GalTextureFormat Format) { this.Position = Position; this.Width = Width; this.Height = Height; this.Pitch = Pitch; this.BlockHeight = BlockHeight; this.Swizzle = Swizzle; this.Format = Format; }
public static byte[] GetTextureData(NvGpuVmm Vmm, long TicPosition) { int[] Tic = ReadWords(Vmm, TicPosition, 8); GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f); long TextureAddress = (uint)Tic[1]; TextureAddress |= (long)((ushort)Tic[2]) << 32; TextureSwizzle Swizzle = (TextureSwizzle)((Tic[2] >> 21) & 7); if (Swizzle == TextureSwizzle.BlockLinear || Swizzle == TextureSwizzle.BlockLinearColorKey) { TextureAddress &= ~0x1ffL; } else if (Swizzle == TextureSwizzle.Pitch || Swizzle == TextureSwizzle.PitchColorKey) { TextureAddress &= ~0x1fL; } int Pitch = (Tic[3] & 0xffff) << 5; int BlockHeightLog2 = (Tic[3] >> 3) & 7; int TileWidthLog2 = (Tic[3] >> 10) & 7; int BlockHeight = 1 << BlockHeightLog2; int TileWidth = 1 << TileWidthLog2; int Width = (Tic[4] & 0xffff) + 1; int Height = (Tic[5] & 0xffff) + 1; TextureInfo Texture = new TextureInfo( TextureAddress, Width, Height, Pitch, BlockHeight, TileWidth, Swizzle, Format); return(TextureReader.Read(Vmm, Texture)); }
public static string Str(this TextureSwizzle swiz) { switch (swiz) { case TextureSwizzle.Red: return("R"); case TextureSwizzle.Green: return("G"); case TextureSwizzle.Blue: return("B"); case TextureSwizzle.Alpha: return("A"); case TextureSwizzle.Zero: return("0"); case TextureSwizzle.One: return("1"); } return("Unknown"); }
public static string GetSwizzle(TextureSwizzle swizzle) { switch (swizzle) { case TextureSwizzle.Rgb: return("rgb"); case TextureSwizzle.R: return("rrr"); case TextureSwizzle.G: return("ggg"); case TextureSwizzle.B: return("bbb"); case TextureSwizzle.A: return("aaa"); default: return("rgb"); } }
public static GalTexture MakeTexture(NsGpu Gpu, AMemory Memory, long TicPosition) { int[] Tic = ReadWords(Memory, TicPosition, 8); GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f); long TextureAddress = (uint)Tic[1]; TextureAddress |= (long)((ushort)Tic[2]) << 32; TextureAddress = Gpu.GetCpuAddr(TextureAddress); TextureSwizzle Swizzle = (TextureSwizzle)((Tic[2] >> 21) & 7); int Pitch = (Tic[3] & 0xffff) << 5; int BlockHeightLog2 = (Tic[3] >> 3) & 7; int BlockHeight = 1 << BlockHeightLog2; int Width = (Tic[4] & 0xffff) + 1; int Height = (Tic[5] & 0xffff) + 1; Texture Texture = new Texture( TextureAddress, Width, Height, Pitch, BlockHeight, Swizzle, Format); byte[] Data = TextureReader.Read(Memory, Texture); return(new GalTexture(Data, Width, Height, Format)); }
/// <summary> /// /// </summary> /// <param name="name">The value for <see cref="Name"/></param> /// <param name="uvCoord">The value for <see cref="UvCoord"/></param> /// <param name="textureSwizzle">The value for <see cref="TextureSwizzle"/></param> public TextureRenderInfo(string name, UvCoord uvCoord, TextureSwizzle textureSwizzle) { Name = name; UvCoord = uvCoord; TextureSwizzle = textureSwizzle; }
private void TextureCopy(NvGpuVmm Vmm, NvGpuPBEntry PBEntry) { CopyOperation Operation = (CopyOperation)ReadRegister(NvGpuEngine2dReg.CopyOperation); bool SrcLinear = ReadRegister(NvGpuEngine2dReg.SrcLinear) != 0; int SrcWidth = ReadRegister(NvGpuEngine2dReg.SrcWidth); int SrcHeight = ReadRegister(NvGpuEngine2dReg.SrcHeight); bool DstLinear = ReadRegister(NvGpuEngine2dReg.DstLinear) != 0; int DstWidth = ReadRegister(NvGpuEngine2dReg.DstWidth); int DstHeight = ReadRegister(NvGpuEngine2dReg.DstHeight); int DstPitch = ReadRegister(NvGpuEngine2dReg.DstPitch); int DstBlkDim = ReadRegister(NvGpuEngine2dReg.DstBlockDimensions); TextureSwizzle DstSwizzle = DstLinear ? TextureSwizzle.Pitch : TextureSwizzle.BlockLinear; int DstBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf); long Key = Vmm.GetPhysicalAddress(MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress)); long SrcAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress); long DstAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.DstAddress); bool IsFbTexture = Gpu.Engine3d.IsFrameBufferPosition(Key); if (IsFbTexture && DstLinear) { DstSwizzle = TextureSwizzle.BlockLinear; } TextureInfo DstTexture = new TextureInfo( DstAddress, DstWidth, DstHeight, DstBlockHeight, DstBlockHeight, DstSwizzle, GalTextureFormat.A8B8G8R8); if (IsFbTexture) { //TODO: Change this when the correct frame buffer resolution is used. //Currently, the frame buffer size is hardcoded to 1280x720. SrcWidth = 1280; SrcHeight = 720; Gpu.Renderer.FrameBuffer.GetBufferData(Key, (byte[] Buffer) => { CopyTexture( Vmm, DstTexture, Buffer, SrcWidth, SrcHeight); }); } else { long Size = SrcWidth * SrcHeight * 4; byte[] Buffer = Vmm.ReadBytes(SrcAddress, Size); CopyTexture( Vmm, DstTexture, Buffer, SrcWidth, SrcHeight); } }
private void TextureCopy(NvGpuVmm Vmm, NvGpuPBEntry PBEntry) { CopyOperation Operation = (CopyOperation)ReadRegister(NvGpuEngine2dReg.CopyOperation); bool SrcLinear = ReadRegister(NvGpuEngine2dReg.SrcLinear) != 0; int SrcWidth = ReadRegister(NvGpuEngine2dReg.SrcWidth); int SrcHeight = ReadRegister(NvGpuEngine2dReg.SrcHeight); int SrcPitch = ReadRegister(NvGpuEngine2dReg.SrcPitch); int SrcBlkDim = ReadRegister(NvGpuEngine2dReg.SrcBlockDimensions); bool DstLinear = ReadRegister(NvGpuEngine2dReg.DstLinear) != 0; int DstWidth = ReadRegister(NvGpuEngine2dReg.DstWidth); int DstHeight = ReadRegister(NvGpuEngine2dReg.DstHeight); int DstPitch = ReadRegister(NvGpuEngine2dReg.DstPitch); int DstBlkDim = ReadRegister(NvGpuEngine2dReg.DstBlockDimensions); TextureSwizzle SrcSwizzle = SrcLinear ? TextureSwizzle.Pitch : TextureSwizzle.BlockLinear; TextureSwizzle DstSwizzle = DstLinear ? TextureSwizzle.Pitch : TextureSwizzle.BlockLinear; int SrcBlockHeight = 1 << ((SrcBlkDim >> 4) & 0xf); int DstBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf); long SrcAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress); long DstAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.DstAddress); long SrcKey = Vmm.GetPhysicalAddress(SrcAddress); long DstKey = Vmm.GetPhysicalAddress(DstAddress); bool IsSrcFb = Gpu.Engine3d.IsFrameBufferPosition(SrcKey); bool IsDstFb = Gpu.Engine3d.IsFrameBufferPosition(DstKey); TextureInfo SrcTexture() { return(new TextureInfo( SrcAddress, SrcWidth, SrcHeight, SrcPitch, SrcBlockHeight, 1, SrcSwizzle, GalTextureFormat.A8B8G8R8)); } TextureInfo DstTexture() { return(new TextureInfo( DstAddress, DstWidth, DstHeight, DstPitch, DstBlockHeight, 1, DstSwizzle, GalTextureFormat.A8B8G8R8)); } //TODO: fb -> fb copies, tex -> fb copies, formats other than RGBA8, //make it throw for unimpl stuff (like the copy mode)... if (IsSrcFb && IsDstFb) { //Frame Buffer -> Frame Buffer copy. Gpu.Renderer.FrameBuffer.Copy( SrcKey, DstKey, 0, 0, SrcWidth, SrcHeight, 0, 0, DstWidth, DstHeight); } if (IsSrcFb) { //Frame Buffer -> Texture copy. Gpu.Renderer.FrameBuffer.GetBufferData(SrcKey, (byte[] Buffer) => { TextureInfo Src = SrcTexture(); TextureInfo Dst = DstTexture(); if (Src.Width != Dst.Width || Src.Height != Dst.Height) { throw new NotImplementedException("Texture resizing is not supported"); } TextureWriter.Write(Vmm, Dst, Buffer); }); } else if (IsDstFb) { //Texture -> Frame Buffer copy. const GalTextureFormat Format = GalTextureFormat.A8B8G8R8; byte[] Buffer = TextureReader.Read(Vmm, SrcTexture()); Gpu.Renderer.FrameBuffer.SetBufferData( DstKey, DstWidth, DstHeight, Format, Buffer); } else { //Texture -> Texture copy. TextureInfo Src = SrcTexture(); TextureInfo Dst = DstTexture(); if (Src.Width != Dst.Width || Src.Height != Dst.Height) { throw new NotImplementedException("Texture resizing is not supported"); } TextureWriter.Write(Vmm, Dst, TextureReader.Read(Vmm, Src)); } }
public static GalImage MakeTexture(NvGpuVmm vmm, long ticPosition) { int[] tic = ReadWords(vmm, ticPosition, 8); GalImageFormat format = GetImageFormat(tic); 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); TextureSwizzle swizzle = (TextureSwizzle)((tic[2] >> 21) & 7); int maxMipmapLevel = (tic[3] >> 28) & 0xF + 1; GalMemoryLayout layout; if (swizzle == TextureSwizzle.BlockLinear || swizzle == TextureSwizzle.BlockLinearColorKey) { layout = GalMemoryLayout.BlockLinear; } else { layout = GalMemoryLayout.Pitch; } 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 width = ((tic[4] >> 0) & 0xffff) + 1; int height = ((tic[5] >> 0) & 0xffff) + 1; int depth = ((tic[5] >> 16) & 0x3fff) + 1; int layoutCount = 1; // TODO: check this if (ImageUtils.IsArray(textureTarget)) { layoutCount = depth; depth = 1; } if (textureTarget == GalTextureTarget.OneD) { height = 1; } if (textureTarget == GalTextureTarget.TwoD || textureTarget == GalTextureTarget.OneD) { depth = 1; } else if (textureTarget == GalTextureTarget.CubeMap) { // FIXME: This is a bit hacky but I guess it's fine for now layoutCount = 6; depth = 1; } else if (textureTarget == GalTextureTarget.CubeArray) { // FIXME: This is a really really hacky but I guess it's fine for now layoutCount *= 6; depth = 1; } GalImage image = new GalImage( width, height, depth, layoutCount, tileWidth, gobBlockHeight, gobBlockDepth, layout, format, textureTarget, maxMipmapLevel, xSource, ySource, zSource, wSource); if (layout == GalMemoryLayout.Pitch) { image.Pitch = (tic[3] & 0xffff) << 5; } return(image); }