Esempio n. 1
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;
        }
Esempio n. 2
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;
        }