private static ImageDescriptor GetImageDescriptor(GalImageFormat Format)
        {
            GalImageFormat PixelFormat = Format & GalImageFormat.FormatMask;

            if (s_ImageTable.TryGetValue(PixelFormat, out ImageDescriptor Descriptor))
            {
                return(Descriptor);
            }

            throw new NotImplementedException($"Format \"{PixelFormat}\" not implemented!");
        }
Beispiel #2
0
        public static bool HasStencil(GalImageFormat Format)
        {
            switch (Format)
            {
            case GalImageFormat.D24_UNORM_S8_UINT:
            case GalImageFormat.D32_SFLOAT_S8_UINT:
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        public static bool HasDepth(GalImageFormat Format)
        {
            switch (Format)
            {
            case GalImageFormat.D24_UNORM_S8_UINT:
            case GalImageFormat.D32_SFLOAT:
            case GalImageFormat.D16_UNORM:
                return(true);
            }

            //Depth formats are fewer than colors, so it's harder to miss one
            //Instead of checking for individual formats, return false
            return(false);
        }
Beispiel #5
0
        private void SetFrameBuffer(NvGpuVmm vmm, int fbIndex)
        {
            long va = MakeInt64From2xInt32(NvGpuEngine3dReg.FrameBufferNAddress + fbIndex * 0x10);

            int surfFormat = ReadRegister(NvGpuEngine3dReg.FrameBufferNFormat + fbIndex * 0x10);

            if (va == 0 || surfFormat == 0)
            {
                _gpu.Renderer.RenderTarget.UnbindColor(fbIndex);

                return;
            }

            long key = vmm.GetPhysicalAddress(va);

            int width  = ReadRegister(NvGpuEngine3dReg.FrameBufferNWidth + fbIndex * 0x10);
            int height = ReadRegister(NvGpuEngine3dReg.FrameBufferNHeight + fbIndex * 0x10);

            int arrayMode   = ReadRegister(NvGpuEngine3dReg.FrameBufferNArrayMode + fbIndex * 0x10);
            int layerCount  = arrayMode & 0xFFFF;
            int layerStride = ReadRegister(NvGpuEngine3dReg.FrameBufferNLayerStride + fbIndex * 0x10);
            int baseLayer   = ReadRegister(NvGpuEngine3dReg.FrameBufferNBaseLayer + fbIndex * 0x10);
            int blockDim    = ReadRegister(NvGpuEngine3dReg.FrameBufferNBlockDim + fbIndex * 0x10);

            int gobBlockHeight = 1 << ((blockDim >> 4) & 7);

            GalMemoryLayout layout = (GalMemoryLayout)((blockDim >> 12) & 1);

            float tx = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateX + fbIndex * 8);
            float ty = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateY + fbIndex * 8);

            float sx = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleX + fbIndex * 8);
            float sy = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleY + fbIndex * 8);

            _viewportX0 = (int)MathF.Max(0, tx - MathF.Abs(sx));
            _viewportY0 = (int)MathF.Max(0, ty - MathF.Abs(sy));

            _viewportX1 = (int)(tx + MathF.Abs(sx));
            _viewportY1 = (int)(ty + MathF.Abs(sy));

            GalImageFormat format = ImageUtils.ConvertSurface((GalSurfaceFormat)surfFormat);

            GalImage image = new GalImage(width, height, 1, 1, 1, gobBlockHeight, 1, layout, format, GalTextureTarget.TwoD);

            _gpu.ResourceManager.SendColorBuffer(vmm, key, fbIndex, image);

            _gpu.Renderer.RenderTarget.SetViewport(fbIndex, _viewportX0, _viewportY0, _viewportX1 - _viewportX0, _viewportY1 - _viewportY0);
        }
Beispiel #6
0
        public void Create(long Key, int Size, GalImage Image)
        {
            int Handle = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, Handle);

            const int Level  = 0; //TODO: Support mipmap textures.
            const int Border = 0;

            TextureCache.AddOrUpdate(Key, new ImageHandler(Handle, Image), (uint)Size);

            GalImageFormat TypeLess = Image.Format & GalImageFormat.FormatMask;

            bool IsASTC = TypeLess >= GalImageFormat.ASTC_BEGIN && TypeLess <= GalImageFormat.ASTC_END;

            if (ImageUtils.IsCompressed(Image.Format) && !IsASTC)
            {
                InternalFormat InternalFmt = OGLEnumConverter.GetCompressedImageFormat(Image.Format);

                GL.CompressedTexImage2D(
                    TextureTarget.Texture2D,
                    Level,
                    InternalFmt,
                    Image.Width,
                    Image.Height,
                    Border,
                    Size,
                    IntPtr.Zero);
            }
            else
            {
                (PixelInternalFormat InternalFmt,
                 PixelFormat Format,
                 PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format);

                GL.TexImage2D(
                    TextureTarget.Texture2D,
                    Level,
                    InternalFmt,
                    Image.Width,
                    Image.Height,
                    Border,
                    Format,
                    Type,
                    IntPtr.Zero);
            }
        }
Beispiel #7
0
 public GalImage(
     int Width,
     int Height,
     GalImageFormat Format,
     GalTextureSource XSource = GalTextureSource.Red,
     GalTextureSource YSource = GalTextureSource.Green,
     GalTextureSource ZSource = GalTextureSource.Blue,
     GalTextureSource WSource = GalTextureSource.Alpha)
 {
     this.Width   = Width;
     this.Height  = Height;
     this.Format  = Format;
     this.XSource = XSource;
     this.YSource = YSource;
     this.ZSource = ZSource;
     this.WSource = WSource;
 }
Beispiel #8
0
        private void SetFrameBuffer(NvGpuVmm Vmm, int FbIndex)
        {
            long VA = MakeInt64From2xInt32(NvGpuEngine3dReg.FrameBufferNAddress + FbIndex * 0x10);

            int SurfFormat = ReadRegister(NvGpuEngine3dReg.FrameBufferNFormat + FbIndex * 0x10);

            if (VA == 0 || SurfFormat == 0)
            {
                Gpu.Renderer.RenderTarget.UnbindColor(FbIndex);

                return;
            }

            long Key = Vmm.GetPhysicalAddress(VA);

            int Width  = ReadRegister(NvGpuEngine3dReg.FrameBufferNWidth + FbIndex * 0x10);
            int Height = ReadRegister(NvGpuEngine3dReg.FrameBufferNHeight + FbIndex * 0x10);

            int BlockDim = ReadRegister(NvGpuEngine3dReg.FrameBufferNBlockDim + FbIndex * 0x10);

            int GobBlockHeight = 1 << ((BlockDim >> 4) & 7);

            GalMemoryLayout Layout = (GalMemoryLayout)((BlockDim >> 12) & 1);

            float TX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateX + FbIndex * 8);
            float TY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateY + FbIndex * 8);

            float SX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleX + FbIndex * 8);
            float SY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleY + FbIndex * 8);

            int VpX = (int)MathF.Max(0, TX - MathF.Abs(SX));
            int VpY = (int)MathF.Max(0, TY - MathF.Abs(SY));

            int VpW = (int)(TX + MathF.Abs(SX)) - VpX;
            int VpH = (int)(TY + MathF.Abs(SY)) - VpY;

            GalImageFormat Format = ImageUtils.ConvertSurface((GalSurfaceFormat)SurfFormat);

            GalImage Image = new GalImage(Width, Height, 1, GobBlockHeight, Layout, Format);

            Gpu.ResourceManager.SendColorBuffer(Vmm, Key, FbIndex, Image);

            ViewportHeight = VpH;

            Gpu.Renderer.RenderTarget.SetViewport(FbIndex, VpX, VpY, VpW, VpH);
        }
Beispiel #9
0
        private static bool IsCompressedTextureFormat(GalImageFormat Format)
        {
            switch (Format)
            {
            case GalImageFormat.BC6H_UFLOAT_BLOCK:
            case GalImageFormat.BC6H_SFLOAT_BLOCK:
            case GalImageFormat.BC7_UNORM_BLOCK:
            case GalImageFormat.BC1_RGBA_UNORM_BLOCK:
            case GalImageFormat.BC2_UNORM_BLOCK:
            case GalImageFormat.BC3_UNORM_BLOCK:
            case GalImageFormat.BC4_SNORM_BLOCK:
            case GalImageFormat.BC4_UNORM_BLOCK:
            case GalImageFormat.BC5_SNORM_BLOCK:
            case GalImageFormat.BC5_UNORM_BLOCK:
                return(true);
            }

            return(false);
        }
Beispiel #10
0
        private void SetFrameBuffer(NvGpuVmm Vmm, int FbIndex)
        {
            long VA = MakeInt64From2xInt32(NvGpuEngine3dReg.FrameBufferNAddress + FbIndex * 0x10);

            int Format = ReadRegister(NvGpuEngine3dReg.FrameBufferNFormat + FbIndex * 0x10);

            if (VA == 0 || Format == 0)
            {
                Gpu.Renderer.FrameBuffer.UnbindColor(FbIndex);

                return;
            }

            long Key = Vmm.GetPhysicalAddress(VA);

            FrameBuffers.Add(Key);

            int Width  = ReadRegister(NvGpuEngine3dReg.FrameBufferNWidth + FbIndex * 0x10);
            int Height = ReadRegister(NvGpuEngine3dReg.FrameBufferNHeight + FbIndex * 0x10);

            float TX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateX + FbIndex * 8);
            float TY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateY + FbIndex * 8);

            float SX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleX + FbIndex * 8);
            float SY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleY + FbIndex * 8);

            int VpX = (int)MathF.Max(0, TX - MathF.Abs(SX));
            int VpY = (int)MathF.Max(0, TY - MathF.Abs(SY));

            int VpW = (int)(TX + MathF.Abs(SX)) - VpX;
            int VpH = (int)(TY + MathF.Abs(SY)) - VpY;

            GalImageFormat ImageFormat = ImageFormatConverter.ConvertFrameBuffer((GalFrameBufferFormat)Format);

            GalImage Image = new GalImage(Width, Height, ImageFormat);

            long Size = TextureHelper.GetTextureSize(Image);

            Gpu.Renderer.Texture.CreateFb(Key, Size, Image);
            Gpu.Renderer.FrameBuffer.BindColor(Key, FbIndex);

            Gpu.Renderer.FrameBuffer.SetViewport(VpX, VpY, VpW, VpH);
        }
Beispiel #11
0
        private void SetZeta(NvGpuVmm vmm)
        {
            Profile.Begin(Profiles.GPU.Engine3d.SetZeta);

            long va = MakeInt64From2xInt32(NvGpuEngine3dReg.ZetaAddress);

            int zetaFormat = ReadRegister(NvGpuEngine3dReg.ZetaFormat);

            int blockDim = ReadRegister(NvGpuEngine3dReg.ZetaBlockDimensions);

            int gobBlockHeight = 1 << ((blockDim >> 4) & 7);

            GalMemoryLayout layout = (GalMemoryLayout)((blockDim >> 12) & 1); //?

            bool zetaEnable = ReadRegisterBool(NvGpuEngine3dReg.ZetaEnable);

            if (va == 0 || zetaFormat == 0 || !zetaEnable)
            {
                _gpu.Renderer.RenderTarget.UnbindZeta();

                Profile.End(Profiles.GPU.Engine3d.SetZeta);

                return;
            }

            long key = vmm.GetPhysicalAddress(va);

            int width  = ReadRegister(NvGpuEngine3dReg.ZetaHoriz);
            int height = ReadRegister(NvGpuEngine3dReg.ZetaVert);

            GalImageFormat format = ImageUtils.ConvertZeta((GalZetaFormat)zetaFormat);

            // TODO: Support non 2D?
            GalImage image = new GalImage(width, height, 1, 1, 1, gobBlockHeight, 1, layout, format, GalTextureTarget.TwoD);

            _gpu.ResourceManager.SendZetaBuffer(vmm, key, image);

            Profile.End(Profiles.GPU.Engine3d.SetZeta);
        }
Beispiel #12
0
 public static bool HasDepth(GalImageFormat Format)
 {
     return((GetImageDescriptor(Format).Target & TargetBuffer.Depth) != 0);
 }
Beispiel #13
0
 public static bool HasStencil(GalImageFormat Format)
 {
     return((GetImageDescriptor(Format).Target & TargetBuffer.Stencil) != 0);
 }
Beispiel #14
0
 public static int GetBytesPerPixel(GalImageFormat Format)
 {
     return(GetImageDescriptor(Format).BytesPerPixel);
 }
Beispiel #15
0
 public static bool HasColor(GalImageFormat Format)
 {
     return((GetImageDescriptor(Format).Target & TargetBuffer.Color) != 0);
 }
Beispiel #16
0
 public static int GetBlockWidth(GalImageFormat Format)
 {
     return(GetImageDescriptor(Format).BlockWidth);
 }
Beispiel #17
0
 public static int GetBlockHeight(GalImageFormat Format)
 {
     return(GetImageDescriptor(Format).BlockHeight);
 }
Beispiel #18
0
        public static (PixelInternalFormat, PixelFormat, PixelType) GetImageFormat(GalImageFormat Format)
        {
            switch (Format)
            {
            case GalImageFormat.R32G32B32A32_SFLOAT:      return(PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float);

            case GalImageFormat.R32G32B32A32_SINT:        return(PixelInternalFormat.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int);

            case GalImageFormat.R32G32B32A32_UINT:        return(PixelInternalFormat.Rgba32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt);

            case GalImageFormat.R16G16B16A16_SFLOAT:      return(PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat);

            case GalImageFormat.R16G16B16A16_SINT:        return(PixelInternalFormat.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short);

            case GalImageFormat.R16G16B16A16_UINT:        return(PixelInternalFormat.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort);

            case GalImageFormat.A8B8G8R8_SNORM_PACK32:    return(PixelInternalFormat.Rgba8Snorm, PixelFormat.Rgba, PixelType.Byte);

            case GalImageFormat.A8B8G8R8_UNORM_PACK32:    return(PixelInternalFormat.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte);

            case GalImageFormat.A8B8G8R8_SINT_PACK32:     return(PixelInternalFormat.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte);

            case GalImageFormat.A8B8G8R8_UINT_PACK32:     return(PixelInternalFormat.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte);

            case GalImageFormat.A8B8G8R8_SRGB_PACK32:     return(PixelInternalFormat.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte);

            case GalImageFormat.A2B10G10R10_UINT_PACK32:  return(PixelInternalFormat.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed);

            case GalImageFormat.A2B10G10R10_UNORM_PACK32: return(PixelInternalFormat.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Reversed);

            case GalImageFormat.R32_SFLOAT:               return(PixelInternalFormat.R32f, PixelFormat.Red, PixelType.Float);

            case GalImageFormat.R32_SINT:                 return(PixelInternalFormat.R32i, PixelFormat.Red, PixelType.Int);

            case GalImageFormat.R32_UINT:                 return(PixelInternalFormat.R32ui, PixelFormat.Red, PixelType.UnsignedInt);

            case GalImageFormat.A1R5G5B5_UNORM_PACK16:    return(PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort5551);

            case GalImageFormat.B5G6R5_UNORM_PACK16:      return(PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565);

            case GalImageFormat.R16G16_SFLOAT:            return(PixelInternalFormat.Rg16f, PixelFormat.Rg, PixelType.HalfFloat);

            case GalImageFormat.R16G16_SINT:              return(PixelInternalFormat.Rg16i, PixelFormat.RgInteger, PixelType.Short);

            case GalImageFormat.R16G16_SNORM:             return(PixelInternalFormat.Rg16Snorm, PixelFormat.Rg, PixelType.Byte);

            case GalImageFormat.R16G16_UNORM:             return(PixelInternalFormat.Rg16, PixelFormat.Rg, PixelType.UnsignedShort);

            case GalImageFormat.R8G8_SINT:                return(PixelInternalFormat.Rg8i, PixelFormat.RgInteger, PixelType.Byte);

            case GalImageFormat.R8G8_SNORM:               return(PixelInternalFormat.Rg8Snorm, PixelFormat.Rg, PixelType.Byte);

            case GalImageFormat.R8G8_UINT:                return(PixelInternalFormat.Rg8ui, PixelFormat.RgInteger, PixelType.UnsignedByte);

            case GalImageFormat.R8G8_UNORM:               return(PixelInternalFormat.Rg8, PixelFormat.Rg, PixelType.UnsignedByte);

            case GalImageFormat.R16_SFLOAT:               return(PixelInternalFormat.R16f, PixelFormat.Red, PixelType.HalfFloat);

            case GalImageFormat.R16_SINT:                 return(PixelInternalFormat.R16i, PixelFormat.RedInteger, PixelType.Short);

            case GalImageFormat.R16_SNORM:                return(PixelInternalFormat.R16Snorm, PixelFormat.Red, PixelType.Byte);

            case GalImageFormat.R16_UINT:                 return(PixelInternalFormat.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort);

            case GalImageFormat.R16_UNORM:                return(PixelInternalFormat.R16, PixelFormat.Red, PixelType.UnsignedShort);

            case GalImageFormat.R8_SINT:                  return(PixelInternalFormat.R8i, PixelFormat.RedInteger, PixelType.Byte);

            case GalImageFormat.R8_SNORM:                 return(PixelInternalFormat.R8Snorm, PixelFormat.Red, PixelType.Byte);

            case GalImageFormat.R8_UINT:                  return(PixelInternalFormat.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte);

            case GalImageFormat.R8_UNORM:                 return(PixelInternalFormat.R8, PixelFormat.Red, PixelType.UnsignedByte);

            case GalImageFormat.B10G11R11_UFLOAT_PACK32:  return(PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.UnsignedInt10F11F11FRev);

            case GalImageFormat.R4G4B4A4_UNORM_PACK16_REVERSED: return(PixelInternalFormat.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Reversed);

            case GalImageFormat.D24_UNORM_S8_UINT: return(PixelInternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248);

            case GalImageFormat.D32_SFLOAT:        return(PixelInternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float);

            case GalImageFormat.D16_UNORM:         return(PixelInternalFormat.DepthComponent16, PixelFormat.DepthComponent, PixelType.UnsignedShort);
            }

            throw new NotImplementedException(Format.ToString());
        }
Beispiel #19
0
        private void TextureCopy(NvGpuVmm vmm)
        {
            CopyOperation operation = (CopyOperation)ReadRegister(NvGpuEngine2dReg.CopyOperation);

            int  dstFormat = ReadRegister(NvGpuEngine2dReg.DstFormat);
            bool dstLinear = ReadRegister(NvGpuEngine2dReg.DstLinear) != 0;
            int  dstWidth  = ReadRegister(NvGpuEngine2dReg.DstWidth);
            int  dstHeight = ReadRegister(NvGpuEngine2dReg.DstHeight);
            int  dstDepth  = ReadRegister(NvGpuEngine2dReg.DstDepth);
            int  dstLayer  = ReadRegister(NvGpuEngine2dReg.DstLayer);
            int  dstPitch  = ReadRegister(NvGpuEngine2dReg.DstPitch);
            int  dstBlkDim = ReadRegister(NvGpuEngine2dReg.DstBlockDimensions);

            int  srcFormat = ReadRegister(NvGpuEngine2dReg.SrcFormat);
            bool srcLinear = ReadRegister(NvGpuEngine2dReg.SrcLinear) != 0;
            int  srcWidth  = ReadRegister(NvGpuEngine2dReg.SrcWidth);
            int  srcHeight = ReadRegister(NvGpuEngine2dReg.SrcHeight);
            int  srcDepth  = ReadRegister(NvGpuEngine2dReg.SrcDepth);
            int  srcLayer  = ReadRegister(NvGpuEngine2dReg.SrcLayer);
            int  srcPitch  = ReadRegister(NvGpuEngine2dReg.SrcPitch);
            int  srcBlkDim = ReadRegister(NvGpuEngine2dReg.SrcBlockDimensions);

            int dstBlitX = ReadRegister(NvGpuEngine2dReg.BlitDstX);
            int dstBlitY = ReadRegister(NvGpuEngine2dReg.BlitDstY);
            int dstBlitW = ReadRegister(NvGpuEngine2dReg.BlitDstW);
            int dstBlitH = ReadRegister(NvGpuEngine2dReg.BlitDstH);

            long blitDuDx = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitDuDxFract);
            long blitDvDy = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitDvDyFract);

            long srcBlitX = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitSrcXFract);
            long srcBlitY = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitSrcYFract);

            GalImageFormat srcImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)srcFormat);
            GalImageFormat dstImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)dstFormat);

            GalMemoryLayout srcLayout = GetLayout(srcLinear);
            GalMemoryLayout dstLayout = GetLayout(dstLinear);

            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 isSrcLayered = false;
            bool isDstLayered = false;

            GalTextureTarget srcTarget = GalTextureTarget.TwoD;

            if (srcDepth != 0)
            {
                srcTarget = GalTextureTarget.TwoDArray;
                srcDepth++;
                isSrcLayered = true;
            }
            else
            {
                srcDepth = 1;
            }

            GalTextureTarget dstTarget = GalTextureTarget.TwoD;

            if (dstDepth != 0)
            {
                dstTarget = GalTextureTarget.TwoDArray;
                dstDepth++;
                isDstLayered = true;
            }
            else
            {
                dstDepth = 1;
            }

            GalImage srcTexture = new GalImage(
                srcWidth,
                srcHeight,
                1, srcDepth, 1,
                srcBlockHeight, 1,
                srcLayout,
                srcImgFormat,
                srcTarget);

            GalImage dstTexture = new GalImage(
                dstWidth,
                dstHeight,
                1, dstDepth, 1,
                dstBlockHeight, 1,
                dstLayout,
                dstImgFormat,
                dstTarget);

            srcTexture.Pitch = srcPitch;
            dstTexture.Pitch = dstPitch;

            long GetLayerOffset(GalImage image, int layer)
            {
                int targetMipLevel = image.MaxMipmapLevel <= 1 ? 1 : image.MaxMipmapLevel - 1;

                return(ImageUtils.GetLayerOffset(image, targetMipLevel) * layer);
            }

            int srcLayerIndex = -1;

            if (isSrcLayered && _gpu.ResourceManager.TryGetTextureLayer(srcKey, out srcLayerIndex) && srcLayerIndex != 0)
            {
                srcKey = srcKey - GetLayerOffset(srcTexture, srcLayerIndex);
            }

            int dstLayerIndex = -1;

            if (isDstLayered && _gpu.ResourceManager.TryGetTextureLayer(dstKey, out dstLayerIndex) && dstLayerIndex != 0)
            {
                dstKey = dstKey - GetLayerOffset(dstTexture, dstLayerIndex);
            }

            _gpu.ResourceManager.SendTexture(vmm, srcKey, srcTexture);
            _gpu.ResourceManager.SendTexture(vmm, dstKey, dstTexture);

            if (isSrcLayered && srcLayerIndex == -1)
            {
                for (int layer = 0; layer < srcTexture.LayerCount; layer++)
                {
                    _gpu.ResourceManager.SetTextureArrayLayer(srcKey + GetLayerOffset(srcTexture, layer), layer);
                }

                srcLayerIndex = 0;
            }

            if (isDstLayered && dstLayerIndex == -1)
            {
                for (int layer = 0; layer < dstTexture.LayerCount; layer++)
                {
                    _gpu.ResourceManager.SetTextureArrayLayer(dstKey + GetLayerOffset(dstTexture, layer), layer);
                }

                dstLayerIndex = 0;
            }

            int srcBlitX1 = (int)(srcBlitX >> 32);
            int srcBlitY1 = (int)(srcBlitY >> 32);

            int srcBlitX2 = (int)(srcBlitX + dstBlitW * blitDuDx >> 32);
            int srcBlitY2 = (int)(srcBlitY + dstBlitH * blitDvDy >> 32);

            _gpu.Renderer.RenderTarget.Copy(
                srcTexture,
                dstTexture,
                srcKey,
                dstKey,
                srcLayerIndex,
                dstLayerIndex,
                srcBlitX1,
                srcBlitY1,
                srcBlitX2,
                srcBlitY2,
                dstBlitX,
                dstBlitY,
                dstBlitX + dstBlitW,
                dstBlitY + dstBlitH);

            //Do a guest side copy aswell. This is necessary when
            //the texture is modified by the guest, however it doesn't
            //work when resources that the gpu can write to are copied,
            //like framebuffers.

            // FIXME: SUPPORT MULTILAYER CORRECTLY HERE (this will cause weird stuffs on the first layer)
            ImageUtils.CopyTexture(
                vmm,
                srcTexture,
                dstTexture,
                srcAddress,
                dstAddress,
                srcBlitX1,
                srcBlitY1,
                dstBlitX,
                dstBlitY,
                dstBlitW,
                dstBlitH);

            vmm.IsRegionModified(dstKey, ImageUtils.GetSize(dstTexture), NvGpuBufferType.Texture);
        }
Beispiel #20
0
        public static int GetPitch(GalImageFormat Format, int Width)
        {
            ImageDescriptor Desc = GetImageDescriptor(Format);

            return(Desc.BytesPerPixel * DivRoundUp(Width, Desc.BlockWidth));
        }
Beispiel #21
0
        public static bool HasColor(GalImageFormat Format)
        {
            switch (Format)
            {
            case GalImageFormat.R32G32B32A32_SFLOAT:
            case GalImageFormat.R32G32B32A32_SINT:
            case GalImageFormat.R32G32B32A32_UINT:
            case GalImageFormat.R16G16B16A16_SFLOAT:
            case GalImageFormat.R16G16B16A16_SINT:
            case GalImageFormat.R16G16B16A16_UINT:
            case GalImageFormat.A8B8G8R8_SNORM_PACK32:
            case GalImageFormat.A8B8G8R8_UNORM_PACK32:
            case GalImageFormat.A8B8G8R8_SINT_PACK32:
            case GalImageFormat.A8B8G8R8_UINT_PACK32:
            case GalImageFormat.A2B10G10R10_SINT_PACK32:
            case GalImageFormat.A2B10G10R10_SNORM_PACK32:
            case GalImageFormat.A2B10G10R10_UINT_PACK32:
            case GalImageFormat.A2B10G10R10_UNORM_PACK32:
            case GalImageFormat.R32_SFLOAT:
            case GalImageFormat.R32_SINT:
            case GalImageFormat.R32_UINT:
            case GalImageFormat.BC6H_SFLOAT_BLOCK:
            case GalImageFormat.BC6H_UFLOAT_BLOCK:
            case GalImageFormat.A1R5G5B5_UNORM_PACK16:
            case GalImageFormat.B5G6R5_UNORM_PACK16:
            case GalImageFormat.BC7_UNORM_BLOCK:
            case GalImageFormat.R16G16_SFLOAT:
            case GalImageFormat.R16G16_SINT:
            case GalImageFormat.R16G16_SNORM:
            case GalImageFormat.R16G16_UNORM:
            case GalImageFormat.R8G8_SINT:
            case GalImageFormat.R8G8_SNORM:
            case GalImageFormat.R8G8_UINT:
            case GalImageFormat.R8G8_UNORM:
            case GalImageFormat.R16_SFLOAT:
            case GalImageFormat.R16_SINT:
            case GalImageFormat.R16_SNORM:
            case GalImageFormat.R16_UINT:
            case GalImageFormat.R16_UNORM:
            case GalImageFormat.R8_SINT:
            case GalImageFormat.R8_SNORM:
            case GalImageFormat.R8_UINT:
            case GalImageFormat.R8_UNORM:
            case GalImageFormat.B10G11R11_UFLOAT_PACK32:
            case GalImageFormat.BC1_RGBA_UNORM_BLOCK:
            case GalImageFormat.BC2_UNORM_BLOCK:
            case GalImageFormat.BC3_UNORM_BLOCK:
            case GalImageFormat.BC4_UNORM_BLOCK:
            case GalImageFormat.BC5_UNORM_BLOCK:
            case GalImageFormat.ASTC_4x4_UNORM_BLOCK:
            case GalImageFormat.ASTC_5x5_UNORM_BLOCK:
            case GalImageFormat.ASTC_6x6_UNORM_BLOCK:
            case GalImageFormat.ASTC_8x8_UNORM_BLOCK:
            case GalImageFormat.ASTC_10x10_UNORM_BLOCK:
            case GalImageFormat.ASTC_12x12_UNORM_BLOCK:
            case GalImageFormat.ASTC_5x4_UNORM_BLOCK:
            case GalImageFormat.ASTC_6x5_UNORM_BLOCK:
            case GalImageFormat.ASTC_8x6_UNORM_BLOCK:
            case GalImageFormat.ASTC_10x8_UNORM_BLOCK:
            case GalImageFormat.ASTC_12x10_UNORM_BLOCK:
            case GalImageFormat.ASTC_8x5_UNORM_BLOCK:
            case GalImageFormat.ASTC_10x5_UNORM_BLOCK:
            case GalImageFormat.ASTC_10x6_UNORM_BLOCK:
            case GalImageFormat.R4G4B4A4_UNORM_PACK16_REVERSED:
                return(true);

            case GalImageFormat.D24_UNORM_S8_UINT:
            case GalImageFormat.D32_SFLOAT:
            case GalImageFormat.D16_UNORM:
                return(true);
            }

            throw new NotImplementedException(Format.ToString());
        }
Beispiel #22
0
        public static bool IsCompressed(GalImageFormat Format)
        {
            ImageDescriptor Desc = GetImageDescriptor(Format);

            return((Desc.BlockWidth | Desc.BlockHeight) != 1);
        }
Beispiel #23
0
        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);
        }
Beispiel #24
0
        private void TextureCopy(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
        {
            CopyOperation Operation = (CopyOperation)ReadRegister(NvGpuEngine2dReg.CopyOperation);

            int  SrcFormat = ReadRegister(NvGpuEngine2dReg.SrcFormat);
            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);

            int  DstFormat = ReadRegister(NvGpuEngine2dReg.DstFormat);
            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);

            GalImageFormat SrcImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)SrcFormat);
            GalImageFormat DstImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)DstFormat);

            GalMemoryLayout SrcLayout = GetLayout(SrcLinear);
            GalMemoryLayout DstLayout = GetLayout(DstLinear);

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

            GalImage SrcTexture = new GalImage(
                SrcWidth,
                SrcHeight, 1,
                SrcBlockHeight,
                SrcLayout,
                SrcImgFormat);

            GalImage DstTexture = new GalImage(
                DstWidth,
                DstHeight, 1,
                DstBlockHeight,
                DstLayout,
                DstImgFormat);

            Gpu.ResourceManager.SendTexture(Vmm, SrcKey, SrcTexture);
            Gpu.ResourceManager.SendTexture(Vmm, DstKey, DstTexture);

            Gpu.Renderer.RenderTarget.Copy(
                SrcKey,
                DstKey,
                0,
                0,
                SrcWidth,
                SrcHeight,
                0,
                0,
                DstWidth,
                DstHeight);
        }
Beispiel #25
0
        private void TextureCopy(NvGpuVmm Vmm)
        {
            CopyOperation Operation = (CopyOperation)ReadRegister(NvGpuEngine2dReg.CopyOperation);

            int  DstFormat = ReadRegister(NvGpuEngine2dReg.DstFormat);
            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);

            int  SrcFormat = ReadRegister(NvGpuEngine2dReg.SrcFormat);
            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);

            int DstBlitX = ReadRegister(NvGpuEngine2dReg.BlitDstX);
            int DstBlitY = ReadRegister(NvGpuEngine2dReg.BlitDstY);
            int DstBlitW = ReadRegister(NvGpuEngine2dReg.BlitDstW);
            int DstBlitH = ReadRegister(NvGpuEngine2dReg.BlitDstH);

            long BlitDuDx = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitDuDxFract);
            long BlitDvDy = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitDvDyFract);

            long SrcBlitX = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitSrcXFract);
            long SrcBlitY = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitSrcYFract);

            GalImageFormat SrcImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)SrcFormat);
            GalImageFormat DstImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)DstFormat);

            GalMemoryLayout SrcLayout = GetLayout(SrcLinear);
            GalMemoryLayout DstLayout = GetLayout(DstLinear);

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

            GalImage SrcTexture = new GalImage(
                SrcWidth,
                SrcHeight, 1,
                SrcBlockHeight,
                SrcLayout,
                SrcImgFormat);

            GalImage DstTexture = new GalImage(
                DstWidth,
                DstHeight, 1,
                DstBlockHeight,
                DstLayout,
                DstImgFormat);

            SrcTexture.Pitch = SrcPitch;
            DstTexture.Pitch = DstPitch;

            Gpu.ResourceManager.SendTexture(Vmm, SrcKey, SrcTexture);
            Gpu.ResourceManager.SendTexture(Vmm, DstKey, DstTexture);

            int SrcBlitX1 = (int)(SrcBlitX >> 32);
            int SrcBlitY1 = (int)(SrcBlitY >> 32);

            int SrcBlitX2 = (int)(SrcBlitX + DstBlitW * BlitDuDx >> 32);
            int SrcBlitY2 = (int)(SrcBlitY + DstBlitH * BlitDvDy >> 32);

            Gpu.Renderer.RenderTarget.Copy(
                SrcKey,
                DstKey,
                SrcBlitX1,
                SrcBlitY1,
                SrcBlitX2,
                SrcBlitY2,
                DstBlitX,
                DstBlitY,
                DstBlitX + DstBlitW,
                DstBlitY + DstBlitH);

            //Do a guest side copy aswell. This is necessary when
            //the texture is modified by the guest, however it doesn't
            //work when resources that the gpu can write to are copied,
            //like framebuffers.
            ImageUtils.CopyTexture(
                Vmm,
                SrcTexture,
                DstTexture,
                SrcAddress,
                DstAddress,
                SrcBlitX1,
                SrcBlitY1,
                DstBlitX,
                DstBlitY,
                DstBlitW,
                DstBlitH);

            Vmm.IsRegionModified(DstKey, ImageUtils.GetSize(DstTexture), NvGpuBufferType.Texture);
        }
Beispiel #26
0
        public void Create(long Key, byte[] Data, GalImage Image)
        {
            int Handle = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, Handle);

            const int Level  = 0; //TODO: Support mipmap textures.
            const int Border = 0;

            TextureCache.AddOrUpdate(Key, new ImageHandler(Handle, Image), (uint)Data.Length);

            GalImageFormat TypeLess = Image.Format & GalImageFormat.FormatMask;

            bool IsASTC = TypeLess >= GalImageFormat.ASTC_BEGIN && TypeLess <= GalImageFormat.ASTC_END;

            if (ImageUtils.IsCompressed(Image.Format) && !IsASTC)
            {
                InternalFormat InternalFmt = OGLEnumConverter.GetCompressedImageFormat(Image.Format);

                GL.CompressedTexImage2D(
                    TextureTarget.Texture2D,
                    Level,
                    InternalFmt,
                    Image.Width,
                    Image.Height,
                    Border,
                    Data.Length,
                    Data);
            }
            else
            {
                //TODO: Use KHR_texture_compression_astc_hdr when available
                if (IsASTC)
                {
                    int TextureBlockWidth  = ImageUtils.GetBlockWidth(Image.Format);
                    int TextureBlockHeight = ImageUtils.GetBlockHeight(Image.Format);

                    Data = ASTCDecoder.DecodeToRGBA8888(
                        Data,
                        TextureBlockWidth,
                        TextureBlockHeight, 1,
                        Image.Width,
                        Image.Height, 1);

                    Image.Format = GalImageFormat.A8B8G8R8 | GalImageFormat.Unorm;
                }
                else if (TypeLess == GalImageFormat.G8R8)
                {
                    Data = ImageConverter.G8R8ToR8G8(
                        Data,
                        Image.Width,
                        Image.Height,
                        1);

                    Image.Format = GalImageFormat.R8G8 | (Image.Format & GalImageFormat.TypeMask);
                }

                (PixelInternalFormat InternalFmt,
                 PixelFormat Format,
                 PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format);

                GL.TexImage2D(
                    TextureTarget.Texture2D,
                    Level,
                    InternalFmt,
                    Image.Width,
                    Image.Height,
                    Border,
                    Format,
                    Type,
                    Data);
            }
        }
Beispiel #27
0
        public static (PixelInternalFormat, PixelFormat, PixelType) GetImageFormat(GalImageFormat format)
        {
            switch (format)
            {
            case GalImageFormat.Rgba32 | GalImageFormat.Float: return(PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float);

            case GalImageFormat.Rgba32 | GalImageFormat.Sint:  return(PixelInternalFormat.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int);

            case GalImageFormat.Rgba32 | GalImageFormat.Uint:  return(PixelInternalFormat.Rgba32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt);

            case GalImageFormat.Rgba16 | GalImageFormat.Float: return(PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat);

            case GalImageFormat.Rgba16 | GalImageFormat.Sint:  return(PixelInternalFormat.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short);

            case GalImageFormat.Rgba16 | GalImageFormat.Uint:  return(PixelInternalFormat.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort);

            case GalImageFormat.Rgba16 | GalImageFormat.Unorm: return(PixelInternalFormat.Rgba16, PixelFormat.Rgba, PixelType.UnsignedShort);

            case GalImageFormat.Rg32 | GalImageFormat.Float: return(PixelInternalFormat.Rg32f, PixelFormat.Rg, PixelType.Float);

            case GalImageFormat.Rg32 | GalImageFormat.Sint:  return(PixelInternalFormat.Rg32i, PixelFormat.RgInteger, PixelType.Int);

            case GalImageFormat.Rg32 | GalImageFormat.Uint:  return(PixelInternalFormat.Rg32ui, PixelFormat.RgInteger, PixelType.UnsignedInt);

            case GalImageFormat.Rgbx8 | GalImageFormat.Unorm: return(PixelInternalFormat.Rgb8, PixelFormat.Rgba, PixelType.UnsignedByte);

            case GalImageFormat.Rgba8 | GalImageFormat.Snorm: return(PixelInternalFormat.Rgba8Snorm, PixelFormat.Rgba, PixelType.Byte);

            case GalImageFormat.Rgba8 | GalImageFormat.Unorm: return(PixelInternalFormat.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte);

            case GalImageFormat.Rgba8 | GalImageFormat.Sint:  return(PixelInternalFormat.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte);

            case GalImageFormat.Rgba8 | GalImageFormat.Uint:  return(PixelInternalFormat.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte);

            case GalImageFormat.Rgba8 | GalImageFormat.Srgb:  return(PixelInternalFormat.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte);

            case GalImageFormat.Bgra8 | GalImageFormat.Unorm: return(PixelInternalFormat.Rgba8, PixelFormat.Bgra, PixelType.UnsignedByte);

            case GalImageFormat.Bgra8 | GalImageFormat.Srgb:  return(PixelInternalFormat.Srgb8Alpha8, PixelFormat.Bgra, PixelType.UnsignedByte);

            case GalImageFormat.Rgba4 | GalImageFormat.Unorm: return(PixelInternalFormat.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Reversed);

            case GalImageFormat.Rgb10A2 | GalImageFormat.Uint:  return(PixelInternalFormat.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed);

            case GalImageFormat.Rgb10A2 | GalImageFormat.Unorm: return(PixelInternalFormat.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Reversed);

            case GalImageFormat.R32 | GalImageFormat.Float: return(PixelInternalFormat.R32f, PixelFormat.Red, PixelType.Float);

            case GalImageFormat.R32 | GalImageFormat.Sint:  return(PixelInternalFormat.R32i, PixelFormat.Red, PixelType.Int);

            case GalImageFormat.R32 | GalImageFormat.Uint:  return(PixelInternalFormat.R32ui, PixelFormat.Red, PixelType.UnsignedInt);

            case GalImageFormat.Bgr5A1 | GalImageFormat.Unorm: return(PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort5551);

            case GalImageFormat.Rgb5A1 | GalImageFormat.Unorm: return(PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort1555Reversed);

            case GalImageFormat.Rgb565 | GalImageFormat.Unorm: return(PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565Reversed);

            case GalImageFormat.Bgr565 | GalImageFormat.Unorm: return(PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565);

            case GalImageFormat.Rg16 | GalImageFormat.Float: return(PixelInternalFormat.Rg16f, PixelFormat.Rg, PixelType.HalfFloat);

            case GalImageFormat.Rg16 | GalImageFormat.Sint:  return(PixelInternalFormat.Rg16i, PixelFormat.RgInteger, PixelType.Short);

            case GalImageFormat.Rg16 | GalImageFormat.Snorm: return(PixelInternalFormat.Rg16Snorm, PixelFormat.Rg, PixelType.Short);

            case GalImageFormat.Rg16 | GalImageFormat.Uint:  return(PixelInternalFormat.Rg16ui, PixelFormat.RgInteger, PixelType.UnsignedShort);

            case GalImageFormat.Rg16 | GalImageFormat.Unorm: return(PixelInternalFormat.Rg16, PixelFormat.Rg, PixelType.UnsignedShort);

            case GalImageFormat.Rg8 | GalImageFormat.Sint:  return(PixelInternalFormat.Rg8i, PixelFormat.RgInteger, PixelType.Byte);

            case GalImageFormat.Rg8 | GalImageFormat.Snorm: return(PixelInternalFormat.Rg8Snorm, PixelFormat.Rg, PixelType.Byte);

            case GalImageFormat.Rg8 | GalImageFormat.Uint:  return(PixelInternalFormat.Rg8ui, PixelFormat.RgInteger, PixelType.UnsignedByte);

            case GalImageFormat.Rg8 | GalImageFormat.Unorm: return(PixelInternalFormat.Rg8, PixelFormat.Rg, PixelType.UnsignedByte);

            case GalImageFormat.R16 | GalImageFormat.Float: return(PixelInternalFormat.R16f, PixelFormat.Red, PixelType.HalfFloat);

            case GalImageFormat.R16 | GalImageFormat.Sint:  return(PixelInternalFormat.R16i, PixelFormat.RedInteger, PixelType.Short);

            case GalImageFormat.R16 | GalImageFormat.Snorm: return(PixelInternalFormat.R16Snorm, PixelFormat.Red, PixelType.Short);

            case GalImageFormat.R16 | GalImageFormat.Uint:  return(PixelInternalFormat.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort);

            case GalImageFormat.R16 | GalImageFormat.Unorm: return(PixelInternalFormat.R16, PixelFormat.Red, PixelType.UnsignedShort);

            case GalImageFormat.R8 | GalImageFormat.Sint:  return(PixelInternalFormat.R8i, PixelFormat.RedInteger, PixelType.Byte);

            case GalImageFormat.R8 | GalImageFormat.Snorm: return(PixelInternalFormat.R8Snorm, PixelFormat.Red, PixelType.Byte);

            case GalImageFormat.R8 | GalImageFormat.Uint:  return(PixelInternalFormat.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte);

            case GalImageFormat.R8 | GalImageFormat.Unorm: return(PixelInternalFormat.R8, PixelFormat.Red, PixelType.UnsignedByte);

            case GalImageFormat.R11G11B10 | GalImageFormat.Float: return(PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.UnsignedInt10F11F11FRev);

            case GalImageFormat.D16 | GalImageFormat.Unorm: return(PixelInternalFormat.DepthComponent16, PixelFormat.DepthComponent, PixelType.UnsignedShort);

            case GalImageFormat.D24 | GalImageFormat.Unorm: return(PixelInternalFormat.DepthComponent24, PixelFormat.DepthComponent, PixelType.UnsignedInt);

            case GalImageFormat.D24S8 | GalImageFormat.Uint:  return(PixelInternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248);

            case GalImageFormat.D24S8 | GalImageFormat.Unorm: return(PixelInternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248);

            case GalImageFormat.D32 | GalImageFormat.Float: return(PixelInternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float);

            case GalImageFormat.D32S8 | GalImageFormat.Float: return(PixelInternalFormat.Depth32fStencil8, PixelFormat.DepthStencil, PixelType.Float32UnsignedInt248Rev);
            }

            throw new NotImplementedException($"{format & GalImageFormat.FormatMask} {format & GalImageFormat.TypeMask}");
        }
Beispiel #28
0
 public static int GetBlockDepth(GalImageFormat format)
 {
     return(GetImageDescriptor(format).BlockDepth);
 }
Beispiel #29
0
        private static bool IsAstc(GalImageFormat Format)
        {
            Format &= GalImageFormat.FormatMask;

            return(Format > GalImageFormat.Astc2DStart && Format < GalImageFormat.Astc2DEnd);
        }
Beispiel #30
0
        public static (PixelInternalFormat, PixelFormat, PixelType) GetImageFormat(GalImageFormat Format)
        {
            switch (Format)
            {
            case GalImageFormat.R32G32B32A32 | GalImageFormat.Sfloat: return(PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float);

            case GalImageFormat.R32G32B32A32 | GalImageFormat.Sint:   return(PixelInternalFormat.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int);

            case GalImageFormat.R32G32B32A32 | GalImageFormat.Uint:   return(PixelInternalFormat.Rgba32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt);

            case GalImageFormat.R16G16B16A16 | GalImageFormat.Sfloat: return(PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat);

            case GalImageFormat.R16G16B16A16 | GalImageFormat.Sint:   return(PixelInternalFormat.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short);

            case GalImageFormat.R16G16B16A16 | GalImageFormat.Uint:   return(PixelInternalFormat.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort);

            case GalImageFormat.R32G32 | GalImageFormat.Sfloat: return(PixelInternalFormat.Rg32f, PixelFormat.Rg, PixelType.Float);

            case GalImageFormat.R32G32 | GalImageFormat.Sint:   return(PixelInternalFormat.Rg32i, PixelFormat.RgInteger, PixelType.Int);

            case GalImageFormat.R32G32 | GalImageFormat.Uint:   return(PixelInternalFormat.Rg32ui, PixelFormat.RgInteger, PixelType.UnsignedInt);

            case GalImageFormat.A8B8G8R8 | GalImageFormat.Snorm:  return(PixelInternalFormat.Rgba8Snorm, PixelFormat.Rgba, PixelType.Byte);

            case GalImageFormat.A8B8G8R8 | GalImageFormat.Unorm:  return(PixelInternalFormat.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte);

            case GalImageFormat.A8B8G8R8 | GalImageFormat.Sint:   return(PixelInternalFormat.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte);

            case GalImageFormat.A8B8G8R8 | GalImageFormat.Uint:   return(PixelInternalFormat.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte);

            case GalImageFormat.A8B8G8R8_SRGB:                        return(PixelInternalFormat.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte);

            case GalImageFormat.A4B4G4R4 | GalImageFormat.Unorm:  return(PixelInternalFormat.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Reversed);

            case GalImageFormat.A2B10G10R10 | GalImageFormat.Uint:   return(PixelInternalFormat.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed);

            case GalImageFormat.A2B10G10R10 | GalImageFormat.Unorm:  return(PixelInternalFormat.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Reversed);

            case GalImageFormat.R32 | GalImageFormat.Sfloat: return(PixelInternalFormat.R32f, PixelFormat.Red, PixelType.Float);

            case GalImageFormat.R32 | GalImageFormat.Sint:   return(PixelInternalFormat.R32i, PixelFormat.Red, PixelType.Int);

            case GalImageFormat.R32 | GalImageFormat.Uint:   return(PixelInternalFormat.R32ui, PixelFormat.Red, PixelType.UnsignedInt);

            case GalImageFormat.A1R5G5B5 | GalImageFormat.Unorm:  return(PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort1555Reversed);

            case GalImageFormat.B5G6R5 | GalImageFormat.Unorm:  return(PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565Reversed);

            case GalImageFormat.R16G16 | GalImageFormat.Sfloat: return(PixelInternalFormat.Rg16f, PixelFormat.Rg, PixelType.HalfFloat);

            case GalImageFormat.R16G16 | GalImageFormat.Sint:   return(PixelInternalFormat.Rg16i, PixelFormat.RgInteger, PixelType.Short);

            case GalImageFormat.R16G16 | GalImageFormat.Snorm:  return(PixelInternalFormat.Rg16Snorm, PixelFormat.Rg, PixelType.Byte);

            case GalImageFormat.R16G16 | GalImageFormat.Unorm:  return(PixelInternalFormat.Rg16, PixelFormat.Rg, PixelType.UnsignedShort);

            case GalImageFormat.R8G8 | GalImageFormat.Sint:   return(PixelInternalFormat.Rg8i, PixelFormat.RgInteger, PixelType.Byte);

            case GalImageFormat.R8G8 | GalImageFormat.Snorm:  return(PixelInternalFormat.Rg8Snorm, PixelFormat.Rg, PixelType.Byte);

            case GalImageFormat.R8G8 | GalImageFormat.Uint:   return(PixelInternalFormat.Rg8ui, PixelFormat.RgInteger, PixelType.UnsignedByte);

            case GalImageFormat.R8G8 | GalImageFormat.Unorm:  return(PixelInternalFormat.Rg8, PixelFormat.Rg, PixelType.UnsignedByte);

            case GalImageFormat.R16 | GalImageFormat.Sfloat: return(PixelInternalFormat.R16f, PixelFormat.Red, PixelType.HalfFloat);

            case GalImageFormat.R16 | GalImageFormat.Sint:   return(PixelInternalFormat.R16i, PixelFormat.RedInteger, PixelType.Short);

            case GalImageFormat.R16 | GalImageFormat.Snorm:  return(PixelInternalFormat.R16Snorm, PixelFormat.Red, PixelType.Byte);

            case GalImageFormat.R16 | GalImageFormat.Uint:   return(PixelInternalFormat.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort);

            case GalImageFormat.R16 | GalImageFormat.Unorm:  return(PixelInternalFormat.R16, PixelFormat.Red, PixelType.UnsignedShort);

            case GalImageFormat.R8 | GalImageFormat.Sint:   return(PixelInternalFormat.R8i, PixelFormat.RedInteger, PixelType.Byte);

            case GalImageFormat.R8 | GalImageFormat.Snorm:  return(PixelInternalFormat.R8Snorm, PixelFormat.Red, PixelType.Byte);

            case GalImageFormat.R8 | GalImageFormat.Uint:   return(PixelInternalFormat.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte);

            case GalImageFormat.R8 | GalImageFormat.Unorm:  return(PixelInternalFormat.R8, PixelFormat.Red, PixelType.UnsignedByte);

            case GalImageFormat.B10G11R11 | GalImageFormat.Sfloat: return(PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.UnsignedInt10F11F11FRev);

            case GalImageFormat.D24_S8 | GalImageFormat.Unorm:  return(PixelInternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248);

            case GalImageFormat.D32 | GalImageFormat.Sfloat: return(PixelInternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float);

            case GalImageFormat.D16 | GalImageFormat.Unorm:  return(PixelInternalFormat.DepthComponent16, PixelFormat.DepthComponent, PixelType.UnsignedShort);

            case GalImageFormat.D32_S8 | GalImageFormat.Sfloat: return(PixelInternalFormat.Depth32fStencil8, PixelFormat.DepthStencil, PixelType.Float32UnsignedInt248Rev);
            }

            throw new NotImplementedException($"{Format & GalImageFormat.FormatMask} {Format & GalImageFormat.TypeMask}");
        }