コード例 #1
0
ファイル: GpuLossyCalculator.cs プロジェクト: Zulkir/RAVC
        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);
        }
コード例 #2
0
        public unsafe void CalculateDiff(IDeviceContext context, ITexture2D target, ITexture2D current, ITexture2D parentTexture, int colorDiffThreshold)
        {
            context.ShaderForDispatching = computeShader;

            var map = context.Map(frameInfoBuffer, 0, MapType.WriteDiscard, MapFlags.None);
            *(Vector4*)map.Data = new Vector4(colorDiffThreshold, 0, 0, 0);
            context.Unmap(frameInfoBuffer, 0);

            context.ComputeStage.UniformBuffers[0] = frameInfoBuffer;

            for (int i = 0; i < EncodingConstants.MipLevels; i++)
            {
                var uav = target.ViewAsUnorderedAccessResource(formatId, i);
                var currentSrv = current.ViewAsShaderResource(formatId, i, 1);
                var parentSrv = parentTexture.ViewAsShaderResource(formatId, i, 1);

                context.ComputeStage.UnorderedAccessResources[0] = uav;
                context.ComputeStage.ShaderResources[0] = currentSrv;
                context.ComputeStage.ShaderResources[1] = parentSrv;

                context.Dispatch(RavcMath.DivideAndCeil(target.Width >> i, 16), RavcMath.DivideAndCeil(target.Height >> i, 16), 1);
            }
        }