stride3d/stride · error · NotSupportedException

Unsupported depth format

Error message

Unsupported depth format [{format}]

What it means

Thrown by Texture.InitializeFromImpl on Direct3D12 when computing the DXGI view format for a texture used as a depth buffer, and the given PixelFormat is not one of the four supported depth formats (D16_UNorm, D32_Float, D24_UNorm_S8_UInt, D32_Float_S8X24_UInt) or their typeless variants. Only these formats map to a DXGI depth-stencil resource view format.

Solutions

  1. Change the texture Format to one of PixelFormat.D16_UNorm, PixelFormat.D32_Float, PixelFormat.D24_UNorm_S8_UInt, or PixelFormat.D32_Float_S8X24_UInt.
  2. If you need the typeless forms for shader-resource binding, use R16_Typeless, R32_Typeless, R24G8_Typeless, or R32G8X24_Typeless.
  3. Check TextureDescription.DepthFormat or the pipeline description that produced the format; do not reuse a color format for depth.

Example fix

// before
var texture = Texture.New2D(device, 1024, 1024, PixelFormat.R16_UNorm, TextureFlags.DepthStencil);
// after
var texture = Texture.New2D(device, 1024, 1024, PixelFormat.D16_UNorm, TextureFlags.DepthStencil);
Defensive patterns

Strategy: validation

Validate before calling

static readonly PixelFormat[] SupportedDepthFormats =
{
    PixelFormat.D16_UNorm, PixelFormat.D32_Float,
    PixelFormat.D24_UNorm_S8_UInt, PixelFormat.D32_Float_S8X24_UInt,
    PixelFormat.R16_Typeless, PixelFormat.R32_Typeless,
    PixelFormat.R24G8_Typeless, PixelFormat.R32G8X24_Typeless
};
if (Array.IndexOf(SupportedDepthFormats, desc.Format) < 0)
    throw new ArgumentException($"{desc.Format} is not a supported depth format");

Type guard

bool IsSupportedDepthFormat(PixelFormat f) =>
    f is PixelFormat.D16_UNorm or PixelFormat.D32_Float
      or PixelFormat.D24_UNorm_S8_UInt or PixelFormat.D32_Float_S8X24_UInt
      or PixelFormat.R16_Typeless or PixelFormat.R32_Typeless
      or PixelFormat.R24G8_Typeless or PixelFormat.R32G8X24_Typeless;

Try / catch

try { var tex = Texture.New2D(device, w, h, format, TextureFlags.DepthStencil); }
catch (NotSupportedException ex) { log.Error(ex, "Depth format rejected"); useFallbackDepthFormat(); }

Prevention

When it happens

Trigger: Creating a Texture (GraphicsDevice.AllocateTexture / new Texture) with TextureDescription whose Format is a depth-ish format that is not one of R16_Typeless/R16_UNorm, R32_Typeless/D32_Float, R24G8_Typeless/D24_UNorm_S8_UInt, or R32G8X24_Typeless/D32_Float_S8X24_UInt, with DepthStencilImage flag set.

Common situations: Passing a color format (e.g. R16_UNorm directly, R8_UNorm) or an unusual depth format like R16_UNorm_R16_X8_Typeless as DepthBuffer; porting code from another engine that used raw DXGI formats; misconfigured render target descriptors.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/a582771adc63108e. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Graphics/Direct3D12/Texture.Direct3D12.cs:904

                    ? (Format) ComputeShaderResourceFormatFromDepthFormat(ViewFormat)
                    : (Format) ViewFormat;

                return viewFormat;
            }

            //
            // Given a pixel format, returns the corresponding Silk.NET's depth format.
            //
            static Format ComputeDepthViewFormatFromTextureFormat(PixelFormat format)
            {
                var viewFormat = format switch
                {
                    PixelFormat.R16_Typeless or PixelFormat.D16_UNorm => Silk.NET.DXGI.Format.FormatD16Unorm,
                    PixelFormat.R32_Typeless or PixelFormat.D32_Float => Silk.NET.DXGI.Format.FormatD32Float,
                    PixelFormat.R24G8_Typeless or PixelFormat.D24_UNorm_S8_UInt => Silk.NET.DXGI.Format.FormatD24UnormS8Uint,
                    PixelFormat.R32G8X24_Typeless or PixelFormat.D32_Float_S8X24_UInt => Silk.NET.DXGI.Format.FormatD32FloatS8X24Uint,

                    _ => throw new NotSupportedException($"Unsupported depth format [{format}]")
                };
                return viewFormat;
            }

            //
            // Determines if a format is a Depth-Stencil format that also contains Stencil data.
            //
            static bool IsStencilFormat(PixelFormat format)
            {
                return format switch
                {
                    PixelFormat.R24G8_Typeless or
                    PixelFormat.D24_UNorm_S8_UInt or
                    PixelFormat.R32G8X24_Typeless or
                    PixelFormat.D32_Float_S8X24_UInt => true,

                    _ => false
                };

View on GitHub (pinned to 96fad776d2)