internal static void Init()
        {
            m_buildHistogram = MyShaders.CreateCs("histogram.hlsl", "build_histogram", MyShaderHelpers.FormatMacros("NUMTHREADS 8"));
            m_drawHistogram = MyShaders.CreatePs("data_visualization.hlsl", "display_histogram");

            m_histogram = MyRwTextures.CreateUav1D(512, SharpDX.DXGI.Format.R32_UInt, "histogram");
        }
        internal static void Init()
        {
            m_buildHistogram = MyShaders.CreateCs("histogram.hlsl", new[] { new ShaderMacro("NUMTHREADS", 8) });
            m_drawHistogram = MyShaders.CreatePs("data_visualization_histogram.hlsl");
            m_drawTonemapping = MyShaders.CreatePs("data_visualization_tonemapping.hlsl");

            m_histogram = MyRwTextures.CreateUav1D(513, SharpDX.DXGI.Format.R32_UInt, "histogram");
        }
Пример #3
0
        public override void Dispose()
        {
            if (m_texture != RwTexId.NULL)
            {
                MyRwTextures.Destroy(m_texture);
                m_texture = RwTexId.NULL;
            }

            base.Dispose();
        }
Пример #4
0
        internal static void ResizeCascades()
        {
            if (m_cascadeShadowmapArray != RwTexId.NULL)
            {
                MyRwTextures.Destroy(m_cascadeShadowmapArray);
            }

            m_cascadeResolution = MyRender11.m_renderSettings.ShadowQuality.Resolution();

            m_cascadeShadowmapArray = MyRwTextures.CreateShadowmapArray(m_cascadeResolution, m_cascadeResolution,
                m_cascadesNum, Format.R24G8_Typeless, Format.D24_UNorm_S8_UInt, Format.R24_UNorm_X8_Typeless, "cascades shadowmaps");
        }
Пример #5
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);
        }
Пример #6
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);
        }
        internal static void Combine(RwTexId targetArray, MyShadowCascades firstCascades, MyShadowCascades secondCascades)
        {
            if (!MyRender11.Settings.EnableShadows)
                return;

            ProfilerShort.Begin("MyShadowCascadesPostProcess.Combine");
            MyGpuProfiler.IC_BeginBlock("MyShadowCascadesPostProcess.Combine");

            firstCascades.FillConstantBuffer(firstCascades.CascadeConstantBuffer);
            secondCascades.FillConstantBuffer(secondCascades.CascadeConstantBuffer);
            secondCascades.PostProcessor.MarkCascadesInStencil(secondCascades.CascadeInfo);

            MyRenderContext renderContext = MyRenderContext.Immediate;
            DeviceContext deviceContext = renderContext.DeviceContext;

            deviceContext.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            deviceContext.PixelShader.SetConstantBuffer(10, firstCascades.CascadeConstantBuffer);
            deviceContext.PixelShader.SetConstantBuffer(11, secondCascades.CascadeConstantBuffer);
            deviceContext.PixelShader.SetConstantBuffer(12, m_inverseConstants);

            for (int subresourceIndex = 0; subresourceIndex < targetArray.Description2d.ArraySize; ++subresourceIndex)
            {
                renderContext.BindGBufferForRead(0, MyGBuffer.Main);
                deviceContext.OutputMerger.SetTargets((DepthStencilView)null, (RenderTargetView)targetArray.SubresourceRtv(subresourceIndex));
                deviceContext.PixelShader.SetShaderResource(0, firstCascades.CascadeShadowmapArray.SubresourceSrv(subresourceIndex));
                deviceContext.PixelShader.SetShaderResource(1, secondCascades.CascadeShadowmapArray.ShaderView);
                //deviceContext.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
                renderContext.SetPS(m_combinePS);

                Matrix inverseCascadeMatrix = MatrixD.Transpose(MatrixD.Invert(firstCascades.CascadeInfo[subresourceIndex].CurrentLocalToProjection * MyMatrixHelpers.ClipspaceToTexture));
                var mapping = MyMapping.MapDiscard(m_inverseConstants);
                mapping.WriteAndPosition(ref inverseCascadeMatrix);
                mapping.Unmap();
                
                MyScreenPass.DrawFullscreenQuad(new MyViewport(0, 0, targetArray.Description2d.Width, targetArray.Description2d.Height));
            }

            deviceContext.OutputMerger.SetTargets(null as DepthStencilView, null as RenderTargetView);
            deviceContext.PixelShader.SetShaderResource(0, null);
            deviceContext.PixelShader.SetShaderResource(1, null);
            deviceContext.PixelShader.SetShaderResource(2, null);
            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();
        }
Пример #8
0
        private static void DrawCascadeArray(RwTexId textureArray, int quadStartX, int quadStartY, int quadSize)
        {
            RC.DeviceContext.PixelShader.Set(m_blitTextureArrayShader);
            RC.DeviceContext.PixelShader.SetShaderResource(0, textureArray.SRV);

            var cb = MyCommon.GetMaterialCB(sizeof(uint));
            RC.DeviceContext.PixelShader.SetConstantBuffer(5, cb);

            for (uint cascadeIndex = 0; cascadeIndex < MyRender11.Settings.ShadowCascadeCount; cascadeIndex++)
            {
                float index = (float)cascadeIndex;
                var mapping = MyMapping.MapDiscard(cb);
                mapping.WriteAndPosition(ref index);
                mapping.Unmap();
                DrawQuad(quadStartX + (quadSize + quadStartX / 2) * cascadeIndex, quadStartY, quadSize, quadSize * MyRender11.ViewportResolution.Y / MyRender11.ViewportResolution.X);
            }
            RC.DeviceContext.PixelShader.SetShaderResource(0, null);
        }
Пример #9
0
        // has 6 rtv subresources and mipLevels * 6 srv/uav subresources
        internal static RwTexId CreateCubemap(int resolution, Format resourceFormat, string debugName = null)
        {
            int mipLevels = 1;
            while ((resolution >> mipLevels) > 0)
            {
                ++mipLevels;
            }

            var desc = new Texture2DDescription
            {
                ArraySize = 6,
                BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget | BindFlags.UnorderedAccess,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = resourceFormat,
                MipLevels = mipLevels,
                Usage = ResourceUsage.Default,
                Width = resolution,
                Height = resolution,
                OptionFlags = ResourceOptionFlags.TextureCube,
                SampleDescription = new SampleDescription(1, 0)
            };

            var handle = new RwTexId { Index = Textures.Allocate() };
            Textures.Data[handle.Index] = new MyRwTextureInfo { Description2D = desc };
            Textures.Data[handle.Index].Resource = new Texture2D(MyRender11.Device, desc);

            var res = Textures.Data[handle.Index].Resource;
            Srvs[handle] = new MySrvInfo { Description = null, View = new ShaderResourceView(MyRender11.Device, Textures.Data[handle.Index].Resource) };
            Index.Add(handle);

            var srvDesc = new ShaderResourceViewDescription();
            srvDesc.Dimension = ShaderResourceViewDimension.Texture2DArray;
            srvDesc.Format = resourceFormat;
            srvDesc.Texture2DArray.MipLevels = 1;
            srvDesc.Texture2DArray.ArraySize = 1;

            var uavDesc = new UnorderedAccessViewDescription();
            uavDesc.Dimension = UnorderedAccessViewDimension.Texture2DArray;
            uavDesc.Format = resourceFormat;
            uavDesc.Texture2DArray.ArraySize = 1;

            for (int m = 0; m < mipLevels; ++m)
            {
                for (int i = 0; i < 6; i++)
                {
                    var subresource = i * mipLevels + m;

                    srvDesc.Texture2DArray.FirstArraySlice = i;
                    srvDesc.Texture2DArray.MostDetailedMip = m;

                    SubresourceSrvs[new MySubresourceId { Id = handle, Subresource = subresource }] = new MySrvInfo
                    {
                        Description = srvDesc,
                        View = new ShaderResourceView(MyRender11.Device, res, srvDesc)
                    };

                    uavDesc.Texture2DArray.FirstArraySlice = i;
                    uavDesc.Texture2DArray.MipSlice = m;

                    SubresourceUavs[new MySubresourceId { Id = handle, Subresource = subresource }] = new MyUavInfo
                    {
                        Description = uavDesc,
                        View = new UnorderedAccessView(MyRender11.Device, res, uavDesc)
                    };
                }
            }

            var rtvDesc = new RenderTargetViewDescription();
            rtvDesc.Dimension = RenderTargetViewDimension.Texture2DArray;
            rtvDesc.Format = resourceFormat;
            for (int i = 0; i < 6; i++)
            {
                rtvDesc.Texture2DArray.MipSlice = 0;

                rtvDesc.Texture2DArray.FirstArraySlice = i;
                rtvDesc.Texture2DArray.ArraySize = 1;

                SubresourceRtvs[new MySubresourceId { Id = handle, Subresource = i }] = new MyRtvInfo
                {
                    Description = rtvDesc,
                    View = new RenderTargetView(MyRender11.Device, res, rtvDesc)
                };
            }
                

            return handle;
        }
Пример #10
0
        internal static RwTexId CreateShadowmapArray(int width, int height, int arraySize, 
            Format resourceFormat = Format.R24G8_Typeless, 
            Format depthFormat = Format.D24_UNorm_S8_UInt, 
            Format? viewFormat = Format.R24_UNorm_X8_Typeless, 
            string debugName = null)
        {
            Texture2DDescription desc = new Texture2DDescription();
            desc.Width = width;
            desc.Height = height;
            desc.Format = resourceFormat;
            desc.ArraySize = arraySize;
            desc.MipLevels = 1;
            desc.BindFlags = BindFlags.DepthStencil;
            if (viewFormat.HasValue)
            {
                desc.BindFlags |= BindFlags.ShaderResource;
            }
            desc.Usage = ResourceUsage.Default;
            desc.CpuAccessFlags = 0;
            desc.SampleDescription.Count = 1;
            desc.SampleDescription.Quality = 0;
            desc.OptionFlags = 0;

            var handle = new RwTexId { Index = Textures.Allocate() };
            var res = new Texture2D(MyRender11.Device, desc);
            Textures.Data[handle.Index] = new MyRwTextureInfo { Description2D = desc, Resource = res };
            Index.Add(handle);

            var srvDesc = new ShaderResourceViewDescription();
            if(viewFormat.HasValue)
            {
                srvDesc.Dimension = ShaderResourceViewDimension.Texture2DArray;
                srvDesc.Format = viewFormat.Value;
                srvDesc.Texture2DArray.MipLevels = -1;
                srvDesc.Texture2DArray.MostDetailedMip = 0;
                srvDesc.Texture2DArray.ArraySize = arraySize;
                srvDesc.Texture2DArray.FirstArraySlice = 0;
                Srvs[handle] = new MySrvInfo { Description = srvDesc, View = new ShaderResourceView(MyRender11.Device, res, srvDesc) };
            }

            var dsvDesc = new DepthStencilViewDescription();
            dsvDesc.Dimension = DepthStencilViewDimension.Texture2DArray;
            dsvDesc.Format = depthFormat;
            dsvDesc.Flags = DepthStencilViewFlags.None;
            dsvDesc.Texture2DArray.MipSlice = 0;
            dsvDesc.Texture2DArray.ArraySize = 1;

            srvDesc.Dimension = ShaderResourceViewDimension.Texture2DArray;
            srvDesc.Format = viewFormat.Value;
            srvDesc.Texture2DArray.MipLevels = -1;
            srvDesc.Texture2DArray.MostDetailedMip = 0;
            srvDesc.Texture2DArray.ArraySize = 1;
            for (int i = 0; i < arraySize; i++)
            {
                dsvDesc.Texture2DArray.FirstArraySlice = i;

                SubresourceDsvs[new MySubresourceId { Id = handle, Subresource = i }] = new MyDsvInfo
                {
                    Description = dsvDesc,
                    View = new DepthStencilView(MyRender11.Device, res, dsvDesc)
                };

                srvDesc.Texture2DArray.FirstArraySlice = i;

                SubresourceSrvs[new MySubresourceId { Id = handle, Subresource = i }] = new MySrvInfo
                {
                    Description = srvDesc,
                    View = new ShaderResourceView(MyRender11.Device, res, srvDesc)
                };
            }

            return handle;
        }
Пример #11
0
        internal static RwTexId CreateDynamicTexture(int width, int height, Format fmt)
        {
            var desc = new Texture2DDescription
            {
                ArraySize = 1,
                BindFlags = BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.Write,
                Format = fmt,
                Height = height,
                Width = width,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Dynamic
            };

            var handle = new RwTexId { Index = Textures.Allocate() };
            Textures.Data[handle.Index] = new MyRwTextureInfo { Description2D = desc };
            Textures.Data[handle.Index].Resource = new Texture2D(MyRender11.Device, desc);

            Srvs[handle] = new MySrvInfo { Description = null, View = new ShaderResourceView(MyRender11.Device, Textures.Data[handle.Index].Resource) };
            Index.Add(handle);

            return handle;
        }
Пример #12
0
 internal static Resource GetResource(RwTexId id)
 {
     return Textures.Data[id.Index].Resource;
 }
Пример #13
0
 internal static void Destroy(ref RwTexId id)
 {
     Destroy(id);
     id = RwTexId.NULL;
 }
Пример #14
0
 public MyVideoPlayer(string filename)
     : base(filename)
 {
     m_texture = MyRwTextures.CreateDynamicTexture(VideoWidth, VideoHeight, VideoFormat);
 }
Пример #15
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);
        }
Пример #16
0
 internal static ShaderResourceView GetSrv(RwTexId id, int subres)
 {
     return SubresourceSrvs[new MySubresourceId { Id = id, Subresource = subres }].View;
 }
Пример #17
0
 internal static UnorderedAccessView GetUav(RwTexId id, int subres)
 {
     return SubresourceUavs[new MySubresourceId { Id = id, Subresource = subres }].View;
 }
Пример #18
0
        internal static void Destroy(RwTexId id)
        {
            if(Srvs.ContainsKey(id))
            {
                Srvs[id].View.Dispose();
                Srvs.Remove(id);
            }

            if (Uavs.ContainsKey(id))
            {
                Uavs[id].View.Dispose();
                Uavs.Remove(id);
            }

            if (Dsvs.ContainsKey(id))
            {
                Dsvs[id].View.Dispose();
                Dsvs.Remove(id);
            }

            if (Rtvs.ContainsKey(id))
            {
                Rtvs[id].View.Dispose();
                Rtvs.Remove(id);
            }

            // not very fast, but this function should be called rarely, and number of rw resources is rather limited
            var srvToRemove = new List<MySubresourceId>();
            var dsvToRemove = new List<MySubresourceId>();
            var rtvToRemove = new List<MySubresourceId>();
            var uavToRemove = new List<MySubresourceId>();
            foreach (var kv in SubresourceSrvs)
            {
                if (kv.Key.Id == id)
                {
                    kv.Value.View.Dispose();
                    srvToRemove.Add(kv.Key);
                }
            }
            foreach(var kv in SubresourceDsvs)
            {
                if(kv.Key.Id == id)
                {
                    kv.Value.View.Dispose();
                    dsvToRemove.Add(kv.Key);
                }
            }
            foreach (var kv in SubresourceRtvs)
            {
                if (kv.Key.Id == id)
                {
                    kv.Value.View.Dispose();
                    rtvToRemove.Add(kv.Key);
                }
            }
            foreach (var kv in SubresourceUavs)
            {
                if (kv.Key.Id == id)
                {
                    kv.Value.View.Dispose();
                    uavToRemove.Add(kv.Key);
                }
            }
            foreach (var k in srvToRemove)
            {
                SubresourceSrvs.Remove(k);
            }
            foreach(var k in dsvToRemove)
            {
                SubresourceDsvs.Remove(k);
            }
            foreach (var k in rtvToRemove)
            {
                SubresourceRtvs.Remove(k);
            }
            foreach (var k in uavToRemove)
            {
                SubresourceUavs.Remove(k);
            }

            Textures.Data[id.Index].Resource.Dispose();
            Textures.Data[id.Index].Resource = null;

            Textures.Free(id.Index);
        }
Пример #19
0
        internal static RwTexId CreateRenderTarget(int width, int height, Format fmt, bool mipmapAutogen = false)
        {
            var desc = new Texture2DDescription
            {
                ArraySize = 1,
                BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = fmt,
                Height = height,
                Width = width,
                MipLevels = mipmapAutogen ? 0 : 1,
                OptionFlags = mipmapAutogen ? ResourceOptionFlags.GenerateMipMaps : ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            };

            var handle = new RwTexId { Index = Textures.Allocate() };
            Textures.Data[handle.Index] = new MyRwTextureInfo { Description2D = desc };
            Textures.Data[handle.Index].Resource = new Texture2D(MyRender11.Device, desc);

            Srvs[handle] = new MySrvInfo { Description = null, View = new ShaderResourceView(MyRender11.Device, Textures.Data[handle.Index].Resource) };
            Rtvs[handle] = new MyRtvInfo { Description = null, View = new RenderTargetView(MyRender11.Device, Textures.Data[handle.Index].Resource) };

            Index.Add(handle);

            return handle;
        }
Пример #20
0
 internal static ShaderResourceView GetSrv(RwTexId id)
 {
     return Srvs[id].View;
 }
Пример #21
0
        internal static RwTexId CreateShadowmap(int width, int height)
        {
            Texture2DDescription desc = new Texture2DDescription();
            desc.Width = width;
            desc.Height = height;
            desc.Format = Format.R24G8_Typeless;
            desc.ArraySize = 1;
            desc.MipLevels = 1;
            desc.BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource;
            desc.Usage = ResourceUsage.Default;
            desc.CpuAccessFlags = 0;
            desc.SampleDescription.Count = 1;
            desc.SampleDescription.Quality = 0;
            desc.OptionFlags = 0;

            var handle = new RwTexId { Index = Textures.Allocate() };
            var res = new Texture2D(MyRender11.Device, desc);
            Textures.Data[handle.Index] = new MyRwTextureInfo { Description2D = desc, Resource = res };
            Index.Add(handle);

            ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription();
            srvDesc.Dimension = ShaderResourceViewDimension.Texture2D;
            srvDesc.Format = Format.R24_UNorm_X8_Typeless;
            srvDesc.Texture2D.MipLevels = -1;
            srvDesc.Texture2D.MostDetailedMip = 0;
            Srvs[handle] = new MySrvInfo { Description = srvDesc, View = new ShaderResourceView(MyRender11.Device, res, srvDesc) };

            DepthStencilViewDescription dsvDesc = new DepthStencilViewDescription();
            dsvDesc.Dimension = DepthStencilViewDimension.Texture2D;
            dsvDesc.Format = Format.D24_UNorm_S8_UInt;
            dsvDesc.Flags = DepthStencilViewFlags.None;
            dsvDesc.Texture2D.MipSlice = 0;
            Dsvs[handle] = new MyDsvInfo { Description = dsvDesc, View = new DepthStencilView(MyRender11.Device, res, dsvDesc) };

            return handle;
        }
Пример #22
0
 internal static UnorderedAccessView GetUav(RwTexId id)
 {
     return Uavs[id].View;
 }
Пример #23
0
        internal static RwTexId CreateUav2D(int width, int height, Format resourceFormat, string debugName = null)
        {
            var desc = new Texture2DDescription
            {
                ArraySize = 1,
                BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = resourceFormat,
                MipLevels = 1,
                Usage = ResourceUsage.Default,
                Width = width,
                Height = height,
                SampleDescription = new SampleDescription(1, 0)
            };

            var handle = new RwTexId { Index = Textures.Allocate() };
            Textures.Data[handle.Index] = new MyRwTextureInfo { Description2D = desc };
            Textures.Data[handle.Index].Resource = new Texture2D(MyRender11.Device, desc);

            Srvs[handle] = new MySrvInfo { Description = null, View = new ShaderResourceView(MyRender11.Device, Textures.Data[handle.Index].Resource) };
            Uavs[handle] = new MyUavInfo { Description = null, View = new UnorderedAccessView(MyRender11.Device, Textures.Data[handle.Index].Resource) };
            Index.Add(handle);

            return handle;
        }
Пример #24
0
 internal static DepthStencilView GetDsv(RwTexId id)
 {
     return Dsvs[id].View;
 }
Пример #25
0
        internal static void CreateScreenResources()
        {
            var width = m_resolution.X;
            var height = m_resolution.Y;
            var samples = RenderSettings.AntialiasingMode.SamplesCount();

            if(MyGBuffer.Main == null)
            {
                MyGBuffer.Main = new MyGBuffer();
            }
            MyGBuffer.Main.Resize(width, height, samples, 0);

            MyScreenDependants.Resize(width, height, samples, 0);

            RemoveScreenResources();

            m_resolvedLight = new MyRenderTarget(width, height, Format.R11G11B10_Float, 1, 0);
            m_reduce0 = new MyUnorderedAccessTexture(width, height, Format.R32_Float);
            m_reduce0.SetDebugName("reduce0");
            m_reduce1 = new MyUnorderedAccessTexture(width, height, Format.R32_Float);
            m_reduce1.SetDebugName("reduce1");
            m_uav3 = new MyUnorderedAccessTexture(width, height, Format.R11G11B10_Float);

            m_localLum = new MyUnorderedAccessTexture(
                (width + MyLuminanceAverage.NumThreads - 1) / MyLuminanceAverage.NumThreads,
                (height + MyLuminanceAverage.NumThreads - 1) / MyLuminanceAverage.NumThreads,
                Format.R32_Float);

            m_div2 = new MyUnorderedAccessTexture(width / 2, height / 2, Format.R11G11B10_Float);
            m_div4 = new MyUnorderedAccessTexture(width / 4, height / 4, Format.R11G11B10_Float);
            m_div8 = new MyUnorderedAccessTexture(width / 8, height / 8, Format.R11G11B10_Float);
            m_div8_1 = new MyUnorderedAccessTexture(width / 8, height / 8, Format.R11G11B10_Float);

            m_rgba8_linear = new MyUnorderedAccessTexture(width, height, Format.R8G8B8A8_UNorm);

            m_rgba8_0 = new MyCustomTexture(width, height, BindFlags.RenderTarget | BindFlags.ShaderResource, Format.R8G8B8A8_Typeless);
            m_rgba8_0.AddView(new MyViewKey { Fmt = Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView });
            m_rgba8_0.AddView(new MyViewKey { Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView });

            m_rgba8_1 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            m_prevLum = new MyUnorderedAccessTexture(1, 1, Format.R32_Float);

            Debug.Assert(m_shadowsHelper == RwTexId.NULL);
            m_shadowsHelper = MyRwTextures.CreateUav2D(width, height, Format.R8_UNorm, "cascade shadows gather");
            m_shadowsHelper1 = MyRwTextures.CreateUav2D(width, height, Format.R8_UNorm, "cascade shadows gather 2");
        }
Пример #26
0
 internal static RenderTargetView GetRtv(RwTexId id)
 {
     return Rtvs[id].View;
 }
Пример #27
0
        internal static void CreateScreenResources()
        {
            var width = m_resolution.X;
            var height = m_resolution.Y;
            var samples = RenderSettings.AntialiasingMode.SamplesCount();

            MyUtils.Init(ref MyGBuffer.Main);
            MyGBuffer.Main.Resize(width, height, samples, 0);

            MyScreenDependants.Resize(width, height, samples, 0);

            RemoveScreenResources();

            m_reduce0 = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce0.SetDebugName("reduce0");
            m_reduce1 = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce1.SetDebugName("reduce1");
            m_uav3 = new MyUnorderedAccessTexture(width, height, MyGBuffer.LBufferFormat);

            HalfScreenUavHDR = new MyUnorderedAccessTexture(width / 2, height / 2, MyGBuffer.LBufferFormat);
            QuarterScreenUavHDR = new MyUnorderedAccessTexture(width / 4, height / 4, MyGBuffer.LBufferFormat);
            EighthScreenUavHDR = new MyUnorderedAccessTexture(width / 8, height / 8, MyGBuffer.LBufferFormat);
            EighthScreenUavHDRHelper = new MyUnorderedAccessTexture(width / 8, height / 8, MyGBuffer.LBufferFormat);

            m_rgba8_linear = new MyUnorderedAccessTexture(width, height, Format.R8G8B8A8_UNorm);

            m_rgba8_0 = new MyCustomTexture(width, height, BindFlags.RenderTarget | BindFlags.ShaderResource, Format.R8G8B8A8_Typeless);
            m_rgba8_0.AddView(new MyViewKey { Fmt = Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView });
            m_rgba8_0.AddView(new MyViewKey { Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView });
            m_rgba8_0.AddView(new MyViewKey { Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView });

            m_rgba8_1 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            m_rgba8_2 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            if (samples > 1)
            {
                m_rgba8_ms = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, samples, 0);
            }
            m_prevLum = new MyUnorderedAccessTexture(1, 1, Format.R32G32_Float);

            Debug.Assert(PostProcessedShadows == RwTexId.NULL);
            Debug.Assert(CascadesHelper == RwTexId.NULL);
            PostProcessedShadows = MyRwTextures.CreateUavRenderTarget(width, height, Format.R8_UNorm);
            CascadesHelper = MyRwTextures.CreateRenderTarget(width, height, Format.R8_UNorm);

            m_gbuffer1Copy = MyRwTextures.CreateScratch2D(width, height, Format.R8G8B8A8_UNorm, samples, 0, "gbuffer 1 copy");
        }
Пример #28
0
 internal static DepthStencilView GetDsv(RwTexId id, int subres)
 {
     return SubresourceDsvs[new MySubresourceId { Id = id, Subresource = subres }].View;
 }
        internal void GatherArray(RwTexId postprocessTarget, RwTexId cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer)
        {
            if (!MyRenderProxy.Settings.EnableShadows)
                return;

            MarkCascadesInStencil(cascadeInfo);

            MyGpuProfiler.IC_BeginBlock("Cascades postprocess");

            MyRenderContext renderContext = MyRenderContext.Immediate;
            DeviceContext deviceContext = renderContext.DeviceContext;

            renderContext.SetCS(m_gatherCS);
            ComputeShaderId.TmpUav[0] = postprocessTarget.Uav;
            deviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount);

            deviceContext.ComputeShader.SetShaderResource(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.m_SRV_depth : MyGBuffer.Main.DepthStencil.m_SRV_depth);
            deviceContext.ComputeShader.SetShaderResource(1, MyGBuffer.Main.DepthStencil.m_SRV_stencil);
            deviceContext.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MyRender11.m_shadowmapSamplerState);
            deviceContext.ComputeShader.SetConstantBuffer(0, MyCommon.FrameConstants);
            deviceContext.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer);
            deviceContext.ComputeShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, cascadeArray.ShaderView);

            deviceContext.Dispatch(m_threadGroupCountX, m_threadGroupCountY, 1);

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

            if(MyRender11.Settings.EnableShadowBlur)
                MyBlur.Run(postprocessTarget.Rtv, MyRender11.CascadesHelper.Rtv, MyRender11.CascadesHelper.ShaderView, postprocessTarget.ShaderView, depthDiscardThreshold: 0.2f);

            MyGpuProfiler.IC_EndBlock();
        }
Пример #30
0
 internal static RenderTargetView GetRtv(RwTexId id, int subres)
 {
     return SubresourceRtvs[new MySubresourceId { Id = id, Subresource = subres }].View;
 }