Example #1
0
        internal override TextureView GetRenderTargetView(ViewType viewType, int arrayOrDepthSlice, int mipIndex)
        {
            if ((Description.BindFlags & BindFlags.RenderTarget) == 0)
            {
                return(null);
            }

            if (viewType == ViewType.MipBand)
            {
                throw new NotSupportedException("ViewSlice.MipBand is not supported for render targets");
            }

            int arrayCount;
            int mipCount;

            GetViewSliceBounds(viewType, ref arrayOrDepthSlice, ref mipIndex, out arrayCount, out mipCount);

            var rtvIndex = GetViewIndex(viewType, arrayOrDepthSlice, mipIndex);

            lock (renderTargetViews)
            {
                var rtv = renderTargetViews[rtvIndex];

                // Creates the shader resource view
                if (rtv == null)
                {
                    // Create the render target view
                    var rtvDescription = new RenderTargetViewDescription
                    {
                        Format    = Description.Format,
                        Dimension = RenderTargetViewDimension.Texture3D,
                        Texture3D =
                        {
                            DepthSliceCount = arrayCount,
                            FirstDepthSlice = arrayOrDepthSlice,
                            MipSlice        = mipIndex,
                        }
                    };

                    rtv = new TextureView(this, new RenderTargetView(Device, Resource, rtvDescription));
                    renderTargetViews[rtvIndex] = ToDispose(rtv);
                }

                return(rtv);
            }
        }
Example #2
0
        internal override TextureView GetShaderResourceView(Format viewFormat, ViewType viewType, int arrayOrDepthSlice, int mipIndex)
        {
            if ((Description.BindFlags & BindFlags.ShaderResource) == 0)
            {
                return(null);
            }

            int arrayCount;
            int mipCount;

            GetViewSliceBounds(viewType, ref arrayOrDepthSlice, ref mipIndex, out arrayCount, out mipCount);

            var textureViewKey = new TextureViewKey(viewFormat, viewType, arrayOrDepthSlice, mipIndex);

            lock (shaderResourceViews)
            {
                TextureView srv;
                // Creates the shader resource view
                if (!shaderResourceViews.TryGetValue(textureViewKey, out srv))
                {
                    // Create the view
                    var srvDescription = new ShaderResourceViewDescription
                    {
                        Format    = viewFormat,
                        Dimension = ShaderResourceViewDimension.Texture3D,
                        Texture3D =
                        {
                            MipLevels       = mipCount,
                            MostDetailedMip = mipIndex
                        }
                    };

                    srv = new TextureView(this, new ShaderResourceView(Device, Resource, srvDescription));
                    shaderResourceViews.Add(textureViewKey, ToDispose(srv));
                }

                return(srv);
            }
        }
Example #3
0
        protected override void InitializeViews()
        {
            if ((Description.BindFlags & BindFlags.RenderTarget) != 0)
            {
                renderTargetViews = new TextureView[GetViewCount()];
            }

            if (pureRenderTarget)
            {
                renderTargetViews[0] = new TextureView(this, customRenderTargetView);
            }
            else
            {
                // Perform default initialization
                base.InitializeViews();

                if ((Description.BindFlags & BindFlags.RenderTarget) != 0)
                {
                    GetRenderTargetView(ViewType.Full, 0, 0);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Gets a specific <see cref="DepthStencilView" /> from this texture.
        /// </summary>
        /// <param name="viewType">Type of the view slice.</param>
        /// <param name="arrayOrDepthSlice">The texture array slice index.</param>
        /// <param name="mipMapSlice">The mip map slice index.</param>
        /// <param name="readOnlyView">Indicates if the view is read-only.</param>
        /// <returns>A <see cref="DepthStencilView" /></returns>
        internal virtual TextureView GetDepthStencilView(ViewType viewType, int arrayOrDepthSlice, int mipIndex, bool readOnlyView)
        {
            if ((this.Description.BindFlags & BindFlags.DepthStencil) == 0)
            {
                return(null);
            }

            if (viewType == ViewType.MipBand)
            {
                throw new NotSupportedException("ViewSlice.MipBand is not supported for depth stencils");
            }

            if (readOnlyView && !HasReadOnlyView)
            {
                return(null);
            }

            var views = readOnlyView ? readOnlyViews : depthStencilViews;

            int arrayCount;
            int mipCount;

            GetViewSliceBounds(viewType, ref arrayOrDepthSlice, ref mipIndex, out arrayCount, out mipCount);

            var dsvIndex = GetViewIndex(viewType, arrayOrDepthSlice, mipIndex);

            lock (views)
            {
                var dsv = views[dsvIndex];

                // Creates the shader resource view
                if (dsv == null)
                {
                    // Create the depth stencil view
                    var dsvDescription = new DepthStencilViewDescription()
                    {
                        Format = (Format)DepthFormat
                    };

                    if (this.Description.ArraySize > 1)
                    {
                        dsvDescription.Dimension = this.Description.SampleDescription.Count > 1 ? DepthStencilViewDimension.Texture2DMultisampledArray : DepthStencilViewDimension.Texture2DArray;
                        if (this.Description.SampleDescription.Count > 1)
                        {
                            dsvDescription.Texture2DMSArray.ArraySize       = arrayCount;
                            dsvDescription.Texture2DMSArray.FirstArraySlice = arrayOrDepthSlice;
                        }
                        else
                        {
                            dsvDescription.Texture2DArray.ArraySize       = arrayCount;
                            dsvDescription.Texture2DArray.FirstArraySlice = arrayOrDepthSlice;
                            dsvDescription.Texture2DArray.MipSlice        = mipIndex;
                        }
                    }
                    else
                    {
                        dsvDescription.Dimension = this.Description.SampleDescription.Count > 1 ? DepthStencilViewDimension.Texture2DMultisampled : DepthStencilViewDimension.Texture2D;
                        if (this.Description.SampleDescription.Count <= 1)
                        {
                            dsvDescription.Texture2D.MipSlice = mipIndex;
                        }
                    }

                    if (readOnlyView)
                    {
                        dsvDescription.Flags = DepthStencilViewFlags.ReadOnlyDepth;
                        if (HasStencil)
                        {
                            dsvDescription.Flags |= DepthStencilViewFlags.ReadOnlyStencil;
                        }
                    }

                    dsv             = new TextureView(this, new DepthStencilView(Device, Resource, dsvDescription));
                    views[dsvIndex] = ToDispose(dsv);
                }

                return(dsv);
            }
        }
Example #5
0
        internal override TextureView GetRenderTargetView(ViewType viewType, int arrayOrDepthSlice, int mipIndex)
        {
            if ((Description.BindFlags & BindFlags.RenderTarget) == 0)
            {
                return(null);
            }

            if (viewType == ViewType.MipBand)
            {
                throw new NotSupportedException("ViewSlice.MipBand is not supported for render targets");
            }

            int arrayCount;
            int mipCount;

            GetViewSliceBounds(viewType, ref arrayOrDepthSlice, ref mipIndex, out arrayCount, out mipCount);

            var rtvIndex = GetViewIndex(viewType, arrayOrDepthSlice, mipIndex);

            lock (renderTargetViews)
            {
                var rtv = renderTargetViews[rtvIndex];

                // Creates the shader resource view
                if (rtv == null)
                {
                    // Create the render target view
                    var rtvDescription = new RenderTargetViewDescription {
                        Format = Description.Format
                    };

                    if (Description.ArraySize > 1)
                    {
                        rtvDescription.Dimension = Description.SampleDescription.Count > 1 ? RenderTargetViewDimension.Texture2DMultisampledArray : RenderTargetViewDimension.Texture2DArray;
                        if (Description.SampleDescription.Count > 1)
                        {
                            rtvDescription.Texture2DMSArray.ArraySize       = arrayCount;
                            rtvDescription.Texture2DMSArray.FirstArraySlice = arrayOrDepthSlice;
                        }
                        else
                        {
                            rtvDescription.Texture2DArray.ArraySize       = arrayCount;
                            rtvDescription.Texture2DArray.FirstArraySlice = arrayOrDepthSlice;
                            rtvDescription.Texture2DArray.MipSlice        = mipIndex;
                        }
                    }
                    else
                    {
                        rtvDescription.Dimension = Description.SampleDescription.Count > 1 ? RenderTargetViewDimension.Texture2DMultisampled : RenderTargetViewDimension.Texture2D;
                        if (Description.SampleDescription.Count <= 1)
                        {
                            rtvDescription.Texture2D.MipSlice = mipIndex;
                        }
                    }

                    rtv = new TextureView(this, new RenderTargetView(Device, Resource, rtvDescription));
                    renderTargetViews[rtvIndex] = ToDispose(rtv);
                }

                return(rtv);
            }
        }
Example #6
0
        internal override TextureView GetShaderResourceView(Format viewFormat, ViewType viewType, int arrayOrDepthSlice, int mipIndex)
        {
            if ((Description.BindFlags & BindFlags.ShaderResource) == 0)
            {
                return(null);
            }

            int arrayCount;
            int mipCount;

            GetViewSliceBounds(viewType, ref arrayOrDepthSlice, ref mipIndex, out arrayCount, out mipCount);

            var textureViewKey = new TextureViewKey(viewFormat, viewType, arrayOrDepthSlice, mipIndex);

            lock (shaderResourceViews)
            {
                TextureView srv;
                // Creates the shader resource view
                if (!shaderResourceViews.TryGetValue(textureViewKey, out srv))
                {
                    // Create the view
                    var srvDescription = new ShaderResourceViewDescription {
                        Format = viewFormat
                    };

                    // Initialize for texture arrays or texture cube
                    if (Description.ArraySize > 1)
                    {
                        // If texture cube
                        if ((Description.OptionFlags & ResourceOptionFlags.TextureCube) != 0)
                        {
                            srvDescription.Dimension                   = ShaderResourceViewDimension.TextureCube;
                            srvDescription.TextureCube.MipLevels       = mipCount;
                            srvDescription.TextureCube.MostDetailedMip = mipIndex;
                        }
                        else
                        {
                            // Else regular Texture2D
                            srvDescription.Dimension = Description.SampleDescription.Count > 1 ? ShaderResourceViewDimension.Texture2DMultisampledArray : ShaderResourceViewDimension.Texture2DArray;

                            // Multisample?
                            if (Description.SampleDescription.Count > 1)
                            {
                                srvDescription.Texture2DMSArray.ArraySize       = arrayCount;
                                srvDescription.Texture2DMSArray.FirstArraySlice = arrayOrDepthSlice;
                            }
                            else
                            {
                                srvDescription.Texture2DArray.ArraySize       = arrayCount;
                                srvDescription.Texture2DArray.FirstArraySlice = arrayOrDepthSlice;
                                srvDescription.Texture2DArray.MipLevels       = mipCount;
                                srvDescription.Texture2DArray.MostDetailedMip = mipIndex;
                            }
                        }
                    }
                    else
                    {
                        srvDescription.Dimension = Description.SampleDescription.Count > 1 ? ShaderResourceViewDimension.Texture2DMultisampled : ShaderResourceViewDimension.Texture2D;
                        if (Description.SampleDescription.Count <= 1)
                        {
                            srvDescription.Texture2D.MipLevels       = mipCount;
                            srvDescription.Texture2D.MostDetailedMip = mipIndex;
                        }
                    }

                    srv = new TextureView(this, new ShaderResourceView(Device, Resource, srvDescription));
                    shaderResourceViews.Add(textureViewKey, ToDispose(srv));
                }

                return(srv);
            }
        }