Exemple #1
0
        protected override bool GetPixelFormatSupportCore(
            PixelFormat format,
            TextureType type,
            TextureUsage usage,
            out PixelFormatProperties properties)
        {
            if (D3D11Formats.IsUnsupportedFormat(format))
            {
                properties = default(PixelFormatProperties);
                return(false);
            }

            Format        dxgiFormat = D3D11Formats.ToDxgiFormat(format, (usage & TextureUsage.DepthStencil) != 0);
            FormatSupport fs         = _device.CheckFormatSupport(dxgiFormat);

            if ((usage & TextureUsage.RenderTarget) != 0 && (fs & FormatSupport.RenderTarget) == 0 ||
                (usage & TextureUsage.DepthStencil) != 0 && (fs & FormatSupport.DepthStencil) == 0 ||
                (usage & TextureUsage.Sampled) != 0 && (fs & FormatSupport.ShaderSample) == 0 ||
                (usage & TextureUsage.Cubemap) != 0 && (fs & FormatSupport.TextureCube) == 0 ||
                (usage & TextureUsage.Storage) != 0 && (fs & FormatSupport.TypedUnorderedAccessView) == 0)
            {
                properties = default(PixelFormatProperties);
                return(false);
            }

            const uint MaxTextureDimension = 16384;
            const uint MaxVolumeExtent     = 2048;

            uint sampleCounts = 0;

            if (CheckFormatMultisample(dxgiFormat, 1))
            {
                sampleCounts |= (1 << 0);
            }
            if (CheckFormatMultisample(dxgiFormat, 2))
            {
                sampleCounts |= (1 << 1);
            }
            if (CheckFormatMultisample(dxgiFormat, 4))
            {
                sampleCounts |= (1 << 2);
            }
            if (CheckFormatMultisample(dxgiFormat, 8))
            {
                sampleCounts |= (1 << 3);
            }
            if (CheckFormatMultisample(dxgiFormat, 16))
            {
                sampleCounts |= (1 << 4);
            }
            if (CheckFormatMultisample(dxgiFormat, 32))
            {
                sampleCounts |= (1 << 5);
            }

            properties = new PixelFormatProperties(
                MaxTextureDimension,
                type == TextureType.Texture1D ? 1 : MaxTextureDimension,
                type != TextureType.Texture3D ? 1 : MaxVolumeExtent,
                uint.MaxValue,
                type == TextureType.Texture3D ? 1 : MaxVolumeExtent,
                sampleCounts);
            return(true);
        }