示例#1
0
        internal override TextureView GetShaderResourceView(Format viewFormat, ViewType viewType, int arrayOrDepthSlice, int mipIndex)
        {
            if ((this.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 (this.shaderResourceViews)
            {
                TextureView srv;
                // Creates the shader resource view
                if (!shaderResourceViews.TryGetValue(textureViewKey, out srv))
                {
                    // Create the view
                    var srvDescription = new ShaderResourceViewDescription()
                    {
                        Format = this.Description.Format
                    };

                    // Initialize for texture arrays or texture cube
                    if (this.Description.ArraySize > 1)
                    {
                        // Else regular Texture1D
                        srvDescription.Dimension = ShaderResourceViewDimension.Texture1DArray;
                        srvDescription.Texture1DArray.ArraySize       = arrayCount;
                        srvDescription.Texture1DArray.FirstArraySlice = arrayOrDepthSlice;
                        srvDescription.Texture1DArray.MipLevels       = mipCount;
                        srvDescription.Texture1DArray.MostDetailedMip = mipIndex;
                    }
                    else
                    {
                        srvDescription.Dimension                 = ShaderResourceViewDimension.Texture1D;
                        srvDescription.Texture1D.MipLevels       = mipCount;
                        srvDescription.Texture1D.MostDetailedMip = mipIndex;
                    }

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

                return(srv);
            }
        }
示例#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);
            }
        }
示例#3
0
        internal override TextureView GetShaderResourceView(Format viewFormat, ViewType viewType, int arrayOrDepthSlice, int mipIndex)
        {
            if ((this.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 (this.shaderResourceViews)
            {
                TextureView srv;
                // Creates the shader resource view
                if (!shaderResourceViews.TryGetValue(textureViewKey, out srv))
                {
                    // Create the view
                    var srvDescription = new ShaderResourceViewDescription() { Format = this.Description.Format };

                    // Initialize for texture arrays or texture cube
                    if (this.Description.ArraySize > 1)
                    {
                        // Else regular Texture1D
                        srvDescription.Dimension = ShaderResourceViewDimension.Texture1DArray;
                        srvDescription.Texture1DArray.ArraySize = arrayCount;
                        srvDescription.Texture1DArray.FirstArraySlice = arrayOrDepthSlice;
                        srvDescription.Texture1DArray.MipLevels = mipCount;
                        srvDescription.Texture1DArray.MostDetailedMip = mipIndex;
                    }
                    else
                    {
                        srvDescription.Dimension = ShaderResourceViewDimension.Texture1D;
                        srvDescription.Texture1D.MipLevels = mipCount;
                        srvDescription.Texture1D.MostDetailedMip = mipIndex;
                    }

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

                return srv;
            }
        }
示例#4
0
        internal override TextureView GetShaderResourceView(Format viewFormat, ViewType viewType, int arrayOrDepthSlice, int mipIndex)
        {
            if ((this.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 (this.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(this.GraphicsDevice, this.Resource, srvDescription));
                    this.shaderResourceViews.Add(textureViewKey, ToDispose(srv));
                }

                return srv;
            }
        }
示例#5
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);
            }
        }