예제 #1
0
        public D3D11TextureView(Device device, ref TextureViewDescription description)
            : base(ref description)
        {
            D3D11Texture d3dTex = Util.AssertSubtype <Texture, D3D11Texture>(description.Target);

            if (BaseMipLevel == 0 && MipLevels == Target.MipLevels ||
                BaseArrayLayer == 0 && ArrayLayers == Target.ArrayLayers)
            {
                ShaderResourceView = d3dTex.GetFullShaderResourceView();
            }
            else
            {
                _srvOwned = true;
                ShaderResourceViewDescription srvDesc = D3D11Util.GetSrvDesc(
                    d3dTex,
                    description.BaseMipLevel,
                    description.MipLevels,
                    description.BaseArrayLayer,
                    description.ArrayLayers);
                ShaderResourceView = new ShaderResourceView(device, d3dTex.DeviceTexture, srvDesc);
            }

            if ((d3dTex.Usage & TextureUsage.Storage) == TextureUsage.Storage)
            {
                UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription();
                uavDesc.Format = D3D11Formats.GetViewFormat(d3dTex.DxgiFormat);

                if ((d3dTex.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap)
                {
                    throw new NotSupportedException();
                }
                else if (d3dTex.Depth == 1)
                {
                    if (d3dTex.ArrayLayers == 1)
                    {
                        uavDesc.Dimension          = UnorderedAccessViewDimension.Texture2D;
                        uavDesc.Texture2D.MipSlice = (int)description.BaseMipLevel;
                    }
                    else
                    {
                        uavDesc.Dimension = UnorderedAccessViewDimension.Texture2DArray;
                        uavDesc.Texture2DArray.MipSlice        = (int)description.BaseMipLevel;
                        uavDesc.Texture2DArray.FirstArraySlice = (int)description.BaseArrayLayer;
                        uavDesc.Texture2DArray.ArraySize       = (int)description.ArrayLayers;
                    }
                }
                else
                {
                    uavDesc.Dimension             = UnorderedAccessViewDimension.Texture3D;
                    uavDesc.Texture3D.MipSlice    = (int)description.BaseMipLevel;
                    uavDesc.Texture3D.FirstWSlice = (int)description.BaseArrayLayer;
                    uavDesc.Texture3D.WSize       = (int)description.ArrayLayers;
                }

                UnorderedAccessView = new UnorderedAccessView(device, d3dTex.DeviceTexture, uavDesc);
            }
        }
예제 #2
0
        internal static ShaderResourceViewDescription GetSrvDesc(
            D3D11Texture tex,
            uint baseMipLevel,
            uint levelCount,
            uint baseArrayLayer,
            uint layerCount,
            PixelFormat format)
        {
            ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription();

            srvDesc.Format = D3D11Formats.GetViewFormat(
                D3D11Formats.ToDxgiFormat(format, (tex.Usage & TextureUsage.DepthStencil) != 0));

            if ((tex.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap)
            {
                if (tex.ArrayLayers == 1)
                {
                    srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCube;
                    srvDesc.TextureCube.MostDetailedMip = (int)baseMipLevel;
                    srvDesc.TextureCube.MipLevels       = (int)levelCount;
                }
                else
                {
                    srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCubeArray;
                    srvDesc.TextureCubeArray.MostDetailedMip  = (int)baseMipLevel;
                    srvDesc.TextureCubeArray.MipLevels        = (int)levelCount;
                    srvDesc.TextureCubeArray.First2DArrayFace = (int)baseArrayLayer;
                    srvDesc.TextureCubeArray.CubeCount        = (int)tex.ArrayLayers;
                }
            }
            else if (tex.Depth == 1)
            {
                if (tex.ArrayLayers == 1)
                {
                    srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D;
                    srvDesc.Texture2D.MostDetailedMip = (int)baseMipLevel;
                    srvDesc.Texture2D.MipLevels       = (int)levelCount;
                }
                else
                {
                    srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray;
                    srvDesc.Texture2DArray.MostDetailedMip = (int)baseMipLevel;
                    srvDesc.Texture2DArray.MipLevels       = (int)levelCount;
                    srvDesc.Texture2DArray.FirstArraySlice = (int)baseArrayLayer;
                    srvDesc.Texture2DArray.ArraySize       = (int)layerCount;
                }
            }
            else
            {
                srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture3D;
                srvDesc.Texture3D.MostDetailedMip = (int)baseMipLevel;
                srvDesc.Texture3D.MipLevels       = (int)levelCount;
            }

            return(srvDesc);
        }
예제 #3
0
        public D3D11TextureView(Device device, ref TextureViewDescription description)
            : base(description.Target)
        {
            D3D11Texture d3dTex = Util.AssertSubtype <Texture, D3D11Texture>(description.Target);
            ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription();

            srvDesc.Format = D3D11Formats.GetViewFormat(d3dTex.DeviceTexture.Description.Format);

            if ((d3dTex.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap)
            {
                if (d3dTex.ArrayLayers == 1)
                {
                    srvDesc.Dimension             = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCube;
                    srvDesc.TextureCube.MipLevels = (int)d3dTex.MipLevels;
                }
                else
                {
                    srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCubeArray;
                    srvDesc.TextureCubeArray.MipLevels = (int)d3dTex.MipLevels;
                    srvDesc.TextureCubeArray.CubeCount = (int)d3dTex.ArrayLayers;
                }
            }
            else if (d3dTex.Depth == 1)
            {
                if (d3dTex.ArrayLayers == 1)
                {
                    srvDesc.Dimension           = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D;
                    srvDesc.Texture2D.MipLevels = (int)d3dTex.MipLevels;
                }
                else
                {
                    srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray;
                    srvDesc.Texture2DArray.MipLevels = (int)d3dTex.MipLevels;
                    srvDesc.Texture2DArray.ArraySize = (int)d3dTex.ArrayLayers;
                }
            }
            else
            {
                srvDesc.Dimension           = SharpDX.Direct3D.ShaderResourceViewDimension.Texture3D;
                srvDesc.Texture3D.MipLevels = (int)d3dTex.MipLevels;
            }

            ShaderResourceView = new ShaderResourceView(device, d3dTex.DeviceTexture, srvDesc);
        }
예제 #4
0
        public D3D11TextureView(Device device, ref TextureViewDescription description)
            : base(ref description)
        {
            D3D11Texture d3dTex = Util.AssertSubtype <Texture, D3D11Texture>(description.Target);
            ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription();

            srvDesc.Format = D3D11Formats.GetViewFormat(d3dTex.DxgiFormat);

            if ((d3dTex.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap)
            {
                if (d3dTex.ArrayLayers == 1)
                {
                    srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCube;
                    srvDesc.TextureCube.MostDetailedMip = (int)description.BaseMipLevel;
                    srvDesc.TextureCube.MipLevels       = (int)description.MipLevels;
                }
                else
                {
                    srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCubeArray;
                    srvDesc.TextureCubeArray.MostDetailedMip  = (int)description.BaseMipLevel;
                    srvDesc.TextureCubeArray.MipLevels        = (int)description.MipLevels;
                    srvDesc.TextureCubeArray.First2DArrayFace = (int)description.BaseArrayLayer;
                    srvDesc.TextureCubeArray.CubeCount        = (int)d3dTex.ArrayLayers;
                }
            }
            else if (d3dTex.Depth == 1)
            {
                if (d3dTex.ArrayLayers == 1)
                {
                    srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D;
                    srvDesc.Texture2D.MostDetailedMip = (int)description.BaseMipLevel;
                    srvDesc.Texture2D.MipLevels       = (int)description.MipLevels;
                }
                else
                {
                    srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray;
                    srvDesc.Texture2DArray.MostDetailedMip = (int)description.BaseMipLevel;
                    srvDesc.Texture2DArray.MipLevels       = (int)description.MipLevels;
                    srvDesc.Texture2DArray.FirstArraySlice = (int)description.BaseArrayLayer;
                    srvDesc.Texture2DArray.ArraySize       = (int)description.ArrayLayers;
                }
            }
            else
            {
                srvDesc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture3D;
                srvDesc.Texture3D.MostDetailedMip = (int)description.BaseMipLevel;
                srvDesc.Texture3D.MipLevels       = (int)description.MipLevels;
            }

            ShaderResourceView = new ShaderResourceView(device, d3dTex.DeviceTexture, srvDesc);

            if ((d3dTex.Usage & TextureUsage.Storage) == TextureUsage.Storage)
            {
                UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription();
                uavDesc.Format = D3D11Formats.GetViewFormat(d3dTex.DxgiFormat);

                if ((d3dTex.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap)
                {
                    throw new NotSupportedException();
                }
                else if (d3dTex.Depth == 1)
                {
                    if (d3dTex.ArrayLayers == 1)
                    {
                        uavDesc.Dimension          = UnorderedAccessViewDimension.Texture2D;
                        uavDesc.Texture2D.MipSlice = (int)description.BaseMipLevel;
                    }
                    else
                    {
                        uavDesc.Dimension = UnorderedAccessViewDimension.Texture2DArray;
                        uavDesc.Texture2DArray.MipSlice        = (int)description.BaseMipLevel;
                        uavDesc.Texture2DArray.FirstArraySlice = (int)description.BaseArrayLayer;
                        uavDesc.Texture2DArray.ArraySize       = (int)description.ArrayLayers;
                    }
                }
                else
                {
                    uavDesc.Dimension             = UnorderedAccessViewDimension.Texture3D;
                    uavDesc.Texture3D.MipSlice    = (int)description.BaseMipLevel;
                    uavDesc.Texture3D.FirstWSlice = (int)description.BaseArrayLayer;
                    uavDesc.Texture3D.WSize       = (int)description.ArrayLayers;
                }

                UnorderedAccessView = new UnorderedAccessView(device, d3dTex.DeviceTexture, uavDesc);
            }
        }
예제 #5
0
        public D3D11TextureView(D3D11GraphicsDevice gd, ref TextureViewDescription description)
            : base(ref description)
        {
            ID3D11Device device = gd.Device;
            D3D11Texture d3dTex = Util.AssertSubtype <Texture, D3D11Texture>(description.Target);
            ShaderResourceViewDescription srvDesc = D3D11Util.GetSrvDesc(
                d3dTex,
                description.BaseMipLevel,
                description.MipLevels,
                description.BaseArrayLayer,
                description.ArrayLayers,
                Format);

            ShaderResourceView = device.CreateShaderResourceView(d3dTex.DeviceTexture, srvDesc);

            if ((d3dTex.Usage & TextureUsage.Storage) == TextureUsage.Storage)
            {
                UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription();
                uavDesc.Format = D3D11Formats.GetViewFormat(d3dTex.DxgiFormat);

                if ((d3dTex.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap)
                {
                    throw new NotSupportedException();
                }
                else if (d3dTex.Depth == 1)
                {
                    if (d3dTex.ArrayLayers == 1)
                    {
                        if (d3dTex.Type == TextureType.Texture1D)
                        {
                            uavDesc.ViewDimension      = UnorderedAccessViewDimension.Texture1D;
                            uavDesc.Texture1D.MipSlice = (int)description.BaseMipLevel;
                        }
                        else
                        {
                            uavDesc.ViewDimension      = UnorderedAccessViewDimension.Texture2D;
                            uavDesc.Texture2D.MipSlice = (int)description.BaseMipLevel;
                        }
                    }
                    else
                    {
                        if (d3dTex.Type == TextureType.Texture1D)
                        {
                            uavDesc.ViewDimension                  = UnorderedAccessViewDimension.Texture1DArray;
                            uavDesc.Texture1DArray.MipSlice        = (int)description.BaseMipLevel;
                            uavDesc.Texture1DArray.FirstArraySlice = (int)description.BaseArrayLayer;
                            uavDesc.Texture1DArray.ArraySize       = (int)description.ArrayLayers;
                        }
                        else
                        {
                            uavDesc.ViewDimension                  = UnorderedAccessViewDimension.Texture2DArray;
                            uavDesc.Texture2DArray.MipSlice        = (int)description.BaseMipLevel;
                            uavDesc.Texture2DArray.FirstArraySlice = (int)description.BaseArrayLayer;
                            uavDesc.Texture2DArray.ArraySize       = (int)description.ArrayLayers;
                        }
                    }
                }
                else
                {
                    uavDesc.ViewDimension      = UnorderedAccessViewDimension.Texture3D;
                    uavDesc.Texture3D.MipSlice = (int)description.BaseMipLevel;

                    // Map the entire range of the 3D texture.
                    uavDesc.Texture3D.FirstWSlice = 0;
                    uavDesc.Texture3D.WSize       = (int)d3dTex.Depth;
                }

                UnorderedAccessView = device.CreateUnorderedAccessView(d3dTex.DeviceTexture, uavDesc);
            }
        }