Ejemplo n.º 1
0
        internal static void BuildMipmaps(RwTexId texture)
        {
            RC.Context.ComputeShader.Set(m_mipmap);

            var mipLevels = texture.Description2d.MipLevels;
            var side = texture.Description2d.Width;
            for (int j = 0; j < 6; ++j)
            {
                var mipSide = side;
                for (int i = 1; i < mipLevels; ++i)
                {
                    RC.Context.ComputeShader.SetUnorderedAccessView(0, texture.SubresourceUav(j, i));
                    RC.Context.ComputeShader.SetShaderResource(0, texture.SubresourceSrv(j, i - 1));
                    RC.Context.Dispatch((mipSide + 7) / 8, (mipSide + 7) / 8, 1);
                    RC.Context.ComputeShader.SetShaderResource(0, null);

                    mipSide >>= 1;
                }
            }

            RC.Context.ComputeShader.SetUnorderedAccessView(0, null);
            RC.Context.ComputeShader.Set(null);
        }
Ejemplo n.º 2
0
        internal static void Prefilter(RwTexId probe, RwTexId prefiltered)
        {
            RC.Context.ComputeShader.Set(m_prefilter);

            var mipLevels = prefiltered.Description2d.MipLevels;
            var side = prefiltered.Description2d.Width;
            var probeSide = probe.Description2d.Width;
            
            RC.CSSetCB(1, MyCommon.GetObjectCB(32));

            RC.Context.ComputeShader.SetShaderResource(0, probe.ShaderView);
            RC.Context.ComputeShader.SetSamplers(0, MyRender11.StandardSamplers);

            for (int j = 0; j < 6; ++j)
            {
                var mipSide = side;
                for (int i = 0; i < mipLevels; ++i)
                {
                    uint samplesNum = i == 0 ? 1u : 64u;

                    var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(32));
                    mapping.stream.Write((uint)samplesNum);
                    mapping.stream.Write((uint)probeSide);
                    mapping.stream.Write((uint)mipSide);
                    mapping.stream.Write((uint) j);
                    mapping.stream.Write(1 - (i / (float)(mipLevels - 1)) );
                    mapping.Unmap();

                    RC.Context.ComputeShader.SetUnorderedAccessView(0, prefiltered.SubresourceUav(j, i));
                    RC.Context.Dispatch((mipSide + 7) / 8, (mipSide + 7) / 8, 1);

                    mipSide >>= 1;
                }
            }

            RC.Context.ComputeShader.SetUnorderedAccessView(0, null);
            RC.Context.ComputeShader.SetShaderResource(0, null);

            RC.Context.ComputeShader.Set(null);
        }
        internal static void Blend(RwTexId dst, RwTexId src0, RwTexId src1, float blendWeight)
        {
            //MyImmediateRC.RC.Context.CopyResource(src1.Resource, dst.Resource);

            RC.DeviceContext.ComputeShader.Set(m_blend);

            var mipLevels = dst.Description2d.MipLevels;
            var side = dst.Description2d.Width;

            RC.CSSetCB(1, MyCommon.GetObjectCB(32));

            RC.DeviceContext.ComputeShader.SetSamplers(0, MyRender11.StandardSamplers);

            for (int j = 0; j < 6; ++j)
            {
                var mipSide = side;
                for (int i = 0; i < mipLevels; ++i)
                {
                    uint samplesNum = i == 0 ? 1u : 64u;

                    var blendConstantData = new MyBlendData { field0 = 0, field1 = 0, MipSide = (uint)mipSide, field2 = 0, W = blendWeight };
                    var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(32));
                    mapping.WriteAndPosition(ref blendConstantData);
                    mapping.Unmap();

                    RC.DeviceContext.ComputeShader.SetShaderResource(0, src0.SubresourceSrv(j, i));
                    RC.DeviceContext.ComputeShader.SetShaderResource(1, src1.SubresourceSrv(j, i));

                    // The single parameter version of SetUnorderedAccessView allocates
                    ComputeShaderId.TmpUav[0] = dst.SubresourceUav(j, i);
                    RC.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
                    RC.DeviceContext.Dispatch((mipSide + 7) / 8, (mipSide + 7) / 8, 1);

                    mipSide >>= 1;
                }
            }

            ComputeShaderId.TmpUav[0] = null;
            RC.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
            RC.DeviceContext.ComputeShader.SetShaderResource(0, null);
            RC.DeviceContext.ComputeShader.SetShaderResource(1, null);

            RC.DeviceContext.ComputeShader.Set(null);
        }
Ejemplo n.º 4
0
        internal static void Blend(RwTexId dst, RwTexId src0, RwTexId src1, float w)
        {
            //MyImmediateRC.RC.Context.CopyResource(src1.Resource, dst.Resource);

            RC.Context.ComputeShader.Set(m_blend);

            var mipLevels = dst.Description2d.MipLevels;
            var side = dst.Description2d.Width;

            RC.CSSetCB(1, MyCommon.GetObjectCB(32));

            RC.Context.ComputeShader.SetSamplers(0, MyRender11.StandardSamplers);

            for (int j = 0; j < 6; ++j)
            {
                var mipSide = side;
                for (int i = 0; i < mipLevels; ++i)
                {
                    uint samplesNum = i == 0 ? 1u : 64u;

                    var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(32));
                    mapping.stream.Write((uint)0);
                    mapping.stream.Write((uint)0);
                    mapping.stream.Write((uint)mipSide);
                    mapping.stream.Write((uint)0);
                    mapping.stream.Write(w);
                    mapping.Unmap();

                    RC.Context.ComputeShader.SetShaderResources(0, src0.SubresourceSrv(j, i), src1.SubresourceSrv(j, i));
                    RC.Context.ComputeShader.SetUnorderedAccessView(0, dst.SubresourceUav(j, i));
                    RC.Context.Dispatch((mipSide + 7) / 8, (mipSide + 7) / 8, 1);

                    mipSide >>= 1;
                }
            }

            RC.Context.ComputeShader.SetUnorderedAccessView(0, null);
            RC.Context.ComputeShader.SetShaderResources(0, null, null);

            RC.Context.ComputeShader.Set(null);
        }
        internal static void Prefilter(RwTexId probe, RwTexId prefiltered)
        {
            RC.DeviceContext.ComputeShader.Set(m_prefilter);

            var mipLevels = prefiltered.Description2d.MipLevels;
            var side = prefiltered.Description2d.Width;
            uint probeSide = (uint)probe.Description2d.Width;
            
            ConstantsBufferId constantBuffer = MyCommon.GetObjectCB(32);
            RC.CSSetCB(1, constantBuffer);

            RC.DeviceContext.ComputeShader.SetShaderResource(0, probe.ShaderView);
            RC.DeviceContext.ComputeShader.SetSamplers(0, MyRender11.StandardSamplers);

            for (int j = 0; j < 6; ++j)
            {
                int mipSide = side;
                for (int i = 0; i < mipLevels; ++i)
                {
                    uint samplesNum = i == 0 ? 1u : 64u;
                    uint mipSideUint = (uint)mipSide;
                    uint ju = (uint)j;
                    float mipLevelFactor = 1 - (i / (float)(mipLevels - 1));

                    var mapping = MyMapping.MapDiscard(constantBuffer);
                    mapping.WriteAndPosition(ref samplesNum);
                    mapping.WriteAndPosition(ref probeSide);
                    mapping.WriteAndPosition(ref mipSideUint);
                    mapping.WriteAndPosition(ref ju);
                    mapping.WriteAndPosition(ref mipLevelFactor);
                    mapping.Unmap();

                    ComputeShaderId.TmpUav[0] = prefiltered.SubresourceUav(j, i);
                    RC.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
                    RC.DeviceContext.Dispatch((mipSide + 7) / 8, (mipSide + 7) / 8, 1);

                    mipSide >>= 1;
                }
            }

            ComputeShaderId.TmpUav[0] = null;
            RC.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);
            RC.DeviceContext.ComputeShader.SetShaderResource(0, null);

            RC.DeviceContext.ComputeShader.Set(null);
        }