stride3d/stride · error · NotSupportedException
Unsupported depth format
Error message
Unsupported depth format [{format}] What it means
Thrown by ComputeDepthViewFormatFromTextureFormat when the texture's pixel format cannot be translated into a DXGI format for a Depth-Stencil View. Only the typeless/depth pairs (R16/D16, R32/D32, R24G8/D24S8, R32G8X24/D32S8X24) are valid; anything else is rejected with NotSupportedException while building the DSV description during texture initialization.
Solutions
- Use a depth-capable PixelFormat: D16_UNorm, D32_Float, D24_UNorm_S8_UInt, D32_Float_S8X24_UInt, or their typeless forms R16_Typeless, R32_Typeless, R24G8_Typeless, R32G8X24_Typeless.
- Drop the DepthStencil flag from textures that only need ShaderResource/RenderTarget flags.
- If reading depth in shaders is needed, sample the typeless depth texture with a shader-resource view created from the matching depth format.
Example fix
// before Texture.New2D(device, w, h, PixelFormat.R16_Float, TextureFlags.DepthStencil | TextureFlags.ShaderResource); // after Texture.New2D(device, w, h, PixelFormat.R32_Typeless, TextureFlags.DepthStencil | TextureFlags.ShaderResource);
Defensive patterns
Strategy: validation
Validate before calling
bool ok = format is PixelFormat.R16_Typeless or PixelFormat.D16_UNorm or PixelFormat.R32_Typeless or PixelFormat.D32_Float
or PixelFormat.R24G8_Typeless or PixelFormat.D24_UNorm_S8_UInt or PixelFormat.R32G8X24_Typeless or PixelFormat.D32_Float_S8X24_UInt; Type guard
static bool HasDepthViewFormat(PixelFormat f) => f is PixelFormat.R16_Typeless or PixelFormat.D16_UNorm or PixelFormat.R32_Typeless or PixelFormat.D32_Float or PixelFormat.R24G8_Typeless or PixelFormat.D24_UNorm_S8_UInt or PixelFormat.R32G8X24_Typeless or PixelFormat.D32_Float_S8X24_UInt;
Try / catch
try { dsvTexture = CreateDepthTarget(device, w, h, format); }
catch (NotSupportedException) { dsvTexture = CreateDepthTarget(device, w, h, PixelFormat.D32_Float); } Prevention
- For shadow maps sample-able in shaders, use R32_Typeless / R24G8_Typeless, not R32_Float / R16_Float.
- Validate every TextureFlags.DepthStencil texture against HasDepthViewFormat at startup.
- Never repurpose a color render-target texture as a depth target.
When it happens
Trigger: Initializing a D3D11 texture with DepthStencil flags whose Format is a color or non-depth format (e.g. R8_UNorm, R16_Float), so the DSV format lookup in InitializeFromImpl / dsvDescription fails.
Common situations: Reusing a color render-target texture as a depth buffer, configuring a shadow map with a floating-point color format instead of a depth format, or a typo in the PixelFormat enum.
Related errors
- Unsupported Depth Format
- Cannot clear a stencil buffer without a Stencil Buffer…
- Image format not supported
- This file format is not yet implemented.
- Element size must be greater than zero for structured…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/cb823892115a125e.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Direct3D11/Texture.Direct3D11.cs:1077
/// <summary>
/// Given a pixel format, returns the corresponding Silk.NET's depth format.
/// </summary>
/// <param name="format">The pixel format.</param>
/// <returns>The depth <see cref="Silk.NET.DXGI.Format"/> corresponding to <paramref name="format"/>.</returns>
/// <exception cref="NotSupportedException">
/// The <paramref name="format"/> does not have a corresponding depth format.
/// </exception>
internal 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;
}
/// <summary>
/// Returns a native <see cref="Texture3DDesc"/> from the current <see cref="TextureDescription"/>.
/// </summary>
/// <returns>A Silk.NET's <see cref="Texture3DDesc"/> describing the Texture.</returns>
private Texture3DDesc ConvertToNativeDescription3D()
{
var desc = new Texture3DDesc
{
Width = (uint) textureDescription.Width,
Height = (uint) textureDescription.Height,
Depth = (uint) textureDescription.Depth,
BindFlags = (uint) GetBindFlagsFromTextureFlags(textureDescription.Flags),
Format = (Format) textureDescription.Format,
MipLevels = (uint) textureDescription.MipLevelCount,View on GitHub (pinned to 96fad776d2)