public override MipInfo GetMipmap(LayerMipmapSlice lm) { var res = new MipInfo(); Dll.image_info_mipmap(Resource.Id, lm.Mipmap, out res.Size.X, out res.Size.Y, out res.Size.Z); #if DEBUG var expected = Size.GetMip(lm.Mipmap); Debug.Assert(expected.Width == res.Size.Width); Debug.Assert(expected.Height == res.Size.Height); Debug.Assert(expected.Depth == res.Size.Depth); #endif res.Bytes = Dll.image_get_mipmap(Resource.Id, lm.Layer, lm.Mipmap, out res.ByteSize); return(res); }
private void CacheMipMaps() { var mipLevels = TotalMipLevels; mipInfos = new MipInfo[mipLevels]; var isBlockCompressed = (Format >= PixelFormat.BC1_Typeless && Format <= PixelFormat.BC5_SNorm) || (Format >= PixelFormat.BC6H_Typeless && Format <= PixelFormat.BC7_UNorm_SRgb); for (var mipIndex = 0; mipIndex < mipLevels; mipIndex++) { GetMipSize(isBlockCompressed, mipIndex, out int mipWidth, out int mipHeight); Image.ComputePitch(Format, mipWidth, mipHeight, out int rowPitch, out int slicePitch, out int _, out int _); mipInfos[mipIndex] = new MipInfo(mipWidth, mipHeight, rowPitch, slicePitch, ArraySize); } }
public override MipInfo GetMipmap(LayerMipmapSlice lm) { // calc offset uint mipOffset = 0; // offset for previous layers for (int i = 0; i < lm.Mipmap; ++i) { // add mipmap size * layers mipOffset += (uint)Size.GetMip(i).Product *Format.PixelSize *(uint)LayerMipmap.Layers; } // offset from current layer var res = new MipInfo(); res.Size = Size.GetMip(lm.Mipmap); res.ByteSize = (uint)res.Size.Product * Format.PixelSize; mipOffset += res.ByteSize * (uint)lm.Layer; res.Bytes = ptr + (int)mipOffset; return(res); }
public unsafe void CalculateLossy(IDeviceContext context, ITexture2D target, ITexture2D previous, ITexture2D temporalDiff, int mostDetailedMip) { var mipInfo = new MipInfo { MipLevel = mostDetailedMip, CoordDivisor = 1 << mostDetailedMip }; var map = context.Map(mipInfoBuffer, 0, MapType.WriteDiscard, MapFlags.None); *(MipInfo*)map.Data = mipInfo; context.Unmap(mipInfoBuffer, 0); // todo: try doing everything using MostDetailedMip of SRV context.ShaderForDispatching = computeShader; context.ComputeStage.UniformBuffers[0] = mipInfoBuffer; context.ComputeStage.ShaderResources[0] = previous.ViewAsShaderResource(formatId, 0, previous.MipLevels); context.ComputeStage.ShaderResources[1] = temporalDiff.ViewAsShaderResource(formatId, 0, temporalDiff.MipLevels); context.ComputeStage.UnorderedAccessResources[0] = target.ViewAsUnorderedAccessResource(formatId, 0); context.Dispatch(RavcMath.DivideAndCeil(target.Width, 16), RavcMath.DivideAndCeil(target.Height, 16), 1); }