Example #1
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;
        }
Example #2
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;
        }
Example #3
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;
        }
Example #4
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;
        }
Example #5
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;
        }
Example #6
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;
        }